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