Mon, 23 Dec 2013 19:52:55 +0100
Added support for the editor Tools context menu (as of eric5 5.4.0).
--- a/ChangeLog Thu Dec 19 15:20:42 2013 +0100 +++ b/ChangeLog Mon Dec 23 19:52:55 2013 +0100 @@ -1,5 +1,8 @@ ChangeLog --------- +Version 0.3.0: +- added support for the editor Tools context menu (as of eric5 5.4.0) + Version 0.2.0: - added Spanish translations provided by Jaime Seuma
--- a/PluginPrintRemover.py Thu Dec 19 15:20:42 2013 +0100 +++ b/PluginPrintRemover.py Mon Dec 23 19:52:55 2013 +0100 @@ -23,7 +23,7 @@ author = "Detlev Offenbach <detlev@die-offenbachs.de>" autoactivate = True deactivateable = True -version = "0.2.0" +version = "0.3.0" className = "PrintRemoverPlugin" packageName = "PrintRemover" shortDescription = "Remove print() like debug statements." @@ -103,6 +103,8 @@ self.__translator = None self.__loadTranslator() + + self.__editors = {} def activate(self): """ @@ -118,6 +120,14 @@ self.__ui.showMenu.connect(self.__populateMenu) + e5App().getObject("ViewManager").editorOpenedEd.connect( + self.__editorOpened) + e5App().getObject("ViewManager").editorClosedEd.connect( + self.__editorClosed) + + for editor in e5App().getObject("ViewManager").getOpenEditors(): + self.__editorOpened(editor) + return None, True def deactivate(self): @@ -125,6 +135,18 @@ Public method to deactivate this plugin. """ self.__ui.showMenu.disconnect(self.__populateMenu) + + e5App().getObject("ViewManager").editorOpenedEd.disconnect( + self.__editorOpened) + e5App().getObject("ViewManager").editorClosedEd.disconnect( + self.__editorClosed) + + for editor, acts in self.__editors.items(): + menu = editor.getMenu("Tools") + if menu is not None: + for act in acts: + menu.removeAction(act) + self.__editors = {} def __loadTranslator(self): """ @@ -194,6 +216,36 @@ self.__removeLine) act.setData(string) + def __editorOpened(self, editor): + """ + Private slot called, when a new editor was opened. + + @param editor reference to the new editor (QScintilla.Editor) + """ + menu = editor.getMenu("Tools") + if menu is not None: + self.__editors[editor] = [] + if not menu.isEmpty(): + act = menu.addSeparator() + self.__editors[editor].append(act) + for string in self.getPreferences("StartswithStrings"): + act = menu.addAction( + self.tr("Remove '{0}'").format(string), + self.__removeLine) + act.setData(string) + self.__editors[editor].append(act) + + def __editorClosed(self, editor): + """ + Private slot called, when an editor was closed. + + @param editor reference to the editor (QScintilla.Editor) + """ + try: + del self.__editors[editor] + except KeyError: + pass + def __removeLine(self): """ Private slot to remove lines starting with the selected pattern.
--- a/PrintRemover/Documentation/source/Plugin_Tools_Print_Remover.PluginPrintRemover.html Thu Dec 19 15:20:42 2013 +0100 +++ b/PrintRemover/Documentation/source/Plugin_Tools_Print_Remover.PluginPrintRemover.html Mon Dec 23 19:52:55 2013 +0100 @@ -69,6 +69,12 @@ <td><a href="#PrintRemoverPlugin.__init__">PrintRemoverPlugin</a></td> <td>Constructor</td> </tr><tr> +<td><a href="#PrintRemoverPlugin.__editorClosed">__editorClosed</a></td> +<td>Private slot called, when an editor was closed.</td> +</tr><tr> +<td><a href="#PrintRemoverPlugin.__editorOpened">__editorOpened</a></td> +<td>Private slot called, when a new editor was opened.</td> +</tr><tr> <td><a href="#PrintRemoverPlugin.__loadTranslator">__loadTranslator</a></td> <td>Private method to load the translation file.</td> </tr><tr> @@ -105,6 +111,26 @@ <dd> reference to the user interface object (UI.UserInterface) </dd> +</dl><a NAME="PrintRemoverPlugin.__editorClosed" ID="PrintRemoverPlugin.__editorClosed"></a> +<h4>PrintRemoverPlugin.__editorClosed</h4> +<b>__editorClosed</b>(<i>editor</i>) +<p> + Private slot called, when an editor was closed. +</p><dl> +<dt><i>editor</i></dt> +<dd> +reference to the editor (QScintilla.Editor) +</dd> +</dl><a NAME="PrintRemoverPlugin.__editorOpened" ID="PrintRemoverPlugin.__editorOpened"></a> +<h4>PrintRemoverPlugin.__editorOpened</h4> +<b>__editorOpened</b>(<i>editor</i>) +<p> + Private slot called, when a new editor was opened. +</p><dl> +<dt><i>editor</i></dt> +<dd> +reference to the new editor (QScintilla.Editor) +</dd> </dl><a NAME="PrintRemoverPlugin.__loadTranslator" ID="PrintRemoverPlugin.__loadTranslator"></a> <h4>PrintRemoverPlugin.__loadTranslator</h4> <b>__loadTranslator</b>(<i></i>)