/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to tags.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2007-04-13 17:10:04 UTC
  • mto: This revision was merged to the branch mainline in revision 193.
  • Revision ID: szilveszter.farkas@gmail.com-20070413171004-ey9ccvhboxilhqfy
Finalized Tags window layout. Added Remove confirmation dialog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
from bzrlib.plugins.gtk.logview import LogView
26
26
 
 
27
 
27
28
class TagsWindow(gtk.Window):
28
29
    """ Tags window. Allows the user to view/add/remove tags. """
29
30
    def __init__(self, branch, parent=None):
44
45
        self._logview = LogView()
45
46
        self._hbox = gtk.HBox()
46
47
        self._vbox_buttons = gtk.VBox()
 
48
        self._vbox_buttons_top = gtk.VBox()
 
49
        self._vbox_buttons_bottom = gtk.VBox()
47
50
        self._vpaned = gtk.VPaned()
48
51
        
49
52
        # Set callbacks
56
59
        
57
60
        # Set properties
58
61
        self.set_title(_("Tags - Olive"))
 
62
        self.set_default_size(600, 400)
59
63
        
60
64
        self._scrolledwindow_tags.set_policy(gtk.POLICY_AUTOMATIC,
61
65
                                             gtk.POLICY_AUTOMATIC)
62
66
        
 
67
        self._hbox.set_border_width(5)
 
68
        self._hbox.set_spacing(5)
 
69
        self._vbox_buttons.set_size_request(100, -1)
 
70
        
 
71
        self._vbox_buttons_top.set_spacing(3)
 
72
        
 
73
        self._vpaned.set_position(200)
 
74
        
63
75
        # Construct the dialog
64
76
        self._scrolledwindow_tags.add(self._treeview_tags)
65
77
        
66
 
        self._vbox_buttons.pack_start(self._button_add)
67
 
        self._vbox_buttons.pack_start(self._button_remove)
68
 
        self._vbox_buttons.pack_start(self._button_close)
 
78
        self._vbox_buttons_top.pack_start(self._button_add, False, False)
 
79
        self._vbox_buttons_top.pack_start(self._button_remove, False, False)
 
80
        self._vbox_buttons_bottom.pack_start(self._button_close, False, False)
 
81
        
 
82
        self._vbox_buttons.pack_start(self._vbox_buttons_top, True, True)
 
83
        self._vbox_buttons.pack_start(self._vbox_buttons_bottom, False, False)
69
84
        
70
85
        self._vpaned.add1(self._scrolledwindow_tags)
71
86
        self._vpaned.add2(self._logview)
72
87
        
73
 
        self._hbox.pack_start(self._vpaned)
74
 
        self._hbox.pack_start(self._vbox_buttons)
 
88
        self._hbox.pack_start(self._vpaned, True, True)
 
89
        self._hbox.pack_start(self._vbox_buttons, False, True)
75
90
        
76
91
        self.add(self._hbox)
77
92
        
 
93
        # Default to no tags
 
94
        self._no_tags = True
 
95
        
78
96
        # Load the tags
79
97
        self._load_tags()
80
98
        
83
101
    
84
102
    def _load_tags(self):
85
103
        """ Load the tags into the TreeView. """
86
 
        self._treeview_tags.append_column(gtk.TreeViewColumn(_("Tag Name"),
87
 
                                                             gtk.CellRendererText(),
88
 
                                                             text=0))
89
 
        self._treeview_tags.append_column(gtk.TreeViewColumn(_("Revision ID"),
90
 
                                                             gtk.CellRendererText(),
91
 
                                                             text=1))
 
104
        tvcol_name = gtk.TreeViewColumn(_("Tag Name"),
 
105
                                        gtk.CellRendererText(),
 
106
                                        text=0)
 
107
        tvcol_name.set_resizable(True)
 
108
        
 
109
        tvcol_revid = gtk.TreeViewColumn(_("Revision ID"),
 
110
                                         gtk.CellRendererText(),
 
111
                                         text=1)
 
112
        tvcol_revid.set_resizable(True)
 
113
        
 
114
        self._treeview_tags.append_column(tvcol_name)
 
115
        self._treeview_tags.append_column(tvcol_revid)
 
116
        
 
117
        self._treeview_tags.set_search_column(0)
92
118
        
93
119
        self._refresh_tags()
94
120
    
98
124
        if self.branch.supports_tags():
99
125
            tags = self.branch.tags.get_tag_dict()
100
126
            if len(tags) > 0:
 
127
                self._no_tags = False
101
128
                for name, target in tags.items():
102
129
                    self._model.append([name, target])
103
130
            else:
104
 
                self._no_tags()
 
131
                self._no_tags = True
 
132
                self._no_tags_available()
105
133
        else:
 
134
            self._no_tags = True
106
135
            self._tags_not_supported()
107
136
        
108
137
        self._treeview_tags.set_model(self._model)
113
142
        self._button_add.set_sensitive(False)
114
143
        self._button_remove.set_sensitive(False)
115
144
    
116
 
    def _no_tags(self):
 
145
    def _no_tags_available(self):
117
146
        """ No tags in the branch. """
118
147
        self._model.append([_("No tagged revisions in the branch."), ""])
119
148
        self._button_remove.set_sensitive(False)
133
162
        (path, col) = self._treeview_tags.get_cursor()
134
163
        tag = self._model[path][0]
135
164
        
136
 
        self.branch.tags.delete_tag(tag)
137
 
        self._refresh_tags()
 
165
        dialog = RemoveTagDialog(tag, self)
 
166
        response = dialog.run()
 
167
        if response != gtk.RESPONSE_NONE:
 
168
            dialog.hide()
 
169
        
 
170
            if response == gtk.RESPONSE_OK:
 
171
                self.branch.tags.delete_tag(tag)
 
172
                self._refresh_tags()
 
173
            
 
174
            dialog.destroy()
138
175
    
139
176
    def _on_treeview_changed(self, *args):
140
177
        """ When a user clicks on a tag. """
141
 
        (path, col) = self._treeview_tags.get_cursor()
142
 
        revision = self._model[path][1]
143
 
        
144
 
        self._logview.set_revision(self.branch.repository.get_revision(revision))
 
178
        # Refresh LogView only if there are tags available
 
179
        if not self._no_tags:
 
180
            (path, col) = self._treeview_tags.get_cursor()
 
181
            revision = self._model[path][1]
 
182
            
 
183
            self._logview.set_revision(self.branch.repository.get_revision(revision))
 
184
 
 
185
 
 
186
class RemoveTagDialog(gtk.Dialog):
 
187
    """ Confirm removal of tag. """
 
188
    def __init__(self, tagname, parent):
 
189
        gtk.Dialog.__init__(self, title="Remove tag - Olive",
 
190
                                  parent=parent,
 
191
                                  flags=0,
 
192
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
 
193
        
 
194
        # Get the arguments
 
195
        self.tag = tagname
 
196
        
 
197
        # Create the widgets
 
198
        self._hbox = gtk.HBox()
 
199
        self._vbox_question = gtk.VBox()
 
200
        self._image_question = gtk.image_new_from_stock(gtk.STOCK_DIALOG_QUESTION,
 
201
                                                        gtk.ICON_SIZE_DIALOG)
 
202
        self._label_title = gtk.Label()
 
203
        self._label_question = gtk.Label(_("Are you sure you want to remove the tag?"))
 
204
        self._button_remove = gtk.Button(_("_Remove tag"), use_underline=True)
 
205
        
 
206
        # Set callbacks
 
207
        self._button_remove.connect('clicked', self._on_remove_clicked)
 
208
        
 
209
        # Set properties
 
210
        self._hbox.set_border_width(5)
 
211
        self._hbox.set_spacing(5)
 
212
        self._vbox_question.set_spacing(3)
 
213
        
 
214
        self._label_title.set_markup(_("<b><big>Remove tag?</big></b>"))
 
215
        self._label_title.set_alignment(0.0, 0.5)
 
216
        self._label_question.set_alignment(0.0, 0.5)
 
217
        
 
218
        self._button_remove.set_image(gtk.image_new_from_stock(gtk.STOCK_REMOVE,
 
219
                                                               gtk.ICON_SIZE_BUTTON))
 
220
        self._button_remove.set_flags(gtk.CAN_DEFAULT)
 
221
        
 
222
        # Construct the dialog
 
223
        self._vbox_question.pack_start(self._label_title)
 
224
        self._vbox_question.pack_start(self._label_question)
 
225
        
 
226
        self._hbox.pack_start(self._image_question)
 
227
        self._hbox.pack_start(self._vbox_question)
 
228
        
 
229
        self.vbox.add(self._hbox)
 
230
        
 
231
        self.action_area.pack_end(self._button_remove)
 
232
        
 
233
        # Display dialog
 
234
        self.vbox.show_all()
 
235
        
 
236
        # Default to Commit button
 
237
        self._button_remove.grab_default()
 
238
    
 
239
    def _on_remove_clicked(self, widget):
 
240
        """ Remove button event handler. """
 
241
        self.response(gtk.RESPONSE_OK)