27
from dialog import error_dialog
25
28
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
27
35
class InitDialog(gtk.Dialog):
28
36
""" Initialize dialog. """
29
37
def __init__(self, path, parent=None):
39
47
# Create the widgets
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:"))
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:"))
44
52
self._entry_custom = gtk.Entry()
45
53
self._hbox_custom = gtk.HBox()
67
75
def _on_custom_toggled(self, widget):
68
76
""" Occurs if the Custom radiobutton is toggled. """
69
if self._radio_custom.get_active() == True:
77
if self._radio_custom.get_active():
70
78
self._entry_custom.set_sensitive(True)
71
79
self._entry_custom.grab_focus()
73
81
self._entry_custom.set_sensitive(False)
75
84
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()
76
119
self.response(gtk.RESPONSE_OK)