--- a/ProjectPyramid/Project.py Sun May 05 19:27:51 2013 +0200 +++ b/ProjectPyramid/Project.py Thu Jun 20 18:59:13 2013 +0200 @@ -324,6 +324,24 @@ self.__mainMenu = menu return menu + def registerOpenHook(self): + """ + Public method to register the open hook to open a translations file + in a translations editor. + """ + if self.__hooksInstalled: + editor = self.__plugin.getPreferences("TranslationsEditor") + try: + if editor: + self.__translationsBrowser.addHookMethodAndMenuEntry("open", + self.openPOEditor, + self.trUtf8("Open with {0}").format(os.path.basename(editor))) + else: + self.__translationsBrowser.removeHookMethod("open") + except KeyError: + # ignore for older eric5 versions + pass + def projectOpenedHooks(self): """ Public method to add our hook methods. @@ -353,6 +371,8 @@ self.updateSelectedCatalogs, self.trUtf8("Update Selected Catalogs")) self.__hooksInstalled = True + + self.registerOpenHook() def projectClosedHooks(self): """ @@ -369,6 +389,11 @@ self.__translationsBrowser.removeHookMethod("releaseSelected") self.__translationsBrowser.removeHookMethod("generateAll") self.__translationsBrowser.removeHookMethod("generateSelected") + try: + self.__translationsBrowser.removeHookMethod("open") + except KeyError: + # ignore for older eric5 versions + pass self.__translationsBrowser = None self.__hooksInstalled = False @@ -1406,3 +1431,22 @@ res = dia.startBatchProcesses(argsLists, projectPath) if res: dia.exec_() + + def openPOEditor(self, poFile): + """ + Public method to edit the given file in an external .po editor. + + @param poFile name of the .po file (string) + """ + editor = self.__plugin.getPreferences("TranslationsEditor") + if poFile.endswith(".po") and editor: + try: + wd = self.__projectPath() + except PyramidNoProjectSelectedException: + wd = "" + started, pid = QProcess.startDetached(editor, [poFile], wd) + if not started: + E5MessageBox.critical(None, + self.trUtf8('Process Generation Error'), + self.trUtf8('The translations editor process ({0}) could not' + ' be started.').format(os.path.basename(editor)))