1
# Trivial Bazaar plugin for Nautilus
3
# Copyright (C) 2006 Jeff Bailey
4
# Copyright (C) 2006 Wouter van Heyst
5
# Copyright (C) 2006 Jelmer Vernooij
7
# Published under the GNU GPL
12
from bzrlib.bzrdir import BzrDir
13
from bzrlib.errors import NotBranchError
14
from bzrlib.errors import NoWorkingTree
15
from bzrlib.errors import UnsupportedProtocol
16
from bzrlib.workingtree import WorkingTree
17
from bzrlib.branch import Branch
18
from bzrlib.tree import file_status
20
from bzrlib.plugin import load_plugins
23
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
25
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
29
def add_cb(self, menu, vfs_file):
30
# We can only cope with local files
31
if vfs_file.get_uri_scheme() != 'file':
34
file = vfs_file.get_uri()
36
tree, path = WorkingTree.open_containing(file)
37
except NotBranchError:
44
def ignore_cb(self, menu, vfs_file):
45
# We can only cope with local files
46
if vfs_file.get_uri_scheme() != 'file':
49
file = vfs_file.get_uri()
51
tree, path = WorkingTree.open_containing(file)
52
except NotBranchError:
59
def unignore_cb(self, menu, vfs_file):
60
# We can only cope with local files
61
if vfs_file.get_uri_scheme() != 'file':
64
file = vfs_file.get_uri()
66
tree, path = WorkingTree.open_containing(file)
67
except NotBranchError:
74
def diff_cb(self, menu, vfs_file):
75
# We can only cope with local files
76
if vfs_file.get_uri_scheme() != 'file':
79
file = vfs_file.get_uri()
81
tree, path = WorkingTree.open_containing(file)
82
except NotBranchError:
85
from bzrlib.plugins.gtk.diff import DiffWindow
87
window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
92
def newtree_cb(self, menu, vfs_file):
93
# We can only cope with local files
94
if vfs_file.get_uri_scheme() != 'file':
97
file = vfs_file.get_uri()
99
# We only want to continue here if we get a NotBranchError
101
tree, path = WorkingTree.open_containing(file)
102
except NotBranchError:
103
BzrDir.create_standalone_workingtree(file)
105
def remove_cb(self, menu, vfs_file):
106
# We can only cope with local files
107
if vfs_file.get_uri_scheme() != 'file':
110
file = vfs_file.get_uri()
112
tree, path = WorkingTree.open_containing(file)
113
except NotBranchError:
118
def annotate_cb(self, menu, vfs_file):
119
# We can only cope with local files
120
if vfs_file.get_uri_scheme() != 'file':
123
file = vfs_file.get_uri()
125
vis = cmd_gannotate()
128
def clone_cb(self, menu, vfs_file=None):
129
# We can only cope with local files
130
if vfs_file.get_uri_scheme() != 'file':
133
from bzrlib.plugins.gtk.branch import BranchDialog
135
dialog = BranchDialog(vfs_file.get_name())
136
response = dialog.run()
137
if response != gtk.RESPONSE_NONE:
141
def commit_cb(self, menu, vfs_file=None):
142
# We can only cope with local files
143
if vfs_file.get_uri_scheme() != 'file':
146
file = vfs_file.get_uri()
150
tree, path = WorkingTree.open_containing(file)
152
except NotBranchError, e:
155
except NoWorkingTree, e:
158
(branch, path) = Branch.open_containing(path)
159
except NotBranchError, e:
162
from bzrlib.plugins.gtk.commit import CommitDialog
163
dialog = CommitDialog(tree, path, not branch)
164
response = dialog.run()
165
if response != gtk.RESPONSE_NONE:
169
def log_cb(self, menu, vfs_file):
170
# We can only cope with local files
171
if vfs_file.get_uri_scheme() != 'file':
174
file = vfs_file.get_uri()
176
# We only want to continue here if we get a NotBranchError
178
tree, path = WorkingTree.open_containing(file)
179
except NotBranchError:
182
vis = cmd_visualise()
187
def pull_cb(self, menu, vfs_file):
188
# We can only cope with local files
189
if vfs_file.get_uri_scheme() != 'file':
192
file = vfs_file.get_uri()
194
# We only want to continue here if we get a NotBranchError
196
tree, path = WorkingTree.open_containing(file)
197
except NotBranchError:
200
from bzrlib.plugins.gtk.pull import PullDialog
201
dialog = PullDialog(tree, path)
205
def merge_cb(self, menu, vfs_file):
206
# We can only cope with local files
207
if vfs_file.get_uri_scheme() != 'file':
210
file = vfs_file.get_uri()
212
# We only want to continue here if we get a NotBranchError
214
tree, path = WorkingTree.open_containing(file)
215
except NotBranchError:
218
from bzrlib.plugins.gtk.merge import MergeDialog
219
dialog = MergeDialog(tree, path)
223
def get_background_items(self, window, vfs_file):
225
file = vfs_file.get_uri()
227
tree, path = WorkingTree.open_containing(file)
228
except UnsupportedProtocol:
230
except NotBranchError:
231
item = nautilus.MenuItem('BzrNautilus::newtree',
232
'Make directory versioned',
233
'Create new Bazaar tree in this folder')
234
item.connect('activate', self.newtree_cb, vfs_file)
237
item = nautilus.MenuItem('BzrNautilus::clone',
238
'Checkout Bazaar branch',
239
'Checkout Existing Bazaar Branch')
240
item.connect('activate', self.clone_cb, vfs_file)
245
item = nautilus.MenuItem('BzrNautilus::log',
247
'Show Bazaar history')
248
item.connect('activate', self.log_cb, vfs_file)
251
item = nautilus.MenuItem('BzrNautilus::pull',
253
'Pull from another branch')
254
item.connect('activate', self.pull_cb, vfs_file)
257
item = nautilus.MenuItem('BzrNautilus::merge',
259
'Merge from another branch')
260
item.connect('activate', self.merge_cb, vfs_file)
263
item = nautilus.MenuItem('BzrNautilus::commit',
266
item.connect('activate', self.commit_cb, vfs_file)
272
def get_file_items(self, window, files):
276
for vfs_file in files:
277
# We can only cope with local files
278
if vfs_file.get_uri_scheme() != 'file':
281
file = vfs_file.get_uri()
283
tree, path = WorkingTree.open_containing(file)
284
except NotBranchError:
285
if not vfs_file.is_directory():
287
item = nautilus.MenuItem('BzrNautilus::newtree',
288
'Make directory versioned',
289
'Create new Bazaar tree in %s' % vfs_file.get_name())
290
item.connect('activate', self.newtree_cb, vfs_file)
292
# Refresh the list of filestatuses in the working tree
293
if path not in wtfiles.keys():
295
for rpath, file_class, kind, id, entry in tree.list_files():
296
wtfiles[rpath] = file_class
300
if wtfiles[path] == '?':
301
item = nautilus.MenuItem('BzrNautilus::add',
303
'Add as versioned file')
304
item.connect('activate', self.add_cb, vfs_file)
307
item = nautilus.MenuItem('BzrNautilus::ignore',
309
'Ignore file for versioning')
310
item.connect('activate', self.ignore_cb, vfs_file)
312
elif wtfiles[path] == 'I':
313
item = nautilus.MenuItem('BzrNautilus::unignore',
315
'Unignore file for versioning')
316
item.connect('activate', self.unignore_cb, vfs_file)
318
elif wtfiles[path] == 'V':
319
item = nautilus.MenuItem('BzrNautilus::log',
322
item.connect('activate', self.log_cb, vfs_file)
325
item = nautilus.MenuItem('BzrNautilus::diff',
328
item.connect('activate', self.diff_cb, vfs_file)
331
item = nautilus.MenuItem('BzrNautilus::remove',
333
'Remove this file from versioning')
334
item.connect('activate', self.remove_cb, vfs_file)
337
item = nautilus.MenuItem('BzrNautilus::annotate',
339
'Annotate File Data')
340
item.connect('activate', self.annotate_cb, vfs_file)
343
item = nautilus.MenuItem('BzrNautilus::commit',
346
item.connect('activate', self.commit_cb, vfs_file)
351
def get_columns(self):
352
return nautilus.Column("BzrNautilus::bzr_status",
355
"Version control status"),
357
def update_file_info(self, file):
358
if file.get_uri_scheme() != 'file':
362
tree, path = WorkingTree.open_containing(file.get_uri())
363
except NotBranchError:
369
if tree.has_filename(path):
370
emblem = 'cvs-controlled'
372
id = tree.path2id(path)
374
delta = tree.changes_from(tree.branch.basis_tree())
375
if delta.touches_file_id(id):
376
emblem = 'cvs-modified'
378
for f, _, _ in delta.added:
383
for of, f, _, _, _, _ in delta.renamed:
385
status = 'renamed from %s' % f
387
elif tree.branch.basis_tree().has_filename(path):
388
emblem = 'cvs-removed'
391
# FIXME: Check for ignored files
392
status = 'unversioned'
394
if emblem is not None:
395
file.add_emblem(emblem)
396
file.add_string_attribute('bzr_status', status)