1
# Trivial Bazaar plugin for Nautilus
3
# Copyright (C) 2006 Jeff Bailey
4
# Copyright (C) 2006 Wouter van Heyst
5
# Copyright (C) 2006-2008 Jelmer Vernooij <jelmer@samba.org>
7
# Published under the GNU GPL
12
from bzrlib.branch import Branch
13
3
from bzrlib.bzrdir import BzrDir
14
from bzrlib.errors import NotBranchError, NoWorkingTree, UnsupportedProtocol
4
from bzrlib.errors import NotBranchError
5
from bzrlib.workingtree import WorkingTree
15
6
from bzrlib.tree import file_status
16
from bzrlib.workingtree import WorkingTree
17
from bzrlib.config import GlobalConfig
19
8
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"
11
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
28
13
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
29
14
def __init__(self):
150
131
file = vfs_file.get_uri()
154
133
tree, path = WorkingTree.open_containing(file)
156
except NotBranchError, e:
159
except NoWorkingTree, e:
162
(branch, path) = Branch.open_containing(path)
163
except NotBranchError, e:
134
except NotBranchError:
166
137
from bzrlib.plugins.gtk.commit import CommitDialog
167
138
dialog = CommitDialog(tree, path)
168
response = dialog.run()
169
if response != gtk.RESPONSE_NONE:
173
142
def log_cb(self, menu, vfs_file):
174
143
# We can only cope with local files
221
191
from bzrlib.plugins.gtk.merge import MergeDialog
222
192
dialog = MergeDialog(tree, path)
226
196
def get_background_items(self, window, vfs_file):
228
198
file = vfs_file.get_uri()
231
200
tree, path = WorkingTree.open_containing(file)
232
disabled_flag = self.check_branch_enabled(tree.branch)
233
except UnsupportedProtocol:
235
201
except NotBranchError:
236
disabled_flag = self.check_branch_enabled()
237
202
item = nautilus.MenuItem('BzrNautilus::newtree',
238
203
'Make directory versioned',
239
204
'Create new Bazaar tree in this folder')
241
206
items.append(item)
243
208
item = nautilus.MenuItem('BzrNautilus::clone',
244
'Checkout Bazaar branch ...',
209
'Checkout Bazaar branch',
245
210
'Checkout Existing Bazaar Branch')
246
211
item.connect('activate', self.clone_cb, vfs_file)
247
212
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
216
item = nautilus.MenuItem('BzrNautilus::log',
268
218
'Show Bazaar history')
269
219
item.connect('activate', self.log_cb, vfs_file)
270
220
items.append(item)
272
222
item = nautilus.MenuItem('BzrNautilus::pull',
274
224
'Pull from another branch')
275
225
item.connect('activate', self.pull_cb, vfs_file)
276
226
items.append(item)
278
228
item = nautilus.MenuItem('BzrNautilus::merge',
280
230
'Merge from another branch')
281
231
item.connect('activate', self.merge_cb, vfs_file)
282
232
items.append(item)
284
234
item = nautilus.MenuItem('BzrNautilus::commit',
286
236
'Commit Changes')
287
237
item.connect('activate', self.commit_cb, vfs_file)
288
238
items.append(item)
292
243
def get_file_items(self, window, files):
296
246
for vfs_file in files:
297
247
# We can only cope with local files
298
248
if vfs_file.get_uri_scheme() != 'file':
301
251
file = vfs_file.get_uri()
303
253
tree, path = WorkingTree.open_containing(file)
304
disabled_flag = self.check_branch_enabled(tree.branch)
305
254
except NotBranchError:
306
disabled_flag = self.check_branch_enabled()
307
255
if not vfs_file.is_directory():
310
if disabled_flag == 'False':
313
257
item = nautilus.MenuItem('BzrNautilus::newtree',
314
258
'Make directory versioned',
315
259
'Create new Bazaar tree in %s' % vfs_file.get_name())
316
260
item.connect('activate', self.newtree_cb, vfs_file)
318
except NoWorkingTree:
320
# Refresh the list of filestatuses in the working tree
321
if path not in wtfiles.keys():
323
for rpath, file_class, kind, id, entry in tree.list_files():
324
wtfiles[rpath] = file_class
328
if wtfiles[path] == '?':
263
file_class = tree.file_class(path)
265
if file_class == '?':
329
266
item = nautilus.MenuItem('BzrNautilus::add',
331
268
'Add as versioned file')
337
274
'Ignore file for versioning')
338
275
item.connect('activate', self.ignore_cb, vfs_file)
339
276
items.append(item)
340
elif wtfiles[path] == 'I':
277
elif file_class == 'I':
341
278
item = nautilus.MenuItem('BzrNautilus::unignore',
343
280
'Unignore file for versioning')
344
281
item.connect('activate', self.unignore_cb, vfs_file)
345
282
items.append(item)
346
elif wtfiles[path] == 'V':
283
elif file_class == 'V':
347
284
item = nautilus.MenuItem('BzrNautilus::log',
350
287
item.connect('activate', self.log_cb, vfs_file)
351
288
items.append(item)
353
290
item = nautilus.MenuItem('BzrNautilus::diff',
355
292
'Show differences')
356
293
item.connect('activate', self.diff_cb, vfs_file)
357
294
items.append(item)
391
327
tree, path = WorkingTree.open_containing(file.get_uri())
392
328
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'
334
if tree.has_filename(path):
335
emblem = 'cvs-controlled'
414
336
status = 'unchanged'
337
id = tree.path2id(path)
416
339
delta = tree.changes_from(tree.branch.basis_tree())
417
340
if delta.touches_file_id(id):
418
emblem = 'bzr-modified'
341
emblem = 'cvs-modified'
419
342
status = 'modified'
420
343
for f, _, _ in delta.added:
425
348
for of, f, _, _, _, _ in delta.renamed:
436
359
if emblem is not None:
437
360
file.add_emblem(emblem)
438
361
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)