/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: Curtis Hovey
  • Date: 2011-09-05 03:44:26 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110905034426-p98pxnay9rmzkr99
Fix the initializer for many classes.
Replace Gtk.Dialog.vbox with .get_content_area().

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