/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 nautilus-bzr.py

  • Committer: Jelmer Vernooij
  • Date: 2011-11-29 09:55:31 UTC
  • Revision ID: jelmer@samba.org-20111129095531-mlbt8harl1113ld3
Add branch property page in nautilus-bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
212
212
 
213
213
        return items
214
214
 
 
215
    def _get_file_menuitems(self, tree, intertree, path):
 
216
        file_id = tree.path2id(path)
 
217
        if file_id is None:
 
218
            item = Nautilus.MenuItem(name='BzrNautilus::add',
 
219
                                 label='Add',
 
220
                                 tip='Add as versioned file',
 
221
                                 icon='')
 
222
            item.connect('activate', self.add_cb, tree, path)
 
223
            yield item
 
224
 
 
225
            item = Nautilus.MenuItem(name='BzrNautilus::ignore',
 
226
                                 label='Ignore',
 
227
                                 tip='Ignore file for versioning',
 
228
                                 icon='')
 
229
            item.connect('activate', self.ignore_cb, tree, path)
 
230
            yield item
 
231
        elif tree.is_ignored(path):
 
232
            item = Nautilus.MenuItem(name='BzrNautilus::unignore',
 
233
                                 label='Unignore',
 
234
                                 tip='Unignore file for versioning',
 
235
                                 icon='')
 
236
            item.connect('activate', self.unignore_cb, tree, path)
 
237
            yield item
 
238
        else:
 
239
            item = Nautilus.MenuItem(name='BzrNautilus::log',
 
240
                             label='History ...',
 
241
                             tip='List changes',
 
242
                             icon='')
 
243
            item.connect('activate', self.log_cb, tree.bzrdir, path)
 
244
            yield item
 
245
 
 
246
            if not intertree.file_content_matches(file_id, file_id):
 
247
                item = Nautilus.MenuItem(name='BzrNautilus::diff',
 
248
                                 label='View Changes ...',
 
249
                                 tip='Show differences',
 
250
                                 icon='')
 
251
                item.connect('activate', self.diff_cb, tree, path)
 
252
                yield item
 
253
 
 
254
                item = Nautilus.MenuItem(name='BzrNautilus::commit',
 
255
                             label='Commit ...',
 
256
                             tip='Commit Changes',
 
257
                             icon='')
 
258
                item.connect('activate', self.commit_cb, tree, path)
 
259
                yield item
 
260
 
 
261
            item = Nautilus.MenuItem(name='BzrNautilus::remove',
 
262
                                 label='Remove',
 
263
                                 tip='Remove this file from versioning',
 
264
                                 icon='')
 
265
            item.connect('activate', self.remove_cb, tree, path)
 
266
            yield item
 
267
 
 
268
            item = Nautilus.MenuItem(name='BzrNautilus::annotate',
 
269
                         label='Annotate ...',
 
270
                         tip='Annotate File Data',
 
271
                         icon='')
 
272
            item.connect('activate', self.annotate_cb, tree, path, file_id)
 
273
            yield item
 
274
 
215
275
    def get_file_items(self, window, files):
216
276
        items = []
217
 
 
218
 
        for vfs_file in files:
219
 
            controldir, path = self._open_bzrdir(vfs_file)
220
 
 
221
 
            try:
222
 
                tree = controldir.open_workingtree()
223
 
            except NoWorkingTree:
224
 
                continue
225
 
 
226
 
            nautilus_integration = self.check_branch_enabled(tree.branch)
227
 
            if not nautilus_integration:
228
 
                continue
229
 
 
230
 
            file_id = tree.path2id(path)
231
 
            if file_id is None:
232
 
                item = Nautilus.MenuItem(name='BzrNautilus::add',
233
 
                                     label='Add',
234
 
                                     tip='Add as versioned file',
235
 
                                     icon='')
236
 
                item.connect('activate', self.add_cb, tree, path)
237
 
                items.append(item)
238
 
 
239
 
                item = Nautilus.MenuItem(name='BzrNautilus::ignore',
240
 
                                     label='Ignore',
241
 
                                     tip='Ignore file for versioning',
242
 
                                     icon='')
243
 
                item.connect('activate', self.ignore_cb, tree, path)
244
 
                items.append(item)
245
 
            elif tree.is_ignored(path):
246
 
                item = Nautilus.MenuItem(name='BzrNautilus::unignore',
247
 
                                     label='Unignore',
248
 
                                     tip='Unignore file for versioning',
249
 
                                     icon='')
250
 
                item.connect('activate', self.unignore_cb, tree, path)
251
 
                items.append(item)
252
 
            else:
253
 
                item = Nautilus.MenuItem(name='BzrNautilus::log',
254
 
                                 label='History ...',
255
 
                                 tip='List changes',
256
 
                                 icon='')
257
 
                item.connect('activate', self.log_cb, controldir, path)
258
 
                items.append(item)
 
277
        trees = {}
 
278
 
 
279
        try:
 
280
            for vfs_file in files:
 
281
                controldir, path = self._open_bzrdir(vfs_file)
 
282
 
 
283
                try:
 
284
                    tree = trees[controldir.user_url]
 
285
                except KeyError:
 
286
                    try:
 
287
                        tree = controldir.open_workingtree()
 
288
                    except NoWorkingTree:
 
289
                        continue
 
290
                    trees[controldir.user_url] = tree
 
291
                    tree.lock_read()
 
292
 
 
293
                nautilus_integration = self.check_branch_enabled(tree.branch)
 
294
                if not nautilus_integration:
 
295
                    continue
259
296
 
260
297
                intertree = InterTree.get(tree.basis_tree(), tree)
261
 
                if not intertree.file_content_matches(file_id, file_id):
262
 
                    item = Nautilus.MenuItem(name='BzrNautilus::diff',
263
 
                                     label='View Changes ...',
264
 
                                     tip='Show differences',
265
 
                                     icon='')
266
 
                    item.connect('activate', self.diff_cb, tree, path)
267
 
                    items.append(item)
268
 
 
269
 
                    item = Nautilus.MenuItem(name='BzrNautilus::commit',
270
 
                                 label='Commit ...',
271
 
                                 tip='Commit Changes',
272
 
                                 icon='')
273
 
                    item.connect('activate', self.commit_cb, tree, path)
274
 
                    items.append(item)
275
 
 
276
 
                item = Nautilus.MenuItem(name='BzrNautilus::remove',
277
 
                                     label='Remove',
278
 
                                     tip='Remove this file from versioning',
279
 
                                     icon='')
280
 
                item.connect('activate', self.remove_cb, tree, path)
281
 
                items.append(item)
282
 
 
283
 
                item = Nautilus.MenuItem(name='BzrNautilus::annotate',
284
 
                             label='Annotate ...',
285
 
                             tip='Annotate File Data',
286
 
                             icon='')
287
 
                item.connect('activate', self.annotate_cb, tree, path, file_id)
288
 
                items.append(item)
 
298
                items.extend(list(self._get_file_menuitems(tree, intertree, path)))
 
299
        finally:
 
300
            for tree in trees.itervalues():
 
301
                tree.unlock()
 
302
 
289
303
        return items
290
304
 
291
305
    def get_columns(self):
391
405
 
392
406
            tree.lock_read()
393
407
            try:
394
 
                property_label = Gtk.Label('Version Control')
395
 
                property_label.show()
396
 
 
397
408
                file_id = tree.path2id(path)
398
 
 
399
 
                table = Gtk.Table(homogeneous=False, columns=2, rows=2)
400
 
 
401
 
                table.attach(Gtk.Label('File id:'), 0, 1, 0, 1)
402
 
                table.attach(Gtk.Label(file_id), 1, 2, 0, 1)
403
 
 
404
 
                table.attach(Gtk.Label('SHA1Sum:'), 0, 1, 1, 2)
405
 
                table.attach(Gtk.Label(tree.get_file_sha1(file_id, path)), 1, 1, 1, 2)
406
 
 
407
 
                table.show_all()
408
 
                pages.append(Nautilus.PropertyPage(name="BzrNautilus::version_info",
409
 
                             label=property_label, page=table))
 
409
                pages.append(PropertyPageFile(tree, file_id, path))
 
410
                pages.append(PropertyPageBranch(tree.branch))
410
411
            finally:
411
412
                tree.unlock()
412
413
        return pages
 
414
 
 
415
 
 
416
class PropertyPageFile(Nautilus.PropertyPage):
 
417
 
 
418
    def __init__(self, tree, file_id, path):
 
419
        self.tree = tree
 
420
        self.file_id = file_id
 
421
        self.path = path
 
422
        label = Gtk.Label('File Version')
 
423
        label.show()
 
424
 
 
425
        table = self._create_table()
 
426
 
 
427
        super(PropertyPageFile, self).__init__(label=label,
 
428
            name="BzrNautilus::file_page", page=table)
 
429
 
 
430
    def _create_table(self):
 
431
        table = Gtk.Table(homogeneous=False, columns=2, rows=3)
 
432
 
 
433
        table.attach(Gtk.Label('File id:'), 0, 1, 0, 1)
 
434
        table.attach(Gtk.Label(self.file_id), 1, 2, 0, 1)
 
435
 
 
436
        table.attach(Gtk.Label('SHA1Sum:'), 0, 1, 1, 2)
 
437
        table.attach(Gtk.Label(self.tree.get_file_sha1(self.file_id, self.path)), 1, 1, 1, 2)
 
438
 
 
439
        basis_tree = self.tree.revision_tree(self.tree.last_revision())
 
440
        last_revision = basis_tree.get_file_revision(self.file_id)
 
441
 
 
442
        table.attach(Gtk.Label('Last Change Revision:'), 0, 1, 2, 3)
 
443
        revno = ".".join([str(x) for x in
 
444
            self.tree.branch.revision_id_to_dotted_revno(last_revision)])
 
445
        table.attach(Gtk.Label(revno), 1, 1, 2, 3)
 
446
 
 
447
        table.attach(Gtk.Label('Last Change Author:'), 0, 1, 3, 4)
 
448
        rev = self.tree.branch.repository.get_revision(last_revision)
 
449
        table.attach(Gtk.Label("\n".join(rev.get_apparent_authors())), 1, 1, 3, 4)
 
450
 
 
451
        table.show_all()
 
452
        return table
 
453
 
 
454
 
 
455
class PropertyPageBranch(Nautilus.PropertyPage):
 
456
 
 
457
    def __init__(self, branch):
 
458
        self.branch = branch
 
459
        label = Gtk.Label('Branch')
 
460
        label.show()
 
461
 
 
462
        table = self._create_table()
 
463
 
 
464
        super(PropertyPageBranch, self).__init__(label=label,
 
465
            name="BzrNautilus::branch_page", page=table)
 
466
 
 
467
    def _create_table(self):
 
468
        table = Gtk.Table(homogeneous=False, columns=2, rows=3)
 
469
 
 
470
        table.attach(Gtk.Label('Push location:'), 0, 1, 0, 1)
 
471
        table.attach(Gtk.Label(self.branch.get_push_location()), 1, 2, 0, 1)
 
472
 
 
473
        table.attach(Gtk.Label('Parent location:'), 0, 1, 1, 2)
 
474
        table.attach(Gtk.Label(self.branch.get_parent()), 1, 1, 1, 2)
 
475
 
 
476
        table.show_all()
 
477
        return table