1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
import nautilus
import bzrlib
from bzrlib.bzrdir import BzrDir
from bzrlib.errors import NotBranchError
from bzrlib.workingtree import WorkingTree
from bzrlib.plugin import load_plugins
load_plugins()
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
class BzrExtension(nautilus.MenuProvider):
def __init__(self):
pass
def add_cb(self, menu, vfs_file):
# We can only cope with local files
if vfs_file.get_uri_scheme() != 'file':
return
file = vfs_file.get_uri()
try:
tree, path = WorkingTree.open_containing(file)
except NotBranchError:
return
tree.add(path)
return
def ignore_cb(self, menu, vfs_file):
# We can only cope with local files
if vfs_file.get_uri_scheme() != 'file':
return
file = vfs_file.get_uri()
try:
tree, path = WorkingTree.open_containing(file)
except NotBranchError:
return
#FIXME
return
def unignore_cb(self, menu, vfs_file):
# We can only cope with local files
if vfs_file.get_uri_scheme() != 'file':
return
file = vfs_file.get_uri()
try:
tree, path = WorkingTree.open_containing(file)
except NotBranchError:
return
#FIXME
return
def diff_cb(self, menu, vfs_file):
# We can only cope with local files
if vfs_file.get_uri_scheme() != 'file':
return
file = vfs_file.get_uri()
try:
tree, path = WorkingTree.open_containing(file)
except NotBranchError:
return
from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
window = DiffWindow()
window.set_diff(tree.branch, tree, tree.branch.revision_tree())
window.show()
return
def newtree_cb(self, menu, vfs_file):
# We can only cope with local files
if vfs_file.get_uri_scheme() != 'file':
return
file = vfs_file.get_uri()
# We only want to continue here if we get a NotBranchError
try:
tree, path = WorkingTree.open_containing(file)
except NotBranchError:
BzrDir.create_branch_and_repo(file)
def remove_cb(self, menu, vfs_file):
# We can only cope with local files
if vfs_file.get_uri_scheme() != 'file':
return
file = vfs_file.get_uri()
try:
tree, path = WorkingTree.open_containing(file)
except NotBranchError:
return
tree.remove(path)
def annotate_cb(self, menu, vfs_file):
# We can only cope with local files
if vfs_file.get_uri_scheme() != 'file':
return
file = vfs_file.get_uri()
vis = cmd_gannotate()
vis.run(file)
def clone_cb(self, menu, vfs_file=None):
# We can only cope with local files
if vfs_file.get_uri_scheme() != 'file':
return
file = vfs_file.get_uri()
try:
tree, path = WorkingTree.open_containing(file)
except NotBranchError:
return
from bzrlib.plugins.gtk.clone import CloneDialog
dialog = CloneDialog(file)
if dialog.run() != gtk.RESPONSE_CANCEL:
bzrdir = BzrDir.open(dialog.url)
bzrdir.sprout(dialog.dest_path)
def commit_cb(self, menu, vfs_file=None):
# We can only cope with local files
if vfs_file.get_uri_scheme() != 'file':
return
file = vfs_file.get_uri()
try:
tree, path = WorkingTree.open_containing(file)
except NotBranchError:
return
from bzrlib.plugins.gtk.commit import GCommitDialog
dialog = GCommitDialog(tree)
dialog.set_title(path + " - Commit")
if dialog.run() != gtk.RESPONSE_CANCEL:
Commit().commit(working_tree=wt,message=dialog.message,
specific_files=dialog.specific_files)
def log_cb(self, menu, vfs_file):
# We can only cope with local files
if vfs_file.get_uri_scheme() != 'file':
return
file = vfs_file.get_uri()
# We only want to continue here if we get a NotBranchError
try:
tree, path = WorkingTree.open_containing(file)
except NotBranchError:
return
vis = cmd_visualise()
vis.run(file)
return
def get_background_items(self, window, vfs_file):
file = vfs_file.get_uri()
try:
tree, path = WorkingTree.open_containing(file)
except NotBranchError:
item = nautilus.MenuItem('BzrNautilus::newtree',
'Create new Bazaar tree',
'Create new Bazaar tree in this folder')
item.connect('activate', self.newtree_cb, vfs_file)
items.append(item)
item = nautilus.MenuItem('BzrNautilus::clone',
'Checkout',
'Checkout Existing Bazaar Branch')
item.connect('activate', self.clone_cb, vfs_file)
items.append(item)
return items
items = []
item = nautilus.MenuItem('BzrNautilus::log',
'Log',
'Show Bazaar history')
item.connect('activate', self.log_cb, vfs_file)
items.append(item)
item = nautilus.MenuItem('BzrNautilus::commit',
'Commit',
'Commit Changes')
item.connect('activate', self.commit_cb, vfs_file)
items.append(item)
return items
def get_file_items(self, window, files):
items = []
for vfs_file in files:
# We can only cope with local files
if vfs_file.get_uri_scheme() != 'file':
return
file = vfs_file.get_uri()
try:
tree, path = WorkingTree.open_containing(file)
except NotBranchError:
if not vfs_file.is_directory():
return
item = nautilus.MenuItem('BzrNautilus::newtree',
'Create new Bazaar tree',
'Create new Bazaar tree in %s' % vfs_file.get_name())
item.connect('activate', self.newtree_cb, vfs_file)
return item,
file_class = tree.file_class(path)
if file_class == '?':
item = nautilus.MenuItem('BzrNautilus::add',
'Add',
'Add as versioned file')
item.connect('activate', self.add_cb, vfs_file)
items.append(item)
item = nautilus.MenuItem('BzrNautilus::ignore',
'Ignore',
'Ignore file for versioning')
item.connect('activate', self.ignore_cb, vfs_file)
items.append(item)
elif file_class == 'I':
item = nautilus.MenuItem('BzrNautilus::unignore',
'Unignore',
'Unignore file for versioning')
item.connect('activate', self.unignore_cb, vfs_file)
items.append(item)
elif file_class == 'V':
item = nautilus.MenuItem('BzrNautilus::log',
'Log',
'List changes')
item.connect('activate', self.log_cb, vfs_file)
items.append(item)
item = nautilus.MenuItem('BzrNautilus::diff',
'Diff',
'Show differences')
item.connect('activate', self.diff_cb, vfs_file)
items.append(item)
item = nautilus.MenuItem('BzrNautilus::remove',
'Remove',
'Remove this file from versioning')
item.connect('activate', self.remove_cb, vfs_file)
items.append(item)
item = nautilus.MenuItem('BzrNautilus::annotate',
'Annotate',
'Annotate File Data')
item.connect('activate', self.annotate_cb, vfs_file)
items.append(item)
item = nautilus.MenuItem('BzrNautilus::commit',
'Commit',
'Commit Changes')
item.connect('activate', self.commit_cb, vfs_file)
items.append(item)
return items
|