/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: Daniel Schierbeck
  • Date: 2008-01-13 14:12:49 UTC
  • mto: (423.1.2 trunk)
  • mto: This revision was merged to the branch mainline in revision 429.
  • Revision ID: daniel.schierbeck@gmail.com-20080113141249-gd0i2lknr3yik55r
Moved branch view to its own package.

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
23
 
from bzrlib.plugins.gtk.commands import cmd_gannotate, start_viz_window
24
 
 
25
 
print "Bazaar nautilus module initialized"
26
 
 
 
23
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
27
24
 
28
25
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
29
26
    def __init__(self):
87
84
 
88
85
        from bzrlib.plugins.gtk.diff import DiffWindow
89
86
        window = DiffWindow()
90
 
        window.set_diff(tree.branch._get_nick(local=True), tree, 
91
 
                        tree.branch.basis_tree())
 
87
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
92
88
        window.show()
93
89
 
94
90
        return
164
160
                path = e.path
165
161
 
166
162
        from bzrlib.plugins.gtk.commit import CommitDialog
167
 
        dialog = CommitDialog(tree, path)
 
163
        dialog = CommitDialog(tree, path, not branch)
168
164
        response = dialog.run()
169
165
        if response != gtk.RESPONSE_NONE:
170
166
            dialog.hide()
179
175
 
180
176
        # We only want to continue here if we get a NotBranchError
181
177
        try:
182
 
            branch, path = Branch.open_containing(file)
 
178
            tree, path = WorkingTree.open_containing(file)
183
179
        except NotBranchError:
184
180
            return
185
181
 
186
 
        pp = start_viz_window(branch, [branch.last_revision()])
187
 
        pp.show()
188
 
        gtk.main()
 
182
        vis = cmd_visualise()
 
183
        vis.run(file)
 
184
 
 
185
        return
189
186
 
190
187
    def pull_cb(self, menu, vfs_file):
191
188
        # We can only cope with local files
220
217
 
221
218
        from bzrlib.plugins.gtk.merge import MergeDialog
222
219
        dialog = MergeDialog(tree, path)
223
 
        dialog.run()
224
 
        dialog.destroy()
 
220
        dialog.display()
 
221
        gtk.main()
225
222
 
226
223
    def get_background_items(self, window, vfs_file):
227
224
        items = []
228
225
        file = vfs_file.get_uri()
229
 
 
230
226
        try:
231
227
            tree, path = WorkingTree.open_containing(file)
232
 
            disabled_flag = self.check_branch_enabled(tree.branch)
233
228
        except UnsupportedProtocol:
234
229
            return
235
230
        except NotBranchError:
236
 
            disabled_flag = self.check_branch_enabled()
237
231
            item = nautilus.MenuItem('BzrNautilus::newtree',
238
232
                                 'Make directory versioned',
239
233
                                 'Create new Bazaar tree in this folder')
241
235
            items.append(item)
242
236
 
243
237
            item = nautilus.MenuItem('BzrNautilus::clone',
244
 
                                 'Checkout Bazaar branch ...',
 
238
                                 'Checkout Bazaar branch',
245
239
                                 'Checkout Existing Bazaar Branch')
246
240
            item.connect('activate', self.clone_cb, vfs_file)
247
241
            items.append(item)
248
242
 
249
243
            return items
250
 
        except NoWorkingTree:
251
 
            return
252
 
        
253
 
        if disabled_flag == 'False':
254
 
            item = nautilus.MenuItem('BzrNautilus::enable',
255
 
                                     'Enable Bazaar Plugin for this Branch',
256
 
                                     'Enable Bazaar plugin for nautilus')
257
 
            item.connect('activate', self.toggle_integration, 'True', vfs_file)
258
 
            return item,
259
 
        else:
260
 
            item = nautilus.MenuItem('BzrNautilus::disable',
261
 
                                      'Disable Bazaar Plugin this Branch',
262
 
                                      'Disable Bazaar plugin for nautilus')
263
 
            item.connect('activate', self.toggle_integration, 'False', vfs_file)
264
 
            items.append(item)
265
244
 
266
245
        item = nautilus.MenuItem('BzrNautilus::log',
267
 
                             'History ...',
 
246
                             'Log',
268
247
                             'Show Bazaar history')
269
248
        item.connect('activate', self.log_cb, vfs_file)
270
249
        items.append(item)
271
250
 
272
251
        item = nautilus.MenuItem('BzrNautilus::pull',
273
 
                             'Pull ...',
 
252
                             'Pull',
274
253
                             'Pull from another branch')
275
254
        item.connect('activate', self.pull_cb, vfs_file)
276
255
        items.append(item)
277
256
 
278
257
        item = nautilus.MenuItem('BzrNautilus::merge',
279
 
                             'Merge ...',
 
258
                             'Merge',
280
259
                             'Merge from another branch')
281
260
        item.connect('activate', self.merge_cb, vfs_file)
282
261
        items.append(item)
283
262
 
284
263
        item = nautilus.MenuItem('BzrNautilus::commit',
285
 
                             'Commit ...',
 
264
                             'Commit',
286
265
                             'Commit Changes')
287
266
        item.connect('activate', self.commit_cb, vfs_file)
288
267
        items.append(item)
289
268
 
290
269
        return items
291
270
 
 
271
 
292
272
    def get_file_items(self, window, files):
293
273
        items = []
294
 
        
 
274
 
295
275
        wtfiles = {}
296
276
        for vfs_file in files:
297
277
            # We can only cope with local files
298
278
            if vfs_file.get_uri_scheme() != 'file':
299
 
                continue
 
279
                return
300
280
 
301
281
            file = vfs_file.get_uri()
302
282
            try:
303
283
                tree, path = WorkingTree.open_containing(file)
304
 
                disabled_flag = self.check_branch_enabled(tree.branch)
305
284
            except NotBranchError:
306
 
                disabled_flag = self.check_branch_enabled()
307
285
                if not vfs_file.is_directory():
308
 
                    continue
309
 
 
310
 
                if disabled_flag == 'False':
311
286
                    return
312
 
 
313
287
                item = nautilus.MenuItem('BzrNautilus::newtree',
314
288
                                     'Make directory versioned',
315
289
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
316
290
                item.connect('activate', self.newtree_cb, vfs_file)
317
291
                return item,
318
 
            except NoWorkingTree:
319
 
                continue
320
292
            # Refresh the list of filestatuses in the working tree
321
293
            if path not in wtfiles.keys():
322
294
                tree.lock_read()
345
317
                items.append(item)
346
318
            elif wtfiles[path] == 'V':
347
319
                item = nautilus.MenuItem('BzrNautilus::log',
348
 
                                 'History ...',
 
320
                                 'Log',
349
321
                                 'List changes')
350
322
                item.connect('activate', self.log_cb, vfs_file)
351
323
                items.append(item)
352
324
 
353
325
                item = nautilus.MenuItem('BzrNautilus::diff',
354
 
                                 'View Changes ...',
 
326
                                 'Diff',
355
327
                                 'Show differences')
356
328
                item.connect('activate', self.diff_cb, vfs_file)
357
329
                items.append(item)
363
335
                items.append(item)
364
336
 
365
337
                item = nautilus.MenuItem('BzrNautilus::annotate',
366
 
                             'Annotate ...',
 
338
                             'Annotate',
367
339
                             'Annotate File Data')
368
340
                item.connect('activate', self.annotate_cb, vfs_file)
369
341
                items.append(item)
370
342
 
371
343
                item = nautilus.MenuItem('BzrNautilus::commit',
372
 
                             'Commit ...',
 
344
                             'Commit',
373
345
                             'Commit Changes')
374
346
                item.connect('activate', self.commit_cb, vfs_file)
375
347
                items.append(item)
383
355
                               "Version control status"),
384
356
 
385
357
    def update_file_info(self, file):
386
 
 
387
358
        if file.get_uri_scheme() != 'file':
388
359
            return
389
360
        
391
362
            tree, path = WorkingTree.open_containing(file.get_uri())
392
363
        except NotBranchError:
393
364
            return
394
 
        except NoWorkingTree:
395
 
            return   
396
 
 
397
 
        disabled_flag = self.check_branch_enabled(tree.branch)
398
 
        if disabled_flag == 'False':
399
 
            return
400
365
 
401
366
        emblem = None
402
367
        status = None
403
368
 
404
 
        id = tree.path2id(path)
405
 
        if id == None:
406
 
            if tree.is_ignored(path):
407
 
                status = 'ignored'
408
 
                emblem = 'bzr-ignored'
409
 
            else:
410
 
                status = 'unversioned'
411
 
                        
412
 
        elif tree.has_filename(path):
413
 
            emblem = 'bzr-controlled'
 
369
        if tree.has_filename(path):
 
370
            emblem = 'cvs-controlled'
414
371
            status = 'unchanged'
 
372
            id = tree.path2id(path)
415
373
 
416
374
            delta = tree.changes_from(tree.branch.basis_tree())
417
375
            if delta.touches_file_id(id):
418
 
                emblem = 'bzr-modified'
 
376
                emblem = 'cvs-modified'
419
377
                status = 'modified'
420
378
            for f, _, _ in delta.added:
421
379
                if f == path:
422
 
                    emblem = 'bzr-added'
 
380
                    emblem = 'cvs-added'
423
381
                    status = 'added'
424
382
 
425
383
            for of, f, _, _, _, _ in delta.renamed:
427
385
                    status = 'renamed from %s' % f
428
386
 
429
387
        elif tree.branch.basis_tree().has_filename(path):
430
 
            emblem = 'bzr-removed'
 
388
            emblem = 'cvs-removed'
431
389
            status = 'removed'
432
390
        else:
433
391
            # FIXME: Check for ignored files
436
394
        if emblem is not None:
437
395
            file.add_emblem(emblem)
438
396
        file.add_string_attribute('bzr_status', status)
439
 
 
440
 
    def check_branch_enabled(self, branch=None):
441
 
        # Supports global disable, but there is currently no UI to do this
442
 
        config = GlobalConfig()
443
 
        disabled_flag = config.get_user_option('nautilus_integration')
444
 
        if disabled_flag != 'False':
445
 
            if branch is not None:
446
 
                config = branch.get_config()
447
 
                disabled_flag = config.get_user_option('nautilus_integration')
448
 
        return disabled_flag
449
 
 
450
 
    def toggle_integration(self, menu, action, vfs_file=None):
451
 
        try:
452
 
            tree, path = WorkingTree.open_containing(vfs_file.get_uri())
453
 
        except NotBranchError:
454
 
            return
455
 
        except NoWorkingTree:
456
 
            return
457
 
        branch = tree.branch
458
 
        if branch is None:
459
 
            config = GlobalConfig()
460
 
        else:
461
 
            config = branch.get_config()
462
 
        config.set_user_option('nautilus_integration', action)
463