/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: 2008-06-29 18:12:29 UTC
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629181229-1l2m4cf7vvbyh8qg
Simplify progress bar code, use embedded progress bar inside viz window.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
from bzrlib.errors import NotBranchError, NoWorkingTree, UnsupportedProtocol
15
15
from bzrlib.tree import file_status
16
16
from bzrlib.workingtree import WorkingTree
 
17
from bzrlib.config import GlobalConfig
17
18
 
18
19
from bzrlib.plugin import load_plugins
19
20
load_plugins()
20
21
 
21
 
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
 
22
from bzrlib.plugins.gtk import _i18n, cmd_visualise, cmd_gannotate
22
23
 
23
24
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
24
25
    def __init__(self):
221
222
    def get_background_items(self, window, vfs_file):
222
223
        items = []
223
224
        file = vfs_file.get_uri()
 
225
 
224
226
        try:
225
227
            tree, path = WorkingTree.open_containing(file)
 
228
            disabled_flag = self.check_branch_enabled(tree.branch)
226
229
        except UnsupportedProtocol:
227
230
            return
228
231
        except NotBranchError:
 
232
            disabled_flag = self.check_branch_enabled()
229
233
            item = nautilus.MenuItem('BzrNautilus::newtree',
230
234
                                 'Make directory versioned',
231
235
                                 'Create new Bazaar tree in this folder')
241
245
            return items
242
246
        except NoWorkingTree:
243
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.toggle_integration, 'True', 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.toggle_integration, 'False', vfs_file)
 
260
            items.append(item)
244
261
 
245
262
        item = nautilus.MenuItem('BzrNautilus::log',
246
263
                             'Log',
270
287
 
271
288
    def get_file_items(self, window, files):
272
289
        items = []
273
 
 
 
290
        
274
291
        wtfiles = {}
275
292
        for vfs_file in files:
276
293
            # We can only cope with local files
280
297
            file = vfs_file.get_uri()
281
298
            try:
282
299
                tree, path = WorkingTree.open_containing(file)
 
300
                disabled_flag = self.check_branch_enabled(tree.branch)
283
301
            except NotBranchError:
 
302
                disabled_flag = self.check_branch_enabled()
284
303
                if not vfs_file.is_directory():
285
304
                    continue
 
305
 
 
306
                if disabled_flag == 'False':
 
307
                    return
 
308
 
286
309
                item = nautilus.MenuItem('BzrNautilus::newtree',
287
310
                                     'Make directory versioned',
288
311
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
356
379
                               "Version control status"),
357
380
 
358
381
    def update_file_info(self, file):
 
382
 
359
383
        if file.get_uri_scheme() != 'file':
360
384
            return
361
385
        
364
388
        except NotBranchError:
365
389
            return
366
390
        except NoWorkingTree:
 
391
            return   
 
392
 
 
393
        disabled_flag = self.check_branch_enabled(tree.branch)
 
394
        if disabled_flag == 'False':
367
395
            return
368
396
 
369
397
        emblem = None
393
421
        else:
394
422
            # FIXME: Check for ignored files
395
423
            status = 'unversioned'
396
 
            emblem = 'bzr-unversioned'
397
424
        
398
425
        if emblem is not None:
399
426
            file.add_emblem(emblem)
400
427
        file.add_string_attribute('bzr_status', status)
 
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
 
 
439
    def toggle_integration(self, menu, action, 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()
 
451
        config.set_user_option('nautilus_integration', action)
 
452