QScintilla/Editor.py

changeset 2965
d133c7edd88a
parent 2959
86ad8854361b
child 2980
2cb4e3c50b37
equal deleted inserted replaced
2964:84b65fb9e780 2965:d133c7edd88a
129 Constructor 129 Constructor
130 130
131 @param dbs reference to the debug server object 131 @param dbs reference to the debug server object
132 @param fn name of the file to be opened (string). If it is None, 132 @param fn name of the file to be opened (string). If it is None,
133 a new (empty) editor is opened 133 a new (empty) editor is opened
134 @param vm reference to the view manager object (ViewManager.ViewManager) 134 @param vm reference to the view manager object
135 (ViewManager.ViewManager)
135 @param filetype type of the source file (string) 136 @param filetype type of the source file (string)
136 @param editor reference to an Editor object, if this is a cloned view 137 @param editor reference to an Editor object, if this is a cloned view
137 @param tv reference to the task viewer object 138 @param tv reference to the task viewer object
139 @exception IOError raised to indicate an issue accessing the file
138 """ 140 """
139 super().__init__() 141 super().__init__()
140 self.setAttribute(Qt.WA_DeleteOnClose) 142 self.setAttribute(Qt.WA_DeleteOnClose)
141 self.setAttribute(Qt.WA_KeyCompression) 143 self.setAttribute(Qt.WA_KeyCompression)
142 self.setUtf8(True) 144 self.setUtf8(True)
467 469
468 def addClone(self, editor): 470 def addClone(self, editor):
469 """ 471 """
470 Public method to add a clone to our list. 472 Public method to add a clone to our list.
471 473
472 @param clone reference to the cloned editor (Editor) 474 @param editor reference to the cloned editor (Editor)
473 """ 475 """
474 self.__clones.append(editor) 476 self.__clones.append(editor)
475 477
476 editor.editorRenamed.connect(self.fileRenamed) 478 editor.editorRenamed.connect(self.fileRenamed)
477 editor.languageChanged.connect(self.languageChanged) 479 editor.languageChanged.connect(self.languageChanged)
480 482
481 def removeClone(self, editor): 483 def removeClone(self, editor):
482 """ 484 """
483 Public method to remove a clone from our list. 485 Public method to remove a clone from our list.
484 486
485 @param clone reference to the cloned editor (Editor) 487 @param editor reference to the cloned editor (Editor)
486 """ 488 """
487 if editor in self.__clones: 489 if editor in self.__clones:
488 editor.editorRenamed.disconnect(self.fileRenamed) 490 editor.editorRenamed.disconnect(self.fileRenamed)
489 editor.languageChanged.disconnect(self.languageChanged) 491 editor.languageChanged.disconnect(self.languageChanged)
490 editor.eolChanged.disconnect(self.__eolChanged) 492 editor.eolChanged.disconnect(self.__eolChanged)
493 495
494 def __bindName(self, line0): 496 def __bindName(self, line0):
495 """ 497 """
496 Private method to generate a dummy filename for binding a lexer. 498 Private method to generate a dummy filename for binding a lexer.
497 499
498 @param line0 first line of text to use in the generation process (string) 500 @param line0 first line of text to use in the generation process
501 (string)
502 @return dummy file name to be used for binding a lexer (string)
499 """ 503 """
500 bindName = "" 504 bindName = ""
501 line0 = line0.lower() 505 line0 = line0.lower()
502 506
503 # check first line if it does not start with #! 507 # check first line if it does not start with #!
572 """ 576 """
573 return self.miniMenu 577 return self.miniMenu
574 578
575 def __initContextMenu(self): 579 def __initContextMenu(self):
576 """ 580 """
577 Private method used to setup the context menu 581 Private method used to setup the context menu.
578 """ 582 """
579 self.miniMenu = Preferences.getEditor("MiniContextMenu") 583 self.miniMenu = Preferences.getEditor("MiniContextMenu")
580 584
581 self.menuActs = {} 585 self.menuActs = {}
582 self.menu = QMenu() 586 self.menu = QMenu()
736 self.spellingMenu.triggered.connect(self.__contextMenuSpellingTriggered) 740 self.spellingMenu.triggered.connect(self.__contextMenuSpellingTriggered)
737 741
738 def __initContextMenuAutocompletion(self): 742 def __initContextMenuAutocompletion(self):
739 """ 743 """
740 Private method used to setup the Checks context sub menu. 744 Private method used to setup the Checks context sub menu.
745
746 @return reference to the generated menu (QMenu)
741 """ 747 """
742 menu = QMenu(self.trUtf8('Autocomplete')) 748 menu = QMenu(self.trUtf8('Autocomplete'))
743 749
744 self.menuActs["acDynamic"] = \ 750 self.menuActs["acDynamic"] = \
745 menu.addAction(self.trUtf8('dynamic'), 751 menu.addAction(self.trUtf8('dynamic'),
762 return menu 768 return menu
763 769
764 def __initContextMenuChecks(self): 770 def __initContextMenuChecks(self):
765 """ 771 """
766 Private method used to setup the Checks context sub menu. 772 Private method used to setup the Checks context sub menu.
773
774 @return reference to the generated menu (QMenu)
767 """ 775 """
768 menu = QMenu(self.trUtf8('Check')) 776 menu = QMenu(self.trUtf8('Check'))
769 menu.aboutToShow.connect(self.__showContextMenuChecks) 777 menu.aboutToShow.connect(self.__showContextMenuChecks)
770 return menu 778 return menu
771 779
772 def __initContextMenuShow(self): 780 def __initContextMenuShow(self):
773 """ 781 """
774 Private method used to setup the Show context sub menu. 782 Private method used to setup the Show context sub menu.
783
784 @return reference to the generated menu (QMenu)
775 """ 785 """
776 menu = QMenu(self.trUtf8('Show')) 786 menu = QMenu(self.trUtf8('Show'))
777 787
778 menu.addAction(self.trUtf8('Code metrics...'), self.__showCodeMetrics) 788 menu.addAction(self.trUtf8('Code metrics...'), self.__showCodeMetrics)
779 self.coverageMenuAct = \ 789 self.coverageMenuAct = \
792 return menu 802 return menu
793 803
794 def __initContextMenuGraphics(self): 804 def __initContextMenuGraphics(self):
795 """ 805 """
796 Private method used to setup the diagrams context sub menu. 806 Private method used to setup the diagrams context sub menu.
807
808 @return reference to the generated menu (QMenu)
797 """ 809 """
798 menu = QMenu(self.trUtf8('Diagrams')) 810 menu = QMenu(self.trUtf8('Diagrams'))
799 811
800 menu.addAction(self.trUtf8('Class Diagram...'), 812 menu.addAction(self.trUtf8('Class Diagram...'),
801 self.__showClassDiagram) 813 self.__showClassDiagram)
815 return menu 827 return menu
816 828
817 def __initContextMenuLanguages(self): 829 def __initContextMenuLanguages(self):
818 """ 830 """
819 Private method used to setup the Languages context sub menu. 831 Private method used to setup the Languages context sub menu.
832
833 @return reference to the generated menu (QMenu)
820 """ 834 """
821 menu = QMenu(self.trUtf8("Languages")) 835 menu = QMenu(self.trUtf8("Languages"))
822 836
823 self.languagesActGrp = QActionGroup(self) 837 self.languagesActGrp = QActionGroup(self)
824 self.noLanguageAct = menu.addAction(self.trUtf8("No Language")) 838 self.noLanguageAct = menu.addAction(self.trUtf8("No Language"))
856 return menu 870 return menu
857 871
858 def __initContextMenuEncodings(self): 872 def __initContextMenuEncodings(self):
859 """ 873 """
860 Private method used to setup the Encodings context sub menu. 874 Private method used to setup the Encodings context sub menu.
875
876 @return reference to the generated menu (QMenu)
861 """ 877 """
862 self.supportedEncodings = {} 878 self.supportedEncodings = {}
863 879
864 menu = QMenu(self.trUtf8("Encodings")) 880 menu = QMenu(self.trUtf8("Encodings"))
865 881
878 return menu 894 return menu
879 895
880 def __initContextMenuEol(self): 896 def __initContextMenuEol(self):
881 """ 897 """
882 Private method to setup the eol context sub menu. 898 Private method to setup the eol context sub menu.
899
900 @return reference to the generated menu (QMenu)
883 """ 901 """
884 self.supportedEols = {} 902 self.supportedEols = {}
885 903
886 menu = QMenu(self.trUtf8("End-of-Line Type")) 904 menu = QMenu(self.trUtf8("End-of-Line Type"))
887 905
914 return menu 932 return menu
915 933
916 def __initContextMenuExporters(self): 934 def __initContextMenuExporters(self):
917 """ 935 """
918 Private method used to setup the Exporters context sub menu. 936 Private method used to setup the Exporters context sub menu.
937
938 @return reference to the generated menu (QMenu)
919 """ 939 """
920 menu = QMenu(self.trUtf8("Export as")) 940 menu = QMenu(self.trUtf8("Export as"))
921 941
922 from . import Exporters 942 from . import Exporters
923 supportedExporters = Exporters.getSupportedFormats() 943 supportedExporters = Exporters.getSupportedFormats()
930 950
931 return menu 951 return menu
932 952
933 def __initContextMenuMargins(self): 953 def __initContextMenuMargins(self):
934 """ 954 """
935 Private method used to setup the context menu for the margins 955 Private method used to setup the context menu for the margins.
936 """ 956 """
937 self.marginMenuActs = {} 957 self.marginMenuActs = {}
938 958
939 if self.__unifiedMargins: 959 if self.__unifiedMargins:
940 self.__initContextMenuUnifiedMargins() 960 self.__initContextMenuUnifiedMargins()
941 else: 961 else:
942 self.__initContextMenuSeparateMargins() 962 self.__initContextMenuSeparateMargins()
943 963
944 def __initContextMenuSeparateMargins(self): 964 def __initContextMenuSeparateMargins(self):
945 """ 965 """
946 Private method used to setup the context menu for the separated margins 966 Private method used to setup the context menu for the separated margins.
947 """ 967 """
948 # bookmark margin 968 # bookmark margin
949 self.bmMarginMenu = QMenu() 969 self.bmMarginMenu = QMenu()
950 970
951 self.bmMarginMenu.addAction(self.trUtf8('Toggle bookmark'), 971 self.bmMarginMenu.addAction(self.trUtf8('Toggle bookmark'),
1038 1058
1039 self.indicMarginMenu.aboutToShow.connect(self.__showContextMenuMargin) 1059 self.indicMarginMenu.aboutToShow.connect(self.__showContextMenuMargin)
1040 1060
1041 def __initContextMenuUnifiedMargins(self): 1061 def __initContextMenuUnifiedMargins(self):
1042 """ 1062 """
1043 Private method used to setup the context menu for the unified margins 1063 Private method used to setup the context menu for the unified margins.
1044 """ 1064 """
1045 self.marginMenu = QMenu() 1065 self.marginMenu = QMenu()
1046 1066
1047 self.marginMenu.addAction(self.trUtf8('Toggle bookmark'), 1067 self.marginMenu.addAction(self.trUtf8('Toggle bookmark'),
1048 self.menuToggleBookmark) 1068 self.menuToggleBookmark)
1345 1365
1346 def __encodingChanged(self, encoding, propagate=True): 1366 def __encodingChanged(self, encoding, propagate=True):
1347 """ 1367 """
1348 Private slot to handle a change of the encoding. 1368 Private slot to handle a change of the encoding.
1349 1369
1370 @param encoding changed encoding (string)
1350 @keyparam propagate flag indicating to propagate the change (boolean) 1371 @keyparam propagate flag indicating to propagate the change (boolean)
1351 """ 1372 """
1352 self.encoding = encoding 1373 self.encoding = encoding
1353 self.__checkEncoding() 1374 self.__checkEncoding()
1354 1375
1809 lineno = self.markerLine(self.lastHighlight) 1830 lineno = self.markerLine(self.lastHighlight)
1810 self.ensureVisible(lineno + 1) 1831 self.ensureVisible(lineno + 1)
1811 1832
1812 def highlight(self, line=None, error=False, syntaxError=False): 1833 def highlight(self, line=None, error=False, syntaxError=False):
1813 """ 1834 """
1814 Public method to highlight (or de-highlight) a particular line. 1835 Public method to highlight [or de-highlight] a particular line.
1815 1836
1816 @param line line number to highlight (integer) 1837 @param line line number to highlight (integer)
1817 @param error flag indicating whether the error highlight should be used (boolean) 1838 @param error flag indicating whether the error highlight should be
1839 used (boolean)
1818 @param syntaxError flag indicating a syntax error (boolean) 1840 @param syntaxError flag indicating a syntax error (boolean)
1819 """ 1841 """
1820 if line is None: 1842 if line is None:
1821 self.lastHighlight = None 1843 self.lastHighlight = None
1822 if self.lastErrorMarker is not None: 1844 if self.lastErrorMarker is not None:
1909 1931
1910 def __changeBreakPoints(self, startIndex, endIndex): 1932 def __changeBreakPoints(self, startIndex, endIndex):
1911 """ 1933 """
1912 Private slot to set changed breakpoints. 1934 Private slot to set changed breakpoints.
1913 1935
1914 @param indexes indexes of changed breakpoints. 1936 @param startIndex start index of the breakpoints being changed
1937 (QModelIndex)
1938 @param endIndex end index of the breakpoints being changed
1939 (QModelIndex)
1915 """ 1940 """
1916 if not self.inLinesChanged: 1941 if not self.inLinesChanged:
1917 self.__addBreakPoints(QModelIndex(), startIndex.row(), endIndex.row()) 1942 self.__addBreakPoints(QModelIndex(), startIndex.row(), endIndex.row())
1918 1943
1919 def __breakPointDataAboutToBeChanged(self, startIndex, endIndex): 1944 def __breakPointDataAboutToBeChanged(self, startIndex, endIndex):
1920 """ 1945 """
1921 Private slot to handle the dataAboutToBeChanged signal of the breakpoint model. 1946 Private slot to handle the dataAboutToBeChanged signal of the
1947 breakpoint model.
1922 1948
1923 @param startIndex start index of the rows to be changed (QModelIndex) 1949 @param startIndex start index of the rows to be changed (QModelIndex)
1924 @param endIndex end index of the rows to be changed (QModelIndex) 1950 @param endIndex end index of the rows to be changed (QModelIndex)
1925 """ 1951 """
1926 self.__deleteBreakPoints(QModelIndex(), startIndex.row(), endIndex.row()) 1952 self.__deleteBreakPoints(QModelIndex(), startIndex.row(), endIndex.row())
2153 self.__clearBreakpoints(self.fileName) 2179 self.__clearBreakpoints(self.fileName)
2154 2180
2155 def __clearBreakpoints(self, fileName): 2181 def __clearBreakpoints(self, fileName):
2156 """ 2182 """
2157 Private slot to clear all breakpoints. 2183 Private slot to clear all breakpoints.
2184
2185 @param fileName name of the file (string)
2158 """ 2186 """
2159 idxList = [] 2187 idxList = []
2160 for handle, (ln, _, _, _, _) in list(self.breaks.items()): 2188 for handle, (ln, _, _, _, _) in list(self.breaks.items()):
2161 index = self.breakpointModel.getBreakPointIndex(fileName, ln) 2189 index = self.breakpointModel.getBreakPointIndex(fileName, ln)
2162 if index.isValid(): 2190 if index.isValid():
3570 indexEnd = 0 3598 indexEnd = 0
3571 self.setSelection(lineFrom, indexStart, lineTo, indexEnd) 3599 self.setSelection(lineFrom, indexStart, lineTo, indexEnd)
3572 3600
3573 def indentLineOrSelection(self): 3601 def indentLineOrSelection(self):
3574 """ 3602 """
3575 Public slot to indent the current line or current selection 3603 Public slot to indent the current line or current selection.
3576 """ 3604 """
3577 if self.hasSelectedText(): 3605 if self.hasSelectedText():
3578 self.__indentSelection(True) 3606 self.__indentSelection(True)
3579 else: 3607 else:
3580 self.__indentLine(True) 3608 self.__indentLine(True)
3651 self.ensureVisible(self.__lastEditPosition[0]) 3679 self.ensureVisible(self.__lastEditPosition[0])
3652 3680
3653 def gotoMethodClass(self, goUp=False): 3681 def gotoMethodClass(self, goUp=False):
3654 """ 3682 """
3655 Public method to go to the next Python method or class definition. 3683 Public method to go to the next Python method or class definition.
3684
3685 @param goUp flag indicating the move direction (boolean)
3656 """ 3686 """
3657 if self.isPy3File() or self.isPy2File() or self.isRubyFile(): 3687 if self.isPy3File() or self.isPy2File() or self.isRubyFile():
3658 lineNo = self.getCursorPosition()[0] 3688 lineNo = self.getCursorPosition()[0]
3659 line = self.text(lineNo) 3689 line = self.text(lineNo)
3660 if line.strip().startswith(("class ", "def ", "module ")): 3690 if line.strip().startswith(("class ", "def ", "module ")):
5003 self.showingNotcoveredMarkers = False 5033 self.showingNotcoveredMarkers = False
5004 5034
5005 def hasCoverageMarkers(self): 5035 def hasCoverageMarkers(self):
5006 """ 5036 """
5007 Public method to test, if there are coverage markers. 5037 Public method to test, if there are coverage markers.
5038
5039 @return flag indicating the presence of coverage markers (boolean)
5008 """ 5040 """
5009 return len(self.notcoveredMarkers) > 0 5041 return len(self.notcoveredMarkers) > 0
5010 5042
5011 def nextUncovered(self): 5043 def nextUncovered(self):
5012 """ 5044 """
5636 This overwritten method redirects the action to our 5668 This overwritten method redirects the action to our
5637 ViewManager.closeEditor, which in turn calls our closeIt 5669 ViewManager.closeEditor, which in turn calls our closeIt
5638 method. 5670 method.
5639 5671
5640 @param alsoDelete ignored 5672 @param alsoDelete ignored
5673 @return flag indicating a successful close of the editor (boolean)
5641 """ 5674 """
5642 return self.vm.closeEditor(self) 5675 return self.vm.closeEditor(self)
5643 5676
5644 def closeIt(self): 5677 def closeIt(self):
5645 """ 5678 """
5762 for the minimized mode and reset to the full filename for the 5795 for the minimized mode and reset to the full filename for the
5763 other modes. This is to make the editor windows work nicer 5796 other modes. This is to make the editor windows work nicer
5764 with the QWorkspace. 5797 with the QWorkspace.
5765 5798
5766 @param evt the event, that was generated (QEvent) 5799 @param evt the event, that was generated (QEvent)
5767 @return flag indicating if the event could be processed (bool)
5768 """ 5800 """
5769 if evt.type() == QEvent.WindowStateChange and \ 5801 if evt.type() == QEvent.WindowStateChange and \
5770 self.fileName is not None: 5802 self.fileName is not None:
5771 if self.windowState() == Qt.WindowStates(Qt.WindowMinimized): 5803 if self.windowState() == Qt.WindowStates(Qt.WindowMinimized):
5772 cap = os.path.basename(self.fileName) 5804 cap = os.path.basename(self.fileName)
6002 ################################################################# 6034 #################################################################
6003 6035
6004 def __initContextMenuResources(self): 6036 def __initContextMenuResources(self):
6005 """ 6037 """
6006 Private method used to setup the Resources context sub menu. 6038 Private method used to setup the Resources context sub menu.
6039
6040 @return reference to the generated menu (QMenu)
6007 """ 6041 """
6008 menu = QMenu(self.trUtf8('Resources')) 6042 menu = QMenu(self.trUtf8('Resources'))
6009 6043
6010 menu.addAction(self.trUtf8('Add file...'), 6044 menu.addAction(self.trUtf8('Add file...'),
6011 self.__addFileResource) 6045 self.__addFileResource)
6637 elif token == Editor.SyncToken: 6671 elif token == Editor.SyncToken:
6638 self.__processSyncCommand(argsString) 6672 self.__processSyncCommand(argsString)
6639 6673
6640 def __processStartEditCommand(self, argsString): 6674 def __processStartEditCommand(self, argsString):
6641 """ 6675 """
6642 Private slot to process a remote StartEdit command 6676 Private slot to process a remote StartEdit command.
6643 6677
6644 @param argsString string containing the command parameters (string) 6678 @param argsString string containing the command parameters (string)
6645 """ 6679 """
6646 if not self.__inSharedEdit and not self.__inRemoteSharedEdit: 6680 if not self.__inSharedEdit and not self.__inRemoteSharedEdit:
6647 self.__inRemoteSharedEdit = True 6681 self.__inRemoteSharedEdit = True
6684 6718
6685 return "\n".join(commands) + "\n" 6719 return "\n".join(commands) + "\n"
6686 6720
6687 def __processEndEditCommand(self, argsString): 6721 def __processEndEditCommand(self, argsString):
6688 """ 6722 """
6689 Private slot to process a remote EndEdit command 6723 Private slot to process a remote EndEdit command.
6690 6724
6691 @param argsString string containing the command parameters (string) 6725 @param argsString string containing the command parameters (string)
6692 """ 6726 """
6693 commands = argsString.splitlines() 6727 commands = argsString.splitlines()
6694 sep = self.getLineSeparator() 6728 sep = self.getLineSeparator()
6722 6756
6723 self.setCursorPosition(*cur) 6757 self.setCursorPosition(*cur)
6724 6758
6725 def __processRequestSyncCommand(self, argsString): 6759 def __processRequestSyncCommand(self, argsString):
6726 """ 6760 """
6727 Private slot to process a remote RequestSync command 6761 Private slot to process a remote RequestSync command.
6728 6762
6729 @param argsString string containing the command parameters (string) 6763 @param argsString string containing the command parameters (string)
6730 """ 6764 """
6731 if self.__inSharedEdit: 6765 if self.__inSharedEdit:
6732 hash = str( 6766 hash = str(
6738 if hash == argsString: 6772 if hash == argsString:
6739 self.__send(Editor.SyncToken, self.__savedText) 6773 self.__send(Editor.SyncToken, self.__savedText)
6740 6774
6741 def __processSyncCommand(self, argsString): 6775 def __processSyncCommand(self, argsString):
6742 """ 6776 """
6743 Private slot to process a remote Sync command 6777 Private slot to process a remote Sync command.
6744 6778
6745 @param argsString string containing the command parameters (string) 6779 @param argsString string containing the command parameters (string)
6746 """ 6780 """
6747 if self.__isSyncing: 6781 if self.__isSyncing:
6748 cur = self.getCursorPosition() 6782 cur = self.getCursorPosition()

eric ide

mercurial