22 # Start-Of-Header |
22 # Start-Of-Header |
23 name = "Selection Encloser Plug-in" |
23 name = "Selection Encloser Plug-in" |
24 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
24 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
25 autoactivate = True |
25 autoactivate = True |
26 deactivateable = True |
26 deactivateable = True |
27 version = "2.0.2" |
27 version = "2.1.0" |
28 className = "SelectionEncloserPlugin" |
28 className = "SelectionEncloserPlugin" |
29 packageName = "SelectionEncloser" |
29 packageName = "SelectionEncloser" |
30 shortDescription = "Enclose the selection with a string." |
30 shortDescription = "Enclose the selection with a string." |
31 longDescription = \ |
31 longDescription = \ |
32 """This plug-in implements a tool to enclose the selection of""" \ |
32 """This plug-in implements a tool to enclose the selection of""" \ |
140 |
141 |
141 global selectionEncloserPluginObject |
142 global selectionEncloserPluginObject |
142 selectionEncloserPluginObject = self |
143 selectionEncloserPluginObject = self |
143 |
144 |
144 self.__ui.showMenu.connect(self.__populateMenu) |
145 self.__ui.showMenu.connect(self.__populateMenu) |
|
146 |
|
147 menu = self.__ui.getMenu("plugin_tools") |
|
148 if menu is not None: |
|
149 if not menu.isEmpty(): |
|
150 act = menu.addSeparator() |
|
151 self.__mainActions.append(act) |
|
152 act = menu.addMenu(self.__menu) |
|
153 self.__mainActions.append(act) |
145 |
154 |
146 e5App().getObject("ViewManager").editorOpenedEd.connect( |
155 e5App().getObject("ViewManager").editorOpenedEd.connect( |
147 self.__editorOpened) |
156 self.__editorOpened) |
148 e5App().getObject("ViewManager").editorClosedEd.connect( |
157 e5App().getObject("ViewManager").editorClosedEd.connect( |
149 self.__editorClosed) |
158 self.__editorClosed) |
157 """ |
166 """ |
158 Public method to deactivate this plugin. |
167 Public method to deactivate this plugin. |
159 """ |
168 """ |
160 self.__ui.showMenu.disconnect(self.__populateMenu) |
169 self.__ui.showMenu.disconnect(self.__populateMenu) |
161 |
170 |
|
171 menu = self.__ui.getMenu("plugin_tools") |
|
172 if menu is not None: |
|
173 for act in self.__mainActions: |
|
174 menu.removeAction(act) |
|
175 self.__mainActions = [] |
|
176 |
162 e5App().getObject("ViewManager").editorOpenedEd.disconnect( |
177 e5App().getObject("ViewManager").editorOpenedEd.disconnect( |
163 self.__editorOpened) |
178 self.__editorOpened) |
164 e5App().getObject("ViewManager").editorClosedEd.disconnect( |
179 e5App().getObject("ViewManager").editorClosedEd.disconnect( |
165 self.__editorClosed) |
180 self.__editorClosed) |
166 |
181 |
234 Private slot to populate the tools menu with our entry. |
249 Private slot to populate the tools menu with our entry. |
235 |
250 |
236 @param name name of the menu (string) |
251 @param name name of the menu (string) |
237 @param menu reference to the menu to be populated (QMenu) |
252 @param menu reference to the menu to be populated (QMenu) |
238 """ |
253 """ |
239 if name != "Tools": |
254 if name not in ["Tools", "PluginTools"]: |
240 return |
255 return |
241 |
256 |
242 editor = e5App().getObject("ViewManager").activeWindow() |
257 editor = e5App().getObject("ViewManager").activeWindow() |
243 |
258 |
244 if not menu.isEmpty(): |
259 if name == "Tools": |
245 menu.addSeparator() |
260 if not menu.isEmpty(): |
246 |
261 menu.addSeparator() |
247 act = menu.addMenu(self.__menu) |
262 act = menu.addMenu(self.__menu) |
248 act.setEnabled(editor is not None and editor.hasSelectedText()) |
263 act.setEnabled(editor is not None and editor.hasSelectedText()) |
|
264 elif name == "PluginTools" and self.__mainActions: |
|
265 self.__mainActions[-1].setEnabled(editor is not None and |
|
266 editor.hasSelectedText()) |
249 |
267 |
250 def __editorOpened(self, editor): |
268 def __editorOpened(self, editor): |
251 """ |
269 """ |
252 Private slot called, when a new editor was opened. |
270 Private slot called, when a new editor was opened. |
253 |
271 |