]> granicus.if.org Git - python/commitdiff
further work on new config system;
authorSteven M. Gava <elguavas@python.net>
Wed, 27 Mar 2002 08:40:46 +0000 (08:40 +0000)
committerSteven M. Gava <elguavas@python.net>
Wed, 27 Mar 2002 08:40:46 +0000 (08:40 +0000)
recent files menu

Lib/idlelib/EditorWindow.py
Lib/idlelib/IOBinding.py
Lib/idlelib/configDialog.py

index c2ee115bd4f213d117d18140269d6e626ae5e951..26400f378e5fa727b3bac2ca6e54c77a703fe087 100644 (file)
@@ -105,6 +105,8 @@ class EditorWindow:
             #self.top.instanceDict makes flist.inversedict avalable to
             #configDialog.py so it can access all EditorWindow instaces
             self.top.instanceDict=flist.inversedict
+        self.recentFilesPath=os.path.join(idleConf.GetUserCfgDir(),
+                'recent-files.lst')
         self.vbar = vbar = Scrollbar(top, name='vbar')
         self.text_frame = text_frame = Frame(top)
         self.text = text = Text(text_frame, name='text', padx=5, wrap=None,
@@ -178,6 +180,11 @@ class EditorWindow:
             self.color = None
         self.undo = undo = self.UndoDelegator(); per.insertfilter(undo)
         self.io = io = self.IOBinding(self)
+        #create the Recent Files submenu
+        self.menuRecentFiles=Menu(self.menubar)
+        self.menudict['file'].insert_cascade(3,label='Recent Files',
+                underline=0,menu=self.menuRecentFiles)
+        self.UpdateRecentFilesList()
 
         text.undo_block_start = undo.undo_block_start
         text.undo_block_stop = undo.undo_block_stop
@@ -253,6 +260,7 @@ class EditorWindow:
             menudict[name] = menu = Menu(mbar, name=name)
             mbar.add_cascade(label=label, menu=menu, underline=underline)
         self.fill_menus()
+        #create the ExtraHelp menu, if required
         self.ResetExtraHelpMenu()
 
     def postwindowsmenu(self):
@@ -542,12 +550,69 @@ class EditorWindow:
             self.menuExtraHelp.delete(1,END)
             for menuItem in menuList:
                 self.menuExtraHelp.add_command(label=menuItem[0],
-                        command=lambda:self.display_docs(menuItem[1]))
+                        command=self.__DisplayExtraHelpCallback(menuItem[1]))
         else: #no extra help items
             if hasattr(self,'menuExtraHelp'): 
                 helpMenu.delete(cascadeIndex-1)                    
                 del(self.menuExtraHelp)
+    
+    def __DisplayExtraHelpCallback(self,helpFile):
+        def DisplayExtraHelp(helpFile=helpFile):
+            self.display_docs(helpFile)
+        return DisplayExtraHelp
                     
+    def UpdateRecentFilesList(self,newFile=None):
+        #load or update the recent files list, and menu if required
+        rfList=[]
+        if os.path.exists(self.recentFilesPath):
+            RFfile=open(self.recentFilesPath,'r')
+            try:
+                rfList=RFfile.readlines()
+            finally:
+                RFfile.close()
+        if newFile: 
+            newFile=os.path.abspath(newFile)+'\n'
+            if newFile in rfList:
+                rfList.remove(newFile)
+            rfList.insert(0,newFile)
+        rfList=self.__CleanRecentFiles(rfList)
+        print self.top.instanceDict
+        print self
+        if rfList:
+            for instance in self.top.instanceDict.keys():
+                instance.menuRecentFiles.delete(1,END)
+                for file in rfList:
+                    fileName=file[0:-1]
+                    instance.menuRecentFiles.add_command(label=fileName,
+                            command=instance.__RecentFileCallback(fileName))
+                    
+    def __CleanRecentFiles(self,rfList):
+        origRfList=rfList[:]
+        count=0
+        nonFiles=[]
+        for path in rfList:
+            if not os.path.exists(path[0:-1]): 
+                nonFiles.append(count)
+            count=count+1
+        if nonFiles:
+            nonFiles.reverse()
+            for index in nonFiles:
+                del(rfList[index])
+        if len(rfList)>19:
+            rfList=rfList[0:19]
+        #if rfList != origRfList:
+        RFfile=open(self.recentFilesPath,'w')
+        try:
+            RFfile.writelines(rfList)
+        finally:
+            RFfile.close()
+        return rfList
+    
+    def __RecentFileCallback(self,fileName):
+        def OpenRecentFile(fileName=fileName):
+            self.io.open(editFile=fileName)
+        return OpenRecentFile
+    
     def saved_change_hook(self):
         short = self.short_title()
         long = self.long_title()
@@ -628,6 +693,10 @@ class EditorWindow:
         return reply
 
     def _close(self):
+        print self.io.filename
+        if self.io.filename:
+            self.UpdateRecentFilesList(newFile=self.io.filename)
+            
         WindowList.unregister_callback(self.postwindowsmenu)
         if self.close_hook:
             self.close_hook()
index 4875d111a775e7792ff815bfb0dedbd3a06947c6..17c196db31de7b395f855b2e399ea70792015fe5 100644 (file)
@@ -72,9 +72,12 @@ class IOBinding:
         if self.filename_change_hook:
             self.filename_change_hook()
 
-    def open(self, event):
+    def open(self, event=None, editFile=None):
         if self.editwin.flist:
-            filename = self.askopenfile()
+            if not editFile:
+                filename = self.askopenfile()
+            else:
+                filename=editFile
             if filename:
                 # if the current window has no filename and hasn't been
                 #   modified, we replace it's contents (no loss).  Otherwise
@@ -93,7 +96,10 @@ class IOBinding:
             if reply == "cancel":
                 self.text.focus_set()
                 return "break"
-        filename = self.askopenfile()
+        if not editFile:
+            filename = self.askopenfile()
+        else:
+            filename=editFile
         if filename:
             self.loadfile(filename)
         else:
index 978cbf13158e6f3663c180e0f6ea497b2714ce8a..2d05ed2dc07c916be57f3905454bbab8e817a151 100644 (file)
@@ -1072,12 +1072,9 @@ class ConfigDialog(Toplevel):
         """
         save all configuration changes to user config files.
         """
-        #if self.changedItems['main'].has_key('HelpFiles'):
         #this section gets completely replaced
-        print idleConf.GetAllExtraHelpSourcesList()
         idleConf.userCfg['main'].remove_section('HelpFiles')
         idleConf.userCfg['main'].Save()
-        print idleConf.GetAllExtraHelpSourcesList()
         for configType in self.changedItems.keys():
             cfgTypeHasChanges=0
             for section in self.changedItems[configType].keys():
@@ -1086,7 +1083,6 @@ class ConfigDialog(Toplevel):
                     if self.SetUserValue(configType,section,item,value):
                         cfgTypeHasChanges=1
             if cfgTypeHasChanges: 
-                print configType,'- changed'
                 idleConf.userCfg[configType].Save()                
         self.ResetChangedItems() #clear the changed items dict