/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: 2008-03-28 19:26:53 UTC
  • mto: (450.1.13 trunk)
  • mto: This revision was merged to the branch mainline in revision 458.
  • Revision ID: jelmer@samba.org-20080328192653-trzptkwahx1tulz9
Add module for preferences code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#
7
7
# Published under the GNU GPL
8
8
 
9
 
from gi.repository import Gtk
 
9
import gtk
10
10
import nautilus
 
11
import bzrlib
11
12
from bzrlib.branch import Branch
12
13
from bzrlib.bzrdir import BzrDir
13
 
from bzrlib.errors import (
14
 
    NotBranchError,
15
 
    NoWorkingTree,
16
 
    UnsupportedProtocol,
17
 
    )
 
14
from bzrlib.errors import NotBranchError, NoWorkingTree, UnsupportedProtocol
 
15
from bzrlib.tree import file_status
18
16
from bzrlib.workingtree import WorkingTree
19
 
from bzrlib.config import GlobalConfig
20
17
 
21
18
from bzrlib.plugin import load_plugins
22
19
load_plugins()
23
20
 
24
 
from bzrlib.plugins.gtk.commands import (
25
 
    cmd_gannotate,
26
 
    start_viz_window,
27
 
    )
28
 
 
29
 
print "Bazaar nautilus module initialized"
30
 
 
 
21
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
31
22
 
32
23
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
33
 
 
34
24
    def __init__(self):
35
25
        pass
36
26
 
92
82
 
93
83
        from bzrlib.plugins.gtk.diff import DiffWindow
94
84
        window = DiffWindow()
95
 
        window.set_diff(tree.branch._get_nick(local=True), tree, 
96
 
                        tree.branch.basis_tree())
 
85
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
97
86
        window.show()
98
87
 
99
88
        return
143
132
        
144
133
        dialog = BranchDialog(vfs_file.get_name())
145
134
        response = dialog.run()
146
 
        if response != Gtk.ResponseType.NONE:
 
135
        if response != gtk.RESPONSE_NONE:
147
136
            dialog.hide()
148
137
            dialog.destroy()
149
138
 
171
160
        from bzrlib.plugins.gtk.commit import CommitDialog
172
161
        dialog = CommitDialog(tree, path)
173
162
        response = dialog.run()
174
 
        if response != Gtk.ResponseType.NONE:
 
163
        if response != gtk.RESPONSE_NONE:
175
164
            dialog.hide()
176
165
            dialog.destroy()
177
166
 
184
173
 
185
174
        # We only want to continue here if we get a NotBranchError
186
175
        try:
187
 
            branch, path = Branch.open_containing(file)
 
176
            tree, path = WorkingTree.open_containing(file)
188
177
        except NotBranchError:
189
178
            return
190
179
 
191
 
        pp = start_viz_window(branch, [branch.last_revision()])
192
 
        pp.show()
193
 
        Gtk.main()
 
180
        vis = cmd_visualise()
 
181
        vis.run(file)
 
182
 
 
183
        return
194
184
 
195
185
    def pull_cb(self, menu, vfs_file):
196
186
        # We can only cope with local files
208
198
        from bzrlib.plugins.gtk.pull import PullDialog
209
199
        dialog = PullDialog(tree, path)
210
200
        dialog.display()
211
 
        Gtk.main()
 
201
        gtk.main()
212
202
 
213
203
    def merge_cb(self, menu, vfs_file):
214
204
        # We can only cope with local files
225
215
 
226
216
        from bzrlib.plugins.gtk.merge import MergeDialog
227
217
        dialog = MergeDialog(tree, path)
228
 
        dialog.run()
229
 
        dialog.destroy()
 
218
        dialog.display()
 
219
        gtk.main()
230
220
 
231
221
    def get_background_items(self, window, vfs_file):
232
222
        items = []
233
223
        file = vfs_file.get_uri()
234
 
 
235
224
        try:
236
225
            tree, path = WorkingTree.open_containing(file)
237
 
            disabled_flag = self.check_branch_enabled(tree.branch)
238
226
        except UnsupportedProtocol:
239
227
            return
240
228
        except NotBranchError:
241
 
            disabled_flag = self.check_branch_enabled()
242
229
            item = nautilus.MenuItem('BzrNautilus::newtree',
243
230
                                 'Make directory versioned',
244
231
                                 'Create new Bazaar tree in this folder')
246
233
            items.append(item)
247
234
 
248
235
            item = nautilus.MenuItem('BzrNautilus::clone',
249
 
                                 'Checkout Bazaar branch ...',
 
236
                                 'Checkout Bazaar branch',
250
237
                                 'Checkout Existing Bazaar Branch')
251
238
            item.connect('activate', self.clone_cb, vfs_file)
252
239
            items.append(item)
254
241
            return items
255
242
        except NoWorkingTree:
256
243
            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
244
 
271
245
        item = nautilus.MenuItem('BzrNautilus::log',
272
 
                             'History ...',
 
246
                             'Log',
273
247
                             'Show Bazaar history')
274
248
        item.connect('activate', self.log_cb, vfs_file)
275
249
        items.append(item)
276
250
 
277
251
        item = nautilus.MenuItem('BzrNautilus::pull',
278
 
                             'Pull ...',
 
252
                             'Pull',
279
253
                             'Pull from another branch')
280
254
        item.connect('activate', self.pull_cb, vfs_file)
281
255
        items.append(item)
282
256
 
283
257
        item = nautilus.MenuItem('BzrNautilus::merge',
284
 
                             'Merge ...',
 
258
                             'Merge',
285
259
                             'Merge from another branch')
286
260
        item.connect('activate', self.merge_cb, vfs_file)
287
261
        items.append(item)
288
262
 
289
263
        item = nautilus.MenuItem('BzrNautilus::commit',
290
 
                             'Commit ...',
 
264
                             'Commit',
291
265
                             'Commit Changes')
292
266
        item.connect('activate', self.commit_cb, vfs_file)
293
267
        items.append(item)
296
270
 
297
271
    def get_file_items(self, window, files):
298
272
        items = []
299
 
        
 
273
 
300
274
        wtfiles = {}
301
275
        for vfs_file in files:
302
276
            # We can only cope with local files
306
280
            file = vfs_file.get_uri()
307
281
            try:
308
282
                tree, path = WorkingTree.open_containing(file)
309
 
                disabled_flag = self.check_branch_enabled(tree.branch)
310
283
            except NotBranchError:
311
 
                disabled_flag = self.check_branch_enabled()
312
284
                if not vfs_file.is_directory():
313
285
                    continue
314
 
 
315
 
                if disabled_flag == 'False':
316
 
                    return
317
 
 
318
286
                item = nautilus.MenuItem('BzrNautilus::newtree',
319
287
                                     'Make directory versioned',
320
288
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
350
318
                items.append(item)
351
319
            elif wtfiles[path] == 'V':
352
320
                item = nautilus.MenuItem('BzrNautilus::log',
353
 
                                 'History ...',
 
321
                                 'Log',
354
322
                                 'List changes')
355
323
                item.connect('activate', self.log_cb, vfs_file)
356
324
                items.append(item)
357
325
 
358
326
                item = nautilus.MenuItem('BzrNautilus::diff',
359
 
                                 'View Changes ...',
 
327
                                 'Diff',
360
328
                                 'Show differences')
361
329
                item.connect('activate', self.diff_cb, vfs_file)
362
330
                items.append(item)
368
336
                items.append(item)
369
337
 
370
338
                item = nautilus.MenuItem('BzrNautilus::annotate',
371
 
                             'Annotate ...',
 
339
                             'Annotate',
372
340
                             'Annotate File Data')
373
341
                item.connect('activate', self.annotate_cb, vfs_file)
374
342
                items.append(item)
375
343
 
376
344
                item = nautilus.MenuItem('BzrNautilus::commit',
377
 
                             'Commit ...',
 
345
                             'Commit',
378
346
                             'Commit Changes')
379
347
                item.connect('activate', self.commit_cb, vfs_file)
380
348
                items.append(item)
388
356
                               "Version control status"),
389
357
 
390
358
    def update_file_info(self, file):
391
 
 
392
359
        if file.get_uri_scheme() != 'file':
393
360
            return
394
361
        
397
364
        except NotBranchError:
398
365
            return
399
366
        except NoWorkingTree:
400
 
            return   
401
 
 
402
 
        disabled_flag = self.check_branch_enabled(tree.branch)
403
 
        if disabled_flag == 'False':
404
367
            return
405
368
 
406
369
        emblem = None
407
370
        status = None
408
371
 
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):
 
372
        if tree.has_filename(path):
418
373
            emblem = 'bzr-controlled'
419
374
            status = 'unchanged'
 
375
            id = tree.path2id(path)
420
376
 
421
377
            delta = tree.changes_from(tree.branch.basis_tree())
422
378
            if delta.touches_file_id(id):
437
393
        else:
438
394
            # FIXME: Check for ignored files
439
395
            status = 'unversioned'
 
396
            emblem = 'bzr-unversioned'
440
397
        
441
398
        if emblem is not None:
442
399
            file.add_emblem(emblem)
443
400
        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