3
3
# Copyright (C) 2006 Jeff Bailey
4
4
# Copyright (C) 2006 Wouter van Heyst
5
# Copyright (C) 2006 Jelmer Vernooij
5
# Copyright (C) 2006-2008 Jelmer Vernooij <jelmer@samba.org>
7
7
# Published under the GNU GPL
9
from gi.repository import Gtk
11
from bzrlib.branch import Branch
11
12
from bzrlib.bzrdir import BzrDir
12
from bzrlib.errors import NotBranchError
13
from bzrlib.errors import (
13
18
from bzrlib.workingtree import WorkingTree
14
from bzrlib.tree import file_status
19
from bzrlib.config import GlobalConfig
16
21
from bzrlib.plugin import load_plugins
19
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
24
from bzrlib.plugins.gtk.commands import (
29
print "Bazaar nautilus module initialized"
21
32
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
22
34
def __init__(self):
139
155
file = vfs_file.get_uri()
141
159
tree, path = WorkingTree.open_containing(file)
142
except NotBranchError:
161
except NotBranchError, e:
164
except NoWorkingTree, e:
167
(branch, path) = Branch.open_containing(path)
168
except NotBranchError, e:
145
171
from bzrlib.plugins.gtk.commit import CommitDialog
146
172
dialog = CommitDialog(tree, path)
173
response = dialog.run()
174
if response != Gtk.ResponseType.NONE:
150
178
def log_cb(self, menu, vfs_file):
151
179
# We can only cope with local files
199
226
from bzrlib.plugins.gtk.merge import MergeDialog
200
227
dialog = MergeDialog(tree, path)
204
231
def get_background_items(self, window, vfs_file):
206
233
file = vfs_file.get_uri()
208
236
tree, path = WorkingTree.open_containing(file)
237
disabled_flag = self.check_branch_enabled(tree.branch)
238
except UnsupportedProtocol:
209
240
except NotBranchError:
241
disabled_flag = self.check_branch_enabled()
210
242
item = nautilus.MenuItem('BzrNautilus::newtree',
211
243
'Make directory versioned',
212
244
'Create new Bazaar tree in this folder')
214
246
items.append(item)
216
248
item = nautilus.MenuItem('BzrNautilus::clone',
217
'Checkout Bazaar branch',
249
'Checkout Bazaar branch ...',
218
250
'Checkout Existing Bazaar Branch')
219
251
item.connect('activate', self.clone_cb, vfs_file)
220
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)
224
271
item = nautilus.MenuItem('BzrNautilus::log',
226
273
'Show Bazaar history')
227
274
item.connect('activate', self.log_cb, vfs_file)
228
275
items.append(item)
230
277
item = nautilus.MenuItem('BzrNautilus::pull',
232
279
'Pull from another branch')
233
280
item.connect('activate', self.pull_cb, vfs_file)
234
281
items.append(item)
236
283
item = nautilus.MenuItem('BzrNautilus::merge',
238
285
'Merge from another branch')
239
286
item.connect('activate', self.merge_cb, vfs_file)
240
287
items.append(item)
242
289
item = nautilus.MenuItem('BzrNautilus::commit',
244
291
'Commit Changes')
245
292
item.connect('activate', self.commit_cb, vfs_file)
246
293
items.append(item)
251
297
def get_file_items(self, window, files):
254
301
for vfs_file in files:
255
302
# We can only cope with local files
256
303
if vfs_file.get_uri_scheme() != 'file':
259
306
file = vfs_file.get_uri()
261
308
tree, path = WorkingTree.open_containing(file)
309
disabled_flag = self.check_branch_enabled(tree.branch)
262
310
except NotBranchError:
311
disabled_flag = self.check_branch_enabled()
263
312
if not vfs_file.is_directory():
315
if disabled_flag == 'False':
265
318
item = nautilus.MenuItem('BzrNautilus::newtree',
266
319
'Make directory versioned',
267
320
'Create new Bazaar tree in %s' % vfs_file.get_name())
268
321
item.connect('activate', self.newtree_cb, vfs_file)
271
file_class = tree.file_class(path)
273
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] == '?':
274
334
item = nautilus.MenuItem('BzrNautilus::add',
276
336
'Add as versioned file')
282
342
'Ignore file for versioning')
283
343
item.connect('activate', self.ignore_cb, vfs_file)
284
344
items.append(item)
285
elif file_class == 'I':
345
elif wtfiles[path] == 'I':
286
346
item = nautilus.MenuItem('BzrNautilus::unignore',
288
348
'Unignore file for versioning')
289
349
item.connect('activate', self.unignore_cb, vfs_file)
290
350
items.append(item)
291
elif file_class == 'V':
351
elif wtfiles[path] == 'V':
292
352
item = nautilus.MenuItem('BzrNautilus::log',
295
355
item.connect('activate', self.log_cb, vfs_file)
296
356
items.append(item)
298
358
item = nautilus.MenuItem('BzrNautilus::diff',
300
360
'Show differences')
301
361
item.connect('activate', self.diff_cb, vfs_file)
302
362
items.append(item)
335
396
tree, path = WorkingTree.open_containing(file.get_uri())
336
397
except NotBranchError:
399
except NoWorkingTree:
402
disabled_flag = self.check_branch_enabled(tree.branch)
403
if disabled_flag == 'False':
342
if tree.has_filename(path):
343
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'
344
419
status = 'unchanged'
345
id = tree.path2id(path)
347
421
delta = tree.changes_from(tree.branch.basis_tree())
348
422
if delta.touches_file_id(id):
349
emblem = 'cvs-modified'
423
emblem = 'bzr-modified'
350
424
status = 'modified'
351
425
for f, _, _ in delta.added:
356
430
for of, f, _, _, _, _ in delta.renamed:
367
441
if emblem is not None:
368
442
file.add_emblem(emblem)
369
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)