diff options
author | Steven M. Gava <elguavas@python.net> | 2002-03-27 08:40:46 (GMT) |
---|---|---|
committer | Steven M. Gava <elguavas@python.net> | 2002-03-27 08:40:46 (GMT) |
commit | 1d46e40f58b21dd6c30e21a841d65e9bcbc899b1 (patch) | |
tree | 15895f64f770b2e8d4cc55896f5e6e3ae7f66069 | |
parent | 03594bbb0ee94dd4b58b664b42448855df6af066 (diff) | |
download | cpython-1d46e40f58b21dd6c30e21a841d65e9bcbc899b1.zip cpython-1d46e40f58b21dd6c30e21a841d65e9bcbc899b1.tar.gz cpython-1d46e40f58b21dd6c30e21a841d65e9bcbc899b1.tar.bz2 |
further work on new config system;
recent files menu
-rw-r--r-- | Lib/idlelib/EditorWindow.py | 71 | ||||
-rw-r--r-- | Lib/idlelib/IOBinding.py | 12 | ||||
-rw-r--r-- | Lib/idlelib/configDialog.py | 4 |
3 files changed, 79 insertions, 8 deletions
diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py index c2ee115b..26400f3 100644 --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -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() diff --git a/Lib/idlelib/IOBinding.py b/Lib/idlelib/IOBinding.py index 4875d11..17c196d 100644 --- a/Lib/idlelib/IOBinding.py +++ b/Lib/idlelib/IOBinding.py @@ -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: diff --git a/Lib/idlelib/configDialog.py b/Lib/idlelib/configDialog.py index 978cbf1..2d05ed2 100644 --- a/Lib/idlelib/configDialog.py +++ b/Lib/idlelib/configDialog.py @@ -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 |