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):
149
139
file = vfs_file.get_uri()
153
141
tree, path = WorkingTree.open_containing(file)
155
except NotBranchError, e:
158
except NoWorkingTree, e:
161
(branch, path) = Branch.open_containing(path)
162
except NotBranchError, e:
142
except NotBranchError:
165
145
from bzrlib.plugins.gtk.commit import CommitDialog
166
146
dialog = CommitDialog(tree, path)
167
response = dialog.run()
168
if response != gtk.RESPONSE_NONE:
172
150
def log_cb(self, menu, vfs_file):
173
151
# We can only cope with local files
220
199
from bzrlib.plugins.gtk.merge import MergeDialog
221
200
dialog = MergeDialog(tree, path)
225
204
def get_background_items(self, window, vfs_file):
227
206
file = vfs_file.get_uri()
230
208
tree, path = WorkingTree.open_containing(file)
231
disabled_flag = self.check_branch_enabled(tree.branch)
232
except UnsupportedProtocol:
234
209
except NotBranchError:
235
disabled_flag = self.check_branch_enabled()
236
210
item = nautilus.MenuItem('BzrNautilus::newtree',
237
211
'Make directory versioned',
238
212
'Create new Bazaar tree in this folder')
240
214
items.append(item)
242
216
item = nautilus.MenuItem('BzrNautilus::clone',
243
'Checkout Bazaar branch ...',
217
'Checkout Bazaar branch',
244
218
'Checkout Existing Bazaar Branch')
245
219
item.connect('activate', self.clone_cb, vfs_file)
246
220
items.append(item)
249
except NoWorkingTree:
252
if disabled_flag == 'False':
253
item = nautilus.MenuItem('BzrNautilus::enable',
254
'Enable Bazaar Plugin for this Branch',
255
'Enable Bazaar plugin for nautilus')
256
item.connect('activate', self.toggle_integration, 'True', vfs_file)
259
item = nautilus.MenuItem('BzrNautilus::disable',
260
'Disable Bazaar Plugin this Branch',
261
'Disable Bazaar plugin for nautilus')
262
item.connect('activate', self.toggle_integration, 'False', vfs_file)
265
224
item = nautilus.MenuItem('BzrNautilus::log',
267
226
'Show Bazaar history')
268
227
item.connect('activate', self.log_cb, vfs_file)
269
228
items.append(item)
271
230
item = nautilus.MenuItem('BzrNautilus::pull',
273
232
'Pull from another branch')
274
233
item.connect('activate', self.pull_cb, vfs_file)
275
234
items.append(item)
277
236
item = nautilus.MenuItem('BzrNautilus::merge',
279
238
'Merge from another branch')
280
239
item.connect('activate', self.merge_cb, vfs_file)
281
240
items.append(item)
283
242
item = nautilus.MenuItem('BzrNautilus::commit',
285
244
'Commit Changes')
286
245
item.connect('activate', self.commit_cb, vfs_file)
287
246
items.append(item)
291
251
def get_file_items(self, window, files):
295
254
for vfs_file in files:
296
255
# We can only cope with local files
297
256
if vfs_file.get_uri_scheme() != 'file':
300
259
file = vfs_file.get_uri()
302
261
tree, path = WorkingTree.open_containing(file)
303
disabled_flag = self.check_branch_enabled(tree.branch)
304
262
except NotBranchError:
305
disabled_flag = self.check_branch_enabled()
306
263
if not vfs_file.is_directory():
309
if disabled_flag == 'False':
312
265
item = nautilus.MenuItem('BzrNautilus::newtree',
313
266
'Make directory versioned',
314
267
'Create new Bazaar tree in %s' % vfs_file.get_name())
315
268
item.connect('activate', self.newtree_cb, vfs_file)
317
except NoWorkingTree:
319
# Refresh the list of filestatuses in the working tree
320
if path not in wtfiles.keys():
322
for rpath, file_class, kind, id, entry in tree.list_files():
323
wtfiles[rpath] = file_class
327
if wtfiles[path] == '?':
271
file_class = tree.file_class(path)
273
if file_class == '?':
328
274
item = nautilus.MenuItem('BzrNautilus::add',
330
276
'Add as versioned file')
336
282
'Ignore file for versioning')
337
283
item.connect('activate', self.ignore_cb, vfs_file)
338
284
items.append(item)
339
elif wtfiles[path] == 'I':
285
elif file_class == 'I':
340
286
item = nautilus.MenuItem('BzrNautilus::unignore',
342
288
'Unignore file for versioning')
343
289
item.connect('activate', self.unignore_cb, vfs_file)
344
290
items.append(item)
345
elif wtfiles[path] == 'V':
291
elif file_class == 'V':
346
292
item = nautilus.MenuItem('BzrNautilus::log',
349
295
item.connect('activate', self.log_cb, vfs_file)
350
296
items.append(item)
352
298
item = nautilus.MenuItem('BzrNautilus::diff',
354
300
'Show differences')
355
301
item.connect('activate', self.diff_cb, vfs_file)
356
302
items.append(item)
390
335
tree, path = WorkingTree.open_containing(file.get_uri())
391
336
except NotBranchError:
393
except NoWorkingTree:
396
disabled_flag = self.check_branch_enabled(tree.branch)
397
if disabled_flag == 'False':
403
342
if tree.has_filename(path):
404
emblem = 'bzr-controlled'
343
emblem = 'cvs-controlled'
405
344
status = 'unchanged'
406
345
id = tree.path2id(path)
408
347
delta = tree.changes_from(tree.branch.basis_tree())
409
348
if delta.touches_file_id(id):
410
emblem = 'bzr-modified'
349
emblem = 'cvs-modified'
411
350
status = 'modified'
412
351
for f, _, _ in delta.added:
417
356
for of, f, _, _, _, _ in delta.renamed:
428
367
if emblem is not None:
429
368
file.add_emblem(emblem)
430
369
file.add_string_attribute('bzr_status', status)
432
def check_branch_enabled(self, branch=None):
433
# Supports global disable, but there is currently no UI to do this
434
config = GlobalConfig()
435
disabled_flag = config.get_user_option('nautilus_integration')
436
if disabled_flag != 'False':
437
if branch is not None:
438
config = branch.get_config()
439
disabled_flag = config.get_user_option('nautilus_integration')
442
def toggle_integration(self, menu, action, vfs_file=None):
444
tree, path = WorkingTree.open_containing(vfs_file.get_uri())
445
except NotBranchError:
447
except NoWorkingTree:
451
config = GlobalConfig()
453
config = branch.get_config()
454
config.set_user_option('nautilus_integration', action)