/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-07-15 18:12:57 UTC
  • Revision ID: jelmer@samba.org-20070715181257-g264qus2zyi3v39z
Add RevisionSelectionBox widget, use in TagDialog.

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