/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: matkor
  • Date: 2007-08-23 10:17:40 UTC
  • mto: This revision was merged to the branch mainline in revision 265.
  • Revision ID: matkor@laptop-hp-20070823101740-s17kf9qa383wiuje
Code for "branch update" menuitem and toolbox. Typo fix

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
10
import bzrlib
12
 
from bzrlib.branch import Branch
13
11
from bzrlib.bzrdir import BzrDir
14
 
from bzrlib.errors import NotBranchError, NoWorkingTree, UnsupportedProtocol
 
12
from bzrlib.errors import NotBranchError
 
13
from bzrlib.workingtree import WorkingTree
15
14
from bzrlib.tree import file_status
16
 
from bzrlib.workingtree import WorkingTree
17
 
from bzrlib.config import GlobalConfig
18
15
 
19
16
from bzrlib.plugin import load_plugins
20
17
load_plugins()
21
18
 
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
 
 
 
19
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
27
20
 
28
21
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
29
22
    def __init__(self):
85
78
        except NotBranchError:
86
79
            return
87
80
 
88
 
        from bzrlib.plugins.gtk.diff import DiffWindow
 
81
        from bzrlib.plugins.gtk.viz.diff import DiffWindow
89
82
        window = DiffWindow()
90
 
        window.set_diff(tree.branch._get_nick(local=True), tree, 
91
 
                        tree.branch.basis_tree())
 
83
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
92
84
        window.show()
93
85
 
94
86
        return
104
96
        try:
105
97
            tree, path = WorkingTree.open_containing(file)
106
98
        except NotBranchError:
107
 
            BzrDir.create_standalone_workingtree(file)
 
99
            BzrDir.create_branch_and_repo(file)
108
100
 
109
101
    def remove_cb(self, menu, vfs_file):
110
102
        # We can only cope with local files
137
129
        from bzrlib.plugins.gtk.branch import BranchDialog
138
130
        
139
131
        dialog = BranchDialog(vfs_file.get_name())
140
 
        response = dialog.run()
141
 
        if response != gtk.RESPONSE_NONE:
142
 
            dialog.hide()
143
 
            dialog.destroy()
 
132
        dialog.display()
144
133
 
145
134
    def commit_cb(self, menu, vfs_file=None):
146
135
        # We can only cope with local files
148
137
            return
149
138
 
150
139
        file = vfs_file.get_uri()
151
 
        tree = None
152
 
        branch = None
153
140
        try:
154
141
            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
 
142
        except NotBranchError:
 
143
            return
165
144
 
166
145
        from bzrlib.plugins.gtk.commit import CommitDialog
167
146
        dialog = CommitDialog(tree, path)
168
 
        response = dialog.run()
169
 
        if response != gtk.RESPONSE_NONE:
170
 
            dialog.hide()
171
 
            dialog.destroy()
 
147
        dialog.display()
 
148
        gtk.main()
172
149
 
173
150
    def log_cb(self, menu, vfs_file):
174
151
        # We can only cope with local files
179
156
 
180
157
        # We only want to continue here if we get a NotBranchError
181
158
        try:
182
 
            branch, path = Branch.open_containing(file)
 
159
            tree, path = WorkingTree.open_containing(file)
183
160
        except NotBranchError:
184
161
            return
185
162
 
186
 
        pp = start_viz_window(branch, [branch.last_revision()])
187
 
        pp.show()
188
 
        gtk.main()
 
163
        vis = cmd_visualise()
 
164
        vis.run(file)
 
165
 
 
166
        return
189
167
 
190
168
    def pull_cb(self, menu, vfs_file):
191
169
        # We can only cope with local files
220
198
 
221
199
        from bzrlib.plugins.gtk.merge import MergeDialog
222
200
        dialog = MergeDialog(tree, path)
223
 
        dialog.run()
224
 
        dialog.destroy()
 
201
        dialog.display()
 
202
        gtk.main()
225
203
 
226
204
    def get_background_items(self, window, vfs_file):
227
205
        items = []
228
206
        file = vfs_file.get_uri()
229
 
 
230
207
        try:
231
208
            tree, path = WorkingTree.open_containing(file)
232
 
            disabled_flag = self.check_branch_enabled(tree.branch)
233
 
        except UnsupportedProtocol:
234
 
            return
235
209
        except NotBranchError:
236
 
            disabled_flag = self.check_branch_enabled()
237
210
            item = nautilus.MenuItem('BzrNautilus::newtree',
238
211
                                 'Make directory versioned',
239
212
                                 'Create new Bazaar tree in this folder')
241
214
            items.append(item)
242
215
 
243
216
            item = nautilus.MenuItem('BzrNautilus::clone',
244
 
                                 'Checkout Bazaar branch ...',
 
217
                                 'Checkout Bazaar branch',
245
218
                                 'Checkout Existing Bazaar Branch')
246
219
            item.connect('activate', self.clone_cb, vfs_file)
247
220
            items.append(item)
248
221
 
249
222
            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
223
 
266
224
        item = nautilus.MenuItem('BzrNautilus::log',
267
 
                             'History ...',
 
225
                             'Log',
268
226
                             'Show Bazaar history')
269
227
        item.connect('activate', self.log_cb, vfs_file)
270
228
        items.append(item)
271
229
 
272
230
        item = nautilus.MenuItem('BzrNautilus::pull',
273
 
                             'Pull ...',
 
231
                             'Pull',
274
232
                             'Pull from another branch')
275
233
        item.connect('activate', self.pull_cb, vfs_file)
276
234
        items.append(item)
277
235
 
278
236
        item = nautilus.MenuItem('BzrNautilus::merge',
279
 
                             'Merge ...',
 
237
                             'Merge',
280
238
                             'Merge from another branch')
281
239
        item.connect('activate', self.merge_cb, vfs_file)
282
240
        items.append(item)
283
241
 
284
242
        item = nautilus.MenuItem('BzrNautilus::commit',
285
 
                             'Commit ...',
 
243
                             'Commit',
286
244
                             'Commit Changes')
287
245
        item.connect('activate', self.commit_cb, vfs_file)
288
246
        items.append(item)
289
247
 
290
248
        return items
291
249
 
 
250
 
292
251
    def get_file_items(self, window, files):
293
252
        items = []
294
 
        
295
 
        wtfiles = {}
 
253
 
296
254
        for vfs_file in files:
297
255
            # We can only cope with local files
298
256
            if vfs_file.get_uri_scheme() != 'file':
299
 
                continue
 
257
                return
300
258
 
301
259
            file = vfs_file.get_uri()
302
260
            try:
303
261
                tree, path = WorkingTree.open_containing(file)
304
 
                disabled_flag = self.check_branch_enabled(tree.branch)
305
262
            except NotBranchError:
306
 
                disabled_flag = self.check_branch_enabled()
307
263
                if not vfs_file.is_directory():
308
 
                    continue
309
 
 
310
 
                if disabled_flag == 'False':
311
264
                    return
312
 
 
313
265
                item = nautilus.MenuItem('BzrNautilus::newtree',
314
266
                                     'Make directory versioned',
315
267
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
316
268
                item.connect('activate', self.newtree_cb, vfs_file)
317
269
                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] == '?':
 
270
 
 
271
            file_class = tree.file_class(path)
 
272
 
 
273
            if file_class == '?':
329
274
                item = nautilus.MenuItem('BzrNautilus::add',
330
275
                                     'Add',
331
276
                                     'Add as versioned file')
337
282
                                     'Ignore file for versioning')
338
283
                item.connect('activate', self.ignore_cb, vfs_file)
339
284
                items.append(item)
340
 
            elif wtfiles[path] == 'I':
 
285
            elif file_class == 'I':
341
286
                item = nautilus.MenuItem('BzrNautilus::unignore',
342
287
                                     'Unignore',
343
288
                                     'Unignore file for versioning')
344
289
                item.connect('activate', self.unignore_cb, vfs_file)
345
290
                items.append(item)
346
 
            elif wtfiles[path] == 'V':
 
291
            elif file_class == 'V':
347
292
                item = nautilus.MenuItem('BzrNautilus::log',
348
 
                                 'History ...',
 
293
                                 'Log',
349
294
                                 'List changes')
350
295
                item.connect('activate', self.log_cb, vfs_file)
351
296
                items.append(item)
352
297
 
353
298
                item = nautilus.MenuItem('BzrNautilus::diff',
354
 
                                 'View Changes ...',
 
299
                                 'Diff',
355
300
                                 'Show differences')
356
301
                item.connect('activate', self.diff_cb, vfs_file)
357
302
                items.append(item)
363
308
                items.append(item)
364
309
 
365
310
                item = nautilus.MenuItem('BzrNautilus::annotate',
366
 
                             'Annotate ...',
 
311
                             'Annotate',
367
312
                             'Annotate File Data')
368
313
                item.connect('activate', self.annotate_cb, vfs_file)
369
314
                items.append(item)
370
315
 
371
316
                item = nautilus.MenuItem('BzrNautilus::commit',
372
 
                             'Commit ...',
 
317
                             'Commit',
373
318
                             'Commit Changes')
374
319
                item.connect('activate', self.commit_cb, vfs_file)
375
320
                items.append(item)
383
328
                               "Version control status"),
384
329
 
385
330
    def update_file_info(self, file):
386
 
 
387
331
        if file.get_uri_scheme() != 'file':
388
332
            return
389
333
        
391
335
            tree, path = WorkingTree.open_containing(file.get_uri())
392
336
        except NotBranchError:
393
337
            return
394
 
        except NoWorkingTree:
395
 
            return   
396
 
 
397
 
        disabled_flag = self.check_branch_enabled(tree.branch)
398
 
        if disabled_flag == 'False':
399
 
            return
400
338
 
401
339
        emblem = None
402
340
        status = None
403
341
 
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'
 
342
        if tree.has_filename(path):
 
343
            emblem = 'cvs-controlled'
414
344
            status = 'unchanged'
 
345
            id = tree.path2id(path)
415
346
 
416
347
            delta = tree.changes_from(tree.branch.basis_tree())
417
348
            if delta.touches_file_id(id):
418
 
                emblem = 'bzr-modified'
 
349
                emblem = 'cvs-modified'
419
350
                status = 'modified'
420
351
            for f, _, _ in delta.added:
421
352
                if f == path:
422
 
                    emblem = 'bzr-added'
 
353
                    emblem = 'cvs-added'
423
354
                    status = 'added'
424
355
 
425
356
            for of, f, _, _, _, _ in delta.renamed:
427
358
                    status = 'renamed from %s' % f
428
359
 
429
360
        elif tree.branch.basis_tree().has_filename(path):
430
 
            emblem = 'bzr-removed'
 
361
            emblem = 'cvs-removed'
431
362
            status = 'removed'
432
363
        else:
433
364
            # FIXME: Check for ignored files
436
367
        if emblem is not None:
437
368
            file.add_emblem(emblem)
438
369
        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