eric6/QScintilla/MiniEditor.py

changeset 7278
1820a0344b62
parent 7267
aedc309827c7
child 7279
d02fe4c17413
--- a/eric6/QScintilla/MiniEditor.py	Fri Sep 27 14:49:42 2019 +0200
+++ b/eric6/QScintilla/MiniEditor.py	Sat Sep 28 18:44:48 2019 +0200
@@ -2344,19 +2344,6 @@
             QApplication.restoreOverrideCursor()
             return
         
-        modified = False
-        
-        if (
-            not self.__getEditorConfig("TabForIndentation") and
-            Preferences.getEditor("ConvertTabsOnLoad") and
-            not (self.lexer_ and
-                 self.lexer_.alwaysKeepTabs())
-        ):
-            txtExpanded = txt.expandtabs(self.__getEditorConfig("TabWidth"))
-            if txtExpanded != txt:
-                modified = True
-                txt = txtExpanded
-        
         self.__textEdit.setText(txt)
         QApplication.restoreOverrideCursor()
         
@@ -2366,8 +2353,10 @@
             self.filetype = filetype
         self.__setCurrentFile(fileName)
         
-        self.__textEdit.setModified(modified)
-        self.setWindowModified(modified)
+        self.__textEdit.setModified(False)
+        self.setWindowModified(False)
+        
+        self.__convertTabs()
         
         eolMode = self.__getEditorConfig("EOLMode", nodefault=True)
         if eolMode is None:
@@ -2377,6 +2366,26 @@
             self.__textEdit.convertEols(eolMode)
         
         self.__statusBar.showMessage(self.tr("File loaded"), 2000)
+    
+    def __convertTabs(self):
+        """
+        Private slot to convert tabulators to spaces.
+        """
+        if (
+            (not self.__getEditorConfig("TabForIndentation")) and
+            Preferences.getEditor("ConvertTabsOnLoad") and
+            not (self.lexer_ and
+                 self.lexer_.alwaysKeepTabs())
+        ):
+            txt = self.__textEdit.text()
+            txtExpanded = txt.expandtabs(self.__getEditorConfig("TabWidth"))
+            if txtExpanded != txt:
+                self.__textEdit.beginUndoAction
+                self.__textEdit.setText(txt)
+                self.__textEdit.endUndoAction()
+                
+                self.__textEdit.setModified(True)
+                self.setWindowModified(True)
 
     def __saveFile(self, fileName):
         """
@@ -2630,13 +2639,14 @@
         if Preferences.getEditor("ShowWhitespace"):
             self.__textEdit.setWhitespaceVisibility(QsciScintilla.WsVisible)
             try:
-                self.setWhitespaceForegroundColor(
+                self.__textEdit.setWhitespaceForegroundColor(
                     Preferences.getEditorColour("WhitespaceForeground"))
-                self.setWhitespaceBackgroundColor(
+                self.__textEdit.setWhitespaceBackgroundColor(
                     Preferences.getEditorColour("WhitespaceBackground"))
-                self.setWhitespaceSize(
+                self.__textEdit.setWhitespaceSize(
                     Preferences.getEditor("WhitespaceSize"))
             except AttributeError:
+                # TODO: is this still needed?
                 # QScintilla before 2.5 doesn't support this
                 pass
         else:
@@ -3037,6 +3047,12 @@
             pyname = language.split("|", 1)[1]
             language = ""
         
+        if not self.filetype:
+            if not language and pyname:
+                self.filetype = pyname
+            else:
+                self.filetype = language
+        
         from . import Lexers
         self.lexer_ = Lexers.getLexer(language, self.__textEdit, pyname=pyname)
         if self.lexer_ is None:
@@ -3463,7 +3479,11 @@
             if nodefault:
                 return None
             else:
-                return Preferences.getEditor(option)
+                value = self.__getOverrideValue(option)
+                if value is None:
+                    # no override
+                    value = Preferences.getEditor(option)
+                return value
         
         try:
             if option == "EOLMode":
@@ -3497,6 +3517,28 @@
         
         if value is None and not nodefault:
             # use Preferences as default in case of error
-            value = Preferences.getEditor(option)
+            value = self.__getOverrideValue(option)
+            if value is None:
+                # no override
+                value = Preferences.getEditor(option)
         
         return value
+    
+    def __getOverrideValue(self, option):
+        """
+        Private method to get an override value for the current file type.
+        
+        @param option Preferences option key
+        @type str
+        @return override value; None in case nothing is defined
+        @rtype any
+        """
+        if option in ("TabWidth", "IndentWidth"):
+            overrides = Preferences.getEditor("TabIndentOverride")
+            if self.filetype in overrides:
+                if option == "TabWidth":
+                    return overrides[self.filetype][0]
+                elif option == "IndentWidth":
+                    return overrides[self.filetype][1]
+        
+        return None

eric ide

mercurial