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