mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Added an "Open Recent" command. Fixes 607810.
This commit is contained in:
parent
f4a9ac25e9
commit
c00b6d7a0a
2 changed files with 46 additions and 0 deletions
|
@ -63,6 +63,7 @@ class Editor(W.Window):
|
||||||
text = f.read()
|
text = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
self._creator, filetype = MacOS.GetCreatorAndType(path)
|
self._creator, filetype = MacOS.GetCreatorAndType(path)
|
||||||
|
self.addrecentfile(path)
|
||||||
else:
|
else:
|
||||||
raise IOError, "file '%s' does not exist" % path
|
raise IOError, "file '%s' does not exist" % path
|
||||||
self.path = path
|
self.path = path
|
||||||
|
@ -399,6 +400,7 @@ class Editor(W.Window):
|
||||||
del linecache.cache[self.path]
|
del linecache.cache[self.path]
|
||||||
import macostools
|
import macostools
|
||||||
macostools.touched(self.path)
|
macostools.touched(self.path)
|
||||||
|
self.addrecentfile(self.path)
|
||||||
|
|
||||||
def can_save(self, menuitem):
|
def can_save(self, menuitem):
|
||||||
return self.editgroup.editor.changed or self.editgroup.editor.selchanged
|
return self.editgroup.editor.changed or self.editgroup.editor.selchanged
|
||||||
|
@ -780,6 +782,10 @@ class Editor(W.Window):
|
||||||
|
|
||||||
def selectline(self, lineno, charoffset = 0):
|
def selectline(self, lineno, charoffset = 0):
|
||||||
self.editgroup.editor.selectline(lineno - 1, charoffset)
|
self.editgroup.editor.selectline(lineno - 1, charoffset)
|
||||||
|
|
||||||
|
def addrecentfile(self, filename):
|
||||||
|
app = W.getapplication()
|
||||||
|
app.addrecentfile(filename)
|
||||||
|
|
||||||
class _saveoptions:
|
class _saveoptions:
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,8 @@ class PythonIDE(Wapplication.Application):
|
||||||
newitem = FrameWork.MenuItem(m, "New", "N", 'new')
|
newitem = FrameWork.MenuItem(m, "New", "N", 'new')
|
||||||
openitem = FrameWork.MenuItem(m, "Open"+ELIPSES, "O", 'open')
|
openitem = FrameWork.MenuItem(m, "Open"+ELIPSES, "O", 'open')
|
||||||
openbynameitem = FrameWork.MenuItem(m, "Open File by Name"+ELIPSES, "D", 'openbyname')
|
openbynameitem = FrameWork.MenuItem(m, "Open File by Name"+ELIPSES, "D", 'openbyname')
|
||||||
|
self.openrecentmenu = FrameWork.SubMenu(m, "Open Recent")
|
||||||
|
self.makeopenrecentmenu()
|
||||||
FrameWork.Separator(m)
|
FrameWork.Separator(m)
|
||||||
closeitem = FrameWork.MenuItem(m, "Close", "W", 'close')
|
closeitem = FrameWork.MenuItem(m, "Close", "W", 'close')
|
||||||
saveitem = FrameWork.MenuItem(m, "Save", "S", 'save')
|
saveitem = FrameWork.MenuItem(m, "Save", "S", 'save')
|
||||||
|
@ -278,11 +280,49 @@ class PythonIDE(Wapplication.Application):
|
||||||
self._openwindowscheckmark = 0
|
self._openwindowscheckmark = 0
|
||||||
self.checkopenwindowsmenu()
|
self.checkopenwindowsmenu()
|
||||||
|
|
||||||
|
def makeopenrecentmenu(self):
|
||||||
|
for i in range(len(self.openrecentmenu.items)):
|
||||||
|
self.openrecentmenu.menu.DeleteMenuItem(1)
|
||||||
|
self.openrecentmenu.items = []
|
||||||
|
prefs = self.getprefs()
|
||||||
|
filelist = prefs.recentfiles
|
||||||
|
if not filelist:
|
||||||
|
self.openrecentmenu.enable(0)
|
||||||
|
return
|
||||||
|
self.openrecentmenu.enable(1)
|
||||||
|
for filename in filelist:
|
||||||
|
item = FrameWork.MenuItem(self.openrecentmenu, filename, None, callback = self.domenu_openrecent)
|
||||||
|
|
||||||
|
def addrecentfile(self, file):
|
||||||
|
prefs = self.getprefs()
|
||||||
|
filelist = prefs.recentfiles
|
||||||
|
if not filelist:
|
||||||
|
filelist = []
|
||||||
|
|
||||||
|
if file in filelist:
|
||||||
|
if file == filelist[0]:
|
||||||
|
return
|
||||||
|
filelist.remove(file)
|
||||||
|
filelist.insert(0, file)
|
||||||
|
filelist = filelist[:10]
|
||||||
|
prefs.recentfiles = filelist
|
||||||
|
prefs.save()
|
||||||
|
self.makeopenrecentmenu()
|
||||||
|
|
||||||
def domenu_openwindows(self, id, item, window, event):
|
def domenu_openwindows(self, id, item, window, event):
|
||||||
w = self._openwindows[item]
|
w = self._openwindows[item]
|
||||||
w.ShowWindow()
|
w.ShowWindow()
|
||||||
w.SelectWindow()
|
w.SelectWindow()
|
||||||
|
|
||||||
|
def domenu_openrecent(self, id, item, window, event):
|
||||||
|
prefs = self.getprefs()
|
||||||
|
filelist = prefs.recentfiles
|
||||||
|
if not filelist:
|
||||||
|
filelist = []
|
||||||
|
item = item - 1
|
||||||
|
filename = filelist[item]
|
||||||
|
self.openscript(filename)
|
||||||
|
|
||||||
def domenu_quit(self):
|
def domenu_quit(self):
|
||||||
self._quit()
|
self._quit()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue