PluginSplitMergeCamelCase.py

changeset 10
97dd3b380cfd
parent 6
98590f1781bc
child 13
78a70b22b350
equal deleted inserted replaced
9:ad42404ad714 10:97dd3b380cfd
18 # Start-Of-Header 18 # Start-Of-Header
19 name = "Camel Case Handling Plug-in" 19 name = "Camel Case Handling Plug-in"
20 author = "Detlev Offenbach <detlev@die-offenbachs.de>" 20 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
21 autoactivate = True 21 autoactivate = True
22 deactivateable = True 22 deactivateable = True
23 version = "0.2.0" 23 version = "0.3.0"
24 className = "SplitMergeCamelCasePlugin" 24 className = "SplitMergeCamelCasePlugin"
25 packageName = "SplitMergeCamelCase" 25 packageName = "SplitMergeCamelCase"
26 shortDescription = "Split, merge or convert camel case text" 26 shortDescription = "Split, merge or convert camel case text"
27 longDescription = \ 27 longDescription = \
28 """This plug-in implements a tool to split, merge or convert""" \ 28 """This plug-in implements a tool to split, merge or convert""" \
51 51
52 self.__translator = None 52 self.__translator = None
53 self.__loadTranslator() 53 self.__loadTranslator()
54 54
55 self.__initMenu() 55 self.__initMenu()
56
57 self.__editors = {}
56 58
57 def activate(self): 59 def activate(self):
58 """ 60 """
59 Public method to activate this plugin. 61 Public method to activate this plugin.
60 62
63 global error 65 global error
64 error = "" # clear previous error 66 error = "" # clear previous error
65 67
66 self.__ui.showMenu.connect(self.__populateMenu) 68 self.__ui.showMenu.connect(self.__populateMenu)
67 69
70 e5App().getObject("ViewManager").editorOpenedEd.connect(
71 self.__editorOpened)
72 e5App().getObject("ViewManager").editorClosedEd.connect(
73 self.__editorClosed)
74
75 for editor in e5App().getObject("ViewManager").getOpenEditors():
76 self.__editorOpened(editor)
77
68 return None, True 78 return None, True
69 79
70 def deactivate(self): 80 def deactivate(self):
71 """ 81 """
72 Public method to deactivate this plugin. 82 Public method to deactivate this plugin.
73 """ 83 """
74 self.__ui.showMenu.disconnect(self.__populateMenu) 84 self.__ui.showMenu.disconnect(self.__populateMenu)
85
86 e5App().getObject("ViewManager").editorOpenedEd.disconnect(
87 self.__editorOpened)
88 e5App().getObject("ViewManager").editorClosedEd.disconnect(
89 self.__editorClosed)
90
91 for editor, act in self.__editors.items():
92 editor.showMenu.disconnect(self.__editorShowMenu)
93 menu = editor.getMenu("Tools")
94 if menu is not None:
95 menu.removeAction(act)
96 self.__editors = {}
75 97
76 def __loadTranslator(self): 98 def __loadTranslator(self):
77 """ 99 """
78 Private method to load the translation file. 100 Private method to load the translation file.
79 """ 101 """
128 menu.addSeparator() 150 menu.addSeparator()
129 151
130 act = menu.addMenu(self.__menu) 152 act = menu.addMenu(self.__menu)
131 act.setEnabled(editor.hasSelectedText()) 153 act.setEnabled(editor.hasSelectedText())
132 154
155 def __editorOpened(self, editor):
156 """
157 Private slot called, when a new editor was opened.
158
159 @param editor reference to the new editor (QScintilla.Editor)
160 """
161 menu = editor.getMenu("Tools")
162 if menu is not None:
163 act = menu.addMenu(self.__menu)
164 editor.showMenu.connect(self.__editorShowMenu)
165 self.__editors[editor] = act
166
167 def __editorClosed(self, editor):
168 """
169 Private slot called, when an editor was closed.
170
171 @param editor reference to the editor (QScintilla.Editor)
172 """
173 try:
174 del self.__editors[editor]
175 except KeyError:
176 pass
177
178 def __editorShowMenu(self, menuName, menu, editor):
179 """
180 Private slot called, when the the editor context menu or a submenu is
181 about to be shown.
182
183 @param menuName name of the menu to be shown (string)
184 @param menu reference to the menu (QMenu)
185 @param editor reference to the editor
186 """
187 if menuName == "Tools":
188 self.__menu.setEnabled(editor.hasSelectedText())
189
133 def __applyChange(self, newText, editor): 190 def __applyChange(self, newText, editor):
134 """ 191 """
135 Private method to change the selected text. 192 Private method to change the selected text.
136 193
137 @param newText new (converted) text (string) 194 @param newText new (converted) text (string)

eric ide

mercurial