/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: Scott James Remnant
  • Date: 2005-10-17 01:07:49 UTC
  • Revision ID: scott@netsplit.com-20051017010749-15fa95fc2cf09289
Commit the first version of bzrk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
9
 
import gtk
10
 
import nautilus
11
 
import bzrlib
12
 
from bzrlib.bzrdir import BzrDir
13
 
from bzrlib.errors import NotBranchError
14
 
from bzrlib.errors import NoWorkingTree
15
 
from bzrlib.errors import UnsupportedProtocol
16
 
from bzrlib.workingtree import WorkingTree
17
 
from bzrlib.branch import Branch
18
 
from bzrlib.tree import file_status
19
 
 
20
 
from bzrlib.plugin import load_plugins
21
 
load_plugins()
22
 
 
23
 
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
24
 
 
25
 
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
26
 
    def __init__(self):
27
 
        pass
28
 
 
29
 
    def add_cb(self, menu, vfs_file):
30
 
        # We can only cope with local files
31
 
        if vfs_file.get_uri_scheme() != 'file':
32
 
            return
33
 
 
34
 
        file = vfs_file.get_uri()
35
 
        try:
36
 
            tree, path = WorkingTree.open_containing(file)
37
 
        except NotBranchError:
38
 
            return
39
 
 
40
 
        tree.add(path)
41
 
 
42
 
        return
43
 
 
44
 
    def ignore_cb(self, menu, vfs_file):
45
 
        # We can only cope with local files
46
 
        if vfs_file.get_uri_scheme() != 'file':
47
 
            return
48
 
 
49
 
        file = vfs_file.get_uri()
50
 
        try:
51
 
            tree, path = WorkingTree.open_containing(file)
52
 
        except NotBranchError:
53
 
            return
54
 
 
55
 
        #FIXME
56
 
 
57
 
        return
58
 
 
59
 
    def unignore_cb(self, menu, vfs_file):
60
 
        # We can only cope with local files
61
 
        if vfs_file.get_uri_scheme() != 'file':
62
 
            return
63
 
 
64
 
        file = vfs_file.get_uri()
65
 
        try:
66
 
            tree, path = WorkingTree.open_containing(file)
67
 
        except NotBranchError:
68
 
            return
69
 
 
70
 
        #FIXME
71
 
 
72
 
        return
73
 
 
74
 
    def diff_cb(self, menu, vfs_file):
75
 
        # We can only cope with local files
76
 
        if vfs_file.get_uri_scheme() != 'file':
77
 
            return
78
 
 
79
 
        file = vfs_file.get_uri()
80
 
        try:
81
 
            tree, path = WorkingTree.open_containing(file)
82
 
        except NotBranchError:
83
 
            return
84
 
 
85
 
        from bzrlib.plugins.gtk.diff import DiffWindow
86
 
        window = DiffWindow()
87
 
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
88
 
        window.show()
89
 
 
90
 
        return
91
 
 
92
 
    def newtree_cb(self, menu, vfs_file):
93
 
        # We can only cope with local files
94
 
        if vfs_file.get_uri_scheme() != 'file':
95
 
            return
96
 
 
97
 
        file = vfs_file.get_uri()
98
 
 
99
 
        # We only want to continue here if we get a NotBranchError
100
 
        try:
101
 
            tree, path = WorkingTree.open_containing(file)
102
 
        except NotBranchError:
103
 
            BzrDir.create_standalone_workingtree(file)
104
 
 
105
 
    def remove_cb(self, menu, vfs_file):
106
 
        # We can only cope with local files
107
 
        if vfs_file.get_uri_scheme() != 'file':
108
 
            return
109
 
 
110
 
        file = vfs_file.get_uri()
111
 
        try:
112
 
            tree, path = WorkingTree.open_containing(file)
113
 
        except NotBranchError:
114
 
            return
115
 
 
116
 
        tree.remove(path)
117
 
 
118
 
    def annotate_cb(self, menu, vfs_file):
119
 
        # We can only cope with local files
120
 
        if vfs_file.get_uri_scheme() != 'file':
121
 
            return
122
 
 
123
 
        file = vfs_file.get_uri()
124
 
 
125
 
        vis = cmd_gannotate()
126
 
        vis.run(file)
127
 
 
128
 
    def clone_cb(self, menu, vfs_file=None):
129
 
        # We can only cope with local files
130
 
        if vfs_file.get_uri_scheme() != 'file':
131
 
            return
132
 
 
133
 
        from bzrlib.plugins.gtk.branch import BranchDialog
134
 
        
135
 
        dialog = BranchDialog(vfs_file.get_name())
136
 
        response = dialog.run()
137
 
        if response != gtk.RESPONSE_NONE:
138
 
            dialog.hide()
139
 
            dialog.destroy()
140
 
 
141
 
    def commit_cb(self, menu, vfs_file=None):
142
 
        # We can only cope with local files
143
 
        if vfs_file.get_uri_scheme() != 'file':
144
 
            return
145
 
 
146
 
        file = vfs_file.get_uri()
147
 
        tree = None
148
 
        branch = None
149
 
        try:
150
 
            tree, path = WorkingTree.open_containing(file)
151
 
            branch = tree.branch
152
 
        except NotBranchError, e:
153
 
            path = e.path
154
 
            #return
155
 
        except NoWorkingTree, e:
156
 
            path = e.base
157
 
            try:
158
 
                (branch, path) = Branch.open_containing(path)
159
 
            except NotBranchError, e:
160
 
                path = e.path
161
 
 
162
 
        from bzrlib.plugins.gtk.commit import CommitDialog
163
 
        dialog = CommitDialog(tree, path, not branch)
164
 
        response = dialog.run()
165
 
        if response != gtk.RESPONSE_NONE:
166
 
            dialog.hide()
167
 
            dialog.destroy()
168
 
 
169
 
    def log_cb(self, menu, vfs_file):
170
 
        # We can only cope with local files
171
 
        if vfs_file.get_uri_scheme() != 'file':
172
 
            return
173
 
 
174
 
        file = vfs_file.get_uri()
175
 
 
176
 
        # We only want to continue here if we get a NotBranchError
177
 
        try:
178
 
            tree, path = WorkingTree.open_containing(file)
179
 
        except NotBranchError:
180
 
            return
181
 
 
182
 
        vis = cmd_visualise()
183
 
        vis.run(file)
184
 
 
185
 
        return
186
 
 
187
 
    def pull_cb(self, menu, vfs_file):
188
 
        # We can only cope with local files
189
 
        if vfs_file.get_uri_scheme() != 'file':
190
 
            return
191
 
 
192
 
        file = vfs_file.get_uri()
193
 
 
194
 
        # We only want to continue here if we get a NotBranchError
195
 
        try:
196
 
            tree, path = WorkingTree.open_containing(file)
197
 
        except NotBranchError:
198
 
            return
199
 
 
200
 
        from bzrlib.plugins.gtk.pull import PullDialog
201
 
        dialog = PullDialog(tree, path)
202
 
        dialog.display()
203
 
        gtk.main()
204
 
 
205
 
    def merge_cb(self, menu, vfs_file):
206
 
        # We can only cope with local files
207
 
        if vfs_file.get_uri_scheme() != 'file':
208
 
            return
209
 
 
210
 
        file = vfs_file.get_uri()
211
 
 
212
 
        # We only want to continue here if we get a NotBranchError
213
 
        try:
214
 
            tree, path = WorkingTree.open_containing(file)
215
 
        except NotBranchError:
216
 
            return
217
 
 
218
 
        from bzrlib.plugins.gtk.merge import MergeDialog
219
 
        dialog = MergeDialog(tree, path)
220
 
        dialog.display()
221
 
        gtk.main()
222
 
 
223
 
    def get_background_items(self, window, vfs_file):
224
 
        items = []
225
 
        file = vfs_file.get_uri()
226
 
        try:
227
 
            tree, path = WorkingTree.open_containing(file)
228
 
        except UnsupportedProtocol:
229
 
            return
230
 
        except NotBranchError:
231
 
            item = nautilus.MenuItem('BzrNautilus::newtree',
232
 
                                 'Make directory versioned',
233
 
                                 'Create new Bazaar tree in this folder')
234
 
            item.connect('activate', self.newtree_cb, vfs_file)
235
 
            items.append(item)
236
 
 
237
 
            item = nautilus.MenuItem('BzrNautilus::clone',
238
 
                                 'Checkout Bazaar branch',
239
 
                                 'Checkout Existing Bazaar Branch')
240
 
            item.connect('activate', self.clone_cb, vfs_file)
241
 
            items.append(item)
242
 
 
243
 
            return items
244
 
 
245
 
        item = nautilus.MenuItem('BzrNautilus::log',
246
 
                             'Log',
247
 
                             'Show Bazaar history')
248
 
        item.connect('activate', self.log_cb, vfs_file)
249
 
        items.append(item)
250
 
 
251
 
        item = nautilus.MenuItem('BzrNautilus::pull',
252
 
                             'Pull',
253
 
                             'Pull from another branch')
254
 
        item.connect('activate', self.pull_cb, vfs_file)
255
 
        items.append(item)
256
 
 
257
 
        item = nautilus.MenuItem('BzrNautilus::merge',
258
 
                             'Merge',
259
 
                             'Merge from another branch')
260
 
        item.connect('activate', self.merge_cb, vfs_file)
261
 
        items.append(item)
262
 
 
263
 
        item = nautilus.MenuItem('BzrNautilus::commit',
264
 
                             'Commit',
265
 
                             'Commit Changes')
266
 
        item.connect('activate', self.commit_cb, vfs_file)
267
 
        items.append(item)
268
 
 
269
 
        return items
270
 
 
271
 
 
272
 
    def get_file_items(self, window, files):
273
 
        items = []
274
 
 
275
 
        wtfiles = {}
276
 
        for vfs_file in files:
277
 
            # We can only cope with local files
278
 
            if vfs_file.get_uri_scheme() != 'file':
279
 
                return
280
 
 
281
 
            file = vfs_file.get_uri()
282
 
            try:
283
 
                tree, path = WorkingTree.open_containing(file)
284
 
            except NotBranchError:
285
 
                if not vfs_file.is_directory():
286
 
                    return
287
 
                item = nautilus.MenuItem('BzrNautilus::newtree',
288
 
                                     'Make directory versioned',
289
 
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
290
 
                item.connect('activate', self.newtree_cb, vfs_file)
291
 
                return item,
292
 
            # Refresh the list of filestatuses in the working tree
293
 
            if path not in wtfiles.keys():
294
 
                tree.lock_read()
295
 
                for rpath, file_class, kind, id, entry in tree.list_files():
296
 
                    wtfiles[rpath] = file_class
297
 
                tree.unlock()
298
 
                wtfiles[u''] = 'V'
299
 
 
300
 
            if wtfiles[path] == '?':
301
 
                item = nautilus.MenuItem('BzrNautilus::add',
302
 
                                     'Add',
303
 
                                     'Add as versioned file')
304
 
                item.connect('activate', self.add_cb, vfs_file)
305
 
                items.append(item)
306
 
 
307
 
                item = nautilus.MenuItem('BzrNautilus::ignore',
308
 
                                     'Ignore',
309
 
                                     'Ignore file for versioning')
310
 
                item.connect('activate', self.ignore_cb, vfs_file)
311
 
                items.append(item)
312
 
            elif wtfiles[path] == 'I':
313
 
                item = nautilus.MenuItem('BzrNautilus::unignore',
314
 
                                     'Unignore',
315
 
                                     'Unignore file for versioning')
316
 
                item.connect('activate', self.unignore_cb, vfs_file)
317
 
                items.append(item)
318
 
            elif wtfiles[path] == 'V':
319
 
                item = nautilus.MenuItem('BzrNautilus::log',
320
 
                                 'Log',
321
 
                                 'List changes')
322
 
                item.connect('activate', self.log_cb, vfs_file)
323
 
                items.append(item)
324
 
 
325
 
                item = nautilus.MenuItem('BzrNautilus::diff',
326
 
                                 'Diff',
327
 
                                 'Show differences')
328
 
                item.connect('activate', self.diff_cb, vfs_file)
329
 
                items.append(item)
330
 
 
331
 
                item = nautilus.MenuItem('BzrNautilus::remove',
332
 
                                     'Remove',
333
 
                                     'Remove this file from versioning')
334
 
                item.connect('activate', self.remove_cb, vfs_file)
335
 
                items.append(item)
336
 
 
337
 
                item = nautilus.MenuItem('BzrNautilus::annotate',
338
 
                             'Annotate',
339
 
                             'Annotate File Data')
340
 
                item.connect('activate', self.annotate_cb, vfs_file)
341
 
                items.append(item)
342
 
 
343
 
                item = nautilus.MenuItem('BzrNautilus::commit',
344
 
                             'Commit',
345
 
                             'Commit Changes')
346
 
                item.connect('activate', self.commit_cb, vfs_file)
347
 
                items.append(item)
348
 
 
349
 
        return items
350
 
 
351
 
    def get_columns(self):
352
 
        return nautilus.Column("BzrNautilus::bzr_status",
353
 
                               "bzr_status",
354
 
                               "Bzr Status",
355
 
                               "Version control status"),
356
 
 
357
 
    def update_file_info(self, file):
358
 
        if file.get_uri_scheme() != 'file':
359
 
            return
360
 
        
361
 
        try:
362
 
            tree, path = WorkingTree.open_containing(file.get_uri())
363
 
        except NotBranchError:
364
 
            return
365
 
 
366
 
        emblem = None
367
 
        status = None
368
 
 
369
 
        if tree.has_filename(path):
370
 
            emblem = 'cvs-controlled'
371
 
            status = 'unchanged'
372
 
            id = tree.path2id(path)
373
 
 
374
 
            delta = tree.changes_from(tree.branch.basis_tree())
375
 
            if delta.touches_file_id(id):
376
 
                emblem = 'cvs-modified'
377
 
                status = 'modified'
378
 
            for f, _, _ in delta.added:
379
 
                if f == path:
380
 
                    emblem = 'cvs-added'
381
 
                    status = 'added'
382
 
 
383
 
            for of, f, _, _, _, _ in delta.renamed:
384
 
                if f == path:
385
 
                    status = 'renamed from %s' % f
386
 
 
387
 
        elif tree.branch.basis_tree().has_filename(path):
388
 
            emblem = 'cvs-removed'
389
 
            status = 'removed'
390
 
        else:
391
 
            # FIXME: Check for ignored files
392
 
            status = 'unversioned'
393
 
        
394
 
        if emblem is not None:
395
 
            file.add_emblem(emblem)
396
 
        file.add_string_attribute('bzr_status', status)