/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
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
6
0.7.1 by Wouter van Heyst
use the bzrlib method of loading plugins, takes care of ~/.bazaar/plugins
7
from bzrlib.plugin import load_plugins
8
load_plugins()
9
0.5.8 by jbailey at ubuntu
Add bzrk plugin
10
try:
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
11
    from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
12
    have_gtkplugin = True
13
except ImportError:
14
    have_gtkplugin = False
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
15
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
16
class BzrExtension(nautilus.MenuProvider):
17
    def __init__(self):
18
        pass
19
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
20
    def add_cb(self, menu, vfs_file):
21
        # We can only cope with local files
22
        if vfs_file.get_uri_scheme() != 'file':
23
            return
24
25
        file = vfs_file.get_uri()
26
        try:
27
            tree, path = WorkingTree.open_containing(file)
28
        except NotBranchError:
29
            return
30
31
        tree.add(path)
32
33
        return
34
35
    def ignore_cb(self, menu, vfs_file):
36
        # We can only cope with local files
37
        if vfs_file.get_uri_scheme() != 'file':
38
            return
39
40
        file = vfs_file.get_uri()
41
        try:
42
            tree, path = WorkingTree.open_containing(file)
43
        except NotBranchError:
44
            return
45
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
46
        #FIXME
47
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
48
        return
49
50
    def unignore_cb(self, menu, vfs_file):
51
        # We can only cope with local files
52
        if vfs_file.get_uri_scheme() != 'file':
53
            return
54
55
        file = vfs_file.get_uri()
56
        try:
57
            tree, path = WorkingTree.open_containing(file)
58
        except NotBranchError:
59
            return
60
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
61
        #FIXME
62
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
63
        return
64
65
    def diff_cb(self, menu, vfs_file):
66
        # We can only cope with local files
67
        if vfs_file.get_uri_scheme() != 'file':
68
            return
69
70
        file = vfs_file.get_uri()
71
        try:
72
            tree, path = WorkingTree.open_containing(file)
73
        except NotBranchError:
74
            return
75
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
76
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
77
        window = DiffWindow()
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
78
        window.set_diff(tree.branch, tree, tree.branch.revision_tree())
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
79
        window.show()
80
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
81
        return
82
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
83
    def newtree_cb(self, menu, vfs_file):
84
        # We can only cope with local files
85
        if vfs_file.get_uri_scheme() != 'file':
86
            return
87
88
        file = vfs_file.get_uri()
89
90
        # We only want to continue here if we get a NotBranchError
91
        try:
92
            tree, path = WorkingTree.open_containing(file)
93
        except NotBranchError:
0.5.9 by jbailey at ubuntu
Implement repository creation
94
            BzrDir.create_branch_and_repo(file)
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
95
0.5.4 by jbailey at ubuntu
Add 'add' function. Give framework for other callbacks.
96
    def remove_cb(self, menu, vfs_file):
97
        # We can only cope with local files
98
        if vfs_file.get_uri_scheme() != 'file':
99
            return
100
101
        file = vfs_file.get_uri()
102
        try:
103
            tree, path = WorkingTree.open_containing(file)
104
        except NotBranchError:
105
            return
106
0.5.6 by jbailey at ubuntu
Implement remove
107
        tree.remove(path)
108
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
109
    def annotate_cb(self, menu, vfs_file):
110
        # We can only cope with local files
111
        if vfs_file.get_uri_scheme() != 'file':
112
            return
113
114
        file = vfs_file.get_uri()
115
116
        vis = cmd_gannotate()
117
        vis.run(file)
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
118
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':
122
            return
123
124
        file = vfs_file.get_uri()
125
        try:
126
            tree, path = WorkingTree.open_containing(file)
127
        except NotBranchError:
128
            return
129
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)
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
135
 
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
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':
139
            return
140
141
        file = vfs_file.get_uri()
142
        try:
143
            tree, path = WorkingTree.open_containing(file)
144
        except NotBranchError:
145
            return
146
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
147
        from bzrlib.plugins.gtk.commit import GCommitDialog
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
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)
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
153
0.5.12 by Jelmer Vernooij
Rename "Visualise Bazaar Branch" to "Log", which is a term
154
    def log_cb(self, menu, vfs_file):
0.5.8 by jbailey at ubuntu
Add bzrk plugin
155
        # We can only cope with local files
156
        if vfs_file.get_uri_scheme() != 'file':
157
            return
158
159
        file = vfs_file.get_uri()
160
161
        # We only want to continue here if we get a NotBranchError
162
        try:
163
            tree, path = WorkingTree.open_containing(file)
164
        except NotBranchError:
165
            return
166
167
        vis = cmd_visualise()
168
        vis.run(file)
169
170
        return
171
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
172
    def get_background_items(self, window, vfs_file):
173
        file = vfs_file.get_uri()
174
        try:
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)
0.5.16 by Jelmer Vernooij
Adapt to bzr-gtk's API changes, add 'Clone' dialog
181
            items.append(item)
182
183
            item = nautilus.MenuItem('BzrNautilus::clone',
184
                                 'Checkout',
185
                                 'Checkout Existing Bazaar Branch')
186
            item.connect('activate', self.clone_cb, vfs_file)
187
            items.append(item)
188
189
            return items
0.5.8 by jbailey at ubuntu
Add bzrk plugin
190
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
191
        items = []
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
192
        if have_gtkplugin:
0.5.12 by Jelmer Vernooij
Rename "Visualise Bazaar Branch" to "Log", which is a term
193
            item = nautilus.MenuItem('BzrNautilus::log',
194
                                 'Log',
195
                                 'Show Bazaar history')
196
            item.connect('activate', self.log_cb, vfs_file)
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
197
            items.append(item)
198
199
            item = nautilus.MenuItem('BzrNautilus::commit',
200
                                 'Commit',
201
                                 'Commit Changes')
202
            item.connect('activate', self.commit_cb, vfs_file)
203
            items.append(item)
204
205
        return items
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
206
207
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
208
    def get_file_items(self, window, files):
209
        items = []
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
210
211
        for vfs_file in files:
212
            # We can only cope with local files
213
            if vfs_file.get_uri_scheme() != 'file':
214
                return
215
216
            file = vfs_file.get_uri()
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
217
            try:
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
218
                tree, path = WorkingTree.open_containing(file)
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
219
            except NotBranchError:
0.5.7 by jbailey at ubuntu
Add hook for creating new bzr trees.
220
                if not vfs_file.is_directory():
221
                    return
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)
226
                return item,
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
227
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
228
            file_class = tree.file_class(path)
229
230
            if file_class == '?':
231
                item = nautilus.MenuItem('BzrNautilus::add',
232
                                     'Add',
233
                                     'Add as versioned file')
234
                item.connect('activate', self.add_cb, vfs_file)
235
                items.append(item)
236
237
                item = nautilus.MenuItem('BzrNautilus::ignore',
238
                                     'Ignore',
239
                                     'Ignore file for versioning')
240
                item.connect('activate', self.ignore_cb, vfs_file)
241
                items.append(item)
242
            elif file_class == 'I':
243
                item = nautilus.MenuItem('BzrNautilus::unignore',
244
                                     'Unignore',
245
                                     'Unignore file for versioning')
246
                item.connect('activate', self.unignore_cb, vfs_file)
247
                items.append(item)
248
            elif file_class == 'V':
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
249
                if have_gtkplugin:
250
                    item = nautilus.MenuItem('BzrNautilus::log',
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
251
                                     'Log',
252
                                     'List changes')
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
253
                    item.connect('activate', self.log_cb, vfs_file)
254
                    items.append(item)
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
255
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
256
                    item = nautilus.MenuItem('BzrNautilus::diff',
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
257
                                     'Diff',
258
                                     'Show differences')
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
259
                    item.connect('activate', self.diff_cb, vfs_file)
260
                    items.append(item)
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
261
262
                item = nautilus.MenuItem('BzrNautilus::remove',
263
                                     'Remove',
264
                                     'Remove this file from versioning')
265
                item.connect('activate', self.remove_cb, vfs_file)
266
                items.append(item)
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
267
0.5.13 by Jelmer Vernooij
Use the gtk plugin rather than separate bzrk and gannotate
268
                if have_gtkplugin:
0.6.2 by Jelmer Vernooij
Add 'Annotate' menu entry that uses the gannotate bzr plugin
269
                    item = nautilus.MenuItem('BzrNautilus::annotate',
270
                                 'Annotate',
271
                                 'Annotate File Data')
272
                    item.connect('activate', self.annotate_cb, vfs_file)
273
                    items.append(item)
0.5.15 by Jelmer Vernooij
Add 'Commit' entries
274
275
                    item = nautilus.MenuItem('BzrNautilus::commit',
276
                                 'Commit',
277
                                 'Commit Changes')
278
                    item.connect('activate', self.commit_cb, vfs_file)
279
                    items.append(item)
0.5.2 by jbailey at ubuntu
Bring this to a state where it actually works. Specifically:
280
    
0.5.1 by Jelmer Vernooij
Start working on bzr integration plugin for nautilus
281
        return items