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 import cmd_visualise, cmd_gannotate
14
have_gtkplugin = False
16
class BzrExtension(nautilus.MenuProvider):
20
def add_cb(self, menu, vfs_file):
21
# We can only cope with local files
22
if vfs_file.get_uri_scheme() != 'file':
25
file = vfs_file.get_uri()
27
tree, path = WorkingTree.open_containing(file)
28
except NotBranchError:
35
def ignore_cb(self, menu, vfs_file):
36
# We can only cope with local files
37
if vfs_file.get_uri_scheme() != 'file':
40
file = vfs_file.get_uri()
42
tree, path = WorkingTree.open_containing(file)
43
except NotBranchError:
50
def unignore_cb(self, menu, vfs_file):
51
# We can only cope with local files
52
if vfs_file.get_uri_scheme() != 'file':
55
file = vfs_file.get_uri()
57
tree, path = WorkingTree.open_containing(file)
58
except NotBranchError:
65
def diff_cb(self, menu, vfs_file):
66
# We can only cope with local files
67
if vfs_file.get_uri_scheme() != 'file':
70
file = vfs_file.get_uri()
72
tree, path = WorkingTree.open_containing(file)
73
except NotBranchError:
76
from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
78
window.set_diff(tree.branch, tree, tree.branch.revision_tree())
83
def newtree_cb(self, menu, vfs_file):
84
# We can only cope with local files
85
if vfs_file.get_uri_scheme() != 'file':
88
file = vfs_file.get_uri()
90
# We only want to continue here if we get a NotBranchError
92
tree, path = WorkingTree.open_containing(file)
93
except NotBranchError:
94
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:
109
def annotate_cb(self, menu, vfs_file):
110
# We can only cope with local files
111
if vfs_file.get_uri_scheme() != 'file':
114
file = vfs_file.get_uri()
116
vis = cmd_gannotate()
119
def clone_cb(self, menu, vfs_file=None):
120
# We can only cope with local files
121
if vfs_file.get_uri_scheme() != 'file':
124
file = vfs_file.get_uri()
126
tree, path = WorkingTree.open_containing(file)
127
except NotBranchError:
130
from bzrlib.plugins.gtk.clone import CloneDialog
131
dialog = CloneDialog(file)
132
if dialog.run() != gtk.RESPONSE_CANCEL:
133
bzrdir = BzrDir.open(dialog.url)
134
bzrdir.sprout(dialog.dest_path)
136
def commit_cb(self, menu, vfs_file=None):
137
# We can only cope with local files
138
if vfs_file.get_uri_scheme() != 'file':
141
file = vfs_file.get_uri()
143
tree, path = WorkingTree.open_containing(file)
144
except NotBranchError:
147
from bzrlib.plugins.gtk.commit import GCommitDialog
148
dialog = GCommitDialog(tree)
149
dialog.set_title(path + " - Commit")
150
if dialog.run() != gtk.RESPONSE_CANCEL:
151
Commit().commit(working_tree=wt,message=dialog.message,
152
specific_files=dialog.specific_files)
154
def log_cb(self, menu, vfs_file):
155
# We can only cope with local files
156
if vfs_file.get_uri_scheme() != 'file':
159
file = vfs_file.get_uri()
161
# We only want to continue here if we get a NotBranchError
163
tree, path = WorkingTree.open_containing(file)
164
except NotBranchError:
167
vis = cmd_visualise()
172
def get_background_items(self, window, vfs_file):
173
file = vfs_file.get_uri()
175
tree, path = WorkingTree.open_containing(file)
176
except NotBranchError:
177
item = nautilus.MenuItem('BzrNautilus::newtree',
178
'Create new Bazaar tree',
179
'Create new Bazaar tree in this folder')
180
item.connect('activate', self.newtree_cb, vfs_file)
183
item = nautilus.MenuItem('BzrNautilus::clone',
185
'Checkout Existing Bazaar Branch')
186
item.connect('activate', self.clone_cb, vfs_file)
193
item = nautilus.MenuItem('BzrNautilus::log',
195
'Show Bazaar history')
196
item.connect('activate', self.log_cb, vfs_file)
199
item = nautilus.MenuItem('BzrNautilus::commit',
202
item.connect('activate', self.commit_cb, vfs_file)
208
def get_file_items(self, window, files):
211
for vfs_file in files:
212
# We can only cope with local files
213
if vfs_file.get_uri_scheme() != 'file':
216
file = vfs_file.get_uri()
218
tree, path = WorkingTree.open_containing(file)
219
except NotBranchError:
220
if not vfs_file.is_directory():
222
item = nautilus.MenuItem('BzrNautilus::newtree',
223
'Create new Bazaar tree',
224
'Create new Bazaar tree in %s' % vfs_file.get_name())
225
item.connect('activate', self.newtree_cb, vfs_file)
228
file_class = tree.file_class(path)
230
if file_class == '?':
231
item = nautilus.MenuItem('BzrNautilus::add',
233
'Add as versioned file')
234
item.connect('activate', self.add_cb, vfs_file)
237
item = nautilus.MenuItem('BzrNautilus::ignore',
239
'Ignore file for versioning')
240
item.connect('activate', self.ignore_cb, vfs_file)
242
elif file_class == 'I':
243
item = nautilus.MenuItem('BzrNautilus::unignore',
245
'Unignore file for versioning')
246
item.connect('activate', self.unignore_cb, vfs_file)
248
elif file_class == 'V':
250
item = nautilus.MenuItem('BzrNautilus::log',
253
item.connect('activate', self.log_cb, vfs_file)
256
item = nautilus.MenuItem('BzrNautilus::diff',
259
item.connect('activate', self.diff_cb, vfs_file)
262
item = nautilus.MenuItem('BzrNautilus::remove',
264
'Remove this file from versioning')
265
item.connect('activate', self.remove_cb, vfs_file)
269
item = nautilus.MenuItem('BzrNautilus::annotate',
271
'Annotate File Data')
272
item.connect('activate', self.annotate_cb, vfs_file)
275
item = nautilus.MenuItem('BzrNautilus::commit',
278
item.connect('activate', self.commit_cb, vfs_file)