/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: Jelmer Vernooij
  • Date: 2006-05-19 16:37:13 UTC
  • Revision ID: jelmer@samba.org-20060519163713-be77b31c72cbc7e8
Move visualisation code to a separate directory, preparing for bundling 
the GTK+ plugins for bzr.

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 get_background_items(self, window, vfs_file):
161
 
        items = []
162
 
        file = vfs_file.get_uri()
163
 
        try:
164
 
            tree, path = WorkingTree.open_containing(file)
165
 
        except NotBranchError:
166
 
            item = nautilus.MenuItem('BzrNautilus::newtree',
167
 
                                 'Create new Bazaar tree',
168
 
                                 'Create new Bazaar tree in this folder')
169
 
            item.connect('activate', self.newtree_cb, vfs_file)
170
 
            items.append(item)
171
 
 
172
 
            item = nautilus.MenuItem('BzrNautilus::clone',
173
 
                                 'Checkout',
174
 
                                 'Checkout Existing Bazaar Branch')
175
 
            item.connect('activate', self.clone_cb, vfs_file)
176
 
            items.append(item)
177
 
 
178
 
            return items
179
 
 
180
 
        item = nautilus.MenuItem('BzrNautilus::log',
181
 
                             'Log',
182
 
                             'Show Bazaar history')
183
 
        item.connect('activate', self.log_cb, vfs_file)
184
 
        items.append(item)
185
 
 
186
 
        item = nautilus.MenuItem('BzrNautilus::commit',
187
 
                             'Commit',
188
 
                             'Commit Changes')
189
 
        item.connect('activate', self.commit_cb, vfs_file)
190
 
        items.append(item)
191
 
 
192
 
        return items
193
 
 
194
 
 
195
 
    def get_file_items(self, window, files):
196
 
        items = []
197
 
 
198
 
        for vfs_file in files:
199
 
            # We can only cope with local files
200
 
            if vfs_file.get_uri_scheme() != 'file':
201
 
                return
202
 
 
203
 
            file = vfs_file.get_uri()
204
 
            try:
205
 
                tree, path = WorkingTree.open_containing(file)
206
 
            except NotBranchError:
207
 
                if not vfs_file.is_directory():
208
 
                    return
209
 
                item = nautilus.MenuItem('BzrNautilus::newtree',
210
 
                                     'Create new Bazaar tree',
211
 
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
212
 
                item.connect('activate', self.newtree_cb, vfs_file)
213
 
                return item,
214
 
 
215
 
            file_class = tree.file_class(path)
216
 
 
217
 
            if file_class == '?':
218
 
                item = nautilus.MenuItem('BzrNautilus::add',
219
 
                                     'Add',
220
 
                                     'Add as versioned file')
221
 
                item.connect('activate', self.add_cb, vfs_file)
222
 
                items.append(item)
223
 
 
224
 
                item = nautilus.MenuItem('BzrNautilus::ignore',
225
 
                                     'Ignore',
226
 
                                     'Ignore file for versioning')
227
 
                item.connect('activate', self.ignore_cb, vfs_file)
228
 
                items.append(item)
229
 
            elif file_class == 'I':
230
 
                item = nautilus.MenuItem('BzrNautilus::unignore',
231
 
                                     'Unignore',
232
 
                                     'Unignore file for versioning')
233
 
                item.connect('activate', self.unignore_cb, vfs_file)
234
 
                items.append(item)
235
 
            elif file_class == 'V':
236
 
                item = nautilus.MenuItem('BzrNautilus::log',
237
 
                                 'Log',
238
 
                                 'List changes')
239
 
                item.connect('activate', self.log_cb, vfs_file)
240
 
                items.append(item)
241
 
 
242
 
                item = nautilus.MenuItem('BzrNautilus::diff',
243
 
                                 'Diff',
244
 
                                 'Show differences')
245
 
                item.connect('activate', self.diff_cb, vfs_file)
246
 
                items.append(item)
247
 
 
248
 
                item = nautilus.MenuItem('BzrNautilus::remove',
249
 
                                     'Remove',
250
 
                                     'Remove this file from versioning')
251
 
                item.connect('activate', self.remove_cb, vfs_file)
252
 
                items.append(item)
253
 
 
254
 
                item = nautilus.MenuItem('BzrNautilus::annotate',
255
 
                             'Annotate',
256
 
                             'Annotate File Data')
257
 
                item.connect('activate', self.annotate_cb, vfs_file)
258
 
                items.append(item)
259
 
 
260
 
                item = nautilus.MenuItem('BzrNautilus::commit',
261
 
                             'Commit',
262
 
                             'Commit Changes')
263
 
                item.connect('activate', self.commit_cb, vfs_file)
264
 
                items.append(item)
265
 
 
266
 
        return items
267
 
 
268
 
    def get_columns(self):
269
 
        return nautilus.Column("BzrNautilus::bzr_status",
270
 
                               "bzr_status",
271
 
                               "Bzr Status",
272
 
                               "Version control status"),
273
 
 
274
 
    def update_file_info(self, file):
275
 
        if file.get_uri_scheme() != 'file':
276
 
            return
277
 
        
278
 
        try:
279
 
            tree, path = WorkingTree.open_containing(file.get_uri())
280
 
        except NotBranchError:
281
 
            return
282
 
 
283
 
        emblem = None
284
 
        status = None
285
 
 
286
 
        if tree.has_filename(path):
287
 
            emblem = 'cvs-controlled'
288
 
            status = 'unchanged'
289
 
            id = tree.path2id(path)
290
 
 
291
 
            delta = tree.changes_from(tree.branch.basis_tree())
292
 
            if delta.touches_file_id(id):
293
 
                emblem = 'cvs-modified'
294
 
                status = 'modified'
295
 
            for f, _, _ in delta.added:
296
 
                if f == path:
297
 
                    emblem = 'cvs-added'
298
 
                    status = 'added'
299
 
 
300
 
            for of, f, _, _, _, _ in delta.renamed:
301
 
                if f == path:
302
 
                    status = 'renamed from %s' % f
303
 
 
304
 
        elif tree.branch.basis_tree().has_filename(path):
305
 
            emblem = 'cvs-removed'
306
 
            status = 'removed'
307
 
        else:
308
 
            # FIXME: Check for ignored files
309
 
            status = 'unversioned'
310
 
        
311
 
        if emblem is not None:
312
 
            file.add_emblem(emblem)
313
 
        file.add_string_attribute('bzr_status', status)