diff options
| author | Bent Bisballe Nyeng <deva@aasimon.org> | 2019-02-01 18:05:18 +0100 | 
|---|---|---|
| committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2019-02-01 18:05:18 +0100 | 
| commit | 7a8e610ddde160950839f3af9356d4c416b39396 (patch) | |
| tree | ea3ba79c11677dd97fa6b5cb567f8ef5628c039a | |
| parent | 5ca1c40c92f074315bbdfe328c00484ff18146f2 (diff) | |
Add 'Set default path' button in filebrowser.
| -rw-r--r-- | plugingui/drumkitframecontent.cc | 21 | ||||
| -rw-r--r-- | plugingui/drumkitframecontent.h | 2 | ||||
| -rw-r--r-- | plugingui/filebrowser.cc | 27 | ||||
| -rw-r--r-- | plugingui/filebrowser.h | 3 | ||||
| -rw-r--r-- | plugingui/pluginconfig.cc | 14 | ||||
| -rw-r--r-- | plugingui/pluginconfig.h | 10 | 
6 files changed, 52 insertions, 25 deletions
| diff --git a/plugingui/drumkitframecontent.cc b/plugingui/drumkitframecontent.cc index 46ea67c..1da7201 100644 --- a/plugingui/drumkitframecontent.cc +++ b/plugingui/drumkitframecontent.cc @@ -124,6 +124,9 @@ DrumkitframeContent::DrumkitframeContent(Widget* parent,  	CONNECT(this, settings_notifier.number_of_files_loaded,  	        &drumkit_file_progress, &ProgressBar::setValue); +	CONNECT(this, file_browser. defaultPathChangedNotifier, +	        this, &DrumkitframeContent::defaultPathChanged); +  	midimap_file_progress.setTotal(2);  	file_browser.resize(450, 350); @@ -148,14 +151,15 @@ void DrumkitframeContent::resize(std::size_t width, std::size_t height)  void DrumkitframeContent::kitBrowseClick()  {  	std::string path = drumkit_file.getLineEdit().getText(); +  	if(path == "")  	{ -		path = config.lastkit; +		path = midimap_file.getLineEdit().getText();  	}  	if(path == "")  	{ -		path = midimap_file.getLineEdit().getText(); +		path = config.defaultKitPath;  	}  	file_browser.setPath(path); @@ -169,14 +173,15 @@ void DrumkitframeContent::kitBrowseClick()  void DrumkitframeContent::midimapBrowseClick()  {  	std::string path = midimap_file.getLineEdit().getText(); +  	if(path == "")  	{ -		path = config.lastmidimap; +		path = drumkit_file.getLineEdit().getText();  	}  	if(path == "")  	{ -		path = drumkit_file.getLineEdit().getText(); +		path = config.defaultKitPath;  	}  	file_browser.setPath(path); @@ -186,9 +191,14 @@ void DrumkitframeContent::midimapBrowseClick()  	file_browser.show();  } +void DrumkitframeContent::defaultPathChanged(const std::string& path) +{ +	config.defaultKitPath = path; +	config.save(); +} +  void DrumkitframeContent::selectKitFile(const std::string& filename)  { -	config.lastkit = filename;  	config.save();  	settings.drumkit_file.store(filename); @@ -197,7 +207,6 @@ void DrumkitframeContent::selectKitFile(const std::string& filename)  void DrumkitframeContent::selectMapFile(const std::string& filename)  { -	config.lastmidimap = filename;  	config.save();  	settings.midimap_file.store(filename); diff --git a/plugingui/drumkitframecontent.h b/plugingui/drumkitframecontent.h index 866b720..921927d 100644 --- a/plugingui/drumkitframecontent.h +++ b/plugingui/drumkitframecontent.h @@ -82,6 +82,8 @@ public:  	void midimapBrowseClick();  private: +	void defaultPathChanged(const std::string& path); +  	void selectKitFile(const std::string& filename);  	void selectMapFile(const std::string& filename); diff --git a/plugingui/filebrowser.cc b/plugingui/filebrowser.cc index 75d717d..3db8e0a 100644 --- a/plugingui/filebrowser.cc +++ b/plugingui/filebrowser.cc @@ -55,6 +55,7 @@ FileBrowser::FileBrowser(Widget* parent)  	, lineedit(this)  	, listbox(this)  	, btn_sel(this) +	, btn_def(this)  	, btn_esc(this)  	, back(":resources/bg.png")  { @@ -70,14 +71,15 @@ FileBrowser::FileBrowser(Widget* parent)  	CONNECT(&lineedit, enterPressedNotifier, this, &FileBrowser::handleKeyEvent);  	CONNECT(&listbox, selectionNotifier,  	        this, &FileBrowser::listSelectionChanged); -	CONNECT(this, fileSelectNotifier, -	        this, &FileBrowser::select); -	CONNECT(eventHandler(), closeNotifier, -	        this, &FileBrowser::cancel); +	CONNECT(this, fileSelectNotifier, this, &FileBrowser::select); +	CONNECT(eventHandler(), closeNotifier, this, &FileBrowser::cancel);  	btn_sel.setText("Select");  	CONNECT(&btn_sel, clickNotifier, this, &FileBrowser::selectButtonClicked); +	btn_def.setText("Set default path"); +	CONNECT(&btn_def, clickNotifier, this, &FileBrowser::setDefaultPath); +  	btn_esc.setText("Cancel");  	CONNECT(&btn_esc, clickNotifier, this, &FileBrowser::cancelButtonClicked); @@ -109,6 +111,7 @@ void FileBrowser::resize(std::size_t width, std::size_t height)  	int offset = 0;  	int brd = 5; // border  	int btn_h = 30; +	int btn_w = std::max(width * 2 / 7, std::size_t(0));  	offset += brd; @@ -126,11 +129,14 @@ void FileBrowser::resize(std::size_t width, std::size_t height)  	listbox.resize(std::max((int)width - 1 - 2*brd, 0),  	               std::max((int)height - btn_h - 2*brd - offset, 0)); -	btn_esc.move(brd, height - btn_h - brd); -	btn_esc.resize(std::max(((int)width - 1 - 2*brd) / 2 - brd / 2, 0), btn_h); +	btn_def.move(brd, height - btn_h - brd); +	btn_def.resize(btn_w, btn_h); + +	btn_esc.move(width - (brd + btn_w + brd + btn_w), height - btn_h - brd); +	btn_esc.resize(btn_w, btn_h); -	btn_sel.move(brd + width / 2 - brd / 2, height - btn_h - brd); -	btn_sel.resize(std::max((int)((int)width - 1 - 2*brd) / 2, 0), btn_h); +	btn_sel.move(width - (brd + btn_w), height - btn_h - brd); +	btn_sel.resize(btn_w, btn_h);  }  void FileBrowser::repaintEvent(RepaintEvent* repaintEvent) @@ -149,6 +155,11 @@ void FileBrowser::selectButtonClicked()  	changeDir();  } +void FileBrowser::setDefaultPath() +{ +	defaultPathChangedNotifier(dir.path()); +} +  void FileBrowser::cancelButtonClicked()  {  	cancel(); diff --git a/plugingui/filebrowser.h b/plugingui/filebrowser.h index ff8a7e8..7566391 100644 --- a/plugingui/filebrowser.h +++ b/plugingui/filebrowser.h @@ -50,6 +50,7 @@ public:  	Notifier<const std::string&> fileSelectNotifier; // (const std::string& path)  	Notifier<> fileSelectCancelNotifier; +	Notifier<const std::string&> defaultPathChangedNotifier; // (const std::string& path)  	// From Widget:  	bool isFocusable() override { return true; } @@ -66,6 +67,7 @@ public:  private:  	void listSelectionChanged();  	void selectButtonClicked(); +	void setDefaultPath();  	void cancelButtonClicked();  	void handleKeyEvent(); @@ -85,6 +87,7 @@ private:  	ListBox listbox;  	Button btn_sel; +	Button btn_def;  	Button btn_esc;  	Image back; diff --git a/plugingui/pluginconfig.cc b/plugingui/pluginconfig.cc index 85e101d..a249945 100644 --- a/plugingui/pluginconfig.cc +++ b/plugingui/pluginconfig.cc @@ -30,37 +30,37 @@  #define CONFIGFILENAME "plugingui.conf" -namespace GUI { +namespace GUI +{  Config::Config()  	: ConfigFile(CONFIGFILENAME)  { +	load();  }  Config::~Config()  { +	save();  }  bool Config::load()  { -	lastkit.clear(); -	lastmidimap.clear(); +	defaultKitPath.clear();  	if(!ConfigFile::load())  	{  		return false;  	} -	lastkit = getValue("lastkit"); -	lastmidimap = getValue("lastmidimap"); +	defaultKitPath = getValue("defaultKitPath");  	return true;  }  bool Config::save()  { -	setValue("lastkit", lastkit); -	setValue("lastmidimap", lastmidimap); +	setValue("defaultKitPath", defaultKitPath);  	return ConfigFile::save();  } diff --git a/plugingui/pluginconfig.h b/plugingui/pluginconfig.h index 82344cc..67d0ee8 100644 --- a/plugingui/pluginconfig.h +++ b/plugingui/pluginconfig.h @@ -28,9 +28,12 @@  #include <configfile.h> -namespace GUI { +namespace GUI +{ -class Config : public ConfigFile { +class Config +	: public ConfigFile +{  public:  	Config();  	~Config(); @@ -38,8 +41,7 @@ public:  	bool load();  	bool save(); -	std::string lastkit; -	std::string lastmidimap; +	std::string defaultKitPath;  };  } // GUI:: | 
