24 # Start-Of-Header |
24 # Start-Of-Header |
25 name = "Refactoring Rope Plugin" |
25 name = "Refactoring Rope Plugin" |
26 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
26 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
27 autoactivate = True |
27 autoactivate = True |
28 deactivateable = True |
28 deactivateable = True |
29 version = "4.0.0" |
29 version = "4.0.1" |
30 className = "RefactoringRopePlugin" |
30 className = "RefactoringRopePlugin" |
31 packageName = "RefactoringRope" |
31 packageName = "RefactoringRope" |
32 internalPackages = "rope" |
32 internalPackages = "rope" |
33 shortDescription = "Refactoring using the Rope library." |
33 shortDescription = "Refactoring using the Rope library." |
34 longDescription = """This plug-in implements refactoring functionality""" \ |
34 longDescription = """This plug-in implements refactoring functionality""" \ |
353 self.__projectIsOpen = enabled |
353 self.__projectIsOpen = enabled |
354 |
354 |
355 for editor in self.__editors: |
355 for editor in self.__editors: |
356 if editor.getLanguage() in lang and \ |
356 if editor.getLanguage() in lang and \ |
357 self.__projectIsOpen: |
357 self.__projectIsOpen: |
358 self.__connectEditorSignals(editor) |
358 self.__connectEditor(editor) |
359 if self.getPreferences("CodeAssistEnabled"): |
|
360 self.__setAutoCompletionHook(editor) |
|
361 if self.getPreferences("CodeAssistCalltipsEnabled"): |
|
362 self.__setCalltipsHook(editor) |
|
363 |
359 |
364 def __projectClosed(self): |
360 def __projectClosed(self): |
365 """ |
361 """ |
366 Private slot to handle the projectClosed signal. |
362 Private slot to handle the projectClosed signal. |
367 """ |
363 """ |
368 self.__mainAct.setEnabled(False) |
364 self.__mainAct.setEnabled(False) |
369 self.__projectIsOpen = False |
365 self.__projectIsOpen = False |
370 |
366 |
371 for editor in self.__editors: |
367 for editor in self.__editors: |
372 self.__disconnectEditorSignals(editor) |
368 self.__editorClosed(editor) |
373 if editor.autoCompletionHook() == self.codeAssist: |
|
374 self.__unsetAutoCompletionHook(editor) |
|
375 if editor.callTipHook() == self.codeAssistCallTip: |
|
376 self.__unsetCalltipsHook(editor) |
|
377 |
369 |
378 def __editorOpened(self, editor): |
370 def __editorOpened(self, editor): |
379 """ |
371 """ |
380 Private slot called, when a new editor was opened. |
372 Private slot called, when a new editor was opened. |
381 |
373 |
382 @param editor reference to the new editor (QScintilla.Editor) |
374 @param editor reference to the new editor (QScintilla.Editor) |
383 """ |
375 """ |
384 lang = self.__determineLanguage() |
376 lang = self.__determineLanguage() |
385 |
377 |
386 if editor.getLanguage() in lang and self.__projectIsOpen: |
378 if self.__projectIsOpen: |
387 self.__connectEditorSignals(editor) |
379 if editor.getLanguage() in lang: |
388 if self.getPreferences("CodeAssistEnabled"): |
380 self.__connectEditor(editor) |
389 self.__setAutoCompletionHook(editor) |
|
390 if self.getPreferences("CodeAssistCalltipsEnabled"): |
|
391 self.__setCalltipsHook(editor) |
|
392 |
381 |
393 editor.languageChanged.connect(self.__editorLanguageChanged) |
382 editor.languageChanged.connect(self.__editorLanguageChanged) |
394 self.__editors.append(editor) |
383 self.__editors.append(editor) |
395 |
384 |
396 def __editorClosed(self, editor): |
385 def __editorClosed(self, editor): |
399 |
388 |
400 @param editor reference to the editor (QScintilla.Editor) |
389 @param editor reference to the editor (QScintilla.Editor) |
401 """ |
390 """ |
402 if editor in self.__editors: |
391 if editor in self.__editors: |
403 editor.languageChanged.disconnect(self.__editorLanguageChanged) |
392 editor.languageChanged.disconnect(self.__editorLanguageChanged) |
404 self.__disconnectEditorSignals(editor) |
393 self.__disconnectEditor(editor) |
405 self.__editors.remove(editor) |
394 self.__editors.remove(editor) |
406 if editor.autoCompletionHook() == self.codeAssist: |
|
407 self.__unsetAutoCompletionHook(editor) |
|
408 if editor.callTipHook() == self.codeAssistCallTip: |
|
409 self.__unsetCalltipsHook(editor) |
|
410 |
395 |
411 def __editorLanguageChanged(self, language): |
396 def __editorLanguageChanged(self, language): |
412 """ |
397 """ |
413 Private slot to handle the language change of an editor. |
398 Private slot to handle the language change of an editor. |
414 |
399 |
416 """ |
401 """ |
417 editor = self.sender() |
402 editor = self.sender() |
418 lang = self.__determineLanguage() |
403 lang = self.__determineLanguage() |
419 |
404 |
420 if language in lang and self.__projectIsOpen: |
405 if language in lang and self.__projectIsOpen: |
421 self.__connectEditorSignals(editor) |
406 self.__connectEditor(editor) |
422 if self.getPreferences("CodeAssistEnabled"): |
|
423 self.__setAutoCompletionHook(editor) |
|
424 if self.getPreferences("CodeAssistCalltipsEnabled"): |
|
425 self.__setCalltipsHook(editor) |
|
426 else: |
407 else: |
427 self.__disconnectEditorSignals(editor) |
408 self.__disconnectEditor(editor) |
428 if editor.autoCompletionHook() == self.codeAssist: |
409 |
429 self.__unsetAutoCompletionHook(editor) |
410 def __connectEditor(self, editor): |
430 if editor.callTipHook() == self.codeAssistCallTip: |
411 """ |
431 self.__unsetCalltipsHook(editor) |
412 Private method to connect an editor. |
432 |
|
433 def __connectEditorSignals(self, editor): |
|
434 """ |
|
435 Private method to connect to some signals of an editor. |
|
436 |
413 |
437 @param editor reference to the editor (QScintilla.Editor) |
414 @param editor reference to the editor (QScintilla.Editor) |
438 """ |
415 """ |
439 editor.editorAboutToBeSaved.connect(self.__editorAboutToBeSaved) |
416 editor.editorAboutToBeSaved.connect(self.__editorAboutToBeSaved) |
440 editor.editorSaved.connect(self.__editorSaved) |
417 editor.editorSaved.connect(self.__editorSaved) |
441 |
418 |
442 def __disconnectEditorSignals(self, editor): |
419 if self.getPreferences("CodeAssistEnabled"): |
443 """ |
420 self.__setAutoCompletionHook(editor) |
444 Private method to disconnect to some signals of an editor. |
421 if self.getPreferences("CodeAssistCalltipsEnabled"): |
445 |
422 self.__setCalltipsHook(editor) |
446 @param editor reference to the editor (QScintilla.Editor) |
423 |
447 """ |
424 def __disconnectEditor(self, editor): |
448 editor.editorAboutToBeSaved.disconnect(self.__editorAboutToBeSaved) |
425 """ |
449 editor.editorSaved.disconnect(self.__editorSaved) |
426 Private method to disconnect an editor. |
|
427 |
|
428 @param editor reference to the editor (QScintilla.Editor) |
|
429 """ |
|
430 try: |
|
431 editor.editorAboutToBeSaved.disconnect(self.__editorAboutToBeSaved) |
|
432 editor.editorSaved.disconnect(self.__editorSaved) |
|
433 except TypeError: |
|
434 # just ignore it |
|
435 pass |
|
436 |
|
437 if editor.autoCompletionHook() == self.codeAssist: |
|
438 self.__unsetAutoCompletionHook(editor) |
|
439 if editor.callTipHook() == self.codeAssistCallTip: |
|
440 self.__unsetCalltipsHook(editor) |
450 |
441 |
451 def __completionListSelected(self, id, txt): |
442 def __completionListSelected(self, id, txt): |
452 """ |
443 """ |
453 Private slot to handle the selection from the completion list. |
444 Private slot to handle the selection from the completion list. |
454 |
445 |
555 |
546 |
556 @param filename name of the file that was saved (string) |
547 @param filename name of the file that was saved (string) |
557 """ |
548 """ |
558 import rope.base.libutils |
549 import rope.base.libutils |
559 |
550 |
560 if filename == self.__savedEditorName and self.__oldEditorText: |
551 try: |
561 rope.base.libutils.report_change(self.__object.getProject(), |
552 if filename == self.__savedEditorName and self.__oldEditorText: |
562 self.__savedEditorName, self.__oldEditorText) |
553 rope.base.libutils.report_change(self.__object.getProject(), |
563 elif self.__savedEditorName == "": |
554 self.__savedEditorName, self.__oldEditorText) |
564 rope.base.libutils.report_change(self.__object.getProject(), |
555 elif self.__savedEditorName == "": |
565 filename, "") |
556 rope.base.libutils.report_change(self.__object.getProject(), |
|
557 filename, "") |
|
558 except RuntimeError: |
|
559 # this could come from trying to do PyQt4/PyQt5 mixed stuff |
|
560 # simply ignore it |
|
561 pass |
566 |
562 |
567 def __setCalltipsHook(self, editor): |
563 def __setCalltipsHook(self, editor): |
568 """ |
564 """ |
569 Private method to set the calltip hook. |
565 Private method to set the calltip hook. |
570 |
566 |