Merge lp:~craighewetson/qbzr/qlog-revert-multi-tree into lp:qbzr

Proposed by Craig Hewetson on 2010-05-20
Status: Merged
Merged at revision: 1290
Proposed branch: lp:~craighewetson/qbzr/qlog-revert-multi-tree
Merge into: lp:qbzr
Diff against target: 100 lines (+54/-13)
1 file modified
lib/logwidget.py (+54/-13)
To merge this branch: bzr merge lp:~craighewetson/qbzr/qlog-revert-multi-tree
Reviewer Review Type Date Requested Status
QBzr Developers 2010-05-20 Pending
Review via email: mp+25724@code.launchpad.net

Description of the Change

I've given the "revert from qlog with the option to select working trees", a go...
I'm doing something stupid please feel free to crit.
NOTE: I'm not so good with python.

I've used a disable menu item and a separate as some form of a heading for the "list" of working trees, not sure if this is the best approach.

If this is "Approved" I'll do the same for the per-file revert menu and the Tag actions.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/logwidget.py'
2--- lib/logwidget.py 2010-05-20 14:24:24 +0000
3+++ lib/logwidget.py 2010-05-20 21:59:22 +0000
4@@ -150,8 +150,9 @@
5 self.context_menu.addAction(gettext("Tag &revision..."),
6 self.tag_revision)
7 self.context_menu_revert = \
8- self.context_menu.addAction(gettext("Revert to this revision..."),
9+ self.context_menu.addAction(gettext("R&evert to this revision..."),
10 self.revert_revision)
11+ self.revert_menu = None
12
13 def load_branch(self, branch, fileids, tree=None):
14 self.throbber.show()
15@@ -378,20 +379,28 @@
16 window.show()
17 self.window().windows.append(window)
18
19- def revert_revision(self):
20- """Reverts the working tree to the selected revision."""
21+ def revert_revision(self, selected_working_tree=None):
22+ """Reverts the working tree to the selected revision.
23+ If there are more than 1 working tree the argument
24+ selected_working_tree will be specified as QVariant
25+ with a working tree as a python object.
26+ This will be the working tree that the user selected."""
27 res = QtGui.QMessageBox.question(self, gettext("Revert Revision"),
28 gettext("Are you sure you want to revert the working "
29 "tree to the selected revision?"
30 ),QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
31 if res == QtGui.QMessageBox.Yes:
32- (top_revid, old_revid), count = \
33- self.get_selection_top_and_parent_revids_and_count()
34- gp = self.graph_provider
35- assert(len(gp.branches)==1)
36- branch_info = gp.branches[0]
37- rev_tree = gp.get_revid_repo(top_revid).revision_tree(top_revid)
38- branch_info.tree.revert(filenames=None, old_tree=rev_tree,
39+ (top_revid, old_revid), count = \
40+ self.get_selection_top_and_parent_revids_and_count()
41+ gp = self.graph_provider
42+ rev_tree = gp.get_revid_repo(top_revid).revision_tree(top_revid)
43+ if selected_working_tree:
44+ wt = selected_working_tree.toPyObject()
45+ wt.revert(filenames=None,old_tree=rev_tree, report_changes=True)
46+ else:
47+ assert(len(gp.branches)==1)
48+ branch_info = gp.branches[0]
49+ branch_info.tree.revert(filenames=None, old_tree=rev_tree,
50 report_changes=True)
51
52 def show_diff(self, index=None,
53@@ -444,13 +453,45 @@
54 branch_count == 1 and self.graph_provider.branches[0].tree)
55 (top_revid, old_revid), count = \
56 self.get_selection_top_and_parent_revids_and_count()
57-
58+ working_tree_count = 0
59+ for b in self.graph_provider.branches:
60+ if b.tree:
61+ working_tree_count = working_tree_count + 1
62+
63 self.context_menu_tag.setVisible(count == 1 and branch_count == 1)
64- self.context_menu_revert.setVisible(count == 1 and
65+ self.context_menu_revert.setVisible(False)
66+ if single_branch_with_tree:
67+ self.context_menu_revert.setVisible(count == 1 and
68 single_branch_with_tree)
69-
70+ elif working_tree_count > 0 and (self.revert_menu == None):
71+ self.revert_menu = RevertMenu(self, self.graph_provider.branches)
72+ self.connect(self.revert_menu, QtCore.SIGNAL("triggered(QVariant)"),
73+ self.revert_revision)
74+ self.context_menu.addMenu(self.revert_menu)
75+
76 self.context_menu.popup(self.viewport().mapToGlobal(pos))
77
78+class RevertMenu(QtGui.QMenu):
79+
80+ def __init__ (self, parent, branches):
81+ QtGui.QMenu.__init__(self, gettext("&Revert to this revision..."),
82+ parent)
83+ action = QtGui.QAction("Working Trees:", self)
84+ action.setData(None)
85+ action.setEnabled(False)
86+ self.addAction(action)
87+ self.addSeparator()
88+ for branch in branches:
89+ if branch.tree:
90+ action = QtGui.QAction(str(branch.tree.basedir), self)
91+ action.setData(QtCore.QVariant (branch.tree))
92+ self.addAction(action)
93+
94+ self.connect(self, QtCore.SIGNAL("triggered(QAction *)"),
95+ self.triggered)
96+
97+ def triggered(self, action):
98+ self.emit(QtCore.SIGNAL("triggered(QVariant)"), action.data())
99
100 class GraphTagsBugsItemDelegate(QtGui.QStyledItemDelegate):
101

Subscribers

People subscribed via source and target branches