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.branch import Branch
13
11
from bzrlib.bzrdir import BzrDir
14
from bzrlib.errors import NotBranchError, NoWorkingTree, UnsupportedProtocol
12
from bzrlib.errors import NotBranchError
13
from bzrlib.workingtree import WorkingTree
15
14
from bzrlib.tree import file_status
16
from bzrlib.workingtree import WorkingTree
17
from bzrlib.config import GlobalConfig
19
16
from bzrlib.plugin import load_plugins
22
from bzrlib.plugins.gtk import _i18n, cmd_gannotate, start_viz_window
24
print "Bazaar nautilus module initialized"
19
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
27
21
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
28
22
def __init__(self):
148
139
file = vfs_file.get_uri()
152
141
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:
142
except NotBranchError:
164
145
from bzrlib.plugins.gtk.commit import CommitDialog
165
146
dialog = CommitDialog(tree, path)
166
response = dialog.run()
167
if response != gtk.RESPONSE_NONE:
171
150
def log_cb(self, menu, vfs_file):
172
151
# We can only cope with local files
219
199
from bzrlib.plugins.gtk.merge import MergeDialog
220
200
dialog = MergeDialog(tree, path)
224
204
def get_background_items(self, window, vfs_file):
226
206
file = vfs_file.get_uri()
229
208
tree, path = WorkingTree.open_containing(file)
230
disabled_flag = self.check_branch_enabled(tree.branch)
231
except UnsupportedProtocol:
233
209
except NotBranchError:
234
disabled_flag = self.check_branch_enabled()
235
210
item = nautilus.MenuItem('BzrNautilus::newtree',
236
211
'Make directory versioned',
237
212
'Create new Bazaar tree in this folder')
239
214
items.append(item)
241
216
item = nautilus.MenuItem('BzrNautilus::clone',
242
'Checkout Bazaar branch ...',
217
'Checkout Bazaar branch',
243
218
'Checkout Existing Bazaar Branch')
244
219
item.connect('activate', self.clone_cb, vfs_file)
245
220
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
224
item = nautilus.MenuItem('BzrNautilus::log',
266
226
'Show Bazaar history')
267
227
item.connect('activate', self.log_cb, vfs_file)
268
228
items.append(item)
270
230
item = nautilus.MenuItem('BzrNautilus::pull',
272
232
'Pull from another branch')
273
233
item.connect('activate', self.pull_cb, vfs_file)
274
234
items.append(item)
276
236
item = nautilus.MenuItem('BzrNautilus::merge',
278
238
'Merge from another branch')
279
239
item.connect('activate', self.merge_cb, vfs_file)
280
240
items.append(item)
282
242
item = nautilus.MenuItem('BzrNautilus::commit',
284
244
'Commit Changes')
285
245
item.connect('activate', self.commit_cb, vfs_file)
286
246
items.append(item)
290
251
def get_file_items(self, window, files):
294
254
for vfs_file in files:
295
255
# We can only cope with local files
296
256
if vfs_file.get_uri_scheme() != 'file':
299
259
file = vfs_file.get_uri()
301
261
tree, path = WorkingTree.open_containing(file)
302
disabled_flag = self.check_branch_enabled(tree.branch)
303
262
except NotBranchError:
304
disabled_flag = self.check_branch_enabled()
305
263
if not vfs_file.is_directory():
308
if disabled_flag == 'False':
311
265
item = nautilus.MenuItem('BzrNautilus::newtree',
312
266
'Make directory versioned',
313
267
'Create new Bazaar tree in %s' % vfs_file.get_name())
314
268
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] == '?':
271
file_class = tree.file_class(path)
273
if file_class == '?':
327
274
item = nautilus.MenuItem('BzrNautilus::add',
329
276
'Add as versioned file')
335
282
'Ignore file for versioning')
336
283
item.connect('activate', self.ignore_cb, vfs_file)
337
284
items.append(item)
338
elif wtfiles[path] == 'I':
285
elif file_class == 'I':
339
286
item = nautilus.MenuItem('BzrNautilus::unignore',
341
288
'Unignore file for versioning')
342
289
item.connect('activate', self.unignore_cb, vfs_file)
343
290
items.append(item)
344
elif wtfiles[path] == 'V':
291
elif file_class == 'V':
345
292
item = nautilus.MenuItem('BzrNautilus::log',
348
295
item.connect('activate', self.log_cb, vfs_file)
349
296
items.append(item)
351
298
item = nautilus.MenuItem('BzrNautilus::diff',
353
300
'Show differences')
354
301
item.connect('activate', self.diff_cb, vfs_file)
355
302
items.append(item)
389
335
tree, path = WorkingTree.open_containing(file.get_uri())
390
336
except NotBranchError:
392
except NoWorkingTree:
395
disabled_flag = self.check_branch_enabled(tree.branch)
396
if disabled_flag == 'False':
402
342
if tree.has_filename(path):
403
emblem = 'bzr-controlled'
343
emblem = 'cvs-controlled'
404
344
status = 'unchanged'
405
345
id = tree.path2id(path)
407
347
delta = tree.changes_from(tree.branch.basis_tree())
408
348
if delta.touches_file_id(id):
409
emblem = 'bzr-modified'
349
emblem = 'cvs-modified'
410
350
status = 'modified'
411
351
for f, _, _ in delta.added:
416
356
for of, f, _, _, _, _ in delta.renamed:
427
367
if emblem is not None:
428
368
file.add_emblem(emblem)
429
369
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)