7
7
# Published under the GNU GPL
9
from gi.repository import Gtk
11
12
from bzrlib.branch import Branch
12
13
from bzrlib.bzrdir import BzrDir
13
from bzrlib.errors import (
14
from bzrlib.errors import NotBranchError, NoWorkingTree, UnsupportedProtocol
15
from bzrlib.tree import file_status
18
16
from bzrlib.workingtree import WorkingTree
19
from bzrlib.config import GlobalConfig
21
18
from bzrlib.plugin import load_plugins
24
from bzrlib.plugins.gtk.commands import (
29
print "Bazaar nautilus module initialized"
21
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
32
23
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
34
24
def __init__(self):
93
83
from bzrlib.plugins.gtk.diff import DiffWindow
94
84
window = DiffWindow()
95
window.set_diff(tree.branch._get_nick(local=True), tree,
96
tree.branch.basis_tree())
85
window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
171
160
from bzrlib.plugins.gtk.commit import CommitDialog
172
161
dialog = CommitDialog(tree, path)
173
162
response = dialog.run()
174
if response != Gtk.ResponseType.NONE:
163
if response != gtk.RESPONSE_NONE:
185
174
# We only want to continue here if we get a NotBranchError
187
branch, path = Branch.open_containing(file)
176
tree, path = WorkingTree.open_containing(file)
188
177
except NotBranchError:
191
pp = start_viz_window(branch, [branch.last_revision()])
180
vis = cmd_visualise()
195
185
def pull_cb(self, menu, vfs_file):
196
186
# We can only cope with local files
208
198
from bzrlib.plugins.gtk.pull import PullDialog
209
199
dialog = PullDialog(tree, path)
213
203
def merge_cb(self, menu, vfs_file):
214
204
# We can only cope with local files
226
216
from bzrlib.plugins.gtk.merge import MergeDialog
227
217
dialog = MergeDialog(tree, path)
231
221
def get_background_items(self, window, vfs_file):
233
223
file = vfs_file.get_uri()
236
225
tree, path = WorkingTree.open_containing(file)
237
disabled_flag = self.check_branch_enabled(tree.branch)
238
226
except UnsupportedProtocol:
240
228
except NotBranchError:
241
disabled_flag = self.check_branch_enabled()
242
229
item = nautilus.MenuItem('BzrNautilus::newtree',
243
230
'Make directory versioned',
244
231
'Create new Bazaar tree in this folder')
246
233
items.append(item)
248
235
item = nautilus.MenuItem('BzrNautilus::clone',
249
'Checkout Bazaar branch ...',
236
'Checkout Bazaar branch',
250
237
'Checkout Existing Bazaar Branch')
251
238
item.connect('activate', self.clone_cb, vfs_file)
252
239
items.append(item)
255
242
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)
271
245
item = nautilus.MenuItem('BzrNautilus::log',
273
247
'Show Bazaar history')
274
248
item.connect('activate', self.log_cb, vfs_file)
275
249
items.append(item)
277
251
item = nautilus.MenuItem('BzrNautilus::pull',
279
253
'Pull from another branch')
280
254
item.connect('activate', self.pull_cb, vfs_file)
281
255
items.append(item)
283
257
item = nautilus.MenuItem('BzrNautilus::merge',
285
259
'Merge from another branch')
286
260
item.connect('activate', self.merge_cb, vfs_file)
287
261
items.append(item)
289
263
item = nautilus.MenuItem('BzrNautilus::commit',
291
265
'Commit Changes')
292
266
item.connect('activate', self.commit_cb, vfs_file)
293
267
items.append(item)
306
280
file = vfs_file.get_uri()
308
282
tree, path = WorkingTree.open_containing(file)
309
disabled_flag = self.check_branch_enabled(tree.branch)
310
283
except NotBranchError:
311
disabled_flag = self.check_branch_enabled()
312
284
if not vfs_file.is_directory():
315
if disabled_flag == 'False':
318
286
item = nautilus.MenuItem('BzrNautilus::newtree',
319
287
'Make directory versioned',
320
288
'Create new Bazaar tree in %s' % vfs_file.get_name())
350
318
items.append(item)
351
319
elif wtfiles[path] == 'V':
352
320
item = nautilus.MenuItem('BzrNautilus::log',
355
323
item.connect('activate', self.log_cb, vfs_file)
356
324
items.append(item)
358
326
item = nautilus.MenuItem('BzrNautilus::diff',
360
328
'Show differences')
361
329
item.connect('activate', self.diff_cb, vfs_file)
362
330
items.append(item)
368
336
items.append(item)
370
338
item = nautilus.MenuItem('BzrNautilus::annotate',
372
340
'Annotate File Data')
373
341
item.connect('activate', self.annotate_cb, vfs_file)
374
342
items.append(item)
376
344
item = nautilus.MenuItem('BzrNautilus::commit',
378
346
'Commit Changes')
379
347
item.connect('activate', self.commit_cb, vfs_file)
380
348
items.append(item)
397
364
except NotBranchError:
399
366
except NoWorkingTree:
402
disabled_flag = self.check_branch_enabled(tree.branch)
403
if disabled_flag == 'False':
409
id = tree.path2id(path)
411
if tree.is_ignored(path):
413
emblem = 'bzr-ignored'
415
status = 'unversioned'
417
elif tree.has_filename(path):
372
if tree.has_filename(path):
418
373
emblem = 'bzr-controlled'
419
374
status = 'unchanged'
375
id = tree.path2id(path)
421
377
delta = tree.changes_from(tree.branch.basis_tree())
422
378
if delta.touches_file_id(id):
438
394
# FIXME: Check for ignored files
439
395
status = 'unversioned'
396
emblem = 'bzr-unversioned'
441
398
if emblem is not None:
442
399
file.add_emblem(emblem)
443
400
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)