--- a/IconEditor/IconEditorWindow.py Mon Aug 12 19:41:53 2013 +0200 +++ b/IconEditor/IconEditorWindow.py Mon Aug 12 22:21:53 2013 +0200 @@ -9,10 +9,12 @@ from __future__ import unicode_literals # __IGNORE_WARNING__ +import os + from PyQt4.QtCore import pyqtSignal, Qt, QSize, QSignalMapper, QFileInfo, QFile, \ QEvent from PyQt4.QtGui import QScrollArea, QPalette, QImage, QImageReader, QImageWriter, \ - QKeySequence, qApp, QLabel, QDockWidget, QWhatsThis + QKeySequence, QLabel, QDockWidget, QWhatsThis from E5Gui.E5Action import E5Action, createActionGroup from E5Gui import E5FileDialog, E5MessageBox @@ -38,7 +40,7 @@ windows = [] def __init__(self, fileName="", parent=None, fromEric=False, - initShortcutsOnly=False): + initShortcutsOnly=False, project=None): """ Constructor @@ -48,6 +50,7 @@ eric5 (boolean) @keyparam initShortcutsOnly flag indicating to just initialize the keyboard shortcuts (boolean) + @keyparam project reference to the project object (Project) """ super(IconEditorWindow, self).__init__(parent) self.setObjectName("eric5_icon_editor") @@ -106,6 +109,10 @@ self.__checkActions() + self.__project = project + self.__lastOpenPath = "" + self.__lastSavePath = "" + self.grabGesture(Qt.PinchGesture) def __initFileFilters(self): @@ -275,10 +282,8 @@ """<b>Quit</b>""" """<p>Quit the icon editor.</p>""" )) - if self.fromEric: - self.exitAct.triggered[()].connect(self.close) - else: - self.exitAct.triggered[()].connect(qApp.closeAllWindows) + if not self.fromEric: + self.exitAct.triggered[()].connect(self.__closeAll) self.__actions.append(self.exitAct) def __initEditActions(self): @@ -754,8 +759,9 @@ menu.addSeparator() menu.addAction(self.closeAct) menu.addAction(self.closeAllAct) - menu.addSeparator() - menu.addAction(self.exitAct) + if not self.fromEric: + menu.addSeparator() + menu.addAction(self.exitAct) menu = mb.addMenu(self.trUtf8("&Edit")) menu.setTearOffEnabled(True) @@ -821,7 +827,8 @@ filetb.addAction(self.saveAsAct) filetb.addSeparator() filetb.addAction(self.closeAct) - filetb.addAction(self.exitAct) + if not self.fromEric: + filetb.addAction(self.exitAct) edittb = self.addToolBar(self.trUtf8("Edit")) edittb.setObjectName("EditToolBar") @@ -932,7 +939,8 @@ Preferences.setGeometry("IconEditorGeometry", self.saveGeometry()) try: - del self.__class__.windows[self.__class__.windows.index(self)] + if self.fromEric or len(self.__class__.windows) > 1: + del self.__class__.windows[self.__class__.windows.index(self)] except ValueError: pass @@ -958,7 +966,9 @@ """ Public slot called to open a new icon editor window. """ - ie = IconEditorWindow(parent=self.parent(), fromEric=self.fromEric) + ie = IconEditorWindow(parent=self.parent(), fromEric=self.fromEric, + project=self.__project) + ie.setRecentPaths(self.__lastOpenPath, self.__lastSavePath) ie.show() def __openIcon(self): @@ -966,14 +976,19 @@ Private slot to open an icon file. """ if self.__maybeSave(): + if not self.__lastOpenPath: + if self.__project and self.__project.isOpen(): + self.__lastOpenPath = self.__project.getProjectPath() + fileName = E5FileDialog.getOpenFileNameAndFilter( self, self.trUtf8("Open icon file"), - "", + self.__lastOpenPath, self.__inputFilter, self.__defaultFilter)[0] if fileName: self.__loadIconFile(fileName) + self.__lastOpenPath = os.path.dirname(fileName) self.__checkActions() def __saveIcon(self): @@ -989,10 +1004,16 @@ """ Private slot to save the icon with a new name. """ + if not self.__lastSavePath: + if self.__project and self.__project.isOpen(): + self.__lastSavePath = self.__project.getProjectPath() + if not self.__lastSavePath and self.__lastOpenPath: + self.__lastSavePath = self.__lastOpenPath + fileName, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( self, self.trUtf8("Save icon file"), - "", + self.__lastSavePath, self.__outputFilter, self.__defaultFilter, E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) @@ -1013,6 +1034,8 @@ if not res: return False + self.__lastSavePath = os.path.dirname(fileName) + return self.__saveIconFile(fileName) def __closeAll(self): @@ -1022,6 +1045,7 @@ for win in self.__class__.windows[:]: if win != self: win.close() + self.close() def __loadIconFile(self, fileName): """ @@ -1128,6 +1152,18 @@ return False return True + def setRecentPaths(self, openPath, savePath): + """ + Public method to set the last open and save paths. + + @param openPath least recently used open path (string) + @param savePath least recently used save path (string) + """ + if openPath: + self.__lastOpenPath = openPath + if savePath: + self.__lastSavePath = savePath + def __checkActions(self): """ Private slot to check some actions for their enable/disable status.