NCBI C++ ToolKit
ui_file_load_manager.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_CORE___UI_FILE_LOAD_MANAGER__HPP
2 #define GUI_CORE___UI_FILE_LOAD_MANAGER__HPP
3 
4 /* $Id: ui_file_load_manager.hpp 47479 2023-05-02 13:24:02Z ucko $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Andrey Yazhuk
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbistl.hpp>
36 #include <corelib/ncbiobj.hpp>
37 
38 #include <gui/gui_export.h>
39 
40 #include <util/format_guess.hpp>
41 
43 
46 
47 #include <gui/utils/mru_list.hpp>
50 
51 #include <wx/panel.h>
52 
54 
56 
59 class COpenDlg;
60 
61 ///////////////////////////////////////////////////////////////////////////////
62 /// IFileFormatLoaderManager
63 ///
64 /// IFileFormatLoaderManager extends IUIToolManager interface.
65 /// The interface represents a specialized Loader Manager that loads files in a
66 /// particular format.
68  public IUIToolManager
69 {
70 public:
71  // return file loader id string to be used in MRU file list instead of label.
72  virtual string GetFileLoaderId() const = 0;
73 
74  /// return file wildcard for the format (example - "*.txt;*.tab" )
75  virtual wxString GetFormatWildcard() = 0;
76 
77  /// checks given filenames and returns true if the manager can handle them,
78  /// otherwise - shows an error message
79  virtual bool ValidateFilenames(const vector<wxString>& filenames) = 0;
80 
81  /// initilize the manager with the given filenames
82  virtual void SetFilenames(const vector<wxString>& filenames) = 0;
83  /// get actual filenames that will be opened
84  virtual void GetFilenames(vector<wxString>& filenames) const = 0;
85 
86  /// return true if the current state of the loader UI is the first valid
87  /// state (first step in a wizard-like sequence)
88  virtual bool IsInitialState() = 0;
89 
90  /// return true if the given file format is supported by this manager
91  virtual bool RecognizeFormat(const wxString& filename) = 0;
92 
93  /// return true if the given file format is supported by this manager
94  virtual bool RecognizeFormat(CFormatGuess::EFormat fmt) = 0;
95 
96  /// returns true if loader can handle only one file
97  virtual bool SingleFileLoader() const { return false; }
98 
99  /// returns true if loader's format can be guessed
100  virtual bool CanGuessFormat() const { return true; }
101 
102 };
103 
104 
105 ///////////////////////////////////////////////////////////////////////////////
106 /// Extension Point ID for IFileFormatLoaderManager objects
107 ///
108 /// Components that need to add support for new File Formats to the application
109 /// should provide Extensions for this Extension Point. The Extensions shall
110 /// implement IFileFormatLoaderManager interface.
111 #define EXT_POINT__FILE_FORMAT_LOADER_MANAGER "file_format_loader_manager"
112 
113 
114 ///////////////////////////////////////////////////////////////////////////////
115 /// CFileLoadManager
116 /// CFileLoadManager - a Loader Manager implementing "File" option in "Open" dialog.
117 /// CFileLoadManager combines IFileFormatLoaderManager for different file formats
118 /// and acts as a Facade for them.
120  public CObject,
121  public IUIToolManager,
122  public IToolWizard,
123  public IRegSettings
124 {
125 public:
127  {
128  public:
129  CFileDescriptor(const wxString& fileName,
130  const wxString& fileLoaderLabel,
131  const string& fileLoaderId)
132  : m_FileName(fileName),
133  m_FileLoaderLabel(fileLoaderLabel),
134  m_FileLoaderId(fileLoaderId) {}
135 
136  bool operator==(const CFileDescriptor& fd)
137  {
138  return ((m_FileName == fd.m_FileName) &&
139  (m_FileLoaderId == fd.m_FileLoaderId));
140  }
141 
142  wxString GetFileName() const { return m_FileName; }
143  wxString GetFileLoaderLabel() const { return m_FileLoaderLabel; }
144  string GetFileLoaderId() const { return m_FileLoaderId; }
145  private:
146  wxString m_FileName;
149  };
150 
152 
154 
155  void LoadRegisteredManagers();
156 
157  void SetDialog(COpenDlg* dlg);
158 
159  /// @name IUIToolManager interface implementation
160  /// @{
161  virtual void SetServiceLocator(IServiceLocator* srv_locator);
162  virtual void SetParentWindow(wxWindow* parent);
163  virtual const IUIObject& GetDescriptor() const;
164  virtual void InitUI();
165  virtual void CleanUI();
166  virtual wxPanel* GetCurrentPanel();
167  virtual bool CanDo(EAction action);
168  virtual bool IsFinalState();
169  virtual bool IsCompletedState();
170  virtual bool DoTransition(EAction action);
171  virtual IAppTask* GetTask();
172  virtual IExecuteUnit* GetExecuteUnit();
173  virtual IWizardPage* GetFirstPage();
174  virtual void SetPrevPage(IWizardPage* prevPage);
175  virtual IUIToolManager* GetAlternateToolManager() { return m_AltToolManager; }
176  virtual void ResetState();
177  /// @}
178 
179  /// @name IToolWizard interface implementation
180  /// @{
181  virtual string GetLabel() const { return GetDescriptor().GetLabel(); }
182  /// @}
183 
184  /// @name IRegSettings interface implementation
185  /// @{
186  virtual void SetRegistryPath(const string& path);
187  virtual void LoadSettings();
188  virtual void SaveSettings() const;
189  /// @}
190 
191  virtual void AddFileFormat(IFileFormatLoaderManager* manager);
192  virtual void SetFilenames(vector<wxString>& filenames);
193  vector<wxString> GetFilenames() const { return m_Filenames; }
194 
195  virtual void OnFormatChanged();
196 
197 protected:
198  enum EState {
199  eInvalid = -1,
201  eFormatDefined, // the actual state is defined by the current format manager
203  eCompleted
204  };
205 
207 
208  using TProjectId = objects::CGBProjectHandle::TId;
209 
210  void x_AutoGuessFormat();
211 
212  TProjectId x_CreateNewProject(const string &new_prj_name);
213 
214  CFileLoadOptionPanel* x_GetOptionsPanel();
215  void x_UpdateWizardPages();
216  bool x_CanLeavePage(bool forward);
217 
218  bool x_CheckFormatConflict(const vector<wxString>& filenames, TFormatMgrRef& manager);
219 
220 
221 protected:
222  class CFilePage : public CWizardPage
223  {
224  public:
225  CFilePage(CFileLoadManager& manager) : m_Manager(manager) {}
226  virtual wxPanel* GetPanel();
227  virtual bool CanLeavePage(bool forward) { return m_Manager.x_CanLeavePage(forward); }
228  private:
230  };
231 
232 
236  wxWindow* m_ParentWindow;
238 
239  string m_RegPath;
240 
242 
243  vector<TFormatMgrRef> m_FormatManagers;
246 
247  /// If a file type is better handled by a different tool manager, set it here
249 
250  vector<wxString> m_Filenames;
251 
254 
256 
258 
261 };
262 
263 
265 
266 
267 #endif // GUI_CORE___UI_FILE_LOAD_MANAGER__HPP
268 
User-defined methods of the data storage class.
CFileDescriptor(const wxString &fileName, const wxString &fileLoaderLabel, const string &fileLoaderId)
bool operator==(const CFileDescriptor &fd)
CFilePage(CFileLoadManager &manager)
virtual bool CanLeavePage(bool forward)
CFileLoadManager CFileLoadManager - a Loader Manager implementing "File" option in "Open" dialog.
CProjectSelectorPanel * m_ProjectSelPanel
IUIToolManager * m_AltToolManager
If a file type is better handled by a different tool manager, set it here.
virtual string GetLabel() const
objects::CGBProjectHandle::TId TProjectId
TFormatMgrRef m_AutodetectFormat
vector< TFormatMgrRef > m_FormatManagers
SProjectSelectorParams m_ProjectParams
vector< wxString > m_Filenames
IWizardPage * m_OpenObjectsPage
IServiceLocator * m_SrvLocator
CIRef< IFileFormatLoaderManager > TFormatMgrRef
CFileLoadOptionPanel * m_OptionPanel
virtual IUIToolManager * GetAlternateToolManager()
If a transition fails, it may make sense to switch to a different tool manger When a tool manager ide...
vector< wxString > GetFilenames() const
CTimeMRUList< CFileDescriptor > TMRUPathList
EFormat
The formats are checked in the same order as declared here.
CObject –.
Definition: ncbiobj.hpp:180
COpenDlg.
Definition: open_dlg.hpp:78
CProjectLoadOptionPanel CProjectLoadOptionPanel - dialog panel for loading Projects and Workspaces.
CProjectSelectorPanel - a panel that allows the user to specify how the project items created by a pl...
CUIObject - default mix-in implementation of IUIObject.
Definition: ui_object.hpp:81
IAppTask.
Definition: app_task.hpp:83
IFileFormatLoaderManager.
virtual void GetFilenames(vector< wxString > &filenames) const =0
get actual filenames that will be opened
virtual bool IsInitialState()=0
return true if the current state of the loader UI is the first valid state (first step in a wizard-li...
virtual void SetFilenames(const vector< wxString > &filenames)=0
initilize the manager with the given filenames
virtual bool RecognizeFormat(const wxString &filename)=0
return true if the given file format is supported by this manager
virtual bool SingleFileLoader() const
returns true if loader can handle only one file
virtual bool RecognizeFormat(CFormatGuess::EFormat fmt)=0
return true if the given file format is supported by this manager
virtual bool CanGuessFormat() const
returns true if loader's format can be guessed
virtual bool ValidateFilenames(const vector< wxString > &filenames)=0
checks given filenames and returns true if the manager can handle them, otherwise - shows an error me...
virtual wxString GetFormatWildcard()=0
return file wildcard for the format (example - "*.txt;*.tab" )
virtual string GetFileLoaderId() const =0
IRegSettings An interface for objects that save / restore settings using CGuiRegistry.
virtual void SaveSettings() const =0
virtual void LoadSettings()=0
virtual void SetRegistryPath(const string &path)=0
IServiceLocator - an abstract mechanism for locating services.
Definition: service.hpp:71
virtual void SetPrevPage(IWizardPage *)
Sets a wizard page which should show before the first page of the tool.
Definition: tool_wizard.hpp:61
virtual void SetParentWindow(wxWindow *parent)=0
virtual IWizardPage * GetFirstPage()
Returns first options page (if any) of the tool to be shown in wizard dialog.
Definition: tool_wizard.hpp:57
IUIObject - object that provides basic properties often required in a UI object.
Definition: ui_object.hpp:63
virtual void SetServiceLocator(IServiceLocator *srv_locator)=0
Sets / unsets Service Locator.
virtual void ResetState()
virtual bool CanDo(EAction action)=0
Indicates whether given transition is possible in the current state.
virtual bool DoTransition(EAction action)=0
Performs transition if possible and returns true, otherwise the function shall warn the user about th...
virtual bool IsFinalState()=0
True if Tool Manager has reached its final state, i.e.
virtual const IUIObject & GetDescriptor() const =0
Returns the object describing this tool (UI meta data).
virtual wxPanel * GetCurrentPanel()=0
Return the panel corresponding to the current state of Tool Manager.
virtual IExecuteUnit * GetExecuteUnit()
virtual void CleanUI()=0
CleanUI() is called after the host finished using the manager.
virtual bool IsCompletedState()=0
Manager goes into "Complete" state when "Finish" button is pressed and all input data is gatherred an...
virtual IAppTask * GetTask()=0
Once parameters are gathered and validated this function is called to produce the final Task object t...
virtual void InitUI()=0
Initializes the Manager before using it in UI.
virtual const string & GetLabel() const =0
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUICORE_EXPORT
Definition: gui_export.h:508
Defines to provide correct exporting from DLLs in Windows.
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
The NCBI C++/STL use hints.
static int filenames
Definition: pcregrep.c:172
SProjectSelectorParams - holds data for CProjectSelectorPanel.
Modified on Wed May 15 15:04:29 2024 by modify_doxy.py rev. 669887