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
12
from bzrlib.branch import Branch
3
13
from bzrlib.bzrdir import BzrDir
4
from bzrlib.errors import NotBranchError
14
from bzrlib.errors import NotBranchError, NoWorkingTree, UnsupportedProtocol
15
from bzrlib.tree import file_status
5
16
from bzrlib.workingtree import WorkingTree
6
from bzrlib.tree import file_status
8
18
from bzrlib.plugin import load_plugins
89
99
tree, path = WorkingTree.open_containing(file)
90
100
except NotBranchError:
91
BzrDir.create_branch_and_repo(file)
101
BzrDir.create_standalone_workingtree(file)
93
103
def remove_cb(self, menu, vfs_file):
94
104
# We can only cope with local files
118
128
if vfs_file.get_uri_scheme() != 'file':
121
from bzrlib.plugins.gtk.olive.branch import BranchDialog
131
from bzrlib.plugins.gtk.branch import BranchDialog
123
133
dialog = BranchDialog(vfs_file.get_name())
134
response = dialog.run()
135
if response != gtk.RESPONSE_NONE:
126
139
def commit_cb(self, menu, vfs_file=None):
127
140
# We can only cope with local files
131
144
file = vfs_file.get_uri()
133
148
tree, path = WorkingTree.open_containing(file)
134
except NotBranchError:
150
except NotBranchError, e:
153
except NoWorkingTree, e:
156
(branch, path) = Branch.open_containing(path)
157
except NotBranchError, e:
137
from bzrlib.plugins.gtk.olive.commit import CommitDialog
160
from bzrlib.plugins.gtk.commit import CommitDialog
138
161
dialog = CommitDialog(tree, path)
162
response = dialog.run()
163
if response != gtk.RESPONSE_NONE:
142
167
def log_cb(self, menu, vfs_file):
143
168
# We can only cope with local files
185
def pull_cb(self, menu, vfs_file):
186
# We can only cope with local files
187
if vfs_file.get_uri_scheme() != 'file':
190
file = vfs_file.get_uri()
192
# We only want to continue here if we get a NotBranchError
194
tree, path = WorkingTree.open_containing(file)
195
except NotBranchError:
198
from bzrlib.plugins.gtk.pull import PullDialog
199
dialog = PullDialog(tree, path)
203
def merge_cb(self, menu, vfs_file):
204
# We can only cope with local files
205
if vfs_file.get_uri_scheme() != 'file':
208
file = vfs_file.get_uri()
210
# We only want to continue here if we get a NotBranchError
212
tree, path = WorkingTree.open_containing(file)
213
except NotBranchError:
216
from bzrlib.plugins.gtk.merge import MergeDialog
217
dialog = MergeDialog(tree, path)
160
221
def get_background_items(self, window, vfs_file):
162
223
file = vfs_file.get_uri()
164
225
tree, path = WorkingTree.open_containing(file)
226
except UnsupportedProtocol:
165
228
except NotBranchError:
166
229
item = nautilus.MenuItem('BzrNautilus::newtree',
167
230
'Make directory versioned',
183
248
item.connect('activate', self.log_cb, vfs_file)
184
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)
186
263
item = nautilus.MenuItem('BzrNautilus::commit',
188
265
'Commit Changes')
195
271
def get_file_items(self, window, files):
198
275
for vfs_file in files:
199
276
# We can only cope with local files
200
277
if vfs_file.get_uri_scheme() != 'file':
203
280
file = vfs_file.get_uri()
205
282
tree, path = WorkingTree.open_containing(file)
206
283
except NotBranchError:
207
284
if not vfs_file.is_directory():
209
286
item = nautilus.MenuItem('BzrNautilus::newtree',
210
287
'Make directory versioned',
211
288
'Create new Bazaar tree in %s' % vfs_file.get_name())
212
289
item.connect('activate', self.newtree_cb, vfs_file)
215
file_class = tree.file_class(path)
217
if file_class == '?':
291
except NoWorkingTree:
293
# Refresh the list of filestatuses in the working tree
294
if path not in wtfiles.keys():
296
for rpath, file_class, kind, id, entry in tree.list_files():
297
wtfiles[rpath] = file_class
301
if wtfiles[path] == '?':
218
302
item = nautilus.MenuItem('BzrNautilus::add',
220
304
'Add as versioned file')
226
310
'Ignore file for versioning')
227
311
item.connect('activate', self.ignore_cb, vfs_file)
228
312
items.append(item)
229
elif file_class == 'I':
313
elif wtfiles[path] == 'I':
230
314
item = nautilus.MenuItem('BzrNautilus::unignore',
232
316
'Unignore file for versioning')
233
317
item.connect('activate', self.unignore_cb, vfs_file)
234
318
items.append(item)
235
elif file_class == 'V':
319
elif wtfiles[path] == 'V':
236
320
item = nautilus.MenuItem('BzrNautilus::log',
279
363
tree, path = WorkingTree.open_containing(file.get_uri())
280
364
except NotBranchError:
366
except NoWorkingTree:
286
372
if tree.has_filename(path):
287
emblem = 'cvs-controlled'
373
emblem = 'bzr-controlled'
288
374
status = 'unchanged'
289
375
id = tree.path2id(path)
291
377
delta = tree.changes_from(tree.branch.basis_tree())
292
378
if delta.touches_file_id(id):
293
emblem = 'cvs-modified'
379
emblem = 'bzr-modified'
294
380
status = 'modified'
295
381
for f, _, _ in delta.added:
300
386
for of, f, _, _, _, _ in delta.renamed: