src/eric7/QScintilla/Shell.py

branch
eric7
changeset 10619
bd15b5b625cb
parent 10556
b4a75c77f9cd
child 10621
f5631f40c4d9
--- a/src/eric7/QScintilla/Shell.py	Sun Mar 03 15:56:25 2024 +0100
+++ b/src/eric7/QScintilla/Shell.py	Sun Mar 03 16:31:14 2024 +0100
@@ -321,6 +321,10 @@
             self.menu.addAction(self.tr("Configure..."), self.__configure)
             self.menu.addSeparator()
             self.menu.addAction(self.tr("Special Commands Help"), self.__showHelp)
+            self.menu.addSeparator()
+            self.__showSourceAct = self.menu.addAction(
+                self.tr("Show Source"), self.__showSource
+            )
 
             self.customContextMenuRequested.connect(self.__showContextMenu)
         self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
@@ -2119,6 +2123,14 @@
         @type QPoint
         """
         if not self.__windowed:
+            # check, if the cursor is positioned on an exception line
+            # The exception line looks like 'File: /path/of/file.py, Line: 111'.
+            line = self.getCursorPosition()[0]
+            text = self.text(line).strip()
+            self.__showSourceAct.setEnabled(
+                bool(re.search(r'File: (.*?), Line: (\d+)', text))
+            )
+
             self.menu.popup(self.mapToGlobal(pos))
 
     def clear(self):
@@ -2612,7 +2624,7 @@
         self.__helpDialog.show()
 
     #################################################################
-    ## Project Support
+    ## Project Support methods
     #################################################################
 
     def __projectOpened(self):
@@ -2634,6 +2646,22 @@
             self.dbs.startClient(False)
             self.__getBanner()
 
+    #######################################################################
+    ## Tool methods
+    #######################################################################
 
+    def __showSource(self):
+        """
+        Private method to open an editor for an exception line.
+        
+        Note: The exception line looks like 'File: /path/of/file.py, Line: 111'.
+        """
+        line = self.getCursorPosition()[0]
+        text = self.text(line).strip()
+        match = re.search(r'File: (.*?), Line: (\d+)', text)
+        if match:
+            filename = match.group(1)
+            linenumber = int(match.group(2))
+            self.vm.openSourceFile(filename, lineno=linenumber)
 #
 # eflag: noqa = M601

eric ide

mercurial