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