/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
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
17
from gi.repository import Gtk
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
18
188.1.2 by Szilveszter Farkas (Phanatic)
Implemented init functionality.
19
import os
20
724 by Jelmer Vernooij
Fix formatting, imports.
21
from bzrlib import (
22
    bzrdir,
23
    errors,
24
    transport,
25
    )
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
26
724 by Jelmer Vernooij
Fix formatting, imports.
27
from bzrlib.plugins.gtk.dialog import error_dialog
28
from bzrlib.plugins.gtk.errors import show_bzr_error
729.1.1 by Jelmer Vernooij
Move i18n support to a separate file, so gettext files aren't loaded unless bzr-gtk is used.
29
from bzrlib.plugins.gtk.i18n import _i18n
724 by Jelmer Vernooij
Fix formatting, imports.
30
188.1.2 by Szilveszter Farkas (Phanatic)
Implemented init functionality.
31
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
32
class InitDialog(Gtk.Dialog):
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
33
    """ Initialize dialog. """
724 by Jelmer Vernooij
Fix formatting, imports.
34
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
35
    def __init__(self, path, parent=None):
36
        """ Initialize the Initialize dialog. """
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
37
        GObject.GObject.__init__(self, title="Initialize - Olive",
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
38
                                  parent=parent,
39
                                  flags=0,
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
40
                                  buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
41
        
42
        # Get arguments
43
        self.path = path
44
        
45
        # Create the widgets
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
46
        self._button_init = Gtk.Button(_i18n("_Initialize"), use_underline=True)
47
        self._label_question = Gtk.Label(label=_i18n("Which directory do you want to initialize?"))
48
        self._radio_current = Gtk.RadioButton(None, _i18n("Current directory"))
49
        self._radio_custom = Gtk.RadioButton(self._radio_current, _i18n("Create a new directory with the name:"))
50
        self._entry_custom = Gtk.Entry()
51
        self._hbox_custom = Gtk.HBox()
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
52
        
53
        # Set callbacks
54
        self._button_init.connect('clicked', self._on_init_clicked)
55
        self._radio_custom.connect('toggled', self._on_custom_toggled)
56
        
57
        # Set properties
58
        self._entry_custom.set_sensitive(False)
59
        
60
        # Construct the dialog
61
        self.action_area.pack_end(self._button_init)
62
        
63
        self._hbox_custom.pack_start(self._radio_custom, False, False)
64
        self._hbox_custom.pack_start(self._entry_custom, True, True)
65
        
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
66
        self.vbox.pack_start(self._label_question, True, True, 0)
67
        self.vbox.pack_start(self._radio_current, True, True, 0)
68
        self.vbox.pack_start(self._hbox_custom, True, True, 0)
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
69
        
70
        # Display the dialog
71
        self.vbox.show_all()
72
    
73
    def _on_custom_toggled(self, widget):
74
        """ Occurs if the Custom radiobutton is toggled. """
188.1.2 by Szilveszter Farkas (Phanatic)
Implemented init functionality.
75
        if self._radio_custom.get_active():
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
76
            self._entry_custom.set_sensitive(True)
77
            self._entry_custom.grab_focus()
78
        else:
79
            self._entry_custom.set_sensitive(False)
80
    
188.1.2 by Szilveszter Farkas (Phanatic)
Implemented init functionality.
81
    @show_bzr_error
188.1.1 by Szilveszter Farkas (Phanatic)
Inital implementation of the Initialize dialog. Not fully functional yet.
82
    def _on_init_clicked(self, widget):
188.1.2 by Szilveszter Farkas (Phanatic)
Implemented init functionality.
83
        if self._radio_custom.get_active() and len(self._entry_custom.get_text()) == 0:
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
84
            error_dialog(_i18n("Directory name not specified"),
85
                         _i18n("You should specify a new directory name."))
188.1.2 by Szilveszter Farkas (Phanatic)
Implemented init functionality.
86
            return
87
        
88
        if self._radio_current.get_active():
89
            location = self.path
90
        else:
91
            location = self.path + os.sep + self._entry_custom.get_text()
92
        
93
        format = bzrdir.format_registry.make_bzrdir('default')        
94
        to_transport = transport.get_transport(location)
95
        
96
        try:
97
            to_transport.mkdir('.')
98
        except errors.FileExists:
99
            pass
100
                    
101
        try:
102
            existing_bzrdir = bzrdir.BzrDir.open(location)
103
        except errors.NotBranchError:
104
            branch = bzrdir.BzrDir.create_branch_convenience(to_transport.base,
105
                                                             format=format)
106
        else:
107
            from bzrlib.transport.local import LocalTransport
108
            if existing_bzrdir.has_branch():
109
                if (isinstance(to_transport, LocalTransport)
110
                    and not existing_bzrdir.has_workingtree()):
111
                        raise errors.BranchExistsWithoutWorkingTree(location)
112
                raise errors.AlreadyBranchError(location)
113
            else:
114
                branch = existing_bzrdir.create_branch()
115
                existing_bzrdir.create_workingtree()
116
        
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
117
        self.response(Gtk.ResponseType.OK)