dabo Commit
Revision 6137
Date: 2010-10-23 12:03:47 -0700 (Sat, 23 Oct 2010)
Author: Ed
Trac: http://trac.dabodev.com/changeset/6137
Changed:
U trunk/ide/ClassDesigner.py
U trunk/ide/ClassDesignerFormMixin.py
U trunk/ide/ClassDesignerMenu.py
U trunk/ide/Editor.py
Log:
Aded a menu item for "Open Recent" to both the Class Designer and the Editor.
Diff:
Modified: trunk/ide/ClassDesigner.py
===================================================================
--- trunk/ide/ClassDesigner.py 2010-10-23 17:38:43 UTC (rev 6136)
+++ trunk/ide/ClassDesigner.py 2010-10-23 19:03:47 UTC (rev 6137)
@@ -163,7 +163,9 @@
self._recreateValsDict = {}
self._valsDictLIFO = []
# Add this to the persistent MRUs
- self._persistentMRUs[self._customClassCaption] =
self.addCustomClass
+ self.Application._persistentMRUs[self._customClassCaption] =
self.addCustomClass
+ # Persist opened designs, too
+ self.Application._persistentMRUs["OpenRecent"] =
self.onMRUSelection
# Save the default atts for sizers. This way we can distinguish
# from default sizers that can be replaced from customized
# sizers which should remain.
@@ -351,7 +353,7 @@
class DesForm(dfm, base):
_superBase = base
_superMixin = dfm
- _classFile = filepath
+ _classFile = os.path.realpath(filepath)
def __init__(self, parent=None, *args, **kwargs):
self._isMain = formIsMain
if isDialog:
@@ -568,6 +570,28 @@
return ret
+ def addMRUPath(self, pth):
+ """Convenience method for other classes that hides the details
of
+ MRUs from them. All we need is the path.
+ """
+ self.Application.addToMRU(_("Open Recent"),
os.path.realpath(pth), self.onMRUSelection)
+
+
+ def onMRUSelection(self, evt):
+ """The user selected an MRU menu item. Translate that prompt to
the
+ actual path, and open that design.
+ """
+ # The prompt will have a number prepended to the actual path,
+ # separated by a space.
+ pth = evt.prompt.split(" ", 1)[-1]
+ openDesigns = [frm for frm in self.getDesignerWindows()
+ if frm._classFile == pth]
+ if openDesigns:
+ openDesigns[0].bringToFront()
+ else:
+ self.openClass(pth)
+
+
def openClass(self, pth):
"""Called when the user selects the 'Open' menu and selects
a saved XML file. We need to open the file, and confirm that it
is
@@ -578,6 +602,8 @@
self.openingClassXML = True
# Clear any existing superclass info
self._superClassInfo = {}
+ # Add to the MRU list
+ self.addMRUPath(pth)
# Translate the file path into a class dictionary.
clsd = self._importClassXML(pth)
importStatements = clsd.pop("importStatements", "")
@@ -672,7 +698,7 @@
frm.Caption = os.path.splitext(fname)[0]
frm.Controller = self
self.CurrentForm = frm
- frm._classFile = pth
+ frm._classFile = os.path.realpath(pth)
frm._formMode = isFormClass
if isFormClass:
# See if there is any code associated with the form
@@ -2007,7 +2033,7 @@
obj = self.addNewControl(frm.initLayoutPanel, newClass)
frm.Caption = _("Dabo Class Designer: %s") % obj.Name
if pth:
- frm._classFile = pth
+ frm._classFile = os.path.realpath(pth)
frm.Visible = True
dui.callAfter(frm.bringToFront)
dui.callAfter(frm.saveState)
@@ -2367,6 +2393,14 @@
return self.CurrentForm.getObjectHierarchy()
+ def getDesignerWindows(self, frm=None):
+ """Returns a list of the currently open designer surface
windows."""
+ # NOTE: 'dfm' is the ClassDesignerFormMixin class
+ return [win for win in self.uiForms
+ if isinstance(win, dfm)
+ and win is not frm]
+
+
def designerFormClosing(self, frm):
"""Checks to see if there are no more available
ClassDesigner windows. If not, terminate the app.
@@ -2376,10 +2410,7 @@
# May need to explicitly release these.
frm.release()
except: pass
- # NOTE: 'dfm' is the ClassDesignerFormMixin class
- desWindows = [win for win in self.uiForms
- if isinstance(win, dfm)
- and win is not frm]
+ desWindows = self.getDesignerWindows(frm)
if not desWindows:
# No more designer windows left, so exit the app
dui.callAfter(self.onFileExit, None)
Modified: trunk/ide/ClassDesignerFormMixin.py
===================================================================
--- trunk/ide/ClassDesignerFormMixin.py 2010-10-23 17:38:43 UTC (rev 6136)
+++ trunk/ide/ClassDesignerFormMixin.py 2010-10-23 19:03:47 UTC (rev 6137)
@@ -525,6 +525,8 @@
# IOErrorrror that the calling method can catch.
codecs.open(fname, "wb", encoding="utf-8").write(textToSave)
cfName = "%s-code.py" % os.path.splitext(fname)[0]
+ if newFile:
+ self.Controller.addMRUPath(fname)
if singleFile:
# Delete the code file if present.
if os.path.exists(cfName):
Modified: trunk/ide/ClassDesignerMenu.py
===================================================================
--- trunk/ide/ClassDesignerMenu.py 2010-10-23 17:38:43 UTC (rev 6136)
+++ trunk/ide/ClassDesignerMenu.py 2010-10-23 19:03:47 UTC (rev 6137)
@@ -108,6 +108,8 @@
OnHit=app.onSaveDesign,
ItemID="file_save",
help=_("Save the ClassDesigner contents as a
form"))
+ recent = dabo.ui.dMenu(Caption=_("Open Recent"),
MenuID="file_open_recent", MRU=True)
+ fm.prependMenu(recent)
fm.prepend(_("&Open"),
HotKey="Ctrl+O",
OnHit=app.onOpenDesign,
Modified: trunk/ide/Editor.py
===================================================================
--- trunk/ide/Editor.py 2010-10-23 17:38:43 UTC (rev 6136)
+++ trunk/ide/Editor.py 2010-10-23 19:03:47 UTC (rev 6137)
@@ -565,7 +565,6 @@
app = self.Application
mb = self.MenuBar
fileMenu = mb.getMenu("base_file")
- app.onMenuOpenMRU(fileMenu)
editMenu = mb.getMenu("base_edit")
mb.remove(mb.getMenuIndex("base_view"))
@@ -588,6 +587,9 @@
fileMenu.remove(clsItem)
fileMenu.prepend(_("&Close Editor"), HotKey="Ctrl+W",
OnHit=self.onFileClose, bmp="close",
ItemID="file_close_editor", help=_("Close
file"))
+ recentMenu = dabo.ui.dMenu(Caption=_("Open Recent"),
MenuID="file_open_recent",
+ MRU=True)
+ fileMenu.prependMenu(recentMenu)
fileMenu.prepend(_("&Open"), HotKey="Ctrl+O",
OnHit=self.onFileOpen, bmp="open",
ItemID="file_open", help=_("Open file"))
fileMenu.prepend(_("&New"), HotKey="Ctrl+N",
OnHit=self.onFileNew, bmp="new",
@@ -763,14 +765,18 @@
def onFileOpen(self, evt):
- fileName =
self.CurrentEditor.promptForFileName(prompt=_("Open"),
- path=self._lastPath)
- if fileName is not None:
+ fileNames =
self.CurrentEditor.promptForFileName(prompt=_("Open"),
+ path=self._lastPath, multiple=True)
+ if fileNames is None:
+ # They bailed
+ return
+ for fileName in fileNames:
self._lastPath = os.path.split(fileName)[0]
self.Application.setUserSetting("lastPath",
self._lastPath)
self.openFile(fileName)
+ @classmethod
def onMRUSelection(cls, evt):
"""This needs to be a classmethod, since the form
that originally opens a file path might get closed, and
@@ -778,7 +784,9 @@
would barf. So we make this a classmethod, and pass
the call to the first EditorForm instance we can find.
"""
- pth = " ".join(evt.prompt.split(" ")[1:])
+ # The prompt will have a number prepended to the actual path,
+ # separated by a space.
+ pth = evt.prompt.split(" ", 1)[-1]
# Find the topmost form that is an EditorForm
app = dabo.dAppRef
try:
@@ -788,7 +796,6 @@
edf = [frm for frm in app.uiForms
if isinstance(frm, EditorForm)][0]
edf.openFile(pth)
- onMRUSelection = classmethod(onMRUSelection)
def openFile(self, pth, justReportErrors=False):
@@ -807,7 +814,7 @@
raise
if target:
# Add to the MRU list
- self.Application.addToMRU(_("File"), pth,
self.onMRUSelection)
+ self.Application.addToMRU(_("Open Recent"), pth,
self.onMRUSelection)
self.updateLex()
return target
@@ -1104,28 +1111,22 @@
\x00\x00\x00IEND\xaeB`\x82'
-def onFileMRU(evt):
-#- print "MRU EVT", evt
-#- print "APP", dabo.dAppRef
- pass
-
def main():
files = sys.argv[1:]
- app = dabo.dApp()
- app.BasePrefKey = "ide.Editor"
+ app = dabo.dApp(MainFormClass=EditorForm, BasePrefKey="ide.Editor")
app.setAppInfo("appName", _("Dabo Editor"))
app.setAppInfo("appShortName", _("DaboEditor"))
- app._persistentMRUs = {_("File") : onFileMRU}
- app.MainFormClass = None
app.setup()
- frm = app.MainForm = EditorForm()
- frm.onFileNew(None)
- for file in files:
- frm.openFile(file)
- frm.show()
-
+ frm = app.MainForm
+ app._persistentMRUs = {_("Open Recent") : frm.onMRUSelection}
+ def _openForms():
+ frm.onFileNew(None)
+ for file in files:
+ frm.openFile(os.path.realpath(file))
+ frm.show()
+ dabo.ui.callAfter(_openForms)
app.start()
if __name__ == "__main__":
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]