/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: Szilveszter Farkas (Phanatic)
  • Date: 2007-04-06 17:16:31 UTC
  • mto: (188.2.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 190.
  • Revision ID: szilveszter.farkas@gmail.com-20070406171631-mtb9r4kptogh35ox
Inital implementation of the Initialize dialog. Not fully functional yet.

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
28
25
from errors import show_bzr_error
29
26
 
30
 
from bzrlib import bzrdir
31
 
from bzrlib import transport
32
 
import bzrlib.errors as errors
33
 
from bzrlib.plugins.gtk import _i18n
34
 
 
35
27
class InitDialog(gtk.Dialog):
36
28
    """ Initialize dialog. """
37
29
    def __init__(self, path, parent=None):
45
37
        self.path = path
46
38
        
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()
54
46
        
74
66
    
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()
80
72
        else:
81
73
            self._entry_custom.set_sensitive(False)
82
74
    
83
 
    @show_bzr_error
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."))
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
 
        
119
76
        self.response(gtk.RESPONSE_OK)