17 |
17 |
18 class AddDirectoryDialog(QDialog, Ui_AddDirectoryDialog): |
18 class AddDirectoryDialog(QDialog, Ui_AddDirectoryDialog): |
19 """ |
19 """ |
20 Class implementing a dialog to add files of a directory to the project. |
20 Class implementing a dialog to add files of a directory to the project. |
21 """ |
21 """ |
22 def __init__(self, pro, fileTypeFilter='source', parent=None, name=None, |
22 |
23 startdir=None): |
23 def __init__( |
|
24 self, pro, fileTypeFilter="source", parent=None, name=None, startdir=None |
|
25 ): |
24 """ |
26 """ |
25 Constructor |
27 Constructor |
26 |
28 |
27 @param pro reference to the project object |
29 @param pro reference to the project object |
28 @param fileTypeFilter file type filter (string) |
30 @param fileTypeFilter file type filter (string) |
29 @param parent parent widget of this dialog (QWidget) |
31 @param parent parent widget of this dialog (QWidget) |
30 @param name name of this dialog (string) |
32 @param name name of this dialog (string) |
31 @param startdir start directory for the selection dialog |
33 @param startdir start directory for the selection dialog |
32 """ |
34 """ |
33 super().__init__(parent) |
35 super().__init__(parent) |
34 if name: |
36 if name: |
35 self.setObjectName(name) |
37 self.setObjectName(name) |
36 self.setupUi(self) |
38 self.setupUi(self) |
37 |
39 |
38 self.sourceDirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
40 self.sourceDirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
39 self.sourceDirPicker.setDefaultDirectory(startdir) |
41 self.sourceDirPicker.setDefaultDirectory(startdir) |
40 self.targetDirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
42 self.targetDirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
41 self.targetDirPicker.setDefaultDirectory(startdir) |
43 self.targetDirPicker.setDefaultDirectory(startdir) |
42 |
44 |
43 self.ppath = pro.ppath |
45 self.ppath = pro.ppath |
44 self.targetDirPicker.setText(self.ppath) |
46 self.targetDirPicker.setText(self.ppath) |
45 self.on_filterComboBox_highlighted(0) |
47 self.on_filterComboBox_highlighted(0) |
46 # enable all dialog elements |
48 # enable all dialog elements |
47 if fileTypeFilter == 'source': # it is a source file |
49 if fileTypeFilter == "source": # it is a source file |
48 self.filterComboBox.addItem( |
50 self.filterComboBox.addItem(self.tr("Source Files"), "SOURCES") |
49 self.tr("Source Files"), "SOURCES") |
51 elif fileTypeFilter == "form": |
50 elif fileTypeFilter == 'form': |
52 self.filterComboBox.addItem(self.tr("Forms Files"), "FORMS") |
51 self.filterComboBox.addItem( |
53 elif fileTypeFilter == "resource": |
52 self.tr("Forms Files"), "FORMS") |
54 self.filterComboBox.addItem(self.tr("Resource Files"), "RESOURCES") |
53 elif fileTypeFilter == 'resource': |
55 elif fileTypeFilter == "interface": |
54 self.filterComboBox.addItem( |
56 self.filterComboBox.addItem(self.tr("Interface Files"), "INTERFACES") |
55 self.tr("Resource Files"), "RESOURCES") |
57 elif fileTypeFilter == "protocol": |
56 elif fileTypeFilter == 'interface': |
58 self.filterComboBox.addItem(self.tr("Protocol Files"), "PROTOCOLS") |
57 self.filterComboBox.addItem( |
59 elif fileTypeFilter == "others": |
58 self.tr("Interface Files"), "INTERFACES") |
60 self.filterComboBox.addItem(self.tr("Other Files (*)"), "OTHERS") |
59 elif fileTypeFilter == 'protocol': |
61 self.on_filterComboBox_highlighted(self.filterComboBox.count() - 1) |
60 self.filterComboBox.addItem( |
|
61 self.tr("Protocol Files"), "PROTOCOLS") |
|
62 elif fileTypeFilter == 'others': |
|
63 self.filterComboBox.addItem( |
|
64 self.tr("Other Files (*)"), "OTHERS") |
|
65 self.on_filterComboBox_highlighted( |
|
66 self.filterComboBox.count() - 1) |
|
67 else: |
62 else: |
68 self.filterComboBox.addItem( |
63 self.filterComboBox.addItem(self.tr("Source Files"), "SOURCES") |
69 self.tr("Source Files"), "SOURCES") |
64 self.filterComboBox.addItem(self.tr("Forms Files"), "FORMS") |
70 self.filterComboBox.addItem( |
65 self.filterComboBox.addItem(self.tr("Resource Files"), "RESOURCES") |
71 self.tr("Forms Files"), "FORMS") |
66 self.filterComboBox.addItem(self.tr("Interface Files"), "INTERFACES") |
72 self.filterComboBox.addItem( |
67 self.filterComboBox.addItem(self.tr("Protocol Files"), "PROTOCOLS") |
73 self.tr("Resource Files"), "RESOURCES") |
68 self.filterComboBox.addItem(self.tr("Other Files (*)"), "OTHERS") |
74 self.filterComboBox.addItem( |
|
75 self.tr("Interface Files"), "INTERFACES") |
|
76 self.filterComboBox.addItem( |
|
77 self.tr("Protocol Files"), "PROTOCOLS") |
|
78 self.filterComboBox.addItem( |
|
79 self.tr("Other Files (*)"), "OTHERS") |
|
80 self.filterComboBox.setCurrentIndex(0) |
69 self.filterComboBox.setCurrentIndex(0) |
81 |
70 |
82 msh = self.minimumSizeHint() |
71 msh = self.minimumSizeHint() |
83 self.resize(max(self.width(), msh.width()), msh.height()) |
72 self.resize(max(self.width(), msh.width()), msh.height()) |
84 |
73 |
85 @pyqtSlot(int) |
74 @pyqtSlot(int) |
86 def on_filterComboBox_highlighted(self, index): |
75 def on_filterComboBox_highlighted(self, index): |
87 """ |
76 """ |
88 Private slot to handle the selection of a file type. |
77 Private slot to handle the selection of a file type. |
89 |
78 |
90 @param index index of the selected entry |
79 @param index index of the selected entry |
91 @type int |
80 @type int |
92 """ |
81 """ |
93 fileType = self.filterComboBox.itemData(index) |
82 fileType = self.filterComboBox.itemData(index) |
94 |
83 |
95 if fileType == "OTHERS": |
84 if fileType == "OTHERS": |
96 self.targetDirLabel.setEnabled(False) |
85 self.targetDirLabel.setEnabled(False) |
97 self.targetDirPicker.setEnabled(False) |
86 self.targetDirPicker.setEnabled(False) |
98 self.recursiveCheckBox.setEnabled(False) |
87 self.recursiveCheckBox.setEnabled(False) |
99 else: |
88 else: |
100 self.targetDirLabel.setEnabled(True) |
89 self.targetDirLabel.setEnabled(True) |
101 self.targetDirPicker.setEnabled(True) |
90 self.targetDirPicker.setEnabled(True) |
102 self.recursiveCheckBox.setEnabled(True) |
91 self.recursiveCheckBox.setEnabled(True) |
103 |
92 |
104 @pyqtSlot(str) |
93 @pyqtSlot(str) |
105 def on_sourceDirPicker_textChanged(self, directory): |
94 def on_sourceDirPicker_textChanged(self, directory): |
106 """ |
95 """ |
107 Private slot to handle the source directory text changed. |
96 Private slot to handle the source directory text changed. |
108 |
97 |
109 If the entered source directory is a subdirectory of the current |
98 If the entered source directory is a subdirectory of the current |
110 projects main directory, the target directory path is synchronized. |
99 projects main directory, the target directory path is synchronized. |
111 It is assumed, that the user wants to add a bunch of files to |
100 It is assumed, that the user wants to add a bunch of files to |
112 the project in place. |
101 the project in place. |
113 |
102 |
114 @param directory the text of the source directory line edit (string) |
103 @param directory the text of the source directory line edit (string) |
115 """ |
104 """ |
116 if directory.startswith(self.ppath): |
105 if directory.startswith(self.ppath): |
117 self.targetDirPicker.setText(directory) |
106 self.targetDirPicker.setText(directory) |
118 |
107 |
119 def getData(self): |
108 def getData(self): |
120 """ |
109 """ |
121 Public slot to retrieve the dialogs data. |
110 Public slot to retrieve the dialogs data. |
122 |
111 |
123 @return tuple of four values (string, string, string, boolean) giving |
112 @return tuple of four values (string, string, string, boolean) giving |
124 the selected file type, the source and target directory and |
113 the selected file type, the source and target directory and |
125 a flag indicating a recursive add |
114 a flag indicating a recursive add |
126 """ |
115 """ |
127 filetype = self.filterComboBox.itemData( |
116 filetype = self.filterComboBox.itemData(self.filterComboBox.currentIndex()) |
128 self.filterComboBox.currentIndex()) |
|
129 return ( |
117 return ( |
130 filetype, |
118 filetype, |
131 self.sourceDirPicker.text(), |
119 self.sourceDirPicker.text(), |
132 self.targetDirPicker.text(), |
120 self.targetDirPicker.text(), |
133 self.recursiveCheckBox.isChecked()) |
121 self.recursiveCheckBox.isChecked(), |
|
122 ) |