Commit cf6f1b69 authored by Kurt B. Kaiser's avatar Kurt B. Kaiser

M EditorWindow.py

M IOBinding.py
M NEWS.txt
M configDialog.py

- If nulls somehow got into the strings in recent-files.lst
  EditorWindow.update_recent_files_list() was failing.  Python Bug 931336.
parent 5bed4560
...@@ -2,6 +2,7 @@ import sys ...@@ -2,6 +2,7 @@ import sys
import os import os
import re import re
import imp import imp
from itertools import count
from Tkinter import * from Tkinter import *
import tkSimpleDialog import tkSimpleDialog
import tkMessageBox import tkMessageBox
...@@ -78,10 +79,10 @@ class EditorWindow: ...@@ -78,10 +79,10 @@ class EditorWindow:
self.top = top = self.Toplevel(root, menu=self.menubar) self.top = top = self.Toplevel(root, menu=self.menubar)
if flist: if flist:
self.vars = flist.vars self.vars = flist.vars
#self.top.instanceDict makes flist.inversedict avalable to #self.top.instance_dict makes flist.inversedict avalable to
#configDialog.py so it can access all EditorWindow instaces #configDialog.py so it can access all EditorWindow instaces
self.top.instanceDict=flist.inversedict self.top.instance_dict=flist.inversedict
self.recentFilesPath=os.path.join(idleConf.GetUserCfgDir(), self.recent_files_path=os.path.join(idleConf.GetUserCfgDir(),
'recent-files.lst') 'recent-files.lst')
self.vbar = vbar = Scrollbar(top, name='vbar') self.vbar = vbar = Scrollbar(top, name='vbar')
self.text_frame = text_frame = Frame(top) self.text_frame = text_frame = Frame(top)
...@@ -178,11 +179,12 @@ class EditorWindow: ...@@ -178,11 +179,12 @@ class EditorWindow:
self.io = io = self.IOBinding(self) self.io = io = self.IOBinding(self)
io.set_filename_change_hook(self.filename_change_hook) io.set_filename_change_hook(self.filename_change_hook)
#create the Recent Files submenu # Create the recent files submenu
self.menuRecentFiles=Menu(self.menubar) self.recent_files_menu = Menu(self.menubar)
self.menudict['file'].insert_cascade(3,label='Recent Files', self.menudict['file'].insert_cascade(3, label='Recent Files',
underline=0,menu=self.menuRecentFiles) underline=0,
self.UpdateRecentFilesList() menu=self.recent_files_menu)
self.update_recent_files_list()
if filename: if filename:
if os.path.exists(filename) and not os.path.isdir(filename): if os.path.exists(filename) and not os.path.isdir(filename):
...@@ -579,66 +581,48 @@ class EditorWindow: ...@@ -579,66 +581,48 @@ class EditorWindow:
self.display_docs(helpfile) self.display_docs(helpfile)
return display_extra_help return display_extra_help
def UpdateRecentFilesList(self,newFile=None): def update_recent_files_list(self, new_file=None):
"Load or update the recent files list, and menu if required" "Load and update the recent files list and menus"
rfList=[] rf_list = []
if os.path.exists(self.recentFilesPath): if os.path.exists(self.recent_files_path):
RFfile=open(self.recentFilesPath,'r') rf_list_file = open(self.recent_files_path,'r')
try: try:
rfList=RFfile.readlines() rf_list = rf_list_file.readlines()
finally: finally:
RFfile.close() rf_list_file.close()
if newFile: if new_file:
newFile=os.path.abspath(newFile)+'\n' new_file = os.path.abspath(new_file) + '\n'
if newFile in rfList: if new_file in rf_list:
rfList.remove(newFile) rf_list.remove(new_file) # move to top
rfList.insert(0,newFile) rf_list.insert(0, new_file)
rfList=self.__CleanRecentFiles(rfList) # clean and save the recent files list
#print self.flist.inversedict bad_paths = []
#print self.top.instanceDict for path in rf_list:
#print self if '\0' in path or not os.path.exists(path[0:-1]):
ullist = "1234567890ABCDEFGHIJ" bad_paths.append(path)
if rfList: rf_list = [path for path in rf_list if path not in bad_paths]
for instance in self.top.instanceDict.keys(): ulchars = "1234567890ABCDEFGHIJK"
menu = instance.menuRecentFiles rf_list = rf_list[0:len(ulchars)]
menu.delete(1,END) rf_file = open(self.recent_files_path, 'w')
i = 0 ; ul = 0; ullen = len(ullist)
for file in rfList:
fileName=file[0:-1]
callback = instance.__RecentFileCallback(fileName)
if i > ullen: # don't underline menuitems
ul=None
menu.add_command(label=ullist[i] + " " + fileName,
command=callback,
underline=ul)
i += 1
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: try:
RFfile.writelines(rfList) rf_file.writelines(rf_list)
finally: finally:
RFfile.close() rf_file.close()
return rfList # for each edit window instance, construct the recent files menu
for instance in self.top.instance_dict.keys():
menu = instance.recent_files_menu
menu.delete(1, END) # clear, and rebuild:
for i, file in zip(count(), rf_list):
file_name = file[0:-1] # zap \n
callback = instance.__recent_file_callback(file_name)
menu.add_command(label=ulchars[i] + " " + file_name,
command=callback,
underline=0)
def __RecentFileCallback(self,fileName): def __recent_file_callback(self, file_name):
def OpenRecentFile(fileName=fileName): def open_recent_file(fn_closure=file_name):
self.io.open(editFile=fileName) self.io.open(editFile=fn_closure)
return OpenRecentFile return open_recent_file
def saved_change_hook(self): def saved_change_hook(self):
short = self.short_title() short = self.short_title()
...@@ -729,7 +713,7 @@ class EditorWindow: ...@@ -729,7 +713,7 @@ class EditorWindow:
def _close(self): def _close(self):
#print self.io.filename #print self.io.filename
if self.io.filename: if self.io.filename:
self.UpdateRecentFilesList(newFile=self.io.filename) self.update_recent_files_list(new_file=self.io.filename)
WindowList.unregister_callback(self.postwindowsmenu) WindowList.unregister_callback(self.postwindowsmenu)
if self.close_hook: if self.close_hook:
self.close_hook() self.close_hook()
......
...@@ -540,7 +540,7 @@ class IOBinding: ...@@ -540,7 +540,7 @@ class IOBinding:
def updaterecentfileslist(self,filename): def updaterecentfileslist(self,filename):
"Update recent file list on all editor windows" "Update recent file list on all editor windows"
self.editwin.UpdateRecentFilesList(filename) self.editwin.update_recent_files_list(filename)
def test(): def test():
root = Tk() root = Tk()
......
...@@ -3,8 +3,11 @@ What's New in IDLE 1.1a0? ...@@ -3,8 +3,11 @@ What's New in IDLE 1.1a0?
*Release date: XX-XXX-2004* *Release date: XX-XXX-2004*
- If nulls somehow got into the strings in recent-files.lst
EditorWindow.update_recent_files_list() was failing. Python Bug 931336.
- If the normal background is changed via Configure/Highlighting, it will update - If the normal background is changed via Configure/Highlighting, it will update
immediately, thanks to the previously mentioned patch. immediately, thanks to the previously mentioned patch by Nigel Rowe.
- Add a highlight theme for builtin keywords. Python Patch 805830 Nigel Rowe - Add a highlight theme for builtin keywords. Python Patch 805830 Nigel Rowe
This also fixed IDLEfork bug [ 693418 ] Normal text background color not refreshed This also fixed IDLEfork bug [ 693418 ] Normal text background color not refreshed
......
...@@ -1157,7 +1157,7 @@ class ConfigDialog(Toplevel): ...@@ -1157,7 +1157,7 @@ class ConfigDialog(Toplevel):
#update theme and repaint #update theme and repaint
#update keybindings and re-bind #update keybindings and re-bind
#update user help sources menu #update user help sources menu
winInstances=self.parent.instanceDict.keys() winInstances=self.parent.instance_dict.keys()
for instance in winInstances: for instance in winInstances:
instance.ResetColorizer() instance.ResetColorizer()
instance.ResetFont() instance.ResetFont()
...@@ -1183,5 +1183,5 @@ if __name__ == '__main__': ...@@ -1183,5 +1183,5 @@ if __name__ == '__main__':
root=Tk() root=Tk()
Button(root,text='Dialog', Button(root,text='Dialog',
command=lambda:ConfigDialog(root,'Settings')).pack() command=lambda:ConfigDialog(root,'Settings')).pack()
root.instanceDict={} root.instance_dict={}
root.mainloop() root.mainloop()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment