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
from bzrlib.bzrdir import BzrDir
14
from bzrlib.errors import NotBranchError, NoWorkingTree, UnsupportedProtocol
15
from bzrlib.tree import file_status
16
from bzrlib.workingtree import WorkingTree
17
from bzrlib.config import GlobalConfig
19
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"
28
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
32
def add_cb(self, menu, vfs_file):
33
# We can only cope with local files
34
if vfs_file.get_uri_scheme() != 'file':
37
file = vfs_file.get_uri()
39
tree, path = WorkingTree.open_containing(file)
40
except NotBranchError:
47
def ignore_cb(self, menu, vfs_file):
48
# We can only cope with local files
49
if vfs_file.get_uri_scheme() != 'file':
52
file = vfs_file.get_uri()
54
tree, path = WorkingTree.open_containing(file)
55
except NotBranchError:
62
def unignore_cb(self, menu, vfs_file):
63
# We can only cope with local files
64
if vfs_file.get_uri_scheme() != 'file':
67
file = vfs_file.get_uri()
69
tree, path = WorkingTree.open_containing(file)
70
except NotBranchError:
77
def diff_cb(self, menu, vfs_file):
78
# We can only cope with local files
79
if vfs_file.get_uri_scheme() != 'file':
82
file = vfs_file.get_uri()
84
tree, path = WorkingTree.open_containing(file)
85
except NotBranchError:
88
from bzrlib.plugins.gtk.diff import DiffWindow
90
window.set_diff(tree.branch._get_nick(local=True), tree,
91
tree.branch.basis_tree())
96
def newtree_cb(self, menu, vfs_file):
97
# We can only cope with local files
98
if vfs_file.get_uri_scheme() != 'file':
101
file = vfs_file.get_uri()
103
# We only want to continue here if we get a NotBranchError
105
tree, path = WorkingTree.open_containing(file)
106
except NotBranchError:
107
BzrDir.create_standalone_workingtree(file)
109
def remove_cb(self, menu, vfs_file):
110
# We can only cope with local files
111
if vfs_file.get_uri_scheme() != 'file':
114
file = vfs_file.get_uri()
116
tree, path = WorkingTree.open_containing(file)
117
except NotBranchError:
122
def annotate_cb(self, menu, vfs_file):
123
# We can only cope with local files
124
if vfs_file.get_uri_scheme() != 'file':
127
file = vfs_file.get_uri()
129
vis = cmd_gannotate()
132
def clone_cb(self, menu, vfs_file=None):
133
# We can only cope with local files
134
if vfs_file.get_uri_scheme() != 'file':
137
from bzrlib.plugins.gtk.branch import BranchDialog
139
dialog = BranchDialog(vfs_file.get_name())
140
response = dialog.run()
141
if response != gtk.RESPONSE_NONE:
145
def commit_cb(self, menu, vfs_file=None):
146
# We can only cope with local files
147
if vfs_file.get_uri_scheme() != 'file':
150
file = vfs_file.get_uri()
154
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:
166
from bzrlib.plugins.gtk.commit import CommitDialog
167
dialog = CommitDialog(tree, path)
168
response = dialog.run()
169
if response != gtk.RESPONSE_NONE:
173
def log_cb(self, menu, vfs_file):
174
# We can only cope with local files
175
if vfs_file.get_uri_scheme() != 'file':
178
file = vfs_file.get_uri()
180
# We only want to continue here if we get a NotBranchError
182
branch, path = Branch.open_containing(file)
183
except NotBranchError:
186
pp = start_viz_window(branch, [branch.last_revision()])
190
def pull_cb(self, menu, vfs_file):
191
# We can only cope with local files
192
if vfs_file.get_uri_scheme() != 'file':
195
file = vfs_file.get_uri()
197
# We only want to continue here if we get a NotBranchError
199
tree, path = WorkingTree.open_containing(file)
200
except NotBranchError:
203
from bzrlib.plugins.gtk.pull import PullDialog
204
dialog = PullDialog(tree, path)
208
def merge_cb(self, menu, vfs_file):
209
# We can only cope with local files
210
if vfs_file.get_uri_scheme() != 'file':
213
file = vfs_file.get_uri()
215
# We only want to continue here if we get a NotBranchError
217
tree, path = WorkingTree.open_containing(file)
218
except NotBranchError:
221
from bzrlib.plugins.gtk.merge import MergeDialog
222
dialog = MergeDialog(tree, path)
226
def get_background_items(self, window, vfs_file):
228
file = vfs_file.get_uri()
231
tree, path = WorkingTree.open_containing(file)
232
disabled_flag = self.check_branch_enabled(tree.branch)
233
except UnsupportedProtocol:
235
except NotBranchError:
236
disabled_flag = self.check_branch_enabled()
237
item = nautilus.MenuItem('BzrNautilus::newtree',
238
'Make directory versioned',
239
'Create new Bazaar tree in this folder')
240
item.connect('activate', self.newtree_cb, vfs_file)
243
item = nautilus.MenuItem('BzrNautilus::clone',
244
'Checkout Bazaar branch ...',
245
'Checkout Existing Bazaar Branch')
246
item.connect('activate', self.clone_cb, vfs_file)
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
item = nautilus.MenuItem('BzrNautilus::log',
268
'Show Bazaar history')
269
item.connect('activate', self.log_cb, vfs_file)
272
item = nautilus.MenuItem('BzrNautilus::pull',
274
'Pull from another branch')
275
item.connect('activate', self.pull_cb, vfs_file)
278
item = nautilus.MenuItem('BzrNautilus::merge',
280
'Merge from another branch')
281
item.connect('activate', self.merge_cb, vfs_file)
284
item = nautilus.MenuItem('BzrNautilus::commit',
287
item.connect('activate', self.commit_cb, vfs_file)
292
def get_file_items(self, window, files):
296
for vfs_file in files:
297
# We can only cope with local files
298
if vfs_file.get_uri_scheme() != 'file':
301
file = vfs_file.get_uri()
303
tree, path = WorkingTree.open_containing(file)
304
disabled_flag = self.check_branch_enabled(tree.branch)
305
except NotBranchError:
306
disabled_flag = self.check_branch_enabled()
307
if not vfs_file.is_directory():
310
if disabled_flag == 'False':
313
item = nautilus.MenuItem('BzrNautilus::newtree',
314
'Make directory versioned',
315
'Create new Bazaar tree in %s' % vfs_file.get_name())
316
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] == '?':
329
item = nautilus.MenuItem('BzrNautilus::add',
331
'Add as versioned file')
332
item.connect('activate', self.add_cb, vfs_file)
335
item = nautilus.MenuItem('BzrNautilus::ignore',
337
'Ignore file for versioning')
338
item.connect('activate', self.ignore_cb, vfs_file)
340
elif wtfiles[path] == 'I':
341
item = nautilus.MenuItem('BzrNautilus::unignore',
343
'Unignore file for versioning')
344
item.connect('activate', self.unignore_cb, vfs_file)
346
elif wtfiles[path] == 'V':
347
item = nautilus.MenuItem('BzrNautilus::log',
350
item.connect('activate', self.log_cb, vfs_file)
353
item = nautilus.MenuItem('BzrNautilus::diff',
356
item.connect('activate', self.diff_cb, vfs_file)
359
item = nautilus.MenuItem('BzrNautilus::remove',
361
'Remove this file from versioning')
362
item.connect('activate', self.remove_cb, vfs_file)
365
item = nautilus.MenuItem('BzrNautilus::annotate',
367
'Annotate File Data')
368
item.connect('activate', self.annotate_cb, vfs_file)
371
item = nautilus.MenuItem('BzrNautilus::commit',
374
item.connect('activate', self.commit_cb, vfs_file)
379
def get_columns(self):
380
return nautilus.Column("BzrNautilus::bzr_status",
383
"Version control status"),
385
def update_file_info(self, file):
387
if file.get_uri_scheme() != 'file':
391
tree, path = WorkingTree.open_containing(file.get_uri())
392
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'
416
delta = tree.changes_from(tree.branch.basis_tree())
417
if delta.touches_file_id(id):
418
emblem = 'bzr-modified'
420
for f, _, _ in delta.added:
425
for of, f, _, _, _, _ in delta.renamed:
427
status = 'renamed from %s' % f
429
elif tree.branch.basis_tree().has_filename(path):
430
emblem = 'bzr-removed'
433
# FIXME: Check for ignored files
434
status = 'unversioned'
436
if emblem is not None:
437
file.add_emblem(emblem)
438
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)