3
from bzrlib.bzrdir import BzrDir
4
from bzrlib.errors import NotBranchError
5
from bzrlib.workingtree import WorkingTree
6
from bzrlib.tree import file_status
8
from bzrlib.plugin import load_plugins
11
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
13
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
17
def add_cb(self, menu, vfs_file):
18
# We can only cope with local files
19
if vfs_file.get_uri_scheme() != 'file':
22
file = vfs_file.get_uri()
24
tree, path = WorkingTree.open_containing(file)
25
except NotBranchError:
32
def ignore_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 unignore_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 diff_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:
73
from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
75
window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
80
def newtree_cb(self, menu, vfs_file):
81
# We can only cope with local files
82
if vfs_file.get_uri_scheme() != 'file':
85
file = vfs_file.get_uri()
87
# We only want to continue here if we get a NotBranchError
89
tree, path = WorkingTree.open_containing(file)
90
except NotBranchError:
91
BzrDir.create_branch_and_repo(file)
93
def remove_cb(self, menu, vfs_file):
94
# We can only cope with local files
95
if vfs_file.get_uri_scheme() != 'file':
98
file = vfs_file.get_uri()
100
tree, path = WorkingTree.open_containing(file)
101
except NotBranchError:
106
def annotate_cb(self, menu, vfs_file):
107
# We can only cope with local files
108
if vfs_file.get_uri_scheme() != 'file':
111
file = vfs_file.get_uri()
113
vis = cmd_gannotate()
116
def clone_cb(self, menu, vfs_file=None):
117
# We can only cope with local files
118
if vfs_file.get_uri_scheme() != 'file':
121
from bzrlib.plugins.gtk.olive.branch import BranchDialog
123
dialog = BranchDialog(vfs_file.get_name())
126
def commit_cb(self, menu, vfs_file=None):
127
# We can only cope with local files
128
if vfs_file.get_uri_scheme() != 'file':
131
file = vfs_file.get_uri()
133
tree, path = WorkingTree.open_containing(file)
134
except NotBranchError:
137
from bzrlib.plugins.gtk.olive.commit import CommitDialog
138
dialog = CommitDialog(tree, path)
142
def log_cb(self, menu, vfs_file):
143
# We can only cope with local files
144
if vfs_file.get_uri_scheme() != 'file':
147
file = vfs_file.get_uri()
149
# We only want to continue here if we get a NotBranchError
151
tree, path = WorkingTree.open_containing(file)
152
except NotBranchError:
155
vis = cmd_visualise()
160
def pull_cb(self, menu, vfs_file):
161
# We can only cope with local files
162
if vfs_file.get_uri_scheme() != 'file':
165
file = vfs_file.get_uri()
167
# We only want to continue here if we get a NotBranchError
169
tree, path = WorkingTree.open_containing(file)
170
except NotBranchError:
173
from bzrlib.plugins.gtk.olive.pull import PullDialog
174
dialog = PullDialog(tree, path)
178
def merge_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
tree, path = WorkingTree.open_containing(file)
188
except NotBranchError:
191
from bzrlib.plugins.gtk.olive.merge import MergeDialog
192
dialog = MergeDialog(tree, path)
196
def get_background_items(self, window, vfs_file):
198
file = vfs_file.get_uri()
200
tree, path = WorkingTree.open_containing(file)
201
except NotBranchError:
202
item = nautilus.MenuItem('BzrNautilus::newtree',
203
'Make directory versioned',
204
'Create new Bazaar tree in this folder')
205
item.connect('activate', self.newtree_cb, vfs_file)
208
item = nautilus.MenuItem('BzrNautilus::clone',
209
'Checkout Bazaar branch',
210
'Checkout Existing Bazaar Branch')
211
item.connect('activate', self.clone_cb, vfs_file)
216
item = nautilus.MenuItem('BzrNautilus::log',
218
'Show Bazaar history')
219
item.connect('activate', self.log_cb, vfs_file)
222
item = nautilus.MenuItem('BzrNautilus::pull',
224
'Pull from another branch')
225
item.connect('activate', self.pull_cb, vfs_file)
228
item = nautilus.MenuItem('BzrNautilus::merge',
230
'Merge from another branch')
231
item.connect('activate', self.merge_cb, vfs_file)
234
item = nautilus.MenuItem('BzrNautilus::commit',
237
item.connect('activate', self.commit_cb, vfs_file)
243
def get_file_items(self, window, files):
246
for vfs_file in files:
247
# We can only cope with local files
248
if vfs_file.get_uri_scheme() != 'file':
251
file = vfs_file.get_uri()
253
tree, path = WorkingTree.open_containing(file)
254
except NotBranchError:
255
if not vfs_file.is_directory():
257
item = nautilus.MenuItem('BzrNautilus::newtree',
258
'Make directory versioned',
259
'Create new Bazaar tree in %s' % vfs_file.get_name())
260
item.connect('activate', self.newtree_cb, vfs_file)
263
file_class = tree.file_class(path)
265
if file_class == '?':
266
item = nautilus.MenuItem('BzrNautilus::add',
268
'Add as versioned file')
269
item.connect('activate', self.add_cb, vfs_file)
272
item = nautilus.MenuItem('BzrNautilus::ignore',
274
'Ignore file for versioning')
275
item.connect('activate', self.ignore_cb, vfs_file)
277
elif file_class == 'I':
278
item = nautilus.MenuItem('BzrNautilus::unignore',
280
'Unignore file for versioning')
281
item.connect('activate', self.unignore_cb, vfs_file)
283
elif file_class == 'V':
284
item = nautilus.MenuItem('BzrNautilus::log',
287
item.connect('activate', self.log_cb, vfs_file)
290
item = nautilus.MenuItem('BzrNautilus::diff',
293
item.connect('activate', self.diff_cb, vfs_file)
296
item = nautilus.MenuItem('BzrNautilus::remove',
298
'Remove this file from versioning')
299
item.connect('activate', self.remove_cb, vfs_file)
302
item = nautilus.MenuItem('BzrNautilus::annotate',
304
'Annotate File Data')
305
item.connect('activate', self.annotate_cb, vfs_file)
308
item = nautilus.MenuItem('BzrNautilus::commit',
311
item.connect('activate', self.commit_cb, vfs_file)
316
def get_columns(self):
317
return nautilus.Column("BzrNautilus::bzr_status",
320
"Version control status"),
322
def update_file_info(self, file):
323
if file.get_uri_scheme() != 'file':
327
tree, path = WorkingTree.open_containing(file.get_uri())
328
except NotBranchError:
334
if tree.has_filename(path):
335
emblem = 'cvs-controlled'
337
id = tree.path2id(path)
339
delta = tree.changes_from(tree.branch.basis_tree())
340
if delta.touches_file_id(id):
341
emblem = 'cvs-modified'
343
for f, _, _ in delta.added:
348
for of, f, _, _, _, _ in delta.renamed:
350
status = 'renamed from %s' % f
352
elif tree.branch.basis_tree().has_filename(path):
353
emblem = 'cvs-removed'
356
# FIXME: Check for ignored files
357
status = 'unversioned'
359
if emblem is not None:
360
file.add_emblem(emblem)
361
file.add_string_attribute('bzr_status', status)