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
11
from bzrlib.branch import Branch
12
11
from bzrlib.bzrdir import BzrDir
13
from bzrlib.errors import (
12
from bzrlib.errors import NotBranchError
18
13
from bzrlib.workingtree import WorkingTree
19
from bzrlib.config import GlobalConfig
14
from bzrlib.tree import file_status
21
16
from bzrlib.plugin import load_plugins
24
from bzrlib.plugins.gtk.commands import (
29
print "Bazaar nautilus module initialized"
19
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
32
21
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
34
22
def __init__(self):
155
139
file = vfs_file.get_uri()
159
141
tree, path = WorkingTree.open_containing(file)
161
except NotBranchError, e:
164
except NoWorkingTree, e:
167
(branch, path) = Branch.open_containing(path)
168
except NotBranchError, e:
142
except NotBranchError:
171
145
from bzrlib.plugins.gtk.commit import CommitDialog
172
146
dialog = CommitDialog(tree, path)
173
response = dialog.run()
174
if response != gtk.RESPONSE_NONE:
178
150
def log_cb(self, menu, vfs_file):
179
151
# We can only cope with local files
226
199
from bzrlib.plugins.gtk.merge import MergeDialog
227
200
dialog = MergeDialog(tree, path)
231
204
def get_background_items(self, window, vfs_file):
233
206
file = vfs_file.get_uri()
236
208
tree, path = WorkingTree.open_containing(file)
237
disabled_flag = self.check_branch_enabled(tree.branch)
238
except UnsupportedProtocol:
240
209
except NotBranchError:
241
disabled_flag = self.check_branch_enabled()
242
210
item = nautilus.MenuItem('BzrNautilus::newtree',
243
211
'Make directory versioned',
244
212
'Create new Bazaar tree in this folder')
246
214
items.append(item)
248
216
item = nautilus.MenuItem('BzrNautilus::clone',
249
'Checkout Bazaar branch ...',
217
'Checkout Bazaar branch',
250
218
'Checkout Existing Bazaar Branch')
251
219
item.connect('activate', self.clone_cb, vfs_file)
252
220
items.append(item)
255
except NoWorkingTree:
258
if disabled_flag == 'False':
259
item = nautilus.MenuItem('BzrNautilus::enable',
260
'Enable Bazaar Plugin for this Branch',
261
'Enable Bazaar plugin for nautilus')
262
item.connect('activate', self.toggle_integration, 'True', vfs_file)
265
item = nautilus.MenuItem('BzrNautilus::disable',
266
'Disable Bazaar Plugin this Branch',
267
'Disable Bazaar plugin for nautilus')
268
item.connect('activate', self.toggle_integration, 'False', vfs_file)
271
224
item = nautilus.MenuItem('BzrNautilus::log',
273
226
'Show Bazaar history')
274
227
item.connect('activate', self.log_cb, vfs_file)
275
228
items.append(item)
277
230
item = nautilus.MenuItem('BzrNautilus::pull',
279
232
'Pull from another branch')
280
233
item.connect('activate', self.pull_cb, vfs_file)
281
234
items.append(item)
283
236
item = nautilus.MenuItem('BzrNautilus::merge',
285
238
'Merge from another branch')
286
239
item.connect('activate', self.merge_cb, vfs_file)
287
240
items.append(item)
289
242
item = nautilus.MenuItem('BzrNautilus::commit',
291
244
'Commit Changes')
292
245
item.connect('activate', self.commit_cb, vfs_file)
293
246
items.append(item)
297
251
def get_file_items(self, window, files):
301
254
for vfs_file in files:
302
255
# We can only cope with local files
303
256
if vfs_file.get_uri_scheme() != 'file':
306
259
file = vfs_file.get_uri()
308
261
tree, path = WorkingTree.open_containing(file)
309
disabled_flag = self.check_branch_enabled(tree.branch)
310
262
except NotBranchError:
311
disabled_flag = self.check_branch_enabled()
312
263
if not vfs_file.is_directory():
315
if disabled_flag == 'False':
318
265
item = nautilus.MenuItem('BzrNautilus::newtree',
319
266
'Make directory versioned',
320
267
'Create new Bazaar tree in %s' % vfs_file.get_name())
321
268
item.connect('activate', self.newtree_cb, vfs_file)
323
except NoWorkingTree:
325
# Refresh the list of filestatuses in the working tree
326
if path not in wtfiles.keys():
328
for rpath, file_class, kind, id, entry in tree.list_files():
329
wtfiles[rpath] = file_class
333
if wtfiles[path] == '?':
271
file_class = tree.file_class(path)
273
if file_class == '?':
334
274
item = nautilus.MenuItem('BzrNautilus::add',
336
276
'Add as versioned file')
342
282
'Ignore file for versioning')
343
283
item.connect('activate', self.ignore_cb, vfs_file)
344
284
items.append(item)
345
elif wtfiles[path] == 'I':
285
elif file_class == 'I':
346
286
item = nautilus.MenuItem('BzrNautilus::unignore',
348
288
'Unignore file for versioning')
349
289
item.connect('activate', self.unignore_cb, vfs_file)
350
290
items.append(item)
351
elif wtfiles[path] == 'V':
291
elif file_class == 'V':
352
292
item = nautilus.MenuItem('BzrNautilus::log',
355
295
item.connect('activate', self.log_cb, vfs_file)
356
296
items.append(item)
358
298
item = nautilus.MenuItem('BzrNautilus::diff',
360
300
'Show differences')
361
301
item.connect('activate', self.diff_cb, vfs_file)
362
302
items.append(item)
396
335
tree, path = WorkingTree.open_containing(file.get_uri())
397
336
except NotBranchError:
399
except NoWorkingTree:
402
disabled_flag = self.check_branch_enabled(tree.branch)
403
if disabled_flag == 'False':
409
id = tree.path2id(path)
411
if tree.is_ignored(path):
413
emblem = 'bzr-ignored'
415
status = 'unversioned'
417
elif tree.has_filename(path):
418
emblem = 'bzr-controlled'
342
if tree.has_filename(path):
343
emblem = 'cvs-controlled'
419
344
status = 'unchanged'
345
id = tree.path2id(path)
421
347
delta = tree.changes_from(tree.branch.basis_tree())
422
348
if delta.touches_file_id(id):
423
emblem = 'bzr-modified'
349
emblem = 'cvs-modified'
424
350
status = 'modified'
425
351
for f, _, _ in delta.added:
430
356
for of, f, _, _, _, _ in delta.renamed:
441
367
if emblem is not None:
442
368
file.add_emblem(emblem)
443
369
file.add_string_attribute('bzr_status', status)
445
def check_branch_enabled(self, branch=None):
446
# Supports global disable, but there is currently no UI to do this
447
config = GlobalConfig()
448
disabled_flag = config.get_user_option('nautilus_integration')
449
if disabled_flag != 'False':
450
if branch is not None:
451
config = branch.get_config()
452
disabled_flag = config.get_user_option('nautilus_integration')
455
def toggle_integration(self, menu, action, vfs_file=None):
457
tree, path = WorkingTree.open_containing(vfs_file.get_uri())
458
except NotBranchError:
460
except NoWorkingTree:
464
config = GlobalConfig()
466
config = branch.get_config()
467
config.set_user_option('nautilus_integration', action)