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
3
12
from bzrlib.bzrdir import BzrDir
4
13
from bzrlib.errors import NotBranchError
14
from bzrlib.errors import NoWorkingTree
15
from bzrlib.errors import UnsupportedProtocol
5
16
from bzrlib.workingtree import WorkingTree
17
from bzrlib.branch import Branch
18
from bzrlib.tree import file_status
7
20
from bzrlib.plugin import load_plugins
10
23
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
12
class BzrExtension(nautilus.MenuProvider):
25
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
13
26
def __init__(self):
117
130
if vfs_file.get_uri_scheme() != 'file':
120
file = vfs_file.get_uri()
122
tree, path = WorkingTree.open_containing(file)
123
except NotBranchError:
126
from bzrlib.plugins.gtk.clone import CloneDialog
127
dialog = CloneDialog(file)
128
if dialog.run() != gtk.RESPONSE_CANCEL:
129
bzrdir = BzrDir.open(dialog.url)
130
bzrdir.sprout(dialog.dest_path)
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:
132
141
def commit_cb(self, menu, vfs_file=None):
133
142
# We can only cope with local files
137
146
file = vfs_file.get_uri()
139
150
tree, path = WorkingTree.open_containing(file)
140
except NotBranchError:
152
except NotBranchError, e:
155
except NoWorkingTree, e:
158
(branch, path) = Branch.open_containing(path)
159
except NotBranchError, e:
143
from bzrlib.plugins.gtk.commit import GCommitDialog
144
dialog = GCommitDialog(tree)
145
dialog.set_title(path + " - Commit")
146
if dialog.run() != gtk.RESPONSE_CANCEL:
147
Commit().commit(working_tree=wt,message=dialog.message,
148
specific_files=dialog.specific_files)
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:
150
169
def log_cb(self, menu, vfs_file):
151
170
# We can only cope with local files
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)
168
223
def get_background_items(self, window, vfs_file):
169
225
file = vfs_file.get_uri()
171
227
tree, path = WorkingTree.open_containing(file)
228
except UnsupportedProtocol:
172
230
except NotBranchError:
173
231
item = nautilus.MenuItem('BzrNautilus::newtree',
174
'Create new Bazaar tree',
232
'Make directory versioned',
175
233
'Create new Bazaar tree in this folder')
176
234
item.connect('activate', self.newtree_cb, vfs_file)
177
235
items.append(item)
179
237
item = nautilus.MenuItem('BzrNautilus::clone',
238
'Checkout Bazaar branch',
181
239
'Checkout Existing Bazaar Branch')
182
240
item.connect('activate', self.clone_cb, vfs_file)
183
241
items.append(item)
188
245
item = nautilus.MenuItem('BzrNautilus::log',
190
247
'Show Bazaar history')
191
248
item.connect('activate', self.log_cb, vfs_file)
192
249
items.append(item)
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)
194
263
item = nautilus.MenuItem('BzrNautilus::commit',
196
265
'Commit Changes')
215
285
if not vfs_file.is_directory():
217
287
item = nautilus.MenuItem('BzrNautilus::newtree',
218
'Create new Bazaar tree',
288
'Make directory versioned',
219
289
'Create new Bazaar tree in %s' % vfs_file.get_name())
220
290
item.connect('activate', self.newtree_cb, vfs_file)
223
file_class = tree.file_class(path)
225
if file_class == '?':
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] == '?':
226
301
item = nautilus.MenuItem('BzrNautilus::add',
228
303
'Add as versioned file')
234
309
'Ignore file for versioning')
235
310
item.connect('activate', self.ignore_cb, vfs_file)
236
311
items.append(item)
237
elif file_class == 'I':
312
elif wtfiles[path] == 'I':
238
313
item = nautilus.MenuItem('BzrNautilus::unignore',
240
315
'Unignore file for versioning')
241
316
item.connect('activate', self.unignore_cb, vfs_file)
242
317
items.append(item)
243
elif file_class == 'V':
318
elif wtfiles[path] == 'V':
244
319
item = nautilus.MenuItem('BzrNautilus::log',
272
347
items.append(item)
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)