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
9
from gi.repository import Gtk
11
from bzrlib.branch import Branch
3
12
from bzrlib.bzrdir import BzrDir
4
from bzrlib.errors import NotBranchError
13
from bzrlib.errors import (
5
18
from bzrlib.workingtree import WorkingTree
6
from bzrlib.tree import file_status
19
from bzrlib.config import GlobalConfig
8
21
from bzrlib.plugin import load_plugins
11
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
24
from bzrlib.plugins.gtk.commands import (
29
print "Bazaar nautilus module initialized"
13
32
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
14
34
def __init__(self):
131
155
file = vfs_file.get_uri()
133
159
tree, path = WorkingTree.open_containing(file)
134
except NotBranchError:
161
except NotBranchError, e:
164
except NoWorkingTree, e:
167
(branch, path) = Branch.open_containing(path)
168
except NotBranchError, e:
137
from bzrlib.plugins.gtk.olive.commit import CommitDialog
171
from bzrlib.plugins.gtk.commit import CommitDialog
138
172
dialog = CommitDialog(tree, path)
173
response = dialog.run()
174
if response != Gtk.ResponseType.NONE:
142
178
def log_cb(self, menu, vfs_file):
143
179
# We can only cope with local files
188
223
except NotBranchError:
191
from bzrlib.plugins.gtk.olive.merge import MergeDialog
226
from bzrlib.plugins.gtk.merge import MergeDialog
192
227
dialog = MergeDialog(tree, path)
196
231
def get_background_items(self, window, vfs_file):
198
233
file = vfs_file.get_uri()
200
236
tree, path = WorkingTree.open_containing(file)
237
disabled_flag = self.check_branch_enabled(tree.branch)
238
except UnsupportedProtocol:
201
240
except NotBranchError:
241
disabled_flag = self.check_branch_enabled()
202
242
item = nautilus.MenuItem('BzrNautilus::newtree',
203
243
'Make directory versioned',
204
244
'Create new Bazaar tree in this folder')
206
246
items.append(item)
208
248
item = nautilus.MenuItem('BzrNautilus::clone',
209
'Checkout Bazaar branch',
249
'Checkout Bazaar branch ...',
210
250
'Checkout Existing Bazaar Branch')
211
251
item.connect('activate', self.clone_cb, vfs_file)
212
252
items.append(item)
255
except NoWorkingTree:
258
if disabled_flag == 'False':
259
item = nautilus.MenuItem('BzrNautilus::enable',
260
'Enable Bazaar Plugin for this Branch',
261
'Enable Bazaar plugin for nautilus')
262
item.connect('activate', self.toggle_integration, 'True', vfs_file)
265
item = nautilus.MenuItem('BzrNautilus::disable',
266
'Disable Bazaar Plugin this Branch',
267
'Disable Bazaar plugin for nautilus')
268
item.connect('activate', self.toggle_integration, 'False', vfs_file)
216
271
item = nautilus.MenuItem('BzrNautilus::log',
218
273
'Show Bazaar history')
219
274
item.connect('activate', self.log_cb, vfs_file)
220
275
items.append(item)
222
277
item = nautilus.MenuItem('BzrNautilus::pull',
224
279
'Pull from another branch')
225
280
item.connect('activate', self.pull_cb, vfs_file)
226
281
items.append(item)
228
283
item = nautilus.MenuItem('BzrNautilus::merge',
230
285
'Merge from another branch')
231
286
item.connect('activate', self.merge_cb, vfs_file)
232
287
items.append(item)
234
289
item = nautilus.MenuItem('BzrNautilus::commit',
236
291
'Commit Changes')
237
292
item.connect('activate', self.commit_cb, vfs_file)
238
293
items.append(item)
243
297
def get_file_items(self, window, files):
246
301
for vfs_file in files:
247
302
# We can only cope with local files
248
303
if vfs_file.get_uri_scheme() != 'file':
251
306
file = vfs_file.get_uri()
253
308
tree, path = WorkingTree.open_containing(file)
309
disabled_flag = self.check_branch_enabled(tree.branch)
254
310
except NotBranchError:
311
disabled_flag = self.check_branch_enabled()
255
312
if not vfs_file.is_directory():
315
if disabled_flag == 'False':
257
318
item = nautilus.MenuItem('BzrNautilus::newtree',
258
319
'Make directory versioned',
259
320
'Create new Bazaar tree in %s' % vfs_file.get_name())
260
321
item.connect('activate', self.newtree_cb, vfs_file)
263
file_class = tree.file_class(path)
265
if file_class == '?':
323
except NoWorkingTree:
325
# Refresh the list of filestatuses in the working tree
326
if path not in wtfiles.keys():
328
for rpath, file_class, kind, id, entry in tree.list_files():
329
wtfiles[rpath] = file_class
333
if wtfiles[path] == '?':
266
334
item = nautilus.MenuItem('BzrNautilus::add',
268
336
'Add as versioned file')
274
342
'Ignore file for versioning')
275
343
item.connect('activate', self.ignore_cb, vfs_file)
276
344
items.append(item)
277
elif file_class == 'I':
345
elif wtfiles[path] == 'I':
278
346
item = nautilus.MenuItem('BzrNautilus::unignore',
280
348
'Unignore file for versioning')
281
349
item.connect('activate', self.unignore_cb, vfs_file)
282
350
items.append(item)
283
elif file_class == 'V':
351
elif wtfiles[path] == 'V':
284
352
item = nautilus.MenuItem('BzrNautilus::log',
287
355
item.connect('activate', self.log_cb, vfs_file)
288
356
items.append(item)
290
358
item = nautilus.MenuItem('BzrNautilus::diff',
292
360
'Show differences')
293
361
item.connect('activate', self.diff_cb, vfs_file)
294
362
items.append(item)
327
396
tree, path = WorkingTree.open_containing(file.get_uri())
328
397
except NotBranchError:
399
except NoWorkingTree:
402
disabled_flag = self.check_branch_enabled(tree.branch)
403
if disabled_flag == 'False':
334
if tree.has_filename(path):
335
emblem = 'cvs-controlled'
409
id = tree.path2id(path)
411
if tree.is_ignored(path):
413
emblem = 'bzr-ignored'
415
status = 'unversioned'
417
elif tree.has_filename(path):
418
emblem = 'bzr-controlled'
336
419
status = 'unchanged'
337
id = tree.path2id(path)
339
421
delta = tree.changes_from(tree.branch.basis_tree())
340
422
if delta.touches_file_id(id):
341
emblem = 'cvs-modified'
423
emblem = 'bzr-modified'
342
424
status = 'modified'
343
425
for f, _, _ in delta.added:
348
430
for of, f, _, _, _, _ in delta.renamed:
359
441
if emblem is not None:
360
442
file.add_emblem(emblem)
361
443
file.add_string_attribute('bzr_status', status)
445
def check_branch_enabled(self, branch=None):
446
# Supports global disable, but there is currently no UI to do this
447
config = GlobalConfig()
448
disabled_flag = config.get_user_option('nautilus_integration')
449
if disabled_flag != 'False':
450
if branch is not None:
451
config = branch.get_config()
452
disabled_flag = config.get_user_option('nautilus_integration')
455
def toggle_integration(self, menu, action, vfs_file=None):
457
tree, path = WorkingTree.open_containing(vfs_file.get_uri())
458
except NotBranchError:
460
except NoWorkingTree:
464
config = GlobalConfig()
466
config = branch.get_config()
467
config.set_user_option('nautilus_integration', action)