/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
 
try:
18
 
    import pygtk
19
 
    pygtk.require("2.0")
20
 
except:
21
 
    pass
22
 
 
23
 
import gtk
24
 
 
25
 
import os
26
 
 
27
 
from dialog import error_dialog
28
 
from errors import show_bzr_error
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
 
 
35
 
class InitDialog(gtk.Dialog):
36
 
    """ Initialize dialog. """
37
 
    def __init__(self, path, parent=None):
38
 
        """ Initialize the Initialize dialog. """
39
 
        gtk.Dialog.__init__(self, title="Initialize - Olive",
40
 
                                  parent=parent,
41
 
                                  flags=0,
42
 
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
43
 
        
44
 
        # Get arguments
45
 
        self.path = path
46
 
        
47
 
        # 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:"))
52
 
        self._entry_custom = gtk.Entry()
53
 
        self._hbox_custom = gtk.HBox()
54
 
        
55
 
        # Set callbacks
56
 
        self._button_init.connect('clicked', self._on_init_clicked)
57
 
        self._radio_custom.connect('toggled', self._on_custom_toggled)
58
 
        
59
 
        # Set properties
60
 
        self._entry_custom.set_sensitive(False)
61
 
        
62
 
        # Construct the dialog
63
 
        self.action_area.pack_end(self._button_init)
64
 
        
65
 
        self._hbox_custom.pack_start(self._radio_custom, False, False)
66
 
        self._hbox_custom.pack_start(self._entry_custom, True, True)
67
 
        
68
 
        self.vbox.pack_start(self._label_question)
69
 
        self.vbox.pack_start(self._radio_current)
70
 
        self.vbox.pack_start(self._hbox_custom)
71
 
        
72
 
        # Display the dialog
73
 
        self.vbox.show_all()
74
 
    
75
 
    def _on_custom_toggled(self, widget):
76
 
        """ Occurs if the Custom radiobutton is toggled. """
77
 
        if self._radio_custom.get_active():
78
 
            self._entry_custom.set_sensitive(True)
79
 
            self._entry_custom.grab_focus()
80
 
        else:
81
 
            self._entry_custom.set_sensitive(False)
82
 
    
83
 
    @show_bzr_error
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
 
        
119
 
        self.response(gtk.RESPONSE_OK)