/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-10-08 20:51:52 UTC
  • Revision ID: jelmer@samba.org-20061008205152-1c5306ee8eb43b95
Use Olive's clone dialog in nautilus-bzr; remove the old Clone dialog 
from BzrGtk.

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