The Battle for Wesnoth
1.13.4+dev
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
widgets
file_menu.hpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2003 - 2016 by David White <
[email protected]
>
3
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY.
11
12
See the COPYING file for more details.
13
*/
14
15
#ifndef FILE_MENU_H_INCLUDED
16
#define FILE_MENU_H_INCLUDED
17
18
#include "
construct_dialog.hpp
"
19
20
namespace
gui
{
21
22
23
/// A widget where the user may navigate through directories and choose
24
/// a file.
25
class
file_menu
:
public
menu
{
26
public
:
27
//Static members
28
static
const
char
path_delim
;
29
30
/// Initialize the file menu. start_file is the file that will be
31
/// selected initially. The current directory will be
32
/// the one the file is in.
33
file_menu
(
CVideo
&disp,
std::string
start_file=
""
);
34
35
/// Return the chosen file.
36
std::string
get_choice
()
const
;
37
38
int
delete_chosen_file
();
39
40
std::string
get_directory
()
const
{
return
current_dir_
; }
41
42
/// Return path with to_add added, using a path delimiter between them.
43
std::string
add_path
(
const
std::string
&
path
,
const
std::string
& to_add)
const
;
44
45
/// Return the string with the last path delimiter removed, if one
46
/// was there.
47
std::string
strip_last_delim
(
const
std::string
&
path
)
const
;
48
49
bool
is_directory
(
const
std::string
& fname)
const
;
50
51
void
change_directory
(
const
std::string
&
path
);
52
bool
make_directory
(
const
std::string
& subdir_name);
53
54
/**
55
* Selects file (type-a-head search)
56
**/
57
void
select_file
(
const
std::string
& begin_of_filename);
58
59
bool
type_a_head
()
const
;
60
void
reset_type_a_head
();
61
62
protected
:
63
void
handle_event
(
const
SDL_Event&
event
);
64
65
private
:
66
/// If file_or_dir is a file, return the directory the file is in,
67
/// if it is a directory, return the directory name. If no path
68
/// delimiters could be found, return the unchanged argument.
69
std::string
get_path
(
const
std::string
& file_or_dir)
const
;
70
71
/// Return the path that is the specified number of levels up from
72
/// the path. If the movement could not proceed due to being at the
73
/// root or having an invalid argument, return the path that the
74
/// movement ended on.
75
std::string
get_path_up
(
const
std::string
&
path
,
76
const
unsigned
levels
=1)
const
;
77
78
79
/// Return true if the path is the root of the filesystem.
80
bool
is_root
(
const
std::string
&
path
)
const
;
81
82
/// Show the files in the current directory.
83
void
display_current_files
();
84
85
/// Updated the locally maintained lists of files and directories in
86
/// the current directory.
87
void
update_file_lists
();
88
89
/// Set the textbox to reflect the selected file.
90
void
entry_selected
(
const
unsigned
entry);
91
92
std::string
current_dir_
;
93
std::string
chosen_file_
;
94
std::vector<std::string>
files_in_current_dir_
,
dirs_in_current_dir_
;
95
int
last_selection_
;
96
int
type_a_head_
;
97
};
98
99
}
//end namespace gui
100
101
#endif // FILE_MENU_H_INCLUDED
gui::file_menu::path_delim
static const char path_delim
Definition:
file_menu.hpp:28
gui::file_menu::make_directory
bool make_directory(const std::string &subdir_name)
Definition:
file_menu.cpp:117
gui::file_menu::handle_event
void handle_event(const SDL_Event &event)
Definition:
file_menu.cpp:130
CVideo
Definition:
video.hpp:58
gui::file_menu::dirs_in_current_dir_
std::vector< std::string > dirs_in_current_dir_
Definition:
file_menu.hpp:94
gui
General purpose widgets.
Definition:
construct_dialog.cpp:40
construct_dialog.hpp
gui::file_menu::file_menu
file_menu(CVideo &disp, std::string start_file="")
Initialize the file menu.
Definition:
file_menu.cpp:52
gui::file_menu::last_selection_
int last_selection_
Definition:
file_menu.hpp:95
gui::file_menu::entry_selected
void entry_selected(const unsigned entry)
Set the textbox to reflect the selected file.
Definition:
file_menu.cpp:141
statistics::levels
std::vector< std::pair< const std::string *, const stats * > > levels
Stats (and name) for each scenario. The pointers are never nullptr.
Definition:
statistics.hpp:115
path
GLsizei const char ** path
Definition:
glew.h:4654
gui::file_menu::strip_last_delim
std::string strip_last_delim(const std::string &path) const
Return the string with the last path delimiter removed, if one was there.
Definition:
file_menu.cpp:232
gui::file_menu::display_current_files
void display_current_files()
Show the files in the current directory.
Definition:
file_menu.cpp:72
gui::file_menu::is_directory
bool is_directory(const std::string &fname) const
Definition:
file_menu.cpp:163
gui::file_menu::get_path_up
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.
Definition:
file_menu.cpp:207
gui::file_menu::reset_type_a_head
void reset_type_a_head()
Definition:
file_menu.cpp:285
gui::file_menu::get_choice
std::string get_choice() const
Return the chosen file.
Definition:
file_menu.cpp:191
gui::file_menu::is_root
bool is_root(const std::string &path) const
Return true if the path is the root of the filesystem.
Definition:
file_menu.cpp:240
gui::file_menu::get_directory
std::string get_directory() const
Definition:
file_menu.hpp:40
gui::file_menu::type_a_head_
int type_a_head_
Definition:
file_menu.hpp:96
gui::file_menu::select_file
void select_file(const std::string &begin_of_filename)
Selects file (type-a-head search)
Definition:
file_menu.cpp:295
gui::file_menu::chosen_file_
std::string chosen_file_
Definition:
file_menu.hpp:93
gui::file_menu::current_dir_
std::string current_dir_
Definition:
file_menu.hpp:92
gui::file_menu::get_path
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.
Definition:
file_menu.cpp:196
gui::file_menu::update_file_lists
void update_file_lists()
Updated the locally maintained lists of files and directories in the current directory.
Definition:
file_menu.cpp:317
gui::file_menu::add_path
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.
Definition:
file_menu.cpp:244
gui::file_menu
A widget where the user may navigate through directories and choose a file.
Definition:
file_menu.hpp:25
event
cl_event event
Definition:
glew.h:3070
gui::menu
Definition:
menu.hpp:28
gui::file_menu::type_a_head
bool type_a_head() const
Definition:
file_menu.cpp:280
gui::file_menu::delete_chosen_file
int delete_chosen_file()
Definition:
file_menu.cpp:104
gui::file_menu::change_directory
void change_directory(const std::string &path)
Definition:
file_menu.cpp:169
string
GLsizei const GLcharARB ** string
Definition:
glew.h:4503
gui::file_menu::files_in_current_dir_
std::vector< std::string > files_in_current_dir_
Definition:
file_menu.hpp:94
Generated by
1.8.8