15
15
"""Graphical support for Bazaar using GTK.
17
17
This plugin includes:
18
commit-notify Start the graphical notifier of commits.
18
19
gannotate GTK+ annotate.
19
20
gbranch GTK+ branching.
20
21
gcheckout GTK+ checkout.
21
22
gcommit GTK+ commit dialog.
22
23
gconflicts GTK+ conflicts.
23
24
gdiff Show differences in working tree in a GTK+ Window.
25
ghandle-patch Display and optionally merge a merge directive or patch.
24
26
ginit Initialise a new branch.
25
gmerge GTK+ merge dialog
26
27
gmissing GTK+ missing revisions dialog.
27
28
gpreferences GTK+ preferences dialog.
104
105
bzrlib.ui.ui_factory = GtkUIFactory()
108
return [os.path.dirname(__file__),
109
return os.path.dirname(__file__)
112
def icon_path(*args):
113
basedirs = [os.path.join(data_path()),
109
114
"/usr/share/bzr-gtk",
110
115
"/usr/local/share/bzr-gtk"]
113
def data_path(*args):
114
for basedir in data_basedirs():
115
path = os.path.join(basedir, *args)
116
for basedir in basedirs:
117
path = os.path.join(basedir, 'icons', *args)
116
118
if os.path.exists(path):
121
def icon_path(*args):
122
return data_path(os.path.join('icons', *args))
126
pygtk = import_pygtk()
129
except RuntimeError, e:
130
if str(e) == "could not open display":
136
123
class GTKCommand(Command):
137
124
"""Abstract class providing GTK specific run commands."""
126
def open_display(self):
127
pygtk = import_pygtk()
130
except RuntimeError, e:
131
if str(e) == "could not open display":
141
138
dialog = self.get_gtk_dialog(os.path.abspath('.'))
196
193
if revision is not None:
197
194
if len(revision) == 1:
199
revision_id = revision[0].as_revision_id(tree1.branch)
196
revision_id = revision[0].in_history(branch).rev_id
200
197
tree2 = branch.repository.revision_tree(revision_id)
201
198
elif len(revision) == 2:
202
revision_id_0 = revision[0].as_revision_id(branch)
199
revision_id_0 = revision[0].in_history(branch).rev_id
203
200
tree2 = branch.repository.revision_tree(revision_id_0)
204
revision_id_1 = revision[1].as_revision_id(branch)
201
revision_id_1 = revision[1].in_history(branch).rev_id
205
202
tree1 = branch.repository.revision_tree(revision_id_1)
314
312
if revision is not None:
315
313
if len(revision) != 1:
316
314
raise BzrCommandError("Only 1 revion may be specified.")
317
revision_id = revision[0].as_revision_id(br)
315
revision_id = revision[0].in_history(br).rev_id
318
316
tree = br.repository.revision_tree(revision_id)
320
318
revision_id = getattr(tree, 'get_revision_id', lambda: None)()
322
window = GAnnotateWindow(all, plain, branch=br)
320
window = GAnnotateWindow(all, plain)
323
321
window.connect("destroy", lambda w: gtk.main_quit())
324
322
config = GAnnotateConfig(window)
362
360
except NoWorkingTree, e:
363
361
from dialog import error_dialog
364
error_dialog(_i18n('Directory does not have a working tree'),
365
_i18n('Operation aborted.'))
362
error_dialog(_('Directory does not have a working tree'),
363
_('Operation aborted.'))
366
364
return 1 # should this be retval=3?
368
366
# It is a good habit to keep things locked for the duration, but it
390
388
def run(self, path='.', revision=None):
390
gtk = self.open_display()
393
391
from status import StatusDialog
394
392
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
396
394
if revision is not None:
398
revision_id = revision[0].as_revision_id(wt.branch)
400
from bzrlib.errors import BzrError
401
raise BzrError('Revision %r doesn\'t exist' % revision[0].user_spec )
395
revision_id = revision[0].in_history(wt.branch).rev_id
403
397
revision_id = None
450
444
from bzrlib.plugins.gtk.preferences import PreferencesWindow
451
445
dialog = PreferencesWindow()
455
class cmd_gmerge(Command):
456
""" GTK+ merge dialog
459
takes_args = ["merge_from_path?"]
460
def run(self, merge_from_path=None):
461
from bzrlib import workingtree
462
from bzrlib.plugins.gtk.dialog import error_dialog
463
from bzrlib.plugins.gtk.merge import MergeDialog
465
(wt, path) = workingtree.WorkingTree.open_containing('.')
466
old_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
467
delta = wt.changes_from(old_tree)
468
if len(delta.added) or len(delta.removed) or len(delta.renamed) or len(delta.modified):
469
error_dialog(_i18n('There are local changes in the branch'),
470
_i18n('Please commit or revert the changes before merging.'))
472
parent_branch_path = wt.branch.get_parent()
473
merge = MergeDialog(wt, path, parent_branch_path)
474
response = merge.run()
478
449
class cmd_gmissing(Command):
479
450
""" GTK+ missing revisions dialog.
552
522
register_command(cmd)
525
class cmd_commit_notify(GTKCommand):
526
"""Run the bzr commit notifier.
528
This is a background program which will pop up a notification on the users
529
screen when a commit occurs.
533
from notify import NotifyPopupMenu
534
gtk = self.open_display()
535
menu = NotifyPopupMenu()
536
icon = gtk.status_icon_new_from_file(icon_path("bzr-icon-64.png"))
537
icon.connect('popup-menu', menu.display)
543
from bzrlib.bzrdir import BzrDir
544
from bzrlib import errors
545
from bzrlib.osutils import format_date
546
from bzrlib.transport import get_transport
547
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
549
BROADCAST_INTERFACE = "org.bazaarvcs.plugins.dbus.Broadcast"
550
bus = dbus.SessionBus()
552
def catch_branch(revision_id, urls):
553
# TODO: show all the urls, or perhaps choose the 'best'.
556
if isinstance(revision_id, unicode):
557
revision_id = revision_id.encode('utf8')
558
transport = get_transport(url)
559
a_dir = BzrDir.open_from_transport(transport)
560
branch = a_dir.open_branch()
561
revno = branch.revision_id_to_revno(revision_id)
562
revision = branch.repository.get_revision(revision_id)
563
summary = 'New revision %d in %s' % (revno, url)
564
body = 'Committer: %s\n' % revision.committer
565
body += 'Date: %s\n' % format_date(revision.timestamp,
568
body += revision.message
569
body = cgi.escape(body)
570
nw = pynotify.Notification(summary, body)
571
def start_viz(notification=None, action=None, data=None):
572
"""Start the viz program."""
573
pp = start_viz_window(branch, revision_id)
575
def start_branch(notification=None, action=None, data=None):
576
"""Start a Branch dialog"""
577
from bzrlib.plugins.gtk.branch import BranchDialog
578
bd = BranchDialog(remote_path=url)
580
nw.add_action("inspect", "Inspect", start_viz, None)
581
nw.add_action("branch", "Branch", start_branch, None)
587
bus.add_signal_receiver(catch_branch,
588
dbus_interface=BROADCAST_INTERFACE,
589
signal_name="Revision")
590
pynotify.init("bzr commit-notify")
593
register_command(cmd_commit_notify)
555
596
class cmd_gselftest(GTKCommand):
556
597
"""Version of selftest that displays a notification at the end"""
648
689
register_command(cmd_test_gtk)
692
class cmd_ghandle_patch(GTKCommand):
693
"""Display a patch or merge directive, possibly merging.
695
This is a helper, meant to be launched from other programs like browsers
696
or email clients. Since these programs often do not allow parameters to
697
be provided, a "handle-patch" script is included.
700
takes_args = ['path']
704
from bzrlib.plugins.gtk.diff import (DiffWindow,
705
MergeDirectiveWindow)
706
lines = open(path, 'rb').readlines()
707
lines = [l.replace('\r\n', '\n') for l in lines]
709
directive = merge_directive.MergeDirective.from_lines(lines)
710
except errors.NotAMergeDirective:
711
window = DiffWindow()
712
window.set_diff_text(path, lines)
714
window = MergeDirectiveWindow(directive, path)
715
window.set_diff_text(path, directive.patch.splitlines(True))
717
gtk = self.open_display()
718
window.connect("destroy", gtk.main_quit)
720
from dialog import error_dialog
721
error_dialog('Error', str(e))
726
register_command(cmd_ghandle_patch)
653
730
gettext.install('olive-gtk')
655
# Let's create a specialized alias to protect '_' from being erased by other
656
# uses of '_' as an anonymous variable (think pdb for one).
657
_i18n = gettext.gettext
659
733
class NoDisplayError(BzrCommandError):
660
734
"""gtk could not find a proper display"""