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