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

reporegistry: add context menu with "open" action for repo nodes

Changeset 781df6ece173

Parent c7511f08ca12

by Adrian Buehlmann

Changes to 2 files · Browse files at 781df6ece173 Showing diff from parent c7511f08ca12 Diff from another changeset...

 
47
48
49
 
 
 
50
51
52
53
54
 
 
 
 
55
56
57
58
 
59
60
 
61
62
 
 
 
63
64
65
 
154
155
156
157
 
158
159
160
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
 
 
 
163
164
165
 
169
170
171
172
 
173
174
175
 
185
186
187
 
 
 
 
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
 
163
164
165
 
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
 
234
235
236
 
237
238
239
240
 
250
251
252
253
254
255
@@ -47,19 +47,28 @@
  def parent(self):   return self._parent   + def menulist(self): + return [] +    class RepoItem(RepoTreeItem):   def __init__(self, rootpath, parent=None):   RepoTreeItem.__init__(self, parent) - self.rootpath = rootpath + self._rootpath = rootpath + + def rootpath(self): + return self._rootpath     def data(self, column):   if column == 0: - return QVariant(os.path.basename(self.rootpath)) + return QVariant(os.path.basename(self._rootpath))   elif column == 1: - return QVariant(self.rootpath) + return QVariant(self._rootpath)   return QVariant()   + def menulist(self): + return ['open'] +    class RepoGroupItem(RepoTreeItem):   def __init__(self, name, parent=None): @@ -154,12 +163,68 @@
    def getRepoItem(self, reporoot):   for c in self.allrepos.childs: - if c.rootpath == reporoot: + if c.rootpath() == reporoot:   return c   return None     +class RepoTreeView(QtGui.QTreeView): + def __init__(self, parent): + QtGui.QTreeView.__init__(self) + self.parent = parent + self.selitem = None + self.createActions() + + def contextMenuEvent(self, event): + selection = self.selectedIndexes() + if len(selection) == 0: + return + self.selitem = selection[0].internalPointer() + menulist = self.selitem.menulist() + if len(menulist) > 0: + menu = QtGui.QMenu(self) + for act in menulist: + if act: + menu.addAction(self._actions[act]) + else: + menu.addSeparator() + menu.exec_(event.globalPos()) + + def _action_defs(self): + a = [("open", _("Open"), None, + _("Opens the repository in a new tab"), None, self.open) + ] + return a + + def createActions(self): + self._actions = {} + for name, desc, icon, tip, key, cb in self._action_defs(): + self._actions[name] = QtGui.QAction(desc, self) + QtCore.QTimer.singleShot(0, self.configureActions) + + def configureActions(self): + for name, desc, icon, tip, key, cb in self._action_defs(): + act = self._actions[name] + ''' + if icon: + act.setIcon(geticon(icon)) + ''' + if tip: + act.setStatusTip(tip) + if key: + act.setShortcut(key) + if cb: + connect(act, SIGNAL('triggered()'), cb) + self.addAction(act) + + def open(self): + self.parent.openrepo(self.selitem.rootpath()) + +  class RepoRegistryView(QWidget): + + openRepoSignal = QtCore.pyqtSignal(QtCore.QString) +   def __init__(self, parent=None):   QWidget.__init__(self, parent)   @@ -169,7 +234,7 @@
    self.tmodel = m = RepoTreeModel()   - self.tview = tv = QtGui.QTreeView() + self.tview = tv = RepoTreeView(self)   lay.addWidget(tv)   tv.setModel(m)   @@ -185,3 +250,6 @@
  m = self.tmodel   if m.getRepoItem(reporoot) == None:   m.addRepo(reporoot) + + def openrepo(self, path): + self.openRepoSignal.emit(path)
 
77
78
79
 
 
 
 
 
 
80
81
82
 
77
78
79
80
81
82
83
84
85
86
87
88
@@ -77,6 +77,12 @@
    self.setAcceptDrops(True)   + self.reporegistry.openRepoSignal.connect(self.openRepo) + + def openRepo(self, repopath): + repo = hg.repository(self.ui, path=str(repopath)) + self.addRepoTab(repo) +   def find_root(self, url):   p = str(url.toLocalFile())   return paths.find_root(p)