/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: Daniel Schierbeck
  • Date: 2007-11-02 14:49:57 UTC
  • mto: (330.6.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 341.
  • Revision ID: daniel.schierbeck@gmail.com-20071102144957-8r4lp70ma5bpk8r8
Renamed logview 'revisionview'.

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, cmd_visualise, cmd_gannotate
 
19
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
23
20
 
24
21
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
25
22
    def __init__(self):
81
78
        except NotBranchError:
82
79
            return
83
80
 
84
 
        from bzrlib.plugins.gtk.diff import DiffWindow
 
81
        from bzrlib.plugins.gtk.viz.diff import DiffWindow
85
82
        window = DiffWindow()
86
83
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
87
84
        window.show()
99
96
        try:
100
97
            tree, path = WorkingTree.open_containing(file)
101
98
        except NotBranchError:
102
 
            BzrDir.create_standalone_workingtree(file)
 
99
            BzrDir.create_branch_and_repo(file)
103
100
 
104
101
    def remove_cb(self, menu, vfs_file):
105
102
        # We can only cope with local files
132
129
        from bzrlib.plugins.gtk.branch import BranchDialog
133
130
        
134
131
        dialog = BranchDialog(vfs_file.get_name())
135
 
        response = dialog.run()
136
 
        if response != gtk.RESPONSE_NONE:
137
 
            dialog.hide()
138
 
            dialog.destroy()
 
132
        dialog.display()
139
133
 
140
134
    def commit_cb(self, menu, vfs_file=None):
141
135
        # We can only cope with local files
143
137
            return
144
138
 
145
139
        file = vfs_file.get_uri()
146
 
        tree = None
147
 
        branch = None
148
140
        try:
149
141
            tree, path = WorkingTree.open_containing(file)
150
 
            branch = tree.branch
151
 
        except NotBranchError, e:
152
 
            path = e.path
153
 
            #return
154
 
        except NoWorkingTree, e:
155
 
            path = e.base
156
 
            try:
157
 
                (branch, path) = Branch.open_containing(path)
158
 
            except NotBranchError, e:
159
 
                path = e.path
 
142
        except NotBranchError:
 
143
            return
160
144
 
161
145
        from bzrlib.plugins.gtk.commit import CommitDialog
162
146
        dialog = CommitDialog(tree, path)
163
 
        response = dialog.run()
164
 
        if response != gtk.RESPONSE_NONE:
165
 
            dialog.hide()
166
 
            dialog.destroy()
 
147
        dialog.display()
 
148
        gtk.main()
167
149
 
168
150
    def log_cb(self, menu, vfs_file):
169
151
        # We can only cope with local files
222
204
    def get_background_items(self, window, vfs_file):
223
205
        items = []
224
206
        file = vfs_file.get_uri()
225
 
 
226
207
        try:
227
208
            tree, path = WorkingTree.open_containing(file)
228
 
            disabled_flag = self.check_branch_enabled(tree.branch)
229
 
        except UnsupportedProtocol:
230
 
            return
231
209
        except NotBranchError:
232
 
            disabled_flag = self.check_branch_enabled()
233
210
            item = nautilus.MenuItem('BzrNautilus::newtree',
234
211
                                 'Make directory versioned',
235
212
                                 'Create new Bazaar tree in this folder')
243
220
            items.append(item)
244
221
 
245
222
            return items
246
 
        except NoWorkingTree:
247
 
            return
248
 
        
249
 
        if disabled_flag == 'False':
250
 
            item = nautilus.MenuItem('BzrNautilus::enable',
251
 
                                     'Enable Bazaar Plugin for this Branch',
252
 
                                     'Enable Bazaar plugin for nautilus')
253
 
            item.connect('activate', self.toggle_integration, 'True', vfs_file)
254
 
            return item,
255
 
        else:
256
 
            item = nautilus.MenuItem('BzrNautilus::disable',
257
 
                                      'Disable Bazaar Plugin for the Branch',
258
 
                                      'Disable Bazaar plugin for nautilus')
259
 
            item.connect('activate', self.toggle_integration, 'False', vfs_file)
260
 
            items.append(item)
261
223
 
262
224
        item = nautilus.MenuItem('BzrNautilus::log',
263
225
                             'Log',
285
247
 
286
248
        return items
287
249
 
 
250
 
288
251
    def get_file_items(self, window, files):
289
252
        items = []
290
 
        
291
 
        wtfiles = {}
 
253
 
292
254
        for vfs_file in files:
293
255
            # We can only cope with local files
294
256
            if vfs_file.get_uri_scheme() != 'file':
295
 
                continue
 
257
                return
296
258
 
297
259
            file = vfs_file.get_uri()
298
260
            try:
299
261
                tree, path = WorkingTree.open_containing(file)
300
 
                disabled_flag = self.check_branch_enabled(tree.branch)
301
262
            except NotBranchError:
302
 
                disabled_flag = self.check_branch_enabled()
303
263
                if not vfs_file.is_directory():
304
 
                    continue
305
 
 
306
 
                if disabled_flag == 'False':
307
264
                    return
308
 
 
309
265
                item = nautilus.MenuItem('BzrNautilus::newtree',
310
266
                                     'Make directory versioned',
311
267
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
312
268
                item.connect('activate', self.newtree_cb, vfs_file)
313
269
                return item,
314
 
            except NoWorkingTree:
315
 
                continue
316
 
            # Refresh the list of filestatuses in the working tree
317
 
            if path not in wtfiles.keys():
318
 
                tree.lock_read()
319
 
                for rpath, file_class, kind, id, entry in tree.list_files():
320
 
                    wtfiles[rpath] = file_class
321
 
                tree.unlock()
322
 
                wtfiles[u''] = 'V'
323
 
 
324
 
            if wtfiles[path] == '?':
 
270
 
 
271
            file_class = tree.file_class(path)
 
272
 
 
273
            if file_class == '?':
325
274
                item = nautilus.MenuItem('BzrNautilus::add',
326
275
                                     'Add',
327
276
                                     'Add as versioned file')
333
282
                                     'Ignore file for versioning')
334
283
                item.connect('activate', self.ignore_cb, vfs_file)
335
284
                items.append(item)
336
 
            elif wtfiles[path] == 'I':
 
285
            elif file_class == 'I':
337
286
                item = nautilus.MenuItem('BzrNautilus::unignore',
338
287
                                     'Unignore',
339
288
                                     'Unignore file for versioning')
340
289
                item.connect('activate', self.unignore_cb, vfs_file)
341
290
                items.append(item)
342
 
            elif wtfiles[path] == 'V':
 
291
            elif file_class == 'V':
343
292
                item = nautilus.MenuItem('BzrNautilus::log',
344
293
                                 'Log',
345
294
                                 'List changes')
379
328
                               "Version control status"),
380
329
 
381
330
    def update_file_info(self, file):
382
 
 
383
331
        if file.get_uri_scheme() != 'file':
384
332
            return
385
333
        
387
335
            tree, path = WorkingTree.open_containing(file.get_uri())
388
336
        except NotBranchError:
389
337
            return
390
 
        except NoWorkingTree:
391
 
            return   
392
 
 
393
 
        disabled_flag = self.check_branch_enabled(tree.branch)
394
 
        if disabled_flag == 'False':
395
 
            return
396
338
 
397
339
        emblem = None
398
340
        status = None
399
341
 
400
342
        if tree.has_filename(path):
401
 
            emblem = 'bzr-controlled'
 
343
            emblem = 'cvs-controlled'
402
344
            status = 'unchanged'
403
345
            id = tree.path2id(path)
404
346
 
405
347
            delta = tree.changes_from(tree.branch.basis_tree())
406
348
            if delta.touches_file_id(id):
407
 
                emblem = 'bzr-modified'
 
349
                emblem = 'cvs-modified'
408
350
                status = 'modified'
409
351
            for f, _, _ in delta.added:
410
352
                if f == path:
411
 
                    emblem = 'bzr-added'
 
353
                    emblem = 'cvs-added'
412
354
                    status = 'added'
413
355
 
414
356
            for of, f, _, _, _, _ in delta.renamed:
416
358
                    status = 'renamed from %s' % f
417
359
 
418
360
        elif tree.branch.basis_tree().has_filename(path):
419
 
            emblem = 'bzr-removed'
 
361
            emblem = 'cvs-removed'
420
362
            status = 'removed'
421
363
        else:
422
364
            # FIXME: Check for ignored files
425
367
        if emblem is not None:
426
368
            file.add_emblem(emblem)
427
369
        file.add_string_attribute('bzr_status', status)
428
 
 
429
 
    def check_branch_enabled(self, branch=None):
430
 
        # Supports global disable, but there is currently no UI to do this
431
 
        config = GlobalConfig()
432
 
        disabled_flag = config.get_user_option('nautilus_integration')
433
 
        if disabled_flag != 'False':
434
 
            if branch is not None:
435
 
                config = branch.get_config()
436
 
                disabled_flag = config.get_user_option('nautilus_integration')
437
 
        return disabled_flag
438
 
 
439
 
    def toggle_integration(self, menu, action, vfs_file=None):
440
 
        try:
441
 
            tree, path = WorkingTree.open_containing(vfs_file.get_uri())
442
 
        except NotBranchError:
443
 
            return
444
 
        except NoWorkingTree:
445
 
            return
446
 
        branch = tree.branch
447
 
        if branch is None:
448
 
            config = GlobalConfig()
449
 
        else:
450
 
            config = branch.get_config()
451
 
        config.set_user_option('nautilus_integration', action)
452