/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: Szilveszter Farkas (Phanatic)
  • Date: 2008-03-07 15:56:36 UTC
  • mto: This revision was merged to the branch mainline in revision 444.
  • Revision ID: szilveszter.farkas@gmail.com-20080307155636-q0e5xkgmujhzgdjx
Fixed bug #131471 (don't allow pressing the button if there are no conflicts).

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
18
17
 
19
18
from bzrlib.plugin import load_plugins
20
19
load_plugins()
21
20
 
22
 
from bzrlib.plugins.gtk import _i18n, cmd_visualise, cmd_gannotate
 
21
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
23
22
 
24
23
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
25
24
    def __init__(self):
222
221
    def get_background_items(self, window, vfs_file):
223
222
        items = []
224
223
        file = vfs_file.get_uri()
225
 
 
226
224
        try:
227
225
            tree, path = WorkingTree.open_containing(file)
228
 
            disabled_flag = self.check_branch_enabled(tree.branch)
229
226
        except UnsupportedProtocol:
230
227
            return
231
228
        except NotBranchError:
232
 
            disabled_flag = self.check_branch_enabled()
233
229
            item = nautilus.MenuItem('BzrNautilus::newtree',
234
230
                                 'Make directory versioned',
235
231
                                 'Create new Bazaar tree in this folder')
245
241
            return items
246
242
        except NoWorkingTree:
247
243
            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)
261
244
 
262
245
        item = nautilus.MenuItem('BzrNautilus::log',
263
246
                             'Log',
287
270
 
288
271
    def get_file_items(self, window, files):
289
272
        items = []
290
 
        
 
273
 
291
274
        wtfiles = {}
292
275
        for vfs_file in files:
293
276
            # We can only cope with local files
297
280
            file = vfs_file.get_uri()
298
281
            try:
299
282
                tree, path = WorkingTree.open_containing(file)
300
 
                disabled_flag = self.check_branch_enabled(tree.branch)
301
283
            except NotBranchError:
302
 
                disabled_flag = self.check_branch_enabled()
303
284
                if not vfs_file.is_directory():
304
285
                    continue
305
 
 
306
 
                if disabled_flag == 'False':
307
 
                    return
308
 
 
309
286
                item = nautilus.MenuItem('BzrNautilus::newtree',
310
287
                                     'Make directory versioned',
311
288
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
379
356
                               "Version control status"),
380
357
 
381
358
    def update_file_info(self, file):
382
 
 
383
359
        if file.get_uri_scheme() != 'file':
384
360
            return
385
361
        
388
364
        except NotBranchError:
389
365
            return
390
366
        except NoWorkingTree:
391
 
            return   
392
 
 
393
 
        disabled_flag = self.check_branch_enabled(tree.branch)
394
 
        if disabled_flag == 'False':
395
367
            return
396
368
 
397
369
        emblem = None
398
370
        status = None
399
371
 
400
372
        if tree.has_filename(path):
401
 
            emblem = 'bzr-controlled'
 
373
            emblem = 'cvs-controlled'
402
374
            status = 'unchanged'
403
375
            id = tree.path2id(path)
404
376
 
405
377
            delta = tree.changes_from(tree.branch.basis_tree())
406
378
            if delta.touches_file_id(id):
407
 
                emblem = 'bzr-modified'
 
379
                emblem = 'cvs-modified'
408
380
                status = 'modified'
409
381
            for f, _, _ in delta.added:
410
382
                if f == path:
411
 
                    emblem = 'bzr-added'
 
383
                    emblem = 'cvs-added'
412
384
                    status = 'added'
413
385
 
414
386
            for of, f, _, _, _, _ in delta.renamed:
416
388
                    status = 'renamed from %s' % f
417
389
 
418
390
        elif tree.branch.basis_tree().has_filename(path):
419
 
            emblem = 'bzr-removed'
 
391
            emblem = 'cvs-removed'
420
392
            status = 'removed'
421
393
        else:
422
394
            # FIXME: Check for ignored files
425
397
        if emblem is not None:
426
398
            file.add_emblem(emblem)
427
399
        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