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
11
from bzrlib.branch import Branch
12
from bzrlib.bzrdir import BzrDir
13
from bzrlib.errors import (
18
from bzrlib.workingtree import WorkingTree
19
from bzrlib.config import GlobalConfig
21
from bzrlib.plugin import load_plugins
24
from bzrlib.plugins.gtk.commands import (
29
print "Bazaar nautilus module initialized"
32
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
37
def add_cb(self, menu, vfs_file):
38
# We can only cope with local files
39
if vfs_file.get_uri_scheme() != 'file':
42
file = vfs_file.get_uri()
44
tree, path = WorkingTree.open_containing(file)
45
except NotBranchError:
52
def ignore_cb(self, menu, vfs_file):
53
# We can only cope with local files
54
if vfs_file.get_uri_scheme() != 'file':
57
file = vfs_file.get_uri()
59
tree, path = WorkingTree.open_containing(file)
60
except NotBranchError:
67
def unignore_cb(self, menu, vfs_file):
68
# We can only cope with local files
69
if vfs_file.get_uri_scheme() != 'file':
72
file = vfs_file.get_uri()
74
tree, path = WorkingTree.open_containing(file)
75
except NotBranchError:
82
def diff_cb(self, menu, vfs_file):
83
# We can only cope with local files
84
if vfs_file.get_uri_scheme() != 'file':
87
file = vfs_file.get_uri()
89
tree, path = WorkingTree.open_containing(file)
90
except NotBranchError:
93
from bzrlib.plugins.gtk.diff import DiffWindow
95
window.set_diff(tree.branch._get_nick(local=True), tree,
96
tree.branch.basis_tree())
101
def newtree_cb(self, menu, vfs_file):
102
# We can only cope with local files
103
if vfs_file.get_uri_scheme() != 'file':
106
file = vfs_file.get_uri()
108
# We only want to continue here if we get a NotBranchError
110
tree, path = WorkingTree.open_containing(file)
111
except NotBranchError:
112
BzrDir.create_standalone_workingtree(file)
114
def remove_cb(self, menu, vfs_file):
115
# We can only cope with local files
116
if vfs_file.get_uri_scheme() != 'file':
119
file = vfs_file.get_uri()
121
tree, path = WorkingTree.open_containing(file)
122
except NotBranchError:
127
def annotate_cb(self, menu, vfs_file):
128
# We can only cope with local files
129
if vfs_file.get_uri_scheme() != 'file':
132
file = vfs_file.get_uri()
134
vis = cmd_gannotate()
137
def clone_cb(self, menu, vfs_file=None):
138
# We can only cope with local files
139
if vfs_file.get_uri_scheme() != 'file':
142
from bzrlib.plugins.gtk.branch import BranchDialog
144
dialog = BranchDialog(vfs_file.get_name())
145
response = dialog.run()
146
if response != gtk.RESPONSE_NONE:
150
def commit_cb(self, menu, vfs_file=None):
151
# We can only cope with local files
152
if vfs_file.get_uri_scheme() != 'file':
155
file = vfs_file.get_uri()
159
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:
171
from bzrlib.plugins.gtk.commit import CommitDialog
172
dialog = CommitDialog(tree, path)
173
response = dialog.run()
174
if response != gtk.RESPONSE_NONE:
178
def log_cb(self, menu, vfs_file):
179
# We can only cope with local files
180
if vfs_file.get_uri_scheme() != 'file':
183
file = vfs_file.get_uri()
185
# We only want to continue here if we get a NotBranchError
187
branch, path = Branch.open_containing(file)
188
except NotBranchError:
191
pp = start_viz_window(branch, [branch.last_revision()])
195
def pull_cb(self, menu, vfs_file):
196
# We can only cope with local files
197
if vfs_file.get_uri_scheme() != 'file':
200
file = vfs_file.get_uri()
202
# We only want to continue here if we get a NotBranchError
204
tree, path = WorkingTree.open_containing(file)
205
except NotBranchError:
208
from bzrlib.plugins.gtk.pull import PullDialog
209
dialog = PullDialog(tree, path)
213
def merge_cb(self, menu, vfs_file):
214
# We can only cope with local files
215
if vfs_file.get_uri_scheme() != 'file':
218
file = vfs_file.get_uri()
220
# We only want to continue here if we get a NotBranchError
222
tree, path = WorkingTree.open_containing(file)
223
except NotBranchError:
226
from bzrlib.plugins.gtk.merge import MergeDialog
227
dialog = MergeDialog(tree, path)
231
def get_background_items(self, window, vfs_file):
233
file = vfs_file.get_uri()
236
tree, path = WorkingTree.open_containing(file)
237
disabled_flag = self.check_branch_enabled(tree.branch)
238
except UnsupportedProtocol:
240
except NotBranchError:
241
disabled_flag = self.check_branch_enabled()
242
item = nautilus.MenuItem('BzrNautilus::newtree',
243
'Make directory versioned',
244
'Create new Bazaar tree in this folder')
245
item.connect('activate', self.newtree_cb, vfs_file)
248
item = nautilus.MenuItem('BzrNautilus::clone',
249
'Checkout Bazaar branch ...',
250
'Checkout Existing Bazaar Branch')
251
item.connect('activate', self.clone_cb, vfs_file)
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
item = nautilus.MenuItem('BzrNautilus::log',
273
'Show Bazaar history')
274
item.connect('activate', self.log_cb, vfs_file)
277
item = nautilus.MenuItem('BzrNautilus::pull',
279
'Pull from another branch')
280
item.connect('activate', self.pull_cb, vfs_file)
283
item = nautilus.MenuItem('BzrNautilus::merge',
285
'Merge from another branch')
286
item.connect('activate', self.merge_cb, vfs_file)
289
item = nautilus.MenuItem('BzrNautilus::commit',
292
item.connect('activate', self.commit_cb, vfs_file)
297
def get_file_items(self, window, files):
301
for vfs_file in files:
302
# We can only cope with local files
303
if vfs_file.get_uri_scheme() != 'file':
306
file = vfs_file.get_uri()
308
tree, path = WorkingTree.open_containing(file)
309
disabled_flag = self.check_branch_enabled(tree.branch)
310
except NotBranchError:
311
disabled_flag = self.check_branch_enabled()
312
if not vfs_file.is_directory():
315
if disabled_flag == 'False':
318
item = nautilus.MenuItem('BzrNautilus::newtree',
319
'Make directory versioned',
320
'Create new Bazaar tree in %s' % vfs_file.get_name())
321
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] == '?':
334
item = nautilus.MenuItem('BzrNautilus::add',
336
'Add as versioned file')
337
item.connect('activate', self.add_cb, vfs_file)
340
item = nautilus.MenuItem('BzrNautilus::ignore',
342
'Ignore file for versioning')
343
item.connect('activate', self.ignore_cb, vfs_file)
345
elif wtfiles[path] == 'I':
346
item = nautilus.MenuItem('BzrNautilus::unignore',
348
'Unignore file for versioning')
349
item.connect('activate', self.unignore_cb, vfs_file)
351
elif wtfiles[path] == 'V':
352
item = nautilus.MenuItem('BzrNautilus::log',
355
item.connect('activate', self.log_cb, vfs_file)
358
item = nautilus.MenuItem('BzrNautilus::diff',
361
item.connect('activate', self.diff_cb, vfs_file)
364
item = nautilus.MenuItem('BzrNautilus::remove',
366
'Remove this file from versioning')
367
item.connect('activate', self.remove_cb, vfs_file)
370
item = nautilus.MenuItem('BzrNautilus::annotate',
372
'Annotate File Data')
373
item.connect('activate', self.annotate_cb, vfs_file)
376
item = nautilus.MenuItem('BzrNautilus::commit',
379
item.connect('activate', self.commit_cb, vfs_file)
384
def get_columns(self):
385
return nautilus.Column("BzrNautilus::bzr_status",
388
"Version control status"),
390
def update_file_info(self, file):
392
if file.get_uri_scheme() != 'file':
396
tree, path = WorkingTree.open_containing(file.get_uri())
397
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'
421
delta = tree.changes_from(tree.branch.basis_tree())
422
if delta.touches_file_id(id):
423
emblem = 'bzr-modified'
425
for f, _, _ in delta.added:
430
for of, f, _, _, _, _ in delta.renamed:
432
status = 'renamed from %s' % f
434
elif tree.branch.basis_tree().has_filename(path):
435
emblem = 'bzr-removed'
438
# FIXME: Check for ignored files
439
status = 'unversioned'
441
if emblem is not None:
442
file.add_emblem(emblem)
443
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)