/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: 2006-05-19 16:56:46 UTC
  • mfrom: (0.1.25 gannotate)
  • Revision ID: jelmer@samba.org-20060519165646-0d867938fdbc9097
Merge in Dan Loda's gannotate plugin and put it in annotate/

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
from gi.repository import Gtk
18
 
 
19
 
import os
20
 
 
21
 
from bzrlib import (
22
 
    bzrdir,
23
 
    errors,
24
 
    transport,
25
 
    )
26
 
 
27
 
from bzrlib.plugins.gtk.dialog import error_dialog
28
 
from bzrlib.plugins.gtk.errors import show_bzr_error
29
 
from bzrlib.plugins.gtk.i18n import _i18n
30
 
 
31
 
 
32
 
class InitDialog(Gtk.Dialog):
33
 
    """ Initialize dialog. """
34
 
 
35
 
    def __init__(self, path, parent=None):
36
 
        """ Initialize the Initialize dialog. """
37
 
        GObject.GObject.__init__(self, title="Initialize - Olive",
38
 
                                  parent=parent,
39
 
                                  flags=0,
40
 
                                  buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
41
 
        
42
 
        # Get arguments
43
 
        self.path = path
44
 
        
45
 
        # Create the widgets
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()
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
 
        
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)
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. """
75
 
        if self._radio_custom.get_active():
76
 
            self._entry_custom.set_sensitive(True)
77
 
            self._entry_custom.grab_focus()
78
 
        else:
79
 
            self._entry_custom.set_sensitive(False)
80
 
    
81
 
    @show_bzr_error
82
 
    def _on_init_clicked(self, widget):
83
 
        if self._radio_custom.get_active() and len(self._entry_custom.get_text()) == 0:
84
 
            error_dialog(_i18n("Directory name not specified"),
85
 
                         _i18n("You should specify a new directory name."))
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
 
        
117
 
        self.response(Gtk.ResponseType.OK)