Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXRecentFiles.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                     R e c e n t   F i l e s   L i s t                         *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1998,2009 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 *********************************************************************************
00021 * $Id: FXRecentFiles.h,v 1.32 2009/01/07 13:24:50 fox Exp $                     *
00022 ********************************************************************************/
00023 #ifndef FXRECENTFILES_H
00024 #define FXRECENTFILES_H
00025 
00026 #ifndef FXOBJECT_H
00027 #include "FXObject.h"
00028 #endif
00029 
00030 namespace FX {
00031 
00032 
00033 class FXApp;
00034 
00035 
00036 /**
00037 * The Recent Files group manages a most recently used (MRU) file list by
00038 * means of the standard system registry.
00039 * When connected to a widget, like a menu command, the recent files object
00040 * updates the menu commands label to the associated recent file name; when
00041 * the menu command is invoked, the recent file object sends its target a
00042 * SEL_COMMAND message with the message data set to the associated file name,
00043 * of the type const char*.
00044 * When adding or removing file names, the recent files object automatically
00045 * updates the system registry to record these changes.
00046 * The ID_ANYFILES may be connected to a menu separator to cause automatic
00047 * hiding of the menu separator when there are no recent files.
00048 * The number of file names is typically no more than 10.
00049 * File names should not be empty.
00050 */
00051 class FXAPI FXRecentFiles : public FXObject {
00052   FXDECLARE(FXRecentFiles)
00053 private:
00054   FXSettings *settings;       // Settings database where list is kept
00055   FXObject   *target;         // Target object to send message
00056   FXSelector  message;        // Message to send
00057   FXString    group;          // MRU File group
00058   FXuint      maxfiles;       // Maximum number of files to track
00059 private:
00060   static const FXchar key[32][7];
00061 private:
00062   FXRecentFiles(const FXRecentFiles&);
00063   FXRecentFiles &operator=(const FXRecentFiles&);
00064 public:
00065   long onCmdClear(FXObject*,FXSelector,void*);
00066   long onCmdFile(FXObject*,FXSelector,void*);
00067   long onUpdFile(FXObject*,FXSelector,void*);
00068   long onUpdAnyFiles(FXObject*,FXSelector,void*);
00069 public:
00070   enum{
00071     ID_CLEAR,
00072     ID_ANYFILES,
00073     ID_FILE_1,
00074     ID_FILE_2,
00075     ID_FILE_3,
00076     ID_FILE_4,
00077     ID_FILE_5,
00078     ID_FILE_6,
00079     ID_FILE_7,
00080     ID_FILE_8,
00081     ID_FILE_9,
00082     ID_FILE_10,
00083     ID_LAST
00084     };
00085 public:
00086 
00087   /**
00088   * Make new recent files group. 
00089   * A Settings object and group name must be assigned prior to usage.
00090   */
00091   FXRecentFiles();
00092 
00093   /**
00094   * Make new recent files group, using settings database from application.
00095   * An optional target and message may be passed to invoke when one of the 
00096   * list of files is invoked.
00097   */
00098   FXRecentFiles(FXApp* a,const FXString& gp="Recent Files",FXObject *tgt=NULL,FXSelector sel=0);
00099 
00100   /**
00101   * Make new recent files group, using given settings database.
00102   * An optional target and message may be passed to invoke when one of the 
00103   * list of files is invoked.
00104   */  
00105   FXRecentFiles(FXSettings* st,const FXString& gp="Recent Files",FXObject *tgt=NULL,FXSelector sel=0);
00106 
00107   /// Change settings database
00108   void setSettings(FXSettings* s){ settings=s; }
00109 
00110   /// Return settings database
00111   FXSettings* getSettings() const { return settings; }
00112 
00113   /// Change number of files we're tracking
00114   void setMaxFiles(FXuint mx);
00115 
00116   /// Return the maximum number of files being tracked
00117   FXuint getMaxFiles() const { return maxfiles; }
00118 
00119   /// Set group name
00120   void setGroupName(const FXString& name){ group=name; }
00121 
00122   /// Return group name
00123   FXString getGroupName() const { return group; }
00124 
00125   /// Change the target
00126   void setTarget(FXObject *t){ target=t; }
00127 
00128   /// Get the target
00129   FXObject *getTarget() const { return target; }
00130 
00131   /// Change the message
00132   void setSelector(FXSelector sel){ message=sel; }
00133 
00134   /// Return the message id
00135   FXSelector getSelector() const { return message; }
00136 
00137   /// Obtain the filename at index
00138   FXString getFile(FXuint index) const;
00139 
00140   /// Change the filename at index
00141   void setFile(FXuint index,const FXString& filename);
00142 
00143   /// Append a file
00144   void appendFile(const FXString& filename);
00145 
00146   /// Remove a file
00147   void removeFile(const FXString& filename);
00148 
00149   /// Clear the list of files
00150   void clear();
00151 
00152   /// Save to a stream
00153   virtual void save(FXStream& store) const;
00154 
00155   /// Load from a stream
00156   virtual void load(FXStream& store);
00157 
00158   /// Destructor
00159   virtual ~FXRecentFiles();
00160   };
00161 
00162 }
00163 
00164 #endif

Copyright © 1997-2009 Jeroen van der Zijp