/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-03 14:19:44 UTC
  • Revision ID: jelmer@samba.org-20070203141944-oa6iqhetsy0slqo0
Fix references to dialog.

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.diff 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
137
121
        from bzrlib.plugins.gtk.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
137
        from bzrlib.plugins.gtk.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)
 
151
            tree, path = WorkingTree.open_containing(file)
183
152
        except NotBranchError:
184
153
            return
185
154
 
186
 
        pp = start_viz_window(branch, [branch.last_revision()])
187
 
        pp.show()
188
 
        gtk.main()
 
155
        vis = cmd_visualise()
 
156
        vis.run(file)
 
157
 
 
158
        return
189
159
 
190
160
    def pull_cb(self, menu, vfs_file):
191
161
        # We can only cope with local files
220
190
 
221
191
        from bzrlib.plugins.gtk.merge import MergeDialog
222
192
        dialog = MergeDialog(tree, path)
223
 
        dialog.run()
224
 
        dialog.destroy()
 
193
        dialog.display()
 
194
        gtk.main()
225
195
 
226
196
    def get_background_items(self, window, vfs_file):
227
197
        items = []
228
198
        file = vfs_file.get_uri()
229
 
 
230
199
        try:
231
200
            tree, path = WorkingTree.open_containing(file)
232
 
            disabled_flag = self.check_branch_enabled(tree.branch)
233
 
        except UnsupportedProtocol:
234
 
            return
235
201
        except NotBranchError:
236
 
            disabled_flag = self.check_branch_enabled()
237
202
            item = nautilus.MenuItem('BzrNautilus::newtree',
238
203
                                 'Make directory versioned',
239
204
                                 'Create new Bazaar tree in this folder')
241
206
            items.append(item)
242
207
 
243
208
            item = nautilus.MenuItem('BzrNautilus::clone',
244
 
                                 'Checkout Bazaar branch ...',
 
209
                                 'Checkout Bazaar branch',
245
210
                                 'Checkout Existing Bazaar Branch')
246
211
            item.connect('activate', self.clone_cb, vfs_file)
247
212
            items.append(item)
248
213
 
249
214
            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
215
 
266
216
        item = nautilus.MenuItem('BzrNautilus::log',
267
 
                             'History ...',
 
217
                             'Log',
268
218
                             'Show Bazaar history')
269
219
        item.connect('activate', self.log_cb, vfs_file)
270
220
        items.append(item)
271
221
 
272
222
        item = nautilus.MenuItem('BzrNautilus::pull',
273
 
                             'Pull ...',
 
223
                             'Pull',
274
224
                             'Pull from another branch')
275
225
        item.connect('activate', self.pull_cb, vfs_file)
276
226
        items.append(item)
277
227
 
278
228
        item = nautilus.MenuItem('BzrNautilus::merge',
279
 
                             'Merge ...',
 
229
                             'Merge',
280
230
                             'Merge from another branch')
281
231
        item.connect('activate', self.merge_cb, vfs_file)
282
232
        items.append(item)
283
233
 
284
234
        item = nautilus.MenuItem('BzrNautilus::commit',
285
 
                             'Commit ...',
 
235
                             'Commit',
286
236
                             'Commit Changes')
287
237
        item.connect('activate', self.commit_cb, vfs_file)
288
238
        items.append(item)
289
239
 
290
240
        return items
291
241
 
 
242
 
292
243
    def get_file_items(self, window, files):
293
244
        items = []
294
 
        
295
 
        wtfiles = {}
 
245
 
296
246
        for vfs_file in files:
297
247
            # We can only cope with local files
298
248
            if vfs_file.get_uri_scheme() != 'file':
299
 
                continue
 
249
                return
300
250
 
301
251
            file = vfs_file.get_uri()
302
252
            try:
303
253
                tree, path = WorkingTree.open_containing(file)
304
 
                disabled_flag = self.check_branch_enabled(tree.branch)
305
254
            except NotBranchError:
306
 
                disabled_flag = self.check_branch_enabled()
307
255
                if not vfs_file.is_directory():
308
 
                    continue
309
 
 
310
 
                if disabled_flag == 'False':
311
256
                    return
312
 
 
313
257
                item = nautilus.MenuItem('BzrNautilus::newtree',
314
258
                                     'Make directory versioned',
315
259
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
316
260
                item.connect('activate', self.newtree_cb, vfs_file)
317
261
                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] == '?':
 
262
 
 
263
            file_class = tree.file_class(path)
 
264
 
 
265
            if file_class == '?':
329
266
                item = nautilus.MenuItem('BzrNautilus::add',
330
267
                                     'Add',
331
268
                                     'Add as versioned file')
337
274
                                     'Ignore file for versioning')
338
275
                item.connect('activate', self.ignore_cb, vfs_file)
339
276
                items.append(item)
340
 
            elif wtfiles[path] == 'I':
 
277
            elif file_class == 'I':
341
278
                item = nautilus.MenuItem('BzrNautilus::unignore',
342
279
                                     'Unignore',
343
280
                                     'Unignore file for versioning')
344
281
                item.connect('activate', self.unignore_cb, vfs_file)
345
282
                items.append(item)
346
 
            elif wtfiles[path] == 'V':
 
283
            elif file_class == 'V':
347
284
                item = nautilus.MenuItem('BzrNautilus::log',
348
 
                                 'History ...',
 
285
                                 'Log',
349
286
                                 'List changes')
350
287
                item.connect('activate', self.log_cb, vfs_file)
351
288
                items.append(item)
352
289
 
353
290
                item = nautilus.MenuItem('BzrNautilus::diff',
354
 
                                 'View Changes ...',
 
291
                                 'Diff',
355
292
                                 'Show differences')
356
293
                item.connect('activate', self.diff_cb, vfs_file)
357
294
                items.append(item)
363
300
                items.append(item)
364
301
 
365
302
                item = nautilus.MenuItem('BzrNautilus::annotate',
366
 
                             'Annotate ...',
 
303
                             'Annotate',
367
304
                             'Annotate File Data')
368
305
                item.connect('activate', self.annotate_cb, vfs_file)
369
306
                items.append(item)
370
307
 
371
308
                item = nautilus.MenuItem('BzrNautilus::commit',
372
 
                             'Commit ...',
 
309
                             'Commit',
373
310
                             'Commit Changes')
374
311
                item.connect('activate', self.commit_cb, vfs_file)
375
312
                items.append(item)
383
320
                               "Version control status"),
384
321
 
385
322
    def update_file_info(self, file):
386
 
 
387
323
        if file.get_uri_scheme() != 'file':
388
324
            return
389
325
        
391
327
            tree, path = WorkingTree.open_containing(file.get_uri())
392
328
        except NotBranchError:
393
329
            return
394
 
        except NoWorkingTree:
395
 
            return   
396
 
 
397
 
        disabled_flag = self.check_branch_enabled(tree.branch)
398
 
        if disabled_flag == 'False':
399
 
            return
400
330
 
401
331
        emblem = None
402
332
        status = None
403
333
 
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'
 
334
        if tree.has_filename(path):
 
335
            emblem = 'cvs-controlled'
414
336
            status = 'unchanged'
 
337
            id = tree.path2id(path)
415
338
 
416
339
            delta = tree.changes_from(tree.branch.basis_tree())
417
340
            if delta.touches_file_id(id):
418
 
                emblem = 'bzr-modified'
 
341
                emblem = 'cvs-modified'
419
342
                status = 'modified'
420
343
            for f, _, _ in delta.added:
421
344
                if f == path:
422
 
                    emblem = 'bzr-added'
 
345
                    emblem = 'cvs-added'
423
346
                    status = 'added'
424
347
 
425
348
            for of, f, _, _, _, _ in delta.renamed:
427
350
                    status = 'renamed from %s' % f
428
351
 
429
352
        elif tree.branch.basis_tree().has_filename(path):
430
 
            emblem = 'bzr-removed'
 
353
            emblem = 'cvs-removed'
431
354
            status = 'removed'
432
355
        else:
433
356
            # FIXME: Check for ignored files
436
359
        if emblem is not None:
437
360
            file.add_emblem(emblem)
438
361
        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