PluginSplitMergeCamelCase.py

changeset 20
8b4c08b95279
parent 19
e245c6797cee
child 22
7845a580e12f
equal deleted inserted replaced
19:e245c6797cee 20:8b4c08b95279
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.4.0" 23 version = "0.5.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""" \
209 editor = e5App().getObject("ViewManager").activeWindow() 209 editor = e5App().getObject("ViewManager").activeWindow()
210 if editor is None: 210 if editor is None:
211 return 211 return
212 212
213 text = editor.selectedText() 213 text = editor.selectedText()
214 newText = re.sub(r"([A-Z])", r" \1", text) 214 if text:
215 if newText.startswith(" "): 215 newText = re.sub(r"([A-Z])", r" \1", text)
216 newText = newText[1:] 216 if newText.startswith(" "):
217 if newText != text: 217 newText = newText[1:]
218 self.__applyChange(newText, editor) 218 if newText != text:
219 self.__applyChange(newText, editor)
219 220
220 def __mergeCamelCase(self): 221 def __mergeCamelCase(self):
221 """ 222 """
222 Private slot to merge the selected text to camel case. 223 Private slot to merge the selected text to camel case.
223 """ 224 """
224 editor = e5App().getObject("ViewManager").activeWindow() 225 editor = e5App().getObject("ViewManager").activeWindow()
225 if editor is None: 226 if editor is None:
226 return 227 return
227 228
228 text = editor.selectedText() 229 text = editor.selectedText()
229 newText = "".join(text.split()) 230 if text:
230 if newText != text: 231 newText = "".join(text.split())
231 self.__applyChange(newText, editor) 232 if newText != text:
233 self.__applyChange(newText, editor)
232 234
233 def __camelCaseToUnderscore(self): 235 def __camelCaseToUnderscore(self):
234 """ 236 """
235 Private slot to convert camel case text to underscore separated text. 237 Private slot to convert camel case text to underscore separated text.
236 """ 238 """
237 editor = e5App().getObject("ViewManager").activeWindow() 239 editor = e5App().getObject("ViewManager").activeWindow()
238 if editor is None: 240 if editor is None:
239 return 241 return
240 242
241 text = editor.selectedText() 243 text = editor.selectedText()
242 newText = re.sub(r"([A-Z])", r"_\1", text).lower() 244 if text:
243 if newText.startswith("_"): 245 newText = re.sub(r"([A-Z])", r"_\1", text).lower()
244 newText = newText[1:] 246 if newText.startswith("_"):
245 if newText != text: 247 newText = newText[1:]
246 self.__applyChange(newText, editor) 248 if newText != text:
249 self.__applyChange(newText, editor)
247 250
248 def __underscoreToCamelCase(self, uppercaseFirst=False): 251 def __underscoreToCamelCase(self, uppercaseFirst=False):
249 """ 252 """
250 Private slot to convert underscore separated text to camel case. 253 Private slot to convert underscore separated text to camel case.
251 254
255 editor = e5App().getObject("ViewManager").activeWindow() 258 editor = e5App().getObject("ViewManager").activeWindow()
256 if editor is None: 259 if editor is None:
257 return 260 return
258 261
259 text = editor.selectedText() 262 text = editor.selectedText()
260 newText = "".join([s.capitalize() for s in text.split("_")]) 263 if text:
261 if not uppercaseFirst: 264 newText = "".join([s.capitalize() for s in text.split("_")])
262 newText = newText[0].lower() + newText[1:] 265 if not uppercaseFirst:
263 if newText != text: 266 newText = newText[0].lower() + newText[1:]
264 self.__applyChange(newText, editor) 267 if newText != text:
268 self.__applyChange(newText, editor)
265 269
266 def __underscoreToCamelCaseUppercaseFirst(self): 270 def __underscoreToCamelCaseUppercaseFirst(self):
267 """ 271 """
268 Private slot to convert underscore separated text to camel case 272 Private slot to convert underscore separated text to camel case
269 upper casing the first character. 273 upper casing the first character.

eric ide

mercurial