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
7
7
# Published under the GNU GPL
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
19
20
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"
23
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
28
25
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
29
26
def __init__(self):
180
176
# We only want to continue here if we get a NotBranchError
182
branch, path = Branch.open_containing(file)
178
tree, path = WorkingTree.open_containing(file)
183
179
except NotBranchError:
186
pp = start_viz_window(branch, [branch.last_revision()])
182
vis = cmd_visualise()
190
187
def pull_cb(self, menu, vfs_file):
191
188
# We can only cope with local files
221
218
from bzrlib.plugins.gtk.merge import MergeDialog
222
219
dialog = MergeDialog(tree, path)
226
223
def get_background_items(self, window, vfs_file):
228
225
file = vfs_file.get_uri()
231
227
tree, path = WorkingTree.open_containing(file)
232
disabled_flag = self.check_branch_enabled(tree.branch)
233
228
except UnsupportedProtocol:
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)
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)
250
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)
292
272
def get_file_items(self, window, files):
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':
301
281
file = vfs_file.get_uri()
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():
310
if disabled_flag == 'False':
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)
318
except NoWorkingTree:
320
292
# Refresh the list of filestatuses in the working tree
321
293
if path not in wtfiles.keys():
345
317
items.append(item)
346
318
elif wtfiles[path] == 'V':
347
319
item = nautilus.MenuItem('BzrNautilus::log',
350
322
item.connect('activate', self.log_cb, vfs_file)
351
323
items.append(item)
353
325
item = nautilus.MenuItem('BzrNautilus::diff',
355
327
'Show differences')
356
328
item.connect('activate', self.diff_cb, vfs_file)
357
329
items.append(item)
391
362
tree, path = WorkingTree.open_containing(file.get_uri())
392
363
except NotBranchError:
394
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):
413
emblem = 'bzr-controlled'
369
if tree.has_filename(path):
370
emblem = 'cvs-controlled'
414
371
status = 'unchanged'
372
id = tree.path2id(path)
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:
425
383
for of, f, _, _, _, _ in delta.renamed:
436
394
if emblem is not None:
437
395
file.add_emblem(emblem)
438
396
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)