src/eric7/Project/ProjectBaseBrowser.py

branch
eric7
changeset 10256
1b728f26d1ae
parent 10069
435cc5875135
child 10398
ef1ea18994d5
--- a/src/eric7/Project/ProjectBaseBrowser.py	Tue Oct 24 11:45:39 2023 +0200
+++ b/src/eric7/Project/ProjectBaseBrowser.py	Wed Oct 25 14:30:33 2023 +0200
@@ -25,7 +25,12 @@
 from eric7.EricWidgets import EricMessageBox
 from eric7.EricWidgets.EricApplication import ericApp
 from eric7.UI.Browser import Browser
-from eric7.UI.BrowserModel import BrowserDirectoryItem, BrowserFileItem
+from eric7.UI.BrowserModel import (
+    BrowserClassItem,
+    BrowserDirectoryItem,
+    BrowserFileItem,
+    BrowserMethodItem,
+)
 from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
 
 from .ProjectBrowserModel import (
@@ -706,6 +711,32 @@
         itm = self.model().item(self.currentIndex())
         return itm
 
+    def currentDirectory(self, relative=False):
+        """
+        Public method to determine the directory of the currently selected entry.
+
+        @param relative flag indicating to return the directory as a relative path
+        @type bool
+        @return directory of the current entry
+        @rtype str
+        """
+        itm = self.model().item(self.currentIndex())
+        if isinstance(
+            itm, (ProjectBrowserFileItem, BrowserClassItem, BrowserMethodItem)
+        ):
+            dn = os.path.dirname(itm.fileName())
+        elif isinstance(
+            itm, (ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem)
+        ):
+            dn = itm.dirName()
+        else:
+            dn = ""
+
+        if relative:
+            dn = self.project.getRelativePath(dn)
+
+        return dn
+
     def _keyboardSearchType(self, item):
         """
         Protected method to check, if the item is of the correct type.

eric ide

mercurial