/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
5
# Copyright (C) 2006 Jelmer Vernooij
6
#
7
# Published under the GNU GPL
8
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
9
import nautilus
10
import bzrlib
11
from bzrlib.bzrdir import BzrDir
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
12
from bzrlib.errors import NotBranchError
13
from bzrlib.workingtree import WorkingTree
88 by Jelmer Vernooij
Show column with file status.
14
from bzrlib.tree import file_status
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
15
0.7.1 by Wouter van Heyst
use the bzrlib method of loading plugins, takes care of ~/.bazaar/plugins
16
from bzrlib.plugin import load_plugins
17
load_plugins()
18
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
19
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
20
88 by Jelmer Vernooij
Show column with file status.
21
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
22
    def __init__(self):
23
        pass
24
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
25
    def add_cb(self, menu, vfs_file):
26
        # We can only cope with local files
27
        if vfs_file.get_uri_scheme() != 'file':
28
            return
29
30
        file = vfs_file.get_uri()
31
        try:
32
            tree, path = WorkingTree.open_containing(file)
33
        except NotBranchError:
34
            return
35
36
        tree.add(path)
37
38
        return
39
40
    def ignore_cb(self, menu, vfs_file):
41
        # We can only cope with local files
42
        if vfs_file.get_uri_scheme() != 'file':
43
            return
44
45
        file = vfs_file.get_uri()
46
        try:
47
            tree, path = WorkingTree.open_containing(file)
48
        except NotBranchError:
49
            return
50
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
51
        #FIXME
52
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
53
        return
54
55
    def unignore_cb(self, menu, vfs_file):
56
        # We can only cope with local files
57
        if vfs_file.get_uri_scheme() != 'file':
58
            return
59
60
        file = vfs_file.get_uri()
61
        try:
62
            tree, path = WorkingTree.open_containing(file)
63
        except NotBranchError:
64
            return
65
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
66
        #FIXME
67
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
68
        return
69
70
    def diff_cb(self, menu, vfs_file):
71
        # We can only cope with local files
72
        if vfs_file.get_uri_scheme() != 'file':
73
            return
74
75
        file = vfs_file.get_uri()
76
        try:
77
            tree, path = WorkingTree.open_containing(file)
78
        except NotBranchError:
79
            return
80
149 by Jelmer Vernooij
Move diff to top-level directory as well.
81
        from bzrlib.plugins.gtk.viz.diff import DiffWindow
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
82
        window = DiffWindow()
87 by Jelmer Vernooij
Fix diff window in nautilus.
83
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
84
        window.show()
85
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
86
        return
87
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
88
    def newtree_cb(self, menu, vfs_file):
89
        # We can only cope with local files
90
        if vfs_file.get_uri_scheme() != 'file':
91
            return
92
93
        file = vfs_file.get_uri()
94
95
        # We only want to continue here if we get a NotBranchError
96
        try:
97
            tree, path = WorkingTree.open_containing(file)
98
        except NotBranchError:
0.5.9 by jbailey at ubuntu
Implement repository creation
99
            BzrDir.create_branch_and_repo(file)
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
100
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
101
    def remove_cb(self, menu, vfs_file):
102
        # We can only cope with local files
103
        if vfs_file.get_uri_scheme() != 'file':
104
            return
105
106
        file = vfs_file.get_uri()
107
        try:
108
            tree, path = WorkingTree.open_containing(file)
109
        except NotBranchError:
110
            return
111
0.5.6 by jbailey at ubuntu
Implement remove
112
        tree.remove(path)
113
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
114
    def annotate_cb(self, menu, vfs_file):
115
        # We can only cope with local files
116
        if vfs_file.get_uri_scheme() != 'file':
117
            return
118
119
        file = vfs_file.get_uri()
120
121
        vis = cmd_gannotate()
122
        vis.run(file)
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
123
124
    def clone_cb(self, menu, vfs_file=None):
125
        # We can only cope with local files
126
        if vfs_file.get_uri_scheme() != 'file':
127
            return
128
142 by Jelmer Vernooij
Move some files to the top-level directory, add first test.
129
        from bzrlib.plugins.gtk.branch import BranchDialog
90 by Jelmer Vernooij
Use Olive's clone dialog in nautilus-bzr; remove the old Clone dialog
130
        
131
        dialog = BranchDialog(vfs_file.get_name())
132
        dialog.display()
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
133
 
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
134
    def commit_cb(self, menu, vfs_file=None):
135
        # We can only cope with local files
136
        if vfs_file.get_uri_scheme() != 'file':
137
            return
138
139
        file = vfs_file.get_uri()
140
        try:
141
            tree, path = WorkingTree.open_containing(file)
142
        except NotBranchError:
143
            return
144
142 by Jelmer Vernooij
Move some files to the top-level directory, add first test.
145
        from bzrlib.plugins.gtk.commit import CommitDialog
90 by Jelmer Vernooij
Use Olive's clone dialog in nautilus-bzr; remove the old Clone dialog
146
        dialog = CommitDialog(tree, path)
147
        dialog.display()
148
        gtk.main()
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
149
0.5.12 by Jelmer Vernooij
Rename "Visualise Bazaar Branch" to "Log", which is a term
150
    def log_cb(self, menu, vfs_file):
0.5.8 by jbailey at ubuntu
Add bzrk plugin
151
        # We can only cope with local files
152
        if vfs_file.get_uri_scheme() != 'file':
153
            return
154
155
        file = vfs_file.get_uri()
156
157
        # We only want to continue here if we get a NotBranchError
158
        try:
159
            tree, path = WorkingTree.open_containing(file)
160
        except NotBranchError:
161
            return
162
163
        vis = cmd_visualise()
164
        vis.run(file)
165
166
        return
167
91.1.4 by Jelmer Vernooij
List pull and merge in nautilus-bzr.
168
    def pull_cb(self, menu, vfs_file):
169
        # We can only cope with local files
170
        if vfs_file.get_uri_scheme() != 'file':
171
            return
172
173
        file = vfs_file.get_uri()
174
175
        # We only want to continue here if we get a NotBranchError
176
        try:
177
            tree, path = WorkingTree.open_containing(file)
178
        except NotBranchError:
179
            return
180
142 by Jelmer Vernooij
Move some files to the top-level directory, add first test.
181
        from bzrlib.plugins.gtk.pull import PullDialog
91.1.4 by Jelmer Vernooij
List pull and merge in nautilus-bzr.
182
        dialog = PullDialog(tree, path)
183
        dialog.display()
184
        gtk.main()
185
186
    def merge_cb(self, menu, vfs_file):
187
        # We can only cope with local files
188
        if vfs_file.get_uri_scheme() != 'file':
189
            return
190
191
        file = vfs_file.get_uri()
192
193
        # We only want to continue here if we get a NotBranchError
194
        try:
195
            tree, path = WorkingTree.open_containing(file)
196
        except NotBranchError:
197
            return
198
142 by Jelmer Vernooij
Move some files to the top-level directory, add first test.
199
        from bzrlib.plugins.gtk.merge import MergeDialog
91.1.4 by Jelmer Vernooij
List pull and merge in nautilus-bzr.
200
        dialog = MergeDialog(tree, path)
201
        dialog.display()
202
        gtk.main()
203
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
204
    def get_background_items(self, window, vfs_file):
90 by Jelmer Vernooij
Use Olive's clone dialog in nautilus-bzr; remove the old Clone dialog
205
        items = []
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
206
        file = vfs_file.get_uri()
207
        try:
208
            tree, path = WorkingTree.open_containing(file)
209
        except NotBranchError:
210
            item = nautilus.MenuItem('BzrNautilus::newtree',
91 by Jelmer Vernooij
Some update to TODO.
211
                                 'Make directory versioned',
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
212
                                 'Create new Bazaar tree in this folder')
213
            item.connect('activate', self.newtree_cb, vfs_file)
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
214
            items.append(item)
215
216
            item = nautilus.MenuItem('BzrNautilus::clone',
91 by Jelmer Vernooij
Some update to TODO.
217
                                 'Checkout Bazaar branch',
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
218
                                 'Checkout Existing Bazaar Branch')
219
            item.connect('activate', self.clone_cb, vfs_file)
220
            items.append(item)
221
222
            return items
0.5.8 by jbailey at ubuntu
Add bzrk plugin
223
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
224
        item = nautilus.MenuItem('BzrNautilus::log',
225
                             'Log',
226
                             'Show Bazaar history')
227
        item.connect('activate', self.log_cb, vfs_file)
228
        items.append(item)
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
229
91.1.4 by Jelmer Vernooij
List pull and merge in nautilus-bzr.
230
        item = nautilus.MenuItem('BzrNautilus::pull',
231
                             'Pull',
232
                             'Pull from another branch')
233
        item.connect('activate', self.pull_cb, vfs_file)
234
        items.append(item)
235
236
        item = nautilus.MenuItem('BzrNautilus::merge',
237
                             'Merge',
238
                             'Merge from another branch')
239
        item.connect('activate', self.merge_cb, vfs_file)
240
        items.append(item)
241
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
242
        item = nautilus.MenuItem('BzrNautilus::commit',
243
                             'Commit',
244
                             'Commit Changes')
245
        item.connect('activate', self.commit_cb, vfs_file)
246
        items.append(item)
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
247
248
        return items
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
249
250
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
251
    def get_file_items(self, window, files):
252
        items = []
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
253
254
        for vfs_file in files:
255
            # We can only cope with local files
256
            if vfs_file.get_uri_scheme() != 'file':
257
                return
258
259
            file = vfs_file.get_uri()
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
260
            try:
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
261
                tree, path = WorkingTree.open_containing(file)
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
262
            except NotBranchError:
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
263
                if not vfs_file.is_directory():
264
                    return
265
                item = nautilus.MenuItem('BzrNautilus::newtree',
91 by Jelmer Vernooij
Some update to TODO.
266
                                     'Make directory versioned',
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
267
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
268
                item.connect('activate', self.newtree_cb, vfs_file)
269
                return item,
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
270
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
271
            file_class = tree.file_class(path)
272
273
            if file_class == '?':
274
                item = nautilus.MenuItem('BzrNautilus::add',
275
                                     'Add',
276
                                     'Add as versioned file')
277
                item.connect('activate', self.add_cb, vfs_file)
278
                items.append(item)
279
280
                item = nautilus.MenuItem('BzrNautilus::ignore',
281
                                     'Ignore',
282
                                     'Ignore file for versioning')
283
                item.connect('activate', self.ignore_cb, vfs_file)
284
                items.append(item)
285
            elif file_class == 'I':
286
                item = nautilus.MenuItem('BzrNautilus::unignore',
287
                                     'Unignore',
288
                                     'Unignore file for versioning')
289
                item.connect('activate', self.unignore_cb, vfs_file)
290
                items.append(item)
291
            elif file_class == 'V':
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
292
                item = nautilus.MenuItem('BzrNautilus::log',
293
                                 'Log',
294
                                 'List changes')
295
                item.connect('activate', self.log_cb, vfs_file)
296
                items.append(item)
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
297
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
298
                item = nautilus.MenuItem('BzrNautilus::diff',
299
                                 'Diff',
300
                                 'Show differences')
301
                item.connect('activate', self.diff_cb, vfs_file)
302
                items.append(item)
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
303
304
                item = nautilus.MenuItem('BzrNautilus::remove',
305
                                     'Remove',
306
                                     'Remove this file from versioning')
307
                item.connect('activate', self.remove_cb, vfs_file)
308
                items.append(item)
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
309
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
310
                item = nautilus.MenuItem('BzrNautilus::annotate',
311
                             'Annotate',
312
                             'Annotate File Data')
313
                item.connect('activate', self.annotate_cb, vfs_file)
314
                items.append(item)
315
316
                item = nautilus.MenuItem('BzrNautilus::commit',
317
                             'Commit',
318
                             'Commit Changes')
319
                item.connect('activate', self.commit_cb, vfs_file)
320
                items.append(item)
321
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
322
        return items
88 by Jelmer Vernooij
Show column with file status.
323
324
    def get_columns(self):
325
        return nautilus.Column("BzrNautilus::bzr_status",
326
                               "bzr_status",
327
                               "Bzr Status",
328
                               "Version control status"),
329
330
    def update_file_info(self, file):
331
        if file.get_uri_scheme() != 'file':
332
            return
333
        
334
        try:
335
            tree, path = WorkingTree.open_containing(file.get_uri())
336
        except NotBranchError:
337
            return
338
339
        emblem = None
340
        status = None
341
342
        if tree.has_filename(path):
343
            emblem = 'cvs-controlled'
344
            status = 'unchanged'
345
            id = tree.path2id(path)
346
347
            delta = tree.changes_from(tree.branch.basis_tree())
348
            if delta.touches_file_id(id):
349
                emblem = 'cvs-modified'
350
                status = 'modified'
351
            for f, _, _ in delta.added:
352
                if f == path:
353
                    emblem = 'cvs-added'
354
                    status = 'added'
355
356
            for of, f, _, _, _, _ in delta.renamed:
357
                if f == path:
358
                    status = 'renamed from %s' % f
359
360
        elif tree.branch.basis_tree().has_filename(path):
361
            emblem = 'cvs-removed'
362
            status = 'removed'
363
        else:
364
            # FIXME: Check for ignored files
365
            status = 'unversioned'
366
        
367
        if emblem is not None:
368
            file.add_emblem(emblem)
369
        file.add_string_attribute('bzr_status', status)