/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
1
import nautilus
2
import bzrlib
3
from bzrlib.bzrdir import BzrDir
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
4
from bzrlib.errors import NotBranchError
5
from bzrlib.workingtree import WorkingTree
88 by Jelmer Vernooij
Show column with file status.
6
from bzrlib.tree import file_status
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
7
0.7.1 by Wouter van Heyst
use the bzrlib method of loading plugins, takes care of ~/.bazaar/plugins
8
from bzrlib.plugin import load_plugins
9
load_plugins()
10
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
11
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
12
88 by Jelmer Vernooij
Show column with file status.
13
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
14
    def __init__(self):
15
        pass
16
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
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
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
43
        #FIXME
44
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
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
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
58
        #FIXME
59
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
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
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
73
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
74
        window = DiffWindow()
87 by Jelmer Vernooij
Fix diff window in nautilus.
75
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
76
        window.show()
77
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
78
        return
79
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
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:
0.5.9 by jbailey at ubuntu
Implement repository creation
91
            BzrDir.create_branch_and_repo(file)
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
92
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
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
0.5.6 by jbailey at ubuntu
Implement remove
104
        tree.remove(path)
105
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
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)
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
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
        file = vfs_file.get_uri()
122
        try:
123
            tree, path = WorkingTree.open_containing(file)
124
        except NotBranchError:
125
            return
126
127
        from bzrlib.plugins.gtk.clone import CloneDialog
128
        dialog = CloneDialog(file)
129
        if dialog.run() != gtk.RESPONSE_CANCEL:
130
            bzrdir = BzrDir.open(dialog.url)
131
            bzrdir.sprout(dialog.dest_path)
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
132
 
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
133
    def commit_cb(self, menu, vfs_file=None):
134
        # We can only cope with local files
135
        if vfs_file.get_uri_scheme() != 'file':
136
            return
137
138
        file = vfs_file.get_uri()
139
        try:
140
            tree, path = WorkingTree.open_containing(file)
141
        except NotBranchError:
142
            return
143
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
144
        from bzrlib.plugins.gtk.commit import GCommitDialog
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
145
        dialog = GCommitDialog(tree)
146
        dialog.set_title(path + " - Commit")
147
        if dialog.run() != gtk.RESPONSE_CANCEL:
148
            Commit().commit(working_tree=wt,message=dialog.message,
149
                            specific_files=dialog.specific_files)
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
150
0.5.12 by Jelmer Vernooij
Rename "Visualise Bazaar Branch" to "Log", which is a term
151
    def log_cb(self, menu, vfs_file):
0.5.8 by jbailey at ubuntu
Add bzrk plugin
152
        # We can only cope with local files
153
        if vfs_file.get_uri_scheme() != 'file':
154
            return
155
156
        file = vfs_file.get_uri()
157
158
        # We only want to continue here if we get a NotBranchError
159
        try:
160
            tree, path = WorkingTree.open_containing(file)
161
        except NotBranchError:
162
            return
163
164
        vis = cmd_visualise()
165
        vis.run(file)
166
167
        return
168
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
169
    def get_background_items(self, window, vfs_file):
170
        file = vfs_file.get_uri()
171
        try:
172
            tree, path = WorkingTree.open_containing(file)
173
        except NotBranchError:
174
            item = nautilus.MenuItem('BzrNautilus::newtree',
175
                                 'Create new Bazaar tree',
176
                                 'Create new Bazaar tree in this folder')
177
            item.connect('activate', self.newtree_cb, vfs_file)
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
178
            items.append(item)
179
180
            item = nautilus.MenuItem('BzrNautilus::clone',
181
                                 'Checkout',
182
                                 'Checkout Existing Bazaar Branch')
183
            item.connect('activate', self.clone_cb, vfs_file)
184
            items.append(item)
185
186
            return items
0.5.8 by jbailey at ubuntu
Add bzrk plugin
187
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
188
        items = []
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
189
        item = nautilus.MenuItem('BzrNautilus::log',
190
                             'Log',
191
                             'Show Bazaar history')
192
        item.connect('activate', self.log_cb, vfs_file)
193
        items.append(item)
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
194
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
195
        item = nautilus.MenuItem('BzrNautilus::commit',
196
                             'Commit',
197
                             'Commit Changes')
198
        item.connect('activate', self.commit_cb, vfs_file)
199
        items.append(item)
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
200
201
        return items
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
202
203
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
204
    def get_file_items(self, window, files):
205
        items = []
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
206
207
        for vfs_file in files:
208
            # We can only cope with local files
209
            if vfs_file.get_uri_scheme() != 'file':
210
                return
211
212
            file = vfs_file.get_uri()
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
213
            try:
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
214
                tree, path = WorkingTree.open_containing(file)
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
215
            except NotBranchError:
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
216
                if not vfs_file.is_directory():
217
                    return
218
                item = nautilus.MenuItem('BzrNautilus::newtree',
219
                                     'Create new Bazaar tree',
220
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
221
                item.connect('activate', self.newtree_cb, vfs_file)
222
                return item,
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
223
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
224
            file_class = tree.file_class(path)
225
226
            if file_class == '?':
227
                item = nautilus.MenuItem('BzrNautilus::add',
228
                                     'Add',
229
                                     'Add as versioned file')
230
                item.connect('activate', self.add_cb, vfs_file)
231
                items.append(item)
232
233
                item = nautilus.MenuItem('BzrNautilus::ignore',
234
                                     'Ignore',
235
                                     'Ignore file for versioning')
236
                item.connect('activate', self.ignore_cb, vfs_file)
237
                items.append(item)
238
            elif file_class == 'I':
239
                item = nautilus.MenuItem('BzrNautilus::unignore',
240
                                     'Unignore',
241
                                     'Unignore file for versioning')
242
                item.connect('activate', self.unignore_cb, vfs_file)
243
                items.append(item)
244
            elif file_class == 'V':
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
245
                item = nautilus.MenuItem('BzrNautilus::log',
246
                                 'Log',
247
                                 'List changes')
248
                item.connect('activate', self.log_cb, vfs_file)
249
                items.append(item)
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
250
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
251
                item = nautilus.MenuItem('BzrNautilus::diff',
252
                                 'Diff',
253
                                 'Show differences')
254
                item.connect('activate', self.diff_cb, vfs_file)
255
                items.append(item)
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
256
257
                item = nautilus.MenuItem('BzrNautilus::remove',
258
                                     'Remove',
259
                                     'Remove this file from versioning')
260
                item.connect('activate', self.remove_cb, vfs_file)
261
                items.append(item)
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
262
81 by Jelmer Vernooij
Remove unnecessary "#!/usr/bin/python" shebang lines (fixes #59125).
263
                item = nautilus.MenuItem('BzrNautilus::annotate',
264
                             'Annotate',
265
                             'Annotate File Data')
266
                item.connect('activate', self.annotate_cb, vfs_file)
267
                items.append(item)
268
269
                item = nautilus.MenuItem('BzrNautilus::commit',
270
                             'Commit',
271
                             'Commit Changes')
272
                item.connect('activate', self.commit_cb, vfs_file)
273
                items.append(item)
274
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
275
        return items
88 by Jelmer Vernooij
Show column with file status.
276
277
    def get_columns(self):
278
        return nautilus.Column("BzrNautilus::bzr_status",
279
                               "bzr_status",
280
                               "Bzr Status",
281
                               "Version control status"),
282
283
    def update_file_info(self, file):
284
        if file.get_uri_scheme() != 'file':
285
            return
286
        
287
        try:
288
            tree, path = WorkingTree.open_containing(file.get_uri())
289
        except NotBranchError:
290
            return
291
292
        emblem = None
293
        status = None
294
295
        if tree.has_filename(path):
296
            emblem = 'cvs-controlled'
297
            status = 'unchanged'
298
            id = tree.path2id(path)
299
300
            delta = tree.changes_from(tree.branch.basis_tree())
301
            if delta.touches_file_id(id):
302
                emblem = 'cvs-modified'
303
                status = 'modified'
304
            for f, _, _ in delta.added:
305
                if f == path:
306
                    emblem = 'cvs-added'
307
                    status = 'added'
308
309
            for of, f, _, _, _, _ in delta.renamed:
310
                if f == path:
311
                    status = 'renamed from %s' % f
312
313
        elif tree.branch.basis_tree().has_filename(path):
314
            emblem = 'cvs-removed'
315
            status = 'removed'
316
        else:
317
            # FIXME: Check for ignored files
318
            status = 'unversioned'
319
        
320
        if emblem is not None:
321
            file.add_emblem(emblem)
322
        file.add_string_attribute('bzr_status', status)