Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

add initial version of a "repository registry" widget to workbench

inspired by MacHg

Changeset 1ca58b3e828d

Parent 52576d86fa09

by Adrian Buehlmann

Changes to 3 files · Browse files at 1ca58b3e828d Showing diff from parent 52576d86fa09 Diff from another changeset...

Change 1 of 1 Show Entire File tortoisehg/​hgqt/​reporegistry.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@@ -0,0 +1,126 @@
+# reporegistry.py - registry for a user's repositories +# +# Copyright 2010 Adrian Buehlmann <adrian@cadifra.com> +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. + +from PyQt4 import QtCore, QtGui + +from PyQt4.QtCore import Qt, QVariant, SIGNAL, SLOT +from PyQt4.QtCore import QModelIndex + +from PyQt4.QtGui import QWidget, QVBoxLayout + +from tortoisehg.hgqt.i18n import _ + +connect = QtCore.QObject.connect + +class RepoTreeItem: + def __init__(self, name, parent=None): + self.name = name + self._parent = parent + self.childs = [] + self._row = 0 + + def appendChild(self, child): + child._row = len(self.childs) + child._parent = self + self.childs.append(child) + + def child(self, row): + return self.childs[row] + + def childCount(self): + return len(self.childs) + + def columnCount(self): + return 1 + + def data(self, column): + return QVariant(self.name) + + def row(self): + return self._row + + def parent(self): + return self._parent + + +class RepoTreeModel(QtCore.QAbstractItemModel): + def __init__(self, parent=None): + QtCore.QAbstractItemModel.__init__(self, parent) + + self.rootItem = root = RepoTreeItem('') + + self.allrepos = all = RepoTreeItem(_('All Repositories')) + root.appendChild(all) + + all.appendChild(RepoTreeItem('dummy-repo-A')) + all.appendChild(RepoTreeItem('dummy-repo-B')) + all.appendChild(RepoTreeItem('dummy-repo-C')) + + def index(self, row, column, parent): + if not self.hasIndex(row, column, parent): + return QModelIndex() + if (not parent.isValid()): + parentItem = self.rootItem + else: + parentItem = parent.internalPointer() + childItem = parentItem.child(row) + if childItem: + return self.createIndex(row, column, childItem) + else: + return QModelIndex() + + def parent(self, index): + if not index.isValid(): + return QModelIndex() + childItem = index.internalPointer() + parentItem = childItem.parent() + if parentItem is self.rootItem: + return QModelIndex() + return self.createIndex(parentItem.row(), 0, parentItem) + + def rowCount(self, parent): + if parent.column() > 0: + return 0 + if not parent.isValid(): + parentItem = self.rootItem; + else: + parentItem = parent.internalPointer() + return parentItem.childCount() + + def columnCount(self, parent): + if parent.isValid(): + return parent.internalPointer().columnCount() + else: + return self.rootItem.columnCount() + + def data(self, index, role): + if not index.isValid(): + return QVariant() + if role != Qt.DisplayRole: + return QVariant(); + item = index.internalPointer() + return item.data(index.column()) + + def flags(self, index): + if not index.isValid(): + return 0 + return Qt.ItemIsEnabled | Qt.ItemIsSelectable + + +class RepoRegistryView(QWidget): + def __init__(self, parent=None): + QWidget.__init__(self, parent) + + lay = QVBoxLayout() + lay.setContentsMargins(0, 0, 0, 0) + self.setLayout(lay) + + self.tmodel = m = RepoTreeModel() + + self.tview = tv = QtGui.QTreeView() + lay.addWidget(tv) + tv.setModel(m)
 
26
27
28
29
30
31
 
 
 
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
47
48
 
197
198
199
 
 
 
 
 
 
 
 
200
201
202
 
26
27
28
 
 
 
29
30
31
32
 
 
 
 
 
 
 
 
 
 
 
 
 
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
203
204
205
206
207
208
209
210
211
212
213
214
215
216
@@ -26,23 +26,29 @@
  <number>0</number>   </property>   <item> - <widget class="QTabWidget" name="repoTabsWidget"> - <property name="currentIndex"> - <number>0</number> + <widget class="QSplitter" name="reporegistrysplitter"> + <property name="orientation"> + <enum>Qt::Horizontal</enum>   </property> - <property name="documentMode"> - <bool>true</bool> - </property> - <property name="tabsClosable"> - <bool>true</bool> - </property> - <property name="movable"> - <bool>true</bool> - </property> - <widget class="QWidget" name="firstRepoTab"> - <attribute name="title"> - <string>repo1</string> - </attribute> + <widget class="RepoRegistryView" name="reporegistry" native="true"/> + <widget class="QTabWidget" name="repoTabsWidget"> + <property name="currentIndex"> + <number>0</number> + </property> + <property name="documentMode"> + <bool>true</bool> + </property> + <property name="tabsClosable"> + <bool>true</bool> + </property> + <property name="movable"> + <bool>true</bool> + </property> + <widget class="QWidget" name="firstRepoTab"> + <attribute name="title"> + <string>repo1</string> + </attribute> + </widget>   </widget>   </widget>   </item> @@ -197,6 +203,14 @@
  </property>   </action>   </widget> + <customwidgets> + <customwidget> + <class>RepoRegistryView</class> + <extends>QWidget</extends> + <header>reporegistry.h</header> + <container>1</container> + </customwidget> + </customwidgets>   <resources>   <include location="workbench.qrc"/>   </resources>
 
2
3
4
5
 
6
7
8
 
22
23
24
25
 
 
 
 
 
 
26
27
28
 
30
31
32
33
 
34
35
36
 
121
122
123
 
124
 
2
3
4
 
5
6
7
8
 
22
23
24
 
25
26
27
28
29
30
31
32
33
 
35
36
37
 
38
39
40
41
 
126
127
128
129
130
@@ -2,7 +2,7 @@
   # Form implementation generated from reading ui file 'C:\Users\adi\hgrepos\thg-qt\tortoisehg\hgqt\workbench.ui'  # -# Created: Sat May 15 20:00:23 2010 +# Created: Sun May 16 12:30:17 2010  # by: PyQt4 UI code generator 4.7.3  #  # WARNING! All changes made in this file will be lost! @@ -22,7 +22,12 @@
  self.horizontalLayout.setSpacing(0)   self.horizontalLayout.setMargin(0)   self.horizontalLayout.setObjectName("horizontalLayout") - self.repoTabsWidget = QtGui.QTabWidget(self.centralwidget) + self.reporegistrysplitter = QtGui.QSplitter(self.centralwidget) + self.reporegistrysplitter.setOrientation(QtCore.Qt.Horizontal) + self.reporegistrysplitter.setObjectName("reporegistrysplitter") + self.reporegistry = RepoRegistryView(self.reporegistrysplitter) + self.reporegistry.setObjectName("reporegistry") + self.repoTabsWidget = QtGui.QTabWidget(self.reporegistrysplitter)   self.repoTabsWidget.setDocumentMode(True)   self.repoTabsWidget.setTabsClosable(True)   self.repoTabsWidget.setMovable(True) @@ -30,7 +35,7 @@
  self.firstRepoTab = QtGui.QWidget()   self.firstRepoTab.setObjectName("firstRepoTab")   self.repoTabsWidget.addTab(self.firstRepoTab, "") - self.horizontalLayout.addWidget(self.repoTabsWidget) + self.horizontalLayout.addWidget(self.reporegistrysplitter)   MainWindow.setCentralWidget(self.centralwidget)   self.menubar = QtGui.QMenuBar(MainWindow)   self.menubar.setGeometry(QtCore.QRect(0, 0, 671, 19)) @@ -121,4 +126,5 @@
  self.actionBack.setText(QtGui.QApplication.translate("MainWindow", "Back", None, QtGui.QApplication.UnicodeUTF8))   self.actionForward.setText(QtGui.QApplication.translate("MainWindow", "Forward", None, QtGui.QApplication.UnicodeUTF8))   +from reporegistry import RepoRegistryView  import workbench_rc