Merge lp://staging/~nmb/bzr-explorer/custom-switch into lp://staging/bzr-explorer

Proposed by Neil Martinsen-Burrell
Status: Merged
Merged at revision: not available
Proposed branch: lp://staging/~nmb/bzr-explorer/custom-switch
Merge into: lp://staging/bzr-explorer
Diff against target: 162 lines (+101/-0)
3 files modified
lib/explorer.py (+16/-0)
lib/explorer_preferences.py (+5/-0)
lib/switch_dialog.py (+80/-0)
To merge this branch: bzr merge lp://staging/~nmb/bzr-explorer/custom-switch
Reviewer Review Type Date Requested Status
Ian Clatworthy Approve
Review via email: mp+18105@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
Neil Martinsen-Burrell (nmb) wrote :

This branch adds a custom switch dialog, based on QBzr's switch dialog. The intention is to pre-populate the branch combo box with the other colocated branches when we have a colocated branch. It uses repository.find_branches() to get the branches to list, and for colocated branches it uses the "-> branch-name" syntax in the combo box, rather than the full path.

I tried to test out the performance in contexts other than colocated branches, but it is possible that I missed something. There is a preference to choose the custom dialog, just like for checkout, init, etc.

381. By Neil Martinsen-Burrell

remove an unused import

Revision history for this message
Ian Clatworthy (ian-clatworthy) wrote :

Looks good. I'll add a NEWS item and merge.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/explorer.py'
2--- lib/explorer.py 2010-01-26 08:26:53 +0000
3+++ lib/explorer.py 2010-01-26 21:42:16 +0000
4@@ -42,6 +42,7 @@
5 location as mod_location,
6 location_set_browser,
7 location_viewer,
8+ switch_dialog,
9 tools,
10 tool_dialogs,
11 ui_explorer,
12@@ -1265,6 +1266,7 @@
13 'init': (self._start_init, True, self._finish_init),
14 'branch': (self._start_branch, False, self._finish_branch),
15 'checkout': (self._start_checkout, False, self._finish_checkout),
16+ 'switch': (self._start_switch, False, self._finish_switch),
17 }
18 if cmd_id in internal_handlers:
19 if self.dry_run:
20@@ -1336,6 +1338,20 @@
21 new_location = osutils.abspath(to_location)
22 self.open_location(new_location)
23
24+ def _start_switch(self, context=None):
25+ branch, bzrdir, location = None, None, None
26+ if context:
27+ branch_location = context.get('branch-root')
28+ checkout_location = context.get('root')
29+ return switch_dialog.QSwitchExplorerStyleDialog(branch_location,
30+ checkout_location,
31+ parent=self)
32+
33+ def _finish_switch(self):
34+ dialog = self._custom_modeless_dialogs['switch']
35+ self.do_refresh()
36+
37+
38 ## Toolbar helper methods ##
39
40 def _get_toolbar(self, name):
41
42=== modified file 'lib/explorer_preferences.py'
43--- lib/explorer_preferences.py 2010-01-24 12:09:18 +0000
44+++ lib/explorer_preferences.py 2010-01-26 21:42:16 +0000
45@@ -41,6 +41,7 @@
46 "custom-dialog-init": True,
47 "custom-dialog-branch": True,
48 "custom-dialog-checkout": True,
49+ "custom-dialog-switch": True,
50 "advanced-commands-terminal": False,
51 "workingtree-style": "qbrowse",
52 "workspace-model": "feature-branches",
53@@ -52,6 +53,7 @@
54 "custom-dialog-init",
55 "custom-dialog-branch",
56 "custom-dialog-checkout",
57+ "custom-dialog-switch",
58 "advanced-commands-terminal",
59 "bind-branches-by-default",
60 ]
61@@ -155,6 +157,8 @@
62 gettext("Use custom branch dialog"))
63 custom_dialog_checkout_cb = self._build_checkbox_field("custom-dialog-checkout",
64 gettext("Use custom checkout dialog"))
65+ custom_dialog_switch_cb = self._build_checkbox_field("custom-dialog-switch",
66+ gettext("Use custom switch dialog"))
67 layout = QtGui.QFormLayout()
68 layout.addRow(gettext("Suite"), suite_combo)
69 # Make the checkboxes span both columns. If this violates OS X
70@@ -162,6 +166,7 @@
71 layout.addRow(custom_dialog_init_cb)
72 layout.addRow(custom_dialog_branch_cb)
73 layout.addRow(custom_dialog_checkout_cb)
74+ layout.addRow(custom_dialog_switch_cb)
75 return layout
76
77 def _build_appearance(self):
78
79=== added file 'lib/switch_dialog.py'
80--- lib/switch_dialog.py 1970-01-01 00:00:00 +0000
81+++ lib/switch_dialog.py 2010-01-26 21:42:16 +0000
82@@ -0,0 +1,80 @@
83+# Copyright (C) 2010 Canonical Ltd
84+#
85+# This program is free software; you can redistribute it and/or modify
86+# it under the terms of the GNU General Public License as published by
87+# the Free Software Foundation; either version 2 of the License, or
88+# (at your option) any later version.
89+#
90+# This program is distributed in the hope that it will be useful,
91+# but WITHOUT ANY WARRANTY; without even the implied warranty of
92+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93+# GNU General Public License for more details.
94+#
95+# You should have received a copy of the GNU General Public License
96+# along with this program; if not, write to the Free Software
97+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
98+
99+
100+from bzrlib.plugins.qbzr.lib.util import (
101+ runs_in_loading_queue,
102+ url_for_display,
103+ )
104+from bzrlib.plugins.qbzr.lib.uifactory import ui_current_widget
105+from bzrlib.plugins.qbzr.lib.trace import (
106+ reports_exception,
107+ SUB_LOAD_METHOD)
108+from bzrlib.plugins.qbzr.lib.switch import QBzrSwitchWindow
109+
110+from bzrlib.branch import Branch
111+from bzrlib.bzrdir import BzrDir
112+from bzrlib import (urlutils,
113+ )
114+
115+
116+class QSwitchExplorerStyleDialog(QBzrSwitchWindow):
117+
118+ def __init__(self, branch_location, checkout_location, parent):
119+ """A window to switch a checkout.
120+
121+ :param: branch_location
122+ the location of the current branch
123+ :param: checkout_location
124+ the location of the checkout to be switched
125+ :param: parent
126+ the parent window
127+ """
128+ super(QSwitchExplorerStyleDialog, self).__init__(
129+ Branch.open(branch_location),
130+ BzrDir.open(checkout_location),
131+ location=None)
132+ self.parent = parent
133+
134+ @runs_in_loading_queue
135+ @ui_current_widget
136+ @reports_exception(type=SUB_LOAD_METHOD)
137+ def initial_load(self):
138+ super(QSwitchExplorerStyleDialog, self).initial_load()
139+ branch_combo = self.branch_combo
140+ branch_combo.clear()
141+ for br in self.branch.bzrdir.find_repository().find_branches():
142+ self.processEvents()
143+ branch_combo.addItem(self._display_url(br.base), br.base)
144+
145+ def _display_url(self, branch_url):
146+ """Make a shorter display url where appropriate."""
147+ if '.bzr/branches' in self.branch.base or \
148+ '.bzrbranches' in self.branch.base:
149+ return '-> %s' % urlutils.basename(branch_url)
150+ else:
151+ return url_for_display(branch_url)
152+
153+ def do_start(self):
154+ branch_combo = self.branch_combo
155+ location = branch_combo.itemData(
156+ branch_combo.currentIndex()).toString()
157+ if location == '':
158+ location = branch_combo.currentText()
159+ if self.create_branch_box.isChecked():
160+ self.process_widget.do_start(None, 'switch', '--create-branch', location)
161+ else:
162+ self.process_widget.do_start(None, 'switch', location)

Subscribers

People subscribed via source and target branches