/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-07-15 15:22:29 UTC
  • Revision ID: jelmer@samba.org-20070715152229-clmlen0vpd8d2pzx
Add docstrings, remove unused code.

Show diffs side-by-side

added added

removed removed

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