A widget where the user may navigate through directories and choose a file. More...
#include <file_menu.hpp>
Public Member Functions | |
file_menu (CVideo &disp, std::string start_file="") | |
Initialize the file menu. More... | |
std::string | get_choice () const |
Return the chosen file. More... | |
int | delete_chosen_file () |
std::string | get_directory () const |
std::string | add_path (const std::string &path, const std::string &to_add) const |
Return path with to_add added, using a path delimiter between them. More... | |
std::string | strip_last_delim (const std::string &path) const |
Return the string with the last path delimiter removed, if one was there. More... | |
bool | is_directory (const std::string &fname) const |
void | change_directory (const std::string &path) |
bool | make_directory (const std::string &subdir_name) |
void | select_file (const std::string &begin_of_filename) |
Selects file (type-a-head search) More... | |
bool | type_a_head () const |
void | reset_type_a_head () |
![]() | |
menu (CVideo &video, const std::vector< std::string > &items, bool click_selects=false, int max_height=-1, int max_width=-1, const sorter *sorter_obj=nullptr, style *menu_style=nullptr, const bool auto_join=true) | |
~menu () | |
Default implementation, but defined out-of-line for efficiency reasons. More... | |
int | selection () const |
void | move_selection (size_t id) |
void | move_selection_keeping_viewport (size_t id) |
void | reset_selection () |
const item & | get_item (int index) const |
const item & | get_selected_item () const |
void | change_item (int pos1, int pos2, const std::string &str) |
virtual void | erase_item (size_t index) |
void | set_heading (const std::vector< std::string > &heading) |
virtual void | set_items (const std::vector< std::string > &items, bool strip_spaces=true, bool keep_viewport=false) |
Set new items to show and redraw/recalculate everything. More... | |
void | set_max_height (const int new_max_height) |
Set a new max height for this menu. More... | |
void | set_max_width (const int new_max_width) |
int | get_max_height () |
int | get_max_width () |
size_t | number_of_items () const |
int | process () |
bool | double_clicked () |
void | set_click_selects (bool value) |
void | set_numeric_keypress_selection (bool value) |
void | scroll (unsigned int pos) |
void | set_sorter (sorter *s) |
void | sort_by (int column) |
int | get_sort_by () |
bool | get_sort_reversed () |
![]() | |
scrollarea (CVideo &video, bool auto_join=true) | |
Create a zone with automatic handling of scrollbar. More... | |
virtual void | hide (bool value=true) |
![]() | |
SDL_Rect const & | location () const |
virtual void | set_location (SDL_Rect const &rect) |
void | set_location (int x, int y) |
void | set_width (int w) |
void | set_height (int h) |
void | set_measurements (int w, int h) |
int | width () const |
int | height () const |
bool | focus (const SDL_Event *event) |
void | set_focus (bool focus) |
bool | hidden () const |
virtual void | enable (bool new_val=true) |
bool | enabled () const |
void | set_clip_rect (const SDL_Rect &rect) |
void | set_volatile (bool val=true) |
void | set_dirty (bool dirty=true) |
bool | dirty () const |
const std::string & | id () const |
void | set_id (const std::string &id) |
void | set_help_string (const std::string &str) |
void | set_tooltip_string (const std::string &str) |
virtual void | process_tooltip_string (int mousex, int mousey) |
![]() | |
virtual void | join () |
virtual void | join (context &c) |
virtual void | join_same (sdl_handler *parent) |
virtual void | leave () |
virtual void | join_global () |
virtual void | leave_global () |
Static Public Attributes | |
static const char | path_delim |
![]() | |
static style & | default_style = menu::bluebg_style |
static style | simple_style |
static imgsel_style | bluebg_style |
Protected Member Functions | |
void | handle_event (const SDL_Event &event) |
![]() | |
bool | item_ends_with_image (const std::string &item) const |
void | set_inner_location (const SDL_Rect &rect) |
bool | requires_event_focus (const SDL_Event *event=nullptr) const |
const std::vector< int > & | column_widths () const |
virtual void | draw_row (const size_t row_index, const SDL_Rect &rect, ROW_TYPE type) |
int | hit (int x, int y) const |
std::pair< int, int > | hit_cell (int x, int y) const |
int | hit_column (int x) const |
int | hit_heading (int x, int y) const |
void | invalidate_row (size_t id) |
void | invalidate_row_pos (size_t pos) |
void | invalidate_heading () |
![]() | |
virtual sdl_handler_vector | handler_members () |
virtual void | update_location (SDL_Rect const &rect) |
virtual void | process_event () |
SDL_Rect | inner_location () const |
unsigned | scrollbar_width () const |
unsigned | get_position () const |
unsigned | get_max_position () const |
void | set_position (unsigned pos) |
void | adjust_position (unsigned pos) |
void | move_position (int dep) |
void | set_shown_size (unsigned h) |
void | set_full_size (unsigned h) |
void | set_scroll_rate (unsigned r) |
bool | has_scrollbar () const |
![]() | |
widget (widget const &o) | |
widget (CVideo &video, const bool auto_join=true) | |
virtual | ~widget () |
void | bg_register (SDL_Rect const &rect) |
void | bg_restore () const |
void | bg_restore (SDL_Rect const &rect) const |
void | bg_update () |
void | bg_cancel () |
CVideo & | video () const |
const SDL_Rect * | clip_rect () const |
virtual sdl_handler_vector | member_handlers () |
virtual void | handle_window_event (SDL_Event const &event) |
bool | mouse_locked () const |
void | aquire_mouse_lock () |
void | free_mouse_lock () |
![]() | |
sdl_handler (const bool auto_join=true) | |
virtual | ~sdl_handler () |
Private Member Functions | |
std::string | get_path (const std::string &file_or_dir) const |
If file_or_dir is a file, return the directory the file is in, if it is a directory, return the directory name. More... | |
std::string | get_path_up (const std::string &path, const unsigned levels=1) const |
Return the path that is the specified number of levels up from the path. More... | |
bool | is_root (const std::string &path) const |
Return true if the path is the root of the filesystem. More... | |
void | display_current_files () |
Show the files in the current directory. More... | |
void | update_file_lists () |
Updated the locally maintained lists of files and directories in the current directory. More... | |
void | entry_selected (const unsigned entry) |
Set the textbox to reflect the selected file. More... | |
Private Attributes | |
std::string | current_dir_ |
std::string | chosen_file_ |
std::vector< std::string > | files_in_current_dir_ |
std::vector< std::string > | dirs_in_current_dir_ |
int | last_selection_ |
int | type_a_head_ |
Additional Inherited Members | |
![]() | |
enum | ROW_TYPE { NORMAL_ROW, SELECTED_ROW, HEADING_ROW } |
![]() | |
style * | style_ |
bool | silent_ |
![]() | |
bool | focus_ |
A widget where the user may navigate through directories and choose a file.
Definition at line 25 of file file_menu.hpp.
gui::file_menu::file_menu | ( | CVideo & | disp, |
std::string | start_file = "" |
||
) |
Initialize the file menu.
start_file is the file that will be selected initially. The current directory will be the one the file is in.
Definition at line 52 of file file_menu.cpp.
References chosen_file_, current_dir_, filesystem::file_exists(), filesystem::is_directory(), path_delim, and update_file_lists().
std::string gui::file_menu::add_path | ( | const std::string & | path, |
const std::string & | to_add | ||
) | const |
Return path with to_add added, using a path delimiter between them.
Definition at line 244 of file file_menu.cpp.
References get_path_up(), path_delim, gui::path_up(), and strip_last_delim().
Referenced by entry_selected(), make_directory(), and dialogs::file_dialog::unformat_filename().
void gui::file_menu::change_directory | ( | const std::string & | path | ) |
Definition at line 169 of file file_menu.cpp.
References chosen_file_, current_dir_, get_path_up(), is_root(), last_selection_, gui::path_up(), and update_file_lists().
Referenced by dialogs::file_dialog::action().
int gui::file_menu::delete_chosen_file | ( | ) |
Definition at line 104 of file file_menu.cpp.
References chosen_file_, current_dir_, filesystem::delete_file(), last_selection_, and update_file_lists().
Referenced by dialogs::file_dialog::action().
|
private |
Show the files in the current directory.
Definition at line 72 of file file_menu.cpp.
References COLUMN_SEPARATOR, current_dir_, gui::dir_picture(), dirs_in_current_dir_, files_in_current_dir_, gui::menu::get_max_width(), font::IMAGE, is_root(), font::line_width(), font::NULL_MARKUP, gui::path_up(), gui::menu::set_items(), font::SIZE_NORMAL, and gui::widget::width().
Referenced by update_file_lists().
|
private |
Set the textbox to reflect the selected file.
Definition at line 141 of file file_menu.cpp.
References add_path(), chosen_file_, current_dir_, dirs_in_current_dir_, files_in_current_dir_, is_root(), gui::path_up(), and game_config::images::selected.
Referenced by handle_event(), and reset_type_a_head().
std::string gui::file_menu::get_choice | ( | ) | const |
Return the chosen file.
Definition at line 191 of file file_menu.cpp.
References chosen_file_.
Referenced by dialogs::file_dialog::action().
|
inline |
Definition at line 40 of file file_menu.hpp.
References current_dir_.
Referenced by dialogs::file_dialog::action(), dialogs::file_dialog::file_dialog(), and dialogs::file_dialog::unformat_filename().
|
private |
If file_or_dir is a file, return the directory the file is in, if it is a directory, return the directory name.
If no path delimiters could be found, return the unchanged argument.
Definition at line 196 of file file_menu.cpp.
References filesystem::is_directory(), and path_delim.
Referenced by get_path_up().
|
private |
Return the path that is the specified number of levels up from the path.
If the movement could not proceed due to being at the root or having an invalid argument, return the path that the movement ended on.
Definition at line 207 of file file_menu.cpp.
References get_path(), i, is_root(), path_delim, and strip_last_delim().
Referenced by add_path(), and change_directory().
|
protectedvirtual |
Reimplemented from gui::menu.
Definition at line 130 of file file_menu.cpp.
References entry_selected(), gui::menu::handle_event(), last_selection_, gui::menu::selection(), type_a_head(), and type_a_head_.
bool gui::file_menu::is_directory | ( | const std::string & | fname | ) | const |
Definition at line 163 of file file_menu.cpp.
References filesystem::is_directory(), and gui::path_up().
Referenced by dialogs::file_dialog::action(), and dialogs::file_dialog::format_filename().
|
private |
Return true if the path is the root of the filesystem.
Definition at line 240 of file file_menu.cpp.
References path_delim.
Referenced by change_directory(), display_current_files(), entry_selected(), get_path_up(), and select_file().
bool gui::file_menu::make_directory | ( | const std::string & | subdir_name | ) |
Definition at line 117 of file file_menu.cpp.
References add_path(), chosen_file_, current_dir_, last_selection_, filesystem::make_directory(), and update_file_lists().
Referenced by dialogs::file_dialog::action().
void gui::file_menu::reset_type_a_head | ( | ) |
Definition at line 285 of file file_menu.cpp.
References entry_selected(), last_selection_, and type_a_head_.
Referenced by dialogs::file_dialog::action().
void gui::file_menu::select_file | ( | const std::string & | begin_of_filename | ) |
Selects file (type-a-head search)
Definition at line 295 of file file_menu.cpp.
References current_dir_, dirs_in_current_dir_, files_in_current_dir_, is_root(), gui::menu::move_selection(), and type_a_head_.
Referenced by dialogs::file_dialog::action(), and dialogs::file_dialog::select_file().
std::string gui::file_menu::strip_last_delim | ( | const std::string & | path | ) | const |
Return the string with the last path delimiter removed, if one was there.
Definition at line 232 of file file_menu.cpp.
References path_delim.
Referenced by add_path(), dialogs::file_dialog::format_dirname(), and get_path_up().
bool gui::file_menu::type_a_head | ( | ) | const |
Definition at line 280 of file file_menu.cpp.
References gui::menu::selection(), and type_a_head_.
Referenced by dialogs::file_dialog::action(), and handle_event().
|
private |
Updated the locally maintained lists of files and directories in the current directory.
Definition at line 317 of file file_menu.cpp.
References current_dir_, dirs_in_current_dir_, display_current_files(), filesystem::FILE_NAME_ONLY, files_in_current_dir_, and filesystem::get_files_in_dir().
Referenced by change_directory(), delete_chosen_file(), file_menu(), and make_directory().
|
private |
Definition at line 93 of file file_menu.hpp.
Referenced by change_directory(), delete_chosen_file(), entry_selected(), file_menu(), get_choice(), and make_directory().
|
private |
Definition at line 92 of file file_menu.hpp.
Referenced by change_directory(), delete_chosen_file(), display_current_files(), entry_selected(), file_menu(), get_directory(), make_directory(), select_file(), and update_file_lists().
|
private |
Definition at line 94 of file file_menu.hpp.
Referenced by display_current_files(), entry_selected(), select_file(), and update_file_lists().
|
private |
Definition at line 94 of file file_menu.hpp.
Referenced by display_current_files(), entry_selected(), select_file(), and update_file_lists().
|
private |
Definition at line 95 of file file_menu.hpp.
Referenced by change_directory(), delete_chosen_file(), handle_event(), make_directory(), and reset_type_a_head().
|
static |
Definition at line 28 of file file_menu.hpp.
Referenced by add_path(), file_menu(), dialogs::file_dialog::format_filename(), get_path(), get_path_up(), is_root(), and strip_last_delim().
|
private |
Definition at line 96 of file file_menu.hpp.
Referenced by handle_event(), reset_type_a_head(), select_file(), and type_a_head().