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, cmd_gannotate, start_viz_window
24
print "Bazaar nautilus module initialized"
11
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
27
13
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
28
14
def __init__(self):
148
131
file = vfs_file.get_uri()
152
133
tree, path = WorkingTree.open_containing(file)
154
except NotBranchError, e:
157
except NoWorkingTree, e:
160
(branch, path) = Branch.open_containing(path)
161
except NotBranchError, e:
134
except NotBranchError:
164
from bzrlib.plugins.gtk.commit import CommitDialog
137
from bzrlib.plugins.gtk.olive.commit import CommitDialog
165
138
dialog = CommitDialog(tree, path)
166
response = dialog.run()
167
if response != gtk.RESPONSE_NONE:
171
142
def log_cb(self, menu, vfs_file):
172
143
# We can only cope with local files
216
188
except NotBranchError:
219
from bzrlib.plugins.gtk.merge import MergeDialog
191
from bzrlib.plugins.gtk.olive.merge import MergeDialog
220
192
dialog = MergeDialog(tree, path)
224
196
def get_background_items(self, window, vfs_file):
226
198
file = vfs_file.get_uri()
229
200
tree, path = WorkingTree.open_containing(file)
230
disabled_flag = self.check_branch_enabled(tree.branch)
231
except UnsupportedProtocol:
233
201
except NotBranchError:
234
disabled_flag = self.check_branch_enabled()
235
202
item = nautilus.MenuItem('BzrNautilus::newtree',
236
203
'Make directory versioned',
237
204
'Create new Bazaar tree in this folder')
239
206
items.append(item)
241
208
item = nautilus.MenuItem('BzrNautilus::clone',
242
'Checkout Bazaar branch ...',
209
'Checkout Bazaar branch',
243
210
'Checkout Existing Bazaar Branch')
244
211
item.connect('activate', self.clone_cb, vfs_file)
245
212
items.append(item)
248
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
216
item = nautilus.MenuItem('BzrNautilus::log',
266
218
'Show Bazaar history')
267
219
item.connect('activate', self.log_cb, vfs_file)
268
220
items.append(item)
270
222
item = nautilus.MenuItem('BzrNautilus::pull',
272
224
'Pull from another branch')
273
225
item.connect('activate', self.pull_cb, vfs_file)
274
226
items.append(item)
276
228
item = nautilus.MenuItem('BzrNautilus::merge',
278
230
'Merge from another branch')
279
231
item.connect('activate', self.merge_cb, vfs_file)
280
232
items.append(item)
282
234
item = nautilus.MenuItem('BzrNautilus::commit',
284
236
'Commit Changes')
285
237
item.connect('activate', self.commit_cb, vfs_file)
286
238
items.append(item)
290
243
def get_file_items(self, window, files):
294
246
for vfs_file in files:
295
247
# We can only cope with local files
296
248
if vfs_file.get_uri_scheme() != 'file':
299
251
file = vfs_file.get_uri()
301
253
tree, path = WorkingTree.open_containing(file)
302
disabled_flag = self.check_branch_enabled(tree.branch)
303
254
except NotBranchError:
304
disabled_flag = self.check_branch_enabled()
305
255
if not vfs_file.is_directory():
308
if disabled_flag == 'False':
311
257
item = nautilus.MenuItem('BzrNautilus::newtree',
312
258
'Make directory versioned',
313
259
'Create new Bazaar tree in %s' % vfs_file.get_name())
314
260
item.connect('activate', self.newtree_cb, vfs_file)
316
except NoWorkingTree:
318
# Refresh the list of filestatuses in the working tree
319
if path not in wtfiles.keys():
321
for rpath, file_class, kind, id, entry in tree.list_files():
322
wtfiles[rpath] = file_class
326
if wtfiles[path] == '?':
263
file_class = tree.file_class(path)
265
if file_class == '?':
327
266
item = nautilus.MenuItem('BzrNautilus::add',
329
268
'Add as versioned file')
335
274
'Ignore file for versioning')
336
275
item.connect('activate', self.ignore_cb, vfs_file)
337
276
items.append(item)
338
elif wtfiles[path] == 'I':
277
elif file_class == 'I':
339
278
item = nautilus.MenuItem('BzrNautilus::unignore',
341
280
'Unignore file for versioning')
342
281
item.connect('activate', self.unignore_cb, vfs_file)
343
282
items.append(item)
344
elif wtfiles[path] == 'V':
283
elif file_class == 'V':
345
284
item = nautilus.MenuItem('BzrNautilus::log',
348
287
item.connect('activate', self.log_cb, vfs_file)
349
288
items.append(item)
351
290
item = nautilus.MenuItem('BzrNautilus::diff',
353
292
'Show differences')
354
293
item.connect('activate', self.diff_cb, vfs_file)
355
294
items.append(item)
389
327
tree, path = WorkingTree.open_containing(file.get_uri())
390
328
except NotBranchError:
392
except NoWorkingTree:
395
disabled_flag = self.check_branch_enabled(tree.branch)
396
if disabled_flag == 'False':
402
334
if tree.has_filename(path):
403
emblem = 'bzr-controlled'
335
emblem = 'cvs-controlled'
404
336
status = 'unchanged'
405
337
id = tree.path2id(path)
407
339
delta = tree.changes_from(tree.branch.basis_tree())
408
340
if delta.touches_file_id(id):
409
emblem = 'bzr-modified'
341
emblem = 'cvs-modified'
410
342
status = 'modified'
411
343
for f, _, _ in delta.added:
416
348
for of, f, _, _, _, _ in delta.renamed:
427
359
if emblem is not None:
428
360
file.add_emblem(emblem)
429
361
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)