/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

Merged an approved request (single clicking bookmark).

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_gannotate, start_viz_window
23
 
 
24
 
print "Bazaar nautilus module initialized"
25
 
 
 
21
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
26
22
 
27
23
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
28
24
    def __init__(self):
177
173
 
178
174
        # We only want to continue here if we get a NotBranchError
179
175
        try:
180
 
            branch, path = Branch.open_containing(file)
 
176
            tree, path = WorkingTree.open_containing(file)
181
177
        except NotBranchError:
182
178
            return
183
179
 
184
 
        pp = start_viz_window(branch, [branch.last_revision()])
185
 
        pp.show()
186
 
        gtk.main()
 
180
        vis = cmd_visualise()
 
181
        vis.run(file)
 
182
 
 
183
        return
187
184
 
188
185
    def pull_cb(self, menu, vfs_file):
189
186
        # We can only cope with local files
218
215
 
219
216
        from bzrlib.plugins.gtk.merge import MergeDialog
220
217
        dialog = MergeDialog(tree, path)
221
 
        dialog.run()
222
 
        dialog.destroy()
 
218
        dialog.display()
 
219
        gtk.main()
223
220
 
224
221
    def get_background_items(self, window, vfs_file):
225
222
        items = []
226
223
        file = vfs_file.get_uri()
227
 
 
228
224
        try:
229
225
            tree, path = WorkingTree.open_containing(file)
230
 
            disabled_flag = self.check_branch_enabled(tree.branch)
231
226
        except UnsupportedProtocol:
232
227
            return
233
228
        except NotBranchError:
234
 
            disabled_flag = self.check_branch_enabled()
235
229
            item = nautilus.MenuItem('BzrNautilus::newtree',
236
230
                                 'Make directory versioned',
237
231
                                 'Create new Bazaar tree in this folder')
239
233
            items.append(item)
240
234
 
241
235
            item = nautilus.MenuItem('BzrNautilus::clone',
242
 
                                 'Checkout Bazaar branch ...',
 
236
                                 'Checkout Bazaar branch',
243
237
                                 'Checkout Existing Bazaar Branch')
244
238
            item.connect('activate', self.clone_cb, vfs_file)
245
239
            items.append(item)
247
241
            return items
248
242
        except NoWorkingTree:
249
243
            return
250
 
        
251
 
        if disabled_flag == 'False':
252
 
            item = nautilus.MenuItem('BzrNautilus::enable',
253
 
                                     'Enable Bazaar Plugin for this Branch',
254
 
                                     'Enable Bazaar plugin for nautilus')
255
 
            item.connect('activate', self.toggle_integration, 'True', vfs_file)
256
 
            return item,
257
 
        else:
258
 
            item = nautilus.MenuItem('BzrNautilus::disable',
259
 
                                      'Disable Bazaar Plugin this Branch',
260
 
                                      'Disable Bazaar plugin for nautilus')
261
 
            item.connect('activate', self.toggle_integration, 'False', vfs_file)
262
 
            items.append(item)
263
244
 
264
245
        item = nautilus.MenuItem('BzrNautilus::log',
265
 
                             'History ...',
 
246
                             'Log',
266
247
                             'Show Bazaar history')
267
248
        item.connect('activate', self.log_cb, vfs_file)
268
249
        items.append(item)
269
250
 
270
251
        item = nautilus.MenuItem('BzrNautilus::pull',
271
 
                             'Pull ...',
 
252
                             'Pull',
272
253
                             'Pull from another branch')
273
254
        item.connect('activate', self.pull_cb, vfs_file)
274
255
        items.append(item)
275
256
 
276
257
        item = nautilus.MenuItem('BzrNautilus::merge',
277
 
                             'Merge ...',
 
258
                             'Merge',
278
259
                             'Merge from another branch')
279
260
        item.connect('activate', self.merge_cb, vfs_file)
280
261
        items.append(item)
281
262
 
282
263
        item = nautilus.MenuItem('BzrNautilus::commit',
283
 
                             'Commit ...',
 
264
                             'Commit',
284
265
                             'Commit Changes')
285
266
        item.connect('activate', self.commit_cb, vfs_file)
286
267
        items.append(item)
289
270
 
290
271
    def get_file_items(self, window, files):
291
272
        items = []
292
 
        
 
273
 
293
274
        wtfiles = {}
294
275
        for vfs_file in files:
295
276
            # We can only cope with local files
299
280
            file = vfs_file.get_uri()
300
281
            try:
301
282
                tree, path = WorkingTree.open_containing(file)
302
 
                disabled_flag = self.check_branch_enabled(tree.branch)
303
283
            except NotBranchError:
304
 
                disabled_flag = self.check_branch_enabled()
305
284
                if not vfs_file.is_directory():
306
285
                    continue
307
 
 
308
 
                if disabled_flag == 'False':
309
 
                    return
310
 
 
311
286
                item = nautilus.MenuItem('BzrNautilus::newtree',
312
287
                                     'Make directory versioned',
313
288
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
343
318
                items.append(item)
344
319
            elif wtfiles[path] == 'V':
345
320
                item = nautilus.MenuItem('BzrNautilus::log',
346
 
                                 'History ...',
 
321
                                 'Log',
347
322
                                 'List changes')
348
323
                item.connect('activate', self.log_cb, vfs_file)
349
324
                items.append(item)
350
325
 
351
326
                item = nautilus.MenuItem('BzrNautilus::diff',
352
 
                                 'View Changes ...',
 
327
                                 'Diff',
353
328
                                 'Show differences')
354
329
                item.connect('activate', self.diff_cb, vfs_file)
355
330
                items.append(item)
361
336
                items.append(item)
362
337
 
363
338
                item = nautilus.MenuItem('BzrNautilus::annotate',
364
 
                             'Annotate ...',
 
339
                             'Annotate',
365
340
                             'Annotate File Data')
366
341
                item.connect('activate', self.annotate_cb, vfs_file)
367
342
                items.append(item)
368
343
 
369
344
                item = nautilus.MenuItem('BzrNautilus::commit',
370
 
                             'Commit ...',
 
345
                             'Commit',
371
346
                             'Commit Changes')
372
347
                item.connect('activate', self.commit_cb, vfs_file)
373
348
                items.append(item)
381
356
                               "Version control status"),
382
357
 
383
358
    def update_file_info(self, file):
384
 
 
385
359
        if file.get_uri_scheme() != 'file':
386
360
            return
387
361
        
390
364
        except NotBranchError:
391
365
            return
392
366
        except NoWorkingTree:
393
 
            return   
394
 
 
395
 
        disabled_flag = self.check_branch_enabled(tree.branch)
396
 
        if disabled_flag == 'False':
397
367
            return
398
368
 
399
369
        emblem = None
423
393
        else:
424
394
            # FIXME: Check for ignored files
425
395
            status = 'unversioned'
 
396
            emblem = 'bzr-unversioned'
426
397
        
427
398
        if emblem is not None:
428
399
            file.add_emblem(emblem)
429
400
        file.add_string_attribute('bzr_status', status)
430
 
 
431
 
    def check_branch_enabled(self, branch=None):
432
 
        # Supports global disable, but there is currently no UI to do this
433
 
        config = GlobalConfig()
434
 
        disabled_flag = config.get_user_option('nautilus_integration')
435
 
        if disabled_flag != 'False':
436
 
            if branch is not None:
437
 
                config = branch.get_config()
438
 
                disabled_flag = config.get_user_option('nautilus_integration')
439
 
        return disabled_flag
440
 
 
441
 
    def toggle_integration(self, menu, action, vfs_file=None):
442
 
        try:
443
 
            tree, path = WorkingTree.open_containing(vfs_file.get_uri())
444
 
        except NotBranchError:
445
 
            return
446
 
        except NoWorkingTree:
447
 
            return
448
 
        branch = tree.branch
449
 
        if branch is None:
450
 
            config = GlobalConfig()
451
 
        else:
452
 
            config = branch.get_config()
453
 
        config.set_user_option('nautilus_integration', action)
454