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, cmd_gannotate, start_viz_window
24
print "Bazaar nautilus module initialized"
21
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
27
23
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
28
24
def __init__(self):
178
174
# We only want to continue here if we get a NotBranchError
180
branch, path = Branch.open_containing(file)
176
tree, path = WorkingTree.open_containing(file)
181
177
except NotBranchError:
184
pp = start_viz_window(branch, [branch.last_revision()])
180
vis = cmd_visualise()
188
185
def pull_cb(self, menu, vfs_file):
189
186
# We can only cope with local files
219
216
from bzrlib.plugins.gtk.merge import MergeDialog
220
217
dialog = MergeDialog(tree, path)
224
221
def get_background_items(self, window, vfs_file):
226
223
file = vfs_file.get_uri()
229
225
tree, path = WorkingTree.open_containing(file)
230
disabled_flag = self.check_branch_enabled(tree.branch)
231
226
except UnsupportedProtocol:
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)
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)
248
242
except NoWorkingTree:
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)
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)
264
245
item = nautilus.MenuItem('BzrNautilus::log',
266
247
'Show Bazaar history')
267
248
item.connect('activate', self.log_cb, vfs_file)
268
249
items.append(item)
270
251
item = nautilus.MenuItem('BzrNautilus::pull',
272
253
'Pull from another branch')
273
254
item.connect('activate', self.pull_cb, vfs_file)
274
255
items.append(item)
276
257
item = nautilus.MenuItem('BzrNautilus::merge',
278
259
'Merge from another branch')
279
260
item.connect('activate', self.merge_cb, vfs_file)
280
261
items.append(item)
282
263
item = nautilus.MenuItem('BzrNautilus::commit',
284
265
'Commit Changes')
285
266
item.connect('activate', self.commit_cb, vfs_file)
286
267
items.append(item)
299
280
file = vfs_file.get_uri()
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():
308
if disabled_flag == 'False':
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',
348
323
item.connect('activate', self.log_cb, vfs_file)
349
324
items.append(item)
351
326
item = nautilus.MenuItem('BzrNautilus::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)
363
338
item = nautilus.MenuItem('BzrNautilus::annotate',
365
340
'Annotate File Data')
366
341
item.connect('activate', self.annotate_cb, vfs_file)
367
342
items.append(item)
369
344
item = nautilus.MenuItem('BzrNautilus::commit',
371
346
'Commit Changes')
372
347
item.connect('activate', self.commit_cb, vfs_file)
373
348
items.append(item)
424
394
# FIXME: Check for ignored files
425
395
status = 'unversioned'
396
emblem = 'bzr-unversioned'
427
398
if emblem is not None:
428
399
file.add_emblem(emblem)
429
400
file.add_string_attribute('bzr_status', status)
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')
441
def toggle_integration(self, menu, action, vfs_file=None):
443
tree, path = WorkingTree.open_containing(vfs_file.get_uri())
444
except NotBranchError:
446
except NoWorkingTree:
450
config = GlobalConfig()
452
config = branch.get_config()
453
config.set_user_option('nautilus_integration', action)