diff -r f23c43e18046 -r 906485dcd210 src/eric7/QScintilla/Editor.py --- a/src/eric7/QScintilla/Editor.py Sun Oct 02 11:44:07 2022 +0200 +++ b/src/eric7/QScintilla/Editor.py Sat Oct 29 15:24:59 2022 +0200 @@ -35,27 +35,27 @@ from PyQt6.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog from PyQt6.Qsci import QsciScintilla, QsciMacro, QsciStyledText -from EricWidgets.EricApplication import ericApp -from EricWidgets import EricFileDialog, EricMessageBox -from EricGui.EricOverrideCursor import EricOverrideCursor - -from EricUtilities.EricCache import EricCache +from eric7.EricWidgets.EricApplication import ericApp +from eric7.EricWidgets import EricFileDialog, EricMessageBox +from eric7.EricGui.EricOverrideCursor import EricOverrideCursor + +from eric7.EricUtilities.EricCache import EricCache from .QsciScintillaCompat import QsciScintillaCompat from .EditorMarkerMap import EditorMarkerMap from .SpellChecker import SpellChecker -from Globals import recentNameBreakpointConditions - -import Preferences -import Utilities -from Utilities import MouseUtilities - -import UI.PixmapCache - -from UI import PythonDisViewer - -from CodeFormatting.BlackFormattingAction import BlackFormattingAction +from eric7.Globals import recentNameBreakpointConditions + +from eric7 import Preferences, Utilities +from eric7.Utilities import MouseUtilities + +from eric7.EricGui import EricPixmapCache + +from eric7.UI import PythonDisViewer + +from eric7.CodeFormatting.BlackFormattingAction import BlackFormattingAction +from eric7.CodeFormatting.BlackUtilities import aboutBlack EditorAutoCompletionListID = 1 TemplateCompletionListID = 2 @@ -336,16 +336,16 @@ self.__changeMarkerUnsaved = self.markerDefine( self.__createChangeMarkerPixmap("OnlineChangeTraceMarkerUnsaved") ) - self.breakpoint = self.markerDefine(UI.PixmapCache.getPixmap("break")) - self.cbreakpoint = self.markerDefine(UI.PixmapCache.getPixmap("cBreak")) - self.tbreakpoint = self.markerDefine(UI.PixmapCache.getPixmap("tBreak")) - self.tcbreakpoint = self.markerDefine(UI.PixmapCache.getPixmap("tCBreak")) - self.dbreakpoint = self.markerDefine(UI.PixmapCache.getPixmap("breakDisabled")) - self.bookmark = self.markerDefine(UI.PixmapCache.getPixmap("bookmark16")) - self.syntaxerror = self.markerDefine(UI.PixmapCache.getPixmap("syntaxError")) - self.notcovered = self.markerDefine(UI.PixmapCache.getPixmap("notcovered")) - self.taskmarker = self.markerDefine(UI.PixmapCache.getPixmap("task")) - self.warning = self.markerDefine(UI.PixmapCache.getPixmap("warning")) + self.breakpoint = self.markerDefine(EricPixmapCache.getPixmap("break")) + self.cbreakpoint = self.markerDefine(EricPixmapCache.getPixmap("cBreak")) + self.tbreakpoint = self.markerDefine(EricPixmapCache.getPixmap("tBreak")) + self.tcbreakpoint = self.markerDefine(EricPixmapCache.getPixmap("tCBreak")) + self.dbreakpoint = self.markerDefine(EricPixmapCache.getPixmap("breakDisabled")) + self.bookmark = self.markerDefine(EricPixmapCache.getPixmap("bookmark16")) + self.syntaxerror = self.markerDefine(EricPixmapCache.getPixmap("syntaxError")) + self.notcovered = self.markerDefine(EricPixmapCache.getPixmap("notcovered")) + self.taskmarker = self.markerDefine(EricPixmapCache.getPixmap("task")) + self.warning = self.markerDefine(EricPixmapCache.getPixmap("warning")) # define the line markers if Preferences.getEditor("LineMarkersBackground"): @@ -354,10 +354,10 @@ self.__setLineMarkerColours() else: self.currentline = self.markerDefine( - UI.PixmapCache.getPixmap("currentLineMarker") + EricPixmapCache.getPixmap("currentLineMarker") ) self.errorline = self.markerDefine( - UI.PixmapCache.getPixmap("errorLineMarker") + EricPixmapCache.getPixmap("errorLineMarker") ) self.breakpointMask = ( @@ -398,24 +398,47 @@ self.isResourcesFile = False if editor is None: if self.fileName: - if ( - pathlib.Path(self.fileName).stat().st_size // 1024 - ) > Preferences.getEditor("WarnFilesize"): + if not Utilities.MimeTypes.isTextFile(self.fileName): + EricMessageBox.warning( + None, + self.tr("Open File"), + self.tr( + "<p>The file <b>{0}</b> is not a text file. It will not be" + " opened!</p>" + ).format(self.fileName), + ) + raise OSError() + + fileSizeKB = pathlib.Path(self.fileName).stat().st_size // 1024 + if fileSizeKB > Preferences.getEditor("RejectFilesize"): + EricMessageBox.warning( + None, + self.tr("Open File"), + self.tr( + "<p>The size of the file <b>{0}</b> is <b>{1} KB</b> and" + " exceeds the configured limit of <b>{2} KB</b>. It will" + " not be opened!</p>" + ).format( + self.fileName, + fileSizeKB, + Preferences.getEditor("RejectFilesize"), + ), + ) + raise OSError() + elif fileSizeKB > Preferences.getEditor("WarnFilesize"): res = EricMessageBox.yesNo( - self, + None, self.tr("Open File"), self.tr( """<p>The size of the file <b>{0}</b>""" """ is <b>{1} KB</b>.""" """ Do you really want to load it?</p>""" - ).format( - self.fileName, - pathlib.Path(self.fileName).stat().st_size // 1024, - ), + ).format(self.fileName, fileSizeKB), icon=EricMessageBox.Warning, ) if not res: raise OSError() + self.readFile(self.fileName, True) self.__bindLexer(self.fileName) self.__bindCompleter(self.fileName) @@ -612,45 +635,49 @@ # finale size of the completion images imageSize = QSize(22, 22) - self.registerImage(self.ClassID, UI.PixmapCache.getPixmap("class", imageSize)) + self.registerImage(self.ClassID, EricPixmapCache.getPixmap("class", imageSize)) self.registerImage( self.ClassProtectedID, - UI.PixmapCache.getPixmap("class_protected", imageSize), + EricPixmapCache.getPixmap("class_protected", imageSize), + ) + self.registerImage( + self.ClassPrivateID, EricPixmapCache.getPixmap("class_private", imageSize) ) self.registerImage( - self.ClassPrivateID, UI.PixmapCache.getPixmap("class_private", imageSize) - ) - self.registerImage(self.MethodID, UI.PixmapCache.getPixmap("method", imageSize)) + self.MethodID, EricPixmapCache.getPixmap("method", imageSize) + ) self.registerImage( self.MethodProtectedID, - UI.PixmapCache.getPixmap("method_protected", imageSize), + EricPixmapCache.getPixmap("method_protected", imageSize), ) self.registerImage( - self.MethodPrivateID, UI.PixmapCache.getPixmap("method_private", imageSize) + self.MethodPrivateID, EricPixmapCache.getPixmap("method_private", imageSize) ) self.registerImage( - self.AttributeID, UI.PixmapCache.getPixmap("attribute", imageSize) + self.AttributeID, EricPixmapCache.getPixmap("attribute", imageSize) ) self.registerImage( self.AttributeProtectedID, - UI.PixmapCache.getPixmap("attribute_protected", imageSize), + EricPixmapCache.getPixmap("attribute_protected", imageSize), ) self.registerImage( self.AttributePrivateID, - UI.PixmapCache.getPixmap("attribute_private", imageSize), - ) - self.registerImage(self.EnumID, UI.PixmapCache.getPixmap("enum", imageSize)) + EricPixmapCache.getPixmap("attribute_private", imageSize), + ) + self.registerImage(self.EnumID, EricPixmapCache.getPixmap("enum", imageSize)) self.registerImage( - self.KeywordsID, UI.PixmapCache.getPixmap("keywords", imageSize) - ) - self.registerImage(self.ModuleID, UI.PixmapCache.getPixmap("module", imageSize)) - + self.KeywordsID, EricPixmapCache.getPixmap("keywords", imageSize) + ) self.registerImage( - self.FromDocumentID, UI.PixmapCache.getPixmap("editor", imageSize) + self.ModuleID, EricPixmapCache.getPixmap("module", imageSize) ) self.registerImage( - self.TemplateImageID, UI.PixmapCache.getPixmap("templateViewer", imageSize) + self.FromDocumentID, EricPixmapCache.getPixmap("editor", imageSize) + ) + + self.registerImage( + self.TemplateImageID, EricPixmapCache.getPixmap("templateViewer", imageSize) ) def addClone(self, editor): @@ -830,43 +857,43 @@ self.__menus["SpellCheck"] = self.spellCheckMenu self.menuActs["Undo"] = self.menu.addAction( - UI.PixmapCache.getIcon("editUndo"), self.tr("Undo"), self.undo + EricPixmapCache.getIcon("editUndo"), self.tr("Undo"), self.undo ) self.menuActs["Redo"] = self.menu.addAction( - UI.PixmapCache.getIcon("editRedo"), self.tr("Redo"), self.redo + EricPixmapCache.getIcon("editRedo"), self.tr("Redo"), self.redo ) self.menuActs["Revert"] = self.menu.addAction( self.tr("Revert to last saved state"), self.revertToUnmodified ) self.menu.addSeparator() self.menuActs["Cut"] = self.menu.addAction( - UI.PixmapCache.getIcon("editCut"), self.tr("Cut"), self.cut + EricPixmapCache.getIcon("editCut"), self.tr("Cut"), self.cut ) self.menuActs["Copy"] = self.menu.addAction( - UI.PixmapCache.getIcon("editCopy"), self.tr("Copy"), self.copy + EricPixmapCache.getIcon("editCopy"), self.tr("Copy"), self.copy ) self.menuActs["Paste"] = self.menu.addAction( - UI.PixmapCache.getIcon("editPaste"), self.tr("Paste"), self.paste + EricPixmapCache.getIcon("editPaste"), self.tr("Paste"), self.paste ) if not self.miniMenu: self.menu.addSeparator() self.menu.addAction( - UI.PixmapCache.getIcon("editIndent"), + EricPixmapCache.getIcon("editIndent"), self.tr("Indent"), self.indentLineOrSelection, ) self.menu.addAction( - UI.PixmapCache.getIcon("editUnindent"), + EricPixmapCache.getIcon("editUnindent"), self.tr("Unindent"), self.unindentLineOrSelection, ) self.menuActs["Comment"] = self.menu.addAction( - UI.PixmapCache.getIcon("editComment"), + EricPixmapCache.getIcon("editComment"), self.tr("Comment"), self.commentLineOrSelection, ) self.menuActs["Uncomment"] = self.menu.addAction( - UI.PixmapCache.getIcon("editUncomment"), + EricPixmapCache.getIcon("editUncomment"), self.tr("Uncomment"), self.uncommentLineOrSelection, ) @@ -935,12 +962,12 @@ self.menuActs["Tools"] = self.menu.addMenu(self.toolsMenu) self.menu.addSeparator() self.menu.addAction( - UI.PixmapCache.getIcon("documentNewView"), + EricPixmapCache.getIcon("documentNewView"), self.tr("New Document View"), self.__newView, ) self.menuActs["NewSplit"] = self.menu.addAction( - UI.PixmapCache.getIcon("splitVertical"), + EricPixmapCache.getIcon("splitVertical"), self.tr("New Document View (with new split)"), self.__newViewNewSplit, ) @@ -949,15 +976,15 @@ self.reopenEncodingMenu = self.__initContextMenuReopenWithEncoding() self.menuActs["Reopen"] = self.menu.addMenu(self.reopenEncodingMenu) self.menuActs["Save"] = self.menu.addAction( - UI.PixmapCache.getIcon("fileSave"), self.tr("Save"), self.__contextSave + EricPixmapCache.getIcon("fileSave"), self.tr("Save"), self.__contextSave ) self.menu.addAction( - UI.PixmapCache.getIcon("fileSaveAs"), + EricPixmapCache.getIcon("fileSaveAs"), self.tr("Save As..."), self.__contextSaveAs, ) self.menu.addAction( - UI.PixmapCache.getIcon("fileSaveCopy"), + EricPixmapCache.getIcon("fileSaveCopy"), self.tr("Save Copy..."), self.__contextSaveCopy, ) @@ -1019,6 +1046,10 @@ """ menu = QMenu(self.tr("Code Formatting")) + act = menu.addAction(self.tr("Black"), aboutBlack) + font = act.font() + font.setBold(True) + act.setFont(font) menu.addAction( self.tr("Format Code"), lambda: self.__performFormatWithBlack(BlackFormattingAction.Format), @@ -1092,7 +1123,7 @@ ) menu.addSeparator() menu.addAction( - UI.PixmapCache.getIcon("open"), + EricPixmapCache.getIcon("open"), self.tr("Load Diagram..."), self.__loadDiagram, ) @@ -1112,7 +1143,7 @@ self.languagesActGrp = QActionGroup(self) self.noLanguageAct = menu.addAction( - UI.PixmapCache.getIcon("fileText"), self.tr("Text") + EricPixmapCache.getIcon("fileText"), self.tr("Text") ) self.noLanguageAct.setCheckable(True) self.noLanguageAct.setData("None") @@ -1128,7 +1159,7 @@ if language != "Guessed": self.supportedLanguages[language] = supportedLanguages[language][:2] act = menu.addAction( - UI.PixmapCache.getIcon(supportedLanguages[language][2]), + EricPixmapCache.getIcon(supportedLanguages[language][2]), self.supportedLanguages[language][0], ) act.setCheckable(True) @@ -1182,7 +1213,7 @@ @rtype QMenu """ menu = QMenu(self.tr("Re-Open With Encoding")) - menu.setIcon(UI.PixmapCache.getIcon("open")) + menu.setIcon(EricPixmapCache.getIcon("open")) for encoding in sorted(Utilities.supportedCodecs): act = menu.addAction(encoding) @@ -1205,19 +1236,19 @@ self.eolActGrp = QActionGroup(self) - act = menu.addAction(UI.PixmapCache.getIcon("eolLinux"), self.tr("Unix")) + act = menu.addAction(EricPixmapCache.getIcon("eolLinux"), self.tr("Unix")) act.setCheckable(True) act.setData("\n") self.supportedEols["\n"] = act self.eolActGrp.addAction(act) - act = menu.addAction(UI.PixmapCache.getIcon("eolWindows"), self.tr("Windows")) + act = menu.addAction(EricPixmapCache.getIcon("eolWindows"), self.tr("Windows")) act.setCheckable(True) act.setData("\r\n") self.supportedEols["\r\n"] = act self.eolActGrp.addAction(act) - act = menu.addAction(UI.PixmapCache.getIcon("eolMac"), self.tr("Macintosh")) + act = menu.addAction(EricPixmapCache.getIcon("eolMac"), self.tr("Macintosh")) act.setCheckable(True) act.setData("\r") self.supportedEols["\r"] = act @@ -1236,18 +1267,18 @@ @rtype QMenu """ menu = QMenu(self.tr("Spelling")) - menu.setIcon(UI.PixmapCache.getIcon("spellchecking")) + menu.setIcon(EricPixmapCache.getIcon("spellchecking")) self.spellLanguagesMenu = self.__initContextMenuSpellLanguages() self.__menus["SpellLanguages"] = self.spellLanguagesMenu self.menuActs["SpellCheck"] = menu.addAction( - UI.PixmapCache.getIcon("spellchecking"), + EricPixmapCache.getIcon("spellchecking"), self.tr("Check spelling..."), self.checkSpelling, ) self.menuActs["SpellCheckSelection"] = menu.addAction( - UI.PixmapCache.getIcon("spellchecking"), + EricPixmapCache.getIcon("spellchecking"), self.tr("Check spelling of selection..."), self.__checkSpellingSelection, ) @@ -2589,7 +2620,7 @@ else [] ) - from Debugger.EditBreakpointDialog import EditBreakpointDialog + from eric7.Debugger.EditBreakpointDialog import EditBreakpointDialog dlg = EditBreakpointDialog( (self.fileName, ln), @@ -2921,7 +2952,7 @@ """ Public slot to extract all tasks. """ - from Tasks.Task import Task + from eric7.Tasks.Task import Task markers = { taskType: Preferences.getTasks(markersName).split() @@ -4459,10 +4490,10 @@ self.__setLineMarkerColours() else: self.markerDefine( - UI.PixmapCache.getPixmap("currentLineMarker"), self.currentline + EricPixmapCache.getPixmap("currentLineMarker"), self.currentline ) self.markerDefine( - UI.PixmapCache.getPixmap("errorLineMarker"), self.errorline + EricPixmapCache.getPixmap("errorLineMarker"), self.errorline ) # set the text display @@ -5644,9 +5675,11 @@ splitOrientation = self.vm.getSplitOrientation() if splitOrientation == Qt.Orientation.Horizontal: - self.menuActs["NewSplit"].setIcon(UI.PixmapCache.getIcon("splitHorizontal")) - else: - self.menuActs["NewSplit"].setIcon(UI.PixmapCache.getIcon("splitVertical")) + self.menuActs["NewSplit"].setIcon( + EricPixmapCache.getIcon("splitHorizontal") + ) + else: + self.menuActs["NewSplit"].setIcon(EricPixmapCache.getIcon("splitVertical")) self.menuActs["Tools"].setEnabled(not self.toolsMenu.isEmpty()) @@ -6073,7 +6106,7 @@ if not self.checkDirty(): return - from DataViews.CodeMetricsDialog import CodeMetricsDialog + from eric7.DataViews.CodeMetricsDialog import CodeMetricsDialog self.codemetrics = CodeMetricsDialog() self.codemetrics.show() @@ -6132,7 +6165,7 @@ fn = self.__getCodeCoverageFile() self.__coverageFile = fn if fn: - from DataViews.PyCoverageDialog import PyCoverageDialog + from eric7.DataViews.PyCoverageDialog import PyCoverageDialog self.codecoverage = PyCoverageDialog() self.codecoverage.show() @@ -6296,7 +6329,7 @@ else: return - from DataViews.PyProfileDialog import PyProfileDialog + from eric7.DataViews.PyProfileDialog import PyProfileDialog self.profiledata = PyProfileDialog() self.profiledata.show() @@ -7238,6 +7271,9 @@ """ super().mouseDoubleClickEvent(evt) + # accept all double click events even if not handled by QScintilla + evt.accept() + self.mouseDoubleClick.emit(evt.position().toPoint(), evt.buttons()) def wheelEvent(self, evt): @@ -7593,7 +7629,7 @@ Private method to handle the Add localized resource context menu action. """ - from Project.AddLanguageDialog import AddLanguageDialog + from eric7.Project.AddLanguageDialog import AddLanguageDialog dlg = AddLanguageDialog(self) if dlg.exec() == QDialog.DialogCode.Accepted: @@ -7624,7 +7660,7 @@ """ Private method to handle the Class Diagram context menu action. """ - from Graphics.UMLDialog import UMLDialog, UMLDialogType + from eric7.Graphics.UMLDialog import UMLDialog, UMLDialogType if not self.checkDirty(): return @@ -7642,7 +7678,7 @@ """ Private method to handle the Package Diagram context menu action. """ - from Graphics.UMLDialog import UMLDialog, UMLDialogType + from eric7.Graphics.UMLDialog import UMLDialog, UMLDialogType if not self.checkDirty(): return @@ -7667,7 +7703,7 @@ """ Private method to handle the Imports Diagram context menu action. """ - from Graphics.UMLDialog import UMLDialog, UMLDialogType + from eric7.Graphics.UMLDialog import UMLDialog, UMLDialogType if not self.checkDirty(): return @@ -7691,7 +7727,7 @@ """ Private method to handle the Imports Diagram context menu action. """ - from Graphics.UMLDialog import UMLDialog, UMLDialogType + from eric7.Graphics.UMLDialog import UMLDialog, UMLDialogType res = EricMessageBox.yesNo( self, @@ -7708,7 +7744,7 @@ """ Private slot to load a diagram from file. """ - from Graphics.UMLDialog import UMLDialog, UMLDialogType + from eric7.Graphics.UMLDialog import UMLDialog, UMLDialogType self.loadedDiagram = UMLDialog( UMLDialogType.NO_DIAGRAM, self.project, parent=self @@ -7792,9 +7828,12 @@ else selectedText.lower() ) self.replaceSelectedText(replacementText) - self.setSelection( - startLine, startIndex, endLine, len(replacementText.splitlines()[-1]) + endIndex = ( + startIndex + len(replacementText) + if len(replacementText.splitlines()) <= 1 + else len(replacementText.splitlines()[-1]) ) + self.setSelection(startLine, startIndex, endLine, endIndex) return super().editorCommand(cmd) @@ -8048,7 +8087,7 @@ if suggestions: self.spellingMenu.addSeparator() self.spellingMenu.addAction( - UI.PixmapCache.getIcon("spellchecking"), + EricPixmapCache.getIcon("spellchecking"), self.tr("Check spelling..."), self.__checkSpellingWord, ) @@ -8930,7 +8969,7 @@ docstringMenu = DocstringMenuForEnterOnly(self) act = docstringMenu.addAction( - UI.PixmapCache.getIcon("fileText"), + EricPixmapCache.getIcon("fileText"), self.tr("Generate Docstring"), lambda: generator.insertDocstring(cursorPosition, fromStart=False), ) @@ -9041,8 +9080,10 @@ @param action formatting operation to be performed @type BlackFormattingAction """ - from CodeFormatting.BlackConfigurationDialog import BlackConfigurationDialog - from CodeFormatting.BlackFormattingDialog import BlackFormattingDialog + from eric7.CodeFormatting.BlackConfigurationDialog import ( + BlackConfigurationDialog, + ) + from eric7.CodeFormatting.BlackFormattingDialog import BlackFormattingDialog if not self.isModified() or self.saveFile(): withProject = (