File Browser eric7

Sun, 10 Dec 2023 17:06:00 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 10 Dec 2023 17:06:00 +0100
branch
eric7
changeset 10396
2f72e9330af2
parent 10395
16933878e27b
child 10397
f60464a5f7ea

File Browser
- Added a menu entry to show the directory path of an entry in a file manager.

docs/changelog.md file | annotate | diff | comparison | revisions
src/eric7/SystemUtilities/FileSystemUtilities.py file | annotate | diff | comparison | revisions
src/eric7/UI/Browser.py file | annotate | diff | comparison | revisions
--- a/docs/changelog.md	Thu Dec 07 10:40:51 2023 +0100
+++ b/docs/changelog.md	Sun Dec 10 17:06:00 2023 +0100
@@ -14,6 +14,8 @@
     - Added the capability to comment/uncomment/toggle comment for languages
       that do not support single line comments (e.g. HTML uses `<!--` and
       `-->`.
+- File Browser
+    - Added a menu entry to show the directory path of an entry in a file manager.
 - Viewmanager
     - Added `Close Tabs to the Left` and `Close Tabs to the Right` context
       menu entries to the tabview view manager.
--- a/src/eric7/SystemUtilities/FileSystemUtilities.py	Thu Dec 07 10:40:51 2023 +0100
+++ b/src/eric7/SystemUtilities/FileSystemUtilities.py	Sun Dec 10 17:06:00 2023 +0100
@@ -729,6 +729,31 @@
     return mountedPaths
 
 
+def startfile(filePath):
+    """
+    Function to open the given file path with the system default application.
+
+    @param filePath file path to be opened
+    @type str or Path
+    @return flag indicating a successful start of the associated application
+    @rtype bool
+    """
+    filePath = str(filePath)
+
+    if OSUtilities.isWindowsPlatform():
+        return os.startfile(filePath)  # secok
+
+    elif OSUtilities.isMacPlatform():
+        return subprocess.call(("open", filePath))  # secok
+
+    elif OSUtilities.isLinuxPlatform() or OSUtilities.isFreeBsdPlatform():
+        return subprocess.call(("xdg-open", filePath))  # secok
+
+    else:
+        # unsupported platform
+        return False
+
+
 ################################################################################
 ## Functions below handle (MicroPython) device and remote file names.
 ################################################################################
--- a/src/eric7/UI/Browser.py	Thu Dec 07 10:40:51 2023 +0100
+++ b/src/eric7/UI/Browser.py	Sun Dec 10 17:06:00 2023 +0100
@@ -250,6 +250,10 @@
         self.sourceMenu.addAction(
             QCoreApplication.translate("Browser", "Open"), self._openItem
         )
+        self.sourceMenu.addAction(
+            QCoreApplication.translate("Browser", "Show in File Manager"),
+            self._showInFileManager,
+        )
         self.testingAct = self.sourceMenu.addAction(
             QCoreApplication.translate("Browser", "Run Test..."), self.handleTesting
         )
@@ -296,6 +300,10 @@
             QCoreApplication.translate("Browser", "Open in PDF Viewer"),
             self._openPdfViewer,
         )
+        self.menu.addAction(
+            QCoreApplication.translate("Browser", "Show in File Manager"),
+            self._showInFileManager,
+        )
         self.menu.addSeparator()
         self.mimeTypeAct = self.menu.addAction(
             QCoreApplication.translate("Browser", "Show Mime-Type"), self.__showMimeType
@@ -341,6 +349,11 @@
         )
         self.dirMenu.addSeparator()
         self.dirMenu.addAction(
+            QCoreApplication.translate("Browser", "Show in File Manager"),
+            self._showInFileManager,
+        )
+        self.dirMenu.addSeparator()
+        self.dirMenu.addAction(
             QCoreApplication.translate("Browser", "Refresh directory"),
             self.__refreshDirectory,
         )
@@ -570,6 +583,26 @@
                     self.sourceFile[str, list].emit(itm.fileName(), itm.linenos())
             self._activating = False
 
+    def _showInFileManager(self):
+        """
+        Protected method to show the selected items path in a file manager application.
+        """
+        itmList = self.getSelectedItems(
+            [
+                BrowserFileItem,
+                BrowserClassItem,
+                BrowserMethodItem,
+                BrowserClassAttributeItem,
+                BrowserImportItem,
+                BrowserDirectoryItem,
+            ]
+        )
+        for itm in itmList:
+            if isinstance(itm, BrowserDirectoryItem):
+                QDesktopServices.openUrl(QUrl(itm.dirName()))
+            else:
+                QDesktopServices.openUrl(QUrl(os.path.dirname(itm.fileName())))
+
     def __showMimeType(self):
         """
         Private slot to show the mime type of the selected entry.

eric ide

mercurial