1 /******************************************************************************** 2 * * 3 * R e c e n t F i l e s L i s t * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 1998,2020 by Jeroen van der Zijp. All Rights Reserved. * 7 ********************************************************************************* 8 * This library is free software; you can redistribute it and/or modify * 9 * it under the terms of the GNU Lesser General Public License as published by * 10 * the Free Software Foundation; either version 3 of the License, or * 11 * (at your option) any later version. * 12 * * 13 * This library is distributed in the hope that it will be useful, * 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 16 * GNU Lesser General Public License for more details. * 17 * * 18 * You should have received a copy of the GNU Lesser General Public License * 19 * along with this program. If not, see <http://www.gnu.org/licenses/> * 20 ********************************************************************************/ 21 #ifndef FXRECENTFILES_H 22 #define FXRECENTFILES_H 23 24 #ifndef FXOBJECT_H 25 #include "FXObject.h" 26 #endif 27 28 namespace FX { 29 30 31 class FXApp; 32 33 34 /** 35 * The Recent Files group manages a most recently used (MRU) file list by 36 * means of the standard system registry. 37 * When connected to a widget, like a menu command, the recent files object 38 * updates the menu commands label to the associated recent file name; when 39 * the menu command is invoked, the recent file object sends its target a 40 * SEL_COMMAND message with the message data set to the associated file name, 41 * of the type const char*. 42 * When adding or removing file names, the recent files object automatically 43 * updates the system registry to record these changes. 44 * The ID_ANYFILES may be connected to a menu separator to cause automatic 45 * hiding of the menu separator when there are no recent files. 46 * The number of file names is typically no more than 10. 47 * File names should not be empty. 48 */ 49 class FXAPI FXRecentFiles : public FXObject { 50 FXDECLARE(FXRecentFiles) 51 private: 52 FXSettings *settings; // Settings database where list is kept 53 FXObject *target; // Target object to send message 54 FXSelector message; // Message to send 55 FXString group; // MRU File group 56 FXuint maxfiles; // Maximum number of files to track 57 private: 58 static const FXchar key[32][7]; 59 private: 60 FXRecentFiles(const FXRecentFiles&); 61 FXRecentFiles &operator=(const FXRecentFiles&); 62 public: 63 long onCmdClear(FXObject*,FXSelector,void*); 64 long onCmdFile(FXObject*,FXSelector,void*); 65 long onUpdFile(FXObject*,FXSelector,void*); 66 long onUpdAnyFiles(FXObject*,FXSelector,void*); 67 public: 68 enum{ 69 ID_CLEAR, 70 ID_ANYFILES, 71 ID_FILE_1, 72 ID_FILE_2, 73 ID_FILE_3, 74 ID_FILE_4, 75 ID_FILE_5, 76 ID_FILE_6, 77 ID_FILE_7, 78 ID_FILE_8, 79 ID_FILE_9, 80 ID_FILE_10, 81 ID_FILE_11, 82 ID_FILE_12, 83 ID_FILE_13, 84 ID_FILE_14, 85 ID_FILE_15, 86 ID_FILE_16, 87 ID_FILE_17, 88 ID_FILE_18, 89 ID_FILE_19, 90 ID_FILE_20, 91 ID_FILE_21, 92 ID_FILE_22, 93 ID_FILE_23, 94 ID_FILE_24, 95 ID_FILE_25, 96 ID_FILE_26, 97 ID_FILE_27, 98 ID_FILE_28, 99 ID_FILE_29, 100 ID_FILE_30, 101 ID_FILE_31, 102 ID_FILE_32, 103 ID_LAST 104 }; 105 public: 106 107 /** 108 * Make new recent files group. 109 * A Settings object and group name must be assigned prior to usage. 110 */ 111 FXRecentFiles(); 112 113 /** 114 * Make new recent files group, using settings database from application. 115 * An optional target and message may be passed to invoke when one of the 116 * list of files is invoked. 117 */ 118 FXRecentFiles(FXApp* a,const FXString& gp="Recent Files",FXObject *tgt=NULL,FXSelector sel=0); 119 120 /** 121 * Make new recent files group, using given settings database. 122 * An optional target and message may be passed to invoke when one of the 123 * list of files is invoked. 124 */ 125 FXRecentFiles(FXSettings* st,const FXString& gp="Recent Files",FXObject *tgt=NULL,FXSelector sel=0); 126 127 /// Change settings database setSettings(FXSettings * s)128 void setSettings(FXSettings* s){ settings=s; } 129 130 /// Return settings database getSettings()131 FXSettings* getSettings() const { return settings; } 132 133 /// Change number of files we're tracking 134 void setMaxFiles(FXuint mx); 135 136 /// Return the maximum number of files being tracked getMaxFiles()137 FXuint getMaxFiles() const { return maxfiles; } 138 139 /// Set group name setGroupName(const FXString & name)140 void setGroupName(const FXString& name){ group=name; } 141 142 /// Return group name getGroupName()143 FXString getGroupName() const { return group; } 144 145 /// Change the target setTarget(FXObject * t)146 void setTarget(FXObject *t){ target=t; } 147 148 /// Get the target getTarget()149 FXObject *getTarget() const { return target; } 150 151 /// Change the message setSelector(FXSelector sel)152 void setSelector(FXSelector sel){ message=sel; } 153 154 /// Return the message id getSelector()155 FXSelector getSelector() const { return message; } 156 157 /// Obtain the filename at index 158 FXString getFile(FXuint index) const; 159 160 /// Change the filename at index 161 void setFile(FXuint index,const FXString& filename); 162 163 /// Append a file 164 void appendFile(const FXString& filename); 165 166 /// Remove a file 167 void removeFile(const FXString& filename); 168 169 /// Clear the list of files 170 void clear(); 171 172 /// Save to a stream 173 virtual void save(FXStream& store) const; 174 175 /// Load from a stream 176 virtual void load(FXStream& store); 177 178 /// Destructor 179 virtual ~FXRecentFiles(); 180 }; 181 182 } 183 184 #endif 185