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
19
18
from bzrlib.plugin import load_plugins
22
from bzrlib.plugins.gtk import _i18n
23
from bzrlib.plugins.gtk.commands import cmd_gannotate, start_viz_window
25
print "Bazaar nautilus module initialized"
21
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
28
23
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
29
24
def __init__(self):
88
83
from bzrlib.plugins.gtk.diff import DiffWindow
89
84
window = DiffWindow()
90
window.set_diff(tree.branch._get_nick(local=True), tree,
91
tree.branch.basis_tree())
85
window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
180
174
# We only want to continue here if we get a NotBranchError
182
branch, path = Branch.open_containing(file)
176
tree, path = WorkingTree.open_containing(file)
183
177
except NotBranchError:
186
pp = start_viz_window(branch, [branch.last_revision()])
180
vis = cmd_visualise()
190
185
def pull_cb(self, menu, vfs_file):
191
186
# We can only cope with local files
221
216
from bzrlib.plugins.gtk.merge import MergeDialog
222
217
dialog = MergeDialog(tree, path)
226
221
def get_background_items(self, window, vfs_file):
228
223
file = vfs_file.get_uri()
231
225
tree, path = WorkingTree.open_containing(file)
232
disabled_flag = self.check_branch_enabled(tree.branch)
233
226
except UnsupportedProtocol:
235
228
except NotBranchError:
236
disabled_flag = self.check_branch_enabled()
237
229
item = nautilus.MenuItem('BzrNautilus::newtree',
238
230
'Make directory versioned',
239
231
'Create new Bazaar tree in this folder')
241
233
items.append(item)
243
235
item = nautilus.MenuItem('BzrNautilus::clone',
244
'Checkout Bazaar branch ...',
236
'Checkout Bazaar branch',
245
237
'Checkout Existing Bazaar Branch')
246
238
item.connect('activate', self.clone_cb, vfs_file)
247
239
items.append(item)
250
242
except NoWorkingTree:
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)
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)
266
245
item = nautilus.MenuItem('BzrNautilus::log',
268
247
'Show Bazaar history')
269
248
item.connect('activate', self.log_cb, vfs_file)
270
249
items.append(item)
272
251
item = nautilus.MenuItem('BzrNautilus::pull',
274
253
'Pull from another branch')
275
254
item.connect('activate', self.pull_cb, vfs_file)
276
255
items.append(item)
278
257
item = nautilus.MenuItem('BzrNautilus::merge',
280
259
'Merge from another branch')
281
260
item.connect('activate', self.merge_cb, vfs_file)
282
261
items.append(item)
284
263
item = nautilus.MenuItem('BzrNautilus::commit',
286
265
'Commit Changes')
287
266
item.connect('activate', self.commit_cb, vfs_file)
288
267
items.append(item)
301
280
file = vfs_file.get_uri()
303
282
tree, path = WorkingTree.open_containing(file)
304
disabled_flag = self.check_branch_enabled(tree.branch)
305
283
except NotBranchError:
306
disabled_flag = self.check_branch_enabled()
307
284
if not vfs_file.is_directory():
310
if disabled_flag == 'False':
313
286
item = nautilus.MenuItem('BzrNautilus::newtree',
314
287
'Make directory versioned',
315
288
'Create new Bazaar tree in %s' % vfs_file.get_name())
345
318
items.append(item)
346
319
elif wtfiles[path] == 'V':
347
320
item = nautilus.MenuItem('BzrNautilus::log',
350
323
item.connect('activate', self.log_cb, vfs_file)
351
324
items.append(item)
353
326
item = nautilus.MenuItem('BzrNautilus::diff',
355
328
'Show differences')
356
329
item.connect('activate', self.diff_cb, vfs_file)
357
330
items.append(item)
363
336
items.append(item)
365
338
item = nautilus.MenuItem('BzrNautilus::annotate',
367
340
'Annotate File Data')
368
341
item.connect('activate', self.annotate_cb, vfs_file)
369
342
items.append(item)
371
344
item = nautilus.MenuItem('BzrNautilus::commit',
373
346
'Commit Changes')
374
347
item.connect('activate', self.commit_cb, vfs_file)
375
348
items.append(item)
392
364
except NotBranchError:
394
366
except NoWorkingTree:
397
disabled_flag = self.check_branch_enabled(tree.branch)
398
if disabled_flag == 'False':
404
id = tree.path2id(path)
406
if tree.is_ignored(path):
408
emblem = 'bzr-ignored'
410
status = 'unversioned'
412
elif tree.has_filename(path):
372
if tree.has_filename(path):
413
373
emblem = 'bzr-controlled'
414
374
status = 'unchanged'
375
id = tree.path2id(path)
416
377
delta = tree.changes_from(tree.branch.basis_tree())
417
378
if delta.touches_file_id(id):
433
394
# FIXME: Check for ignored files
434
395
status = 'unversioned'
396
emblem = 'bzr-unversioned'
436
398
if emblem is not None:
437
399
file.add_emblem(emblem)
438
400
file.add_string_attribute('bzr_status', status)
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')
450
def toggle_integration(self, menu, action, vfs_file=None):
452
tree, path = WorkingTree.open_containing(vfs_file.get_uri())
453
except NotBranchError:
455
except NoWorkingTree:
459
config = GlobalConfig()
461
config = branch.get_config()
462
config.set_user_option('nautilus_integration', action)