/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-17 21:40:43 UTC
  • Revision ID: jelmer@samba.org-20111117214043-r95es6pf8tnisbwa
Fix columns.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
# You can also install nautilus-bzr manually by copying it (or linking it from)
26
26
# ~/.local/share/nautilus-python/extensions/nautilus-bzr.py
27
27
 
28
 
from gi.repository import Gtk, Nautilus, GObject
 
28
from gi.repository import Gtk, GObject, Nautilus
29
29
from bzrlib.controldir import ControlDir
30
30
from bzrlib.errors import (
31
31
    NotBranchError,
61
61
        controldir, path = self._open_bzrdir(vfs_file)
62
62
        tree = controldir.open_workingtree()
63
63
        #FIXME: Add path to ignore file
64
 
        return
65
64
 
66
65
    def unignore_cb(self, menu, vfs_file):
67
66
        # We can only cope with local files
68
67
        controldir, path = self._open_bzrdir(vfs_file)
69
68
        tree = controldir.open_workingtree()
70
69
        #FIXME
71
 
        return
72
70
 
73
71
    def diff_cb(self, menu, vfs_file):
74
72
        controldir, path = self._open_bzrdir(vfs_file)
119
117
            dialog.destroy()
120
118
 
121
119
    def log_cb(self, menu, vfs_file):
 
120
        from bzrlib.plugins.gtk.viz import BranchWindow
122
121
        controldir, path = self._open_bzrdir(vfs_file)
123
122
        branch = controldir.open_branch()
124
 
        pp = start_viz_window(branch, [branch.last_revision()])
 
123
        pp = BranchWindow(branch, [branch.last_revision()])
125
124
        pp.show()
126
125
        Gtk.main()
127
126
 
294
293
                            description="Last change revision"),
295
294
            ]
296
295
 
297
 
    def update_file_info(self, file):
298
 
 
299
 
        if file.get_uri_scheme() != 'file':
300
 
            return
301
 
        
302
 
        try:
303
 
            tree, path = WorkingTree.open_containing(file.get_uri())
304
 
        except NotBranchError:
305
 
            return
306
 
        except NoWorkingTree:
307
 
            return   
308
 
 
309
 
        nautilus_integration = self.check_branch_enabled(tree.branch)
310
 
        if not nautilus_integration:
311
 
            return
312
 
 
 
296
    def _file_summary(self, tree, basis_tree, intertree, path):
 
297
        file_revision = ""
313
298
        emblem = None
314
 
        status = None
315
299
 
316
 
        id = tree.path2id(path)
317
 
        if id == None:
 
300
        file_id = tree.path2id(path)
 
301
        if file_id is None:
318
302
            if tree.is_ignored(path):
319
303
                status = 'ignored'
320
304
                emblem = 'bzr-ignored'
321
305
            else:
322
306
                status = 'unversioned'
323
 
                        
324
 
        elif tree.has_filename(path):
325
 
            emblem = 'bzr-controlled'
326
 
            status = 'unchanged'
327
 
 
328
 
            delta = tree.changes_from(tree.branch.basis_tree())
329
 
            if delta.touches_file_id(id):
330
 
                emblem = 'bzr-modified'
331
 
                status = 'modified'
332
 
            for f, _, _ in delta.added:
333
 
                if f == path:
 
307
            file_revision = "N/A"
 
308
        elif tree.has_filename(path): # Still present
 
309
            if not intertree.file_content_matches(file_id, file_id):
 
310
                if not basis_tree.has_id(file_id):
334
311
                    emblem = 'bzr-added'
335
312
                    status = 'added'
336
 
 
337
 
            for of, f, _, _, _, _ in delta.renamed:
338
 
                if f == path:
339
 
                    status = 'renamed from %s' % f
340
 
 
341
 
        elif tree.branch.basis_tree().has_filename(path):
 
313
                    file_revision = "new file"
 
314
                elif basis_tree.path2id(file_id) != path:
 
315
                    status = 'bzr-renamed'
 
316
                    status = 'renamed from %s' % basis_tree.path2id(file_id)
 
317
                else:
 
318
                    emblem = 'bzr-modified'
 
319
                    status = 'modified'
 
320
            else:
 
321
                emblem = 'bzr-controlled'
 
322
                status = 'unchanged'
 
323
        elif basis_tree.has_filename(path):
342
324
            emblem = 'bzr-removed'
343
325
            status = 'removed'
344
326
        else:
345
327
            # FIXME: Check for ignored files
346
328
            status = 'unversioned'
347
 
 
348
 
        if emblem is not None:
349
 
            file.add_emblem(emblem)
350
 
        file.add_string_attribute('bzr_status', status)
 
329
        return (status, emblem, file_revision)
 
330
 
 
331
    def update_file_info(self, vfs_file):
 
332
        try:
 
333
            controldir, path = self._open_bzrdir(vfs_file)
 
334
        except NotBranchError:
 
335
            return
 
336
 
 
337
        try:
 
338
            tree = controldir.open_workingtree()
 
339
        except NoWorkingTree:
 
340
            return
 
341
 
 
342
        tree.lock_read()
 
343
        try:
 
344
            nautilus_integration = self.check_branch_enabled(tree.branch)
 
345
            if not nautilus_integration:
 
346
                return
 
347
 
 
348
            basis_tree = tree.basis_tree()
 
349
            intertree = InterTree.get(basis_tree, tree)
 
350
 
 
351
            basis_tree.lock_read()
 
352
            try:
 
353
                (status, emblem, file_revision) = self._file_summary(tree, basis_tree, intertree, path)
 
354
            finally:
 
355
                basis_tree.unlock()
 
356
            if emblem is not None:
 
357
                vfs_file.add_emblem(emblem)
 
358
            vfs_file.add_string_attribute('bzr_status', status)
 
359
            vfs_file.add_string_attribute('bzr_revision', file_revision)
 
360
        finally:
 
361
            tree.unlock()
351
362
 
352
363
    def check_branch_enabled(self, branch):
353
364
        # Supports global disable, but there is currently no UI to do this