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