/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
1
# Copyright (C) 2007 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
try:
18
    import pygtk
19
    pygtk.require("2.0")
20
except:
21
    pass
22
23
import gtk
24
188.1.2 by Szilveszter Farkas (Phanatic)
Implemented init functionality.
25
import os
26
27
from dialog import error_dialog
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
28
from errors import show_bzr_error
29
188.1.2 by Szilveszter Farkas (Phanatic)
Implemented init functionality.
30
from bzrlib import bzrdir
31
from bzrlib import transport
32
import bzrlib.errors as errors
33
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
34
class InitDialog(gtk.Dialog):
35
    """ Initialize dialog. """
36
    def __init__(self, path, parent=None):
37
        """ Initialize the Initialize dialog. """
38
        gtk.Dialog.__init__(self, title="Initialize - Olive",
39
                                  parent=parent,
40
                                  flags=0,
41
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
42
        
43
        # Get arguments
44
        self.path = path
45
        
46
        # Create the widgets
47
        self._button_init = gtk.Button(_("_Initialize"), use_underline=True)
48
        self._label_question = gtk.Label(_("Which directory do you want to initialize?"))
49
        self._radio_current = gtk.RadioButton(None, _("Current directory"))
50
        self._radio_custom = gtk.RadioButton(self._radio_current, _("Create a new directory with the name:"))
51
        self._entry_custom = gtk.Entry()
52
        self._hbox_custom = gtk.HBox()
53
        
54
        # Set callbacks
55
        self._button_init.connect('clicked', self._on_init_clicked)
56
        self._radio_custom.connect('toggled', self._on_custom_toggled)
57
        
58
        # Set properties
59
        self._entry_custom.set_sensitive(False)
60
        
61
        # Construct the dialog
62
        self.action_area.pack_end(self._button_init)
63
        
64
        self._hbox_custom.pack_start(self._radio_custom, False, False)
65
        self._hbox_custom.pack_start(self._entry_custom, True, True)
66
        
67
        self.vbox.pack_start(self._label_question)
68
        self.vbox.pack_start(self._radio_current)
69
        self.vbox.pack_start(self._hbox_custom)
70
        
71
        # Display the dialog
72
        self.vbox.show_all()
73
    
74
    def _on_custom_toggled(self, widget):
75
        """ Occurs if the Custom radiobutton is toggled. """
188.1.2 by Szilveszter Farkas (Phanatic)
Implemented init functionality.
76
        if self._radio_custom.get_active():
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
77
            self._entry_custom.set_sensitive(True)
78
            self._entry_custom.grab_focus()
79
        else:
80
            self._entry_custom.set_sensitive(False)
81
    
188.1.2 by Szilveszter Farkas (Phanatic)
Implemented init functionality.
82
    @show_bzr_error
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
83
    def _on_init_clicked(self, widget):
188.1.2 by Szilveszter Farkas (Phanatic)
Implemented init functionality.
84
        if self._radio_custom.get_active() and len(self._entry_custom.get_text()) == 0:
85
            error_dialog(_("Directory name not specified"),
86
                         _("You should specify a new directory name."))
87
            return
88
        
89
        if self._radio_current.get_active():
90
            location = self.path
91
        else:
92
            location = self.path + os.sep + self._entry_custom.get_text()
93
        
94
        format = bzrdir.format_registry.make_bzrdir('default')        
95
        to_transport = transport.get_transport(location)
96
        
97
        try:
98
            to_transport.mkdir('.')
99
        except errors.FileExists:
100
            pass
101
                    
102
        try:
103
            existing_bzrdir = bzrdir.BzrDir.open(location)
104
        except errors.NotBranchError:
105
            branch = bzrdir.BzrDir.create_branch_convenience(to_transport.base,
106
                                                             format=format)
107
        else:
108
            from bzrlib.transport.local import LocalTransport
109
            if existing_bzrdir.has_branch():
110
                if (isinstance(to_transport, LocalTransport)
111
                    and not existing_bzrdir.has_workingtree()):
112
                        raise errors.BranchExistsWithoutWorkingTree(location)
113
                raise errors.AlreadyBranchError(location)
114
            else:
115
                branch = existing_bzrdir.create_branch()
116
                existing_bzrdir.create_workingtree()
117
        
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
118
        self.response(gtk.RESPONSE_OK)