GG
FileDlg.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /* GG is a GUI for SDL and OpenGL.
3  Copyright (C) 2003-2008 T. Zachary Laine
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public License
7  as published by the Free Software Foundation; either version 2.1
8  of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free
17  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18  02111-1307 USA
19 
20  If you do not wish to comply with the terms of the LGPL please
21  contact the author as other terms are available for a fee.
22 
23  Zach Laine
24  whatwasthataddress@gmail.com */
25 
28 #ifndef _GG_FileDlg_h_
29 #define _GG_FileDlg_h_
30 
31 #include <GG/DropDownList.h>
32 
33 #include <boost/filesystem/path.hpp>
34 
35 
36 namespace GG {
37 
38 class TextControl;
39 class Edit;
40 class Button;
41 class Font;
42 
55 class GG_API FileDlg : public Wnd
56 {
57 public:
59 
69  FileDlg(const std::string& directory, const std::string& filename, bool save, bool multi, const boost::shared_ptr<Font>& font,
70  Clr color, Clr border_color, Clr text_color = CLR_BLACK);
72 
74  std::set<std::string> Result() const;
75 
77  bool SelectDirectories() const;
78 
85  bool AppendMissingSaveExtension() const;
86 
87  const std::string& FilesString() const;
88  const std::string& FileTypesString() const;
89  const std::string& SaveString() const;
90  const std::string& OpenString() const;
91  const std::string& CancelString() const;
92 
93  const std::string& MalformedFilenameString() const;
94  const std::string& OverwritePromptString() const;
95  const std::string& InvalidFilenameString() const;
96  const std::string& FilenameIsADirectoryString() const;
97  const std::string& FileDoesNotExistString() const;
98  const std::string& DeviceIsNotReadyString() const;
99  const std::string& ThreeButtonDlgOKString() const;
100  const std::string& ThreeButtonDlgCancelString() const;
101 
102 
104  virtual void Render();
105  virtual void KeyPress(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys);
106 
109  void SelectDirectories(bool directories);
110 
117  void AppendMissingSaveExtension(bool append);
118 
130  void SetFileFilters(const std::vector<std::pair<std::string, std::string> >& filters);
131 
132  void SetFilesString(const std::string& str);
133  void SetFileTypesString(const std::string& str);
134  void SetSaveString(const std::string& str);
135  void SetOpenString(const std::string& str);
136  void SetCancelString(const std::string& str);
137 
138  void SetMalformedFilenameString(const std::string& str);
139  void SetOverwritePromptString(const std::string& str);
140  void SetInvalidFilenameString(const std::string& str);
141  void SetFilenameIsADirectoryString(const std::string& str);
142  void SetFileDoesNotExistString(const std::string& str);
143  void SetDeviceIsNotReadyString(const std::string& str);
144  void SetThreeButtonDlgOKString(const std::string& str);
145  void SetThreeButtonDlgCancelString(const std::string& str);
146 
147 
150  static const boost::filesystem::path& WorkingDirectory();
151 
153 
154  GG_ABSTRACT_EXCEPTION(Exception);
155 
157  GG_CONCRETE_EXCEPTION(BadInitialDirectory, GG::FileDlg, Exception);
159 
160 protected:
161  static const X DEFAULT_WIDTH;
162  static const Y DEFAULT_HEIGHT;
163 
165  FileDlg();
166 
167 
168 private:
169  void CreateChildren(const std::string& filename, bool multi);
170  void PlaceLabelsAndEdits(X button_width, Y button_height);
171  void AttachSignalChildren();
172  void DetachSignalChildren();
173  void Init(const std::string& directory);
174  void ConnectSignals();
175  void OkClicked();
176  void OkHandler(bool double_click);
177  void CancelClicked();
178  void FileSetChanged(const ListBox::SelectionSet& files);
179  void FileDoubleClicked(DropDownList::iterator it);
180  void FilesEditChanged(const std::string& str);
181  void FilterChanged(DropDownList::iterator it);
182  void SetWorkingDirectory(const boost::filesystem::path& p);
183  void PopulateFilters();
184  void UpdateList();
185  void UpdateDirectoryText();
186  void OpenDirectory();
187 
188  Clr m_color;
189  Clr m_border_color;
190  Clr m_text_color;
191  boost::shared_ptr<Font>
192  m_font;
193 
194  bool m_save;
195  std::vector<std::pair<std::string, std::string> >
196  m_file_filters;
197  std::set<std::string>
198  m_result;
199  bool m_select_directories;
200  bool m_append_missing_save_extension;
201  bool m_in_win32_drive_selection;
202 
203  std::string m_save_str;
204  std::string m_open_str;
205  std::string m_cancel_str;
206 
207  std::string m_malformed_filename_str;
208  std::string m_overwrite_prompt_str;
209  std::string m_invalid_filename_str;
210  std::string m_filename_is_a_directory_str;
211  std::string m_file_does_not_exist_str;
212  std::string m_device_is_not_ready_str;
213  std::string m_three_button_dlg_ok_str;
214  std::string m_three_button_dlg_cancel_str;
215 
216  TextControl* m_curr_dir_text;
217  ListBox* m_files_list;
218  Edit* m_files_edit;
219  DropDownList* m_filter_list;
220  Button* m_ok_button;
221  Button* m_cancel_button;
222  TextControl* m_files_label;
223  TextControl* m_file_types_label;
224 
225  static boost::filesystem::path s_working_dir;
226 };
227 
228 } // namespace GG
229 
230 #endif