3
from bzrlib.bzrdir import BzrDir
4
from bzrlib.errors import NotBranchError
5
from bzrlib.workingtree import WorkingTree
7
from bzrlib.plugin import load_plugins
10
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
12
class BzrExtension(nautilus.MenuProvider):
16
def add_cb(self, menu, vfs_file):
17
# We can only cope with local files
18
if vfs_file.get_uri_scheme() != 'file':
21
file = vfs_file.get_uri()
23
tree, path = WorkingTree.open_containing(file)
24
except NotBranchError:
31
def ignore_cb(self, menu, vfs_file):
32
# We can only cope with local files
33
if vfs_file.get_uri_scheme() != 'file':
36
file = vfs_file.get_uri()
38
tree, path = WorkingTree.open_containing(file)
39
except NotBranchError:
46
def unignore_cb(self, menu, vfs_file):
47
# We can only cope with local files
48
if vfs_file.get_uri_scheme() != 'file':
51
file = vfs_file.get_uri()
53
tree, path = WorkingTree.open_containing(file)
54
except NotBranchError:
61
def diff_cb(self, menu, vfs_file):
62
# We can only cope with local files
63
if vfs_file.get_uri_scheme() != 'file':
66
file = vfs_file.get_uri()
68
tree, path = WorkingTree.open_containing(file)
69
except NotBranchError:
72
from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
74
window.set_diff(tree.branch, tree, tree.branch.revision_tree())
79
def newtree_cb(self, menu, vfs_file):
80
# We can only cope with local files
81
if vfs_file.get_uri_scheme() != 'file':
84
file = vfs_file.get_uri()
86
# We only want to continue here if we get a NotBranchError
88
tree, path = WorkingTree.open_containing(file)
89
except NotBranchError:
90
BzrDir.create_branch_and_repo(file)
92
def remove_cb(self, menu, vfs_file):
93
# We can only cope with local files
94
if vfs_file.get_uri_scheme() != 'file':
97
file = vfs_file.get_uri()
99
tree, path = WorkingTree.open_containing(file)
100
except NotBranchError:
105
def annotate_cb(self, menu, vfs_file):
106
# We can only cope with local files
107
if vfs_file.get_uri_scheme() != 'file':
110
file = vfs_file.get_uri()
112
vis = cmd_gannotate()
115
def clone_cb(self, menu, vfs_file=None):
116
# We can only cope with local files
117
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)
132
def commit_cb(self, menu, vfs_file=None):
133
# We can only cope with local files
134
if vfs_file.get_uri_scheme() != 'file':
137
file = vfs_file.get_uri()
139
tree, path = WorkingTree.open_containing(file)
140
except NotBranchError:
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)
150
def log_cb(self, menu, vfs_file):
151
# We can only cope with local files
152
if vfs_file.get_uri_scheme() != 'file':
155
file = vfs_file.get_uri()
157
# We only want to continue here if we get a NotBranchError
159
tree, path = WorkingTree.open_containing(file)
160
except NotBranchError:
163
vis = cmd_visualise()
168
def get_background_items(self, window, vfs_file):
169
file = vfs_file.get_uri()
171
tree, path = WorkingTree.open_containing(file)
172
except NotBranchError:
173
item = nautilus.MenuItem('BzrNautilus::newtree',
174
'Create new Bazaar tree',
175
'Create new Bazaar tree in this folder')
176
item.connect('activate', self.newtree_cb, vfs_file)
179
item = nautilus.MenuItem('BzrNautilus::clone',
181
'Checkout Existing Bazaar Branch')
182
item.connect('activate', self.clone_cb, vfs_file)
188
item = nautilus.MenuItem('BzrNautilus::log',
190
'Show Bazaar history')
191
item.connect('activate', self.log_cb, vfs_file)
194
item = nautilus.MenuItem('BzrNautilus::commit',
197
item.connect('activate', self.commit_cb, vfs_file)
203
def get_file_items(self, window, files):
206
for vfs_file in files:
207
# We can only cope with local files
208
if vfs_file.get_uri_scheme() != 'file':
211
file = vfs_file.get_uri()
213
tree, path = WorkingTree.open_containing(file)
214
except NotBranchError:
215
if not vfs_file.is_directory():
217
item = nautilus.MenuItem('BzrNautilus::newtree',
218
'Create new Bazaar tree',
219
'Create new Bazaar tree in %s' % vfs_file.get_name())
220
item.connect('activate', self.newtree_cb, vfs_file)
223
file_class = tree.file_class(path)
225
if file_class == '?':
226
item = nautilus.MenuItem('BzrNautilus::add',
228
'Add as versioned file')
229
item.connect('activate', self.add_cb, vfs_file)
232
item = nautilus.MenuItem('BzrNautilus::ignore',
234
'Ignore file for versioning')
235
item.connect('activate', self.ignore_cb, vfs_file)
237
elif file_class == 'I':
238
item = nautilus.MenuItem('BzrNautilus::unignore',
240
'Unignore file for versioning')
241
item.connect('activate', self.unignore_cb, vfs_file)
243
elif file_class == 'V':
244
item = nautilus.MenuItem('BzrNautilus::log',
247
item.connect('activate', self.log_cb, vfs_file)
250
item = nautilus.MenuItem('BzrNautilus::diff',
253
item.connect('activate', self.diff_cb, vfs_file)
256
item = nautilus.MenuItem('BzrNautilus::remove',
258
'Remove this file from versioning')
259
item.connect('activate', self.remove_cb, vfs_file)
262
item = nautilus.MenuItem('BzrNautilus::annotate',
264
'Annotate File Data')
265
item.connect('activate', self.annotate_cb, vfs_file)
268
item = nautilus.MenuItem('BzrNautilus::commit',
271
item.connect('activate', self.commit_cb, vfs_file)