Attached is a patch to add a recently used files submenu to the File menu (this might be better as a set of menu items?). It also adds generic support for submenus in action.py.
? recentFiles.diff
? dialogs/__init__.pyc
? dialogs/aboutdialog.pyc
? dialogs/dataeditdialog.pyc
? dialogs/exceptiondialog.pyc
? dialogs/importdialog.pyc
? dialogs/importfits.pyc
? dialogs/reloaddata.pyc
? document/__init__.pyc
? document/commandinterface.pyc
? document/commandinterpreter.pyc
? document/datasets.pyc
? document/doc.pyc
? document/operations.pyc
? document/readcsv.pyc
? document/simpleread.pyc
? helpers/__init__.pyc
? setting/__init__.pyc
? setting/collections.pyc
? setting/controls.pyc
? setting/setting.pyc
? setting/settingdb.pyc
? setting/settings.pyc
? setting/stylesheet.pyc
? utils/__init__.pyc
? utils/fitlm.pyc
? utils/points.pyc
? utils/pref.pyc
? utils/preftypes.pyc
? utils/textrender.pyc
? utils/utilfuncs.pyc
? utils/version.pyc
? widgets/__init__.pyc
? widgets/axis.pyc
? widgets/axisticks.pyc
? widgets/containers.pyc
? widgets/contour.pyc
? widgets/fit.pyc
? widgets/graph.pyc
? widgets/image.pyc
? widgets/key.pyc
? widgets/page.pyc
? widgets/plotters.pyc
? widgets/root.pyc
? widgets/widget.pyc
? widgets/widgetfactory.pyc
? windows/__init__.pyc
? windows/action.pyc
? windows/consolewindow.pyc
? windows/mainwindow.pyc
? windows/plotwindow.pyc
? windows/treeeditwindow.pyc
Index: windows/action.py
===================================================================
RCS file: /cvs/veusz/veusz/windows/action.py,v
retrieving revision 1.12
diff -n -u -r1.12 action.py
--- windows/action.py	24 Nov 2005 21:31:56 -0000	1.12
+++ windows/action.py	5 Mar 2006 19:49:40 -0000
@@ -1,4 +1,4 @@
-# action.py
+## action.py
 # A QAction-like object which can add buttons to things other than
 # QToolBars
 
@@ -186,13 +186,23 @@
             f = os.path.join(_icondir, icon)
             action.setIconSet(qt.QIconSet( qt.QPixmap(f) ))
 
-        # connect the action to the slot
-        if slot != None:
-            qt.QObject.connect( action, qt.SIGNAL('activated()'), slot )
-
-        # add to menu
-        if menus != None:
-            action.addTo( menus[menu] )
+        if callable(slot):
+            # connect the action to the slot
+            if slot is not None:
+                qt.QObject.connect( action, qt.SIGNAL('activated()'), slot )
+                # add to menu
+            if menus is not None:
+                action.addTo( menus[menu] )
+        elif slot is not None:
+            if menus is not None:
+                submenu = qt.QPopupMenu(menus[menu].parentWidget())
+                menus["%s.%s"%(menu ,menuid)] = submenu
+                menus[menu].insertItem(menutext,submenu)
+                populateMenuToolbars(slot, toolbar, menus)
+        else:
+            if menus is not None:
+                action.addTo( menus[menu] )
+                
 
         # add to toolbar
         if addtool and toolbar != None:
Index: windows/mainwindow.py
===================================================================
RCS file: /cvs/veusz/veusz/windows/mainwindow.py,v
retrieving revision 1.50
diff -n -u -r1.50 mainwindow.py
--- windows/mainwindow.py	30 Dec 2005 11:02:31 -0000	1.50
+++ windows/mainwindow.py	5 Mar 2006 19:49:41 -0000
@@ -122,6 +122,9 @@
         self.connect(self.menus['edit'], qt.SIGNAL('aboutToShow()'),
                      self.slotAboutToShowEdit)
 
+        #Get the list of recently opened files
+        self.populateRecentFiles()
+
     def updateStatusbar(self, text):
         '''Display text for a set period.'''
         self.statusBar().message(text, 2000)
@@ -248,11 +251,17 @@
         # Items are: Lookup id, description, menu text, which menu,
         #  Slot, Icon (or ''), whether to add to toolbar,
         #  Keyboard shortcut (or '')
+        # For menus wih submenus slot should be replaced by a list of
+        # submenus items of the dame form where the menu will be of the form
+        # menuid.itemid
         items = [
             ('filenew', 'New document', '&New', 'file',
              self.slotFileNew, 'stock-new.png', True, 'Ctrl+N'),
             ('fileopen', 'Open a document', '&Open...', 'file',
              self.slotFileOpen, 'stock-open.png', True, 'Ctrl+O'),
+            #If we were looking for HIG goodness, there wouldn't be a submenu here
+            ('filerecent', 'Open a recently edited document',
+             'Open &Recent', 'file', [], '', False, ''),
             ('file', ),
             ('filesave', 'Save the document', '&Save', 'file',
              self.slotFileSave, 'stock-save.png', True, 'Ctrl+S'),
@@ -492,6 +501,17 @@
 
             self.slotFileSave()
 
+    def doFileOpen(self,filename):
+        """(Needs a better name) - select whether to load the file in the
+        current window or in a blank window and calls the appropriate loader"""
+        if self.document.isBlank():
+            # If the file is new and there are no modifications,
+            # reuse the current window
+            self.openFile(filename)
+        else:
+            # create a new window
+            self.CreateWindow(filename)
+
     def openFile(self, filename):
         '''Open the given filename in the current window.'''
 
@@ -525,7 +545,7 @@
                            qt.QMessageBox.NoButton,
                            qt.QMessageBox.NoButton,
                            self).exec_loop()
-
+        
         # restore the cursor
         qt.QApplication.restoreOverrideCursor()
 
@@ -544,14 +564,51 @@
             self.dirname = fd.dir()
 
             filename = unicode( fd.selectedFile() )
-            if self.document.isBlank():
-                # If the file is new and there are no modifications,
-                # reuse the current window
-                self.openFile(filename)
+        
+            #Update the list of recently opened files
+            if 'recent_files' in setting.settingdb:
+                filelist = setting.settingdb['recent_files']
+                if filename in filelist:
+                    filelist.remove(filename)
+                filelist.insert(0, filename)
+                filelist = filelist[:5]
             else:
-                # create a new window
-                self.CreateWindow(filename)
+                filelist = [filename]
+            setting.settingdb['recent_files'] = filelist
+            self.populateRecentFiles()
+
+            self.doFileOpen(filename)
+        
+    def populateRecentFiles(self):
+        """Populate the recently opened files menu with a list of
+        recently opened files"""
+        menu = self.menus["file.filerecent"]
+        menu.clear()
+        newMenuItems = []
+        if 'recent_files' in setting.settingdb and setting.settingdb['recent_files']:
+            files = setting.settingdb['recent_files']
+            self._openRecentFunctions = []
+            for i, path in enumerate(files):
+
+                #Surely there is an easier way to do this?
+                def fileOpenerFunction(filename):
+                    path=filename
+                    def f():
+                        self.doFileOpen(path)
+                    return f
+                f = fileOpenerFunction(path)
+                self._openRecentFunctions.append(f)
+                
+                newMenuItems.append(('filerecent%i'%i, 'Open File %s'%path, path,
+                                     'file.filerecent', f,
+                                     '', False, ''))
+            self.recentFileActions = action.populateMenuToolbars(newMenuItems,
+                                                                 self.maintoolbar,
+                                                                 self.menus)
+        else:
+            self.menus['file.filerecent'].setEnabled(False)
                 
+    
     def slotFileExport(self):
         """Export the graph."""
 
_______________________________________________
Veusz-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/veusz-discuss

Répondre à