xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
file_dialog.h
Go to the documentation of this file.
1 #pragma once
5 #include "common_dialog.h"
6 #include <vector>
7 #include <xtd/forms/open_file_name_flags.h>
8 
10 namespace xtd {
12  namespace forms {
14  class open_file_dialog;
15  class save_file_dialog;
17 
42  public:
44  file_dialog() = default;
45 
48  virtual bool add_extension() const {return get_option(OFN_ADDEXTENSION);}
52  virtual file_dialog& add_extension(bool value) {
53  set_option(OFN_ADDEXTENSION, value);
54  return *this;
55  }
56 
61  virtual bool auto_upgrade_enabled() const {return auto_upgrade_enabled_;}
67  virtual file_dialog& auto_upgrade_enabled(bool value) {
68  auto_upgrade_enabled_ = value;
69  return *this;
70  }
71 
75  virtual bool check_file_exists() const {return get_option(OFN_FILEMUSTEXIST);}
80  virtual file_dialog& check_file_exists(bool value) {
81  set_option(OFN_FILEMUSTEXIST, value);
82  return *this;
83  }
84 
87  virtual bool check_path_exists() const {return get_option(OFN_PATHMUSTEXIST);}
91  virtual file_dialog& check_path_exists(bool value) {
92  set_option(OFN_PATHMUSTEXIST, value);
93  return *this;
94  }
95 
99  virtual const xtd::ustring& default_ext() const {return default_ext_;}
104  virtual file_dialog& default_ext(const xtd::ustring& value) {
105  default_ext_ = value;
106  return *this;
107  }
108 
111  virtual bool dereference_link() const {return !get_option(OFN_NODEREFERENCELINKS);}
115  virtual file_dialog& dereference_link(bool value) {
116  set_option(OFN_NODEREFERENCELINKS, !value);
117  return *this;
118  }
119 
125  virtual const xtd::ustring& file_name() const {return file_name_;}
132  virtual file_dialog& file_name(const xtd::ustring& value) {
133  file_name_ = value;
134  return *this;
135  }
136 
140  virtual const std::vector<xtd::ustring> file_names() const {return file_names_;}
141 
150  virtual const xtd::ustring& filter() const {return filter_;}
160  virtual file_dialog& filter(const xtd::ustring& value) {
161  filter_ = value;
162  return *this;
163  }
164 
169  virtual size_t filter_index() const {return filter_index_;}
175  virtual file_dialog& filter_index(size_t value) {
176  filter_index_ = value;
177  return *this;
178  }
179 
187  virtual const xtd::ustring& initial_directory() const {return initial_directory_;}
196  virtual file_dialog& initial_directory(const xtd::ustring& value) {
197  initial_directory_ = value;
198  return *this;
199  }
200 
204  size_t options() const {return options_;}
205 
208  virtual bool restore_directory() const {return get_option(OFN_NOCHANGEDIR);}
212  virtual file_dialog& restore_directory(bool value) {
213  set_option(OFN_NOCHANGEDIR, value);
214  return *this;
215  }
216 
220  virtual bool show_help() const {return !get_option(OFN_SHOWHELP);}
225  virtual file_dialog& show_help(bool value) {
226  set_option(OFN_SHOWHELP, value);
227  return *this;
228  }
229 
232  virtual bool show_hidden_files() const {return !get_option(OFN_FORCESHOWHIDDEN);}
236  virtual file_dialog& show_hidden_files(bool value) {
237  set_option(OFN_FORCESHOWHIDDEN, value);
238  return *this;
239  }
240 
243  virtual bool show_preview() const {return !get_option(OFN_SHOWPREVIEW);}
247  virtual file_dialog& show_preview(bool value) {
248  set_option(OFN_SHOWPREVIEW, value);
249  return *this;
250  }
251 
256  virtual bool support_multi_dotted_extensions() const {return support_multi_dotted_extensions_;}
263  support_multi_dotted_extensions_ = value;
264  return *this;
265  }
266 
270  virtual const xtd::ustring& title() const {return title_;}
275  virtual file_dialog& title(const xtd::ustring& value) {
276  title_ = value;
277  return *this;
278  }
279 
283  virtual bool validate_names() const {return !get_option(OFN_NOVALIDATE);}
288  virtual file_dialog& validate_names(bool value) {
289  set_option(OFN_NOVALIDATE, !value);
290  return *this;
291  }
292 
295  void reset() override;
296 
299  xtd::ustring to_string() const noexcept override {
300  return ustring::format("{}: title: {}, filename: {}", ustring::full_class_name(*this), title_, file_name_);
301  }
302 
304  friend std::ostream& operator<<(std::ostream& os, const xtd::forms::file_dialog& dialog) noexcept {
305  return os << dialog.to_string();
306  }
308 
309  protected:
314  bool run_dialog(intptr_t hwnd_owner) override;
317  void run_sheet(intptr_t hwnd_owner) override;
318 
320  bool get_option(size_t flag) const {return (options_ & flag) == flag;}
321  void set_option(size_t flag, bool value) {options_ = value ? options_ | flag : options_ & ~flag;}
322 
323  bool auto_upgrade_enabled_ = true;
324  xtd::ustring default_ext_ = "";
325  xtd::ustring file_name_ = "";
326  std::vector<xtd::ustring> file_names_;
327  xtd::ustring filter_ = "";
328  size_t filter_index_ = 1;
329  xtd::ustring initial_directory_ = "";
330  size_t options_ = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_ADDEXTENSION;
331  bool support_multi_dotted_extensions_ = true;
332  xtd::ustring title_ = "";
334 
335  private:
336  friend class open_file_dialog;
337  friend class save_file_dialog;
338  virtual bool run_file_dialog(intptr_t hwnd_owner) = 0;
339  virtual void run_file_sheet(intptr_t hwnd_owner) = 0;
340  };
341  }
342 }
Specifies the base class used for displaying dialog boxes on the screen.
Definition: common_dialog.h:31
Displays a dialog box from which the user can select a file.
Definition: file_dialog.h:41
virtual bool dereference_link() const
Gets a value indicating whether the dialog box returns the location of the file referenced by the sho...
Definition: file_dialog.h:111
virtual size_t filter_index() const
Gets the index of the filter currently selected in the file dialog box.
Definition: file_dialog.h:169
virtual file_dialog & support_multi_dotted_extensions(bool value)
Sets whether the dialog box supports displaying and saving files that have multiple file name extensi...
Definition: file_dialog.h:262
virtual bool check_path_exists() const
Gets a value indicating whether the dialog box displays a warning if the user specifies a path that d...
Definition: file_dialog.h:87
file_dialog()=default
Initializes a new instance of the common_dialog class.
virtual bool validate_names() const
Gets a value indicating whether the dialog box accepts only valid file names.
Definition: file_dialog.h:283
size_t options() const
Gets values to initialize the file_dialog.
Definition: file_dialog.h:204
virtual file_dialog & show_help(bool value)
Sets a value indicating whether the Help button is displayed in the file dialog box.
Definition: file_dialog.h:225
virtual file_dialog & filter(const xtd::ustring &value)
Sets the current file name filter string, which determines the choices that appear in the "Save as fi...
Definition: file_dialog.h:160
void run_sheet(intptr_t hwnd_owner) override
Runs file dialog box in sheet mode.
virtual file_dialog & dereference_link(bool value)
Sets a value indicating whether the dialog box returns the location of the file referenced by the sho...
Definition: file_dialog.h:115
virtual file_dialog & show_preview(bool value)
Sets a value indicating whether preview file is displayed in the file dialog box.
Definition: file_dialog.h:247
virtual bool show_help() const
Gets a value indicating whether the Help button is displayed in the file dialog box.
Definition: file_dialog.h:220
virtual bool show_hidden_files() const
Gets a value indicating whether hidden files are displayed in the file dialog box.
Definition: file_dialog.h:232
virtual file_dialog & title(const xtd::ustring &value)
Sets the file dialog box title.
Definition: file_dialog.h:275
virtual bool show_preview() const
Gets a value indicating whether preview file is displayed in the file dialog box.
Definition: file_dialog.h:243
virtual file_dialog & restore_directory(bool value)
Sets a value indicating whether the dialog box restores the directory to the previously selected dire...
Definition: file_dialog.h:212
virtual bool support_multi_dotted_extensions() const
Gets whether the dialog box supports displaying and saving files that have multiple file name extensi...
Definition: file_dialog.h:256
virtual file_dialog & default_ext(const xtd::ustring &value)
Sets the default file name extension.
Definition: file_dialog.h:104
virtual file_dialog & file_name(const xtd::ustring &value)
Sets a string containing the file name selected in the file dialog box.
Definition: file_dialog.h:132
virtual file_dialog & check_file_exists(bool value)
Sets a value indicating whether the dialog box displays a warning if the user specifies a file name t...
Definition: file_dialog.h:80
xtd::ustring to_string() const noexcept override
Provides a string version of this object.
Definition: file_dialog.h:299
virtual bool auto_upgrade_enabled() const
Gets a value indicating whether this file_dialog instance should automatically upgrade appearance and...
Definition: file_dialog.h:61
virtual bool restore_directory() const
Gets a value indicating whether the dialog box restores the directory to the previously selected dire...
Definition: file_dialog.h:208
virtual const xtd::ustring & file_name() const
Gets a string containing the file name selected in the file dialog box.
Definition: file_dialog.h:125
virtual file_dialog & initial_directory(const xtd::ustring &value)
Sets the initial directory displayed by the file dialog box.
Definition: file_dialog.h:196
virtual file_dialog & show_hidden_files(bool value)
Sets a value indicating whether hidden files are displayed in the file dialog box.
Definition: file_dialog.h:236
virtual const xtd::ustring & initial_directory() const
Gets the initial directory displayed by the file dialog box.
Definition: file_dialog.h:187
virtual const xtd::ustring & filter() const
Gets the current file name filter string, which determines the choices that appear in the "Save as fi...
Definition: file_dialog.h:150
virtual const std::vector< xtd::ustring > file_names() const
Gets the file names of all selected files in the dialog box.
Definition: file_dialog.h:140
bool run_dialog(intptr_t hwnd_owner) override
Runs file dialog box.
virtual file_dialog & check_path_exists(bool value)
Sets a value indicating whether the dialog box displays a warning if the user specifies a path that d...
Definition: file_dialog.h:91
virtual file_dialog & auto_upgrade_enabled(bool value)
Sets a value indicating whether this file_dialog instance should automatically upgrade appearance and...
Definition: file_dialog.h:67
virtual const xtd::ustring & default_ext() const
Gets the default file name extension.
Definition: file_dialog.h:99
virtual file_dialog & filter_index(size_t value)
Sets the index of the filter currently selected in the file dialog box.
Definition: file_dialog.h:175
virtual file_dialog & add_extension(bool value)
Sets a value indicating whether the dialog box automatically adds an extension to a file name if the ...
Definition: file_dialog.h:52
virtual bool check_file_exists() const
Gets a value indicating whether the dialog box displays a warning if the user specifies a file name t...
Definition: file_dialog.h:75
virtual file_dialog & validate_names(bool value)
Gets a value indicating whether the dialog box accepts only valid file names.
Definition: file_dialog.h:288
virtual bool add_extension() const
Gets a value indicating whether the dialog box automatically adds an extension to a file name if the ...
Definition: file_dialog.h:48
void reset() override
Resets all properties to their default values.
virtual const xtd::ustring & title() const
Gets the file dialog box title.
Definition: file_dialog.h:270
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
static ustring full_class_name()
Gets the fully qualified class name of the objec_t, including the namespace of the objec_t.
Definition: ustring.h:427
Contains xtd::forms::common_dialog class.
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:689
#define forms_export_
Define shared library export.
Definition: forms_export.h:13
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17