PCL
FileDialog.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/FileDialog.h - Released 2024-06-18T15:48:54Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_FileDialog_h
53 #define __PCL_FileDialog_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/AutoPointer.h>
60 #include <pcl/File.h>
61 #include <pcl/StringList.h>
62 
63 namespace pcl
64 {
65 
66 // ----------------------------------------------------------------------------
67 
68 class FileDialogPrivate;
69 class OpenFileDialogPrivate;
70 class SaveFileDialogPrivate;
71 class GetDirectoryDialogPrivate;
72 
73 // ----------------------------------------------------------------------------
74 
85 class PCL_CLASS FileFilter
86 {
87 public:
88 
92  FileFilter() = default;
93 
98  FileFilter( const String& description, const StringList extensions )
99  {
100  SetDescription( description );
101  AddExtensions( extensions );
102  }
103 
108  FileFilter( const String& description, const String& extension )
109  {
110  SetDescription( description );
111  AddExtension( extension );
112  }
113 
117  FileFilter( const FileFilter& x ) = default;
118 
122  virtual ~FileFilter()
123  {
124  }
125 
131  {
132  return m_description;
133  }
134 
139  void SetDescription( const String& description )
140  {
141  m_description = description.Trimmed();
142  }
143 
148  const StringList& Extensions() const
149  {
150  return m_extensions;
151  }
152 
157  void AddExtension( const String& extension );
158 
162  void AddExtensions( const StringList& extensions )
163  {
164  for ( const String& extension : extensions )
165  AddExtension( extension );
166  }
167 
171  void Clear();
172 
173 private:
174 
175  String m_description;
176  StringList m_extensions;
177 
178  String MakeAPIFilter() const;
179 
180  friend class FileDialogPrivate;
181 };
182 
183 // ----------------------------------------------------------------------------
184 
193 class PCL_CLASS FileDialog
194 {
195 public:
196 
202 
207 
211  virtual ~FileDialog();
212 
216  String Caption() const;
217 
223  void SetCaption( const String& caption );
224 
233 
238  void SetInitialPath( const String& path );
239 
244  const filter_list& Filters() const;
245 
249  void SetFilters( const filter_list& filters );
250 
254  void SetFilter( const FileFilter& filter )
255  {
256  SetFilters( filter_list() << filter );
257  }
258 
263  void AddFilters( const filter_list& filters );
264 
268  void AddFilter( const FileFilter& filter )
269  {
270  AddFilters( filter_list() << filter );
271  }
272 
282 
291 
297 
304  virtual bool Execute() = 0;
305 
306 protected:
307 
309 };
310 
311 // ----------------------------------------------------------------------------
312 
321 class PCL_CLASS OpenFileDialog : public FileDialog
322 {
323 public:
324 
329 
333  ~OpenFileDialog() override;
334 
350 
361 
367  void EnableMultipleSelections( bool enable = true );
368 
377  void DisableMultipleSelections( bool disable = true )
378  {
379  EnableMultipleSelections( !disable );
380  }
381 
384  bool Execute() override;
385 
394  const StringList& FileNames() const;
395 
403  String FileName() const;
404 
405 private:
406 
408 };
409 
410 // ----------------------------------------------------------------------------
411 
420 class PCL_CLASS SaveFileDialog : public FileDialog
421 {
422 public:
423 
428 
432  ~SaveFileDialog() override;
433 
445 
455 
461  void EnableOverwritePrompt( bool enable = true );
462 
471  void DisableOverwritePrompt( bool disable = true )
472  {
473  EnableOverwritePrompt( !disable );
474  }
475 
478  bool Execute() override;
479 
483  String FileName() const;
484 
485 private:
486 
488 };
489 
490 // ----------------------------------------------------------------------------
491 
500 class PCL_CLASS GetDirectoryDialog : public FileDialog
501 {
502 public:
503 
508 
513 
516  bool Execute() override;
517 
521  String Directory() const;
522 
523 private:
524 
526 };
527 
528 // ----------------------------------------------------------------------------
529 
530 } // pcl
531 
532 #endif // __PCL_FileDialog_h
533 
534 // ----------------------------------------------------------------------------
535 // EOF pcl/FileDialog.h - Released 2024-06-18T15:48:54Z
Abstract base class of PCL file dialogs.
Definition: FileDialog.h:194
const filter_list & Filters() const
String InitialPath() const
virtual bool Execute()=0
void SetFilters(const filter_list &filters)
void SetCaption(const String &caption)
void AddFilters(const filter_list &filters)
String Caption() const
void AddFilter(const FileFilter &filter)
Definition: FileDialog.h:268
String SelectedFileExtension() const
void SetSelectedFileExtension(const String &)
void SetInitialPath(const String &path)
void SetFilter(const FileFilter &filter)
Definition: FileDialog.h:254
filter_list & Filters()
virtual ~FileDialog()
A description of a file type and its associated file extensions.
Definition: FileDialog.h:86
virtual ~FileFilter()
Definition: FileDialog.h:122
FileFilter()=default
String Description() const
Definition: FileDialog.h:130
void AddExtension(const String &extension)
const StringList & Extensions() const
Definition: FileDialog.h:148
FileFilter(const String &description, const String &extension)
Definition: FileDialog.h:108
void SetDescription(const String &description)
Definition: FileDialog.h:139
FileFilter(const FileFilter &x)=default
void AddExtensions(const StringList &extensions)
Definition: FileDialog.h:162
FileFilter(const String &description, const StringList extensions)
Definition: FileDialog.h:98
A modal dialog box to select an existing directory.
Definition: FileDialog.h:501
~GetDirectoryDialog() override
bool Execute() override
String Directory() const
A modal dialog box to select one or more existing files.
Definition: FileDialog.h:322
~OpenFileDialog() override
bool AllowsMultipleSelections() const
const StringList & FileNames() const
void EnableMultipleSelections(bool enable=true)
void DisableMultipleSelections(bool disable=true)
Definition: FileDialog.h:377
String FileName() const
bool Execute() override
A modal dialog box to select a single file name for output.
Definition: FileDialog.h:421
void EnableOverwritePrompt(bool enable=true)
bool IsOverwritePromptEnabled() const
void DisableOverwritePrompt(bool disable=true)
Definition: FileDialog.h:471
String FileName() const
bool Execute() override
~SaveFileDialog() override
Unicode (UTF-16) string.
Definition: String.h:8113
PCL root namespace.
Definition: AbstractImage.h:77