eric7/UI/FindLocationWidget.py

branch
eric7
changeset 8636
c0a3a6e40815
parent 8632
f25cd4b94eb0
child 8643
5adf87ac0c3e
diff -r ea9ba9277670 -r c0a3a6e40815 eric7/UI/FindLocationWidget.py
--- a/eric7/UI/FindLocationWidget.py	Sat Sep 25 18:07:20 2021 +0200
+++ b/eric7/UI/FindLocationWidget.py	Sat Sep 25 18:08:10 2021 +0200
@@ -10,7 +10,8 @@
 import os
 import sys
 
-from PyQt6.QtCore import pyqtSignal, pyqtSlot
+from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl
+from PyQt6.QtGui import QDesktopServices, QImageReader
 from PyQt6.QtWidgets import (
     QWidget, QHeaderView, QApplication, QTreeWidgetItem
 )
@@ -34,9 +35,19 @@
     
     @signal sourceFile(str) emitted to open a file in the editor
     @signal designerFile(str) emitted to open a Qt-Designer file
+    @signal linguistFile(str) emitted to open a Qt-Linguist (*.ts) file
+    @signal trpreview([str]) emitted to preview Qt-Linguist (*.qm) files
+    @signal pixmapFile(str) emitted to open a pixmap file
+    @signal svgFile(str) emitted to open a SVG file
+    @signal umlFile(str) emitted to open an eric UML file
     """
     sourceFile = pyqtSignal(str)
     designerFile = pyqtSignal(str)
+    linguistFile = pyqtSignal(str)
+    trpreview = pyqtSignal(list)
+    pixmapFile = pyqtSignal(str)
+    svgFile = pyqtSignal(str)
+    umlFile = pyqtSignal(str)
     
     def __init__(self, project, parent=None):
         """
@@ -67,7 +78,9 @@
         self.openButton.setIcon(UI.PixmapCache.getIcon("open"))
         self.openButton.clicked.connect(self.__openFile)
         
-        self.project = project
+        self.__project = project
+        self.__project.projectOpened.connect(self.__projectOpened)
+        self.__project.projectClosed.connect(self.__projectClosed)
         self.extsepLabel.setText(os.extsep)
         
         self.__shouldStop = False
@@ -87,8 +100,7 @@
         """
         Private slot to open a file.
         
-        It emits the signal sourceFile or designerFile depending on the
-        file extension.
+        It emits a signal depending on the file extension.
         
         @param itm item to be opened
         @type QTreeWidgetItem
@@ -98,14 +110,26 @@
         if itm is not None:
             fileName = itm.text(0)
             filePath = itm.text(1)
+            fileExt = os.path.splitext(fileName)[1]
+            fullName = os.path.join(filePath, fileName)
             
-            # TODO: add more extensions and use mimetype
-            #       - *.ts, *.qm->*.ts
-            #       Utilities.MimeTypes.isTextFile(filename)
-            if fileName.endswith('.ui'):
-                self.designerFile.emit(os.path.join(filePath, fileName))
+            if fileExt == ".ui":
+                self.designerFile.emit(fullName)
+            elif fileExt == ".ts":
+                self.linguistFile.emit(fullName)
+            elif fileExt == ".qm":
+                self.trpreview.emit([fullName])
+            elif fileExt in (".egj", ".e5g"):
+                self.umlFile.emit(fullName)
+            elif fileExt == ".svg":
+                self.svgFile.emit(fullName)
+            elif fileExt[1:] in QImageReader.supportedImageFormats():
+                self.pixmapFile.emit(fullName)
             else:
-                self.sourceFile.emit(os.path.join(filePath, fileName))
+                if Utilities.MimeTypes.isTextFile(fullName):
+                    self.sourceFile.emit(fullName)
+                else:
+                    QDesktopServices.openUrl(QUrl(fullName))
     
     @pyqtSlot()
     def __searchFile(self):
@@ -135,7 +159,7 @@
         ):
             searchPaths.append(self.searchDirPicker.text())
         if self.projectCheckBox.isChecked():
-            searchPaths.append(self.project.ppath)
+            searchPaths.append(self.__project.getProjectPath())
         if self.syspathCheckBox.isChecked():
             searchPaths.extend(sys.path)
         
@@ -164,8 +188,11 @@
         
         del locations
         self.stopButton.setEnabled(False)
+        self.fileList.sortItems(self.fileList.sortColumn(),
+                                Qt.SortOrder.AscendingOrder)
         self.fileList.header().resizeSections(
             QHeaderView.ResizeMode.ResizeToContents)
+        self.fileList.header().resizeSection(0, self.width() // 2)
         self.fileList.header().setStretchLastSection(True)
         
         self.findStatusLabel.setText(self.tr(
@@ -230,16 +257,25 @@
         self.openButton.setEnabled(current is not None)
     
     @pyqtSlot()
+    def __projectOpened(self):
+        """
+        Private slot to handle a project being opened.
+        """
+        self.projectCheckBox.setEnabled(True)
+        self.projectCheckBox.setChecked(True)
+    
+    @pyqtSlot()
+    def __projectClosed(self):
+        """
+        Private slot to handle a project being closed.
+        """
+        self.projectCheckBox.setEnabled(False)
+        self.projectCheckBox.setChecked(False)
+    
+    @pyqtSlot()
     def activate(self):
         """
         Public slot to enable/disable the project checkbox.
         """
-        if self.project and self.project.isOpen():
-            self.projectCheckBox.setEnabled(True)
-            self.projectCheckBox.setChecked(True)
-        else:
-            self.projectCheckBox.setEnabled(False)
-            self.projectCheckBox.setChecked(False)
-        
         self.fileNameEdit.selectAll()
         self.fileNameEdit.setFocus()

eric ide

mercurial