27
from dialog import error_dialog
28
25
from errors import show_bzr_error
30
from bzrlib import bzrdir
31
from bzrlib import transport
32
import bzrlib.errors as errors
33
from bzrlib.plugins.gtk import _i18n
35
27
class InitDialog(gtk.Dialog):
36
28
""" Initialize dialog. """
37
29
def __init__(self, path, parent=None):
47
39
# Create the widgets
48
self._button_init = gtk.Button(_i18n("_Initialize"), use_underline=True)
49
self._label_question = gtk.Label(_i18n("Which directory do you want to initialize?"))
50
self._radio_current = gtk.RadioButton(None, _i18n("Current directory"))
51
self._radio_custom = gtk.RadioButton(self._radio_current, _i18n("Create a new directory with the name:"))
40
self._button_init = gtk.Button(_("_Initialize"), use_underline=True)
41
self._label_question = gtk.Label(_("Which directory do you want to initialize?"))
42
self._radio_current = gtk.RadioButton(None, _("Current directory"))
43
self._radio_custom = gtk.RadioButton(self._radio_current, _("Create a new directory with the name:"))
52
44
self._entry_custom = gtk.Entry()
53
45
self._hbox_custom = gtk.HBox()
75
67
def _on_custom_toggled(self, widget):
76
68
""" Occurs if the Custom radiobutton is toggled. """
77
if self._radio_custom.get_active():
69
if self._radio_custom.get_active() == True:
78
70
self._entry_custom.set_sensitive(True)
79
71
self._entry_custom.grab_focus()
81
73
self._entry_custom.set_sensitive(False)
84
75
def _on_init_clicked(self, widget):
85
if self._radio_custom.get_active() and len(self._entry_custom.get_text()) == 0:
86
error_dialog(_i18n("Directory name not specified"),
87
_i18n("You should specify a new directory name."))
90
if self._radio_current.get_active():
93
location = self.path + os.sep + self._entry_custom.get_text()
95
format = bzrdir.format_registry.make_bzrdir('default')
96
to_transport = transport.get_transport(location)
99
to_transport.mkdir('.')
100
except errors.FileExists:
104
existing_bzrdir = bzrdir.BzrDir.open(location)
105
except errors.NotBranchError:
106
branch = bzrdir.BzrDir.create_branch_convenience(to_transport.base,
109
from bzrlib.transport.local import LocalTransport
110
if existing_bzrdir.has_branch():
111
if (isinstance(to_transport, LocalTransport)
112
and not existing_bzrdir.has_workingtree()):
113
raise errors.BranchExistsWithoutWorkingTree(location)
114
raise errors.AlreadyBranchError(location)
116
branch = existing_bzrdir.create_branch()
117
existing_bzrdir.create_workingtree()
119
76
self.response(gtk.RESPONSE_OK)