KWWidgets
vtkKWMostRecentFilesManager.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWMostRecentFilesManager.h,v $
4 
5  Copyright (c) Kitware, Inc.
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 // .NAME vtkKWMostRecentFilesManager - a "most recent files" manager.
15 // .SECTION Description
16 // This class is basically a manager that acts as a container for a set of
17 // most recent files.
18 // It provides methods to manipulate them, load/save them from/to the
19 // registry, and display them as entries in a menu.
20 // An instance of this class is created in vtkKWWindowBase
21 // .SECTION Thanks
22 // This work is part of the National Alliance for Medical Image
23 // Computing (NAMIC), funded by the National Institutes of Health
24 // through the NIH Roadmap for Medical Research, Grant U54 EB005149.
25 // Information on the National Centers for Biomedical Computing
26 // can be obtained from http://nihroadmap.nih.gov/bioinformatics.
27 // .SECTION See Also
28 // vtkKWWindowBase
29 
30 #ifndef __vtkKWMostRecentFilesManager_h
31 #define __vtkKWMostRecentFilesManager_h
32 
33 #include "vtkKWObject.h"
34 
35 class vtkKWMostRecentFilesManagerInternals;
36 class vtkKWMenu;
37 
39 {
40 public:
43  void PrintSelf(ostream& os, vtkIndent indent);
44 
45  // Description:
46  // Add a most recent file to the list.
47  // Each most recent file is associated to a target object and a target
48  // command: when a most recent file is invoked (either programmatically or
49  // using the most recent files menu), the associated target commmand is
50  // invoked on the associated target object. If one and/or the other was not
51  // specified when the most recent file was added, the default target
52  // object and/or default target command are used.
53  // An optional label can be specified too.
54  // This label will be used in the menu if LabelVisibilityInMenu is true.
55  // The entry is always added at the beginning of the list (thus, becoming
56  // the most recently used).
57  virtual void AddFile(
58  const char *filename,
59  vtkObject *target_object = NULL,
60  const char *target_command = NULL,
61  const char *label = NULL);
62 
63  // Description:
64  // Query the files
65  virtual int GetNumberOfFiles();
66  virtual const char* GetNthFileName(int idx);
67  virtual vtkObject* GetNthTargetObject(int idx);
68  virtual const char* GetNthTargetCommand(int idx);
69  virtual const char* GetNthLabel(int idx);
70 
71  // Description:
72  // Set/Get the default target object and command.
73  // Each most recent file is associated to a target object and a target
74  // command: when a most recent file is invoked (either programmatically or
75  // using the most recent files menu), the associated target commmand is
76  // invoked on the associated target object. If one and/or the other was not
77  // specified when the most recent file was added, the default target
78  // object and default target command are used.
79  vtkGetObjectMacro(DefaultTargetObject, vtkObject);
80  virtual void SetDefaultTargetObject(vtkObject *object);
81  vtkGetStringMacro(DefaultTargetCommand);
82  virtual void SetDefaultTargetCommand(const char *);
83 
84  // Description:
85  // Load/Save up to 'max_nb' most recent files from/to the registry under
86  // the application's 'reg_key' key.
87  // The parameter-less methods use RegistryKey as 'reg_key' and
88  // MaximumNumberOfFilesInRegistry as 'max_nb'.
89  // Only the filename and target command are saved. When entries are loaded
90  // make sure DefaultTargetObject is set to a valid object.
91  virtual void RestoreFilesListFromRegistry();
92  virtual void SaveFilesToRegistry();
93  virtual void RestoreFilesListFromRegistry(
94  const char *reg_key, int max_nb);
95  virtual void SaveFilesToRegistry(
96  const char *reg_key, int max_nb);
97 
98  // Description:
99  // Set/Get the default registry key the most recent files are saved to or
100  // loaded from when it is not specified explicitly while calling load/save.
101  vtkGetStringMacro(RegistryKey);
102  vtkSetStringMacro(RegistryKey);
103 
104  // Description:
105  // Set/Get the default maximum number of recent files in the registry when
106  // this number is not specified explicitly while calling load/save.
107  vtkGetMacro(MaximumNumberOfFilesInRegistry, int);
108  vtkSetMacro(MaximumNumberOfFilesInRegistry, int);
109 
110  // Description:
111  // Get a most recent files menu object.
112  // This menu is updated automatically as entries are added and removed,
113  // up to MaximumNumberOfFilesInMenu entries.
114  // It is up to the caller to set its parent, and it should be done as soon as
115  // possible if there is a need to use this menu.
116  vtkKWMenu* GetMenu();
117 
118  // Description:
119  // Set/Get the maximum number of recent files in the internal most recent
120  // files menu object (see GetMenu()).
121  vtkGetMacro(MaximumNumberOfFilesInMenu, int);
122  virtual void SetMaximumNumberOfFilesInMenu(int);
123 
124  // Description:
125  // Set a label for a specific file entry.
126  // This label will be used in the menu if LabelVisibilityInMenu is true.
127  virtual void SetFileLabel(const char *filename, const char *label);
128 
129  // Description:
130  // Set/Get the label visibility in menu (Off by default).
131  virtual void SetLabelVisibilityInMenu(int);
132  vtkBooleanMacro(LabelVisibilityInMenu, int);
133  vtkGetMacro(LabelVisibilityInMenu, int);
134 
135  // Description:
136  // Set/Get the basename visibility in menu (On by default).
137  // (i.e., instead of "d:/temp/foo.raw", display "d:/temp")
138  // This setting is ignored per entry if no label is found for that specific
139  // menu entry (in which case only a directory would be displayed, which makes
140  // poor sense).
141  virtual void SetBaseNameVisibilityInMenu(int);
142  vtkBooleanMacro(BaseNameVisibilityInMenu, int);
143  vtkGetMacro(BaseNameVisibilityInMenu, int);
144 
145  // Description:
146  // Separate path from basename in menu (Off by default).
147  // (i.e., instead of "d:/temp/foo.raw", display "foo.raw in d:/temp")
148  virtual void SetSeparatePathInMenu(int);
149  vtkBooleanMacro(SeparatePathInMenu, int);
150  vtkGetMacro(SeparatePathInMenu, int);
151 
152  // Description:
153  // Disable/Enable the most recent files menu if it is a cascade in its
154  // parent. If the menu is empty, it will be disabled.
155  virtual void UpdateMenuStateInParent();
156 
157  // Description:
158  // Populate a given menu with up to 'max_nb' most recent files entries.
159  // You do not need to call this method on GetMenu(), the
160  // internal menu is updated automatically.
161  virtual void PopulateMenu(vtkKWMenu*, int max_nb);
162 
163  // Description:
164  // Event list
165  //BTX
166  enum
167  {
168  MenuHasChangedEvent = 24000
169  };
170  //ETX
171 
172 protected:
175 
176  char *DefaultTargetCommand;
177  vtkObject *DefaultTargetObject;
178  char *RegistryKey;
179  int MaximumNumberOfFilesInRegistry;
180  int MaximumNumberOfFilesInMenu;
181  int LabelVisibilityInMenu;
182  int BaseNameVisibilityInMenu;
183  int SeparatePathInMenu;
184 
185  //BTX
186 
187  // PIMPL Encapsulation for STL containers
188 
189  vtkKWMostRecentFilesManagerInternals *Internals;
190  friend class vtkKWMostRecentFilesManagerInternals;
191 
192  //ETX
193 
194  // Description:
195  // Add a most recent file to the list (internal, do not update the menu
196  // or save to the registry).
197  virtual void AddFileInternal(
198  const char *filename,
199  vtkObject *target_object = NULL,
200  const char *target_command = NULL,
201  const char *label = NULL);
202 
203  // Description:
204  // Update the most recent files menu
205  virtual void UpdateMenu();
206 
207 private:
208 
209  // In private for lazy allocation using GetMenu()
210 
211  vtkKWMenu *Menu;
212 
213  vtkKWMostRecentFilesManager(const vtkKWMostRecentFilesManager&); // Not implemented
214  void operator=(const vtkKWMostRecentFilesManager&); // Not implemented
215 };
216 
217 #endif
218