00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00029 #ifndef _GG_FileDlg_h_
00030 #define _GG_FileDlg_h_
00031
00032 #include <GG/ListBox.h>
00033
00034 #include <boost/filesystem/path.hpp>
00035
00036
00037 namespace GG {
00038
00039 class TextControl;
00040 class Edit;
00041 class DropDownList;
00042 class Button;
00043 class Font;
00044
00052 class GG_API FileDlg : public Wnd
00053 {
00054 public:
00056
00062 FileDlg(const std::string& directory, const std::string& filename, bool save, bool multi, const boost::shared_ptr<Font>& font,
00063 Clr color, Clr border_color, Clr text_color = CLR_BLACK);
00065
00067 std::set<std::string> Result() const;
00068
00070 bool SelectDirectories() const;
00071
00076 bool AppendMissingSaveExtension() const;
00077
00078 const std::string& FilesString() const;
00079 const std::string& FileTypesString() const;
00080 const std::string& SaveString() const;
00081 const std::string& OpenString() const;
00082 const std::string& CancelString() const;
00083
00084 const std::string& MalformedFilenameString() const;
00085 const std::string& OverwritePromptString() const;
00086 const std::string& InvalidFilenameString() const;
00087 const std::string& FilenameIsADirectoryString() const;
00088 const std::string& FileDoesNotExistString() const;
00089 const std::string& DeviceIsNotReadyString() const;
00090 const std::string& ThreeButtonDlgOKString() const;
00091 const std::string& ThreeButtonDlgCancelString() const;
00092
00093
00095 virtual void Render();
00096 virtual void KeyPress(Key key, Flags<ModKey> mod_keys);
00097
00100 void SelectDirectories(bool directories);
00101
00106 void AppendMissingSaveExtension(bool append);
00107
00115 void SetFileFilters(const std::vector<std::pair<std::string, std::string> >& filters);
00116
00117 void SetFilesString(const std::string& str);
00118 void SetFileTypesString(const std::string& str);
00119 void SetSaveString(const std::string& str);
00120 void SetOpenString(const std::string& str);
00121 void SetCancelString(const std::string& str);
00122
00123 void SetMalformedFilenameString(const std::string& str);
00124 void SetOverwritePromptString(const std::string& str);
00125 void SetInvalidFilenameString(const std::string& str);
00126 void SetFilenameIsADirectoryString(const std::string& str);
00127 void SetFileDoesNotExistString(const std::string& str);
00128 void SetDeviceIsNotReadyString(const std::string& str);
00129 void SetThreeButtonDlgOKString(const std::string& str);
00130 void SetThreeButtonDlgCancelString(const std::string& str);
00131
00132
00134 static const boost::filesystem::path& WorkingDirectory();
00135
00137
00138 GG_ABSTRACT_EXCEPTION(Exception);
00139
00141 GG_CONCRETE_EXCEPTION(BadInitialDirectory, GG::FileDlg, Exception);
00143
00144 protected:
00145 enum {WIDTH = 400, HEIGHT = 350};
00146
00148 FileDlg();
00149
00150
00151 private:
00152 void CreateChildren(const std::string& filename, bool multi);
00153 void PlaceLabelsAndEdits(int button_width, int button_height);
00154 void AttachSignalChildren();
00155 void DetachSignalChildren();
00156 void Init(const std::string& directory);
00157 void ConnectSignals();
00158 void OkClicked();
00159 void OkHandler(bool double_click);
00160 void CancelClicked();
00161 void FileSetChanged(const std::set<int>& files);
00162 void FileDoubleClicked(int n, ListBox::Row* row);
00163 void FilesEditChanged(const std::string& str);
00164 void FilterChanged(int idx);
00165 void SetWorkingDirectory(const boost::filesystem::path& p);
00166 void PopulateFilters();
00167 void UpdateList();
00168 void UpdateDirectoryText();
00169 void OpenDirectory();
00170
00171 Clr m_color;
00172 Clr m_border_color;
00173 Clr m_text_color;
00174 boost::shared_ptr<Font>
00175 m_font;
00176
00177 bool m_save;
00178 std::vector<std::pair<std::string, std::string> >
00179 m_file_filters;
00180 std::set<std::string>
00181 m_result;
00182 bool m_select_directories;
00183 bool m_append_missing_save_extension;
00184 bool m_in_win32_drive_selection;
00185
00186 std::string m_save_str;
00187 std::string m_open_str;
00188 std::string m_cancel_str;
00189
00190 std::string m_malformed_filename_str;
00191 std::string m_overwrite_prompt_str;
00192 std::string m_invalid_filename_str;
00193 std::string m_filename_is_a_directory_str;
00194 std::string m_file_does_not_exist_str;
00195 std::string m_device_is_not_ready_str;
00196 std::string m_three_button_dlg_ok_str;
00197 std::string m_three_button_dlg_cancel_str;
00198
00199 TextControl* m_curr_dir_text;
00200 ListBox* m_files_list;
00201 Edit* m_files_edit;
00202 DropDownList* m_filter_list;
00203 Button* m_ok_button;
00204 Button* m_cancel_button;
00205 TextControl* m_files_label;
00206 TextControl* m_file_types_label;
00207
00208 static boost::filesystem::path s_working_dir;
00209
00210 friend class boost::serialization::access;
00211 template <class Archive>
00212 void serialize(Archive& ar, const unsigned int version);
00213 };
00214
00215 }
00216
00217 BOOST_CLASS_VERSION(GG::FileDlg, 1)
00218
00219
00220 template <class Archive>
00221 void GG::FileDlg::serialize(Archive& ar, const unsigned int version)
00222 {
00223 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Wnd)
00224 & BOOST_SERIALIZATION_NVP(m_color)
00225 & BOOST_SERIALIZATION_NVP(m_border_color)
00226 & BOOST_SERIALIZATION_NVP(m_text_color)
00227 & BOOST_SERIALIZATION_NVP(m_font)
00228 & BOOST_SERIALIZATION_NVP(m_save)
00229 & BOOST_SERIALIZATION_NVP(m_file_filters)
00230 & BOOST_SERIALIZATION_NVP(m_result)
00231 & BOOST_SERIALIZATION_NVP(m_save_str)
00232 & BOOST_SERIALIZATION_NVP(m_open_str)
00233 & BOOST_SERIALIZATION_NVP(m_cancel_str)
00234 & BOOST_SERIALIZATION_NVP(m_malformed_filename_str)
00235 & BOOST_SERIALIZATION_NVP(m_overwrite_prompt_str)
00236 & BOOST_SERIALIZATION_NVP(m_invalid_filename_str)
00237 & BOOST_SERIALIZATION_NVP(m_filename_is_a_directory_str)
00238 & BOOST_SERIALIZATION_NVP(m_file_does_not_exist_str)
00239 & BOOST_SERIALIZATION_NVP(m_device_is_not_ready_str)
00240 & BOOST_SERIALIZATION_NVP(m_three_button_dlg_ok_str)
00241 & BOOST_SERIALIZATION_NVP(m_three_button_dlg_cancel_str)
00242 & BOOST_SERIALIZATION_NVP(m_curr_dir_text)
00243 & BOOST_SERIALIZATION_NVP(m_files_list)
00244 & BOOST_SERIALIZATION_NVP(m_files_edit)
00245 & BOOST_SERIALIZATION_NVP(m_filter_list)
00246 & BOOST_SERIALIZATION_NVP(m_ok_button)
00247 & BOOST_SERIALIZATION_NVP(m_cancel_button)
00248 & BOOST_SERIALIZATION_NVP(m_files_label)
00249 & BOOST_SERIALIZATION_NVP(m_file_types_label);
00250
00251 if (1 <= version) {
00252 ar & BOOST_SERIALIZATION_NVP(m_select_directories)
00253 & BOOST_SERIALIZATION_NVP(m_append_missing_save_extension);
00254 }
00255
00256 if (Archive::is_loading::value)
00257 ConnectSignals();
00258 }
00259
00260 #endif // _GG_FileDlg_h_