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 get_background_items(self, window, vfs_file):
162
file = vfs_file.get_uri()
164
tree, path = WorkingTree.open_containing(file)
165
except NotBranchError:
166
item = nautilus.MenuItem('BzrNautilus::newtree',
167
'Create new Bazaar tree',
168
'Create new Bazaar tree in this folder')
169
item.connect('activate', self.newtree_cb, vfs_file)
172
item = nautilus.MenuItem('BzrNautilus::clone',
174
'Checkout Existing Bazaar Branch')
175
item.connect('activate', self.clone_cb, vfs_file)
180
item = nautilus.MenuItem('BzrNautilus::log',
182
'Show Bazaar history')
183
item.connect('activate', self.log_cb, vfs_file)
186
item = nautilus.MenuItem('BzrNautilus::commit',
189
item.connect('activate', self.commit_cb, vfs_file)
195
def get_file_items(self, window, files):
198
for vfs_file in files:
199
# We can only cope with local files
200
if vfs_file.get_uri_scheme() != 'file':
203
file = vfs_file.get_uri()
205
tree, path = WorkingTree.open_containing(file)
206
except NotBranchError:
207
if not vfs_file.is_directory():
209
item = nautilus.MenuItem('BzrNautilus::newtree',
210
'Create new Bazaar tree',
211
'Create new Bazaar tree in %s' % vfs_file.get_name())
212
item.connect('activate', self.newtree_cb, vfs_file)
215
file_class = tree.file_class(path)
217
if file_class == '?':
218
item = nautilus.MenuItem('BzrNautilus::add',
220
'Add as versioned file')
221
item.connect('activate', self.add_cb, vfs_file)
224
item = nautilus.MenuItem('BzrNautilus::ignore',
226
'Ignore file for versioning')
227
item.connect('activate', self.ignore_cb, vfs_file)
229
elif file_class == 'I':
230
item = nautilus.MenuItem('BzrNautilus::unignore',
232
'Unignore file for versioning')
233
item.connect('activate', self.unignore_cb, vfs_file)
235
elif file_class == 'V':
236
item = nautilus.MenuItem('BzrNautilus::log',
239
item.connect('activate', self.log_cb, vfs_file)
242
item = nautilus.MenuItem('BzrNautilus::diff',
245
item.connect('activate', self.diff_cb, vfs_file)
248
item = nautilus.MenuItem('BzrNautilus::remove',
250
'Remove this file from versioning')
251
item.connect('activate', self.remove_cb, vfs_file)
254
item = nautilus.MenuItem('BzrNautilus::annotate',
256
'Annotate File Data')
257
item.connect('activate', self.annotate_cb, vfs_file)
260
item = nautilus.MenuItem('BzrNautilus::commit',
263
item.connect('activate', self.commit_cb, vfs_file)
268
def get_columns(self):
269
return nautilus.Column("BzrNautilus::bzr_status",
272
"Version control status"),
274
def update_file_info(self, file):
275
if file.get_uri_scheme() != 'file':
279
tree, path = WorkingTree.open_containing(file.get_uri())
280
except NotBranchError:
286
if tree.has_filename(path):
287
emblem = 'cvs-controlled'
289
id = tree.path2id(path)
291
delta = tree.changes_from(tree.branch.basis_tree())
292
if delta.touches_file_id(id):
293
emblem = 'cvs-modified'
295
for f, _, _ in delta.added:
300
for of, f, _, _, _, _ in delta.renamed:
302
status = 'renamed from %s' % f
304
elif tree.branch.basis_tree().has_filename(path):
305
emblem = 'cvs-removed'
308
# FIXME: Check for ignored files
309
status = 'unversioned'
311
if emblem is not None:
312
file.add_emblem(emblem)
313
file.add_string_attribute('bzr_status', status)