/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: Martin Albisetti
  • Date: 2008-04-04 00:44:37 UTC
  • Revision ID: argentina@gmail.com-20080404004437-1jqxeu90no7wajdr
Change nautilus enable/disable to per branch basis

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
from bzrlib.tree import file_status
16
16
from bzrlib.workingtree import WorkingTree
17
17
from bzrlib.config import GlobalConfig
18
 
config = GlobalConfig()
19
 
disabled_flag = config.get_user_option('nautilus_integration')
20
18
 
21
19
from bzrlib.plugin import load_plugins
22
20
load_plugins()
222
220
        gtk.main()
223
221
 
224
222
    def get_background_items(self, window, vfs_file):
225
 
        if disabled_flag == 'False':
226
 
            item = nautilus.MenuItem('BzrNautilus::enable',
227
 
                                     'Enable Bazaar Plugin',
228
 
                                     'Enable Bazaar plugin for nautilus')
229
 
            item.connect('activate', self.enable_integration, vfs_file)
230
 
            return item,
231
 
 
232
223
        items = []
233
224
        file = vfs_file.get_uri()
234
 
 
235
 
        item = nautilus.MenuItem('BzrNautilus::disable',
236
 
                                  'Disable Bazaar Plugin',
237
 
                                  'Disable Bazaar plugin for nautilus')
238
 
        item.connect('activate', self.disable_integration, vfs_file)
239
 
        items.append(item)
240
225
 
241
226
        try:
242
227
            tree, path = WorkingTree.open_containing(file)
 
228
            disabled_flag = self.check_branch_enabled(tree.branch)
243
229
        except UnsupportedProtocol:
244
230
            return
245
231
        except NotBranchError:
 
232
            disabled_flag = self.check_branch_enabled()
246
233
            item = nautilus.MenuItem('BzrNautilus::newtree',
247
234
                                 'Make directory versioned',
248
235
                                 'Create new Bazaar tree in this folder')
258
245
            return items
259
246
        except NoWorkingTree:
260
247
            return
 
248
        
 
249
        if disabled_flag == 'False':
 
250
            item = nautilus.MenuItem('BzrNautilus::enable',
 
251
                                     'Enable Bazaar Plugin for this Branch',
 
252
                                     'Enable Bazaar plugin for nautilus')
 
253
            item.connect('activate', self.enable_integration, vfs_file)
 
254
            return item,
 
255
        else:
 
256
            item = nautilus.MenuItem('BzrNautilus::disable',
 
257
                                      'Disable Bazaar Plugin for the Branch',
 
258
                                      'Disable Bazaar plugin for nautilus')
 
259
            item.connect('activate', self.disable_integration, vfs_file)
 
260
            items.append(item)
261
261
 
262
262
        item = nautilus.MenuItem('BzrNautilus::log',
263
263
                             'Log',
286
286
        return items
287
287
 
288
288
    def get_file_items(self, window, files):
289
 
        if disabled_flag == 'False':
290
 
            return
291
 
 
292
289
        items = []
 
290
        
293
291
        wtfiles = {}
294
292
        for vfs_file in files:
295
293
            # We can only cope with local files
299
297
            file = vfs_file.get_uri()
300
298
            try:
301
299
                tree, path = WorkingTree.open_containing(file)
 
300
                disabled_flag = self.check_branch_enabled(tree.branch)
302
301
            except NotBranchError:
 
302
                disabled_flag = self.check_branch_enabled()
303
303
                if not vfs_file.is_directory():
304
304
                    continue
 
305
 
 
306
                if disabled_flag == 'False':
 
307
                    return
 
308
 
305
309
                item = nautilus.MenuItem('BzrNautilus::newtree',
306
310
                                     'Make directory versioned',
307
311
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
375
379
                               "Version control status"),
376
380
 
377
381
    def update_file_info(self, file):
378
 
        if disabled_flag == 'False':
379
 
            return
380
382
 
381
383
        if file.get_uri_scheme() != 'file':
382
384
            return
386
388
        except NotBranchError:
387
389
            return
388
390
        except NoWorkingTree:
 
391
            return   
 
392
 
 
393
        disabled_flag = self.check_branch_enabled(tree.branch)
 
394
        if disabled_flag == 'False':
389
395
            return
390
396
 
391
397
        emblem = None
420
426
            file.add_emblem(emblem)
421
427
        file.add_string_attribute('bzr_status', status)
422
428
 
 
429
    def check_branch_enabled(self, branch=None):
 
430
        # Supports global disable, but there is currently no UI to do this
 
431
        config = GlobalConfig()
 
432
        disabled_flag = config.get_user_option('nautilus_integration')
 
433
        if disabled_flag != 'False':
 
434
            if branch is not None:
 
435
                config = branch.get_config()
 
436
                disabled_flag = config.get_user_option('nautilus_integration')
 
437
        return disabled_flag
 
438
 
423
439
    def enable_integration(self, menu, vfs_file=None):
 
440
        try:
 
441
            tree, path = WorkingTree.open_containing(vfs_file.get_uri())
 
442
        except NotBranchError:
 
443
            return
 
444
        except NoWorkingTree:
 
445
            return
 
446
        branch = tree.branch
 
447
        if branch is None:
 
448
            config = GlobalConfig()
 
449
        else:
 
450
            config = branch.get_config()
424
451
        config.set_user_option('nautilus_integration','True')
425
452
 
426
453
    def disable_integration(self, menu, vfs_file=None):
 
454
        try:
 
455
            tree, path = WorkingTree.open_containing(vfs_file.get_uri())
 
456
        except NotBranchError:
 
457
            return
 
458
        except NoWorkingTree:
 
459
            return   
 
460
        branch = tree.branch
 
461
        if branch is None:
 
462
            config = GlobalConfig()
 
463
        else:
 
464
            config = branch.get_config()
427
465
        config.set_user_option('nautilus_integration','False')