1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
2
# Some parts of the code are:
3
# Copyright (C) 2005, 2006 by Canonical Ltd
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
from bzrlib.plugins.gtk import _i18n, icon_path
26
class OliveGui(gtk.Window):
27
""" Olive main window """
29
def __init__(self, calling_app):
30
# Pointer to calling instance for signal connection
31
self.signal = calling_app
34
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
35
self.set_title(_i18n("Olive - Bazaar GUI"))
36
self.set_icon_list(gtk.gdk.pixbuf_new_from_file(icon_path("oliveicon2.png")),
37
gtk.gdk.pixbuf_new_from_file(icon_path("olive-gtk.png")),
38
# Who has the svg version of the icon? Would be nice to include
39
#gtk.gdk.pixbuf_new_from_file(icon_path("olive.svg"))
41
self.set_property("width-request", 700)
42
self.set_property("height-request", 400)
44
self.connect("destroy", self.destroy)
45
self.connect("delete_event", self.signal.on_window_main_delete_event)
47
# Accelerator group to Quit program
48
accelgroup = gtk.AccelGroup()
49
self.add_accel_group(accelgroup)
50
self.quit_action = gtk.Action(_i18n("Quit"), None, None, gtk.STOCK_QUIT)
51
self.quit_action.connect('activate', self.signal.on_window_main_delete_event)
52
actiongroup = gtk.ActionGroup('QuitAction')
53
actiongroup.add_action_with_accel(self.quit_action, None)
54
self.quit_action.set_accel_group(accelgroup)
55
self.quit_action.connect_accelerator()
57
# High level build up of window
58
self.vbox = gtk.VBox(False, 0)
62
self._create_menubar()
63
self.vbox.pack_start(self.mb, False, False, 0)
66
self._create_toolbar()
67
self.vbox.pack_start(self.tb, False, False, 0)
70
self._create_locationbar()
71
self.vbox.pack_start(self.locationbar, False, False, 0)
74
self.hpaned_main = gtk.HPaned()
75
self._create_bookmarklist()
76
self.hpaned_main.add(self.scrolledwindow_left)
77
self._create_filelist()
78
self.hpaned_main.add(self.scrolledwindow_right)
79
self.vbox.pack_start(self.hpaned_main, True, True, 0)
82
self.statusbar = gtk.Statusbar()
83
self.vbox.pack_end(self.statusbar, False, False, 0)
88
def destroy(self, widget=None, data=None):
89
""" Ends the program """
92
def _create_menubar(self):
93
self.mb = gtk.MenuBar()
96
self.mb_file = gtk.MenuItem(_i18n("_File"))
97
self.mb_file_menu = gtk.Menu()
99
self.mb_file_add = gtk.ImageMenuItem(gtk.STOCK_ADD, _i18n("_Add file(s)"))
100
self.mb_file_add.connect('activate', self.signal.on_menuitem_add_files_activate)
101
self.mb_file_menu.append(self.mb_file_add)
103
self.mb_file_remove = gtk.ImageMenuItem(gtk.STOCK_REMOVE, _i18n("_Remove file(s)"))
104
self.mb_file_remove.connect('activate', self.signal.on_menuitem_remove_file_activate)
105
self.mb_file_menu.append(self.mb_file_remove)
107
self.mb_file_menu.append(gtk.SeparatorMenuItem())
109
self.mb_file_bookmark = gtk.MenuItem(_i18n("_Bookmark current directory"))
110
self.mb_file_bookmark.connect('activate', self.signal.on_menuitem_file_bookmark_activate)
111
self.mb_file_menu.append(self.mb_file_bookmark)
113
self.mb_file_mkdir = gtk.MenuItem(_i18n("_Make directory"))
114
self.mb_file_mkdir.connect('activate', self.signal.on_menuitem_file_make_directory_activate)
115
self.mb_file_menu.append(self.mb_file_mkdir)
117
self.mb_file_menu.append(gtk.SeparatorMenuItem())
119
self.mb_file_rename = gtk.MenuItem(_i18n("_Rename"))
120
self.mb_file_rename.connect('activate', self.signal.on_menuitem_file_rename_activate)
121
self.mb_file_menu.append(self.mb_file_rename)
123
self.mb_file_move = gtk.MenuItem(_i18n("_Move"))
124
self.mb_file_move.connect('activate', self.signal.on_menuitem_file_move_activate)
125
self.mb_file_menu.append(self.mb_file_move)
127
self.mb_file_annotate = gtk.MenuItem(_i18n("_Annotate"))
128
self.mb_file_annotate.connect('activate', self.signal.on_menuitem_file_annotate_activate)
129
self.mb_file_menu.append(self.mb_file_annotate)
131
self.mb_file_menu.append(gtk.SeparatorMenuItem())
133
self.mb_file_quit = self.quit_action.create_menu_item()
134
self.mb_file_menu.append(self.mb_file_quit)
136
self.mb_file.set_submenu(self.mb_file_menu)
137
self.mb.append(self.mb_file)
140
self.mb_view = gtk.MenuItem(_i18n("_View"))
141
self.mb_view_menu = gtk.Menu()
143
self.mb_view_showhidden = gtk.CheckMenuItem(_i18n("Show _hidden files"))
144
self.mb_view_showhidden.connect('activate', self.signal.on_menuitem_view_show_hidden_files_activate)
145
self.mb_view_menu.append(self.mb_view_showhidden)
147
self.mb_view_showignored = gtk.CheckMenuItem(_i18n("Show _ignored files"))
148
self.mb_view_showignored.connect('activate', self.signal.on_menuitem_view_show_ignored_files_activate)
149
self.mb_view_menu.append(self.mb_view_showignored)
151
self.mb_view_menu.append(gtk.SeparatorMenuItem())
153
self.mb_view_refresh = gtk.ImageMenuItem(gtk.STOCK_REFRESH, _i18n("_Refresh"))
154
self.mb_view_refresh.connect('activate', self.signal.on_menuitem_view_refresh_activate)
155
self.mb_view_menu.append(self.mb_view_refresh)
157
self.mb_view.set_submenu(self.mb_view_menu)
158
self.mb.append(self.mb_view)
161
self.mb_branch = gtk.MenuItem(_i18n("_Branch"))
162
self.mb_branch_menu = gtk.Menu()
164
self.mb_branch_initialize = gtk.MenuItem(_i18n("_Initialize"))
165
self.mb_branch_initialize.connect('activate', self.signal.on_menuitem_branch_initialize_activate)
166
self.mb_branch_menu.append(self.mb_branch_initialize)
168
self.mb_branch_get = gtk.MenuItem(_i18n("_Get"))
169
self.mb_branch_get.connect('activate', self.signal.on_menuitem_branch_get_activate)
170
self.mb_branch_menu.append(self.mb_branch_get)
172
self.mb_branch_checkout = gtk.MenuItem(_i18n("C_heckout"))
173
self.mb_branch_checkout.connect('activate', self.signal.on_menuitem_branch_checkout_activate)
174
self.mb_branch_menu.append(self.mb_branch_checkout)
176
self.mb_branch_menu.append(gtk.SeparatorMenuItem())
178
self.mb_branch_pull = gtk.ImageMenuItem(_i18n("Pu_ll"))
179
pullimage = gtk.Image()
180
pullimage.set_from_file(icon_path("pull16.png"))
181
self.mb_branch_pull.set_image(pullimage)
182
self.mb_branch_pull.connect('activate', self.signal.on_menuitem_branch_pull_activate)
183
self.mb_branch_menu.append(self.mb_branch_pull)
185
self.mb_branch_push = gtk.ImageMenuItem(_i18n("Pu_sh"))
186
pushimage = gtk.Image()
187
pushimage.set_from_file(icon_path("push16.png"))
188
self.mb_branch_push.set_image(pushimage)
189
self.mb_branch_push.connect('activate', self.signal.on_menuitem_branch_push_activate)
190
self.mb_branch_menu.append(self.mb_branch_push)
192
self.mb_branch_update = gtk.MenuItem(_i18n("_Update"))
193
self.mb_branch_update.connect('activate', self.signal.on_menuitem_branch_update_activate)
194
self.mb_branch_menu.append(self.mb_branch_update)
196
self.mb_branch_menu.append(gtk.SeparatorMenuItem())
198
self.mb_branch_revert = gtk.ImageMenuItem(_i18n("_Revert all changes"))
199
revertimage = gtk.Image()
200
revertimage.set_from_stock(gtk.STOCK_REVERT_TO_SAVED, gtk.ICON_SIZE_MENU)
201
self.mb_branch_revert.set_image(revertimage)
202
self.mb_branch_revert.connect('activate', self.signal.on_menuitem_branch_revert_activate)
203
self.mb_branch_menu.append(self.mb_branch_revert)
205
self.mb_branch_merge = gtk.MenuItem(_i18n("_Merge"))
206
self.mb_branch_merge.connect('activate', self.signal.on_menuitem_branch_merge_activate)
207
self.mb_branch_menu.append(self.mb_branch_merge)
209
self.mb_branch_commit = gtk.ImageMenuItem(_i18n("_Commit"))
210
commitimage = gtk.Image()
211
commitimage.set_from_file(icon_path("commit16.png"))
212
self.mb_branch_commit.set_image(commitimage)
213
self.mb_branch_commit.connect('activate', self.signal.on_menuitem_branch_commit_activate)
214
self.mb_branch_menu.append(self.mb_branch_commit)
216
self.mb_branch_menu.append(gtk.SeparatorMenuItem())
218
self.mb_branch_tags = gtk.ImageMenuItem(_i18n("Ta_gs"))
219
tagsimage = gtk.Image()
220
tagsimage.set_from_file(icon_path("tag-16.png"))
221
self.mb_branch_tags.set_image(tagsimage)
222
self.mb_branch_tags.connect('activate', self.signal.on_menuitem_branch_tags_activate)
223
self.mb_branch_menu.append(self.mb_branch_tags)
225
self.mb_branch_status = gtk.MenuItem(_i18n("S_tatus"))
226
self.mb_branch_status.connect('activate', self.signal.on_menuitem_branch_status_activate)
227
self.mb_branch_menu.append(self.mb_branch_status)
229
self.mb_branch_missingrevisions = gtk.MenuItem(_i18n("Missing _revisions"))
230
self.mb_branch_missingrevisions.connect('activate', self.signal.on_menuitem_branch_missing_revisions_activate)
231
self.mb_branch_menu.append(self.mb_branch_missingrevisions)
233
self.mb_branch_conflicts = gtk.MenuItem(_i18n("Con_flicts"))
234
self.mb_branch_conflicts.connect('activate', self.signal.on_menuitem_branch_conflicts_activate)
235
self.mb_branch_menu.append(self.mb_branch_conflicts)
237
self.mb_branch.set_submenu(self.mb_branch_menu)
238
self.mb.append(self.mb_branch)
241
self.mb_statistics = gtk.MenuItem(_i18n("_Statistics"))
242
self.mb_statistics_menu = gtk.Menu()
244
self.mb_statistics_differences = gtk.ImageMenuItem(_i18n("_Differences"))
245
diffimage = gtk.Image()
246
diffimage.set_from_file(icon_path("diff16.png"))
247
self.mb_statistics_differences.set_image(diffimage)
248
self.mb_statistics_differences.connect('activate', self.signal.on_menuitem_stats_diff_activate)
249
self.mb_statistics_menu.append(self.mb_statistics_differences)
251
self.mb_statistics_log = gtk.ImageMenuItem(_i18n("_Log"))
252
logimage = gtk.Image()
253
logimage.set_from_file(icon_path("log16.png"))
254
self.mb_statistics_log.set_image(logimage)
255
self.mb_statistics_log.connect('activate', self.signal.on_menuitem_stats_log_activate)
256
self.mb_statistics_menu.append(self.mb_statistics_log)
258
self.mb_statistics_information = gtk.MenuItem(_i18n("_Information"))
259
self.mb_statistics_information.connect('activate', self.signal.on_menuitem_stats_infos_activate)
260
self.mb_statistics_menu.append(self.mb_statistics_information)
262
self.mb_statistics.set_submenu(self.mb_statistics_menu)
263
self.mb.append(self.mb_statistics)
266
self.mb_help = gtk.MenuItem(_i18n("Help"))
267
self.mb_help_menu = gtk.Menu()
269
self.mb_help_about = gtk.ImageMenuItem(gtk.STOCK_ABOUT)
270
self.mb_help_about.connect('activate', self.signal.on_about_activate)
271
self.mb_help_menu.append(self.mb_help_about)
273
self.mb_help.set_submenu(self.mb_help_menu)
274
self.mb.append(self.mb_help)
276
def _create_toolbar(self):
277
self.tb = gtk.Toolbar()
279
self.tb_refresh_icon = gtk.Image()
280
self.tb_refresh_icon.set_from_file(icon_path("refresh.png"))
281
self.tb_refresh = gtk.ToolButton(self.tb_refresh_icon, _i18n("Refresh"))
282
self.tb_refresh.connect('clicked', self.signal.on_menuitem_view_refresh_activate)
283
self.tb.add(self.tb_refresh)
285
self.tb_diff_icon = gtk.Image()
286
self.tb_diff_icon.set_from_file(icon_path("diff.png"))
287
self.tb_diff = gtk.ToolButton(self.tb_diff_icon, _i18n("Diff"))
288
self.tb_diff.connect('clicked', self.signal.on_menuitem_stats_diff_activate)
289
self.tb.add(self.tb_diff)
291
self.tb_log_icon = gtk.Image()
292
self.tb_log_icon.set_from_file(icon_path("log.png"))
293
self.tb_log = gtk.ToolButton(self.tb_log_icon, _i18n("Log"))
294
self.tb_log.connect('clicked', self.signal.on_menuitem_stats_log_activate)
295
self.tb.add(self.tb_log)
297
self.tb.add(gtk.SeparatorToolItem())
299
self.tb_commit_icon = gtk.Image()
300
self.tb_commit_icon.set_from_file(icon_path("commit.png"))
301
self.tb_commit = gtk.ToolButton(self.tb_commit_icon, _i18n("Commit"))
302
self.tb_commit.connect('clicked', self.signal.on_menuitem_branch_commit_activate)
303
self.tb.add(self.tb_commit)
305
self.tb.add(gtk.SeparatorToolItem())
307
self.tb_pull_icon = gtk.Image()
308
self.tb_pull_icon.set_from_file(icon_path("pull.png"))
309
self.tb_pull = gtk.ToolButton(self.tb_pull_icon, _i18n("Pull"))
310
self.tb_pull.connect('clicked', self.signal.on_menuitem_branch_pull_activate)
311
self.tb.add(self.tb_pull)
313
self.tb_push_icon = gtk.Image()
314
self.tb_push_icon.set_from_file(icon_path("push.png"))
315
self.tb_push = gtk.ToolButton(self.tb_push_icon, _i18n("Push"))
316
self.tb_push.connect('clicked', self.signal.on_menuitem_branch_push_activate)
317
self.tb.add(self.tb_push)
319
self.tb_update_icon = gtk.Image()
320
self.tb_update_icon.set_from_file(icon_path("pull.png"))
321
self.tb_update = gtk.ToolButton(self.tb_update_icon, _i18n("Update"))
322
self.tb_update.connect('clicked', self.signal.on_menuitem_branch_update_activate)
323
self.tb.add(self.tb_update)
325
def _create_locationbar(self):
326
""" Creates the location bar, including the history widgets """
327
self.locationbar = gtk.HBox()
329
self.button_location_up = gtk.Button()
330
self.button_location_up.set_relief(gtk.RELIEF_NONE)
331
image_location_up = gtk.Image()
332
image_location_up.set_from_stock(gtk.STOCK_GO_UP, gtk.ICON_SIZE_BUTTON)
333
self.button_location_up.add(image_location_up)
334
self.button_location_up.connect("clicked", self.signal.on_button_location_up_clicked)
335
self.locationbar.pack_start(self.button_location_up, False, False, 0)
337
self.entry_location = gtk.Entry()
338
self.entry_location.connect("activate", self.signal.on_button_location_jump_clicked)
339
self.locationbar.pack_start(self.entry_location, True, True, 0)
341
self.image_location_error = gtk.Image()
342
self.image_location_error.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_BUTTON)
343
self.locationbar.pack_start(self.image_location_error, False, False, 0)
345
self.button_location_jump = gtk.Button(stock=gtk.STOCK_JUMP_TO)
346
self.button_location_jump.set_relief(gtk.RELIEF_NONE)
347
self.button_location_jump.connect("clicked", self.signal.on_button_location_jump_clicked)
348
self.locationbar.pack_start(self.button_location_jump, False, False, 0)
350
self.locationbar.pack_start(gtk.VSeparator(), False, False, 0)
352
self.checkbutton_history = gtk.CheckButton(_i18n("H_istory Mode"))
353
self.checkbutton_history.connect("toggled", self.signal.on_checkbutton_history_toggled)
354
self.locationbar.pack_start(self.checkbutton_history, False, False, 0)
356
self.entry_history_revno = gtk.Entry()
357
self.entry_history_revno.set_property("width-request", 75)
358
self.entry_history_revno.set_sensitive(False)
359
self.entry_history_revno.connect("activate", self.signal.on_entry_history_revno_activate)
360
self.locationbar.pack_start(self.entry_history_revno, False, False, 0)
362
self.button_history_browse = gtk.Button()
363
self.button_history_browse.set_sensitive(False)
364
self.image_history_browse = gtk.Image()
365
self.image_history_browse.set_from_stock(gtk.STOCK_OPEN, gtk.ICON_SIZE_BUTTON)
366
self.button_history_browse.add(self.image_history_browse)
367
self.button_history_browse.connect("clicked", self.signal.on_button_history_browse_clicked)
368
self.locationbar.pack_start(self.button_history_browse, False, False, 0)
370
def _create_bookmarklist(self):
371
""" Creates the bookmark list (a ListStore in a TreeView in a ScrolledWindow)"""
372
self.scrolledwindow_left = gtk.ScrolledWindow()
373
self.scrolledwindow_left.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
375
self.treeview_left = gtk.TreeView()
376
self.treeview_left.set_headers_visible(False)
377
self.treeview_left.connect("button-press-event", self.signal.on_treeview_left_button_press_event)
378
self.treeview_left.connect("row-activated", self.signal.on_treeview_left_row_activated)
379
self.scrolledwindow_left.add(self.treeview_left)
381
# Move olive/__init__.py _load_left List creation here
383
def _create_filelist(self):
384
""" Creates the file list (a ListStore in a TreeView in a ScrolledWindow)"""
385
# Model: [ icon, dir, name, status text, status, size (int), size (human), mtime (int), mtime (local), fileid ]
386
self.scrolledwindow_right = gtk.ScrolledWindow()
387
self.scrolledwindow_right.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
389
self.treeview_right = gtk.TreeView()
390
self.treeview_right.connect("button-press-event", self.signal.on_treeview_right_button_press_event)
391
self.treeview_right.connect("row-activated", self.signal.on_treeview_right_row_activated)
392
self.scrolledwindow_right.add(self.treeview_right)
394
# Move olive/__init__.py _load_right List creation here
396
def set_view_to_localbranch(self, notbranch=False):
397
""" Change the sensitivity of gui items to reflect the fact that the path is a branch or not"""
398
self.mb_branch_initialize.set_sensitive(notbranch)
399
self.mb_branch_get.set_sensitive(notbranch)
400
self.mb_branch_checkout.set_sensitive(notbranch)
401
self.mb_branch_pull.set_sensitive(not notbranch)
402
self.mb_branch_push.set_sensitive(not notbranch)
403
self.mb_branch_update.set_sensitive(not notbranch)
404
self.mb_branch_revert.set_sensitive(not notbranch)
405
self.mb_branch_merge.set_sensitive(not notbranch)
406
self.mb_branch_commit.set_sensitive(not notbranch)
407
self.mb_branch_tags.set_sensitive(not notbranch)
408
self.mb_branch_status.set_sensitive(not notbranch)
409
self.mb_branch_missingrevisions.set_sensitive(not notbranch)
410
self.mb_branch_conflicts.set_sensitive(not notbranch)
411
self.mb_statistics.set_sensitive(not notbranch)
412
self.mb_statistics_differences.set_sensitive(not notbranch)
413
self.mb_file_add.set_sensitive(not notbranch)
414
self.mb_file_remove.set_sensitive(not notbranch)
415
self.mb_file_mkdir.set_sensitive(not notbranch)
416
self.mb_file_rename.set_sensitive(not notbranch)
417
self.mb_file_move.set_sensitive(not notbranch)
418
self.mb_file_annotate.set_sensitive(not notbranch)
419
self.tb_diff.set_sensitive(not notbranch)
420
self.tb_log.set_sensitive(not notbranch)
421
self.tb_commit.set_sensitive(not notbranch)
422
self.tb_pull.set_sensitive(not notbranch)
423
self.tb_push.set_sensitive(not notbranch)
424
self.tb_update.set_sensitive(not notbranch)
426
def set_view_to_remotebranch(self):
427
""" Change the sensitivity of gui items to reflect the fact that the branch is remote"""
428
self.mb_file_add.set_sensitive(False)
429
self.mb_file_remove.set_sensitive(False)
430
self.mb_file_mkdir.set_sensitive(False)
431
self.mb_file_rename.set_sensitive(False)
432
self.mb_file_move.set_sensitive(False)
433
self.mb_file_annotate.set_sensitive(False)
434
self.mb_branch_initialize.set_sensitive(False)
435
self.mb_branch_get.set_sensitive(True)
436
self.mb_branch_checkout.set_sensitive(True)
437
self.mb_branch_pull.set_sensitive(False)
438
self.mb_branch_push.set_sensitive(False)
439
self.mb_branch_update.set_sensitive(False)
440
self.mb_branch_revert.set_sensitive(False)
441
self.mb_branch_merge.set_sensitive(False)
442
self.mb_branch_commit.set_sensitive(False)
443
self.mb_branch_tags.set_sensitive(True)
444
self.mb_branch_status.set_sensitive(False)
445
self.mb_branch_missingrevisions.set_sensitive(False)
446
self.mb_branch_conflicts.set_sensitive(False)
447
self.mb_statistics.set_sensitive(True)
448
self.mb_statistics_differences.set_sensitive(False)
449
self.tb_diff.set_sensitive(False)
450
self.tb_log.set_sensitive(True)
451
self.tb_commit.set_sensitive(False)
452
self.tb_pull.set_sensitive(False)
453
self.tb_push.set_sensitive(False)
454
self.tb_update.set_sensitive(False)