src/eric7/Project/ProjectOthersBrowser.py

Fri, 04 Nov 2022 13:52:26 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 04 Nov 2022 13:52:26 +0100
branch
eric7
changeset 9473
3f23dbf37dbe
parent 9462
e65379fdbd97
child 9482
a2bc06a54d9d
permissions
-rw-r--r--

Resorted the import statements using isort.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
3 # Copyright (c) 2002 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2408
diff changeset
7 Module implementing a class used to display the parts of the project, that
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2408
diff changeset
8 don't fit the other categories.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
8243
cc717c2ae956 Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8222
diff changeset
11 import contextlib
9362
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
12 import os
8243
cc717c2ae956 Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8222
diff changeset
13
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9462
diff changeset
14 from PyQt6.QtCore import QModelIndex, QUrl, pyqtSignal
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
15 from PyQt6.QtGui import QDesktopServices
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
16 from PyQt6.QtWidgets import QDialog, QMenu
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9462
diff changeset
18 from eric7 import Preferences
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9402
diff changeset
19 from eric7.EricWidgets import EricMessageBox
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9462
diff changeset
20 from eric7.Utilities import MimeTypes
4101
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
21
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9462
diff changeset
22 from .ProjectBaseBrowser import ProjectBaseBrowser
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
23 from .ProjectBrowserModel import (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
24 ProjectBrowserDirectoryItem,
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9462
diff changeset
25 ProjectBrowserFileItem,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
26 ProjectBrowserOthersType,
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9462
diff changeset
27 ProjectBrowserSimpleDirectoryItem,
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
28 )
3565
8e1cd7721515 Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
29
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
30
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 class ProjectOthersBrowser(ProjectBaseBrowser):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2408
diff changeset
33 A class used to display the parts of the project, that don't fit the
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2408
diff changeset
34 other categories.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
35
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2408
diff changeset
36 @signal showMenu(str, QMenu) emitted when a menu is about to be shown.
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2408
diff changeset
37 The name of the menu and a reference to the menu are given.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
39
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 476
diff changeset
40 showMenu = pyqtSignal(str, QMenu)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
41
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 def __init__(self, project, parent=None):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
45
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @param project reference to the project object
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 @param parent parent widget of this browser (QWidget)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
49 ProjectBaseBrowser.__init__(self, project, ProjectBrowserOthersType, parent)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
50
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
51 self.selectedItemsFilter = [ProjectBrowserFileItem, ProjectBrowserDirectoryItem]
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.specialMenuEntries = [1]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
54 self.setWindowTitle(self.tr("Others"))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
56 self.setWhatsThis(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
57 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
58 """<b>Project Others Browser</b>"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
59 """<p>This allows to easily see all other files and directories"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
60 """ contained in the current project. Several actions can be"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
61 """ executed via the context menu. The entry which is registered"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
62 """ in the project is shown in a different colour.</p>"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
63 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
64 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
65
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 476
diff changeset
66 project.prepareRepopulateItem.connect(self._prepareRepopulateItem)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 476
diff changeset
67 project.completeRepopulateItem.connect(self._completeRepopulateItem)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
68
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 def _createPopupMenus(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 Protected overloaded method to generate the popup menu.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 ProjectBaseBrowser._createPopupMenus(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
74
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
75 self.menu.addAction(self.tr("Open in Hex Editor"), self._openHexEditor)
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
76 self.editPixmapAct = self.menu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
77 self.tr("Open in Icon Editor"), self._editPixmap
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
78 )
8909
1fd7ed5f83a6 File Browser, Project Others Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
79 self.openInEditorAct = self.menu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
80 self.tr("Open in Editor"), self._openFileInEditor
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
81 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.menu.addSeparator()
4101
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
83 self.mimeTypeAct = self.menu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
84 self.tr("Show Mime-Type"), self.__showMimeType
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
85 )
4101
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
86 self.menu.addSeparator()
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
87 self.renameFileAct = self.menu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
88 self.tr("Rename file"), self._renameFile
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
89 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.menuActions.append(self.renameFileAct)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
91 act = self.menu.addAction(self.tr("Remove from project"), self.__removeItem)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 self.menuActions.append(act)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
93 act = self.menu.addAction(self.tr("Delete"), self.__deleteItem)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 self.menuActions.append(act)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.menu.addSeparator()
9362
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
96 self.menu.addAction(self.tr("Add files..."), self.__addOthersFiles)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
97 self.menu.addAction(self.tr("Add directory..."), self.__addOthersDirectory)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 self.menu.addSeparator()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
99 self.menu.addAction(self.tr("Refresh"), self.__refreshItem)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 self.menu.addSeparator()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
101 self.menu.addAction(self.tr("Copy Path to Clipboard"), self._copyToClipboard)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 self.menu.addSeparator()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
103 self.menu.addAction(self.tr("Expand all directories"), self._expandAllDirs)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
104 self.menu.addAction(self.tr("Collapse all directories"), self._collapseAllDirs)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 self.menu.addSeparator()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
106 self.menu.addAction(self.tr("Configure..."), self._configure)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107
9362
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
108 self.dirMenu = QMenu(self)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
109 self.removeDirAct = self.dirMenu.addAction(
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
110 self.tr("Remove from project"), self._removeDir
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
111 )
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
112 self.dirMenuActions.append(self.removeDirAct)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
113 self.deleteDirAct = self.dirMenu.addAction(
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
114 self.tr("Delete"), self._deleteDirectory
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
115 )
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
116 self.dirMenuActions.append(self.deleteDirAct)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
117 self.dirMenu.addSeparator()
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
118 self.dirMenu.addAction(self.tr("Add files..."), self.__addOthersFiles)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
119 self.dirMenu.addAction(self.tr("Add directory..."), self.__addOthersDirectory)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
120 self.dirMenu.addSeparator()
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
121 self.dirMenu.addAction(self.tr("Copy Path to Clipboard"), self._copyToClipboard)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
122 self.dirMenu.addSeparator()
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
123 self.dirMenu.addAction(self.tr("Expand all directories"), self._expandAllDirs)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
124 self.dirMenu.addAction(
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
125 self.tr("Collapse all directories"), self._collapseAllDirs
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
126 )
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
127 self.dirMenu.addSeparator()
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
128 self.dirMenu.addAction(self.tr("Configure..."), self._configure)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
129
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 self.backMenu = QMenu(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
131 self.backMenu.addAction(self.tr("Add files..."), self.project.addOthersFiles)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
132 self.backMenu.addAction(self.tr("Add directory..."), self.project.addOthersDir)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 self.backMenu.addSeparator()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
134 self.backMenu.addAction(self.tr("Expand all directories"), self._expandAllDirs)
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
135 self.backMenu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
136 self.tr("Collapse all directories"), self._collapseAllDirs
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
137 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 self.backMenu.addSeparator()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
139 self.backMenu.addAction(self.tr("Configure..."), self._configure)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 self.backMenu.setEnabled(False)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 self.multiMenu.addSeparator()
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
143 act = self.multiMenu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
144 self.tr("Remove from project"), self.__removeItem
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
145 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 self.multiMenuActions.append(act)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
147 act = self.multiMenu.addAction(self.tr("Delete"), self.__deleteItem)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 self.multiMenuActions.append(act)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 self.multiMenu.addSeparator()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
150 self.multiMenu.addAction(self.tr("Expand all directories"), self._expandAllDirs)
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
151 self.multiMenu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
152 self.tr("Collapse all directories"), self._collapseAllDirs
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
153 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 self.multiMenu.addSeparator()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
155 self.multiMenu.addAction(self.tr("Configure..."), self._configure)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
156
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
157 self.menu.aboutToShow.connect(self.__showContextMenu)
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
158 self.multiMenu.aboutToShow.connect(self.__showContextMenuMulti)
9362
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
159 self.dirMenu.aboutToShow.connect(self.__showContextMenuDir)
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
160 self.backMenu.aboutToShow.connect(self.__showContextMenuBack)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 self.mainMenu = self.menu
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
162
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 def _contextMenuRequested(self, coord):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 Protected slot to show the context menu.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
166
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 @param coord the position of the mouse pointer (QPoint)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 if not self.project.isOpen():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
171
9462
e65379fdbd97 Changed code to resolve or acknowledge some potential security issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
172 with contextlib.suppress(Exception): # secok
9402
f5d9aa5c62db Reformatted the code with the black tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9362
diff changeset
173 cnt = self.getSelectedItemsCount(
f5d9aa5c62db Reformatted the code with the black tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9362
diff changeset
174 [
f5d9aa5c62db Reformatted the code with the black tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9362
diff changeset
175 ProjectBrowserFileItem,
f5d9aa5c62db Reformatted the code with the black tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9362
diff changeset
176 ProjectBrowserDirectoryItem,
f5d9aa5c62db Reformatted the code with the black tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9362
diff changeset
177 ProjectBrowserSimpleDirectoryItem,
f5d9aa5c62db Reformatted the code with the black tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9362
diff changeset
178 ]
f5d9aa5c62db Reformatted the code with the black tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9362
diff changeset
179 )
9362
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
180 if cnt < 1:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 index = self.indexAt(coord)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 if index.isValid():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 self._selectSingleItem(index)
9402
f5d9aa5c62db Reformatted the code with the black tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9362
diff changeset
184 cnt = self.getSelectedItemsCount(
f5d9aa5c62db Reformatted the code with the black tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9362
diff changeset
185 [
f5d9aa5c62db Reformatted the code with the black tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9362
diff changeset
186 ProjectBrowserFileItem,
f5d9aa5c62db Reformatted the code with the black tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9362
diff changeset
187 ProjectBrowserDirectoryItem,
f5d9aa5c62db Reformatted the code with the black tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9362
diff changeset
188 ProjectBrowserSimpleDirectoryItem,
f5d9aa5c62db Reformatted the code with the black tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9362
diff changeset
189 ]
f5d9aa5c62db Reformatted the code with the black tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9362
diff changeset
190 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
191
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 if cnt > 1:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 self.multiMenu.popup(self.mapToGlobal(coord))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 index = self.indexAt(coord)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 if cnt == 1 and index.isValid():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 itm = self.model().item(index)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 if isinstance(itm, ProjectBrowserFileItem):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 self.editPixmapAct.setVisible(itm.isPixmapFile())
8911
a37761d36236 Fixed an issue hiding the 'Open in Editor' context menu action for files not being SVG files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8909
diff changeset
200 self.openInEditorAct.setVisible(itm.isSvgFile())
4101
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
201 self.mimeTypeAct.setVisible(True)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 self.menu.popup(self.mapToGlobal(coord))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 elif isinstance(itm, ProjectBrowserDirectoryItem):
9362
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
204 self.removeDirAct.setVisible(True)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
205 self.deleteDirAct.setVisible(True)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
206 self.dirMenu.popup(self.mapToGlobal(coord))
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
207 elif isinstance(itm, ProjectBrowserSimpleDirectoryItem):
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
208 self.removeDirAct.setVisible(False)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
209 self.deleteDirAct.setVisible(False)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
210 self.dirMenu.popup(self.mapToGlobal(coord))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 self.backMenu.popup(self.mapToGlobal(coord))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 self.backMenu.popup(self.mapToGlobal(coord))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
215
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 def __showContextMenu(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 Private slot called by the menu aboutToShow signal.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 self._showContextMenu(self.menu)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
221
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 476
diff changeset
222 self.showMenu.emit("Main", self.menu)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
223
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 def __showContextMenuMulti(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 Private slot called by the multiMenu aboutToShow signal.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 ProjectBaseBrowser._showContextMenuMulti(self, self.multiMenu)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
229
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 476
diff changeset
230 self.showMenu.emit("MainMulti", self.multiMenu)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
231
9362
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
232 def __showContextMenuDir(self):
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
233 """
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
234 Private slot called by the dirMenu aboutToShow signal.
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
235 """
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
236 ProjectBaseBrowser._showContextMenuDir(self, self.dirMenu)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
237
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
238 self.showMenu.emit("MainDir", self.dirMenu)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
239
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 def __showContextMenuBack(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 Private slot called by the backMenu aboutToShow signal.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 ProjectBaseBrowser._showContextMenuBack(self, self.backMenu)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
245
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 476
diff changeset
246 self.showMenu.emit("MainBack", self.backMenu)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
247
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 def _showContextMenu(self, menu):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
250 Protected slot called before the context menu is shown.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
251
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
252 It enables/disables the VCS menu entries depending on the overall
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 VCS status and the file status.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
254
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 @param menu Reference to the popup menu (QPopupMenu)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 if self.project.vcs is None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 for act in self.menuActions:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 act.setEnabled(True)
8911
a37761d36236 Fixed an issue hiding the 'Open in Editor' context menu action for files not being SVG files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8909
diff changeset
260 itm = self.model().item(self.currentIndex())
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
261 if isinstance(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
262 itm, (ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem)
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
263 ):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 self.renameFileAct.setEnabled(False)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 self.vcsHelper.showContextMenu(menu, self.menuActions)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
267
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 def _editPixmap(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 Protected slot to handle the open in icon editor popup menu entry.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 itmList = self.getSelectedItems()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
273
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 for itm in itmList:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
275 if isinstance(itm, ProjectBrowserFileItem) and itm.isPixmapFile():
8222
5994b80b8760 Applied some more code simplifications suggested by the new Simplify checker (Y102: use single if) (batch 1).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
276 self.pixmapEditFile.emit(itm.fileName())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
277
4651
7f3f276d3bf3 Integrated the hex editor into the eric IDE.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
278 def _openHexEditor(self):
7f3f276d3bf3 Integrated the hex editor into the eric IDE.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
279 """
7f3f276d3bf3 Integrated the hex editor into the eric IDE.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
280 Protected slot to handle the open in hex editor popup menu entry.
7f3f276d3bf3 Integrated the hex editor into the eric IDE.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
281 """
7f3f276d3bf3 Integrated the hex editor into the eric IDE.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
282 itmList = self.getSelectedItems()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
283
4651
7f3f276d3bf3 Integrated the hex editor into the eric IDE.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
284 for itm in itmList:
7f3f276d3bf3 Integrated the hex editor into the eric IDE.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
285 if isinstance(itm, ProjectBrowserFileItem):
7f3f276d3bf3 Integrated the hex editor into the eric IDE.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
286 self.binaryFile.emit(itm.fileName())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
287
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 def _openItem(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 Protected slot to handle the open popup menu entry.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 itmList = self.getSelectedItems()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
293
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 for itm in itmList:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 if isinstance(itm, ProjectBrowserFileItem):
7482
11b79ec79b6f ProjectOthersBrowser: changed the order of the file type test to make sure that SVG files are opened with the SVG viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
296 if itm.isSvgFile():
11b79ec79b6f ProjectOthersBrowser: changed the order of the file type test to make sure that SVG files are opened with the SVG viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
297 self.svgFile.emit(itm.fileName())
11b79ec79b6f ProjectOthersBrowser: changed the order of the file type test to make sure that SVG files are opened with the SVG viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
298 elif itm.isPixmapFile():
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 476
diff changeset
299 self.pixmapFile.emit(itm.fileName())
8282
16b243bdb12f UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8270
diff changeset
300 elif itm.isEricGraphicsFile():
16b243bdb12f UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8270
diff changeset
301 self.umlFile.emit(itm.fileName())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 else:
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9402
diff changeset
303 if MimeTypes.isTextFile(itm.fileName()):
476
121633976eca Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
304 self.sourceFile.emit(itm.fileName())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 QDesktopServices.openUrl(QUrl(itm.fileName()))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
307
8909
1fd7ed5f83a6 File Browser, Project Others Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
308 def _openFileInEditor(self):
1fd7ed5f83a6 File Browser, Project Others Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
309 """
8925
8375eb895f70 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8911
diff changeset
310 Protected slot to handle the Open in Editor menu action.
8909
1fd7ed5f83a6 File Browser, Project Others Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
311 """
1fd7ed5f83a6 File Browser, Project Others Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
312 itmList = self.getSelectedItems()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
313
8909
1fd7ed5f83a6 File Browser, Project Others Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
314 for itm in itmList:
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9402
diff changeset
315 if isinstance(itm, ProjectBrowserFileItem) and MimeTypes.isTextFile(
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9402
diff changeset
316 itm.fileName()
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9402
diff changeset
317 ):
8909
1fd7ed5f83a6 File Browser, Project Others Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
318 self.sourceFile.emit(itm.fileName())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
319
4101
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
320 def __showMimeType(self):
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
321 """
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
322 Private slot to show the mime type of the selected entry.
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
323 """
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
324 itmList = self.getSelectedItems()
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
325 if itmList:
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9402
diff changeset
326 mimetype = MimeTypes.mimeType(itmList[0].fileName())
4101
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
327 if mimetype is None:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
328 EricMessageBox.warning(
4101
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
329 self,
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
330 self.tr("Show Mime-Type"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
331 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
332 """The mime type of the file could not be""" """ determined."""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
333 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
334 )
4101
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
335 elif mimetype.split("/")[0] == "text":
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
336 EricMessageBox.information(
4101
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
337 self,
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
338 self.tr("Show Mime-Type"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
339 self.tr("""The file has the mime type <b>{0}</b>.""").format(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
340 mimetype
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
341 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
342 )
4101
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
343 else:
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
344 textMimeTypesList = Preferences.getUI("TextMimeTypes")
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
345 if mimetype in textMimeTypesList:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
346 EricMessageBox.information(
4101
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
347 self,
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
348 self.tr("Show Mime-Type"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
349 self.tr("""The file has the mime type <b>{0}</b>.""").format(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
350 mimetype
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
351 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
352 )
4101
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
353 else:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
354 ok = EricMessageBox.yesNo(
4101
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
355 self,
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
356 self.tr("Show Mime-Type"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
357 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
358 """The file has the mime type <b>{0}</b>."""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
359 """<br/> Shall it be added to the list of"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
360 """ text mime types?"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
361 ).format(mimetype),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
362 )
4101
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
363 if ok:
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
364 textMimeTypesList.append(mimetype)
68c26f72c0d1 Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
365 Preferences.setUI("TextMimeTypes", textMimeTypesList)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
366
9362
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
367 def __addOthersFiles(self):
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
368 """
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
369 Private method to add files to the project.
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
370 """
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
371 itm = self.model().item(self.currentIndex())
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
372 if isinstance(itm, ProjectBrowserFileItem):
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
373 dn = os.path.dirname(itm.fileName())
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
374 elif isinstance(
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
375 itm, (ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
376 ):
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
377 dn = itm.dirName()
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
378 else:
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
379 dn = None
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
380 self.project.addFiles("others", dn)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
381
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
382 def __addOthersDirectory(self):
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
383 """
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
384 Private method to add files of a directory to the project.
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
385 """
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
386 itm = self.model().item(self.currentIndex())
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
387 if isinstance(ProjectBrowserFileItem):
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
388 dn = os.path.dirname(itm.fileName())
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
389 elif isinstance(
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
390 itm, (ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
391 ):
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
392 dn = itm.dirName()
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
393 else:
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
394 dn = None
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
395 self.project.addDirectory("others", dn)
9daa438fb4de Improved the 'Add Files' and 'Add Directory' context menu actions of the Others project browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
396
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 def __removeItem(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 """
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2408
diff changeset
399 Private slot to remove the selected entry from the OTHERS project
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2408
diff changeset
400 data area.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 itmList = self.getSelectedItems()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
403
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 for itm in itmList[:]:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 if isinstance(itm, ProjectBrowserFileItem):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 fn = itm.fileName()
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 476
diff changeset
407 self.closeSourceWindow.emit(fn)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 self.project.removeFile(fn)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 dn = itm.dirName()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 self.project.removeDirectory(dn)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
412
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 def __deleteItem(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414 """
2995
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2408
diff changeset
415 Private method to delete the selected entry from the OTHERS project
63d874899b8b Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2408
diff changeset
416 data area.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418 itmList = self.getSelectedItems()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
419
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 items = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421 names = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 fullNames = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 dirItems = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 dirNames = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 dirFullNames = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 for itm in itmList:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 if isinstance(itm, ProjectBrowserFileItem):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 fn2 = itm.fileName()
248
f4561c24989a Changed code to better deal with project relative paths on Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 234
diff changeset
429 fn = self.project.getRelativePath(fn2)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430 items.append(itm)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 fullNames.append(fn2)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 names.append(fn)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 dn2 = itm.dirName()
248
f4561c24989a Changed code to better deal with project relative paths on Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 234
diff changeset
435 dn = self.project.getRelativePath(dn2)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436 dirItems.append(itm)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 dirFullNames.append(dn2)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438 dirNames.append(dn)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
439 items.extend(dirItems)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 fullNames.extend(dirFullNames)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 names.extend(dirNames)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 del itmList
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 del dirFullNames
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444 del dirNames
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
445
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9402
diff changeset
446 from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
447
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
448 dlg = DeleteFilesConfirmationDialog(
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2995
diff changeset
449 self.parent(),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
450 self.tr("Delete files/directories"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
451 self.tr("Do you really want to delete these entries from the" " project?"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
452 names,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
453 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
454
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
455 if dlg.exec() == QDialog.DialogCode.Accepted:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456 for itm, fn2, fn in zip(items[:], fullNames, names):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
457 if isinstance(itm, ProjectBrowserFileItem):
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 476
diff changeset
458 self.closeSourceWindow.emit(fn2)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
459 self.project.deleteFile(fn)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
460 elif isinstance(itm, ProjectBrowserDirectoryItem):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
461 self.project.deleteDirectory(fn2)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
462
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
463 def __refreshItem(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
464 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465 Private slot to refresh (repopulate) an item.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
466 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
467 itm = self.model().item(self.currentIndex())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
468 if isinstance(itm, ProjectBrowserFileItem):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
469 name = itm.fileName()
234
caed45a134f8 Added code to update the Others tab of the project browser (mostly) automatically.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 97
diff changeset
470 self.project.repopulateItem(name)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
471 elif isinstance(itm, ProjectBrowserDirectoryItem):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
472 name = itm.dirName()
234
caed45a134f8 Added code to update the Others tab of the project browser (mostly) automatically.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 97
diff changeset
473 self._model.directoryChanged(name)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
474 else:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
475 name = ""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
476
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
477 self._resizeColumns(QModelIndex())

eric ide

mercurial