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
11
from bzrlib.plugins.gtk.viz import cmd_visualise
12
from bzrlib.plugins.gtk.annotate import cmd_gannotate
15
have_gtkplugin = False
17
class BzrExtension(nautilus.MenuProvider):
21
def add_cb(self, menu, vfs_file):
22
# We can only cope with local files
23
if vfs_file.get_uri_scheme() != 'file':
26
file = vfs_file.get_uri()
28
tree, path = WorkingTree.open_containing(file)
29
except NotBranchError:
36
def ignore_cb(self, menu, vfs_file):
37
# We can only cope with local files
38
if vfs_file.get_uri_scheme() != 'file':
41
file = vfs_file.get_uri()
43
tree, path = WorkingTree.open_containing(file)
44
except NotBranchError:
49
def unignore_cb(self, menu, vfs_file):
50
# We can only cope with local files
51
if vfs_file.get_uri_scheme() != 'file':
54
file = vfs_file.get_uri()
56
tree, path = WorkingTree.open_containing(file)
57
except NotBranchError:
62
def diff_cb(self, menu, vfs_file):
63
# We can only cope with local files
64
if vfs_file.get_uri_scheme() != 'file':
67
file = vfs_file.get_uri()
69
tree, path = WorkingTree.open_containing(file)
70
except NotBranchError:
73
from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
75
window.set_diff(tree.branch, tree, tree.branch.revision_tree())
80
def newtree_cb(self, menu, vfs_file):
81
# We can only cope with local files
82
if vfs_file.get_uri_scheme() != 'file':
85
file = vfs_file.get_uri()
87
# We only want to continue here if we get a NotBranchError
89
tree, path = WorkingTree.open_containing(file)
90
except NotBranchError:
91
BzrDir.create_branch_and_repo(file)
96
def remove_cb(self, menu, vfs_file):
97
# We can only cope with local files
98
if vfs_file.get_uri_scheme() != 'file':
101
file = vfs_file.get_uri()
103
tree, path = WorkingTree.open_containing(file)
104
except NotBranchError:
111
def annotate_cb(self, menu, vfs_file):
112
# We can only cope with local files
113
if vfs_file.get_uri_scheme() != 'file':
116
file = vfs_file.get_uri()
118
vis = cmd_gannotate()
121
def commit_cb(self, menu, vfs_file=None):
122
# We can only cope with local files
123
if vfs_file.get_uri_scheme() != 'file':
126
file = vfs_file.get_uri()
128
tree, path = WorkingTree.open_containing(file)
129
except NotBranchError:
132
from bzrlib.plugins.gtk.commit.gcommit import GCommitDialog
133
dialog = GCommitDialog(tree)
134
dialog.set_title(path + " - Commit")
135
if dialog.run() != gtk.RESPONSE_CANCEL:
136
Commit().commit(working_tree=wt,message=dialog.message,
137
specific_files=dialog.specific_files)
139
def log_cb(self, menu, vfs_file):
140
# We can only cope with local files
141
if vfs_file.get_uri_scheme() != 'file':
144
file = vfs_file.get_uri()
146
# We only want to continue here if we get a NotBranchError
148
tree, path = WorkingTree.open_containing(file)
149
except NotBranchError:
152
vis = cmd_visualise()
157
def get_background_items(self, window, vfs_file):
158
file = vfs_file.get_uri()
160
tree, path = WorkingTree.open_containing(file)
161
except NotBranchError:
162
item = nautilus.MenuItem('BzrNautilus::newtree',
163
'Create new Bazaar tree',
164
'Create new Bazaar tree in this folder')
165
item.connect('activate', self.newtree_cb, vfs_file)
170
item = nautilus.MenuItem('BzrNautilus::log',
172
'Show Bazaar history')
173
item.connect('activate', self.log_cb, vfs_file)
176
item = nautilus.MenuItem('BzrNautilus::commit',
179
item.connect('activate', self.commit_cb, vfs_file)
185
def get_file_items(self, window, files):
188
for vfs_file in files:
189
# We can only cope with local files
190
if vfs_file.get_uri_scheme() != 'file':
193
file = vfs_file.get_uri()
195
tree, path = WorkingTree.open_containing(file)
196
except NotBranchError:
197
if not vfs_file.is_directory():
199
item = nautilus.MenuItem('BzrNautilus::newtree',
200
'Create new Bazaar tree',
201
'Create new Bazaar tree in %s' % vfs_file.get_name())
202
item.connect('activate', self.newtree_cb, vfs_file)
205
file_class = tree.file_class(path)
207
if file_class == '?':
208
item = nautilus.MenuItem('BzrNautilus::add',
210
'Add as versioned file')
211
item.connect('activate', self.add_cb, vfs_file)
214
item = nautilus.MenuItem('BzrNautilus::ignore',
216
'Ignore file for versioning')
217
item.connect('activate', self.ignore_cb, vfs_file)
219
elif file_class == 'I':
220
item = nautilus.MenuItem('BzrNautilus::unignore',
222
'Unignore file for versioning')
223
item.connect('activate', self.unignore_cb, vfs_file)
225
elif file_class == 'V':
227
item = nautilus.MenuItem('BzrNautilus::log',
230
item.connect('activate', self.log_cb, vfs_file)
233
item = nautilus.MenuItem('BzrNautilus::diff',
236
item.connect('activate', self.diff_cb, vfs_file)
239
item = nautilus.MenuItem('BzrNautilus::remove',
241
'Remove this file from versioning')
242
item.connect('activate', self.remove_cb, vfs_file)
246
item = nautilus.MenuItem('BzrNautilus::annotate',
248
'Annotate File Data')
249
item.connect('activate', self.annotate_cb, vfs_file)
252
item = nautilus.MenuItem('BzrNautilus::commit',
255
item.connect('activate', self.commit_cb, vfs_file)