#include <file_dialog.hpp>
Public Member Functions | |
file_dialog () | |
const std::string & | title () const |
Gets the current dialog title text. More... | |
file_dialog & | set_title (const std::string &value) |
Sets the current dialog title text. More... | |
const std::string & | message () const |
Gets the current dialog instructions/message text. More... | |
file_dialog & | set_message (const std::string &value) |
Sets the current dialog instructions/message text. More... | |
std::string | path () const |
Gets the current file selection. More... | |
file_dialog & | set_path (const std::string &value) |
Sets the initial file selection. More... | |
file_dialog & | set_filename (const std::string &value) |
Sets the initial file name input but not the path. More... | |
file_dialog & | set_extension (const std::string &value) |
Sets the default file extension for file names in save mode. More... | |
bool | read_only () const |
Whether user interface elements for manipulating existing objects are provided. More... | |
file_dialog & | set_read_only (bool value) |
Whether to provide user interface elements for manipulating existing objects. More... | |
bool | save_mode () const |
Returns whether save mode is enabled. More... | |
file_dialog & | set_save_mode (bool value) |
Sets the dialog's behavior on non-existent file name inputs. More... | |
file_dialog & | set_ok_label (const std::string &value) |
Sets the OK button label. More... | |
![]() | |
modal_dialog () | |
virtual | ~modal_dialog () |
bool | show (const unsigned auto_close_time=0) |
Shows the window. More... | |
window * | get_window () const |
Returns a pointer to the dialog's window. More... | |
int | get_retval () const |
Returns the cached window exit code. More... | |
void | set_retval (int retval) |
Convenience wrapper to set the window's exit code. More... | |
void | set_always_save_fields (const bool always_save_fields) |
void | set_restore (const bool restore) |
void | set_allow_plugin_skip (const bool allow_plugin_skip) |
void | set_show_even_without_video (const bool show_even_without_video) |
Private Types | |
enum | SELECTION_TYPE { SELECTION_NOT_FOUND, SELECTION_PARENT_NOT_FOUND, SELECTION_IS_DIR, SELECTION_IS_FILE } |
Private Member Functions | |
virtual const std::string & | window_id () const override |
Inherited from modal_dialog, implemented by REGISTER_DIALOG. More... | |
virtual void | pre_show (window &window) override |
Inherited from modal_dialog. More... | |
bool | on_exit (window &window) |
Handles dialog exit events and decides whether to proceed or not. More... | |
void | on_row_selected () |
Handles file/directory selection on single-click. More... | |
void | on_bookmark_selected () |
Handles selection or deselection of bookmarks. More... | |
void | on_bookmark_add_cmd () |
Handles Add Bookmark button press events. More... | |
void | on_bookmark_del_cmd () |
Handles Remove Bookmark button press events. More... | |
void | on_dir_create_cmd () |
Handles New Folder button press events. More... | |
void | on_file_delete_cmd () |
Handles Delete button press events. More... | |
bool | process_fileview_submit () |
Processes file view selection in reaction to row double-click events. More... | |
bool | process_textbox_submit () |
Processes textbox input in reaction to OK button/Enter key events. More... | |
bool | process_submit_common (const std::string &name) |
void | sync_bookmarks_bar () |
Updates the bookmarks bar state to reflect the internal state. More... | |
std::string | get_filelist_selection (class listbox &filelist) |
bool | is_selection_type_acceptable (SELECTION_TYPE stype) const |
Returns whether the given selection type is acceptable for closing the dialog. More... | |
bool | confirm_overwrite (SELECTION_TYPE stype) |
Prompts the user before overwriting an existing file. More... | |
SELECTION_TYPE | register_new_selection (const std::string &name) |
Updates the internal state and returns the type of the selection. More... | |
void | set_input_text (class text_box &t, const std::string &value) |
void | clear_input_text (class text_box &t) |
void | refresh_fileview () |
Updates the dialog contents to match the internal state. More... | |
void | push_fileview_row (class listbox &filelist, const std::string &name, const std::string &icon, bool check_selection=true) |
Row building helper for refresh_fileview(). More... | |
Private Attributes | |
std::string | title_ |
std::string | msg_ |
std::string | ok_label_ |
std::string | extension_ |
std::string | current_entry_ |
std::string | current_dir_ |
bool | read_only_ |
bool | save_mode_ |
std::vector< std::string > | dir_files_ |
std::vector< std::string > | dir_subdirs_ |
std::vector< std::string > | bookmark_paths_ |
int | current_bookmark_ |
int | user_bookmarks_begin_ |
Additional Inherited Members | |
![]() | |
field_bool * | register_bool (const std::string &id, const bool mandatory, const std::function< bool()> callback_load_value=nullptr, const std::function< void(bool)> callback_save_value=nullptr, const std::function< void(widget &)> callback_change=nullptr, const bool initial_fire=false) |
Creates a new boolean field. More... | |
field_bool * | register_bool (const std::string &id, const bool mandatory, bool &linked_variable, const std::function< void(widget &)> callback_change=nullptr, const bool initial_fire=false) |
Creates a new boolean field. More... | |
field_integer * | register_integer (const std::string &id, const bool mandatory, const std::function< int()> callback_load_value=nullptr, const std::function< void(int)> callback_save_value=nullptr) |
Creates a new integer field. More... | |
field_integer * | register_integer (const std::string &id, const bool mandatory, int &linked_variable) |
Creates a new integer field. More... | |
field_text * | register_text (const std::string &id, const bool mandatory, const std::function< std::string()> callback_load_value=nullptr, const std::function< void(const std::string &)> callback_save_value=nullptr, const bool capture_focus=false) |
Creates a new text field. More... | |
field_text * | register_text (const std::string &id, const bool mandatory, std::string &linked_variable, const bool capture_focus=false) |
Creates a new text field. More... | |
field_label * | register_label (const std::string &id, const bool mandatory, const std::string &text, const bool use_markup=false) |
Registers a new styled_widget as a label. More... | |
field_label * | register_image (const std::string &id, const bool mandatory, const std::string &filename) |
Registers a new styled_widget as image. More... | |
![]() | |
std::unique_ptr< window > | window_ |
The window object build for this dialog. More... | |
Definition at line 40 of file file_dialog.hpp.
|
private |
Enumerator | |
---|---|
SELECTION_NOT_FOUND | |
SELECTION_PARENT_NOT_FOUND | |
SELECTION_IS_DIR | |
SELECTION_IS_FILE |
Definition at line 259 of file file_dialog.hpp.
gui2::dialogs::file_dialog::file_dialog | ( | ) |
Definition at line 106 of file file_dialog.cpp.
|
private |
Definition at line 468 of file file_dialog.cpp.
References gui2::text_box::clear(), extension_, save_mode_, gui2::text_box_base::set_selection(), and gui2::text_box_base::set_value().
Referenced by on_row_selected(), and set_input_text().
|
private |
Prompts the user before overwriting an existing file.
This only makes sense in save mode.
Definition at line 295 of file file_dialog.cpp.
References _(), gui2::CANCEL, SELECTION_IS_FILE, gui2::show_message(), and gui2::dialogs::message::yes_no_buttons.
Referenced by process_submit_common().
|
private |
Definition at line 358 of file file_dialog.cpp.
References current_dir_, dir_files_, dir_subdirs_, gui2::listbox::get_selected_row(), filesystem::is_root(), and n.
Referenced by on_row_selected(), and process_fileview_submit().
|
private |
Returns whether the given selection type is acceptable for closing the dialog.
Definition at line 287 of file file_dialog.cpp.
References save_mode_, SELECTION_IS_DIR, SELECTION_IS_FILE, and SELECTION_PARENT_NOT_FOUND.
Referenced by process_submit_common().
|
inline |
Gets the current dialog instructions/message text.
Definition at line 65 of file file_dialog.hpp.
References msg_.
|
private |
Handles Add Bookmark button press events.
Definition at line 648 of file file_dialog.cpp.
References gui2::listbox::add_row(), desktop::add_user_bookmark(), filesystem::base_name(), bookmark_paths_, current_bookmark_, current_dir_, gui2::dialogs::bookmark_create::execute(), gui2::dialogs::modal_dialog::get_window(), sync_bookmarks_bar(), and user_bookmarks_begin_.
Referenced by pre_show().
|
private |
Handles Remove Bookmark button press events.
Definition at line 682 of file file_dialog.cpp.
References bookmark_paths_, current_bookmark_, gui2::dialogs::modal_dialog::get_window(), gui2::listbox::remove_row(), desktop::remove_user_bookmark(), sync_bookmarks_bar(), and user_bookmarks_begin_.
Referenced by pre_show().
|
private |
Handles selection or deselection of bookmarks.
Definition at line 618 of file file_dialog.cpp.
References bookmark_paths_, current_bookmark_, gui2::listbox::get_selected_row(), gui2::dialogs::modal_dialog::get_window(), gui2::window::keyboard_capture(), refresh_fileview(), gui2::listbox::select_row(), gui2::button::set_active(), set_path(), and user_bookmarks_begin_.
Referenced by pre_show().
|
private |
Handles New Folder button press events.
Definition at line 699 of file file_dialog.cpp.
References current_dir_, filesystem::make_directory(), refresh_fileview(), gui2::show_transient_error_message(), and VGETTEXT.
Referenced by pre_show().
|
private |
Handles dialog exit events and decides whether to proceed or not.
Definition at line 265 of file file_dialog.cpp.
References gui2::window::get_retval(), gui2::OK, process_fileview_submit(), process_textbox_submit(), and gui2::window::set_retval().
Referenced by pre_show().
|
private |
Handles Delete button press events.
Definition at line 716 of file file_dialog.cpp.
References _(), gui2::CANCEL, current_dir_, current_entry_, filesystem::delete_directory(), filesystem::delete_file(), filesystem::is_directory(), refresh_fileview(), gui2::show_message(), gui2::show_transient_error_message(), VGETTEXT, and gui2::dialogs::message::yes_no_buttons.
Referenced by pre_show().
|
private |
Handles file/directory selection on single-click.
Definition at line 594 of file file_dialog.cpp.
References clear_input_text(), current_entry_, get_filelist_selection(), gui2::dialogs::modal_dialog::get_window(), gui2::window::keyboard_capture(), and set_input_text().
Referenced by pre_show(), and refresh_fileview().
std::string gui2::dialogs::file_dialog::path | ( | ) | const |
Gets the current file selection.
Definition at line 124 of file file_dialog.cpp.
References current_dir_, current_entry_, filesystem::directory_name(), and filesystem::normalize_path().
Referenced by editor::context_manager::apply_mask_dialog(), editor::context_manager::create_mask_to_dialog(), editor::context_manager::load_map_dialog(), events::menu_handler::save_map(), editor::context_manager::save_map_as_dialog(), editor::context_manager::save_scenario_as_dialog(), gui2::dialogs::custom_tod::select_file(), set_message(), and preferences::show_wesnothd_server_search().
|
overrideprivatevirtual |
Inherited from modal_dialog.
Reimplemented from gui2::dialogs::modal_dialog.
Definition at line 167 of file file_dialog.cpp.
References _(), gui2::listbox::add_row(), bookmark_paths_, gui2::event::connect_signal_mouse_left_click(), gui2::event::connect_signal_notify_modified(), current_bookmark_, desktop::game_paths(), gui2::widget::invisible, msg_, ok_label_, on_bookmark_add_cmd(), on_bookmark_del_cmd(), on_bookmark_selected(), on_dir_create_cmd(), on_exit(), on_file_delete_cmd(), on_row_selected(), read_only_, refresh_fileview(), save_mode_, gui2::button::set_active(), gui2::styled_widget::set_label(), gui2::widget::set_visible(), sync_bookmarks_bar(), desktop::system_paths(), title(), title_, desktop::user_bookmarks(), and user_bookmarks_begin_.
|
private |
Processes file view selection in reaction to row double-click events.
It takes care of synchronizing the state, browsing to the new selection, and/or displaying an error message if appropriate
Definition at line 344 of file file_dialog.cpp.
References get_filelist_selection(), gui2::dialogs::modal_dialog::get_window(), and process_submit_common().
Referenced by on_exit().
|
private |
Definition at line 307 of file file_dialog.cpp.
References confirm_overwrite(), is_selection_type_acceptable(), refresh_fileview(), register_new_selection(), save_mode_, SELECTION_IS_DIR, SELECTION_IS_FILE, SELECTION_NOT_FOUND, SELECTION_PARENT_NOT_FOUND, gui2::show_transient_error_message(), sync_bookmarks_bar(), and VGETTEXT.
Referenced by process_fileview_submit(), and process_textbox_submit().
|
private |
Processes textbox input in reaction to OK button/Enter key events.
It takes care of synchronizing the state, browsing to the new selection, and/or displaying an error message if appropriate
Definition at line 351 of file file_dialog.cpp.
References gui2::text_box_base::get_value(), gui2::dialogs::modal_dialog::get_window(), and process_submit_common().
Referenced by on_exit().
|
private |
Row building helper for refresh_fileview().
filelist | Target for adding the new row. |
name | Label, assumed to be a file name if check_selection = true. |
icon | Row icon. |
check_selection | Whether to set the row to selected if the current file name in the internal state matches the row's label/name. |
Definition at line 527 of file file_dialog.cpp.
References gui2::listbox::add_row(), current_entry_, utils::ellipsis_truncate(), name, gui2::listbox::select_last_row(), and gui2::dialogs::modal_dialog::set_retval().
Referenced by refresh_fileview().
|
inline |
Whether user interface elements for manipulating existing objects are provided.
Definition at line 134 of file file_dialog.hpp.
References read_only_.
|
private |
Updates the dialog contents to match the internal state.
Definition at line 478 of file file_dialog.cpp.
References gui2::listbox::clear(), current_dir_, current_entry_, dir_files_, dir_subdirs_, filesystem::FILE_NAME_ONLY, filesystem::get_files_in_dir(), gui2::dialogs::modal_dialog::get_window(), filesystem::is_root(), on_row_selected(), push_fileview_row(), gui2::listbox::select_row(), set_input_text(), and cursor::WAIT.
Referenced by on_bookmark_selected(), on_dir_create_cmd(), on_file_delete_cmd(), pre_show(), and process_submit_common().
|
private |
Updates the internal state and returns the type of the selection.
If the given name refers to a non-existent object, the internal state is unchanged.
Definition at line 390 of file file_dialog.cpp.
References filesystem::base_name(), current_dir_, current_entry_, DBG_FILEDLG, filesystem::directory_name(), filesystem::file_exists(), filesystem::is_directory(), filesystem::is_relative(), filesystem::is_root(), filesystem::normalize_path(), filesystem::root_name(), SELECTION_IS_DIR, SELECTION_IS_FILE, SELECTION_NOT_FOUND, and SELECTION_PARENT_NOT_FOUND.
Referenced by process_submit_common().
|
inline |
Returns whether save mode is enabled.
See set_save_mode() for more information.
Definition at line 155 of file file_dialog.hpp.
References save_mode_.
|
inline |
Sets the default file extension for file names in save mode.
When this is set to a non-empty string and save mode is active, selecting file entries will cause their name portions to be highlighted in the name text box if their extensions match the provided template, and any time the text box is cleared it will position the cursor before the extension as a hint for the user.
The value provided to this method should be preceded by a dot if applicable (e.g. ".cfg").
Definition at line 125 of file file_dialog.hpp.
References extension_.
Referenced by events::menu_handler::save_map(), editor::context_manager::save_map_as_dialog(), and editor::context_manager::save_scenario_as_dialog().
file_dialog & gui2::dialogs::file_dialog::set_filename | ( | const std::string & | value | ) |
Sets the initial file name input but not the path.
The file name needs not exist in the initial path selected with set_path().
If this is used before set_path() and the path passed there points to a file, that file name will replace the one given here.
Definition at line 160 of file file_dialog.cpp.
References current_entry_.
Referenced by set_message(), and preferences::show_wesnothd_server_search().
|
private |
Definition at line 448 of file file_dialog.cpp.
References clear_input_text(), extension_, gui2::text_box_base::get_length(), save_mode_, gui2::text_box_base::set_selection(), gui2::text_box_base::set_value(), and utf8::size().
Referenced by on_row_selected(), and refresh_fileview().
|
inline |
Sets the current dialog instructions/message text.
The message text may contain Pango markup.
Definition at line 75 of file file_dialog.hpp.
References msg_, path(), set_filename(), and set_path().
Referenced by preferences::show_wesnothd_server_search().
|
inline |
Sets the OK button label.
By default, "Save" is used when save_mode is enabled, and "Open" otherwise. Calling this method with an empty string will reset the label to the default.
Definition at line 182 of file file_dialog.hpp.
References ok_label_.
Referenced by gui2::dialogs::custom_tod::select_file(), and preferences::show_wesnothd_server_search().
file_dialog & gui2::dialogs::file_dialog::set_path | ( | const std::string & | value | ) |
Sets the initial file selection.
If the path is found to refer to a file (more specifically, any non-directory object), that file is initially selected on the directory contents view and the file name box is set to contain its name. If the file does not exist, but the path leading up to it does, the directory contents view displays that path and there isn't an initial file selection or name set unless set_filename() is used first.
If you want to set an initial file name hint/template, use set_filename() after calling this method.
Definition at line 137 of file file_dialog.cpp.
References filesystem::base_name(), current_dir_, current_entry_, filesystem::is_directory(), filesystem::nearest_extant_parent(), and filesystem::normalize_path().
Referenced by editor::context_manager::apply_mask_dialog(), editor::context_manager::create_mask_to_dialog(), editor::context_manager::load_map_dialog(), on_bookmark_selected(), events::menu_handler::save_map(), editor::context_manager::save_map_as_dialog(), editor::context_manager::save_scenario_as_dialog(), gui2::dialogs::custom_tod::select_file(), set_message(), and preferences::show_wesnothd_server_search().
|
inline |
Whether to provide user interface elements for manipulating existing objects.
This is initially disabled.
Definition at line 144 of file file_dialog.hpp.
References read_only_.
Referenced by gui2::dialogs::custom_tod::select_file(), and preferences::show_wesnothd_server_search().
|
inline |
Sets the dialog's behavior on non-existent file name inputs.
This is initially disabled.
When save mode is enabled, file names entered into the dialog by the user need not exist already (but their parent directories still do). Otherwise, the user is only able to select existing files.
Definition at line 169 of file file_dialog.hpp.
References save_mode_.
Referenced by events::menu_handler::save_map(), editor::context_manager::save_map_as_dialog(), and editor::context_manager::save_scenario_as_dialog().
|
inline |
Sets the current dialog title text.
Definition at line 56 of file file_dialog.hpp.
References title_.
Referenced by editor::context_manager::apply_mask_dialog(), editor::context_manager::create_mask_to_dialog(), editor::context_manager::load_map_dialog(), events::menu_handler::save_map(), editor::context_manager::save_map_as_dialog(), editor::context_manager::save_scenario_as_dialog(), gui2::dialogs::custom_tod::select_file(), and preferences::show_wesnothd_server_search().
|
private |
Updates the bookmarks bar state to reflect the internal state.
Definition at line 553 of file file_dialog.cpp.
References bookmark_paths_, current_bookmark_, current_dir_, gui2::listbox::get_item_count(), gui2::dialogs::modal_dialog::get_window(), filesystem::normalize_path(), gui2::listbox::select_row(), gui2::button::set_active(), and user_bookmarks_begin_.
Referenced by on_bookmark_add_cmd(), on_bookmark_del_cmd(), pre_show(), and process_submit_common().
|
inline |
Gets the current dialog title text.
Definition at line 48 of file file_dialog.hpp.
References title_.
Referenced by pre_show().
|
overrideprivatevirtual |
Inherited from modal_dialog, implemented by REGISTER_DIALOG.
Implements gui2::dialogs::modal_dialog.
|
private |
Definition at line 203 of file file_dialog.hpp.
Referenced by on_bookmark_add_cmd(), on_bookmark_del_cmd(), on_bookmark_selected(), pre_show(), and sync_bookmarks_bar().
|
private |
Definition at line 204 of file file_dialog.hpp.
Referenced by on_bookmark_add_cmd(), on_bookmark_del_cmd(), on_bookmark_selected(), pre_show(), and sync_bookmarks_bar().
|
private |
Definition at line 195 of file file_dialog.hpp.
Referenced by get_filelist_selection(), on_bookmark_add_cmd(), on_dir_create_cmd(), on_file_delete_cmd(), path(), refresh_fileview(), register_new_selection(), set_path(), and sync_bookmarks_bar().
|
private |
Definition at line 194 of file file_dialog.hpp.
Referenced by on_file_delete_cmd(), on_row_selected(), path(), push_fileview_row(), refresh_fileview(), register_new_selection(), set_filename(), and set_path().
|
private |
Definition at line 200 of file file_dialog.hpp.
Referenced by get_filelist_selection(), and refresh_fileview().
|
private |
Definition at line 201 of file file_dialog.hpp.
Referenced by get_filelist_selection(), and refresh_fileview().
|
private |
Definition at line 193 of file file_dialog.hpp.
Referenced by clear_input_text(), set_extension(), and set_input_text().
|
private |
Definition at line 190 of file file_dialog.hpp.
Referenced by message(), pre_show(), and set_message().
|
private |
Definition at line 191 of file file_dialog.hpp.
Referenced by pre_show(), and set_ok_label().
|
private |
Definition at line 197 of file file_dialog.hpp.
Referenced by pre_show(), read_only(), and set_read_only().
|
private |
Definition at line 198 of file file_dialog.hpp.
Referenced by clear_input_text(), is_selection_type_acceptable(), pre_show(), process_submit_common(), save_mode(), set_input_text(), and set_save_mode().
|
private |
Definition at line 189 of file file_dialog.hpp.
Referenced by pre_show(), set_title(), and title().
|
private |
Definition at line 205 of file file_dialog.hpp.
Referenced by on_bookmark_add_cmd(), on_bookmark_del_cmd(), on_bookmark_selected(), pre_show(), and sync_bookmarks_bar().