/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>
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
from bzrlib.plugins.gtk.logview import LogView
26
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
27
from dialog import error_dialog
28
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
29
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
30
class TagsWindow(gtk.Window):
31
    """ Tags window. Allows the user to view/add/remove tags. """
32
    def __init__(self, branch, parent=None):
33
        """ Initialize the Tags window. """
34
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
35
        
36
        # Get arguments
37
        self.branch = branch
38
        self._parent = parent
39
        
40
        # Create the widgets
41
        self._button_add = gtk.Button(stock=gtk.STOCK_ADD)
42
        self._button_remove = gtk.Button(stock=gtk.STOCK_REMOVE)
190.1.4 by Szilveszter Farkas (Phanatic)
Added Refresh button to the Tags window.
43
        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).
44
        self._button_close = gtk.Button(stock=gtk.STOCK_CLOSE)
45
        self._model = gtk.ListStore(str, str)
46
        self._treeview_tags = gtk.TreeView(self._model)
47
        self._scrolledwindow_tags = gtk.ScrolledWindow()
48
        self._logview = LogView()
49
        self._hbox = gtk.HBox()
50
        self._vbox_buttons = gtk.VBox()
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
51
        self._vbox_buttons_top = gtk.VBox()
52
        self._vbox_buttons_bottom = gtk.VBox()
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
53
        self._vpaned = gtk.VPaned()
54
        
55
        # Set callbacks
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
56
        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).
57
        self._button_close.connect('clicked', self._on_close_clicked)
190.1.4 by Szilveszter Farkas (Phanatic)
Added Refresh button to the Tags window.
58
        self._button_refresh.connect('clicked', self._on_refresh_clicked)
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
59
        self._button_remove.connect('clicked', self._on_remove_clicked)
60
        self._treeview_tags.connect('cursor-changed', self._on_treeview_changed)
61
        if parent is None:
62
            self.connect('delete-event', gtk.main_quit)
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
63
        
64
        # Set properties
65
        self.set_title(_("Tags - Olive"))
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)
91
        self._vpaned.add2(self._logview)
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. """
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
161
        dialog = AddTagDialog(self.branch, self)
162
        response = dialog.run()
163
        if response != gtk.RESPONSE_NONE:
164
            dialog.hide()
165
        
166
            if response == gtk.RESPONSE_OK:
167
                self.branch.tags.set_tag(dialog.tagname, dialog.revid)
168
                self._refresh_tags()
169
            
170
            dialog.destroy()
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
171
    
190.1.1 by Szilveszter Farkas (Phanatic)
Added 'gtags' command and basic Tags window (just a skeleton).
172
    def _on_close_clicked(self, widget):
173
        """ Close button event handler. """
174
        self.destroy()
175
        if self._parent is None:
176
            gtk.main_quit()
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
177
    
190.1.4 by Szilveszter Farkas (Phanatic)
Added Refresh button to the Tags window.
178
    def _on_refresh_clicked(self, widget):
179
        """ Refresh button event handler. """
180
        self._refresh_tags()
181
    
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
182
    def _on_remove_clicked(self, widget):
183
        """ Remove button event handler. """
184
        (path, col) = self._treeview_tags.get_cursor()
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
185
        if path is None:
186
            return
187
        
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
188
        tag = self._model[path][0]
189
        
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
190
        dialog = RemoveTagDialog(tag, self)
191
        response = dialog.run()
192
        if response != gtk.RESPONSE_NONE:
193
            dialog.hide()
194
        
195
            if response == gtk.RESPONSE_OK:
196
                self.branch.tags.delete_tag(tag)
197
                self._refresh_tags()
198
            
199
            dialog.destroy()
190.1.2 by Szilveszter Farkas (Phanatic)
Display list of tags.
200
    
201
    def _on_treeview_changed(self, *args):
202
        """ When a user clicks on a tag. """
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
203
        # Refresh LogView only if there are tags available
204
        if not self._no_tags:
205
            (path, col) = self._treeview_tags.get_cursor()
206
            revision = self._model[path][1]
207
            
208
            self._logview.set_revision(self.branch.repository.get_revision(revision))
209
210
211
class RemoveTagDialog(gtk.Dialog):
212
    """ Confirm removal of tag. """
213
    def __init__(self, tagname, parent):
214
        gtk.Dialog.__init__(self, title="Remove tag - Olive",
215
                                  parent=parent,
216
                                  flags=0,
217
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
218
        
219
        # Get the arguments
220
        self.tag = tagname
221
        
222
        # Create the widgets
223
        self._hbox = gtk.HBox()
224
        self._vbox_question = gtk.VBox()
225
        self._image_question = gtk.image_new_from_stock(gtk.STOCK_DIALOG_QUESTION,
226
                                                        gtk.ICON_SIZE_DIALOG)
227
        self._label_title = gtk.Label()
190.1.7 by Szilveszter Farkas (Phanatic)
Display tag name on the remove dialog.
228
        self._label_question = gtk.Label()
190.1.3 by Szilveszter Farkas (Phanatic)
Finalized Tags window layout. Added Remove confirmation dialog.
229
        self._button_remove = gtk.Button(_("_Remove tag"), use_underline=True)
230
        
231
        # Set callbacks
232
        self._button_remove.connect('clicked', self._on_remove_clicked)
233
        
234
        # Set properties
235
        self._hbox.set_border_width(5)
236
        self._hbox.set_spacing(5)
237
        self._vbox_question.set_spacing(3)
238
        
239
        self._label_title.set_markup(_("<b><big>Remove tag?</big></b>"))
240
        self._label_title.set_alignment(0.0, 0.5)
190.1.7 by Szilveszter Farkas (Phanatic)
Display tag name on the remove dialog.
241
        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.
242
        self._label_question.set_alignment(0.0, 0.5)
243
        
244
        self._button_remove.set_image(gtk.image_new_from_stock(gtk.STOCK_REMOVE,
245
                                                               gtk.ICON_SIZE_BUTTON))
246
        self._button_remove.set_flags(gtk.CAN_DEFAULT)
247
        
248
        # Construct the dialog
249
        self._vbox_question.pack_start(self._label_title)
250
        self._vbox_question.pack_start(self._label_question)
251
        
252
        self._hbox.pack_start(self._image_question)
253
        self._hbox.pack_start(self._vbox_question)
254
        
255
        self.vbox.add(self._hbox)
256
        
257
        self.action_area.pack_end(self._button_remove)
258
        
259
        # Display dialog
260
        self.vbox.show_all()
261
        
262
        # Default to Commit button
263
        self._button_remove.grab_default()
264
    
265
    def _on_remove_clicked(self, widget):
266
        """ Remove button event handler. """
267
        self.response(gtk.RESPONSE_OK)
190.1.6 by Szilveszter Farkas (Phanatic)
Implemented Add tag dialog.
268
269
270
class AddTagDialog(gtk.Dialog):
271
    """ Add tag dialog. """
272
    def __init__(self, branch, parent):
273
        """ Initialize Add tag dialog. """
274
        gtk.Dialog.__init__(self, title="Add tag - Olive",
275
                                  parent=parent,
276
                                  flags=0,
277
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
278
        
279
        # Get arguments
280
        self._branch = branch
281
        
282
        # Create the widgets
283
        self._button_add = gtk.Button(_("_Add tag"), use_underline=True)
284
        self._button_revid = gtk.Button('')
285
        self._table = gtk.Table(2, 2)
286
        self._label_name = gtk.Label(_("Tag Name:"))
287
        self._label_revid = gtk.Label(_("Revision ID:"))
288
        self._entry_name = gtk.Entry()
289
        self._entry_revid = gtk.Entry()
290
        self._hbox_revid = gtk.HBox()
291
        
292
        # Set callbacks
293
        self._button_add.connect('clicked', self._on_add_clicked)
294
        self._button_revid.connect('clicked', self._on_revid_clicked)
295
        
296
        # Set properties
297
        self._label_name.set_alignment(0, 0.5)
298
        self._label_revid.set_alignment(0, 0.5)
299
        self._button_add.set_image(gtk.image_new_from_stock(gtk.STOCK_ADD,
300
                                                            gtk.ICON_SIZE_BUTTON))
301
        self._button_revid.set_image(gtk.image_new_from_stock(gtk.STOCK_OPEN,
302
                                                               gtk.ICON_SIZE_BUTTON))
303
        self._button_add.set_flags(gtk.CAN_DEFAULT)
304
        
305
        # Construct the dialog
306
        self._hbox_revid.pack_start(self._entry_revid, True, True)
307
        self._hbox_revid.pack_start(self._button_revid, False, False) 
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_revid_clicked(self, widget):
319
        """ Browse for revision button clicked handler. """
320
        from revbrowser import RevisionBrowser
321
        
322
        revb = RevisionBrowser(self._branch, self)
323
        response = revb.run()
324
        if response != gtk.RESPONSE_NONE:
325
            revb.hide()
326
        
327
            if response == gtk.RESPONSE_OK:
328
                if revb.selected_revno is not None:
329
                    self._entry_revid.set_text(revb.selected_revid)
330
            
331
            revb.destroy()
332
    
333
    def _on_add_clicked(self, widget):
334
        """ Add button clicked handler. """
335
        if len(self._entry_name.get_text()) == 0:
336
            error_dialog(_("No tag name specified"),
337
                         _("You have to specify the tag's desired name."))
338
            return
339
        
340
        if len(self._entry_revid.get_text()) == 0:
341
            self.revid = self._branch.last_revision()
342
        else:
343
            self.revid = self._entry_revid.get_text()
344
        
345
        self.tagname = self._entry_name.get_text()
346
        
347
        self.response(gtk.RESPONSE_OK)