/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-09-05 20:46:39 UTC
  • mfrom: (0.5.16 nautilus-bzr)
  • Revision ID: jelmer@samba.org-20060905204639-855b949625e30ba6
Integrate nautilus-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
 
 
7
from bzrlib.plugin import load_plugins
 
8
load_plugins()
 
9
 
 
10
try:
 
11
    from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
 
12
    have_gtkplugin = True
 
13
except ImportError:
 
14
    have_gtkplugin = False
 
15
 
 
16
class BzrExtension(nautilus.MenuProvider):
 
17
    def __init__(self):
 
18
        pass
 
19
 
 
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
 
 
46
        #FIXME
 
47
 
 
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
 
 
61
        #FIXME
 
62
 
 
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
 
 
76
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
 
77
        window = DiffWindow()
 
78
        window.set_diff(tree.branch, tree, tree.branch.revision_tree())
 
79
        window.show()
 
80
 
 
81
        return
 
82
 
 
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:
 
94
            BzrDir.create_branch_and_repo(file)
 
95
 
 
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
 
 
107
        tree.remove(path)
 
108
 
 
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)
 
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)
 
135
 
 
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
 
 
147
        from bzrlib.plugins.gtk.commit import GCommitDialog
 
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)
 
153
 
 
154
    def log_cb(self, menu, vfs_file):
 
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
 
 
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)
 
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
 
190
 
 
191
        items = []
 
192
        if have_gtkplugin:
 
193
            item = nautilus.MenuItem('BzrNautilus::log',
 
194
                                 'Log',
 
195
                                 'Show Bazaar history')
 
196
            item.connect('activate', self.log_cb, vfs_file)
 
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
 
206
 
 
207
 
 
208
    def get_file_items(self, window, files):
 
209
        items = []
 
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()
 
217
            try:
 
218
                tree, path = WorkingTree.open_containing(file)
 
219
            except NotBranchError:
 
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,
 
227
 
 
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':
 
249
                if have_gtkplugin:
 
250
                    item = nautilus.MenuItem('BzrNautilus::log',
 
251
                                     'Log',
 
252
                                     'List changes')
 
253
                    item.connect('activate', self.log_cb, vfs_file)
 
254
                    items.append(item)
 
255
 
 
256
                    item = nautilus.MenuItem('BzrNautilus::diff',
 
257
                                     'Diff',
 
258
                                     'Show differences')
 
259
                    item.connect('activate', self.diff_cb, vfs_file)
 
260
                    items.append(item)
 
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)
 
267
 
 
268
                if have_gtkplugin:
 
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)
 
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)
 
280
    
 
281
        return items