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
18
from bzrlib.plugin import load_plugins
21
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
23
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
27
def add_cb(self, menu, vfs_file):
28
# We can only cope with local files
29
if vfs_file.get_uri_scheme() != 'file':
32
file = vfs_file.get_uri()
34
tree, path = WorkingTree.open_containing(file)
35
except NotBranchError:
42
def ignore_cb(self, menu, vfs_file):
43
# We can only cope with local files
44
if vfs_file.get_uri_scheme() != 'file':
47
file = vfs_file.get_uri()
49
tree, path = WorkingTree.open_containing(file)
50
except NotBranchError:
57
def unignore_cb(self, menu, vfs_file):
58
# We can only cope with local files
59
if vfs_file.get_uri_scheme() != 'file':
62
file = vfs_file.get_uri()
64
tree, path = WorkingTree.open_containing(file)
65
except NotBranchError:
72
def diff_cb(self, menu, vfs_file):
73
# We can only cope with local files
74
if vfs_file.get_uri_scheme() != 'file':
77
file = vfs_file.get_uri()
79
tree, path = WorkingTree.open_containing(file)
80
except NotBranchError:
83
from bzrlib.plugins.gtk.diff import DiffWindow
85
window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
90
def newtree_cb(self, menu, vfs_file):
91
# We can only cope with local files
92
if vfs_file.get_uri_scheme() != 'file':
95
file = vfs_file.get_uri()
97
# We only want to continue here if we get a NotBranchError
99
tree, path = WorkingTree.open_containing(file)
100
except NotBranchError:
101
BzrDir.create_standalone_workingtree(file)
103
def remove_cb(self, menu, vfs_file):
104
# We can only cope with local files
105
if vfs_file.get_uri_scheme() != 'file':
108
file = vfs_file.get_uri()
110
tree, path = WorkingTree.open_containing(file)
111
except NotBranchError:
116
def annotate_cb(self, menu, vfs_file):
117
# We can only cope with local files
118
if vfs_file.get_uri_scheme() != 'file':
121
file = vfs_file.get_uri()
123
vis = cmd_gannotate()
126
def clone_cb(self, menu, vfs_file=None):
127
# We can only cope with local files
128
if vfs_file.get_uri_scheme() != 'file':
131
from bzrlib.plugins.gtk.branch import BranchDialog
133
dialog = BranchDialog(vfs_file.get_name())
134
response = dialog.run()
135
if response != gtk.RESPONSE_NONE:
139
def commit_cb(self, menu, vfs_file=None):
140
# We can only cope with local files
141
if vfs_file.get_uri_scheme() != 'file':
144
file = vfs_file.get_uri()
148
tree, path = WorkingTree.open_containing(file)
150
except NotBranchError, e:
153
except NoWorkingTree, e:
156
(branch, path) = Branch.open_containing(path)
157
except NotBranchError, e:
160
from bzrlib.plugins.gtk.commit import CommitDialog
161
dialog = CommitDialog(tree, path)
162
response = dialog.run()
163
if response != gtk.RESPONSE_NONE:
167
def log_cb(self, menu, vfs_file):
168
# We can only cope with local files
169
if vfs_file.get_uri_scheme() != 'file':
172
file = vfs_file.get_uri()
174
# We only want to continue here if we get a NotBranchError
176
tree, path = WorkingTree.open_containing(file)
177
except NotBranchError:
180
vis = cmd_visualise()
185
def pull_cb(self, menu, vfs_file):
186
# We can only cope with local files
187
if vfs_file.get_uri_scheme() != 'file':
190
file = vfs_file.get_uri()
192
# We only want to continue here if we get a NotBranchError
194
tree, path = WorkingTree.open_containing(file)
195
except NotBranchError:
198
from bzrlib.plugins.gtk.pull import PullDialog
199
dialog = PullDialog(tree, path)
203
def merge_cb(self, menu, vfs_file):
204
# We can only cope with local files
205
if vfs_file.get_uri_scheme() != 'file':
208
file = vfs_file.get_uri()
210
# We only want to continue here if we get a NotBranchError
212
tree, path = WorkingTree.open_containing(file)
213
except NotBranchError:
216
from bzrlib.plugins.gtk.merge import MergeDialog
217
dialog = MergeDialog(tree, path)
221
def get_background_items(self, window, vfs_file):
223
file = vfs_file.get_uri()
225
tree, path = WorkingTree.open_containing(file)
226
except UnsupportedProtocol:
228
except NotBranchError:
229
item = nautilus.MenuItem('BzrNautilus::newtree',
230
'Make directory versioned',
231
'Create new Bazaar tree in this folder')
232
item.connect('activate', self.newtree_cb, vfs_file)
235
item = nautilus.MenuItem('BzrNautilus::clone',
236
'Checkout Bazaar branch',
237
'Checkout Existing Bazaar Branch')
238
item.connect('activate', self.clone_cb, vfs_file)
242
except NoWorkingTree:
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)
271
def get_file_items(self, window, files):
275
for vfs_file in files:
276
# We can only cope with local files
277
if vfs_file.get_uri_scheme() != 'file':
280
file = vfs_file.get_uri()
282
tree, path = WorkingTree.open_containing(file)
283
except NotBranchError:
284
if not vfs_file.is_directory():
286
item = nautilus.MenuItem('BzrNautilus::newtree',
287
'Make directory versioned',
288
'Create new Bazaar tree in %s' % vfs_file.get_name())
289
item.connect('activate', self.newtree_cb, vfs_file)
291
except NoWorkingTree:
293
# Refresh the list of filestatuses in the working tree
294
if path not in wtfiles.keys():
296
for rpath, file_class, kind, id, entry in tree.list_files():
297
wtfiles[rpath] = file_class
301
if wtfiles[path] == '?':
302
item = nautilus.MenuItem('BzrNautilus::add',
304
'Add as versioned file')
305
item.connect('activate', self.add_cb, vfs_file)
308
item = nautilus.MenuItem('BzrNautilus::ignore',
310
'Ignore file for versioning')
311
item.connect('activate', self.ignore_cb, vfs_file)
313
elif wtfiles[path] == 'I':
314
item = nautilus.MenuItem('BzrNautilus::unignore',
316
'Unignore file for versioning')
317
item.connect('activate', self.unignore_cb, vfs_file)
319
elif wtfiles[path] == 'V':
320
item = nautilus.MenuItem('BzrNautilus::log',
323
item.connect('activate', self.log_cb, vfs_file)
326
item = nautilus.MenuItem('BzrNautilus::diff',
329
item.connect('activate', self.diff_cb, vfs_file)
332
item = nautilus.MenuItem('BzrNautilus::remove',
334
'Remove this file from versioning')
335
item.connect('activate', self.remove_cb, vfs_file)
338
item = nautilus.MenuItem('BzrNautilus::annotate',
340
'Annotate File Data')
341
item.connect('activate', self.annotate_cb, vfs_file)
344
item = nautilus.MenuItem('BzrNautilus::commit',
347
item.connect('activate', self.commit_cb, vfs_file)
352
def get_columns(self):
353
return nautilus.Column("BzrNautilus::bzr_status",
356
"Version control status"),
358
def update_file_info(self, file):
359
if file.get_uri_scheme() != 'file':
363
tree, path = WorkingTree.open_containing(file.get_uri())
364
except NotBranchError:
366
except NoWorkingTree:
372
if tree.has_filename(path):
373
emblem = 'cvs-controlled'
375
id = tree.path2id(path)
377
delta = tree.changes_from(tree.branch.basis_tree())
378
if delta.touches_file_id(id):
379
emblem = 'cvs-modified'
381
for f, _, _ in delta.added:
386
for of, f, _, _, _, _ in delta.renamed:
388
status = 'renamed from %s' % f
390
elif tree.branch.basis_tree().has_filename(path):
391
emblem = 'cvs-removed'
394
# FIXME: Check for ignored files
395
status = 'unversioned'
397
if emblem is not None:
398
file.add_emblem(emblem)
399
file.add_string_attribute('bzr_status', status)