8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
11 |
11 |
12 from PyQt6.QtCore import pyqtSlot |
12 from PyQt6.QtCore import pyqtSlot |
13 from PyQt6.QtWidgets import QDialog |
13 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
14 |
14 |
|
15 from eric7.EricWidgets.EricApplication import ericApp |
15 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes |
16 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes |
|
17 from eric7.SystemUtilities import FileSystemUtilities |
16 |
18 |
17 from .Ui_AddFileDialog import Ui_AddFileDialog |
19 from .Ui_AddFileDialog import Ui_AddFileDialog |
18 |
20 |
19 |
21 |
20 class AddFileDialog(QDialog, Ui_AddFileDialog): |
22 class AddFileDialog(QDialog, Ui_AddFileDialog): |
40 super().__init__(parent) |
42 super().__init__(parent) |
41 if name: |
43 if name: |
42 self.setObjectName(name) |
44 self.setObjectName(name) |
43 self.setupUi(self) |
45 self.setupUi(self) |
44 |
46 |
|
47 self.__remoteMode = ( |
|
48 bool(startdir) and FileSystemUtilities.isRemoteFileName(startdir) |
|
49 ) or FileSystemUtilities.isRemoteFileName(pro.getProjectPath()) |
|
50 |
45 self.sourceFilesPicker.setMode(EricPathPickerModes.OPEN_FILES_MODE) |
51 self.sourceFilesPicker.setMode(EricPathPickerModes.OPEN_FILES_MODE) |
|
52 self.sourceFilesPicker.setRemote(self.__remoteMode) |
|
53 |
46 self.targetDirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
54 self.targetDirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
47 self.targetDirPicker.setDefaultDirectory(startdir) |
55 self.targetDirPicker.setDefaultDirectory(startdir) |
|
56 self.targetDirPicker.setRemote(self.__remoteMode) |
48 |
57 |
49 if startdir: |
58 if startdir: |
50 self.targetDirPicker.setText(startdir) |
59 self.targetDirPicker.setText(startdir) |
51 else: |
60 else: |
52 self.targetDirPicker.setText(pro.getProjectPath()) |
61 self.targetDirPicker.setText(pro.getProjectPath()) |
55 self.startdir = startdir |
64 self.startdir = startdir |
56 |
65 |
57 if self.fileTypeFilter is not None: |
66 if self.fileTypeFilter is not None: |
58 self.sourcecodeCheckBox.hide() |
67 self.sourcecodeCheckBox.hide() |
59 |
68 |
|
69 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
|
70 |
60 msh = self.minimumSizeHint() |
71 msh = self.minimumSizeHint() |
61 self.resize(max(self.width(), msh.width()), msh.height()) |
72 self.resize(max(self.width(), msh.width()), msh.height()) |
62 |
73 |
63 @pyqtSlot() |
74 @pyqtSlot() |
64 def on_sourceFilesPicker_aboutToShowPathPickerDialog(self): |
75 def on_sourceFilesPicker_aboutToShowPathPickerDialog(self): |
65 """ |
76 """ |
66 Private slot to perform actions before the source files selection |
77 Private slot to perform actions before the source files selection |
67 dialog is shown. |
78 dialog is shown. |
68 """ |
79 """ |
69 path = self.targetDirPicker.text() |
80 targetPath = self.targetDirPicker.text() |
70 if not path: |
81 if not targetPath: |
71 path = self.startdir |
82 targetPath = self.startdir |
72 self.sourceFilesPicker.setDefaultDirectory(path) |
83 self.sourceFilesPicker.setDefaultDirectory(targetPath) |
73 |
84 |
74 caption = self.tr("Select Files") |
85 caption = ( |
|
86 self.tr("Select Files") |
|
87 if self.__remoteMode |
|
88 else self.tr("Select Remote Files") |
|
89 ) |
75 if self.fileTypeFilter is None: |
90 if self.fileTypeFilter is None: |
76 dfilter = self.__project.getFileCategoryFilterString(withAll=True) |
91 dfilter = self.__project.getFileCategoryFilterString(withAll=True) |
77 elif ( |
92 elif ( |
78 self.fileTypeFilter != "OTHERS" |
93 self.fileTypeFilter != "OTHERS" |
79 and self.fileTypeFilter in self.__project.getFileCategories() |
94 and self.fileTypeFilter in self.__project.getFileCategories() |
101 the project in place. |
116 the project in place. |
102 |
117 |
103 @param sfile the text of the source file picker |
118 @param sfile the text of the source file picker |
104 @type str |
119 @type str |
105 """ |
120 """ |
106 sfile = str(self.sourceFilesPicker.firstPath()) |
121 sfile = self.sourceFilesPicker.firstStrPath() |
107 if sfile.startswith(self.__project.getProjectPath()): |
122 if sfile.startswith(self.__project.getProjectPath()): |
108 if os.path.isdir(sfile): |
123 if self.__remoteMode: |
109 directory = sfile |
124 fsInterface = ( |
|
125 ericApp().getObject("EricServer").getServiceInterface("FileSystem") |
|
126 ) |
|
127 directory = ( |
|
128 sfile if fsInterface.isdir(sfile) else fsInterface.dirname(sfile) |
|
129 ) |
110 else: |
130 else: |
111 directory = os.path.dirname(sfile) |
131 directory = ( |
|
132 sfile if os.path.isdir(sfile) else os.path.dirname(sfile) |
|
133 ) |
112 self.targetDirPicker.setText(directory) |
134 self.targetDirPicker.setText(directory) |
|
135 |
|
136 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(bool(sfile)) |
113 |
137 |
114 def getData(self): |
138 def getData(self): |
115 """ |
139 """ |
116 Public slot to retrieve the dialogs data. |
140 Public slot to retrieve the dialogs data. |
117 |
141 |
118 @return tuple containing the source files, the target directory and a flag |
142 @return tuple containing the source files, the target directory and a flag |
119 telling, whether the files shall be added as source code |
143 telling, whether the files shall be added as source code |
120 @rtype tuple of (list of string, string, boolean) |
144 @rtype tuple of (list of string, string, boolean) |
121 """ |
145 """ |
122 return ( |
146 return ( |
123 [str(p) for p in self.sourceFilesPicker.paths()], |
147 self.sourceFilesPicker.strPaths(), |
124 self.targetDirPicker.text(), |
148 self.targetDirPicker.text(), |
125 self.sourcecodeCheckBox.isChecked(), |
149 self.sourcecodeCheckBox.isChecked(), |
126 ) |
150 ) |