21 # Start-Of-Header |
21 # Start-Of-Header |
22 name = "Print Remover Plug-in" |
22 name = "Print Remover Plug-in" |
23 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
23 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
24 autoactivate = True |
24 autoactivate = True |
25 deactivateable = True |
25 deactivateable = True |
26 version = "0.2.0" |
26 version = "0.3.0" |
27 className = "PrintRemoverPlugin" |
27 className = "PrintRemoverPlugin" |
28 packageName = "PrintRemover" |
28 packageName = "PrintRemover" |
29 shortDescription = "Remove print() like debug statements." |
29 shortDescription = "Remove print() like debug statements." |
30 longDescription = \ |
30 longDescription = \ |
31 """This plug-in implements a tool to remove lines starting with""" \ |
31 """This plug-in implements a tool to remove lines starting with""" \ |
101 "print(", "print ", "console.log"], |
101 "print(", "print ", "console.log"], |
102 } |
102 } |
103 |
103 |
104 self.__translator = None |
104 self.__translator = None |
105 self.__loadTranslator() |
105 self.__loadTranslator() |
|
106 |
|
107 self.__editors = {} |
106 |
108 |
107 def activate(self): |
109 def activate(self): |
108 """ |
110 """ |
109 Public method to activate this plugin. |
111 Public method to activate this plugin. |
110 |
112 |
116 global printRemoverPluginObject |
118 global printRemoverPluginObject |
117 printRemoverPluginObject = self |
119 printRemoverPluginObject = self |
118 |
120 |
119 self.__ui.showMenu.connect(self.__populateMenu) |
121 self.__ui.showMenu.connect(self.__populateMenu) |
120 |
122 |
|
123 e5App().getObject("ViewManager").editorOpenedEd.connect( |
|
124 self.__editorOpened) |
|
125 e5App().getObject("ViewManager").editorClosedEd.connect( |
|
126 self.__editorClosed) |
|
127 |
|
128 for editor in e5App().getObject("ViewManager").getOpenEditors(): |
|
129 self.__editorOpened(editor) |
|
130 |
121 return None, True |
131 return None, True |
122 |
132 |
123 def deactivate(self): |
133 def deactivate(self): |
124 """ |
134 """ |
125 Public method to deactivate this plugin. |
135 Public method to deactivate this plugin. |
126 """ |
136 """ |
127 self.__ui.showMenu.disconnect(self.__populateMenu) |
137 self.__ui.showMenu.disconnect(self.__populateMenu) |
|
138 |
|
139 e5App().getObject("ViewManager").editorOpenedEd.disconnect( |
|
140 self.__editorOpened) |
|
141 e5App().getObject("ViewManager").editorClosedEd.disconnect( |
|
142 self.__editorClosed) |
|
143 |
|
144 for editor, acts in self.__editors.items(): |
|
145 menu = editor.getMenu("Tools") |
|
146 if menu is not None: |
|
147 for act in acts: |
|
148 menu.removeAction(act) |
|
149 self.__editors = {} |
128 |
150 |
129 def __loadTranslator(self): |
151 def __loadTranslator(self): |
130 """ |
152 """ |
131 Private method to load the translation file. |
153 Private method to load the translation file. |
132 """ |
154 """ |
192 act = menu.addAction( |
214 act = menu.addAction( |
193 self.tr("Remove '{0}'").format(string), |
215 self.tr("Remove '{0}'").format(string), |
194 self.__removeLine) |
216 self.__removeLine) |
195 act.setData(string) |
217 act.setData(string) |
196 |
218 |
|
219 def __editorOpened(self, editor): |
|
220 """ |
|
221 Private slot called, when a new editor was opened. |
|
222 |
|
223 @param editor reference to the new editor (QScintilla.Editor) |
|
224 """ |
|
225 menu = editor.getMenu("Tools") |
|
226 if menu is not None: |
|
227 self.__editors[editor] = [] |
|
228 if not menu.isEmpty(): |
|
229 act = menu.addSeparator() |
|
230 self.__editors[editor].append(act) |
|
231 for string in self.getPreferences("StartswithStrings"): |
|
232 act = menu.addAction( |
|
233 self.tr("Remove '{0}'").format(string), |
|
234 self.__removeLine) |
|
235 act.setData(string) |
|
236 self.__editors[editor].append(act) |
|
237 |
|
238 def __editorClosed(self, editor): |
|
239 """ |
|
240 Private slot called, when an editor was closed. |
|
241 |
|
242 @param editor reference to the editor (QScintilla.Editor) |
|
243 """ |
|
244 try: |
|
245 del self.__editors[editor] |
|
246 except KeyError: |
|
247 pass |
|
248 |
197 def __removeLine(self): |
249 def __removeLine(self): |
198 """ |
250 """ |
199 Private slot to remove lines starting with the selected pattern. |
251 Private slot to remove lines starting with the selected pattern. |
200 """ |
252 """ |
201 act = self.sender() |
253 act = self.sender() |