00001 /* $Id: file_menu.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */ 00002 /* 00003 Copyright (C) 2003 - 2012 by David White <dave@whitevine.net> 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 #ifndef FILE_MENU_H_INCLUDED 00017 #define FILE_MENU_H_INCLUDED 00018 00019 #include "../construct_dialog.hpp" 00020 00021 namespace gui { 00022 00023 00024 /// A widget where the user may navigate through directories and choose 00025 /// a file. 00026 class file_menu : public menu { 00027 public: 00028 //Static members 00029 static const char path_delim; 00030 00031 /// Initialize the file menu. start_file is the file that will be 00032 /// selected initially. The current directory will be 00033 /// the one the file is in. 00034 file_menu(CVideo &disp, std::string start_file=""); 00035 00036 /// Return the chosen file. 00037 std::string get_choice() const; 00038 00039 int delete_chosen_file(); 00040 00041 std::string get_directory() const { return current_dir_; } 00042 00043 /// Return path with to_add added, using a path delimiter between them. 00044 std::string add_path(const std::string& path, const std::string& to_add) const; 00045 00046 /// Return the string with the last path delimiter removed, if one 00047 /// was there. 00048 std::string strip_last_delim(const std::string& path) const; 00049 00050 bool is_directory(const std::string& fname) const; 00051 00052 void change_directory(const std::string& path); 00053 bool make_directory(const std::string& subdir_name); 00054 00055 /** 00056 * Selects file (type-a-head search) 00057 **/ 00058 void select_file(const std::string& begin_of_filename); 00059 00060 bool type_a_head() const; 00061 void reset_type_a_head(); 00062 00063 protected: 00064 void handle_event(const SDL_Event& event); 00065 00066 private: 00067 /// If file_or_dir is a file, return the directory the file is in, 00068 /// if it is a directory, return the directory name. If no path 00069 /// delimiters could be found, return the unchanged argument. 00070 std::string get_path(const std::string& file_or_dir) const; 00071 00072 /// Return the path that is the specified number of levels up from 00073 /// the path. If the movement could not proceed due to being at the 00074 /// root or having an invalid argument, return the path that the 00075 /// movement ended on. 00076 std::string get_path_up(const std::string& path, 00077 const unsigned levels=1) const; 00078 00079 00080 /// Return true if the path is the root of the filesystem. 00081 bool is_root(const std::string& path) const; 00082 00083 /// Show the files in the current directory. 00084 void display_current_files(); 00085 00086 /// Updated the locally maintained lists of files and directories in 00087 /// the current directory. 00088 void update_file_lists(); 00089 00090 /// Set the textbox to reflect the selected file. 00091 void entry_selected(const unsigned entry); 00092 00093 std::string current_dir_; 00094 std::string chosen_file_; 00095 std::vector<std::string> files_in_current_dir_, dirs_in_current_dir_; 00096 int last_selection_; 00097 int type_a_head_; 00098 }; 00099 00100 } //end namespace gui 00101 00102 #endif // FILE_MENU_H_INCLUDED
| Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:58 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |