Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.

Sun, 17 Apr 2011 18:43:02 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 17 Apr 2011 18:43:02 +0200
changeset 991
5ec5e707dfa5
parent 990
93253de2ae77
child 992
566e87428fc8

Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.

APIs/Python3/eric5.api file | annotate | diff | comparison | revisions
Debugger/DebugUI.py file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric5.QScintilla.Editor.html file | annotate | diff | comparison | revisions
QScintilla/Editor.py file | annotate | diff | comparison | revisions
changelog file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric5.api	Fri Apr 15 20:04:55 2011 +0200
+++ b/APIs/Python3/eric5.api	Sun Apr 17 18:43:02 2011 +0200
@@ -5053,6 +5053,7 @@
 eric5.QScintilla.Editor.Editor.coverageMarkersShown?7
 eric5.QScintilla.Editor.Editor.curLineHasBreakpoint?4()
 eric5.QScintilla.Editor.Editor.cursorChanged?7
+eric5.QScintilla.Editor.Editor.determineFileType?4()
 eric5.QScintilla.Editor.Editor.dragEnterEvent?4(event)
 eric5.QScintilla.Editor.Editor.dragLeaveEvent?4(event)
 eric5.QScintilla.Editor.Editor.dragMoveEvent?4(event)
--- a/Debugger/DebugUI.py	Fri Apr 15 20:04:55 2011 +0200
+++ b/Debugger/DebugUI.py	Sun Apr 17 18:43:02 2011 +0200
@@ -1380,7 +1380,7 @@
                     self.excIgnoreList, clearShell)
                 
                 self.lastStartAction = 6
-                self.clientType = ""
+                self.clientType = self.project.getProjectLanguage()
             else:
                 editor = self.viewmanager.activeWindow()
                 if editor is None:
@@ -1393,7 +1393,7 @@
                     
                 fn = editor.getFileName()
                 self.lastStartAction = 5
-                self.clientType = editor.getFileTypeByFlag()
+                self.clientType = editor.determineFileType()
                 
             # save the filename for use by the restart method
             self.lastDebuggedFile = fn
@@ -1487,7 +1487,7 @@
                     self.excIgnoreList, clearShell)
                 
                 self.lastStartAction = 8
-                self.clientType = ""
+                self.clientType = self.project.getProjectLanguage()
             else:
                 editor = self.viewmanager.activeWindow()
                 if editor is None:
@@ -1500,7 +1500,7 @@
                     
                 fn = editor.getFileName()
                 self.lastStartAction = 7
-                self.clientType = editor.getFileTypeByFlag()
+                self.clientType = editor.determineFileType()
                 
             # save the filename for use by the restart method
             self.lastDebuggedFile = fn
@@ -1596,7 +1596,7 @@
                     self.excIgnoreList, clearShell)
                 
                 self.lastStartAction = 4
-                self.clientType = ""
+                self.clientType = self.project.getProjectLanguage()
             else:
                 editor = self.viewmanager.activeWindow()
                 if editor is None:
@@ -1609,7 +1609,7 @@
                     
                 fn = editor.getFileName()
                 self.lastStartAction = 3
-                self.clientType = editor.getFileTypeByFlag()
+                self.clientType = editor.determineFileType()
                 
             # save the filename for use by the restart method
             self.lastDebuggedFile = fn
@@ -1707,7 +1707,7 @@
                     autoContinue=self.autoContinue)
                 
                 self.lastStartAction = 2
-                self.clientType = ""
+                self.clientType = self.project.getProjectLanguage()
             else:
                 editor = self.viewmanager.activeWindow()
                 if editor is None:
@@ -1720,7 +1720,7 @@
                     
                 fn = editor.getFileName()
                 self.lastStartAction = 1
-                self.clientType = editor.getFileTypeByFlag()
+                self.clientType = editor.determineFileType()
             
             # save the filename for use by the restart method
             self.lastDebuggedFile = fn
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Fri Apr 15 20:04:55 2011 +0200
+++ b/Documentation/Help/source.qhp	Sun Apr 17 18:43:02 2011 +0200
@@ -5957,6 +5957,7 @@
       <keyword name="Editor.commentSelection" id="Editor.commentSelection" ref="eric5.QScintilla.Editor.html#Editor.commentSelection" />
       <keyword name="Editor.contextMenuEvent" id="Editor.contextMenuEvent" ref="eric5.QScintilla.Editor.html#Editor.contextMenuEvent" />
       <keyword name="Editor.curLineHasBreakpoint" id="Editor.curLineHasBreakpoint" ref="eric5.QScintilla.Editor.html#Editor.curLineHasBreakpoint" />
+      <keyword name="Editor.determineFileType" id="Editor.determineFileType" ref="eric5.QScintilla.Editor.html#Editor.determineFileType" />
       <keyword name="Editor.dragEnterEvent" id="Editor.dragEnterEvent" ref="eric5.QScintilla.Editor.html#Editor.dragEnterEvent" />
       <keyword name="Editor.dragLeaveEvent" id="Editor.dragLeaveEvent" ref="eric5.QScintilla.Editor.html#Editor.dragLeaveEvent" />
       <keyword name="Editor.dragMoveEvent" id="Editor.dragMoveEvent" ref="eric5.QScintilla.Editor.html#Editor.dragMoveEvent" />
--- a/Documentation/Source/eric5.QScintilla.Editor.html	Fri Apr 15 20:04:55 2011 +0200
+++ b/Documentation/Source/eric5.QScintilla.Editor.html	Sun Apr 17 18:43:02 2011 +0200
@@ -601,6 +601,9 @@
 <td><a href="#Editor.curLineHasBreakpoint">curLineHasBreakpoint</a></td>
 <td>Public method to check for the presence of a breakpoint at the current line.</td>
 </tr><tr>
+<td><a href="#Editor.determineFileType">determineFileType</a></td>
+<td>Public method to determine the file type using various tests.</td>
+</tr><tr>
 <td><a href="#Editor.dragEnterEvent">dragEnterEvent</a></td>
 <td>Protected method to handle the drag enter event.</td>
 </tr><tr>
@@ -2199,6 +2202,16 @@
 <dd>
 flag indicating the presence of a breakpoint (boolean)
 </dd>
+</dl><a NAME="Editor.determineFileType" ID="Editor.determineFileType"></a>
+<h4>Editor.determineFileType</h4>
+<b>determineFileType</b>(<i></i>)
+<p>
+        Public method to determine the file type using various tests.
+</p><dl>
+<dt>Returns:</dt>
+<dd>
+type of the displayed file or an empty string (string)
+</dd>
 </dl><a NAME="Editor.dragEnterEvent" ID="Editor.dragEnterEvent"></a>
 <h4>Editor.dragEnterEvent</h4>
 <b>dragEnterEvent</b>(<i>event</i>)
--- a/QScintilla/Editor.py	Fri Apr 15 20:04:55 2011 +0200
+++ b/QScintilla/Editor.py	Sun Apr 17 18:43:02 2011 +0200
@@ -495,7 +495,7 @@
                 self.filetype = "Python2"
             elif "python" in line0:
                 bindName = "dummy.py"
-                self.filetype = "Python"
+                self.filetype = "Python2"
             elif ("/bash" in line0 or "/sh" in line0):
                 bindName = "dummy.sh"
             elif "ruby" in line0:
@@ -1578,6 +1578,27 @@
         else:
             return ""
         
+    def determineFileType(self):
+        """
+        Public method to determine the file type using various tests.
+        
+        @return type of the displayed file or an empty string (string)
+        """
+        ftype = self.filetype
+        if not ftype:
+            ftype = self.getFileTypeByFlag()
+        if not ftype:
+            if self.isPy2File():
+                ftype = "Python2"
+            elif self.isPy3File():
+                ftype = "Python3"
+            elif self.isRubyFile():
+                ftype = "Ruby"
+            else:
+                ftype = ""
+        
+        return ftype
+        
     def getEncoding(self):
         """
         Public method to return the current encoding.
@@ -1595,13 +1616,20 @@
         if self.filetype in ["Python", "Python2"]:
             return True
         
-        if self.filetype == "" and self.fileName is not None:
-            ext = os.path.splitext(self.fileName)[1]
-            if ext in [".py", ".pyw"] and \
-               Preferences.getProject("DeterminePyFromProject") and \
-               self.project.isOpen() and \
-               self.project.isProjectFile(self.fileName):
-                return self.project.getProjectLanguage() in ["Python", "Python2"]
+        if self.filetype == "":
+            line0 = self.text(0)
+            if line0.startswith("#!") and \
+               ("python2" in line0 or \
+                ("python" in line0 and not "python3" in line0)):
+                return True
+            
+            if self.fileName is not None:
+                ext = os.path.splitext(self.fileName)[1]
+                if ext in [".py", ".pyw"] and \
+                   Preferences.getProject("DeterminePyFromProject") and \
+                   self.project.isOpen() and \
+                   self.project.isProjectFile(self.fileName):
+                    return self.project.getProjectLanguage() in ["Python", "Python2"]
             
             if ext in self.dbs.getExtensions('Python2'):
                 return True
@@ -1617,13 +1645,19 @@
         if self.filetype in ["Python3"]:
             return True
         
-        if self.filetype == "" and self.fileName is not None:
-            ext = os.path.splitext(self.fileName)[1]
-            if ext in [".py", ".pyw"] and \
-               Preferences.getProject("DeterminePyFromProject") and \
-               self.project.isOpen() and \
-               self.project.isProjectFile(self.fileName):
-                return self.project.getProjectLanguage() in ["Python3"]
+        if self.filetype == "":
+            line0 = self.text(0)
+            if line0.startswith("#!") and \
+               "python3" in line0:
+                return True
+            
+            if self.fileName is not None:
+                ext = os.path.splitext(self.fileName)[1]
+                if ext in [".py", ".pyw"] and \
+                   Preferences.getProject("DeterminePyFromProject") and \
+                   self.project.isOpen() and \
+                   self.project.isProjectFile(self.fileName):
+                    return self.project.getProjectLanguage() in ["Python3"]
             
             if ext in self.dbs.getExtensions('Python3'):
                 return True
@@ -1636,10 +1670,20 @@
         
         @return flag indicating a Ruby file (boolean)
         """
-        return self.filetype == "Ruby" or \
-            (self.filetype == "" and \
-             self.fileName is not None and \
-             os.path.splitext(self.fileName)[1] in self.dbs.getExtensions('Ruby'))
+        if self.filetype == "Ruby":
+            return True
+        
+        if self.filetype == "":
+            line0 = self.text(0)
+            if line0.startswith("#!") and \
+               "ruby" in line0:
+                return True
+            
+            if self.fileName is not None and \
+               os.path.splitext(self.fileName)[1] in self.dbs.getExtensions('Ruby'):
+                return True
+        
+        return False
         
     def highlightVisible(self):
         """
--- a/changelog	Fri Apr 15 20:04:55 2011 +0200
+++ b/changelog	Sun Apr 17 18:43:02 2011 +0200
@@ -21,6 +21,8 @@
   during a project tasks scan
 - added an action to push a new named branch to the Mercurial plug-in
 - added an interface to VirusTotal to the web browser
+- changed algorithm to determine the debugger backend type to be used by
+  analysing a first line starting with '#!'
 
 Version 5.1-snapshot-20110123:
 - bug fixes

eric ide

mercurial