src/eric7/QScintilla/Editor.py

branch
eric7-maintenance
changeset 10694
f46c1e224e8a
parent 10659
43ead32943ca
parent 10692
9becf9ca115c
child 10733
d96c69a235fc
equal deleted inserted replaced
10662:e6c9ab1dc168 10694:f46c1e224e8a
1040 ) 1040 )
1041 self.menuActs["NewSplit"].setEnabled(self.vm.canSplit()) 1041 self.menuActs["NewSplit"].setEnabled(self.vm.canSplit())
1042 self.menu.addSeparator() 1042 self.menu.addSeparator()
1043 self.reopenEncodingMenu = self.__initContextMenuReopenWithEncoding() 1043 self.reopenEncodingMenu = self.__initContextMenuReopenWithEncoding()
1044 self.menuActs["Reopen"] = self.menu.addMenu(self.reopenEncodingMenu) 1044 self.menuActs["Reopen"] = self.menu.addMenu(self.reopenEncodingMenu)
1045 self.menuActs["Reload"] = self.menu.addAction(
1046 EricPixmapCache.getIcon("reload"), self.tr("Reload"), self.reload
1047 )
1045 self.menuActs["Save"] = self.menu.addAction( 1048 self.menuActs["Save"] = self.menu.addAction(
1046 EricPixmapCache.getIcon("fileSave"), self.tr("Save"), self.__contextSave 1049 EricPixmapCache.getIcon("fileSave"), self.tr("Save"), self.__contextSave
1047 ) 1050 )
1048 self.menu.addAction( 1051 self.menu.addAction(
1049 EricPixmapCache.getIcon("fileSaveAs"), 1052 EricPixmapCache.getIcon("fileSaveAs"),
1639 if language: 1642 if language:
1640 self.filetype = language 1643 self.filetype = language
1641 self.setLanguage(self.supportedLanguages[language][1]) 1644 self.setLanguage(self.supportedLanguages[language][1])
1642 self.checkSyntax() 1645 self.checkSyntax()
1643 1646
1644 self.__docstringGenerator = None 1647 self.resetDocstringGenerator()
1645 1648
1646 def __languageChanged(self, language, propagate=True): 1649 def __languageChanged(self, language, propagate=True):
1647 """ 1650 """
1648 Private method handling a change of a connected editor's language. 1651 Private method handling a change of a connected editor's language.
1649 1652
1662 else: 1665 else:
1663 self.filetype = language 1666 self.filetype = language
1664 self.setLanguage(self.supportedLanguages[language][1], propagate=propagate) 1667 self.setLanguage(self.supportedLanguages[language][1], propagate=propagate)
1665 self.checkSyntax() 1668 self.checkSyntax()
1666 1669
1667 self.__docstringGenerator = None 1670 self.resetDocstringGenerator()
1668 1671
1669 def __resetLanguage(self, propagate=True): 1672 def __resetLanguage(self, propagate=True):
1670 """ 1673 """
1671 Private method used to reset the language selection. 1674 Private method used to reset the language selection.
1672 1675
1691 self.__setMarginsDisplay() 1694 self.__setMarginsDisplay()
1692 self.setMonospaced(useMonospaced) 1695 self.setMonospaced(useMonospaced)
1693 with contextlib.suppress(AttributeError): 1696 with contextlib.suppress(AttributeError):
1694 self.menuActs["MonospacedFont"].setChecked(self.useMonospaced) 1697 self.menuActs["MonospacedFont"].setChecked(self.useMonospaced)
1695 1698
1696 self.__docstringGenerator = None 1699 self.resetDocstringGenerator()
1697 1700
1698 if not self.inLanguageChanged and propagate: 1701 if not self.inLanguageChanged and propagate:
1699 self.inLanguageChanged = True 1702 self.inLanguageChanged = True
1700 self.languageChanged.emit(self.apiLanguage) 1703 self.languageChanged.emit(self.apiLanguage)
1701 self.inLanguageChanged = False 1704 self.inLanguageChanged = False
2412 """ 2415 """
2413 if self.lastHighlight is not None: 2416 if self.lastHighlight is not None:
2414 lineno = self.markerLine(self.lastHighlight) 2417 lineno = self.markerLine(self.lastHighlight)
2415 self.ensureVisible(lineno + 1) 2418 self.ensureVisible(lineno + 1)
2416 2419
2417 def highlight(self, line=None, error=False, syntaxError=False): # noqa: U100 2420 def highlight(self, line=None, error=False):
2418 """ 2421 """
2419 Public method to highlight [or de-highlight] a particular line. 2422 Public method to highlight [or de-highlight] a particular line.
2420 2423
2421 @param line line number to highlight 2424 @param line line number to highlight
2422 @type int 2425 @type int
2423 @param error flag indicating whether the error highlight should be 2426 @param error flag indicating whether the error highlight should be
2424 used 2427 used
2425 @type bool
2426 @param syntaxError flag indicating a syntax error
2427 @type bool 2428 @type bool
2428 """ 2429 """
2429 if line is None: 2430 if line is None:
2430 self.lastHighlight = None 2431 self.lastHighlight = None
2431 if self.lastErrorMarker is not None: 2432 if self.lastErrorMarker is not None:
2463 ## Breakpoint handling methods below 2464 ## Breakpoint handling methods below
2464 ########################################################################### 2465 ###########################################################################
2465 2466
2466 def __modified( 2467 def __modified(
2467 self, 2468 self,
2468 pos, # noqa: U100 2469 _pos,
2469 mtype, 2470 mtype,
2470 text, # noqa: U100 2471 _text,
2471 length, # noqa: U100 2472 _length,
2472 linesAdded, 2473 linesAdded,
2473 line, 2474 line,
2474 foldNow, # noqa: U100 2475 _foldNow,
2475 foldPrev, # noqa: U100 2476 _foldPrev,
2476 token, # noqa: U100 2477 _token,
2477 annotationLinesAdded, # noqa: U100 2478 _annotationLinesAdded,
2478 ): 2479 ):
2479 """ 2480 """
2480 Private method to handle changes of the number of lines. 2481 Private method to handle changes of the number of lines.
2481 2482
2482 @param pos start position of change 2483 @param _pos start position of change (unused)
2483 @type int 2484 @type int
2484 @param mtype flags identifying the change 2485 @param mtype flags identifying the change
2485 @type int 2486 @type int
2486 @param text text that is given to the Undo system 2487 @param _text text that is given to the Undo system (unused)
2487 @type str 2488 @type str
2488 @param length length of the change 2489 @param _length length of the change (unused)
2489 @type int 2490 @type int
2490 @param linesAdded number of added/deleted lines 2491 @param linesAdded number of added/deleted lines
2491 @type int 2492 @type int
2492 @param line line number of a fold level or marker change 2493 @param line line number of a fold level or marker change
2493 @type int 2494 @type int
2494 @param foldNow new fold level 2495 @param _foldNow new fold level (unused)
2495 @type int 2496 @type int
2496 @param foldPrev previous fold level 2497 @param _foldPrev previous fold level (unused)
2497 @type int 2498 @type int
2498 @param token ??? 2499 @param _token ??? (unused)
2499 @type int 2500 @type int
2500 @param annotationLinesAdded number of added/deleted annotation lines 2501 @param _annotationLinesAdded number of added/deleted annotation lines (unused)
2501 @type int 2502 @type int
2502 """ 2503 """
2503 if mtype & (self.SC_MOD_INSERTTEXT | self.SC_MOD_DELETETEXT): 2504 if mtype & (self.SC_MOD_INSERTTEXT | self.SC_MOD_DELETETEXT):
2504 # 1. set/reset the autosave timer 2505 # 1. set/reset the autosave timer
2505 if self.__autosaveInterval > 0: 2506 if self.__autosaveInterval > 0:
3057 printer.setDocName(os.path.basename(fn)) 3058 printer.setDocName(os.path.basename(fn))
3058 else: 3059 else:
3059 printer.setDocName(self.noName) 3060 printer.setDocName(self.noName)
3060 if printDialog.printRange() == QAbstractPrintDialog.PrintRange.Selection: 3061 if printDialog.printRange() == QAbstractPrintDialog.PrintRange.Selection:
3061 # get the selection 3062 # get the selection
3062 fromLine, fromIndex, toLine, toIndex = self.getSelection() 3063 fromLine, _fromIndex, toLine, toIndex = self.getSelection()
3063 if toIndex == 0: 3064 if toIndex == 0:
3064 toLine -= 1 3065 toLine -= 1
3065 # QScintilla seems to print one line more than told 3066 # QScintilla seems to print one line more than told
3066 res = printer.printRange(self, fromLine, toLine - 1) 3067 res = printer.printRange(self, fromLine, toLine - 1)
3067 else: 3068 else:
3959 QsciScintilla.SCI_FOLDCHILDREN, 3960 QsciScintilla.SCI_FOLDCHILDREN,
3960 line - 1, 3961 line - 1,
3961 QsciScintilla.SC_FOLDACTION_EXPAND, 3962 QsciScintilla.SC_FOLDACTION_EXPAND,
3962 ) 3963 )
3963 3964
3964 def __marginClicked(self, margin, line, modifiers): # noqa: U100 3965 def __marginClicked(self, margin, line, _modifiers):
3965 """ 3966 """
3966 Private slot to handle the marginClicked signal. 3967 Private slot to handle the marginClicked signal.
3967 3968
3968 @param margin id of the clicked margin 3969 @param margin id of the clicked margin
3969 @type int 3970 @type int
3970 @param line line number of the click 3971 @param line line number of the click
3971 @type int 3972 @type int
3972 @param modifiers keyboard modifiers 3973 @param _modifiers keyboard modifiers (unused)
3973 @type Qt.KeyboardModifiers 3974 @type Qt.KeyboardModifiers
3974 """ 3975 """
3975 if margin == self.__bmMargin: 3976 if margin == self.__bmMargin:
3976 self.toggleBookmark(line + 1) 3977 self.toggleBookmark(line + 1)
3977 elif margin == self.__bpMargin: 3978 elif margin == self.__bpMargin:
6329 Private slot handling the aboutToShow signal of the context menu. 6330 Private slot handling the aboutToShow signal of the context menu.
6330 """ 6331 """
6331 self.menuActs["Reopen"].setEnabled( 6332 self.menuActs["Reopen"].setEnabled(
6332 not self.isModified() and bool(self.fileName) 6333 not self.isModified() and bool(self.fileName)
6333 ) 6334 )
6335 self.menuActs["Reload"].setEnabled(bool(self.fileName))
6334 self.menuActs["Save"].setEnabled(self.isModified()) 6336 self.menuActs["Save"].setEnabled(self.isModified())
6335 self.menuActs["Undo"].setEnabled(self.isUndoAvailable()) 6337 self.menuActs["Undo"].setEnabled(self.isUndoAvailable())
6336 self.menuActs["Redo"].setEnabled(self.isRedoAvailable()) 6338 self.menuActs["Redo"].setEnabled(self.isRedoAvailable())
6337 self.menuActs["Revert"].setEnabled(self.isModified()) 6339 self.menuActs["Revert"].setEnabled(self.isModified())
6338 self.menuActs["Cut"].setEnabled(self.hasSelectedText()) 6340 self.menuActs["Cut"].setEnabled(self.hasSelectedText())
6822 self.clearSyntaxError() 6824 self.clearSyntaxError()
6823 self.clearFlakesWarnings() 6825 self.clearFlakesWarnings()
6824 6826
6825 error = problems.get("error") 6827 error = problems.get("error")
6826 if error: 6828 if error:
6827 _fn, lineno, col, code, msg = error 6829 _fn, lineno, col, _code, msg = error
6828 self.toggleSyntaxError(lineno, col, True, msg) 6830 self.toggleSyntaxError(lineno, col, True, msg)
6829 6831
6830 for _fn, lineno, col, _code, msg in problems.get("py_warnings", []): 6832 for _fn, lineno, col, _code, msg in problems.get("py_warnings", []):
6831 self.toggleWarning( 6833 self.toggleWarning(
6832 lineno, col, True, msg, warningType=EditorWarningKind.Python 6834 lineno, col, True, msg, warningType=EditorWarningKind.Python
7290 ########################################################################### 7292 ###########################################################################
7291 7293
7292 def toggleWarning( 7294 def toggleWarning(
7293 self, 7295 self,
7294 line, 7296 line,
7295 col, # noqa: U100 7297 _col,
7296 setWarning, 7298 setWarning,
7297 msg="", 7299 msg="",
7298 warningType=EditorWarningKind.Code, 7300 warningType=EditorWarningKind.Code,
7299 ): 7301 ):
7300 """ 7302 """
7302 7304
7303 Note: This method is used to set pyflakes and code style warnings. 7305 Note: This method is used to set pyflakes and code style warnings.
7304 7306
7305 @param line line number of the warning 7307 @param line line number of the warning
7306 @type int 7308 @type int
7307 @param col column of the warning 7309 @param _col column of the warning (unused)
7308 @type int 7310 @type int
7309 @param setWarning flag indicating if the warning marker should be 7311 @param setWarning flag indicating if the warning marker should be
7310 set or deleted 7312 set or deleted
7311 @type bool 7313 @type bool
7312 @param msg warning message 7314 @param msg warning message
8260 self.refresh() 8262 self.refresh()
8261 else: 8263 else:
8262 # do not prompt for this change again... 8264 # do not prompt for this change again...
8263 self.lastModified = pathlib.Path(self.fileName).stat().st_mtime 8265 self.lastModified = pathlib.Path(self.fileName).stat().st_mtime
8264 8266
8267 def getModificationTime(self):
8268 """
8269 Public method to get the time of the latest (saved) modification.
8270
8271 @return time of the latest modification
8272 @rtype int
8273 """
8274 return self.lastModified
8275
8265 @pyqtSlot() 8276 @pyqtSlot()
8266 def recordModificationTime(self): 8277 def recordModificationTime(self):
8267 """ 8278 """
8268 Public slot to record the modification time of our file. 8279 Public slot to record the modification time of our file.
8269 """ 8280 """
8324 self.checkSyntax() 8335 self.checkSyntax()
8325 8336
8326 self.__markerMap.update() 8337 self.__markerMap.update()
8327 8338
8328 self.refreshed.emit() 8339 self.refreshed.emit()
8340
8341 @pyqtSlot()
8342 def reload(self):
8343 """
8344 Public slot to reload the editor contents checking its modification state first.
8345 """
8346 ok = (
8347 EricMessageBox.yesNo(
8348 self,
8349 self.tr("Reload File"),
8350 self.tr(
8351 "<p>The editor contains unsaved modifications.</p>"
8352 "<p><b>Warning:</b> You will lose your changes upon reloading"
8353 " it.</p><p>Shall the editor really be reloaded?</p>"
8354 ),
8355 icon=EricMessageBox.Warning,
8356 )
8357 if self.isModified()
8358 else True
8359 )
8360 if ok:
8361 self.refresh()
8329 8362
8330 def setMonospaced(self, on): 8363 def setMonospaced(self, on):
8331 """ 8364 """
8332 Public method to set/reset a monospaced font. 8365 Public method to set/reset a monospaced font.
8333 8366
9818 9851
9819 ####################################################################### 9852 #######################################################################
9820 ## Methods implementing the docstring generator interface 9853 ## Methods implementing the docstring generator interface
9821 ####################################################################### 9854 #######################################################################
9822 9855
9856 def resetDocstringGenerator(self):
9857 """
9858 Public method to reset the current docstring generator.
9859 """
9860 self.__docstringGenerator = None
9861
9823 def getDocstringGenerator(self): 9862 def getDocstringGenerator(self):
9824 """ 9863 """
9825 Public method to get a reference to the docstring generator. 9864 Public method to get a reference to the docstring generator.
9826 9865
9827 @return reference to the docstring generator 9866 @return reference to the docstring generator

eric ide

mercurial