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,2010 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 #ifndef FXRECENTFILES_H
00022 #define FXRECENTFILES_H
00023 
00024 #ifndef FXOBJECT_H
00025 #include "FXObject.h"
00026 #endif
00027 
00028 namespace FX {
00029 
00030 
00031 class FXApp;
00032 
00033 
00034 /**
00035 * The Recent Files group manages a most recently used (MRU) file list by
00036 * means of the standard system registry.
00037 * When connected to a widget, like a menu command, the recent files object
00038 * updates the menu commands label to the associated recent file name; when
00039 * the menu command is invoked, the recent file object sends its target a
00040 * SEL_COMMAND message with the message data set to the associated file name,
00041 * of the type const char*.
00042 * When adding or removing file names, the recent files object automatically
00043 * updates the system registry to record these changes.
00044 * The ID_ANYFILES may be connected to a menu separator to cause automatic
00045 * hiding of the menu separator when there are no recent files.
00046 * The number of file names is typically no more than 10.
00047 * File names should not be empty.
00048 */
00049 class FXAPI FXRecentFiles : public FXObject {
00050   FXDECLARE(FXRecentFiles)
00051 private:
00052   FXSettings *settings;       // Settings database where list is kept
00053   FXObject   *target;         // Target object to send message
00054   FXSelector  message;        // Message to send
00055   FXString    group;          // MRU File group
00056   FXuint      maxfiles;       // Maximum number of files to track
00057 private:
00058   static const FXchar key[32][7];
00059 private:
00060   FXRecentFiles(const FXRecentFiles&);
00061   FXRecentFiles &operator=(const FXRecentFiles&);
00062 public:
00063   long onCmdClear(FXObject*,FXSelector,void*);
00064   long onCmdFile(FXObject*,FXSelector,void*);
00065   long onUpdFile(FXObject*,FXSelector,void*);
00066   long onUpdAnyFiles(FXObject*,FXSelector,void*);
00067 public:
00068   enum{
00069     ID_CLEAR,
00070     ID_ANYFILES,
00071     ID_FILE_1,
00072     ID_FILE_2,
00073     ID_FILE_3,
00074     ID_FILE_4,
00075     ID_FILE_5,
00076     ID_FILE_6,
00077     ID_FILE_7,
00078     ID_FILE_8,
00079     ID_FILE_9,
00080     ID_FILE_10,
00081     ID_LAST
00082     };
00083 public:
00084 
00085   /**
00086   * Make new recent files group.
00087   * A Settings object and group name must be assigned prior to usage.
00088   */
00089   FXRecentFiles();
00090 
00091   /**
00092   * Make new recent files group, using settings database from application.
00093   * An optional target and message may be passed to invoke when one of the
00094   * list of files is invoked.
00095   */
00096   FXRecentFiles(FXApp* a,const FXString& gp="Recent Files",FXObject *tgt=NULL,FXSelector sel=0);
00097 
00098   /**
00099   * Make new recent files group, using given settings database.
00100   * An optional target and message may be passed to invoke when one of the
00101   * list of files is invoked.
00102   */
00103   FXRecentFiles(FXSettings* st,const FXString& gp="Recent Files",FXObject *tgt=NULL,FXSelector sel=0);
00104 
00105   /// Change settings database
00106   void setSettings(FXSettings* s){ settings=s; }
00107 
00108   /// Return settings database
00109   FXSettings* getSettings() const { return settings; }
00110 
00111   /// Change number of files we're tracking
00112   void setMaxFiles(FXuint mx);
00113 
00114   /// Return the maximum number of files being tracked
00115   FXuint getMaxFiles() const { return maxfiles; }
00116 
00117   /// Set group name
00118   void setGroupName(const FXString& name){ group=name; }
00119 
00120   /// Return group name
00121   FXString getGroupName() const { return group; }
00122 
00123   /// Change the target
00124   void setTarget(FXObject *t){ target=t; }
00125 
00126   /// Get the target
00127   FXObject *getTarget() const { return target; }
00128 
00129   /// Change the message
00130   void setSelector(FXSelector sel){ message=sel; }
00131 
00132   /// Return the message id
00133   FXSelector getSelector() const { return message; }
00134 
00135   /// Obtain the filename at index
00136   FXString getFile(FXuint index) const;
00137 
00138   /// Change the filename at index
00139   void setFile(FXuint index,const FXString& filename);
00140 
00141   /// Append a file
00142   void appendFile(const FXString& filename);
00143 
00144   /// Remove a file
00145   void removeFile(const FXString& filename);
00146 
00147   /// Clear the list of files
00148   void clear();
00149 
00150   /// Save to a stream
00151   virtual void save(FXStream& store) const;
00152 
00153   /// Load from a stream
00154   virtual void load(FXStream& store);
00155 
00156   /// Destructor
00157   virtual ~FXRecentFiles();
00158   };
00159 
00160 }
00161 
00162 #endif

Copyright © 1997-2010 Jeroen van der Zijp