/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to nautilus-bzr.py

  • Committer: Aaron Bentley
  • Date: 2007-01-17 06:42:55 UTC
  • mto: This revision was merged to the branch mainline in revision 129.
  • Revision ID: aaron.bentley@utoronto.ca-20070117064255-x4gznz5e0lyjq3gk
Remove usused span selector

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import nautilus
 
2
import bzrlib
 
3
from bzrlib.bzrdir import BzrDir
 
4
from bzrlib.errors import NotBranchError
 
5
from bzrlib.workingtree import WorkingTree
 
6
from bzrlib.tree import file_status
 
7
 
 
8
from bzrlib.plugin import load_plugins
 
9
load_plugins()
 
10
 
 
11
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
 
12
 
 
13
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
 
14
    def __init__(self):
 
15
        pass
 
16
 
 
17
    def add_cb(self, menu, vfs_file):
 
18
        # We can only cope with local files
 
19
        if vfs_file.get_uri_scheme() != 'file':
 
20
            return
 
21
 
 
22
        file = vfs_file.get_uri()
 
23
        try:
 
24
            tree, path = WorkingTree.open_containing(file)
 
25
        except NotBranchError:
 
26
            return
 
27
 
 
28
        tree.add(path)
 
29
 
 
30
        return
 
31
 
 
32
    def ignore_cb(self, menu, vfs_file):
 
33
        # We can only cope with local files
 
34
        if vfs_file.get_uri_scheme() != 'file':
 
35
            return
 
36
 
 
37
        file = vfs_file.get_uri()
 
38
        try:
 
39
            tree, path = WorkingTree.open_containing(file)
 
40
        except NotBranchError:
 
41
            return
 
42
 
 
43
        #FIXME
 
44
 
 
45
        return
 
46
 
 
47
    def unignore_cb(self, menu, vfs_file):
 
48
        # We can only cope with local files
 
49
        if vfs_file.get_uri_scheme() != 'file':
 
50
            return
 
51
 
 
52
        file = vfs_file.get_uri()
 
53
        try:
 
54
            tree, path = WorkingTree.open_containing(file)
 
55
        except NotBranchError:
 
56
            return
 
57
 
 
58
        #FIXME
 
59
 
 
60
        return
 
61
 
 
62
    def diff_cb(self, menu, vfs_file):
 
63
        # We can only cope with local files
 
64
        if vfs_file.get_uri_scheme() != 'file':
 
65
            return
 
66
 
 
67
        file = vfs_file.get_uri()
 
68
        try:
 
69
            tree, path = WorkingTree.open_containing(file)
 
70
        except NotBranchError:
 
71
            return
 
72
 
 
73
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
 
74
        window = DiffWindow()
 
75
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
 
76
        window.show()
 
77
 
 
78
        return
 
79
 
 
80
    def newtree_cb(self, menu, vfs_file):
 
81
        # We can only cope with local files
 
82
        if vfs_file.get_uri_scheme() != 'file':
 
83
            return
 
84
 
 
85
        file = vfs_file.get_uri()
 
86
 
 
87
        # We only want to continue here if we get a NotBranchError
 
88
        try:
 
89
            tree, path = WorkingTree.open_containing(file)
 
90
        except NotBranchError:
 
91
            BzrDir.create_branch_and_repo(file)
 
92
 
 
93
    def remove_cb(self, menu, vfs_file):
 
94
        # We can only cope with local files
 
95
        if vfs_file.get_uri_scheme() != 'file':
 
96
            return
 
97
 
 
98
        file = vfs_file.get_uri()
 
99
        try:
 
100
            tree, path = WorkingTree.open_containing(file)
 
101
        except NotBranchError:
 
102
            return
 
103
 
 
104
        tree.remove(path)
 
105
 
 
106
    def annotate_cb(self, menu, vfs_file):
 
107
        # We can only cope with local files
 
108
        if vfs_file.get_uri_scheme() != 'file':
 
109
            return
 
110
 
 
111
        file = vfs_file.get_uri()
 
112
 
 
113
        vis = cmd_gannotate()
 
114
        vis.run(file)
 
115
 
 
116
    def clone_cb(self, menu, vfs_file=None):
 
117
        # We can only cope with local files
 
118
        if vfs_file.get_uri_scheme() != 'file':
 
119
            return
 
120
 
 
121
        from bzrlib.plugins.gtk.olive.branch import BranchDialog
 
122
        
 
123
        dialog = BranchDialog(vfs_file.get_name())
 
124
        dialog.display()
 
125
 
 
126
    def commit_cb(self, menu, vfs_file=None):
 
127
        # We can only cope with local files
 
128
        if vfs_file.get_uri_scheme() != 'file':
 
129
            return
 
130
 
 
131
        file = vfs_file.get_uri()
 
132
        try:
 
133
            tree, path = WorkingTree.open_containing(file)
 
134
        except NotBranchError:
 
135
            return
 
136
 
 
137
        from bzrlib.plugins.gtk.olive.commit import CommitDialog
 
138
        dialog = CommitDialog(tree, path)
 
139
        dialog.display()
 
140
        gtk.main()
 
141
 
 
142
    def log_cb(self, menu, vfs_file):
 
143
        # We can only cope with local files
 
144
        if vfs_file.get_uri_scheme() != 'file':
 
145
            return
 
146
 
 
147
        file = vfs_file.get_uri()
 
148
 
 
149
        # We only want to continue here if we get a NotBranchError
 
150
        try:
 
151
            tree, path = WorkingTree.open_containing(file)
 
152
        except NotBranchError:
 
153
            return
 
154
 
 
155
        vis = cmd_visualise()
 
156
        vis.run(file)
 
157
 
 
158
        return
 
159
 
 
160
    def pull_cb(self, menu, vfs_file):
 
161
        # We can only cope with local files
 
162
        if vfs_file.get_uri_scheme() != 'file':
 
163
            return
 
164
 
 
165
        file = vfs_file.get_uri()
 
166
 
 
167
        # We only want to continue here if we get a NotBranchError
 
168
        try:
 
169
            tree, path = WorkingTree.open_containing(file)
 
170
        except NotBranchError:
 
171
            return
 
172
 
 
173
        from bzrlib.plugins.gtk.olive.pull import PullDialog
 
174
        dialog = PullDialog(tree, path)
 
175
        dialog.display()
 
176
        gtk.main()
 
177
 
 
178
    def merge_cb(self, menu, vfs_file):
 
179
        # We can only cope with local files
 
180
        if vfs_file.get_uri_scheme() != 'file':
 
181
            return
 
182
 
 
183
        file = vfs_file.get_uri()
 
184
 
 
185
        # We only want to continue here if we get a NotBranchError
 
186
        try:
 
187
            tree, path = WorkingTree.open_containing(file)
 
188
        except NotBranchError:
 
189
            return
 
190
 
 
191
        from bzrlib.plugins.gtk.olive.merge import MergeDialog
 
192
        dialog = MergeDialog(tree, path)
 
193
        dialog.display()
 
194
        gtk.main()
 
195
 
 
196
    def get_background_items(self, window, vfs_file):
 
197
        items = []
 
198
        file = vfs_file.get_uri()
 
199
        try:
 
200
            tree, path = WorkingTree.open_containing(file)
 
201
        except NotBranchError:
 
202
            item = nautilus.MenuItem('BzrNautilus::newtree',
 
203
                                 'Make directory versioned',
 
204
                                 'Create new Bazaar tree in this folder')
 
205
            item.connect('activate', self.newtree_cb, vfs_file)
 
206
            items.append(item)
 
207
 
 
208
            item = nautilus.MenuItem('BzrNautilus::clone',
 
209
                                 'Checkout Bazaar branch',
 
210
                                 'Checkout Existing Bazaar Branch')
 
211
            item.connect('activate', self.clone_cb, vfs_file)
 
212
            items.append(item)
 
213
 
 
214
            return items
 
215
 
 
216
        item = nautilus.MenuItem('BzrNautilus::log',
 
217
                             'Log',
 
218
                             'Show Bazaar history')
 
219
        item.connect('activate', self.log_cb, vfs_file)
 
220
        items.append(item)
 
221
 
 
222
        item = nautilus.MenuItem('BzrNautilus::pull',
 
223
                             'Pull',
 
224
                             'Pull from another branch')
 
225
        item.connect('activate', self.pull_cb, vfs_file)
 
226
        items.append(item)
 
227
 
 
228
        item = nautilus.MenuItem('BzrNautilus::merge',
 
229
                             'Merge',
 
230
                             'Merge from another branch')
 
231
        item.connect('activate', self.merge_cb, vfs_file)
 
232
        items.append(item)
 
233
 
 
234
        item = nautilus.MenuItem('BzrNautilus::commit',
 
235
                             'Commit',
 
236
                             'Commit Changes')
 
237
        item.connect('activate', self.commit_cb, vfs_file)
 
238
        items.append(item)
 
239
 
 
240
        return items
 
241
 
 
242
 
 
243
    def get_file_items(self, window, files):
 
244
        items = []
 
245
 
 
246
        for vfs_file in files:
 
247
            # We can only cope with local files
 
248
            if vfs_file.get_uri_scheme() != 'file':
 
249
                return
 
250
 
 
251
            file = vfs_file.get_uri()
 
252
            try:
 
253
                tree, path = WorkingTree.open_containing(file)
 
254
            except NotBranchError:
 
255
                if not vfs_file.is_directory():
 
256
                    return
 
257
                item = nautilus.MenuItem('BzrNautilus::newtree',
 
258
                                     'Make directory versioned',
 
259
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
 
260
                item.connect('activate', self.newtree_cb, vfs_file)
 
261
                return item,
 
262
 
 
263
            file_class = tree.file_class(path)
 
264
 
 
265
            if file_class == '?':
 
266
                item = nautilus.MenuItem('BzrNautilus::add',
 
267
                                     'Add',
 
268
                                     'Add as versioned file')
 
269
                item.connect('activate', self.add_cb, vfs_file)
 
270
                items.append(item)
 
271
 
 
272
                item = nautilus.MenuItem('BzrNautilus::ignore',
 
273
                                     'Ignore',
 
274
                                     'Ignore file for versioning')
 
275
                item.connect('activate', self.ignore_cb, vfs_file)
 
276
                items.append(item)
 
277
            elif file_class == 'I':
 
278
                item = nautilus.MenuItem('BzrNautilus::unignore',
 
279
                                     'Unignore',
 
280
                                     'Unignore file for versioning')
 
281
                item.connect('activate', self.unignore_cb, vfs_file)
 
282
                items.append(item)
 
283
            elif file_class == 'V':
 
284
                item = nautilus.MenuItem('BzrNautilus::log',
 
285
                                 'Log',
 
286
                                 'List changes')
 
287
                item.connect('activate', self.log_cb, vfs_file)
 
288
                items.append(item)
 
289
 
 
290
                item = nautilus.MenuItem('BzrNautilus::diff',
 
291
                                 'Diff',
 
292
                                 'Show differences')
 
293
                item.connect('activate', self.diff_cb, vfs_file)
 
294
                items.append(item)
 
295
 
 
296
                item = nautilus.MenuItem('BzrNautilus::remove',
 
297
                                     'Remove',
 
298
                                     'Remove this file from versioning')
 
299
                item.connect('activate', self.remove_cb, vfs_file)
 
300
                items.append(item)
 
301
 
 
302
                item = nautilus.MenuItem('BzrNautilus::annotate',
 
303
                             'Annotate',
 
304
                             'Annotate File Data')
 
305
                item.connect('activate', self.annotate_cb, vfs_file)
 
306
                items.append(item)
 
307
 
 
308
                item = nautilus.MenuItem('BzrNautilus::commit',
 
309
                             'Commit',
 
310
                             'Commit Changes')
 
311
                item.connect('activate', self.commit_cb, vfs_file)
 
312
                items.append(item)
 
313
 
 
314
        return items
 
315
 
 
316
    def get_columns(self):
 
317
        return nautilus.Column("BzrNautilus::bzr_status",
 
318
                               "bzr_status",
 
319
                               "Bzr Status",
 
320
                               "Version control status"),
 
321
 
 
322
    def update_file_info(self, file):
 
323
        if file.get_uri_scheme() != 'file':
 
324
            return
 
325
        
 
326
        try:
 
327
            tree, path = WorkingTree.open_containing(file.get_uri())
 
328
        except NotBranchError:
 
329
            return
 
330
 
 
331
        emblem = None
 
332
        status = None
 
333
 
 
334
        if tree.has_filename(path):
 
335
            emblem = 'cvs-controlled'
 
336
            status = 'unchanged'
 
337
            id = tree.path2id(path)
 
338
 
 
339
            delta = tree.changes_from(tree.branch.basis_tree())
 
340
            if delta.touches_file_id(id):
 
341
                emblem = 'cvs-modified'
 
342
                status = 'modified'
 
343
            for f, _, _ in delta.added:
 
344
                if f == path:
 
345
                    emblem = 'cvs-added'
 
346
                    status = 'added'
 
347
 
 
348
            for of, f, _, _, _, _ in delta.renamed:
 
349
                if f == path:
 
350
                    status = 'renamed from %s' % f
 
351
 
 
352
        elif tree.branch.basis_tree().has_filename(path):
 
353
            emblem = 'cvs-removed'
 
354
            status = 'removed'
 
355
        else:
 
356
            # FIXME: Check for ignored files
 
357
            status = 'unversioned'
 
358
        
 
359
        if emblem is not None:
 
360
            file.add_emblem(emblem)
 
361
        file.add_string_attribute('bzr_status', status)