diff --git a/rtgui/curveeditorgroup.cc b/rtgui/curveeditorgroup.cc index c1915436d..d524e0c4d 100644 --- a/rtgui/curveeditorgroup.cc +++ b/rtgui/curveeditorgroup.cc @@ -423,7 +423,7 @@ Glib::ustring CurveEditorSubGroup::outputFile () { Gtk::FileChooserDialog dialog(M("CURVEEDITOR_SAVEDLGLABEL"), Gtk::FILE_CHOOSER_ACTION_SAVE); - FileChooserLastFolderPersister persister(&dialog, curveDir); + bindCurrentFolder (dialog, curveDir); dialog.set_current_name (lastFilename); dialog.add_button(Gtk::StockID("gtk-cancel"), Gtk::RESPONSE_CANCEL); @@ -468,7 +468,7 @@ Glib::ustring CurveEditorSubGroup::inputFile () { Gtk::FileChooserDialog dialog(M("CURVEEDITOR_LOADDLGLABEL"), Gtk::FILE_CHOOSER_ACTION_OPEN); - FileChooserLastFolderPersister persister(&dialog, curveDir); + bindCurrentFolder (dialog, curveDir); dialog.add_button(Gtk::StockID("gtk-cancel"), Gtk::RESPONSE_CANCEL); dialog.add_button(Gtk::StockID("gtk-apply"), Gtk::RESPONSE_APPLY); diff --git a/rtgui/darkframe.cc b/rtgui/darkframe.cc index e16817cb6..9edde1bbc 100644 --- a/rtgui/darkframe.cc +++ b/rtgui/darkframe.cc @@ -31,7 +31,7 @@ DarkFrame::DarkFrame () : FoldableToolPanel(this, "darkframe", M("TP_DARKFRAME_L hbdf = Gtk::manage(new Gtk::HBox()); hbdf->set_spacing(4); darkFrameFile = Gtk::manage(new MyFileChooserButton(M("TP_DARKFRAME_LABEL"), Gtk::FILE_CHOOSER_ACTION_OPEN)); - darkFrameFilePersister.reset(new FileChooserLastFolderPersister(darkFrameFile, options.lastDarkframeDir)); + bindCurrentFolder (*darkFrameFile, options.lastDarkframeDir); dfLabel = Gtk::manage(new Gtk::Label(M("GENERAL_FILE"))); btnReset = Gtk::manage(new Gtk::Button()); btnReset->set_image (*Gtk::manage(new RTImage ("gtk-cancel.png"))); diff --git a/rtgui/darkframe.h b/rtgui/darkframe.h index 5f8e32d90..fd0dc9fde 100644 --- a/rtgui/darkframe.h +++ b/rtgui/darkframe.h @@ -39,7 +39,6 @@ class DarkFrame : public ToolParamBlock, public FoldableToolPanel protected: MyFileChooserButton *darkFrameFile; - std::auto_ptr darkFrameFilePersister; Gtk::HBox *hbdf; Gtk::Button *btnReset; Gtk::Label *dfLabel; diff --git a/rtgui/filebrowser.cc b/rtgui/filebrowser.cc index 8bb1d69bb..fc0b3b9ae 100644 --- a/rtgui/filebrowser.cc +++ b/rtgui/filebrowser.cc @@ -854,7 +854,7 @@ void FileBrowser::menuItemActivated (Gtk::MenuItem* m) if( !mselected.empty() ) { rtengine::procparams::ProcParams pp = mselected[0]->thumbnail->getProcParams(); Gtk::FileChooserDialog fc("Dark Frame", Gtk::FILE_CHOOSER_ACTION_OPEN ); - FileChooserLastFolderPersister persister(&fc, options.lastDarkframeDir); + bindCurrentFolder (fc, options.lastDarkframeDir); fc.add_button( Gtk::StockID("gtk-cancel"), Gtk::RESPONSE_CANCEL); fc.add_button( Gtk::StockID("gtk-apply"), Gtk::RESPONSE_APPLY); @@ -930,7 +930,7 @@ void FileBrowser::menuItemActivated (Gtk::MenuItem* m) if( !mselected.empty() ) { rtengine::procparams::ProcParams pp = mselected[0]->thumbnail->getProcParams(); Gtk::FileChooserDialog fc("Flat Field", Gtk::FILE_CHOOSER_ACTION_OPEN ); - FileChooserLastFolderPersister persister(&fc, options.lastFlatfieldDir); + bindCurrentFolder (fc, options.lastFlatfieldDir); fc.add_button( Gtk::StockID("gtk-cancel"), Gtk::RESPONSE_CANCEL); fc.add_button( Gtk::StockID("gtk-apply"), Gtk::RESPONSE_APPLY); diff --git a/rtgui/flatfield.cc b/rtgui/flatfield.cc index cc8035fa8..8609bea73 100644 --- a/rtgui/flatfield.cc +++ b/rtgui/flatfield.cc @@ -31,7 +31,7 @@ FlatField::FlatField () : FoldableToolPanel(this, "flatfield", M("TP_FLATFIELD_L hbff = Gtk::manage(new Gtk::HBox()); hbff->set_spacing(2); flatFieldFile = Gtk::manage(new MyFileChooserButton(M("TP_FLATFIELD_LABEL"), Gtk::FILE_CHOOSER_ACTION_OPEN)); - flatFieldFilePersister.reset(new FileChooserLastFolderPersister(flatFieldFile, options.lastFlatfieldDir)); + bindCurrentFolder (*flatFieldFile, options.lastFlatfieldDir); ffLabel = Gtk::manage(new Gtk::Label(M("GENERAL_FILE"))); flatFieldFileReset = Gtk::manage(new Gtk::Button()); flatFieldFileReset->set_image (*Gtk::manage(new RTImage ("gtk-cancel.png"))); diff --git a/rtgui/flatfield.h b/rtgui/flatfield.h index c760433ec..162360b9a 100644 --- a/rtgui/flatfield.h +++ b/rtgui/flatfield.h @@ -41,7 +41,6 @@ class FlatField : public ToolParamBlock, public AdjusterListener, public Foldabl protected: MyFileChooserButton *flatFieldFile; - std::auto_ptr flatFieldFilePersister; Gtk::Label *ffLabel; Gtk::Label *ffInfo; Gtk::Button *flatFieldFileReset; diff --git a/rtgui/guiutils.cc b/rtgui/guiutils.cc index 141273179..9ca9af3e9 100644 --- a/rtgui/guiutils.cc +++ b/rtgui/guiutils.cc @@ -1013,34 +1013,18 @@ bool MyFileChooserButton::on_scroll_event (GdkEventScroll* event) return false; } -FileChooserLastFolderPersister::FileChooserLastFolderPersister( - Gtk::FileChooser* chooser, Glib::ustring& folderVariable) : - chooser(chooser), folderVariable(folderVariable) +void bindCurrentFolder (Gtk::FileChooser& chooser, Glib::ustring& variable) { - assert(chooser != NULL); + chooser.signal_selection_changed ().connect ([&]() + { + const auto current_folder = chooser.get_current_folder (); - selectionChangedConnetion = chooser->signal_selection_changed().connect( - sigc::mem_fun(*this, - &FileChooserLastFolderPersister::selectionChanged)); - - if (!folderVariable.empty()) { - chooser->set_current_folder(folderVariable); - } - -} - -FileChooserLastFolderPersister::~FileChooserLastFolderPersister() -{ - -} - -void FileChooserLastFolderPersister::selectionChanged() -{ - - if (!chooser->get_current_folder().empty()) { - folderVariable = chooser->get_current_folder(); - } + if (!current_folder.empty ()) + variable = current_folder; + }); + if (!variable.empty ()) + chooser.set_current_folder (variable); } TextOrIcon::TextOrIcon (Glib::ustring fname, Glib::ustring labelTx, Glib::ustring tooltipTx, TOITypes type) diff --git a/rtgui/guiutils.h b/rtgui/guiutils.h index 79f050c2f..c43d85b07 100644 --- a/rtgui/guiutils.h +++ b/rtgui/guiutils.h @@ -313,39 +313,9 @@ public: }; /** - * A class which maintains the last folder for a FileChooserDialog or Button by - * caching it in a a variable (which can be persisted externally). - * Each time the user selects a file or folder, the provided variable is updated - * with the associated folder. The path found in the variable is set in the - * dialog instance at constructions time of this object. + * @brief A helper method to connect the current folder property of a file chooser to an arbitrary variable. */ -class FileChooserLastFolderPersister: public Glib::Object -{ -public: - - /** - * Installs this persister on the provided GtkFileChooser instance and - * applies the current folder found in @p folderVariable for the dialog. - * - * @param chooser file chooser to maintain - * @param folderVariable variable storage to use for this dialog - */ - FileChooserLastFolderPersister(Gtk::FileChooser* chooser, Glib::ustring& folderVariable); - - virtual ~FileChooserLastFolderPersister(); - -private: - - /** - * Signal handler for the GtkFileChooser selection action. - */ - void selectionChanged(); - - Gtk::FileChooser* chooser; - Glib::ustring& folderVariable; - sigc::connection selectionChangedConnetion; - -}; +void bindCurrentFolder (Gtk::FileChooser& chooser, Glib::ustring& variable); typedef enum RTUpdatePolicy { RTUP_STATIC, diff --git a/rtgui/icmpanel.cc b/rtgui/icmpanel.cc index 584a99a22..b21ebf751 100644 --- a/rtgui/icmpanel.cc +++ b/rtgui/icmpanel.cc @@ -37,7 +37,7 @@ ICMPanel::ICMPanel () : FoldableToolPanel(this, "icm", M("TP_ICM_LABEL")), iunch ipDialog = Gtk::manage (new MyFileChooserButton (M("TP_ICM_INPUTDLGLABEL"), Gtk::FILE_CHOOSER_ACTION_OPEN)); ipDialog->set_tooltip_text (M("TP_ICM_INPUTCUSTOM_TOOLTIP")); - ipDialogPersister.reset(new FileChooserLastFolderPersister(ipDialog, options.lastIccDir)); + bindCurrentFolder (*ipDialog, options.lastIccDir); // ------------------------------- Input profile @@ -945,7 +945,7 @@ void ICMPanel::saveReferencePressed () } Gtk::FileChooserDialog dialog(M("TP_ICM_SAVEREFERENCE"), Gtk::FILE_CHOOSER_ACTION_SAVE); - FileChooserLastFolderPersister persister(&dialog, options.lastProfilingReferenceDir); + bindCurrentFolder (dialog, options.lastProfilingReferenceDir); dialog.set_current_name (lastRefFilename); dialog.add_button(Gtk::StockID("gtk-cancel"), Gtk::RESPONSE_CANCEL); diff --git a/rtgui/icmpanel.h b/rtgui/icmpanel.h index 863e88a46..640cca5a2 100644 --- a/rtgui/icmpanel.h +++ b/rtgui/icmpanel.h @@ -83,7 +83,6 @@ private: Gtk::RadioButton* ofromfile; Gtk::RadioButton* iunchanged; MyFileChooserButton* ipDialog; - std::auto_ptr ipDialogPersister; Gtk::RadioButton::Group opts; Gtk::Button* saveRef; sigc::connection ipc; diff --git a/rtgui/profilepanel.cc b/rtgui/profilepanel.cc index eb655f424..ca667c4d9 100644 --- a/rtgui/profilepanel.cc +++ b/rtgui/profilepanel.cc @@ -289,7 +289,7 @@ void ProfilePanel::save_clicked (GdkEventButton* event) } Gtk::FileChooserDialog dialog(M("PROFILEPANEL_SAVEDLGLABEL"), Gtk::FILE_CHOOSER_ACTION_SAVE); - FileChooserLastFolderPersister persister( &dialog, options.loadSaveProfilePath ); + bindCurrentFolder (dialog, options.loadSaveProfilePath); dialog.set_current_name (lastFilename); //Add the user's default (or global if multiuser=false) profile path to the Shortcut list @@ -465,7 +465,7 @@ void ProfilePanel::load_clicked (GdkEventButton* event) } Gtk::FileChooserDialog dialog(M("PROFILEPANEL_LOADDLGLABEL"), Gtk::FILE_CHOOSER_ACTION_OPEN); - FileChooserLastFolderPersister persister( &dialog, options.loadSaveProfilePath ); + bindCurrentFolder (dialog, options.loadSaveProfilePath); //Add the user's default (or global if multiuser=false) profile path to the Shortcut list #ifdef WIN32