00001 /*========================================================================= 00002 00003 Module: $RCSfile: vtkKWFileListTable.h,v $ 00004 00005 Copyright (c) Kitware, Inc. 00006 All rights reserved. 00007 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00008 00009 This software is distributed WITHOUT ANY WARRANTY; without even 00010 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00011 PURPOSE. See the above copyright notice for more information. 00012 00013 =========================================================================*/ 00014 // .NAME vtkKWFileListTable - a file list table widget 00015 // .SECTION Description 00016 // A widget for displaying and selecting files/directories within 00017 // a directory. It contains information about file name, size and 00018 // modified time. The files can be sorted by these info individually. 00019 // The right click context menu offers explore, rename, delete functions. 00020 // .SECTION Thanks 00021 // This work is part of the National Alliance for Medical Image 00022 // Computing (NAMIC), funded by the National Institutes of Health 00023 // through the NIH Roadmap for Medical Research, Grant U54 EB005149. 00024 // Information on the National Centers for Biomedical Computing 00025 // can be obtained from http://nihroadmap.nih.gov/bioinformatics. 00026 // .SECTION See Also 00027 // vtkKWFileBrowserDialog vtkKWFileBrowserWidget 00028 00029 #ifndef __vtkKWFileListTable_h 00030 #define __vtkKWFileListTable_h 00031 00032 #include "vtkKWCompositeWidget.h" 00033 00034 class vtkKWMultiColumnListWithScrollbars; 00035 class vtkKWMenu; 00036 class vtkGlobFileNames; 00037 class vtkKWFileListTableInternals; 00038 00039 class KWWidgets_EXPORT vtkKWFileListTable : public vtkKWCompositeWidget 00040 { 00041 public: 00042 static vtkKWFileListTable* New(); 00043 vtkTypeRevisionMacro(vtkKWFileListTable,vtkKWCompositeWidget); 00044 void PrintSelf(ostream& os, vtkIndent indent); 00045 00046 // Description: 00047 // Show folders and files of the given directory (path) in the table, 00048 // based on file patterns and/or extensions if they exist. 00049 // If both patterns and extensions exist, only the patterns are used. 00050 // Return 1 on success, 0 otherwise 00051 virtual int ShowFileList( 00052 const char *path, 00053 const char *filepattern, 00054 const char *fileextensions); 00055 00056 // Description: 00057 // Set/Get the parent directory, of which this widget is 00058 // displaying the files and directories 00059 virtual void SetParentDirectory(const char *arg); 00060 vtkGetStringMacro(ParentDirectory); 00061 00062 // Description: 00063 // Set/Get the file pattern that should contains "*" or "?", 00064 // with which the files will be filtered. When the widget uses 00065 // file pattern to filter files, the file extensions will be ignored. 00066 // Example: "foo*" or "?bar" 00067 virtual void SetFilePattern(const char *arg); 00068 vtkGetStringMacro(FilePattern); 00069 00070 // Description: 00071 // Set/Get the file extenstions that the file table will use 00072 // to filter its files. When the widget uses 00073 // file pattern to filter files, the file extensions will be ignored. 00074 // The argument is NOT a Tk format, just a simple string of extensions 00075 // with space between them. 00076 // Example: ".txt .text .jpg .jpeg" 00077 virtual void SetFileExtensions(const char *arg); 00078 vtkGetStringMacro(FileExtensions); 00079 00080 // Description: 00081 // Set the one of several styles for manipulating the selection. 00082 // Valid constants can be found in vtkKWOptions::SelectionModeType. 00083 virtual void SetSelectionMode(int); 00084 virtual void SetSelectionModeToSingle(); 00085 virtual void SetSelectionModeToBrowse(); 00086 virtual void SetSelectionModeToMultiple(); 00087 virtual void SetSelectionModeToExtended(); 00088 00089 // Description: 00090 // Get the files that are selected. This is meant 00091 // for use with MultipleSelection mode. 00092 virtual const char *GetSelectedFileName() 00093 {return GetNthSelectedFileName(0);} 00094 virtual int GetNumberOfSelectedFileNames(); 00095 virtual const char *GetNthSelectedFileName(int i); 00096 virtual void SelectFileName(const char* filename); 00097 virtual void DeselectFileName(const char*); 00098 virtual void ClearSelection(); 00099 00100 // Description: 00101 // Set/Get the selection background and foreground colors. 00102 virtual void GetSelectionBackgroundColor(double *r, double *g, double *b); 00103 virtual double* GetSelectionBackgroundColor(); 00104 virtual void SetSelectionBackgroundColor(double r, double g, double b); 00105 virtual void SetSelectionBackgroundColor(double rgb[3]) 00106 { this->SetSelectionBackgroundColor(rgb[0], rgb[1], rgb[2]); }; 00107 virtual void GetSelectionForegroundColor(double *r, double *g, double *b); 00108 virtual double* GetSelectionForegroundColor(); 00109 virtual void SetSelectionForegroundColor(double r, double g, double b); 00110 virtual void SetSelectionForegroundColor(double rgb[3]) 00111 { this->SetSelectionForegroundColor(rgb[0], rgb[1], rgb[2]); }; 00112 00113 // Description: 00114 // Set/Get the width (in chars) and height (in lines) of the table. 00115 // If width is set to 0, the widget will be large enough to show 00116 // all columns. In all cases, the widget will still obey to its packing 00117 // layout, i.e. it will stretch all the way if: -fill x 00118 virtual void SetTableWidth(int width); 00119 virtual int GetTableWidth(); 00120 virtual void SetTableHeight(int height); 00121 virtual int GetTableHeight(); 00122 00123 // Description: 00124 // Convenience method to Set/Get the table background color. 00125 virtual void GetTableBackgroundColor(double *r, double *g, double *b); 00126 virtual double* GetTableBackgroundColor(); 00127 virtual void SetTableBackgroundColor(double r, double g, double b); 00128 virtual void SetTableBackgroundColor(double rgb[3]) 00129 { this->SetTableBackgroundColor(rgb[0], rgb[1], rgb[2]); }; 00130 00131 // Description: 00132 // Specifies commands to associate with the widget. 00133 // 'FileSelected' is called whenever the selection is changed. 00134 // 'FileDoubleClicked' is called when a file/folder is double-clicked on. 00135 // 'FileDeleted' is called when a file/folder is removed 00136 // 'FileRenamed' is called when a file/folder is renamed by right click 00137 // 'FileUpdated' is called when a new folder is created from right click 00138 // on empty rows. 00139 // The 'object' argument is the object that will have the method called on 00140 // it. The 'method' argument is the name of the method to be called and any 00141 // arguments in string form. If the object is NULL, the method is still 00142 // evaluated as a simple command. 00143 virtual void SetFileSelectedCommand(vtkObject *obj, const char *method); 00144 virtual void SetFileDoubleClickedCommand(vtkObject *obj, const char *method); 00145 virtual void SetFileDeletedCommand(vtkObject *obj, const char *method); 00146 virtual void SetFileRenamedCommand(vtkObject *obj, const char *method); 00147 virtual void SetFolderCreatedCommand(vtkObject *obj, const char *method); 00148 00149 // Description: 00150 // Define the event types with enumeration 00151 // Even though it is highly recommended to use the commands 00152 // framework defined above to specify the callback methods you want to be 00153 // invoked when specific event occur, you can also use the observer 00154 // framework and listen to the corresponding events/ 00155 // Note that they are passed the same parameters as the commands, if any. 00156 // If more than one numerical parameter is passed, they are all stored 00157 // in the calldata as an array of double. 00158 //BTX 00159 enum 00160 { 00161 FileSelectionChangedEvent = 10000, 00162 FileDoubleClickedEvent, 00163 FileRenamedEvent, 00164 FolderCreatedEvent, 00165 FileDeletedEvent 00166 }; 00167 //ETX 00168 00169 // Description: 00170 // Set focus to the file list component of this widget. 00171 // Based on the visibility 00172 virtual void Focus(); 00173 virtual int HasFocus(); 00174 00175 // Description: 00176 // Add/Remove event binding to the internal file list 00177 // component of this widget, so that these events will be 00178 // invoked directly from the file list component of this widget. 00179 virtual void AddBindingToInternalWidget(const char* event, 00180 vtkObject *obj, const char* method); 00181 virtual void RemoveBindingFromInternalWidget(const char* event, 00182 vtkObject *obj, const char* method); 00183 00184 // Description: 00185 // Callback, do NOT use. 00186 // Right-click context menu callbacks 00187 virtual void ContextMenuCallback(int row, int col, int x, int y); 00188 00189 // Description: 00190 // Callback, do NOT use. 00191 // Callbacks for Prior/Next key navigations in the table 00192 virtual void KeyPriorNextNavigationCallback( 00193 const char *w, int x, int y, 00194 int root_x, int root_y, const char* key); 00195 00196 // Description: 00197 // Callback, do NOT use. 00198 // Rename callback. 00199 virtual int RenameFileCallback(); 00200 00201 // Description: 00202 // Callback, do NOT use. 00203 // Callback triggered when the file list table is getting focus. 00204 virtual void FocusInCallback(); 00205 00206 // Description: 00207 // Callback, do NOT use. 00208 // Launch native explorer callback. 00209 virtual void ExploreFileCallback(); 00210 00211 // Description: 00212 // Callback, do NOT use. 00213 // Create new folder callback. 00214 virtual void CreateNewFolderCallback(const char* parentdir); 00215 00216 // Description: 00217 // Callback, do NOT use. 00218 // Callback triggered when the file selection is changed in the file list. 00219 virtual void SelectedFileChangedCallback(); 00220 00221 // Description: 00222 // Callback, do NOT use. 00223 // Callback triggered for the Navigation keys: Home/End. 00224 // This is used to change the default behavior of the 00225 // vtkKWMultiColumnList, so that the list behaves more like Win32 explorer 00226 virtual void KeyHomeEndNavigationCallback(const char *key); 00227 00228 // Description: 00229 // Callback, do NOT use. 00230 // Callback triggered when an item is double clicked in the file list. 00231 virtual void FileDoubleClickCallback(); 00232 00233 // Description: 00234 // Callback, do NOT use. 00235 // Callback triggered when the 'Delete' key is pressed. 00236 // Remove the selected item from the file list. 00237 virtual int RemoveSelectedFileCallback(); 00238 00239 // Description: 00240 // Callback, do NOT use. 00241 // When the time column in the file list is displayed, convert 00242 // the celltext ('+' as file or '-' as folder plus time value in seconds 00243 // for sorting while keeps folders and files separate)) to ctime format. 00244 // Funtion returns the formatted string that will be displayed: char* 00245 virtual char *GetFormatTimeStringCallback(const char* celltext); 00246 00247 // Description: 00248 // Callback, do NOT use. 00249 // Sort items by time. 00250 virtual int SortTimeCallback(const char* cell1, const char* cell2); 00251 00252 // Description: 00253 // Callback, do NOT use. 00254 // When the size column in the file list is displayed, convert 00255 // the celltext (size value in bytes) to 'KB' format. 00256 // Funtion returns the formatted string that will be displayed: const char* 00257 virtual char *GetFormatSizeStringCallback(const char* celltext); 00258 00259 // Description: 00260 // Callback, do NOT use. 00261 // When the Name column in the file list is displayed, convert 00262 // the celltext (1 as file or 0 as folder plus real name for sorting 00263 // while keeping folders and files seperate) to real name. 00264 // Funtion returns the real name that will be displayed: const char* 00265 virtual char *GetRealNameStringCallback(const char* celltext); 00266 00267 // Description: 00268 // Update the "enable" state of the object and its internal parts. 00269 // Depending on different Ivars (this->Enabled, the application's 00270 // Limited Edition Mode, etc.), the "enable" state of the object 00271 // is updated and propagated to its internal parts/subwidgets. 00272 // This will, for example, enable/disable parts of the widget UI, 00273 // enable/disable the visibility of 3D widgets, etc. 00274 virtual void UpdateEnableState(); 00275 00276 // Description: 00277 // Given the prefix of a file or folder name, this function will make 00278 // the corresponding row with this name visible in the window 00279 virtual void ScrollToFile(const char* prefix); 00280 00281 protected: 00282 vtkKWFileListTable(); 00283 ~vtkKWFileListTable(); 00284 00285 // Description: 00286 // Create the widget. 00287 virtual void CreateWidget(); 00288 00289 // Description: 00290 // Populate the right-click context menu. 00291 virtual void PopulateContextMenu(int rowselected); 00292 00293 // Description: 00294 // Commands 00295 char *FileSelectedCommand; 00296 char *FileDoubleClickedCommand; 00297 char *FileDeletedCommand; 00298 char *FileRenamedCommand; 00299 char *FolderCreatedCommand; 00300 00301 // Description: 00302 // Invoke Commands 00303 virtual void InvokeFileSelectedCommand(const char* path); 00304 virtual void InvokeFileDoubleClickedCommand(const char* path); 00305 virtual void InvokeFileDeletedCommand(const char* path, int isDir); 00306 virtual void InvokeFileRenamedCommand( 00307 const char* oldname, const char* newname); 00308 virtual void InvokeFolderCreatedCommand(const char* filename); 00309 00310 // Description: 00311 // Set the parent directory, file pattern, file extensions 00312 virtual void SetParentDirectoryInternal(const char *arg); 00313 virtual void SetFilePatternInternal(const char *arg); 00314 virtual void SetFileExtensionsInternal(const char *arg); 00315 00316 // Description: 00317 // Member variables 00318 vtkKWFileListTableInternals *Internals; 00319 vtkKWMultiColumnListWithScrollbars *FileList; 00320 vtkKWMenu *ContextMenu; 00321 char* ParentDirectory; 00322 char* FilePattern; 00323 char* FileExtensions; 00324 00325 private: 00326 vtkKWFileListTable(const vtkKWFileListTable&); // Not implemented 00327 void operator=(const vtkKWFileListTable&); // Not implemented 00328 00329 // Description: 00330 // Get a temporary full filename given the row index, 00331 // should be stored right away 00332 virtual char* GetRowFileName(int row); 00333 00334 // Description: 00335 // Get the cell text 00336 virtual const char* GetCellText(int row, int col); 00337 00338 }; 00339 #endif