/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to initialize.py

  • Committer: Jelmer Vernooij
  • Date: 2008-06-29 19:18:34 UTC
  • mto: This revision was merged to the branch mainline in revision 515.
  • Revision ID: jelmer@samba.org-20080629191834-ha2ecpv5szt96nge
Make sure signed testament matches repository data.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
import gtk
24
24
 
 
25
import os
 
26
 
 
27
from dialog import error_dialog
25
28
from errors import show_bzr_error
26
29
 
 
30
from bzrlib import bzrdir
 
31
from bzrlib import transport
 
32
import bzrlib.errors as errors
 
33
from bzrlib.plugins.gtk import _i18n
 
34
 
27
35
class InitDialog(gtk.Dialog):
28
36
    """ Initialize dialog. """
29
37
    def __init__(self, path, parent=None):
37
45
        self.path = path
38
46
        
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()
46
54
        
66
74
    
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()
72
80
        else:
73
81
            self._entry_custom.set_sensitive(False)
74
82
    
 
83
    @show_bzr_error
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."))
 
88
            return
 
89
        
 
90
        if self._radio_current.get_active():
 
91
            location = self.path
 
92
        else:
 
93
            location = self.path + os.sep + self._entry_custom.get_text()
 
94
        
 
95
        format = bzrdir.format_registry.make_bzrdir('default')        
 
96
        to_transport = transport.get_transport(location)
 
97
        
 
98
        try:
 
99
            to_transport.mkdir('.')
 
100
        except errors.FileExists:
 
101
            pass
 
102
                    
 
103
        try:
 
104
            existing_bzrdir = bzrdir.BzrDir.open(location)
 
105
        except errors.NotBranchError:
 
106
            branch = bzrdir.BzrDir.create_branch_convenience(to_transport.base,
 
107
                                                             format=format)
 
108
        else:
 
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)
 
115
            else:
 
116
                branch = existing_bzrdir.create_branch()
 
117
                existing_bzrdir.create_workingtree()
 
118
        
76
119
        self.response(gtk.RESPONSE_OK)