/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
1
# Copyright (C) 2007 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
231 by Jelmer Vernooij
Add RevisionSelectionBox widget, use in TagDialog.
2
# Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
734.1.4 by Curtis Hovey
Updated commit to gtk3.
18
from gi.repository import GObject
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
19
from gi.repository import Gtk
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
20
724 by Jelmer Vernooij
Fix formatting, imports.
21
from bzrlib.plugins.gtk.dialog import error_dialog
729.1.1 by Jelmer Vernooij
Move i18n support to a separate file, so gettext files aren't loaded unless bzr-gtk is used.
22
from bzrlib.plugins.gtk.i18n import _i18n
724 by Jelmer Vernooij
Fix formatting, imports.
23
from bzrlib.plugins.gtk.revidbox import RevisionSelectionBox
330.3.1 by Daniel Schierbeck
Renamed logview 'revisionview'.
24
from bzrlib.plugins.gtk.revisionview import RevisionView
298.2.1 by Daniel Schierbeck
Refactored the GTK window code, creating a single base window class that handles keyboard events.
25
from bzrlib.plugins.gtk.window import Window
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
26
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
27
298.2.1 by Daniel Schierbeck
Refactored the GTK window code, creating a single base window class that handles keyboard events.
28
class TagsWindow(Window):
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
29
    """ Tags window. Allows the user to view/add/remove tags. """
30
    def __init__(self, branch, parent=None):
31
        """ Initialize the Tags window. """
734.1.51 by Curtis Hovey
Fix the initializer for many classes.
32
        super(TagsWindow, self).__init__(parent=parent)
275.1.3 by Daniel Schierbeck
Close tags window when 'destroy' signal is received.
33
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
34
        # Get arguments
35
        self.branch = branch
275.1.5 by Daniel Schierbeck
Made windows close correctly on Ctrl-W and made the application quit on Ctrl-Q.
36
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
37
        # Create the widgets
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
38
        self._button_add = Gtk.Button(stock=Gtk.STOCK_ADD)
39
        self._button_remove = Gtk.Button(stock=Gtk.STOCK_REMOVE)
40
        self._button_refresh = Gtk.Button(stock=Gtk.STOCK_REFRESH)
41
        self._button_close = Gtk.Button(stock=Gtk.STOCK_CLOSE)
42
        self._model = Gtk.ListStore(str, str)
734.1.11 by Curtis Hovey
Updated gtags to gtk3.
43
        self._treeview_tags = Gtk.TreeView(model=self._model)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
44
        self._scrolledwindow_tags = Gtk.ScrolledWindow()
330.3.1 by Daniel Schierbeck
Renamed logview 'revisionview'.
45
        self._revisionview = RevisionView()
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
46
        self._hbox = Gtk.HBox()
47
        self._vbox_buttons = Gtk.VBox()
48
        self._vbox_buttons_top = Gtk.VBox()
49
        self._vbox_buttons_bottom = Gtk.VBox()
50
        self._vpaned = Gtk.VPaned()
724 by Jelmer Vernooij
Fix formatting, imports.
51
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
52
        # Set callbacks
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
53
        self._button_add.connect('clicked', self._on_add_clicked)
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
54
        self._button_close.connect('clicked', self._on_close_clicked)
190.1.4 by Szilveszter Farkas (Phanatic)
Added Refresh button to the Tags window.
55
        self._button_refresh.connect('clicked', self._on_refresh_clicked)
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
56
        self._button_remove.connect('clicked', self._on_remove_clicked)
57
        self._treeview_tags.connect('cursor-changed', self._on_treeview_changed)
724 by Jelmer Vernooij
Fix formatting, imports.
58
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
59
        # Set properties
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
60
        self.set_title(_i18n("Tags"))
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
61
        self.set_default_size(600, 400)
724 by Jelmer Vernooij
Fix formatting, imports.
62
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
63
        self._scrolledwindow_tags.set_policy(Gtk.PolicyType.AUTOMATIC,
64
                                             Gtk.PolicyType.AUTOMATIC)
724 by Jelmer Vernooij
Fix formatting, imports.
65
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
66
        self._hbox.set_border_width(5)
67
        self._hbox.set_spacing(5)
68
        self._vbox_buttons.set_size_request(100, -1)
724 by Jelmer Vernooij
Fix formatting, imports.
69
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
70
        self._vbox_buttons_top.set_spacing(3)
724 by Jelmer Vernooij
Fix formatting, imports.
71
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
72
        self._vpaned.set_position(200)
724 by Jelmer Vernooij
Fix formatting, imports.
73
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
74
        # Construct the dialog
75
        self._scrolledwindow_tags.add(self._treeview_tags)
724 by Jelmer Vernooij
Fix formatting, imports.
76
734.1.51 by Curtis Hovey
Fix the initializer for many classes.
77
        self._vbox_buttons_top.pack_start(
78
            self._button_add, False, False, 0)
79
        self._vbox_buttons_top.pack_start(
80
            self._button_remove, False, False, 0)
81
        self._vbox_buttons_top.pack_start(
82
            self._button_refresh, False, False, 0)
83
        self._vbox_buttons_bottom.pack_start(
84
            self._button_close, False, False, 0)
724 by Jelmer Vernooij
Fix formatting, imports.
85
734.1.51 by Curtis Hovey
Fix the initializer for many classes.
86
        self._vbox_buttons.pack_start(
87
            self._vbox_buttons_top, True, True, 0)
88
        self._vbox_buttons.pack_start(
89
            self._vbox_buttons_bottom, False, False, 0)
724 by Jelmer Vernooij
Fix formatting, imports.
90
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
91
        self._vpaned.add1(self._scrolledwindow_tags)
330.3.1 by Daniel Schierbeck
Renamed logview 'revisionview'.
92
        self._vpaned.add2(self._revisionview)
724 by Jelmer Vernooij
Fix formatting, imports.
93
734.1.11 by Curtis Hovey
Updated gtags to gtk3.
94
        self._hbox.pack_start(self._vpaned, True, True, 0)
95
        self._hbox.pack_start(self._vbox_buttons, False, True, 0)
724 by Jelmer Vernooij
Fix formatting, imports.
96
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
97
        self.add(self._hbox)
724 by Jelmer Vernooij
Fix formatting, imports.
98
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
99
        # Default to no tags
100
        self._no_tags = True
724 by Jelmer Vernooij
Fix formatting, imports.
101
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
102
        # Load the tags
103
        self._load_tags()
724 by Jelmer Vernooij
Fix formatting, imports.
104
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
105
        # Display everything
106
        self._hbox.show_all()
724 by Jelmer Vernooij
Fix formatting, imports.
107
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
108
    def _load_tags(self):
109
        """ Load the tags into the TreeView. """
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
110
        tvcol_name = Gtk.TreeViewColumn(_i18n("Tag Name"),
111
                                        Gtk.CellRendererText(),
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
112
                                        text=0)
113
        tvcol_name.set_resizable(True)
724 by Jelmer Vernooij
Fix formatting, imports.
114
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
115
        tvcol_revid = Gtk.TreeViewColumn(_i18n("Revision ID"),
116
                                         Gtk.CellRendererText(),
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
117
                                         text=1)
118
        tvcol_revid.set_resizable(True)
724 by Jelmer Vernooij
Fix formatting, imports.
119
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
120
        self._treeview_tags.append_column(tvcol_name)
121
        self._treeview_tags.append_column(tvcol_revid)
724 by Jelmer Vernooij
Fix formatting, imports.
122
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
123
        self._treeview_tags.set_search_column(0)
724 by Jelmer Vernooij
Fix formatting, imports.
124
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
125
        self._refresh_tags()
724 by Jelmer Vernooij
Fix formatting, imports.
126
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
127
    def _refresh_tags(self):
128
        """ Refresh the list of tags. """
129
        self._model.clear()
130
        if self.branch.supports_tags():
131
            tags = self.branch.tags.get_tag_dict()
132
            if len(tags) > 0:
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
133
                self._no_tags = False
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
134
                for name, target in tags.items():
135
                    self._model.append([name, target])
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
136
                self._button_add.set_sensitive(True)
137
                self._button_remove.set_sensitive(True)
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
138
            else:
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
139
                self._no_tags = True
140
                self._no_tags_available()
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
141
        else:
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
142
            self._no_tags = True
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
143
            self._tags_not_supported()
144
        self._treeview_tags.set_model(self._model)
724 by Jelmer Vernooij
Fix formatting, imports.
145
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
146
    def _tags_not_supported(self):
147
        """ Tags are not supported. """
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
148
        self._model.append([_i18n("Tags are not supported by this branch format. Please upgrade."), ""])
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
149
        self._button_add.set_sensitive(False)
150
        self._button_remove.set_sensitive(False)
724 by Jelmer Vernooij
Fix formatting, imports.
151
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
152
    def _no_tags_available(self):
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
153
        """ No tags in the branch. """
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
154
        self._model.append([_i18n("No tagged revisions in the branch."), ""])
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
155
        self._button_add.set_sensitive(True)
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
156
        self._button_remove.set_sensitive(False)
724 by Jelmer Vernooij
Fix formatting, imports.
157
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
158
    def _on_add_clicked(self, widget):
159
        """ Add button event handler. """
231 by Jelmer Vernooij
Add RevisionSelectionBox widget, use in TagDialog.
160
        dialog = AddTagDialog(self.branch.repository, None,
161
                              self.branch, self)
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
162
        response = dialog.run()
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
163
        if response != Gtk.ResponseType.NONE:
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
164
            dialog.hide()
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
165
            if response == Gtk.ResponseType.OK:
232 by Jelmer Vernooij
Make 'Add tag' dialog accessible from bzrk.
166
                self.branch.tags.set_tag(dialog.tagname, dialog._revid)
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
167
                self._refresh_tags()
168
            dialog.destroy()
724 by Jelmer Vernooij
Fix formatting, imports.
169
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
170
    def _on_close_clicked(self, widget):
171
        """ Close button event handler. """
172
        self.destroy()
173
        if self._parent is None:
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
174
            Gtk.main_quit()
275.1.5 by Daniel Schierbeck
Made windows close correctly on Ctrl-W and made the application quit on Ctrl-Q.
175
190.1.4 by Szilveszter Farkas (Phanatic)
Added Refresh button to the Tags window.
176
    def _on_refresh_clicked(self, widget):
177
        """ Refresh button event handler. """
178
        self._refresh_tags()
724 by Jelmer Vernooij
Fix formatting, imports.
179
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
180
    def _on_remove_clicked(self, widget):
181
        """ Remove button event handler. """
182
        (path, col) = self._treeview_tags.get_cursor()
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
183
        if path is None:
184
            return
724 by Jelmer Vernooij
Fix formatting, imports.
185
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
186
        tag = self._model[path][0]
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
187
        dialog = RemoveTagDialog(tag, self)
188
        response = dialog.run()
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
189
        if response != Gtk.ResponseType.NONE:
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
190
            dialog.hide()
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
191
            if response == Gtk.ResponseType.OK:
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
192
                self.branch.tags.delete_tag(tag)
193
                self._refresh_tags()
194
            dialog.destroy()
724 by Jelmer Vernooij
Fix formatting, imports.
195
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
196
    def _on_treeview_changed(self, *args):
197
        """ When a user clicks on a tag. """
330.3.1 by Daniel Schierbeck
Renamed logview 'revisionview'.
198
        # Refresh RevisionView only if there are tags available
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
199
        if not self._no_tags:
200
            (path, col) = self._treeview_tags.get_cursor()
201
            revision = self._model[path][1]
330.3.1 by Daniel Schierbeck
Renamed logview 'revisionview'.
202
            self._revisionview.set_revision(self.branch.repository.get_revision(revision))
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
203
204
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
205
class RemoveTagDialog(Gtk.Dialog):
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
206
    """ Confirm removal of tag. """
207
    def __init__(self, tagname, parent):
734.1.51 by Curtis Hovey
Fix the initializer for many classes.
208
        super(RemoveTagDialog, self).__init__(
209
            title="Remove tag", parent=parent, flags=0,
210
            buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
724 by Jelmer Vernooij
Fix formatting, imports.
211
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
212
        # Get the arguments
213
        self.tag = tagname
724 by Jelmer Vernooij
Fix formatting, imports.
214
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
215
        # Create the widgets
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
216
        self._hbox = Gtk.HBox()
217
        self._vbox_question = Gtk.VBox()
218
        self._image_question = Gtk.Image.new_from_stock(Gtk.STOCK_DIALOG_QUESTION,
219
                                                        Gtk.IconSize.DIALOG)
220
        self._label_title = Gtk.Label()
221
        self._label_question = Gtk.Label()
222
        self._button_remove = Gtk.Button(_i18n("_Remove tag"), use_underline=True)
724 by Jelmer Vernooij
Fix formatting, imports.
223
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
224
        # Set callbacks
225
        self._button_remove.connect('clicked', self._on_remove_clicked)
724 by Jelmer Vernooij
Fix formatting, imports.
226
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
227
        # Set properties
228
        self._hbox.set_border_width(5)
229
        self._hbox.set_spacing(5)
230
        self._vbox_question.set_spacing(3)
724 by Jelmer Vernooij
Fix formatting, imports.
231
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
232
        self._label_title.set_markup(_i18n("<b><big>Remove tag?</big></b>"))
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
233
        self._label_title.set_alignment(0.0, 0.5)
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
234
        self._label_question.set_markup(_i18n("Are you sure you want to remove the tag: <b>%s</b>?") % self.tag)
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
235
        self._label_question.set_alignment(0.0, 0.5)
724 by Jelmer Vernooij
Fix formatting, imports.
236
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
237
        self._button_remove.set_image(Gtk.Image.new_from_stock(Gtk.STOCK_REMOVE,
238
                                                               Gtk.IconSize.BUTTON))
239
        self._button_remove.set_can_default(True)
724 by Jelmer Vernooij
Fix formatting, imports.
240
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
241
        # Construct the dialog
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
242
        self._vbox_question.pack_start(self._label_title, True, True, 0)
243
        self._vbox_question.pack_start(self._label_question, True, True, 0)
724 by Jelmer Vernooij
Fix formatting, imports.
244
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
245
        self._hbox.pack_start(self._image_question, True, True, 0)
246
        self._hbox.pack_start(self._vbox_question, True, True, 0)
724 by Jelmer Vernooij
Fix formatting, imports.
247
734.1.51 by Curtis Hovey
Fix the initializer for many classes.
248
        self.get_content_area().add(self._hbox)
724 by Jelmer Vernooij
Fix formatting, imports.
249
734.1.51 by Curtis Hovey
Fix the initializer for many classes.
250
        self.action_area.pack_end(self._button_remove, False, False, 0)
724 by Jelmer Vernooij
Fix formatting, imports.
251
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
252
        # Display dialog
734.1.51 by Curtis Hovey
Fix the initializer for many classes.
253
        self.get_content_area().show_all()
724 by Jelmer Vernooij
Fix formatting, imports.
254
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
255
        # Default to Commit button
256
        self._button_remove.grab_default()
724 by Jelmer Vernooij
Fix formatting, imports.
257
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
258
    def _on_remove_clicked(self, widget):
259
        """ Remove button event handler. """
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
260
        self.response(Gtk.ResponseType.OK)
261
262
263
class AddTagDialog(Gtk.Dialog):
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
264
    """ Add tag dialog. """
724 by Jelmer Vernooij
Fix formatting, imports.
265
231 by Jelmer Vernooij
Add RevisionSelectionBox widget, use in TagDialog.
266
    def __init__(self, repository, revid=None, branch=None, parent=None):
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
267
        """ Initialize Add tag dialog. """
734.1.51 by Curtis Hovey
Fix the initializer for many classes.
268
        super(AddTagDialog, self).__init__(
269
            title="Add tag", parent=parent, flags=0,
270
            buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
724 by Jelmer Vernooij
Fix formatting, imports.
271
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
272
        # Get arguments
231 by Jelmer Vernooij
Add RevisionSelectionBox widget, use in TagDialog.
273
        self._repository = repository
274
        self._revid = revid
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
275
        self._branch = branch
724 by Jelmer Vernooij
Fix formatting, imports.
276
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
277
        # Create the widgets
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
278
        self._button_add = Gtk.Button(_i18n("_Add tag"), use_underline=True)
279
        self._table = Gtk.Table(2, 2)
280
        self._label_name = Gtk.Label(label=_i18n("Tag Name:"))
281
        self._label_revid = Gtk.Label(label=_i18n("Revision ID:"))
282
        self._entry_name = Gtk.Entry()
232 by Jelmer Vernooij
Make 'Add tag' dialog accessible from bzrk.
283
        if self._revid is not None:
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
284
            self._hbox_revid = Gtk.Label(label=self._revid)
232 by Jelmer Vernooij
Make 'Add tag' dialog accessible from bzrk.
285
        else:
286
            self._hbox_revid = RevisionSelectionBox(self._branch)
724 by Jelmer Vernooij
Fix formatting, imports.
287
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
288
        # Set callbacks
289
        self._button_add.connect('clicked', self._on_add_clicked)
724 by Jelmer Vernooij
Fix formatting, imports.
290
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
291
        # Set properties
292
        self._label_name.set_alignment(0, 0.5)
293
        self._label_revid.set_alignment(0, 0.5)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
294
        self._button_add.set_image(Gtk.Image.new_from_stock(Gtk.STOCK_ADD,
295
                                                            Gtk.IconSize.BUTTON))
296
        self._button_add.set_can_default(True)
724 by Jelmer Vernooij
Fix formatting, imports.
297
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
298
        # Construct the dialog
299
        self._table.attach(self._label_name, 0, 1, 0, 1)
300
        self._table.attach(self._label_revid, 0, 1, 1, 2)
301
        self._table.attach(self._entry_name, 1, 2, 0, 1)
302
        self._table.attach(self._hbox_revid, 1, 2, 1, 2)
734.1.51 by Curtis Hovey
Fix the initializer for many classes.
303
        self.get_content_area().add(self._table)
304
        self.action_area.pack_end(self._button_add, False, False, 0)
724 by Jelmer Vernooij
Fix formatting, imports.
305
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
306
        # Show the dialog
734.1.51 by Curtis Hovey
Fix the initializer for many classes.
307
        self.get_content_area().show_all()
724 by Jelmer Vernooij
Fix formatting, imports.
308
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
309
    def _on_add_clicked(self, widget):
310
        """ Add button clicked handler. """
311
        if len(self._entry_name.get_text()) == 0:
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
312
            error_dialog(_i18n("No tag name specified"),
313
                         _i18n("You have to specify the tag's desired name."))
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
314
            return
724 by Jelmer Vernooij
Fix formatting, imports.
315
232 by Jelmer Vernooij
Make 'Add tag' dialog accessible from bzrk.
316
        if self._revid is None:
317
            if self._hbox_revid.get_revision_id() is None:
318
                self._revid = self._branch.last_revision()
319
            else:
487.3.1 by Javier Derderian
Fixed bug #228709. Can't add tag
320
                self._revid = self._hbox_revid.get_revision_id()
724 by Jelmer Vernooij
Fix formatting, imports.
321
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
322
        self.tagname = self._entry_name.get_text()
724 by Jelmer Vernooij
Fix formatting, imports.
323
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
324
        self.response(Gtk.ResponseType.OK)