1
# -*- coding: utf-8 -*-
3
# QBzr - Qt frontend to Bazaar commands
6
# Javier Der Derian <javierder@gmail.com>
8
# This program is free software; you can redistribute it and/or
9
# modify it under the terms of the GNU General Public License
10
# as published by the Free Software Foundation; either version 2
11
# of the License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program; if not, write to the Free Software
20
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
from PyQt4 import QtCore, QtGui
25
from bzrlib import errors, osutils
27
from bzrlib.plugins.qbzr.lib.i18n import gettext
28
from bzrlib.plugins.qbzr.lib.subprocess import SubProcessDialog
29
from bzrlib.plugins.qbzr.lib.util import (
34
from bzrlib.plugins.qbzr.lib.uifactory import ui_current_widget
35
from bzrlib.plugins.qbzr.lib.trace import (
41
class QBzrBindDialog(SubProcessDialog):
43
def __init__(self, branch, location=None, ui_mode = None):
45
super(QBzrBindDialog, self).__init__(
46
gettext("Bind branch"),
48
default_size = (400, 400),
55
# Display information fields
56
gbBind = QtGui.QGroupBox(gettext("Bind"), self)
57
bind_box = QtGui.QFormLayout(gbBind)
58
bind_box.addRow(gettext("Branch location:"),
59
QtGui.QLabel(url_for_display(branch.base)))
60
self.currbound = branch.get_bound_location()
61
if self.currbound != None:
62
bind_box.addRow(gettext("Currently bound to:"),
63
QtGui.QLabel(url_for_display(self.currbound)))
65
# Build the "Bind to" widgets
66
branch_label = QtGui.QLabel(gettext("Bind to:"))
67
branch_combo = QtGui.QComboBox()
68
branch_combo.setEditable(True)
69
self.branch_combo = branch_combo
70
browse_button = QtGui.QPushButton(gettext("Browse"))
71
QtCore.QObject.connect(browse_button, QtCore.SIGNAL("clicked(bool)"),
74
# Add some useful values into the combo box. If a location was given,
75
# default to it. If an old bound location exists, suggest it.
76
# Otherwise suggest the parent branch, if any.
79
suggestions.append(osutils.abspath(location))
80
old_location = branch.get_old_bound_location()
82
url = url_for_display(old_location)
83
if url not in suggestions:
84
suggestions.append(url)
85
parent_location = branch.get_parent()
87
url = url_for_display(parent_location)
88
if url not in suggestions:
89
suggestions.append(url)
91
branch_combo.addItems(suggestions)
93
# Build the "Bind to" row/panel
94
bind_hbox = QtGui.QHBoxLayout()
95
bind_hbox.addWidget(branch_label)
96
bind_hbox.addWidget(branch_combo)
97
bind_hbox.addWidget(browse_button)
98
bind_hbox.setStretchFactor(branch_label,0)
99
bind_hbox.setStretchFactor(branch_combo,1)
100
bind_hbox.setStretchFactor(browse_button,0)
101
bind_box.addRow(bind_hbox)
103
# Put the form together
104
layout = QtGui.QVBoxLayout(self)
105
layout.addWidget(gbBind)
106
layout.addWidget(self.make_default_status_box())
107
layout.addWidget(self.buttonbox)
109
def browse_clicked(self):
110
fileName = QtGui.QFileDialog.getExistingDirectory(self,
111
gettext("Select branch location"));
113
self.branch_combo.insertItem(0,fileName)
114
self.branch_combo.setCurrentIndex(0)
116
@reports_exception(type=SUB_LOAD_METHOD)
119
location = unicode(self.branch_combo.currentText())
121
raise errors.BzrCommandError(
122
gettext("Master branch location not specified."))
126
location = unicode(self.branch_combo.currentText())
127
self.process_widget.do_start(None, 'bind', location)