/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
164 by Jelmer Vernooij
Add copyright information.
1
# Trivial Bazaar plugin for Nautilus
2
#
3
# Copyright (C) 2006 Jeff Bailey
4
# Copyright (C) 2006 Wouter van Heyst
751 by Jelmer Vernooij
Update installation instructions.
5
# Copyright (C) 2006-2011 Jelmer Vernooij <jelmer@samba.org>
6
#
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21
# Installation:
22
# setup.py can install nautilus-bzr to the right system folder, if pkg-config
23
# is present.
24
#
25
# You can also install nautilus-bzr manually by copying it (or linking it from)
26
# ~/.local/share/nautilus-python/extensions/nautilus-bzr.py
164 by Jelmer Vernooij
Add copyright information.
27
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
28
from gi.repository import Gtk, Nautilus, GObject
29
from bzrlib.controldir import ControlDir
724 by Jelmer Vernooij
Fix formatting, imports.
30
from bzrlib.errors import (
31
    NotBranchError,
32
    NoWorkingTree,
33
    )
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
34
from bzrlib.tree import InterTree
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
35
from bzrlib.workingtree import WorkingTree
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
36
0.7.1 by Wouter van Heyst
use the bzrlib method of loading plugins, takes care of ~/.bazaar/plugins
37
from bzrlib.plugin import load_plugins
38
load_plugins()
39
576.2.1 by Jelmer Vernooij
Use ... notation for options that lead to dialogs, fix some nautilus-bzr menu items that had regressed.
40
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
41
class BazaarExtension(Nautilus.MenuProvider, Nautilus.ColumnProvider,
42
        Nautilus.InfoProvider, Nautilus.PropertyPageProvider, GObject.GObject):
43
    """Nautilus extension providing Bazaar integration."""
724 by Jelmer Vernooij
Fix formatting, imports.
44
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
45
    def __init__(self):
46
        pass
47
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
48
    @classmethod
49
    def _open_bzrdir(cls, vfs_file):
50
        uri = vfs_file.get_uri()
51
        controldir, path = ControlDir.open_containing(uri)
52
        return controldir, path
53
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
54
    def add_cb(self, menu, vfs_file):
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
55
        controldir, path = self._open_bzrdir(vfs_file)
56
        tree = controldir.open_workingtree()
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
57
        tree.add(path)
58
59
    def ignore_cb(self, menu, vfs_file):
60
        # We can only cope with local files
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
61
        controldir, path = self._open_bzrdir(vfs_file)
62
        tree = controldir.open_workingtree()
63
        #FIXME: Add path to ignore file
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
64
        return
65
66
    def unignore_cb(self, menu, vfs_file):
67
        # We can only cope with local files
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
68
        controldir, path = self._open_bzrdir(vfs_file)
69
        tree = controldir.open_workingtree()
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
70
        #FIXME
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
71
        return
72
73
    def diff_cb(self, menu, vfs_file):
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
74
        controldir, path = self._open_bzrdir(vfs_file)
75
        tree = controldir.open_workingtree()
419 by Szilveszter Farkas
Applied nautilus-bzr patches by Toshio Kuratomi.
76
        from bzrlib.plugins.gtk.diff import DiffWindow
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
77
        window = DiffWindow()
630 by Jelmer Vernooij
Use _get_nick(local=True) rather than .nick to get at a branches' nick, since
78
        window.set_diff(tree.branch._get_nick(local=True), tree, 
79
                        tree.branch.basis_tree())
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
80
        window.show()
81
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
82
        return
83
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
84
    def newtree_cb(self, menu, vfs_file):
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
85
        controldir, path = self._open_bzrdir(vfs_file)
86
        controldir.create_workingtree()
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
87
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
88
    def remove_cb(self, menu, vfs_file):
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
89
        controldir, path = self._open_bzrdir(vfs_file)
90
        tree = controldir.open_workingtree()
0.5.6 by jbailey at ubuntu
Implement remove
91
        tree.remove(path)
92
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
93
    def annotate_cb(self, menu, vfs_file):
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
94
        from bzrlib.plugins.gtk.annotate.gannotate import GAnnotateWindow
95
        controldir, path = self._open_bzrdir(vfs_file)
96
        win = GAnnotateWindow()
97
        win.annotate(controldir.open_workingtree(), controldir.open_branch(), path)
98
        Gtk.main()
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
99
100
    def clone_cb(self, menu, vfs_file=None):
142 by Jelmer Vernooij
Move some files to the top-level directory, add first test.
101
        from bzrlib.plugins.gtk.branch import BranchDialog
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
102
        controldir, path = self._open_bzrdir(vfs_file)
103
90 by Jelmer Vernooij
Use Olive's clone dialog in nautilus-bzr; remove the old Clone dialog
104
        dialog = BranchDialog(vfs_file.get_name())
419 by Szilveszter Farkas
Applied nautilus-bzr patches by Toshio Kuratomi.
105
        response = dialog.run()
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
106
        if response != Gtk.ResponseType.NONE:
419 by Szilveszter Farkas
Applied nautilus-bzr patches by Toshio Kuratomi.
107
            dialog.hide()
108
            dialog.destroy()
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
109
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
110
    def commit_cb(self, menu, vfs_file=None):
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
111
        controldir, path = self._open_bzrdir(vfs_file)
112
        tree = controldir.open_workingtree()
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
113
142 by Jelmer Vernooij
Move some files to the top-level directory, add first test.
114
        from bzrlib.plugins.gtk.commit import CommitDialog
423.13.4 by Jelmer Vernooij
Fix commit dialog from nautilus.
115
        dialog = CommitDialog(tree, path)
419 by Szilveszter Farkas
Applied nautilus-bzr patches by Toshio Kuratomi.
116
        response = dialog.run()
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
117
        if response != Gtk.ResponseType.NONE:
419 by Szilveszter Farkas
Applied nautilus-bzr patches by Toshio Kuratomi.
118
            dialog.hide()
119
            dialog.destroy()
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
120
0.5.12 by Jelmer Vernooij
Rename "Visualise Bazaar Branch" to "Log", which is a term
121
    def log_cb(self, menu, vfs_file):
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
122
        controldir, path = self._open_bzrdir(vfs_file)
123
        branch = controldir.open_branch()
576.2.1 by Jelmer Vernooij
Use ... notation for options that lead to dialogs, fix some nautilus-bzr menu items that had regressed.
124
        pp = start_viz_window(branch, [branch.last_revision()])
125
        pp.show()
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
126
        Gtk.main()
0.5.8 by jbailey at ubuntu
Add bzrk plugin
127
91.1.4 by Jelmer Vernooij
List pull and merge in nautilus-bzr.
128
    def pull_cb(self, menu, vfs_file):
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
129
        controldir, path = self._open_bzrdir(vfs_file)
130
        tree = controldir.open_workingtree()
142 by Jelmer Vernooij
Move some files to the top-level directory, add first test.
131
        from bzrlib.plugins.gtk.pull import PullDialog
91.1.4 by Jelmer Vernooij
List pull and merge in nautilus-bzr.
132
        dialog = PullDialog(tree, path)
133
        dialog.display()
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
134
        Gtk.main()
91.1.4 by Jelmer Vernooij
List pull and merge in nautilus-bzr.
135
136
    def merge_cb(self, menu, vfs_file):
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
137
        controldir, path = self._open_bzrdir(vfs_file)
138
        tree = controldir.open_workingtree()
142 by Jelmer Vernooij
Move some files to the top-level directory, add first test.
139
        from bzrlib.plugins.gtk.merge import MergeDialog
91.1.4 by Jelmer Vernooij
List pull and merge in nautilus-bzr.
140
        dialog = MergeDialog(tree, path)
576.2.1 by Jelmer Vernooij
Use ... notation for options that lead to dialogs, fix some nautilus-bzr menu items that had regressed.
141
        dialog.run()
578 by Jelmer Vernooij
Merge nautilus improvements.
142
        dialog.destroy()
91.1.4 by Jelmer Vernooij
List pull and merge in nautilus-bzr.
143
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
144
    def get_background_items(self, window, vfs_file):
145
        try:
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
146
            controldir, path = self._open_bzrdir(vfs_file)
147
        except NotBranchError:
419 by Szilveszter Farkas
Applied nautilus-bzr patches by Toshio Kuratomi.
148
            return
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
149
        try:
150
            branch = controldir.open_branch()
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
151
        except NotBranchError:
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
152
            items = []
153
            item = Nautilus.MenuItem('BzrNautilus::newtree',
91 by Jelmer Vernooij
Some update to TODO.
154
                                 'Make directory versioned',
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
155
                                 'Create new Bazaar tree in this folder')
156
            item.connect('activate', self.newtree_cb, vfs_file)
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
157
            items.append(item)
158
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
159
            item = Nautilus.MenuItem('BzrNautilus::clone',
576.2.1 by Jelmer Vernooij
Use ... notation for options that lead to dialogs, fix some nautilus-bzr menu items that had regressed.
160
                                 'Checkout Bazaar branch ...',
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
161
                                 'Checkout Existing Bazaar Branch')
162
            item.connect('activate', self.clone_cb, vfs_file)
163
            items.append(item)
164
            return items
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
165
166
        items = []
167
168
        nautilus_integration = self.check_branch_enabled(branch)
169
        if not nautilus_integration:
170
            item = Nautilus.MenuItem('BzrNautilus::enable',
459 by Martin Albisetti
Change nautilus enable/disable to per branch basis
171
                                     'Enable Bazaar Plugin for this Branch',
172
                                     'Enable Bazaar plugin for nautilus')
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
173
            item.connect('activate', self.toggle_integration, True, vfs_file)
174
            return [item]
459 by Martin Albisetti
Change nautilus enable/disable to per branch basis
175
        else:
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
176
            item = Nautilus.MenuItem('BzrNautilus::disable',
177
                                     'Disable Bazaar Plugin this Branch',
178
                                     'Disable Bazaar plugin for nautilus')
179
            item.connect('activate', self.toggle_integration, False, vfs_file)
459 by Martin Albisetti
Change nautilus enable/disable to per branch basis
180
            items.append(item)
0.5.8 by jbailey at ubuntu
Add bzrk plugin
181
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
182
        item = Nautilus.MenuItem('BzrNautilus::log',
576.2.1 by Jelmer Vernooij
Use ... notation for options that lead to dialogs, fix some nautilus-bzr menu items that had regressed.
183
                             'History ...',
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
184
                             'Show Bazaar history')
185
        item.connect('activate', self.log_cb, vfs_file)
186
        items.append(item)
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
187
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
188
        item = Nautilus.MenuItem('BzrNautilus::pull',
576.2.1 by Jelmer Vernooij
Use ... notation for options that lead to dialogs, fix some nautilus-bzr menu items that had regressed.
189
                             'Pull ...',
91.1.4 by Jelmer Vernooij
List pull and merge in nautilus-bzr.
190
                             'Pull from another branch')
191
        item.connect('activate', self.pull_cb, vfs_file)
192
        items.append(item)
193
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
194
        try:
195
            tree = controldir.open_workingtree()
196
        except NoWorkingTree:
197
            item = Nautilus.MenuItem('BzrNautilus::create_tree',
198
                                 'Create working tree...',
199
                                 'Create a working tree for this branch')
200
            item.connect('activate', self.create_tree_cb, vfs_file)
201
            items.append(item)
202
        else:
203
            item = Nautilus.MenuItem('BzrNautilus::merge',
204
                                 'Merge ...',
205
                                 'Merge from another branch')
206
            item.connect('activate', self.merge_cb, vfs_file)
207
            items.append(item)
91.1.4 by Jelmer Vernooij
List pull and merge in nautilus-bzr.
208
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
209
            item = Nautilus.MenuItem('BzrNautilus::commit',
210
                                 'Commit ...',
211
                                 'Commit Changes')
212
            item.connect('activate', self.commit_cb, vfs_file)
213
            items.append(item)
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
214
215
        return items
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
216
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
217
    def get_file_items(self, window, files):
218
        items = []
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
219
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
220
        for vfs_file in files:
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
221
            controldir, path = self._open_bzrdir(vfs_file)
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
222
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
223
            try:
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
224
                tree = controldir.open_workingtree()
423.13.2 by Jelmer Vernooij
Fix handling of NoWorkingTree exception in a couple more places.
225
            except NoWorkingTree:
226
                continue
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
227
228
            nautilus_integration = self.check_branch_enabled(tree.branch)
229
            if not nautilus_integration:
230
                continue
231
232
            file_id = tree.path2id(path)
233
            if file_id is None:
234
                item = Nautilus.MenuItem('BzrNautilus::add',
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
235
                                     'Add',
236
                                     'Add as versioned file')
237
                item.connect('activate', self.add_cb, vfs_file)
238
                items.append(item)
239
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
240
                item = Nautilus.MenuItem('BzrNautilus::ignore',
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
241
                                     'Ignore',
242
                                     'Ignore file for versioning')
243
                item.connect('activate', self.ignore_cb, vfs_file)
244
                items.append(item)
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
245
            elif tree.is_ignored(path):
246
                item = Nautilus.MenuItem('BzrNautilus::unignore',
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
247
                                     'Unignore',
248
                                     'Unignore file for versioning')
249
                item.connect('activate', self.unignore_cb, vfs_file)
250
                items.append(item)
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
251
            else:
252
                item = Nautilus.MenuItem('BzrNautilus::log',
576.2.1 by Jelmer Vernooij
Use ... notation for options that lead to dialogs, fix some nautilus-bzr menu items that had regressed.
253
                                 'History ...',
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
254
                                 'List changes')
255
                item.connect('activate', self.log_cb, vfs_file)
256
                items.append(item)
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
257
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
258
                intertree = InterTree.get(tree.basis_tree(), tree)
259
                if not intertree.file_content_matches(file_id, file_id):
260
                    item = Nautilus.MenuItem('BzrNautilus::diff',
261
                                     'View Changes ...',
262
                                     'Show differences')
263
                    item.connect('activate', self.diff_cb, vfs_file)
264
                    items.append(item)
265
266
                    item = Nautilus.MenuItem('BzrNautilus::commit',
267
                                 'Commit ...',
268
                                 'Commit Changes')
269
                    item.connect('activate', self.commit_cb, vfs_file)
270
                    items.append(item)
271
272
                item = Nautilus.MenuItem('BzrNautilus::remove',
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
273
                                     'Remove',
274
                                     'Remove this file from versioning')
275
                item.connect('activate', self.remove_cb, vfs_file)
276
                items.append(item)
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
277
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
278
                item = Nautilus.MenuItem('BzrNautilus::annotate',
576.2.1 by Jelmer Vernooij
Use ... notation for options that lead to dialogs, fix some nautilus-bzr menu items that had regressed.
279
                             'Annotate ...',
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
280
                             'Annotate File Data')
281
                item.connect('activate', self.annotate_cb, vfs_file)
282
                items.append(item)
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
283
        return items
88 by Jelmer Vernooij
Show column with file status.
284
285
    def get_columns(self):
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
286
        return [
287
            Nautilus.Column(name="BzrNautilus::bzr_status",
288
                            attribute="bzr_status",
289
                            label="Status",
290
                            description="Version control status"),
291
            Nautilus.Column(name="BzrNautilus::bzr_revision",
292
                            attribute="bzr_revision",
293
                            label="Revision",
294
                            description="Last change revision"),
295
            ]
88 by Jelmer Vernooij
Show column with file status.
296
297
    def update_file_info(self, file):
454 by Martin Albisetti
Add the logic to enable/disable the plugin
298
88 by Jelmer Vernooij
Show column with file status.
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
423.13.1 by Jelmer Vernooij
Fix handling of NoWorkingTree error.
306
        except NoWorkingTree:
459 by Martin Albisetti
Change nautilus enable/disable to per branch basis
307
            return   
308
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
309
        nautilus_integration = self.check_branch_enabled(tree.branch)
310
        if not nautilus_integration:
423.13.1 by Jelmer Vernooij
Fix handling of NoWorkingTree error.
311
            return
88 by Jelmer Vernooij
Show column with file status.
312
313
        emblem = None
314
        status = None
315
658.1.1 by Lucas Shrewsbury
Fix #294632 by adding ignored emblem and correct status.
316
        id = tree.path2id(path)
317
        if id == None:
318
            if tree.is_ignored(path):
319
                status = 'ignored'
320
                emblem = 'bzr-ignored'
321
            else:
322
                status = 'unversioned'
323
                        
324
        elif tree.has_filename(path):
423.13.5 by Jelmer Vernooij
Change emblems to the new emblems submitted by Martin.
325
            emblem = 'bzr-controlled'
88 by Jelmer Vernooij
Show column with file status.
326
            status = 'unchanged'
327
328
            delta = tree.changes_from(tree.branch.basis_tree())
329
            if delta.touches_file_id(id):
423.13.5 by Jelmer Vernooij
Change emblems to the new emblems submitted by Martin.
330
                emblem = 'bzr-modified'
88 by Jelmer Vernooij
Show column with file status.
331
                status = 'modified'
332
            for f, _, _ in delta.added:
333
                if f == path:
423.13.5 by Jelmer Vernooij
Change emblems to the new emblems submitted by Martin.
334
                    emblem = 'bzr-added'
88 by Jelmer Vernooij
Show column with file status.
335
                    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):
423.13.5 by Jelmer Vernooij
Change emblems to the new emblems submitted by Martin.
342
            emblem = 'bzr-removed'
88 by Jelmer Vernooij
Show column with file status.
343
            status = 'removed'
344
        else:
345
            # FIXME: Check for ignored files
346
            status = 'unversioned'
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
347
88 by Jelmer Vernooij
Show column with file status.
348
        if emblem is not None:
349
            file.add_emblem(emblem)
350
        file.add_string_attribute('bzr_status', status)
454 by Martin Albisetti
Add the logic to enable/disable the plugin
351
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
352
    def check_branch_enabled(self, branch):
459 by Martin Albisetti
Change nautilus enable/disable to per branch basis
353
        # Supports global disable, but there is currently no UI to do this
752 by Jelmer Vernooij
Initial work on fixing nautilus-bzr.
354
        config = branch.get_config_stack()
355
        return config.get("nautilus_integration")
356
357
    def toggle_integration(self, menu, action, vfs_file):
358
        controldir = self._open_bzrdir(vfs_file)
359
        branch = controldir.open_branch()
360
        config = branch.get_config_stack()
361
        config.set("nautilus_integration", action)