gui2/tfile_dialog: Allow users to customize labels when bookmarking paths
We're piggybacking on the existing tfolder_create dialog with some added functionality and a dummy tbookmark_create class for now.
This commit is contained in:
parent
007a76d72f
commit
bb005cfe3c
3 changed files with 55 additions and 5 deletions
|
@ -649,10 +649,20 @@ void tfile_dialog::on_bookmark_selected(twindow& window)
|
|||
|
||||
void tfile_dialog::on_bookmark_add_cmd(twindow& window)
|
||||
{
|
||||
tlistbox& bookmarks_bar = find_widget<tlistbox>(&window, "bookmarks", false);
|
||||
const std::string& default_label = fs::base_name(current_dir_);
|
||||
|
||||
// TODO: Maybe let users set custom labels?
|
||||
const std::string& label = fs::base_name(current_dir_);
|
||||
std::string label = default_label;
|
||||
|
||||
const bool confirm = gui2::tbookmark_create::execute(label, window.video());
|
||||
if(!confirm) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(label.empty()) {
|
||||
label = default_label;
|
||||
}
|
||||
|
||||
tlistbox& bookmarks_bar = find_widget<tlistbox>(&window, "bookmarks", false);
|
||||
|
||||
desktop::add_user_bookmark(label, current_dir_);
|
||||
bookmark_paths_.push_back(current_dir_);
|
||||
|
|
|
@ -16,7 +16,11 @@
|
|||
|
||||
#include "gui/dialogs/folder_create.hpp"
|
||||
|
||||
#include "gettext.hpp"
|
||||
#include "gui/auxiliary/find_widget.hpp"
|
||||
#include "gui/widgets/control.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
@ -27,13 +31,15 @@ namespace gui2
|
|||
*
|
||||
* == Folder Create ==
|
||||
*
|
||||
* Dialog for providing the name of a new folder to create.
|
||||
* Dialog for providing the name of a new folder or bookmark to create.
|
||||
* Used by the file dialog.
|
||||
*
|
||||
* @begin{table}{dialog_widgets}
|
||||
*
|
||||
* title & & control & m &
|
||||
* Label with the dialog caption. Changed in bookmark mode. $
|
||||
* name & & text_box & m &
|
||||
* Input field for the new folder name. $
|
||||
* Input field for the new folder/bookmark name. $
|
||||
*
|
||||
* @end{table}
|
||||
*/
|
||||
|
@ -41,7 +47,16 @@ namespace gui2
|
|||
REGISTER_DIALOG(folder_create)
|
||||
|
||||
tfolder_create::tfolder_create(std::string& folder_name)
|
||||
: bookmark_mode_(false)
|
||||
{
|
||||
register_text("name", true, folder_name, true);
|
||||
}
|
||||
|
||||
void tfolder_create::pre_show(twindow& window)
|
||||
{
|
||||
if(bookmark_mode_) {
|
||||
find_widget<tcontrol>(&window, "title", false).set_label(_("New Bookmark"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,9 +42,34 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
friend class tbookmark_create;
|
||||
|
||||
bool bookmark_mode_;
|
||||
|
||||
/** Changes the dialog caption so it can be used for naming bookmarks. */
|
||||
tfolder_create& enable_bookmark_mode()
|
||||
{
|
||||
bookmark_mode_ = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
|
||||
virtual const std::string& window_id() const;
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
void pre_show(twindow& window);
|
||||
};
|
||||
|
||||
class tbookmark_create
|
||||
{
|
||||
public:
|
||||
/** The execute function; see @ref tdialog for more information. */
|
||||
static bool execute(std::string& bookmark_name, CVideo& video)
|
||||
{
|
||||
return tfolder_create(bookmark_name).enable_bookmark_mode().show(video);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* ! GUI_DIALOGS_EDIT_LABEL_INCLUDED */
|
||||
|
|
Loading…
Add table
Reference in a new issue