/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# Copyright (C) 2007 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

try:
    import pygtk
    pygtk.require("2.0")
except:
    pass

import gtk

from bzrlib.plugins.gtk.logview import LogView


class TagsWindow(gtk.Window):
    """ Tags window. Allows the user to view/add/remove tags. """
    def __init__(self, branch, parent=None):
        """ Initialize the Tags window. """
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        
        # Get arguments
        self.branch = branch
        self._parent = parent
        
        # Create the widgets
        self._button_add = gtk.Button(stock=gtk.STOCK_ADD)
        self._button_remove = gtk.Button(stock=gtk.STOCK_REMOVE)
        self._button_refresh = gtk.Button(stock=gtk.STOCK_REFRESH)
        self._button_close = gtk.Button(stock=gtk.STOCK_CLOSE)
        self._model = gtk.ListStore(str, str)
        self._treeview_tags = gtk.TreeView(self._model)
        self._scrolledwindow_tags = gtk.ScrolledWindow()
        self._logview = LogView()
        self._hbox = gtk.HBox()
        self._vbox_buttons = gtk.VBox()
        self._vbox_buttons_top = gtk.VBox()
        self._vbox_buttons_bottom = gtk.VBox()
        self._vpaned = gtk.VPaned()
        
        # Set callbacks
        self._button_add.connect('clicked', self._on_add_clicked)
        self._button_close.connect('clicked', self._on_close_clicked)
        self._button_refresh.connect('clicked', self._on_refresh_clicked)
        self._button_remove.connect('clicked', self._on_remove_clicked)
        self._treeview_tags.connect('cursor-changed', self._on_treeview_changed)
        if parent is None:
            self.connect('delete-event', gtk.main_quit)
        
        # Set properties
        self.set_title(_("Tags - Olive"))
        self.set_default_size(600, 400)
        
        self._scrolledwindow_tags.set_policy(gtk.POLICY_AUTOMATIC,
                                             gtk.POLICY_AUTOMATIC)
        
        self._hbox.set_border_width(5)
        self._hbox.set_spacing(5)
        self._vbox_buttons.set_size_request(100, -1)
        
        self._vbox_buttons_top.set_spacing(3)
        
        self._vpaned.set_position(200)
        
        # Construct the dialog
        self._scrolledwindow_tags.add(self._treeview_tags)
        
        self._vbox_buttons_top.pack_start(self._button_add, False, False)
        self._vbox_buttons_top.pack_start(self._button_remove, False, False)
        self._vbox_buttons_top.pack_start(self._button_refresh, False, False)
        self._vbox_buttons_bottom.pack_start(self._button_close, False, False)
        
        self._vbox_buttons.pack_start(self._vbox_buttons_top, True, True)
        self._vbox_buttons.pack_start(self._vbox_buttons_bottom, False, False)
        
        self._vpaned.add1(self._scrolledwindow_tags)
        self._vpaned.add2(self._logview)
        
        self._hbox.pack_start(self._vpaned, True, True)
        self._hbox.pack_start(self._vbox_buttons, False, True)
        
        self.add(self._hbox)
        
        # Default to no tags
        self._no_tags = True
        
        # Load the tags
        self._load_tags()
        
        # Display everything
        self._hbox.show_all()
    
    def _load_tags(self):
        """ Load the tags into the TreeView. """
        tvcol_name = gtk.TreeViewColumn(_("Tag Name"),
                                        gtk.CellRendererText(),
                                        text=0)
        tvcol_name.set_resizable(True)
        
        tvcol_revid = gtk.TreeViewColumn(_("Revision ID"),
                                         gtk.CellRendererText(),
                                         text=1)
        tvcol_revid.set_resizable(True)
        
        self._treeview_tags.append_column(tvcol_name)
        self._treeview_tags.append_column(tvcol_revid)
        
        self._treeview_tags.set_search_column(0)
        
        self._refresh_tags()
    
    def _refresh_tags(self):
        """ Refresh the list of tags. """
        self._model.clear()
        if self.branch.supports_tags():
            tags = self.branch.tags.get_tag_dict()
            if len(tags) > 0:
                self._no_tags = False
                for name, target in tags.items():
                    self._model.append([name, target])
            else:
                self._no_tags = True
                self._no_tags_available()
        else:
            self._no_tags = True
            self._tags_not_supported()
        
        self._treeview_tags.set_model(self._model)
    
    def _tags_not_supported(self):
        """ Tags are not supported. """
        self._model.append([_("Tags are not supported by this branch format. Please upgrade."), ""])
        self._button_add.set_sensitive(False)
        self._button_remove.set_sensitive(False)
    
    def _no_tags_available(self):
        """ No tags in the branch. """
        self._model.append([_("No tagged revisions in the branch."), ""])
        self._button_remove.set_sensitive(False)
    
    def _on_add_clicked(self, widget):
        """ Add button event handler. """
        return
    
    def _on_close_clicked(self, widget):
        """ Close button event handler. """
        self.destroy()
        if self._parent is None:
            gtk.main_quit()
    
    def _on_refresh_clicked(self, widget):
        """ Refresh button event handler. """
        self._refresh_tags()
    
    def _on_remove_clicked(self, widget):
        """ Remove button event handler. """
        (path, col) = self._treeview_tags.get_cursor()
        tag = self._model[path][0]
        
        dialog = RemoveTagDialog(tag, self)
        response = dialog.run()
        if response != gtk.RESPONSE_NONE:
            dialog.hide()
        
            if response == gtk.RESPONSE_OK:
                self.branch.tags.delete_tag(tag)
                self._refresh_tags()
            
            dialog.destroy()
    
    def _on_treeview_changed(self, *args):
        """ When a user clicks on a tag. """
        # Refresh LogView only if there are tags available
        if not self._no_tags:
            (path, col) = self._treeview_tags.get_cursor()
            revision = self._model[path][1]
            
            self._logview.set_revision(self.branch.repository.get_revision(revision))


class RemoveTagDialog(gtk.Dialog):
    """ Confirm removal of tag. """
    def __init__(self, tagname, parent):
        gtk.Dialog.__init__(self, title="Remove tag - Olive",
                                  parent=parent,
                                  flags=0,
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
        
        # Get the arguments
        self.tag = tagname
        
        # Create the widgets
        self._hbox = gtk.HBox()
        self._vbox_question = gtk.VBox()
        self._image_question = gtk.image_new_from_stock(gtk.STOCK_DIALOG_QUESTION,
                                                        gtk.ICON_SIZE_DIALOG)
        self._label_title = gtk.Label()
        self._label_question = gtk.Label(_("Are you sure you want to remove the tag?"))
        self._button_remove = gtk.Button(_("_Remove tag"), use_underline=True)
        
        # Set callbacks
        self._button_remove.connect('clicked', self._on_remove_clicked)
        
        # Set properties
        self._hbox.set_border_width(5)
        self._hbox.set_spacing(5)
        self._vbox_question.set_spacing(3)
        
        self._label_title.set_markup(_("<b><big>Remove tag?</big></b>"))
        self._label_title.set_alignment(0.0, 0.5)
        self._label_question.set_alignment(0.0, 0.5)
        
        self._button_remove.set_image(gtk.image_new_from_stock(gtk.STOCK_REMOVE,
                                                               gtk.ICON_SIZE_BUTTON))
        self._button_remove.set_flags(gtk.CAN_DEFAULT)
        
        # Construct the dialog
        self._vbox_question.pack_start(self._label_title)
        self._vbox_question.pack_start(self._label_question)
        
        self._hbox.pack_start(self._image_question)
        self._hbox.pack_start(self._vbox_question)
        
        self.vbox.add(self._hbox)
        
        self.action_area.pack_end(self._button_remove)
        
        # Display dialog
        self.vbox.show_all()
        
        # Default to Commit button
        self._button_remove.grab_default()
    
    def _on_remove_clicked(self, widget):
        """ Remove button event handler. """
        self.response(gtk.RESPONSE_OK)