The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
gui2::dialogs::file_dialog Class Reference

#include <file_dialog.hpp>

Inheritance diagram for gui2::dialogs::file_dialog:
Inheritance graph

Public Member Functions

 file_dialog ()
 
const std::string & title () const
 Gets the current dialog title text. More...
 
file_dialogset_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_dialogset_message (const std::string &value)
 Sets the current dialog instructions/message text. More...
 
std::string path () const
 Gets the current file selection. More...
 
file_dialogset_path (const std::string &value)
 Sets the initial file selection. More...
 
file_dialogset_filename (const std::string &value)
 Sets the initial file name input but not the path. More...
 
file_dialogset_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_dialogset_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_dialogset_save_mode (bool value)
 Sets the dialog's behavior on non-existent file name inputs. More...
 
file_dialogset_ok_label (const std::string &value)
 Sets the OK button label. More...
 
- Public Member Functions inherited from gui2::dialogs::modal_dialog
 modal_dialog ()
 
virtual ~modal_dialog ()
 
bool show (CVideo &video, const unsigned auto_close_time=0)
 Shows the window. More...
 
windowget_window () const
 Returns a pointer to the dialog's window. More...
 
int get_retval () const
 
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 (window &window)
 Handles file/directory selection on single-click. More...
 
void on_bookmark_selected (window &window)
 Handles selection or deselection of bookmarks. More...
 
void on_bookmark_add_cmd (window &window)
 Handles Add Bookmark button press events. More...
 
void on_bookmark_del_cmd (window &window)
 Handles Remove Bookmark button press events. More...
 
void on_dir_create_cmd (window &window)
 Handles New Folder button press events. More...
 
void on_file_delete_cmd (window &window)
 Handles Delete button press events. More...
 
bool process_fileview_submit (window &window)
 Processes file view selection in reaction to row double-click events. More...
 
bool process_textbox_submit (window &window)
 Processes textbox input in reaction to OK button/Enter key events. More...
 
bool process_submit_common (window &window, const std::string &name)
 
void sync_bookmarks_bar (window &window)
 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 (window &window, 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 (window &window)
 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

- Protected Member Functions inherited from gui2::dialogs::modal_dialog
field_boolregister_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_boolregister_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_integerregister_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_integerregister_integer (const std::string &id, const bool mandatory, int &linked_variable)
 Creates a new integer field. More...
 
field_textregister_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_textregister_text (const std::string &id, const bool mandatory, std::string &linked_variable, const bool capture_focus=false)
 Creates a new text field. More...
 
field_labelregister_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_labelregister_image (const std::string &id, const bool mandatory, const std::string &filename)
 Registers a new styled_widget as image. More...
 

Detailed Description

Definition at line 40 of file file_dialog.hpp.

Member Enumeration Documentation

Enumerator
SELECTION_NOT_FOUND 
SELECTION_PARENT_NOT_FOUND 
SELECTION_IS_DIR 
SELECTION_IS_FILE 

Definition at line 259 of file file_dialog.hpp.

Constructor & Destructor Documentation

gui2::dialogs::file_dialog::file_dialog ( )

Definition at line 109 of file file_dialog.cpp.

Member Function Documentation

void gui2::dialogs::file_dialog::clear_input_text ( class text_box t)
private
bool gui2::dialogs::file_dialog::confirm_overwrite ( window window,
file_dialog::SELECTION_TYPE  stype 
)
private

Prompts the user before overwriting an existing file.

This only makes sense in save mode.

Returns
true if the selection does not refer to an existing file or the user accepted the overwrite prompt; false otherwise.

Definition at line 299 of file file_dialog.cpp.

References _(), gui2::window::CANCEL, message(), SELECTION_IS_FILE, gui2::show_message(), gui2::window::video(), and gui2::dialogs::message::yes_no_buttons.

Referenced by process_submit_common().

std::string gui2::dialogs::file_dialog::get_filelist_selection ( class listbox filelist)
private
bool gui2::dialogs::file_dialog::is_selection_type_acceptable ( file_dialog::SELECTION_TYPE  stype) const
private

Returns whether the given selection type is acceptable for closing the dialog.

Todo:
This currently never returns true for SELECTION_IS_DIR, awaiting a need to implement a directory selection mode.

Definition at line 291 of file file_dialog.cpp.

References save_mode_, SELECTION_IS_DIR, SELECTION_IS_FILE, and SELECTION_PARENT_NOT_FOUND.

Referenced by process_submit_common().

const std::string& gui2::dialogs::file_dialog::message ( ) const
inline

Gets the current dialog instructions/message text.

Definition at line 65 of file file_dialog.hpp.

References msg_.

Referenced by confirm_overwrite(), and on_file_delete_cmd().

void gui2::dialogs::file_dialog::on_bookmark_add_cmd ( window window)
private
void gui2::dialogs::file_dialog::on_bookmark_del_cmd ( window window)
private

Handles Remove Bookmark button press events.

Definition at line 687 of file file_dialog.cpp.

References bookmark_paths_, current_bookmark_, gui2::listbox::remove_row(), desktop::remove_user_bookmark(), sync_bookmarks_bar(), and user_bookmarks_begin_.

Referenced by pre_show().

void gui2::dialogs::file_dialog::on_bookmark_selected ( window window)
private
void gui2::dialogs::file_dialog::on_dir_create_cmd ( window window)
private
bool gui2::dialogs::file_dialog::on_exit ( window window)
private

Handles dialog exit events and decides whether to proceed or not.

Definition at line 268 of file file_dialog.cpp.

References gui2::window::get_retval(), gui2::window::OK, process_fileview_submit(), process_textbox_submit(), and gui2::window::set_retval().

Referenced by pre_show().

void gui2::dialogs::file_dialog::on_file_delete_cmd ( window window)
private
void gui2::dialogs::file_dialog::on_row_selected ( window window)
private

Handles file/directory selection on single-click.

Definition at line 599 of file file_dialog.cpp.

References clear_input_text(), current_entry_, get_filelist_selection(), and set_input_text().

Referenced by pre_show(), and refresh_fileview().

std::string gui2::dialogs::file_dialog::path ( ) const
void gui2::dialogs::file_dialog::pre_show ( window window)
overrideprivatevirtual
bool gui2::dialogs::file_dialog::process_fileview_submit ( window window)
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

Returns
Whether to exit the dialog successfully (true) or continue (false).

Definition at line 348 of file file_dialog.cpp.

References get_filelist_selection(), and process_submit_common().

Referenced by on_exit().

bool gui2::dialogs::file_dialog::process_submit_common ( window window,
const std::string &  name 
)
private
bool gui2::dialogs::file_dialog::process_textbox_submit ( window window)
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

Returns
Whether to exit the dialog successfully (true) or continue (false).

Definition at line 355 of file file_dialog.cpp.

References gui2::text_box_base::get_value(), and process_submit_common().

Referenced by on_exit().

void gui2::dialogs::file_dialog::push_fileview_row ( class listbox filelist,
const std::string &  name,
const std::string &  icon,
bool  check_selection = true 
)
private

Row building helper for refresh_fileview().

Parameters
filelistTarget for adding the new row.
nameLabel, assumed to be a file name if check_selection = true.
iconRow icon.
check_selectionWhether to set the row to selected if the current file name in the internal state matches the row's label/name.

Definition at line 531 of file file_dialog.cpp.

References gui2::listbox::add_row(), current_entry_, utils::ellipsis_truncate(), gui2::listbox::get_item_count(), name(), and gui2::listbox::select_row().

Referenced by refresh_fileview().

bool gui2::dialogs::file_dialog::read_only ( ) const
inline

Whether user interface elements for manipulating existing objects are provided.

Definition at line 134 of file file_dialog.hpp.

References read_only_.

void gui2::dialogs::file_dialog::refresh_fileview ( window window)
private
file_dialog::SELECTION_TYPE gui2::dialogs::file_dialog::register_new_selection ( const std::string &  name)
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 394 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().

bool gui2::dialogs::file_dialog::save_mode ( ) const
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_.

file_dialog& gui2::dialogs::file_dialog::set_extension ( const std::string &  value)
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 163 of file file_dialog.cpp.

References current_entry_.

Referenced by preferences::show_wesnothd_server_search().

void gui2::dialogs::file_dialog::set_input_text ( class text_box t,
const std::string &  value 
)
private
file_dialog& gui2::dialogs::file_dialog::set_message ( const std::string &  value)
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_.

Referenced by preferences::show_wesnothd_server_search().

file_dialog& gui2::dialogs::file_dialog::set_ok_label ( const std::string &  value)
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 140 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(), and preferences::show_wesnothd_server_search().

file_dialog& gui2::dialogs::file_dialog::set_read_only ( bool  value)
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().

file_dialog& gui2::dialogs::file_dialog::set_save_mode ( bool  value)
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().

file_dialog& gui2::dialogs::file_dialog::set_title ( const std::string &  value)
inline
void gui2::dialogs::file_dialog::sync_bookmarks_bar ( window window)
private
const std::string& gui2::dialogs::file_dialog::title ( ) const
inline

Gets the current dialog title text.

Definition at line 48 of file file_dialog.hpp.

References title_.

Referenced by pre_show().

virtual const std::string& gui2::dialogs::file_dialog::window_id ( ) const
overrideprivatevirtual

Inherited from modal_dialog, implemented by REGISTER_DIALOG.

Implements gui2::dialogs::modal_dialog.

Member Data Documentation

std::vector<std::string> gui2::dialogs::file_dialog::bookmark_paths_
private
int gui2::dialogs::file_dialog::current_bookmark_
private
std::string gui2::dialogs::file_dialog::current_dir_
private
std::string gui2::dialogs::file_dialog::current_entry_
private
std::vector<std::string> gui2::dialogs::file_dialog::dir_files_
private

Definition at line 200 of file file_dialog.hpp.

Referenced by get_filelist_selection(), and refresh_fileview().

std::vector<std::string> gui2::dialogs::file_dialog::dir_subdirs_
private

Definition at line 201 of file file_dialog.hpp.

Referenced by get_filelist_selection(), and refresh_fileview().

std::string gui2::dialogs::file_dialog::extension_
private

Definition at line 193 of file file_dialog.hpp.

Referenced by clear_input_text(), set_extension(), and set_input_text().

std::string gui2::dialogs::file_dialog::msg_
private

Definition at line 190 of file file_dialog.hpp.

Referenced by message(), pre_show(), and set_message().

std::string gui2::dialogs::file_dialog::ok_label_
private

Definition at line 191 of file file_dialog.hpp.

Referenced by pre_show(), and set_ok_label().

bool gui2::dialogs::file_dialog::read_only_
private

Definition at line 197 of file file_dialog.hpp.

Referenced by pre_show(), read_only(), and set_read_only().

bool gui2::dialogs::file_dialog::save_mode_
private
std::string gui2::dialogs::file_dialog::title_
private

Definition at line 189 of file file_dialog.hpp.

Referenced by pre_show(), set_title(), and title().

int gui2::dialogs::file_dialog::user_bookmarks_begin_
private

The documentation for this class was generated from the following files: