10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 from PyQt5.QtCore import pyqtSlot |
12 from PyQt5.QtCore import pyqtSlot |
13 from PyQt5.QtWidgets import QDialog |
13 from PyQt5.QtWidgets import QDialog |
14 |
14 |
15 from E5Gui.E5Completers import E5DirCompleter |
15 from E5Gui.E5PathPicker import E5PathPickerModes |
16 from E5Gui import E5FileDialog |
|
17 |
16 |
18 from .Ui_AddDirectoryDialog import Ui_AddDirectoryDialog |
17 from .Ui_AddDirectoryDialog import Ui_AddDirectoryDialog |
19 |
|
20 import Utilities |
|
21 import UI.PixmapCache |
|
22 |
18 |
23 |
19 |
24 class AddDirectoryDialog(QDialog, Ui_AddDirectoryDialog): |
20 class AddDirectoryDialog(QDialog, Ui_AddDirectoryDialog): |
25 """ |
21 """ |
26 Class implementing a dialog to add files of a directory to the project. |
22 Class implementing a dialog to add files of a directory to the project. |
39 super(AddDirectoryDialog, self).__init__(parent) |
35 super(AddDirectoryDialog, self).__init__(parent) |
40 if name: |
36 if name: |
41 self.setObjectName(name) |
37 self.setObjectName(name) |
42 self.setupUi(self) |
38 self.setupUi(self) |
43 |
39 |
44 self.sourceDirButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
40 self.sourceDirPicker.setMode(E5PathPickerModes.DirectoryMode) |
45 self.targetDirButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
41 self.sourceDirPicker.setDefaultDirectory(startdir) |
46 |
42 self.targetDirPicker.setMode(E5PathPickerModes.DirectoryMode) |
47 self.sourceDirCompleter = E5DirCompleter(self.sourceDirEdit) |
43 self.targetDirPicker.setDefaultDirectory(startdir) |
48 self.targetDirCompleter = E5DirCompleter(self.targetDirEdit) |
|
49 |
44 |
50 self.ppath = pro.ppath |
45 self.ppath = pro.ppath |
51 self.targetDirEdit.setText(self.ppath) |
46 self.targetDirPicker.setText(self.ppath) |
52 self.startdir = startdir |
|
53 self.on_filterComboBox_highlighted('(*.py)') |
47 self.on_filterComboBox_highlighted('(*.py)') |
54 # enable all dialog elements |
48 # enable all dialog elements |
55 if filter == 'source': # it is a source file |
49 if filter == 'source': # it is a source file |
56 self.filterComboBox.addItem( |
50 self.filterComboBox.addItem( |
57 self.tr("Source Files"), "SOURCES") |
51 self.tr("Source Files"), "SOURCES") |
91 |
85 |
92 @param fileType the selected file type (string) |
86 @param fileType the selected file type (string) |
93 """ |
87 """ |
94 if fileType.endswith('(*)'): |
88 if fileType.endswith('(*)'): |
95 self.targetDirLabel.setEnabled(False) |
89 self.targetDirLabel.setEnabled(False) |
96 self.targetDirEdit.setEnabled(False) |
90 self.targetDirPicker.setEnabled(False) |
97 self.targetDirButton.setEnabled(False) |
|
98 self.recursiveCheckBox.setEnabled(False) |
91 self.recursiveCheckBox.setEnabled(False) |
99 else: |
92 else: |
100 self.targetDirLabel.setEnabled(True) |
93 self.targetDirLabel.setEnabled(True) |
101 self.targetDirEdit.setEnabled(True) |
94 self.targetDirPicker.setEnabled(True) |
102 self.targetDirButton.setEnabled(True) |
|
103 self.recursiveCheckBox.setEnabled(True) |
95 self.recursiveCheckBox.setEnabled(True) |
104 |
96 |
105 def __dirDialog(self, textEdit): |
97 @pyqtSlot(str) |
|
98 def on_sourceDirPicker_textChanged(self, dir): |
106 """ |
99 """ |
107 Private slot to display a directory selection dialog. |
100 Private slot to handle the source directory text changed. |
108 |
|
109 @param textEdit field for the display of the selected directory name |
|
110 (QLineEdit) |
|
111 """ |
|
112 startdir = textEdit.text() |
|
113 if not startdir and self.startdir is not None: |
|
114 startdir = self.startdir |
|
115 |
|
116 directory = E5FileDialog.getExistingDirectory( |
|
117 self, |
|
118 self.tr("Select directory"), |
|
119 startdir) |
|
120 |
|
121 if directory: |
|
122 textEdit.setText(Utilities.toNativeSeparators(directory)) |
|
123 |
|
124 @pyqtSlot() |
|
125 def on_sourceDirButton_clicked(self): |
|
126 """ |
|
127 Private slot to handle the source dir button press. |
|
128 """ |
|
129 self.__dirDialog(self.sourceDirEdit) |
|
130 |
|
131 @pyqtSlot() |
|
132 def on_targetDirButton_clicked(self): |
|
133 """ |
|
134 Private slot to handle the target dir button press. |
|
135 """ |
|
136 self.__dirDialog(self.targetDirEdit) |
|
137 |
|
138 @pyqtSlot(str) |
|
139 def on_sourceDirEdit_textChanged(self, dir): |
|
140 """ |
|
141 Private slot to handle the source dir text changed. |
|
142 |
101 |
143 If the entered source directory is a subdirectory of the current |
102 If the entered source directory is a subdirectory of the current |
144 projects main directory, the target directory path is synchronized. |
103 projects main directory, the target directory path is synchronized. |
145 It is assumed, that the user wants to add a bunch of files to |
104 It is assumed, that the user wants to add a bunch of files to |
146 the project in place. |
105 the project in place. |
147 |
106 |
148 @param dir the text of the source directory line edit (string) |
107 @param dir the text of the source directory line edit (string) |
149 """ |
108 """ |
150 if dir.startswith(self.ppath): |
109 if dir.startswith(self.ppath): |
151 self.targetDirEdit.setText(dir) |
110 self.targetDirPicker.setText(dir) |
152 |
111 |
153 def getData(self): |
112 def getData(self): |
154 """ |
113 """ |
155 Public slot to retrieve the dialogs data. |
114 Public slot to retrieve the dialogs data. |
156 |
115 |