/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: 2007-02-01 15:50:40 UTC
  • Revision ID: jelmer@samba.org-20070201155040-3hq4mfbxs99kzazy
add framework for tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Trivial Bazaar plugin for Nautilus
2
 
#
3
 
# Copyright (C) 2006 Jeff Bailey
4
 
# Copyright (C) 2006 Wouter van Heyst
5
 
# Copyright (C) 2006-2008 Jelmer Vernooij <jelmer@samba.org>
6
 
#
7
 
# Published under the GNU GPL
8
 
 
9
 
import gtk
10
1
import nautilus
11
2
import bzrlib
12
 
from bzrlib.branch import Branch
13
3
from bzrlib.bzrdir import BzrDir
14
 
from bzrlib.errors import NotBranchError, NoWorkingTree, UnsupportedProtocol
 
4
from bzrlib.errors import NotBranchError
 
5
from bzrlib.workingtree import WorkingTree
15
6
from bzrlib.tree import file_status
16
 
from bzrlib.workingtree import WorkingTree
17
 
from bzrlib.config import GlobalConfig
18
7
 
19
8
from bzrlib.plugin import load_plugins
20
9
load_plugins()
21
10
 
22
 
from bzrlib.plugins.gtk import _i18n, cmd_gannotate, start_viz_window
23
 
 
24
 
print "Bazaar nautilus module initialized"
25
 
 
 
11
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
26
12
 
27
13
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
28
14
    def __init__(self):
84
70
        except NotBranchError:
85
71
            return
86
72
 
87
 
        from bzrlib.plugins.gtk.diff import DiffWindow
 
73
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
88
74
        window = DiffWindow()
89
75
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
90
76
        window.show()
102
88
        try:
103
89
            tree, path = WorkingTree.open_containing(file)
104
90
        except NotBranchError:
105
 
            BzrDir.create_standalone_workingtree(file)
 
91
            BzrDir.create_branch_and_repo(file)
106
92
 
107
93
    def remove_cb(self, menu, vfs_file):
108
94
        # We can only cope with local files
132
118
        if vfs_file.get_uri_scheme() != 'file':
133
119
            return
134
120
 
135
 
        from bzrlib.plugins.gtk.branch import BranchDialog
 
121
        from bzrlib.plugins.gtk.olive.branch import BranchDialog
136
122
        
137
123
        dialog = BranchDialog(vfs_file.get_name())
138
 
        response = dialog.run()
139
 
        if response != gtk.RESPONSE_NONE:
140
 
            dialog.hide()
141
 
            dialog.destroy()
 
124
        dialog.display()
142
125
 
143
126
    def commit_cb(self, menu, vfs_file=None):
144
127
        # We can only cope with local files
146
129
            return
147
130
 
148
131
        file = vfs_file.get_uri()
149
 
        tree = None
150
 
        branch = None
151
132
        try:
152
133
            tree, path = WorkingTree.open_containing(file)
153
 
            branch = tree.branch
154
 
        except NotBranchError, e:
155
 
            path = e.path
156
 
            #return
157
 
        except NoWorkingTree, e:
158
 
            path = e.base
159
 
            try:
160
 
                (branch, path) = Branch.open_containing(path)
161
 
            except NotBranchError, e:
162
 
                path = e.path
 
134
        except NotBranchError:
 
135
            return
163
136
 
164
 
        from bzrlib.plugins.gtk.commit import CommitDialog
 
137
        from bzrlib.plugins.gtk.olive.commit import CommitDialog
165
138
        dialog = CommitDialog(tree, path)
166
 
        response = dialog.run()
167
 
        if response != gtk.RESPONSE_NONE:
168
 
            dialog.hide()
169
 
            dialog.destroy()
 
139
        dialog.display()
 
140
        gtk.main()
170
141
 
171
142
    def log_cb(self, menu, vfs_file):
172
143
        # We can only cope with local files
177
148
 
178
149
        # We only want to continue here if we get a NotBranchError
179
150
        try:
180
 
            branch, path = Branch.open_containing(file)
 
151
            tree, path = WorkingTree.open_containing(file)
181
152
        except NotBranchError:
182
153
            return
183
154
 
184
 
        pp = start_viz_window(branch, [branch.last_revision()])
185
 
        pp.show()
186
 
        gtk.main()
 
155
        vis = cmd_visualise()
 
156
        vis.run(file)
 
157
 
 
158
        return
187
159
 
188
160
    def pull_cb(self, menu, vfs_file):
189
161
        # We can only cope with local files
198
170
        except NotBranchError:
199
171
            return
200
172
 
201
 
        from bzrlib.plugins.gtk.pull import PullDialog
 
173
        from bzrlib.plugins.gtk.olive.pull import PullDialog
202
174
        dialog = PullDialog(tree, path)
203
175
        dialog.display()
204
176
        gtk.main()
216
188
        except NotBranchError:
217
189
            return
218
190
 
219
 
        from bzrlib.plugins.gtk.merge import MergeDialog
 
191
        from bzrlib.plugins.gtk.olive.merge import MergeDialog
220
192
        dialog = MergeDialog(tree, path)
221
 
        dialog.run()
222
 
        dialog.destroy()
 
193
        dialog.display()
 
194
        gtk.main()
223
195
 
224
196
    def get_background_items(self, window, vfs_file):
225
197
        items = []
226
198
        file = vfs_file.get_uri()
227
 
 
228
199
        try:
229
200
            tree, path = WorkingTree.open_containing(file)
230
 
            disabled_flag = self.check_branch_enabled(tree.branch)
231
 
        except UnsupportedProtocol:
232
 
            return
233
201
        except NotBranchError:
234
 
            disabled_flag = self.check_branch_enabled()
235
202
            item = nautilus.MenuItem('BzrNautilus::newtree',
236
203
                                 'Make directory versioned',
237
204
                                 'Create new Bazaar tree in this folder')
239
206
            items.append(item)
240
207
 
241
208
            item = nautilus.MenuItem('BzrNautilus::clone',
242
 
                                 'Checkout Bazaar branch ...',
 
209
                                 'Checkout Bazaar branch',
243
210
                                 'Checkout Existing Bazaar Branch')
244
211
            item.connect('activate', self.clone_cb, vfs_file)
245
212
            items.append(item)
246
213
 
247
214
            return items
248
 
        except NoWorkingTree:
249
 
            return
250
 
        
251
 
        if disabled_flag == 'False':
252
 
            item = nautilus.MenuItem('BzrNautilus::enable',
253
 
                                     'Enable Bazaar Plugin for this Branch',
254
 
                                     'Enable Bazaar plugin for nautilus')
255
 
            item.connect('activate', self.toggle_integration, 'True', vfs_file)
256
 
            return item,
257
 
        else:
258
 
            item = nautilus.MenuItem('BzrNautilus::disable',
259
 
                                      'Disable Bazaar Plugin this Branch',
260
 
                                      'Disable Bazaar plugin for nautilus')
261
 
            item.connect('activate', self.toggle_integration, 'False', vfs_file)
262
 
            items.append(item)
263
215
 
264
216
        item = nautilus.MenuItem('BzrNautilus::log',
265
 
                             'History ...',
 
217
                             'Log',
266
218
                             'Show Bazaar history')
267
219
        item.connect('activate', self.log_cb, vfs_file)
268
220
        items.append(item)
269
221
 
270
222
        item = nautilus.MenuItem('BzrNautilus::pull',
271
 
                             'Pull ...',
 
223
                             'Pull',
272
224
                             'Pull from another branch')
273
225
        item.connect('activate', self.pull_cb, vfs_file)
274
226
        items.append(item)
275
227
 
276
228
        item = nautilus.MenuItem('BzrNautilus::merge',
277
 
                             'Merge ...',
 
229
                             'Merge',
278
230
                             'Merge from another branch')
279
231
        item.connect('activate', self.merge_cb, vfs_file)
280
232
        items.append(item)
281
233
 
282
234
        item = nautilus.MenuItem('BzrNautilus::commit',
283
 
                             'Commit ...',
 
235
                             'Commit',
284
236
                             'Commit Changes')
285
237
        item.connect('activate', self.commit_cb, vfs_file)
286
238
        items.append(item)
287
239
 
288
240
        return items
289
241
 
 
242
 
290
243
    def get_file_items(self, window, files):
291
244
        items = []
292
 
        
293
 
        wtfiles = {}
 
245
 
294
246
        for vfs_file in files:
295
247
            # We can only cope with local files
296
248
            if vfs_file.get_uri_scheme() != 'file':
297
 
                continue
 
249
                return
298
250
 
299
251
            file = vfs_file.get_uri()
300
252
            try:
301
253
                tree, path = WorkingTree.open_containing(file)
302
 
                disabled_flag = self.check_branch_enabled(tree.branch)
303
254
            except NotBranchError:
304
 
                disabled_flag = self.check_branch_enabled()
305
255
                if not vfs_file.is_directory():
306
 
                    continue
307
 
 
308
 
                if disabled_flag == 'False':
309
256
                    return
310
 
 
311
257
                item = nautilus.MenuItem('BzrNautilus::newtree',
312
258
                                     'Make directory versioned',
313
259
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
314
260
                item.connect('activate', self.newtree_cb, vfs_file)
315
261
                return item,
316
 
            except NoWorkingTree:
317
 
                continue
318
 
            # Refresh the list of filestatuses in the working tree
319
 
            if path not in wtfiles.keys():
320
 
                tree.lock_read()
321
 
                for rpath, file_class, kind, id, entry in tree.list_files():
322
 
                    wtfiles[rpath] = file_class
323
 
                tree.unlock()
324
 
                wtfiles[u''] = 'V'
325
 
 
326
 
            if wtfiles[path] == '?':
 
262
 
 
263
            file_class = tree.file_class(path)
 
264
 
 
265
            if file_class == '?':
327
266
                item = nautilus.MenuItem('BzrNautilus::add',
328
267
                                     'Add',
329
268
                                     'Add as versioned file')
335
274
                                     'Ignore file for versioning')
336
275
                item.connect('activate', self.ignore_cb, vfs_file)
337
276
                items.append(item)
338
 
            elif wtfiles[path] == 'I':
 
277
            elif file_class == 'I':
339
278
                item = nautilus.MenuItem('BzrNautilus::unignore',
340
279
                                     'Unignore',
341
280
                                     'Unignore file for versioning')
342
281
                item.connect('activate', self.unignore_cb, vfs_file)
343
282
                items.append(item)
344
 
            elif wtfiles[path] == 'V':
 
283
            elif file_class == 'V':
345
284
                item = nautilus.MenuItem('BzrNautilus::log',
346
 
                                 'History ...',
 
285
                                 'Log',
347
286
                                 'List changes')
348
287
                item.connect('activate', self.log_cb, vfs_file)
349
288
                items.append(item)
350
289
 
351
290
                item = nautilus.MenuItem('BzrNautilus::diff',
352
 
                                 'View Changes ...',
 
291
                                 'Diff',
353
292
                                 'Show differences')
354
293
                item.connect('activate', self.diff_cb, vfs_file)
355
294
                items.append(item)
361
300
                items.append(item)
362
301
 
363
302
                item = nautilus.MenuItem('BzrNautilus::annotate',
364
 
                             'Annotate ...',
 
303
                             'Annotate',
365
304
                             'Annotate File Data')
366
305
                item.connect('activate', self.annotate_cb, vfs_file)
367
306
                items.append(item)
368
307
 
369
308
                item = nautilus.MenuItem('BzrNautilus::commit',
370
 
                             'Commit ...',
 
309
                             'Commit',
371
310
                             'Commit Changes')
372
311
                item.connect('activate', self.commit_cb, vfs_file)
373
312
                items.append(item)
381
320
                               "Version control status"),
382
321
 
383
322
    def update_file_info(self, file):
384
 
 
385
323
        if file.get_uri_scheme() != 'file':
386
324
            return
387
325
        
389
327
            tree, path = WorkingTree.open_containing(file.get_uri())
390
328
        except NotBranchError:
391
329
            return
392
 
        except NoWorkingTree:
393
 
            return   
394
 
 
395
 
        disabled_flag = self.check_branch_enabled(tree.branch)
396
 
        if disabled_flag == 'False':
397
 
            return
398
330
 
399
331
        emblem = None
400
332
        status = None
401
333
 
402
334
        if tree.has_filename(path):
403
 
            emblem = 'bzr-controlled'
 
335
            emblem = 'cvs-controlled'
404
336
            status = 'unchanged'
405
337
            id = tree.path2id(path)
406
338
 
407
339
            delta = tree.changes_from(tree.branch.basis_tree())
408
340
            if delta.touches_file_id(id):
409
 
                emblem = 'bzr-modified'
 
341
                emblem = 'cvs-modified'
410
342
                status = 'modified'
411
343
            for f, _, _ in delta.added:
412
344
                if f == path:
413
 
                    emblem = 'bzr-added'
 
345
                    emblem = 'cvs-added'
414
346
                    status = 'added'
415
347
 
416
348
            for of, f, _, _, _, _ in delta.renamed:
418
350
                    status = 'renamed from %s' % f
419
351
 
420
352
        elif tree.branch.basis_tree().has_filename(path):
421
 
            emblem = 'bzr-removed'
 
353
            emblem = 'cvs-removed'
422
354
            status = 'removed'
423
355
        else:
424
356
            # FIXME: Check for ignored files
427
359
        if emblem is not None:
428
360
            file.add_emblem(emblem)
429
361
        file.add_string_attribute('bzr_status', status)
430
 
 
431
 
    def check_branch_enabled(self, branch=None):
432
 
        # Supports global disable, but there is currently no UI to do this
433
 
        config = GlobalConfig()
434
 
        disabled_flag = config.get_user_option('nautilus_integration')
435
 
        if disabled_flag != 'False':
436
 
            if branch is not None:
437
 
                config = branch.get_config()
438
 
                disabled_flag = config.get_user_option('nautilus_integration')
439
 
        return disabled_flag
440
 
 
441
 
    def toggle_integration(self, menu, action, vfs_file=None):
442
 
        try:
443
 
            tree, path = WorkingTree.open_containing(vfs_file.get_uri())
444
 
        except NotBranchError:
445
 
            return
446
 
        except NoWorkingTree:
447
 
            return
448
 
        branch = tree.branch
449
 
        if branch is None:
450
 
            config = GlobalConfig()
451
 
        else:
452
 
            config = branch.get_config()
453
 
        config.set_user_option('nautilus_integration', action)
454