/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: Aaron Bentley
  • Date: 2008-02-23 06:39:14 UTC
  • Revision ID: aaron@aaronbentley.com-20080223063914-49gdt7ed630rug9b
Add handle-patch script

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