file_menu.hpp

Go to the documentation of this file.
00001 /* $Id: file_menu.hpp 23842 2008-02-16 08:47:16Z mordante $ */
00002 /*
00003    Copyright (C) 2003 - 2008 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 version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 #ifndef FILE_MENU_H_INCLUDED
00016 #define FILE_MENU_H_INCLUDED
00017 
00018 #include "../construct_dialog.hpp"
00019 
00020 namespace gui {
00021 
00022 
00023 /// A widget where the user may navigate through directories and choose
00024 /// a file.
00025 class file_menu : public menu {
00026 public:
00027     //Static members
00028     static const char path_delim;
00029 
00030     /// Initialize the file menu. start_file is the file that will be
00031     /// selected initially. The current directory will be
00032     /// the one the file is in.
00033     file_menu(CVideo &disp, std::string start_file="");
00034 
00035     /// Return the chosen file.
00036     std::string get_choice() const;
00037 
00038     int delete_chosen_file();
00039 
00040     std::string get_directory() const { return current_dir_; }
00041 
00042     /// Return path with to_add added, using a path delimiter between them.
00043     std::string add_path(const std::string path, const std::string to_add) const;
00044 
00045     /// Return the string with the last path delimiter removed, if one
00046     /// was there.
00047     std::string strip_last_delim(const std::string path) const;
00048 
00049     bool is_directory(const std::string& fname) const;
00050 
00051     void change_directory(const std::string path);
00052     bool make_directory(const std::string& subdir_name);
00053 
00054 protected:
00055     void handle_event(const SDL_Event& event);
00056 
00057 private:
00058     /// If file_or_dir is a file, return the directory the file is in,
00059     /// if it is a directory, return the directory name. If no path
00060     /// delimiters could be found, return the unchanged argument.
00061     std::string get_path(const std::string file_or_dir) const;
00062 
00063     /// Return the path that is the specified number of levels up from
00064     /// the path. If the movement could not proceed due to being at the
00065     /// root or having an invalid argument, return the path that the
00066     /// movement ended on.
00067     std::string get_path_up(const std::string path,
00068                             const unsigned levels=1) const;
00069 
00070 
00071     /// Return true if the path is the root of the filesystem.
00072     bool is_root(const std::string path) const;
00073 
00074     /// Show the files in the current directory.
00075     void display_current_files();
00076 
00077     /// Updated the locally maintained lists of files and directories in
00078     /// the current directory.
00079     void update_file_lists();
00080 
00081     /// Set the textbox to reflect the selected file.
00082     void entry_selected(const unsigned entry);
00083 
00084     std::string current_dir_;
00085     std::string chosen_file_;
00086     std::vector<std::string> files_in_current_dir_, dirs_in_current_dir_;
00087     int last_selection_;
00088 };
00089 
00090 } //end namespace gui
00091 
00092 #endif // FILE_MENU_H_INCLUDED

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs