40 def __init__(self, type_, bold=False): |
40 def __init__(self, type_, bold=False): |
41 """ |
41 """ |
42 Constructor |
42 Constructor |
43 |
43 |
44 @param type_ type of file/directory in the project |
44 @param type_ type of file/directory in the project |
|
45 @type str |
45 @param bold flag indicating a highlighted font |
46 @param bold flag indicating a highlighted font |
|
47 @type bool |
46 """ |
48 """ |
47 self._projectTypes = [type_] |
49 self._projectTypes = [type_] |
48 self.bold = bold |
50 self.bold = bold |
49 self.vcsState = " " |
51 self.vcsState = " " |
50 |
52 |
51 def getTextColor(self): |
53 def getTextColor(self): |
52 """ |
54 """ |
53 Public method to get the items text color. |
55 Public method to get the items text color. |
54 |
56 |
55 @return text color (QColor) |
57 @return text color |
|
58 @rtype QColor |
56 """ |
59 """ |
57 if self.bold: |
60 if self.bold: |
58 return Preferences.getProjectBrowserColour("Highlighted") |
61 return Preferences.getProjectBrowserColour("Highlighted") |
59 else: |
62 else: |
60 return None |
63 return None |
61 |
64 |
62 def setVcsState(self, state): |
65 def setVcsState(self, state): |
63 """ |
66 """ |
64 Public method to set the items VCS state. |
67 Public method to set the items VCS state. |
65 |
68 |
66 @param state VCS state (one of A, C, M, U or " ") (string) |
69 @param state VCS state (one of A, C, M, U or " ") |
|
70 @type str |
67 """ |
71 """ |
68 self.vcsState = state |
72 self.vcsState = state |
69 |
73 |
70 def addVcsStatus(self, vcsStatus): |
74 def addVcsStatus(self, vcsStatus): |
71 """ |
75 """ |
72 Public method to add the VCS status. |
76 Public method to add the VCS status. |
73 |
77 |
74 @param vcsStatus VCS status text (string) |
78 @param vcsStatus VCS status text |
|
79 @type str |
75 """ |
80 """ |
76 self.itemData.append(vcsStatus) |
81 self.itemData.append(vcsStatus) |
77 |
82 |
78 def setVcsStatus(self, vcsStatus): |
83 def setVcsStatus(self, vcsStatus): |
79 """ |
84 """ |
80 Public method to set the VCS status. |
85 Public method to set the VCS status. |
81 |
86 |
82 @param vcsStatus VCS status text (string) |
87 @param vcsStatus VCS status text |
|
88 @type str |
83 """ |
89 """ |
84 self.itemData[1] = vcsStatus |
90 self.itemData[1] = vcsStatus |
85 |
91 |
86 def getProjectTypes(self): |
92 def getProjectTypes(self): |
87 """ |
93 """ |
88 Public method to get the project type. |
94 Public method to get the project type. |
89 |
95 |
90 @return project type |
96 @return project type |
|
97 @rtype str |
91 """ |
98 """ |
92 return self._projectTypes[:] |
99 return self._projectTypes[:] |
93 |
100 |
94 def addProjectType(self, type_): |
101 def addProjectType(self, type_): |
95 """ |
102 """ |
96 Public method to add a type to the list. |
103 Public method to add a type to the list. |
97 |
104 |
98 @param type_ type to add to the list |
105 @param type_ type to add to the list |
|
106 @type str |
99 """ |
107 """ |
100 self._projectTypes.append(type_) |
108 self._projectTypes.append(type_) |
101 |
109 |
102 |
110 |
103 class ProjectBrowserSimpleDirectoryItem( |
111 class ProjectBrowserSimpleDirectoryItem( |
111 def __init__(self, parent, projectType, text, path=""): |
119 def __init__(self, parent, projectType, text, path=""): |
112 """ |
120 """ |
113 Constructor |
121 Constructor |
114 |
122 |
115 @param parent parent item |
123 @param parent parent item |
|
124 @type BrowserItem |
116 @param projectType type of file/directory in the project |
125 @param projectType type of file/directory in the project |
117 @param text text to be displayed (string) |
126 @type str |
118 @param path path of the directory (string) |
127 @param text text to be displayed |
|
128 @type str |
|
129 @param path path of the directory |
|
130 @type str |
119 """ |
131 """ |
120 BrowserSimpleDirectoryItem.__init__(self, parent, text, path=path) |
132 BrowserSimpleDirectoryItem.__init__(self, parent, text, path=path) |
121 ProjectBrowserItemMixin.__init__(self, projectType) |
133 ProjectBrowserItemMixin.__init__(self, projectType) |
122 |
134 |
123 self.type_ = ProjectBrowserItemSimpleDirectory |
135 self.type_ = ProjectBrowserItemSimpleDirectory |
131 def __init__(self, parent, dinfo, projectType, full=True, bold=False): |
143 def __init__(self, parent, dinfo, projectType, full=True, bold=False): |
132 """ |
144 """ |
133 Constructor |
145 Constructor |
134 |
146 |
135 @param parent parent item |
147 @param parent parent item |
136 @param dinfo dinfo is the string for the directory (string) |
148 @type BrowserItem |
|
149 @param dinfo dinfo is the string for the directory |
|
150 @type str |
137 @param projectType type of file/directory in the project |
151 @param projectType type of file/directory in the project |
138 @param full flag indicating full pathname should be displayed (boolean) |
152 @type str |
139 @param bold flag indicating a highlighted font (boolean) |
153 @param full flag indicating full pathname should be displayed |
|
154 @type bool |
|
155 @param bold flag indicating a highlighted font |
|
156 @type bool |
140 """ |
157 """ |
141 BrowserDirectoryItem.__init__(self, parent, dinfo, full) |
158 BrowserDirectoryItem.__init__(self, parent, dinfo, full) |
142 ProjectBrowserItemMixin.__init__(self, projectType, bold) |
159 ProjectBrowserItemMixin.__init__(self, projectType, bold) |
143 |
160 |
144 self.type_ = ProjectBrowserItemDirectory |
161 self.type_ = ProjectBrowserItemDirectory |
154 ): |
171 ): |
155 """ |
172 """ |
156 Constructor |
173 Constructor |
157 |
174 |
158 @param parent parent item |
175 @param parent parent item |
159 @param finfo the string for the file (string) |
176 @type BrowserItem |
|
177 @param finfo the string for the file |
|
178 @type str |
160 @param projectType type of file/directory in the project |
179 @param projectType type of file/directory in the project |
161 @param full flag indicating full pathname should be displayed (boolean) |
180 @type str |
162 @param bold flag indicating a highlighted font (boolean) |
181 @param full flag indicating full pathname should be displayed |
163 @param sourceLanguage source code language of the project (string) |
182 @type bool |
|
183 @param bold flag indicating a highlighted font |
|
184 @type bool |
|
185 @param sourceLanguage source code language of the project |
|
186 @type str |
164 """ |
187 """ |
165 BrowserFileItem.__init__(self, parent, finfo, full, sourceLanguage) |
188 BrowserFileItem.__init__(self, parent, finfo, full, sourceLanguage) |
166 ProjectBrowserItemMixin.__init__(self, projectType, bold) |
189 ProjectBrowserItemMixin.__init__(self, projectType, bold) |
167 |
190 |
168 self.type_ = ProjectBrowserItemFile |
191 self.type_ = ProjectBrowserItemFile |
179 |
202 |
180 def __init__(self, parent): |
203 def __init__(self, parent): |
181 """ |
204 """ |
182 Constructor |
205 Constructor |
183 |
206 |
184 @param parent reference to parent object (Project.Project) |
207 @param parent reference to parent object |
|
208 @type Project.Project |
185 """ |
209 """ |
186 super().__init__(parent, nopopulate=True) |
210 super().__init__(parent, nopopulate=True) |
187 |
211 |
188 rootData = self.tr("Name") |
212 rootData = self.tr("Name") |
189 self.rootItem = BrowserItem(None, rootData) |
213 self.rootItem = BrowserItem(None, rootData) |
234 |
258 |
235 def data(self, index, role): |
259 def data(self, index, role): |
236 """ |
260 """ |
237 Public method to get data of an item. |
261 Public method to get data of an item. |
238 |
262 |
239 @param index index of the data to retrieve (QModelIndex) |
263 @param index index of the data to retrieve |
240 @param role role of data (Qt.ItemDataRole) |
264 @type QModelIndex |
|
265 @param role role of data |
|
266 @type Qt.ItemDataRole |
241 @return requested data |
267 @return requested data |
|
268 @rtype Any |
242 """ |
269 """ |
243 if not index.isValid(): |
270 if not index.isValid(): |
244 return None |
271 return None |
245 |
272 |
246 if role == Qt.ItemDataRole.ForegroundRole: |
273 if role == Qt.ItemDataRole.ForegroundRole: |
266 def populateItem(self, parentItem, repopulate=False): |
293 def populateItem(self, parentItem, repopulate=False): |
267 """ |
294 """ |
268 Public method to populate an item's subtree. |
295 Public method to populate an item's subtree. |
269 |
296 |
270 @param parentItem reference to the item to be populated |
297 @param parentItem reference to the item to be populated |
271 @param repopulate flag indicating a repopulation (boolean) |
298 @type BrowserItem |
|
299 @param repopulate flag indicating a repopulation |
|
300 @type bool |
272 """ |
301 """ |
273 if parentItem.type() == ProjectBrowserItemSimpleDirectory: |
302 if parentItem.type() == ProjectBrowserItemSimpleDirectory: |
274 return # nothing to do |
303 return # nothing to do |
275 elif parentItem.type() == ProjectBrowserItemDirectory: |
304 elif parentItem.type() == ProjectBrowserItemDirectory: |
276 self.populateProjectDirectoryItem(parentItem, repopulate) |
305 self.populateProjectDirectoryItem(parentItem, repopulate) |
282 def populateProjectDirectoryItem(self, parentItem, repopulate=False): |
311 def populateProjectDirectoryItem(self, parentItem, repopulate=False): |
283 """ |
312 """ |
284 Public method to populate a directory item's subtree. |
313 Public method to populate a directory item's subtree. |
285 |
314 |
286 @param parentItem reference to the directory item to be populated |
315 @param parentItem reference to the directory item to be populated |
287 @param repopulate flag indicating a repopulation (boolean) |
316 @type BrowserItem |
|
317 @param repopulate flag indicating a repopulation |
|
318 @type bool |
288 """ |
319 """ |
289 self._addWatchedItem(parentItem) |
320 self._addWatchedItem(parentItem) |
290 |
321 |
291 qdir = QDir(parentItem.dirName()) |
322 qdir = QDir(parentItem.dirName()) |
292 |
323 |
432 |
463 |
433 <b>Note</b>: This method creates all necessary parent items, if they |
464 <b>Note</b>: This method creates all necessary parent items, if they |
434 don't exist. |
465 don't exist. |
435 |
466 |
436 @param type_ type of the item |
467 @param type_ type of the item |
437 @param name name of the item (string) |
468 @type str |
438 @param dontSplit flag indicating the name should not be split (boolean) |
469 @param name name of the item |
439 @return reference to the item found and the new display name (string) |
470 @type str |
|
471 @param dontSplit flag indicating the name should not be split |
|
472 @type bool |
|
473 @return reference to the item found and the new display name |
|
474 @rtype str |
440 """ |
475 """ |
441 if dontSplit: |
476 if dontSplit: |
442 pathlist = [] |
477 pathlist = [] |
443 pathlist.append(name) |
478 pathlist.append(name) |
444 pathlist.append("ignore_me") |
479 pathlist.append("ignore_me") |
472 |
507 |
473 def findChildItem(self, text, column, parentItem=None): |
508 def findChildItem(self, text, column, parentItem=None): |
474 """ |
509 """ |
475 Public method to find a child item given some text. |
510 Public method to find a child item given some text. |
476 |
511 |
477 @param text text to search for (string) |
512 @param text text to search for |
478 @param column column to search in (integer) |
513 @type str |
|
514 @param column column to search in |
|
515 @type int |
479 @param parentItem reference to parent item |
516 @param parentItem reference to parent item |
|
517 @type BrowserItem |
480 @return reference to the item found |
518 @return reference to the item found |
|
519 @rtype BrowserItem |
481 """ |
520 """ |
482 if parentItem is None: |
521 if parentItem is None: |
483 parentItem = self.rootItem |
522 parentItem = self.rootItem |
484 |
523 |
485 for itm in parentItem.children(): |
524 for itm in parentItem.children(): |
490 |
529 |
491 def addNewItem(self, typeString, name, additionalTypeStrings=None): |
530 def addNewItem(self, typeString, name, additionalTypeStrings=None): |
492 """ |
531 """ |
493 Public method to add a new item to the model. |
532 Public method to add a new item to the model. |
494 |
533 |
495 @param typeString string denoting the type of the new item (string) |
534 @param typeString string denoting the type of the new item |
496 @param name name of the new item (string) |
535 @type str |
497 @param additionalTypeStrings names of additional types (list of string) |
536 @param name name of the new item |
|
537 @type str |
|
538 @param additionalTypeStrings names of additional types |
|
539 @type list of str |
498 """ |
540 """ |
499 # Show the entry in bold in the others browser to make it more |
541 # Show the entry in bold in the others browser to make it more |
500 # distinguishable |
542 # distinguishable |
501 bold = typeString == "OTHERS" |
543 bold = typeString == "OTHERS" |
502 |
544 |
557 |
601 |
558 def findItem(self, name): |
602 def findItem(self, name): |
559 """ |
603 """ |
560 Public method to find an item given its name. |
604 Public method to find an item given its name. |
561 |
605 |
562 @param name name of the item (string) |
606 @param name name of the item |
|
607 @type str |
563 @return reference to the item found |
608 @return reference to the item found |
|
609 @rtype BrowserItem |
564 """ |
610 """ |
565 if QDir.isAbsolutePath(name): |
611 if QDir.isAbsolutePath(name): |
566 name = self.project.getRelativePath(name) |
612 name = self.project.getRelativePath(name) |
567 pathlist = re.split(r"/|\\", name) |
613 pathlist = re.split(r"/|\\", name) |
568 if len(pathlist) > 0: |
614 if len(pathlist) > 0: |
578 |
624 |
579 def itemIndexByName(self, name): |
625 def itemIndexByName(self, name): |
580 """ |
626 """ |
581 Public method to find an item's index given its name. |
627 Public method to find an item's index given its name. |
582 |
628 |
583 @param name name of the item (string) |
629 @param name name of the item |
584 @return index of the item found (QModelIndex) |
630 @type str |
|
631 @return index of the item found |
|
632 @rtype QModelIndex |
585 """ |
633 """ |
586 itm = self.findItem(name) |
634 itm = self.findItem(name) |
587 index = self.createIndex(itm.row(), 0, itm) if itm else QModelIndex() |
635 index = self.createIndex(itm.row(), 0, itm) if itm else QModelIndex() |
588 return index |
636 return index |
589 |
637 |
590 def itemIndexByNameAndLine(self, name, lineno): |
638 def itemIndexByNameAndLine(self, name, lineno): |
591 """ |
639 """ |
592 Public method to find an item's index given its name. |
640 Public method to find an item's index given its name. |
593 |
641 |
594 @param name name of the item (string) |
642 @param name name of the item |
595 @param lineno one based line number of the item (integer) |
643 @type str |
596 @return index of the item found (QModelIndex) |
644 @param lineno one based line number of the item |
|
645 @type int |
|
646 @return index of the item found |
|
647 @rtype QModelIndex |
597 """ |
648 """ |
598 index = QModelIndex() |
649 index = QModelIndex() |
599 itm = self.findItem(name) |
650 itm = self.findItem(name) |
600 if itm is not None and isinstance(itm, ProjectBrowserFileItem): |
651 if itm is not None and isinstance(itm, ProjectBrowserFileItem): |
601 olditem = itm |
652 olditem = itm |
721 def __addVCSStatus(self, item, name): |
773 def __addVCSStatus(self, item, name): |
722 """ |
774 """ |
723 Private method used to set the vcs status of a node. |
775 Private method used to set the vcs status of a node. |
724 |
776 |
725 @param item item to work on |
777 @param item item to work on |
726 @param name filename belonging to this item (string) |
778 @type BrowserItem |
|
779 @param name filename belonging to this item |
|
780 @type str |
727 """ |
781 """ |
728 vcs = self.project.vcs |
782 vcs = self.project.vcs |
729 if vcs is not None: |
783 if vcs is not None: |
730 state = vcs.vcsRegisteredState(name) |
784 state = vcs.vcsRegisteredState(name) |
731 if state == vcs.canBeCommitted: |
785 if state == vcs.canBeCommitted: |
738 def __updateVCSStatus(self, item, name, recursive=True): |
792 def __updateVCSStatus(self, item, name, recursive=True): |
739 """ |
793 """ |
740 Private method used to update the vcs status of a node. |
794 Private method used to update the vcs status of a node. |
741 |
795 |
742 @param item item to work on |
796 @param item item to work on |
743 @param name filename belonging to this item (string) |
797 @type BrowserItem |
744 @param recursive flag indicating a recursive update (boolean) |
798 @param name filename belonging to this item |
|
799 @type str |
|
800 @param recursive flag indicating a recursive update |
|
801 @type bool |
745 """ |
802 """ |
746 vcs = self.project.vcs |
803 vcs = self.project.vcs |
747 if vcs is not None: |
804 if vcs is not None: |
748 vcs.clearStatusCache() |
805 vcs.clearStatusCache() |
749 state = vcs.vcsRegisteredState(name) |
806 state = vcs.vcsRegisteredState(name) |
764 |
821 |
765 def updateVCSStatus(self, name, recursive=True): |
822 def updateVCSStatus(self, name, recursive=True): |
766 """ |
823 """ |
767 Public method used to update the vcs status of a node. |
824 Public method used to update the vcs status of a node. |
768 |
825 |
769 @param name filename belonging to this item (string) |
826 @param name filename belonging to this item |
770 @param recursive flag indicating a recursive update (boolean) |
827 @type str |
|
828 @param recursive flag indicating a recursive update |
|
829 @type bool |
771 """ |
830 """ |
772 item = self.findItem(name) |
831 item = self.findItem(name) |
773 if item: |
832 if item: |
774 self.__updateVCSStatus(item, name, recursive) |
833 self.__updateVCSStatus(item, name, recursive) |
775 |
834 |
776 def removeItem(self, name): |
835 def removeItem(self, name): |
777 """ |
836 """ |
778 Public method to remove a named item. |
837 Public method to remove a named item. |
779 |
838 |
780 @param name file or directory name of the item (string). |
839 @param name file or directory name of the item |
|
840 @type str |
781 """ |
841 """ |
782 fname = os.path.basename(name) |
842 fname = os.path.basename(name) |
783 parentItem = self.findParentItemByName(0, name)[0] |
843 parentItem = self.findParentItemByName(0, name)[0] |
784 parentIndex = ( |
844 parentIndex = ( |
785 QModelIndex() |
845 QModelIndex() |
825 |
886 |
826 def changeVCSStates(self, statesList): |
887 def changeVCSStates(self, statesList): |
827 """ |
888 """ |
828 Public slot to record the (non normal) VCS states. |
889 Public slot to record the (non normal) VCS states. |
829 |
890 |
830 @param statesList list of VCS state entries (list of strings) giving |
891 @param statesList list of VCS state entries giving the states in the |
831 the states in the first column and the path relative to the project |
892 first column and the path relative to the project directory starting |
832 directory starting with the third column. The allowed status flags |
893 with the third column. The allowed status flags are: |
833 are: |
|
834 <ul> |
894 <ul> |
835 <li>"A" path was added but not yet comitted</li> |
895 <li>"A" path was added but not yet comitted</li> |
836 <li>"M" path has local changes</li> |
896 <li>"M" path has local changes</li> |
837 <li>"O" path was removed</li> |
897 <li>"O" path was removed</li> |
838 <li>"R" path was deleted and then re-added</li> |
898 <li>"R" path was deleted and then re-added</li> |
839 <li>"U" path needs an update</li> |
899 <li>"U" path needs an update</li> |
840 <li>"Z" path contains a conflict</li> |
900 <li>"Z" path contains a conflict</li> |
841 <li>" " path is back at normal</li> |
901 <li>" " path is back at normal</li> |
842 </ul> |
902 </ul> |
|
903 @type list of str |
843 """ |
904 """ |
844 statesList.sort() |
905 statesList.sort() |
845 lastHead = "" |
906 lastHead = "" |
846 itemCache = {} |
907 itemCache = {} |
847 if len(statesList) == 1 and statesList[0] == "--RESET--": |
908 if len(statesList) == 1 and statesList[0] == "--RESET--": |
889 |
950 |
890 def __changeParentsVCSState(self, path, itemCache): |
951 def __changeParentsVCSState(self, path, itemCache): |
891 """ |
952 """ |
892 Private method to recursively change the parents VCS state. |
953 Private method to recursively change the parents VCS state. |
893 |
954 |
894 @param path pathname of parent item (string) |
955 @param path pathname of parent item |
|
956 @type str |
895 @param itemCache reference to the item cache used to store |
957 @param itemCache reference to the item cache used to store |
896 references to named items |
958 references to named items |
|
959 @type dict |
897 """ |
960 """ |
898 while path: |
961 while path: |
899 try: |
962 try: |
900 itm = itemCache[path] |
963 itm = itemCache[path] |
901 except KeyError: |
964 except KeyError: |