/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: 2007-02-01 15:50:40 UTC
  • Revision ID: jelmer@samba.org-20070201155040-3hq4mfbxs99kzazy
add framework for tests.

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-2008 Jelmer Vernooij <jelmer@samba.org>
6
 
#
7
 
# Published under the GNU GPL
8
 
 
9
 
import gtk
10
1
import nautilus
11
2
import bzrlib
12
 
from bzrlib.branch import Branch
13
3
from bzrlib.bzrdir import BzrDir
14
 
from bzrlib.errors import NotBranchError, NoWorkingTree, UnsupportedProtocol
 
4
from bzrlib.errors import NotBranchError
 
5
from bzrlib.workingtree import WorkingTree
15
6
from bzrlib.tree import file_status
16
 
from bzrlib.workingtree import WorkingTree
17
 
from bzrlib.config import GlobalConfig
18
7
 
19
8
from bzrlib.plugin import load_plugins
20
9
load_plugins()
21
10
 
22
 
from bzrlib.plugins.gtk import _i18n, cmd_gannotate, start_viz_window
23
 
 
24
 
print "Bazaar nautilus module initialized"
25
 
 
 
11
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
26
12
 
27
13
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
28
14
    def __init__(self):
84
70
        except NotBranchError:
85
71
            return
86
72
 
87
 
        from bzrlib.plugins.gtk.diff import DiffWindow
 
73
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
88
74
        window = DiffWindow()
89
 
        window.set_diff(tree.branch._get_nick(local=True), tree, 
90
 
                        tree.branch.basis_tree())
 
75
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
91
76
        window.show()
92
77
 
93
78
        return
103
88
        try:
104
89
            tree, path = WorkingTree.open_containing(file)
105
90
        except NotBranchError:
106
 
            BzrDir.create_standalone_workingtree(file)
 
91
            BzrDir.create_branch_and_repo(file)
107
92
 
108
93
    def remove_cb(self, menu, vfs_file):
109
94
        # We can only cope with local files
133
118
        if vfs_file.get_uri_scheme() != 'file':
134
119
            return
135
120
 
136
 
        from bzrlib.plugins.gtk.branch import BranchDialog
 
121
        from bzrlib.plugins.gtk.olive.branch import BranchDialog
137
122
        
138
123
        dialog = BranchDialog(vfs_file.get_name())
139
 
        response = dialog.run()
140
 
        if response != gtk.RESPONSE_NONE:
141
 
            dialog.hide()
142
 
            dialog.destroy()
 
124
        dialog.display()
143
125
 
144
126
    def commit_cb(self, menu, vfs_file=None):
145
127
        # We can only cope with local files
147
129
            return
148
130
 
149
131
        file = vfs_file.get_uri()
150
 
        tree = None
151
 
        branch = None
152
132
        try:
153
133
            tree, path = WorkingTree.open_containing(file)
154
 
            branch = tree.branch
155
 
        except NotBranchError, e:
156
 
            path = e.path
157
 
            #return
158
 
        except NoWorkingTree, e:
159
 
            path = e.base
160
 
            try:
161
 
                (branch, path) = Branch.open_containing(path)
162
 
            except NotBranchError, e:
163
 
                path = e.path
 
134
        except NotBranchError:
 
135
            return
164
136
 
165
 
        from bzrlib.plugins.gtk.commit import CommitDialog
 
137
        from bzrlib.plugins.gtk.olive.commit import CommitDialog
166
138
        dialog = CommitDialog(tree, path)
167
 
        response = dialog.run()
168
 
        if response != gtk.RESPONSE_NONE:
169
 
            dialog.hide()
170
 
            dialog.destroy()
 
139
        dialog.display()
 
140
        gtk.main()
171
141
 
172
142
    def log_cb(self, menu, vfs_file):
173
143
        # We can only cope with local files
178
148
 
179
149
        # We only want to continue here if we get a NotBranchError
180
150
        try:
181
 
            branch, path = Branch.open_containing(file)
 
151
            tree, path = WorkingTree.open_containing(file)
182
152
        except NotBranchError:
183
153
            return
184
154
 
185
 
        pp = start_viz_window(branch, [branch.last_revision()])
186
 
        pp.show()
187
 
        gtk.main()
 
155
        vis = cmd_visualise()
 
156
        vis.run(file)
 
157
 
 
158
        return
188
159
 
189
160
    def pull_cb(self, menu, vfs_file):
190
161
        # We can only cope with local files
199
170
        except NotBranchError:
200
171
            return
201
172
 
202
 
        from bzrlib.plugins.gtk.pull import PullDialog
 
173
        from bzrlib.plugins.gtk.olive.pull import PullDialog
203
174
        dialog = PullDialog(tree, path)
204
175
        dialog.display()
205
176
        gtk.main()
217
188
        except NotBranchError:
218
189
            return
219
190
 
220
 
        from bzrlib.plugins.gtk.merge import MergeDialog
 
191
        from bzrlib.plugins.gtk.olive.merge import MergeDialog
221
192
        dialog = MergeDialog(tree, path)
222
 
        dialog.run()
223
 
        dialog.destroy()
 
193
        dialog.display()
 
194
        gtk.main()
224
195
 
225
196
    def get_background_items(self, window, vfs_file):
226
197
        items = []
227
198
        file = vfs_file.get_uri()
228
 
 
229
199
        try:
230
200
            tree, path = WorkingTree.open_containing(file)
231
 
            disabled_flag = self.check_branch_enabled(tree.branch)
232
 
        except UnsupportedProtocol:
233
 
            return
234
201
        except NotBranchError:
235
 
            disabled_flag = self.check_branch_enabled()
236
202
            item = nautilus.MenuItem('BzrNautilus::newtree',
237
203
                                 'Make directory versioned',
238
204
                                 'Create new Bazaar tree in this folder')
240
206
            items.append(item)
241
207
 
242
208
            item = nautilus.MenuItem('BzrNautilus::clone',
243
 
                                 'Checkout Bazaar branch ...',
 
209
                                 'Checkout Bazaar branch',
244
210
                                 'Checkout Existing Bazaar Branch')
245
211
            item.connect('activate', self.clone_cb, vfs_file)
246
212
            items.append(item)
247
213
 
248
214
            return items
249
 
        except NoWorkingTree:
250
 
            return
251
 
        
252
 
        if disabled_flag == 'False':
253
 
            item = nautilus.MenuItem('BzrNautilus::enable',
254
 
                                     'Enable Bazaar Plugin for this Branch',
255
 
                                     'Enable Bazaar plugin for nautilus')
256
 
            item.connect('activate', self.toggle_integration, 'True', vfs_file)
257
 
            return item,
258
 
        else:
259
 
            item = nautilus.MenuItem('BzrNautilus::disable',
260
 
                                      'Disable Bazaar Plugin this Branch',
261
 
                                      'Disable Bazaar plugin for nautilus')
262
 
            item.connect('activate', self.toggle_integration, 'False', vfs_file)
263
 
            items.append(item)
264
215
 
265
216
        item = nautilus.MenuItem('BzrNautilus::log',
266
 
                             'History ...',
 
217
                             'Log',
267
218
                             'Show Bazaar history')
268
219
        item.connect('activate', self.log_cb, vfs_file)
269
220
        items.append(item)
270
221
 
271
222
        item = nautilus.MenuItem('BzrNautilus::pull',
272
 
                             'Pull ...',
 
223
                             'Pull',
273
224
                             'Pull from another branch')
274
225
        item.connect('activate', self.pull_cb, vfs_file)
275
226
        items.append(item)
276
227
 
277
228
        item = nautilus.MenuItem('BzrNautilus::merge',
278
 
                             'Merge ...',
 
229
                             'Merge',
279
230
                             'Merge from another branch')
280
231
        item.connect('activate', self.merge_cb, vfs_file)
281
232
        items.append(item)
282
233
 
283
234
        item = nautilus.MenuItem('BzrNautilus::commit',
284
 
                             'Commit ...',
 
235
                             'Commit',
285
236
                             'Commit Changes')
286
237
        item.connect('activate', self.commit_cb, vfs_file)
287
238
        items.append(item)
288
239
 
289
240
        return items
290
241
 
 
242
 
291
243
    def get_file_items(self, window, files):
292
244
        items = []
293
 
        
294
 
        wtfiles = {}
 
245
 
295
246
        for vfs_file in files:
296
247
            # We can only cope with local files
297
248
            if vfs_file.get_uri_scheme() != 'file':
298
 
                continue
 
249
                return
299
250
 
300
251
            file = vfs_file.get_uri()
301
252
            try:
302
253
                tree, path = WorkingTree.open_containing(file)
303
 
                disabled_flag = self.check_branch_enabled(tree.branch)
304
254
            except NotBranchError:
305
 
                disabled_flag = self.check_branch_enabled()
306
255
                if not vfs_file.is_directory():
307
 
                    continue
308
 
 
309
 
                if disabled_flag == 'False':
310
256
                    return
311
 
 
312
257
                item = nautilus.MenuItem('BzrNautilus::newtree',
313
258
                                     'Make directory versioned',
314
259
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
315
260
                item.connect('activate', self.newtree_cb, vfs_file)
316
261
                return item,
317
 
            except NoWorkingTree:
318
 
                continue
319
 
            # Refresh the list of filestatuses in the working tree
320
 
            if path not in wtfiles.keys():
321
 
                tree.lock_read()
322
 
                for rpath, file_class, kind, id, entry in tree.list_files():
323
 
                    wtfiles[rpath] = file_class
324
 
                tree.unlock()
325
 
                wtfiles[u''] = 'V'
326
 
 
327
 
            if wtfiles[path] == '?':
 
262
 
 
263
            file_class = tree.file_class(path)
 
264
 
 
265
            if file_class == '?':
328
266
                item = nautilus.MenuItem('BzrNautilus::add',
329
267
                                     'Add',
330
268
                                     'Add as versioned file')
336
274
                                     'Ignore file for versioning')
337
275
                item.connect('activate', self.ignore_cb, vfs_file)
338
276
                items.append(item)
339
 
            elif wtfiles[path] == 'I':
 
277
            elif file_class == 'I':
340
278
                item = nautilus.MenuItem('BzrNautilus::unignore',
341
279
                                     'Unignore',
342
280
                                     'Unignore file for versioning')
343
281
                item.connect('activate', self.unignore_cb, vfs_file)
344
282
                items.append(item)
345
 
            elif wtfiles[path] == 'V':
 
283
            elif file_class == 'V':
346
284
                item = nautilus.MenuItem('BzrNautilus::log',
347
 
                                 'History ...',
 
285
                                 'Log',
348
286
                                 'List changes')
349
287
                item.connect('activate', self.log_cb, vfs_file)
350
288
                items.append(item)
351
289
 
352
290
                item = nautilus.MenuItem('BzrNautilus::diff',
353
 
                                 'View Changes ...',
 
291
                                 'Diff',
354
292
                                 'Show differences')
355
293
                item.connect('activate', self.diff_cb, vfs_file)
356
294
                items.append(item)
362
300
                items.append(item)
363
301
 
364
302
                item = nautilus.MenuItem('BzrNautilus::annotate',
365
 
                             'Annotate ...',
 
303
                             'Annotate',
366
304
                             'Annotate File Data')
367
305
                item.connect('activate', self.annotate_cb, vfs_file)
368
306
                items.append(item)
369
307
 
370
308
                item = nautilus.MenuItem('BzrNautilus::commit',
371
 
                             'Commit ...',
 
309
                             'Commit',
372
310
                             'Commit Changes')
373
311
                item.connect('activate', self.commit_cb, vfs_file)
374
312
                items.append(item)
382
320
                               "Version control status"),
383
321
 
384
322
    def update_file_info(self, file):
385
 
 
386
323
        if file.get_uri_scheme() != 'file':
387
324
            return
388
325
        
390
327
            tree, path = WorkingTree.open_containing(file.get_uri())
391
328
        except NotBranchError:
392
329
            return
393
 
        except NoWorkingTree:
394
 
            return   
395
 
 
396
 
        disabled_flag = self.check_branch_enabled(tree.branch)
397
 
        if disabled_flag == 'False':
398
 
            return
399
330
 
400
331
        emblem = None
401
332
        status = None
402
333
 
403
334
        if tree.has_filename(path):
404
 
            emblem = 'bzr-controlled'
 
335
            emblem = 'cvs-controlled'
405
336
            status = 'unchanged'
406
337
            id = tree.path2id(path)
407
338
 
408
339
            delta = tree.changes_from(tree.branch.basis_tree())
409
340
            if delta.touches_file_id(id):
410
 
                emblem = 'bzr-modified'
 
341
                emblem = 'cvs-modified'
411
342
                status = 'modified'
412
343
            for f, _, _ in delta.added:
413
344
                if f == path:
414
 
                    emblem = 'bzr-added'
 
345
                    emblem = 'cvs-added'
415
346
                    status = 'added'
416
347
 
417
348
            for of, f, _, _, _, _ in delta.renamed:
419
350
                    status = 'renamed from %s' % f
420
351
 
421
352
        elif tree.branch.basis_tree().has_filename(path):
422
 
            emblem = 'bzr-removed'
 
353
            emblem = 'cvs-removed'
423
354
            status = 'removed'
424
355
        else:
425
356
            # FIXME: Check for ignored files
428
359
        if emblem is not None:
429
360
            file.add_emblem(emblem)
430
361
        file.add_string_attribute('bzr_status', status)
431
 
 
432
 
    def check_branch_enabled(self, branch=None):
433
 
        # Supports global disable, but there is currently no UI to do this
434
 
        config = GlobalConfig()
435
 
        disabled_flag = config.get_user_option('nautilus_integration')
436
 
        if disabled_flag != 'False':
437
 
            if branch is not None:
438
 
                config = branch.get_config()
439
 
                disabled_flag = config.get_user_option('nautilus_integration')
440
 
        return disabled_flag
441
 
 
442
 
    def toggle_integration(self, menu, action, vfs_file=None):
443
 
        try:
444
 
            tree, path = WorkingTree.open_containing(vfs_file.get_uri())
445
 
        except NotBranchError:
446
 
            return
447
 
        except NoWorkingTree:
448
 
            return
449
 
        branch = tree.branch
450
 
        if branch is None:
451
 
            config = GlobalConfig()
452
 
        else:
453
 
            config = branch.get_config()
454
 
        config.set_user_option('nautilus_integration', action)
455