Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

dlgAddMatchFiles.hpp

Go to the documentation of this file.
00001 /* 00002 * wxChecksums 00003 * Copyright (C) 2003-2004 Julien Couot 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 /** 00021 * \file dlgAddMatchFiles.hpp 00022 * Dialog for adding files by pattern matching. 00023 */ 00024 00025 #ifndef INC_DLGADDMATCHFILES_HPP 00026 #define INC_DLGADDMATCHFILES_HPP 00027 00028 //--------------------------------------------------------------------------- 00029 // For compilers that support precompilation, includes "wx.h". 00030 #include <wx/wxprec.h> 00031 00032 #ifdef __BORLANDC__ 00033 #pragma hdrstop 00034 #endif 00035 00036 #ifndef WX_PRECOMP 00037 // Include your minimal set of headers here, or wx.h 00038 #include <wx/wx.h> 00039 #endif 00040 00041 #include <wx/spinctrl.h> 00042 00043 #include "fdftlmk.hpp" 00044 #include "slstview.hpp" 00045 //--------------------------------------------------------------------------- 00046 00047 00048 /** 00049 * Dialog for choosing a new file name. 00050 * 00051 * If no name of checksums' file is given to the constructor, give one with 00052 * the setChecksumsFileName() method before showing the dialog. 00053 */ 00054 class dlgAddMatchFiles : public wxDialog 00055 { 00056 public: // classes used by the dialog 00057 // Match pattern. 00058 class MatchPattern; 00059 00060 // Array of match pattern entries. 00061 class ArrayMatchPattern; 00062 00063 public: 00064 // Creates a new dialog. 00065 dlgAddMatchFiles(); 00066 00067 // Creates a new dialog. 00068 dlgAddMatchFiles(wxWindow* parent, const wxString& checksumsFileName = wxEmptyString); 00069 00070 // Destructor. 00071 virtual ~dlgAddMatchFiles(); 00072 00073 // Creates and initializes the controls of the dialog. 00074 void createControls(); 00075 00076 protected: 00077 // Sets the title of the dialog. 00078 void setDialogTitle(); 00079 00080 protected: 00081 static long idGen; ///< Value for unique identifiers generation. 00082 wxSortableListView* lvwPatterns; ///< List of patterns. 00083 ArrayMatchPattern* matchPatterns; ///< Match patterns given by the validator. 00084 wxButton* btnRemove; ///< Button for removing patterns. 00085 wxRadioBox* rbxSortBy; ///< Sort by radio box buttons. 00086 wxRadioBox* rbxSortOrder; ///< Sort order radio box buttons. 00087 wxButton* btnAddPattern;///< Add a pattern to the list. 00088 wxComboBox* cboPattern; ///< Pattern to add. 00089 wxComboBox* cboDirectory; ///< Directory of the pattern. 00090 wxSpinCtrl* spnDepth; ///< Search depth. 00091 wxString checksumsFileName; ///< Name of the checksums' file where the files will be added. 00092 00093 // Gets a new unique identifier. 00094 static long getID(); 00095 00096 // Processes button Remove. 00097 void btnRemoveClick(wxCommandEvent& event); 00098 // Processes button Add list. 00099 void btnAddListClick(wxCommandEvent& event); 00100 // Processes button Load list. 00101 void btnLoadListClick(wxCommandEvent& event); 00102 // Processes button Save list. 00103 void btnSaveListClick(wxCommandEvent& event); 00104 // Processes button Browse. 00105 void btnBrowseClick(wxCommandEvent& event); 00106 // Processes button Add pattern. 00107 void btnAddPatternClick(wxCommandEvent& event); 00108 00109 // Event handler for the selection of an item. 00110 void lvwPatternsSelectItem(wxListEvent& event); 00111 // Event handler for the deselection of an item. 00112 void lvwPatternsDeselectItem(wxListEvent& event); 00113 // Event handler for the key down event. 00114 void lvwPatternsKeyDown(wxListEvent& event); 00115 // Processes a click on a header of a column of the list of patterns. 00116 void lvwPatternsColumnClick(wxListEvent& event); 00117 00118 // Processes a selection of the column to sort. 00119 void rbxSortBySelect(wxCommandEvent& event); 00120 // Processes a selection of the sort order. 00121 void rbxSortOrderSelect(wxCommandEvent& event); 00122 00123 // Event handler for the enter key pressed on a search combo box. 00124 void cboAddTextEnter(wxCommandEvent& event); 00125 00126 // Processes button Add. 00127 void btnAddClick(wxCommandEvent& event); 00128 00129 /// Controls IDs 00130 enum 00131 { 00132 LVW_FILES = wxID_HIGHEST + 1, 00133 BTN_REMOVE, 00134 BTN_ADDLIST, 00135 BTN_LOADLIST, 00136 BTN_SAVELIST, 00137 CBO_PATTERN, 00138 CBO_DIRECTORY, 00139 BTN_BROWSE, 00140 BTN_ADD_PATTERN, 00141 SPN_DEPTH, 00142 RBX_SORT_BY, 00143 RBX_SORT_ORDER, 00144 BTN_ADD 00145 }; 00146 00147 // Add a pattern to the list view of patterns. 00148 void addPatternToListView(const MatchPattern& pattern); 00149 00150 // A validator for the patterns' list. 00151 class PatternsListValidator; 00152 /// <CODE>FilesListValidator</CODE> can access to <CODE>getID()</CODE>. 00153 friend class PatternsListValidator; 00154 00155 DECLARE_EVENT_TABLE() 00156 00157 private: 00158 DECLARE_DYNAMIC_CLASS(dlgAddMatchFiles) 00159 00160 public: 00161 // Gets the matching patterns. 00162 void getMatchPatterns(ArrayMatchPattern& patterns) const; 00163 00164 // Gets the name of the checksums' file where the files will be added. 00165 wxString getChecksumsFileName() const; 00166 00167 // Sets the name of the checksums' file where the files will be added. 00168 void setChecksumsFileName(const wxString& fileName); 00169 00170 public: 00171 // Gets the root configuration key for parameters of this dialog 00172 static wxString getRootConfigKey(); 00173 00174 // Gets the configuration key for the last patterns 00175 static wxString getMatchPatternConfigKey(const int n); 00176 00177 // Gets the configuration key for the last directories 00178 static wxString getDirectoryConfigKey(const int n); 00179 00180 // Gets the maximum size of the history of the last patterns and directories 00181 static int getHistoryMaxSize(); 00182 00183 protected: 00184 /// Preferences keys 00185 enum PreferencesKey 00186 { 00187 prGUI_ADD_MATCH_FILES_SORT_BY = 0, 00188 prGUI_ADD_MATCH_FILES_SORT_ORDER, 00189 prGUI_ADD_MATCH_FILES_DIRECTORY_WIDTH, 00190 prGUI_ADD_MATCH_FILES_PATTERN_WIDTH, 00191 prGUI_ADD_MATCH_FILES_DEPTH_WIDTH, 00192 prGUI_ADD_MATCH_FILES_WINDOW_SIZE 00193 }; 00194 00195 // Gets the configuration key corresponding to the given preference key. 00196 static wxString getConfigKey(const PreferencesKey pk); 00197 00198 private: // Utility functions 00199 // Adds a file or a directory or a match pattern to a combo box. 00200 static void addLineToComboBox(wxComboBox* cboBox, const int maxLines); 00201 00202 // Gets the last directory used and the filter for the open or save dialog. 00203 static void getLastDirectoryAndFilter(const wxString& configKey, wxString& lastDirKey, wxString& lastDir, wxFileDialogFilterMaker& fltMaker); 00204 00205 // Reads a file of matching patterns. 00206 static void readMatchPatternsFile(const wxString& fileName, ArrayMatchPattern& patterns); 00207 }; 00208 //--------------------------------------------------------------------------- 00209 00210 00211 /** 00212 * Represent a match pattern used by the 'Add match files' dialog. 00213 * 00214 * It contains: 00215 * - A directory in which the search of files begins. 00216 * - A set of patterns separated by the character ';'. 00217 * - The depth of recursion in the subdirectories (0 = infinite). 00218 */ 00219 class dlgAddMatchFiles::MatchPattern 00220 { 00221 protected: 00222 wxString directory; ///< directory of the match pattern. 00223 wxString pattern; ///< match pattern. 00224 int depth; ///< search depth. 00225 00226 // Clones the source instance in this instance. 00227 void clone(const MatchPattern& source); 00228 00229 public: 00230 /// Default constructor. 00231 MatchPattern() : depth(0) {} 00232 00233 // Constructor. 00234 MatchPattern(const wxString& dir, const wxString& pat, const int dep); 00235 00236 /** 00237 * Copy constructor. 00238 * 00239 * @param source Source instance. 00240 */ 00241 MatchPattern(const MatchPattern& source) 00242 { 00243 clone(source); 00244 } 00245 00246 // Assignment operator. 00247 MatchPattern& operator=(const MatchPattern& source); 00248 00249 // Accessors 00250 /** 00251 * Gets the directory. 00252 * 00253 * @return The directory. 00254 */ 00255 wxString getDirectory() const 00256 { 00257 return directory; 00258 } 00259 00260 /** 00261 * Sets the directory. 00262 * 00263 * @param newDir New directory. 00264 */ 00265 void setDirectory(const wxString& newDir) 00266 { 00267 directory = newDir; 00268 } 00269 00270 /** 00271 * Gets the pattern. 00272 * 00273 * @return The pattern. 00274 */ 00275 wxString getPattern() const 00276 { 00277 return pattern; 00278 } 00279 00280 /** 00281 * Sets the pattern. 00282 * 00283 * @param newPattern The new pattern. 00284 */ 00285 void setPattern(const wxString& newPattern) 00286 { 00287 pattern = newPattern; 00288 } 00289 00290 /** 00291 * Gets the depth. 00292 * 00293 * @return The depth. 00294 */ 00295 int getDepth() const 00296 { 00297 return depth; 00298 } 00299 00300 /** 00301 * Sets the depth. 00302 * 00303 * @param newDepth The new depth. 00304 */ 00305 void setDepth(const int newDepth) 00306 { 00307 depth = newDepth; 00308 } 00309 00310 // Useful methods 00311 // Gets the patterns. 00312 wxArrayString getPatterns() const; 00313 00314 // Adds the given patterns to this pattern. 00315 void addPatterns(const wxString& patterns); 00316 00317 // Remove the given patterns from this pattern. 00318 void removePatterns(const wxString& patterns); 00319 00320 // Indicates if the pattern includes all the given patterns. 00321 bool isIncludingAllPatterns(const wxString& patterns) const; 00322 00323 // Compare the depths of this pattern and the given one. 00324 int compareDepth(const MatchPattern& cmp) const; 00325 00326 // Compare two match patterns. 00327 bool operator==(const MatchPattern& cmp) const; 00328 }; 00329 //--------------------------------------------------------------------------- 00330 00331 00332 /** 00333 * Array of matching patterns. 00334 */ 00335 class dlgAddMatchFiles::ArrayMatchPattern 00336 { 00337 protected: 00338 typedef MatchPattern* pMatchPattern; ///< Pointer on a matching pattern. 00339 static const size_t ALLOC_NEW; ///< Number of patterns to allocate when the array is to small for new elements. 00340 size_t allocated; ///< number of allocated matching patterns. 00341 size_t used; ///< number of used matching patterns. 00342 pMatchPattern* patterns; ///< Array of patterns. 00343 00344 // Clones the source instance in this instance. 00345 void clone(const ArrayMatchPattern& source); 00346 00347 public: 00348 // Default constructor. 00349 ArrayMatchPattern(); 00350 00351 // Constructor with an amount of allocated elements. 00352 ArrayMatchPattern(size_t count); 00353 00354 // Copy constructor. 00355 ArrayMatchPattern(const ArrayMatchPattern& source); 00356 00357 // Assignment operator. 00358 ArrayMatchPattern& operator=(const ArrayMatchPattern& source); 00359 00360 // Destructor. 00361 ~ArrayMatchPattern(); 00362 00363 // Adds a pattern to the array. 00364 void add(MatchPattern pattern); 00365 00366 // Preallocates memory for a given number of patterns. 00367 void alloc(size_t count); 00368 00369 // Empties the array. 00370 void clear(); 00371 00372 // Gets the number of patterns in the array. 00373 size_t getCount() const; 00374 00375 // Gets the pattern at the given index. 00376 MatchPattern& item(size_t index) const; 00377 00378 // Gets the pattern at the given index. 00379 MatchPattern& operator[](size_t index) const; 00380 }; 00381 //--------------------------------------------------------------------------- 00382 00383 00384 #endif // INC_DLGADDMATCHFILES_HPP

Generated on Sun May 30 13:37:44 2004 for wxChecksums by doxygen 1.3.7