eric6/QScintilla/Editor.py

changeset 7998
cd41c844862f
parent 7969
62eff8b34a8d
child 8000
47b15df088e4
equal deleted inserted replaced
7997:2ca23396c25c 7998:cd41c844862f
254 self.acAPI = False 254 self.acAPI = False
255 255
256 self.__lastEditPosition = None 256 self.__lastEditPosition = None
257 self.__annotationLines = 0 257 self.__annotationLines = 0
258 258
259 self.__docstringGenerator = None
260
259 # list of clones 261 # list of clones
260 self.__clones = [] 262 self.__clones = []
261 263
262 # clear QScintilla defined keyboard commands 264 # clear QScintilla defined keyboard commands
263 # we do our own handling through the view manager 265 # we do our own handling through the view manager
841 self.menuActs["SpellCheckRemove"] = self.menu.addAction( 843 self.menuActs["SpellCheckRemove"] = self.menu.addAction(
842 self.tr("Remove from dictionary"), 844 self.tr("Remove from dictionary"),
843 self.__removeFromSpellingDictionary) 845 self.__removeFromSpellingDictionary)
844 self.menuActs["SpellCheckLanguages"] = self.menu.addMenu( 846 self.menuActs["SpellCheckLanguages"] = self.menu.addMenu(
845 self.spellLanguagesMenu) 847 self.spellLanguagesMenu)
848 self.menu.addSeparator()
849 self.menuActs["Docstring"] = self.menu.addAction(
850 self.tr("Insert Docstring"),
851 self.__insertDocstring)
846 self.menu.addSeparator() 852 self.menu.addSeparator()
847 self.menu.addAction( 853 self.menu.addAction(
848 self.tr('Shorten empty lines'), self.shortenEmptyLines) 854 self.tr('Shorten empty lines'), self.shortenEmptyLines)
849 self.menu.addSeparator() 855 self.menu.addSeparator()
850 self.menuActs["Languages"] = self.menu.addMenu(self.languagesMenu) 856 self.menuActs["Languages"] = self.menu.addMenu(self.languagesMenu)
4820 if ( 4826 if (
4821 char == "(" and 4827 char == "(" and
4822 Preferences.getDocuViewer("ShowInfoOnOpenParenthesis") 4828 Preferences.getDocuViewer("ShowInfoOnOpenParenthesis")
4823 ): 4829 ):
4824 self.vm.showEditorInfo(self) 4830 self.vm.showEditorInfo(self)
4825 4831
4832 self.__delayedDocstringMenuPopup(self.getCursorPosition())
4833
4826 if self.isListActive(): 4834 if self.isListActive():
4827 if self.__isStartChar(char): 4835 if self.__isStartChar(char):
4828 self.cancelList() 4836 self.cancelList()
4829 self.autoComplete(auto=True, context=True) 4837 self.autoComplete(auto=True, context=True)
4830 return 4838 return
5489 else: 5497 else:
5490 self.menuActs["NewSplit"].setIcon( 5498 self.menuActs["NewSplit"].setIcon(
5491 UI.PixmapCache.getIcon("splitVertical")) 5499 UI.PixmapCache.getIcon("splitVertical"))
5492 5500
5493 self.menuActs["Tools"].setEnabled(not self.toolsMenu.isEmpty()) 5501 self.menuActs["Tools"].setEnabled(not self.toolsMenu.isEmpty())
5502
5503 cline = self.getCursorPosition()[0]
5504 line = self.text(cline)
5505 self.menuActs["Docstring"].setEnabled(
5506 self.getDocstringGenerator().isFunctionStart(line))
5494 5507
5495 self.showMenu.emit("Main", self.menu, self) 5508 self.showMenu.emit("Main", self.menu, self)
5496 5509
5497 def __showContextMenuAutocompletion(self): 5510 def __showContextMenuAutocompletion(self):
5498 """ 5511 """
7092 @param event the mouse press event 7105 @param event the mouse press event
7093 @type QMouseEvent 7106 @type QMouseEvent
7094 """ 7107 """
7095 self.vm.eventFilter(self, event) 7108 self.vm.eventFilter(self, event)
7096 super(Editor, self).mousePressEvent(event) 7109 super(Editor, self).mousePressEvent(event)
7110
7111 def mouseDoubleClickEvent(self, evt):
7112 """
7113 Protected method to handle mouse double click events.
7114
7115 @param evt reference to the mouse event
7116 @type QMouseEvent
7117 """
7118 super(Editor, self).mouseDoubleClickEvent(evt)
7119
7120 self.mouseDoubleClick.emit(evt.pos(), evt.buttons())
7097 7121
7098 def wheelEvent(self, evt): 7122 def wheelEvent(self, evt):
7099 """ 7123 """
7100 Protected method to handle wheel events. 7124 Protected method to handle wheel events.
7101 7125
8619 elif option == "IndentWidth": 8643 elif option == "IndentWidth":
8620 return overrides[language][1] 8644 return overrides[language][1]
8621 8645
8622 return None 8646 return None
8623 8647
8624 def mouseDoubleClickEvent(self, evt): 8648 #######################################################################
8625 """ 8649 ## Methods implementing the docstring generator interface
8626 Protected method to handle mouse double click events. 8650 #######################################################################
8627 8651
8628 @param evt reference to the mouse event 8652 def getDocstringGenerator(self):
8629 @type QMouseEvent 8653 """
8630 """ 8654 Public method to get a reference to the docstring generator.
8631 super(Editor, self).mouseDoubleClickEvent(evt) 8655
8632 8656 @return reference to the docstring generator
8633 self.mouseDoubleClick.emit(evt.pos(), evt.buttons()) 8657 @rtype BaseDocstringGenerator
8658 """
8659 if self.__docstringGenerator is None:
8660 from . import DocstringGenerator
8661 self.__docstringGenerator = (
8662 DocstringGenerator.getDocstringGenerator(self)
8663 )
8664
8665 return self.__docstringGenerator
8666
8667 @pyqtSlot()
8668 def __insertDocstring(self):
8669 """
8670 Private slot to generate and insert a docstring for the function under
8671 the cursor.
8672 """
8673 generator = self.getDocstringGenerator()
8674 generator.insertDocstring(self.getCursorPosition(), fromStart=True)
8675
8676 def __delayedDocstringMenuPopup(self, cursorPosition):
8677 """
8678 Private method to test, if the user might want to insert a docstring.
8679
8680 @param cursorPosition current cursor position (line and column)
8681 @type tuple of (int, int)
8682 """
8683 if self.getDocstringGenerator().isDocstringIntro(cursorPosition):
8684 lineText = self.text(cursorPosition[0])
8685
8686 QTimer.singleShot(
8687 300,
8688 lambda: self.__popupDocstringMenu(lineText, cursorPosition)
8689 )
8690
8691 def __popupDocstringMenu(self, lastLineText, lastCursorPosition):
8692 """
8693 Private slot to pop up a menu asking the user, if a docstring should be
8694 inserted.
8695
8696 @param lastLineText line contents when the delay timer was started
8697 @type str
8698 @param lastCursorPosition position of the cursor when the delay timer
8699 was started (line and index)
8700 @type tuple of (int, int)
8701 """
8702 cursorPosition = self.getCursorPosition()
8703 if lastCursorPosition != cursorPosition:
8704 return
8705
8706 if self.text(cursorPosition[0]) != lastLineText:
8707 return
8708
8709 generator = self.getDocstringGenerator()
8710 if generator.hasFunctionDefinition(cursorPosition):
8711 from .DocstringGenerator.BaseDocstringGenerator import (
8712 DocstringMenuForEnterOnly
8713 )
8714 docstringMenu = DocstringMenuForEnterOnly(self)
8715 act = docstringMenu.addAction(
8716 UI.PixmapCache.getIcon("fileText"),
8717 self.tr("Generate Docstring"),
8718 lambda: generator.insertDocstring(cursorPosition,
8719 fromStart=False)
8720 )
8721 docstringMenu.setActiveAction(act)
8722 docstringMenu.popup(
8723 self.mapToGlobal(self.getGlobalCursorPosition()))

eric ide

mercurial