/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 16:11:12 UTC
  • mfrom: (475.2.2 gtk)
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629161112-3j4zp0r0e7cv6cds
Merge Chad's progress bar in viz patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#
3
3
# Copyright (C) 2006 Jeff Bailey
4
4
# Copyright (C) 2006 Wouter van Heyst
5
 
# Copyright (C) 2006 Jelmer Vernooij
 
5
# Copyright (C) 2006-2008 Jelmer Vernooij <jelmer@samba.org>
6
6
#
7
7
# Published under the GNU GPL
8
8
 
9
9
import gtk
10
10
import nautilus
11
11
import bzrlib
 
12
from bzrlib.branch import Branch
12
13
from bzrlib.bzrdir import BzrDir
13
 
from bzrlib.errors import NotBranchError
14
 
from bzrlib.errors import NoWorkingTree
15
 
from bzrlib.errors import UnsupportedProtocol
 
14
from bzrlib.errors import NotBranchError, NoWorkingTree, UnsupportedProtocol
 
15
from bzrlib.tree import file_status
16
16
from bzrlib.workingtree import WorkingTree
17
 
from bzrlib.branch import Branch
18
 
from bzrlib.tree import file_status
 
17
from bzrlib.config import GlobalConfig
19
18
 
20
19
from bzrlib.plugin import load_plugins
21
20
load_plugins()
22
21
 
23
 
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
 
22
from bzrlib.plugins.gtk import _i18n, cmd_visualise, cmd_gannotate
24
23
 
25
24
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
26
25
    def __init__(self):
160
159
                path = e.path
161
160
 
162
161
        from bzrlib.plugins.gtk.commit import CommitDialog
163
 
        dialog = CommitDialog(tree, path, not branch)
 
162
        dialog = CommitDialog(tree, path)
164
163
        response = dialog.run()
165
164
        if response != gtk.RESPONSE_NONE:
166
165
            dialog.hide()
223
222
    def get_background_items(self, window, vfs_file):
224
223
        items = []
225
224
        file = vfs_file.get_uri()
 
225
 
226
226
        try:
227
227
            tree, path = WorkingTree.open_containing(file)
 
228
            disabled_flag = self.check_branch_enabled(tree.branch)
228
229
        except UnsupportedProtocol:
229
230
            return
230
231
        except NotBranchError:
 
232
            disabled_flag = self.check_branch_enabled()
231
233
            item = nautilus.MenuItem('BzrNautilus::newtree',
232
234
                                 'Make directory versioned',
233
235
                                 'Create new Bazaar tree in this folder')
241
243
            items.append(item)
242
244
 
243
245
            return items
 
246
        except NoWorkingTree:
 
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',
268
285
 
269
286
        return items
270
287
 
271
 
 
272
288
    def get_file_items(self, window, files):
273
289
        items = []
274
 
 
 
290
        
275
291
        wtfiles = {}
276
292
        for vfs_file in files:
277
293
            # We can only cope with local files
278
294
            if vfs_file.get_uri_scheme() != 'file':
279
 
                return
 
295
                continue
280
296
 
281
297
            file = vfs_file.get_uri()
282
298
            try:
283
299
                tree, path = WorkingTree.open_containing(file)
 
300
                disabled_flag = self.check_branch_enabled(tree.branch)
284
301
            except NotBranchError:
 
302
                disabled_flag = self.check_branch_enabled()
285
303
                if not vfs_file.is_directory():
 
304
                    continue
 
305
 
 
306
                if disabled_flag == 'False':
286
307
                    return
 
308
 
287
309
                item = nautilus.MenuItem('BzrNautilus::newtree',
288
310
                                     'Make directory versioned',
289
311
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
290
312
                item.connect('activate', self.newtree_cb, vfs_file)
291
313
                return item,
 
314
            except NoWorkingTree:
 
315
                continue
292
316
            # Refresh the list of filestatuses in the working tree
293
317
            if path not in wtfiles.keys():
294
318
                tree.lock_read()
355
379
                               "Version control status"),
356
380
 
357
381
    def update_file_info(self, file):
 
382
 
358
383
        if file.get_uri_scheme() != 'file':
359
384
            return
360
385
        
362
387
            tree, path = WorkingTree.open_containing(file.get_uri())
363
388
        except NotBranchError:
364
389
            return
 
390
        except NoWorkingTree:
 
391
            return   
 
392
 
 
393
        disabled_flag = self.check_branch_enabled(tree.branch)
 
394
        if disabled_flag == 'False':
 
395
            return
365
396
 
366
397
        emblem = None
367
398
        status = None
368
399
 
369
400
        if tree.has_filename(path):
370
 
            emblem = 'cvs-controlled'
 
401
            emblem = 'bzr-controlled'
371
402
            status = 'unchanged'
372
403
            id = tree.path2id(path)
373
404
 
374
405
            delta = tree.changes_from(tree.branch.basis_tree())
375
406
            if delta.touches_file_id(id):
376
 
                emblem = 'cvs-modified'
 
407
                emblem = 'bzr-modified'
377
408
                status = 'modified'
378
409
            for f, _, _ in delta.added:
379
410
                if f == path:
380
 
                    emblem = 'cvs-added'
 
411
                    emblem = 'bzr-added'
381
412
                    status = 'added'
382
413
 
383
414
            for of, f, _, _, _, _ in delta.renamed:
385
416
                    status = 'renamed from %s' % f
386
417
 
387
418
        elif tree.branch.basis_tree().has_filename(path):
388
 
            emblem = 'cvs-removed'
 
419
            emblem = 'bzr-removed'
389
420
            status = 'removed'
390
421
        else:
391
422
            # FIXME: Check for ignored files
394
425
        if emblem is not None:
395
426
            file.add_emblem(emblem)
396
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