Replace the last folder persister and the use of std::auto_ptr by a simple method using a lambda to bind a variable using the selection_changed signal.

This commit is contained in:
Adam Reichold
2015-12-25 19:48:20 +01:00
parent 547b969ed4
commit ff616eb473
11 changed files with 21 additions and 70 deletions

View File

@@ -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);

View File

@@ -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")));

View File

@@ -39,7 +39,6 @@ class DarkFrame : public ToolParamBlock, public FoldableToolPanel
protected:
MyFileChooserButton *darkFrameFile;
std::auto_ptr<FileChooserLastFolderPersister> darkFrameFilePersister;
Gtk::HBox *hbdf;
Gtk::Button *btnReset;
Gtk::Label *dfLabel;

View File

@@ -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);

View File

@@ -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")));

View File

@@ -41,7 +41,6 @@ class FlatField : public ToolParamBlock, public AdjusterListener, public Foldabl
protected:
MyFileChooserButton *flatFieldFile;
std::auto_ptr<FileChooserLastFolderPersister> flatFieldFilePersister;
Gtk::Label *ffLabel;
Gtk::Label *ffInfo;
Gtk::Button *flatFieldFileReset;

View File

@@ -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)

View File

@@ -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,

View File

@@ -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);

View File

@@ -83,7 +83,6 @@ private:
Gtk::RadioButton* ofromfile;
Gtk::RadioButton* iunchanged;
MyFileChooserButton* ipDialog;
std::auto_ptr<FileChooserLastFolderPersister> ipDialogPersister;
Gtk::RadioButton::Group opts;
Gtk::Button* saveRef;
sigc::connection ipc;

View File

@@ -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