22
22
gcommit           GTK+ commit dialog.
 
23
23
gconflicts        GTK+ conflicts. 
 
24
24
gdiff             Show differences in working tree in a GTK+ Window. 
 
 
25
ghandle-patch     Display and optionally merge a merge directive or patch.
 
25
26
ginit             Initialise a new branch.
 
26
27
gmissing          GTK+ missing revisions dialog. 
 
27
28
gpreferences      GTK+ preferences dialog. 
 
 
39
 
version_info = (0, 95, 0, 'dev', 1)
 
 
40
version_info = (0, 94, 0, 'dev', 0)
 
41
42
if version_info[3] == 'final':
 
42
43
    version_string = '%d.%d.%d' % version_info[:3]
 
 
108
109
    return os.path.dirname(__file__)
 
111
 
def icon_path(*args):
 
112
 
    basedirs = [os.path.join(data_path()),
 
113
 
             "/usr/share/bzr-gtk", 
 
114
 
             "/usr/local/share/bzr-gtk"]
 
115
 
    for basedir in basedirs:
 
116
 
        path = os.path.join(basedir, 'icons', *args)
 
117
 
        if os.path.exists(path):
 
123
 
    pygtk = import_pygtk()
 
126
 
    except RuntimeError, e:
 
127
 
        if str(e) == "could not open display":
 
133
112
class GTKCommand(Command):
 
134
113
    """Abstract class providing GTK specific run commands."""
 
 
115
    def open_display(self):
 
 
116
        pygtk = import_pygtk()
 
 
119
        except RuntimeError, e:
 
 
120
            if str(e) == "could not open display":
 
138
127
        dialog = self.get_gtk_dialog(os.path.abspath('.'))
 
 
169
158
    def run(self, location="."):
 
170
159
        (br, path) = branch.Branch.open_containing(location)
 
172
161
        from push import PushDialog
 
173
162
        dialog = PushDialog(br.repository, br.last_revision(), br)
 
 
193
182
            if revision is not None:
 
194
183
                if len(revision) == 1:
 
196
 
                    revision_id = revision[0].as_revision_id(tree1.branch)
 
 
185
                    revision_id = revision[0].in_history(branch).rev_id
 
197
186
                    tree2 = branch.repository.revision_tree(revision_id)
 
198
187
                elif len(revision) == 2:
 
199
 
                    revision_id_0 = revision[0].as_revision_id(branch)
 
 
188
                    revision_id_0 = revision[0].in_history(branch).rev_id
 
200
189
                    tree2 = branch.repository.revision_tree(revision_id_0)
 
201
 
                    revision_id_1 = revision[1].as_revision_id(branch)
 
 
190
                    revision_id_1 = revision[1].in_history(branch).rev_id
 
202
191
                    tree1 = branch.repository.revision_tree(revision_id_1)
 
 
229
 
def start_viz_window(branch, revisions, limit=None):
 
 
218
def start_viz_window(branch, revision, limit=None):
 
230
219
    """Start viz on branch with revision revision.
 
232
221
    :return: The viz window object.
 
234
223
    from viz import BranchWindow
 
235
 
    return BranchWindow(branch, revisions, limit)
 
 
224
    return BranchWindow(branch, revision, limit)
 
238
227
class cmd_visualise(Command):
 
 
249
238
        Option('limit', "Maximum number of revisions to display.",
 
251
 
    takes_args = [ "locations*" ]
 
 
240
    takes_args = [ "location?" ]
 
252
241
    aliases = [ "visualize", "vis", "viz" ]
 
254
 
    def run(self, locations_list, revision=None, limit=None):
 
 
243
    def run(self, location=".", revision=None, limit=None):
 
256
 
        if locations_list is None:
 
257
 
            locations_list = ["."]
 
259
 
        for location in locations_list:
 
260
 
            (br, path) = branch.Branch.open_containing(location)
 
262
 
                revids.append(br.last_revision())
 
264
 
                revids.append(revision[0].as_revision_id(br))
 
 
245
        (br, path) = branch.Branch.open_containing(location)
 
 
247
            revid = br.last_revision()
 
 
251
            (revno, revid) = revision[0].in_history(br)
 
266
 
        pp = start_viz_window(br, revids, limit)
 
 
254
        pp = start_viz_window(br, revid, limit)
 
267
255
        pp.connect("destroy", lambda w: gtk.main_quit())
 
 
286
274
    aliases = ["gblame", "gpraise"]
 
288
276
    def run(self, filename, all=False, plain=False, line='1', revision=None):
 
 
277
        gtk = self.open_display()
 
 
311
299
        if revision is not None:
 
312
300
            if len(revision) != 1:
 
313
301
                raise BzrCommandError("Only 1 revion may be specified.")
 
314
 
            revision_id = revision[0].as_revision_id(br)
 
 
302
            revision_id = revision[0].in_history(br).rev_id
 
315
303
            tree = br.repository.revision_tree(revision_id)
 
317
305
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
 
319
 
        window = GAnnotateWindow(all, plain, branch=br)
 
 
307
        window = GAnnotateWindow(all, plain)
 
320
308
        window.connect("destroy", lambda w: gtk.main_quit())
 
321
309
        config = GAnnotateConfig(window)
 
 
359
347
        except NoWorkingTree, e:
 
360
348
            from dialog import error_dialog
 
361
 
            error_dialog(_i18n('Directory does not have a working tree'),
 
362
 
                         _i18n('Operation aborted.'))
 
 
349
            error_dialog(_('Directory does not have a working tree'),
 
 
350
                         _('Operation aborted.'))
 
363
351
            return 1 # should this be retval=3?
 
365
353
        # It is a good habit to keep things locked for the duration, but it
 
 
383
371
    aliases = [ "gst" ]
 
384
372
    takes_args = ['PATH?']
 
385
 
    takes_options = ['revision']
 
387
 
    def run(self, path='.', revision=None):
 
 
375
    def run(self, path='.'):
 
 
377
        gtk = self.open_display()
 
390
378
        from status import StatusDialog
 
391
379
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
 
393
 
        if revision is not None:
 
395
 
                revision_id = revision[0].as_revision_id(wt.branch)
 
397
 
                from bzrlib.errors import BzrError
 
398
 
                raise BzrError('Revision %r doesn\'t exist' % revision[0].user_spec )
 
402
 
        status = StatusDialog(wt, wt_path, revision_id)
 
 
380
        status = StatusDialog(wt, wt_path)
 
403
381
        status.connect("destroy", gtk.main_quit)
 
 
412
390
        (br, path) = branch.Branch.open_containing(".")
 
 
391
        gtk = self.open_display()
 
414
392
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
 
415
393
        from StringIO import StringIO
 
416
394
        dialog = SendMergeDirectiveDialog(br)
 
 
536
514
        from notify import NotifyPopupMenu
 
 
515
        gtk = self.open_display()
 
538
516
        menu = NotifyPopupMenu()
 
539
 
        icon = gtk.status_icon_new_from_file(icon_path("bzr-icon-64.png"))
 
 
517
        icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
 
540
518
        icon.connect('popup-menu', menu.display)
 
 
549
527
        from bzrlib.transport import get_transport
 
550
528
        if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
 
552
 
        BROADCAST_INTERFACE = "org.bazaarvcs.plugins.dbus.Broadcast"
 
 
530
        from bzrlib.plugins.dbus import activity
 
553
531
        bus = dbus.SessionBus()
 
 
532
        # get the object so we can subscribe to callbacks from it.
 
 
533
        broadcast_service = bus.get_object(
 
 
534
            activity.Broadcast.DBUS_NAME,
 
 
535
            activity.Broadcast.DBUS_PATH)
 
555
537
        def catch_branch(revision_id, urls):
 
556
538
            # TODO: show all the urls, or perhaps choose the 'best'.
 
 
587
569
            except Exception, e:
 
590
 
        bus.add_signal_receiver(catch_branch,
 
591
 
                                dbus_interface=BROADCAST_INTERFACE,
 
592
 
                                signal_name="Revision")
 
 
572
        broadcast_service.connect_to_signal("Revision", catch_branch,
 
 
573
            dbus_interface=activity.Broadcast.DBUS_INTERFACE)
 
593
574
        pynotify.init("bzr commit-notify")
 
 
692
673
register_command(cmd_test_gtk)
 
 
676
class cmd_ghandle_patch(GTKCommand):
 
 
677
    """Display a patch or merge directive, possibly merging.
 
 
679
    This is a helper, meant to be launched from other programs like browsers
 
 
680
    or email clients.  Since these programs often do not allow parameters to
 
 
681
    be provided, a "handle-patch" script is included.
 
 
684
    takes_args = ['path']
 
 
688
            from bzrlib.plugins.gtk.diff import (DiffWindow,
 
 
689
                                                 MergeDirectiveWindow)
 
 
690
            lines = open(path, 'rb').readlines()
 
 
691
            lines = [l.replace('\r\n', '\n') for l in lines]
 
 
693
                directive = merge_directive.MergeDirective.from_lines(lines)
 
 
694
            except errors.NotAMergeDirective:
 
 
695
                window = DiffWindow()
 
 
696
                window.set_diff_text(path, lines)
 
 
698
                window = MergeDirectiveWindow(directive, path)
 
 
699
                window.set_diff_text(path, directive.patch.splitlines(True))
 
 
701
            gtk = self.open_display()
 
 
702
            window.connect("destroy", gtk.main_quit)
 
 
704
            from dialog import error_dialog
 
 
705
            error_dialog('Error', str(e))
 
 
710
register_command(cmd_ghandle_patch)
 
697
714
gettext.install('olive-gtk')
 
699
 
# Let's create a specialized alias to protect '_' from being erased by other
 
700
 
# uses of '_' as an anonymous variable (think pdb for one).
 
701
 
_i18n = gettext.gettext
 
703
717
class NoDisplayError(BzrCommandError):
 
704
718
    """gtk could not find a proper display"""