The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
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.
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.
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 
94  std::vector<std::string> files_in_current_dir_, dirs_in_current_dir_;
97 };
98 
99 } //end namespace gui
100 
101 #endif // FILE_MENU_H_INCLUDED
static const char path_delim
Definition: file_menu.hpp:28
bool make_directory(const std::string &subdir_name)
Definition: file_menu.cpp:117
void handle_event(const SDL_Event &event)
Definition: file_menu.cpp:130
Definition: video.hpp:58
std::vector< std::string > dirs_in_current_dir_
Definition: file_menu.hpp:94
General purpose widgets.
file_menu(CVideo &disp, std::string start_file="")
Initialize the file menu.
Definition: file_menu.cpp:52
void entry_selected(const unsigned entry)
Set the textbox to reflect the selected file.
Definition: file_menu.cpp:141
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
GLsizei const char ** path
Definition: glew.h:4654
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
void display_current_files()
Show the files in the current directory.
Definition: file_menu.cpp:72
bool is_directory(const std::string &fname) const
Definition: file_menu.cpp:163
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
void reset_type_a_head()
Definition: file_menu.cpp:285
std::string get_choice() const
Return the chosen file.
Definition: file_menu.cpp:191
bool is_root(const std::string &path) const
Return true if the path is the root of the filesystem.
Definition: file_menu.cpp:240
std::string get_directory() const
Definition: file_menu.hpp:40
void select_file(const std::string &begin_of_filename)
Selects file (type-a-head search)
Definition: file_menu.cpp:295
std::string chosen_file_
Definition: file_menu.hpp:93
std::string current_dir_
Definition: file_menu.hpp:92
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
void update_file_lists()
Updated the locally maintained lists of files and directories in the current directory.
Definition: file_menu.cpp:317
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
A widget where the user may navigate through directories and choose a file.
Definition: file_menu.hpp:25
cl_event event
Definition: glew.h:3070
bool type_a_head() const
Definition: file_menu.cpp:280
int delete_chosen_file()
Definition: file_menu.cpp:104
void change_directory(const std::string &path)
Definition: file_menu.cpp:169
GLsizei const GLcharARB ** string
Definition: glew.h:4503
std::vector< std::string > files_in_current_dir_
Definition: file_menu.hpp:94