From 45a3b36b3aadbaa3adbbedbc47738467c5bd6501 Mon Sep 17 00:00:00 2001 From: Lawrence Lee <45837045+Lawrence37@users.noreply.github.com> Date: Sun, 30 Apr 2023 12:30:46 -0700 Subject: [PATCH] Fix file chooser entry not updating Save file name while it is typed in the text entry. Add placeholder text for Lensfun database directory to indicate automatic detection if left blank. --- rtgui/guiutils.cc | 21 +++++++++++++++++++-- rtgui/guiutils.h | 3 +++ rtgui/preferences.cc | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/rtgui/guiutils.cc b/rtgui/guiutils.cc index 3581097ed..a0317d226 100644 --- a/rtgui/guiutils.cc +++ b/rtgui/guiutils.cc @@ -1548,13 +1548,18 @@ MyFileChooserEntry::MyFileChooserEntry(const Glib::ustring &title, Gtk::FileChoo MyFileChooserWidget(title, action), pimpl(new Impl()) { + const auto on_text_changed = [this]() { + set_filename(pimpl->entry.get_text()); + }; + pimpl->entry.get_buffer()->signal_deleted_text().connect([on_text_changed](guint, guint) { on_text_changed(); }); + pimpl->entry.get_buffer()->signal_inserted_text().connect([on_text_changed](guint, const gchar *, guint) { on_text_changed(); }); + pimpl->file_chooser_button.set_image(*Gtk::manage(make_folder_image().release())); pimpl->file_chooser_button.signal_clicked().connect([this]() { - const auto &filename = pimpl->entry.get_text(); + const auto &filename = get_filename(); if (Glib::file_test(filename, Glib::FILE_TEST_IS_DIR)) { set_current_folder(filename); } - set_filename(filename); show_chooser(this); }); @@ -1563,6 +1568,18 @@ MyFileChooserEntry::MyFileChooserEntry(const Glib::ustring &title, Gtk::FileChoo } +Glib::ustring MyFileChooserEntry::get_placeholder_text() const +{ + return pimpl->entry.get_placeholder_text(); +} + + +void MyFileChooserEntry::set_placeholder_text(const Glib::ustring &text) +{ + pimpl->entry.set_placeholder_text(text); +} + + void MyFileChooserEntry::on_filename_set() { if (pimpl->entry.get_text() != get_filename()) { diff --git a/rtgui/guiutils.h b/rtgui/guiutils.h index 58877aed4..8bc047bf7 100644 --- a/rtgui/guiutils.h +++ b/rtgui/guiutils.h @@ -463,6 +463,9 @@ class MyFileChooserEntry : public Gtk::Box, public MyFileChooserWidget public: explicit MyFileChooserEntry(const Glib::ustring &title, Gtk::FileChooserAction action = Gtk::FILE_CHOOSER_ACTION_OPEN); + Glib::ustring get_placeholder_text() const; + void set_placeholder_text(const Glib::ustring &text); + protected: void on_filename_set() override; diff --git a/rtgui/preferences.cc b/rtgui/preferences.cc index 1e652faf4..da8272442 100644 --- a/rtgui/preferences.cc +++ b/rtgui/preferences.cc @@ -671,6 +671,7 @@ Gtk::Widget* Preferences::getImageProcessingPanel () Gtk::Label *lensfunDbDirLabel = Gtk::manage(new Gtk::Label(M("PREFERENCES_LENSFUNDBDIR") + ":")); setExpandAlignProperties(lensfunDbDirLabel, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER); lensfunDbDir = Gtk::manage(new MyFileChooserEntry(M("PREFERENCES_LENSFUNDBDIR"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER)); + lensfunDbDir->set_placeholder_text(Glib::ustring::compose("(%1)", M("GENERAL_AUTO"))); setExpandAlignProperties(lensfunDbDir, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER); Gtk::Label* lensfunDbDirRestartNeededLabel = Gtk::manage(new Gtk::Label(Glib::ustring(" (") + M("PREFERENCES_APPLNEXTSTARTUP") + ")")); setExpandAlignProperties(lensfunDbDirRestartNeededLabel, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);