/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-14 02:19:21 UTC
  • mto: (452.2.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 453.
  • Revision ID: jelmer@samba.org-20080314021921-2dgptk62dhp7pd91
Honor child_submit_to in the submit_branch if no email address was specified.
Consistent with the changes in bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Trivial Bazaar plugin for Nautilus
 
2
#
 
3
# Copyright (C) 2006 Jeff Bailey
 
4
# Copyright (C) 2006 Wouter van Heyst
 
5
# Copyright (C) 2006-2008 Jelmer Vernooij <jelmer@samba.org>
 
6
#
 
7
# Published under the GNU GPL
 
8
 
 
9
import gtk
1
10
import nautilus
2
11
import bzrlib
 
12
from bzrlib.branch import Branch
3
13
from bzrlib.bzrdir import BzrDir
4
 
from bzrlib.errors import NotBranchError
 
14
from bzrlib.errors import NotBranchError, NoWorkingTree, UnsupportedProtocol
 
15
from bzrlib.tree import file_status
5
16
from bzrlib.workingtree import WorkingTree
6
 
from bzrlib.tree import file_status
7
17
 
8
18
from bzrlib.plugin import load_plugins
9
19
load_plugins()
70
80
        except NotBranchError:
71
81
            return
72
82
 
73
 
        from bzrlib.plugins.gtk.viz.diff import DiffWindow
 
83
        from bzrlib.plugins.gtk.diff import DiffWindow
74
84
        window = DiffWindow()
75
85
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
76
86
        window.show()
88
98
        try:
89
99
            tree, path = WorkingTree.open_containing(file)
90
100
        except NotBranchError:
91
 
            BzrDir.create_branch_and_repo(file)
 
101
            BzrDir.create_standalone_workingtree(file)
92
102
 
93
103
    def remove_cb(self, menu, vfs_file):
94
104
        # We can only cope with local files
121
131
        from bzrlib.plugins.gtk.branch import BranchDialog
122
132
        
123
133
        dialog = BranchDialog(vfs_file.get_name())
124
 
        dialog.display()
 
134
        response = dialog.run()
 
135
        if response != gtk.RESPONSE_NONE:
 
136
            dialog.hide()
 
137
            dialog.destroy()
125
138
 
126
139
    def commit_cb(self, menu, vfs_file=None):
127
140
        # We can only cope with local files
129
142
            return
130
143
 
131
144
        file = vfs_file.get_uri()
 
145
        tree = None
 
146
        branch = None
132
147
        try:
133
148
            tree, path = WorkingTree.open_containing(file)
134
 
        except NotBranchError:
135
 
            return
 
149
            branch = tree.branch
 
150
        except NotBranchError, e:
 
151
            path = e.path
 
152
            #return
 
153
        except NoWorkingTree, e:
 
154
            path = e.base
 
155
            try:
 
156
                (branch, path) = Branch.open_containing(path)
 
157
            except NotBranchError, e:
 
158
                path = e.path
136
159
 
137
160
        from bzrlib.plugins.gtk.commit import CommitDialog
138
161
        dialog = CommitDialog(tree, path)
139
 
        dialog.display()
140
 
        gtk.main()
 
162
        response = dialog.run()
 
163
        if response != gtk.RESPONSE_NONE:
 
164
            dialog.hide()
 
165
            dialog.destroy()
141
166
 
142
167
    def log_cb(self, menu, vfs_file):
143
168
        # We can only cope with local files
198
223
        file = vfs_file.get_uri()
199
224
        try:
200
225
            tree, path = WorkingTree.open_containing(file)
 
226
        except UnsupportedProtocol:
 
227
            return
201
228
        except NotBranchError:
202
229
            item = nautilus.MenuItem('BzrNautilus::newtree',
203
230
                                 'Make directory versioned',
212
239
            items.append(item)
213
240
 
214
241
            return items
 
242
        except NoWorkingTree:
 
243
            return
215
244
 
216
245
        item = nautilus.MenuItem('BzrNautilus::log',
217
246
                             'Log',
239
268
 
240
269
        return items
241
270
 
242
 
 
243
271
    def get_file_items(self, window, files):
244
272
        items = []
245
273
 
 
274
        wtfiles = {}
246
275
        for vfs_file in files:
247
276
            # We can only cope with local files
248
277
            if vfs_file.get_uri_scheme() != 'file':
249
 
                return
 
278
                continue
250
279
 
251
280
            file = vfs_file.get_uri()
252
281
            try:
253
282
                tree, path = WorkingTree.open_containing(file)
254
283
            except NotBranchError:
255
284
                if not vfs_file.is_directory():
256
 
                    return
 
285
                    continue
257
286
                item = nautilus.MenuItem('BzrNautilus::newtree',
258
287
                                     'Make directory versioned',
259
288
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
260
289
                item.connect('activate', self.newtree_cb, vfs_file)
261
290
                return item,
262
 
 
263
 
            file_class = tree.file_class(path)
264
 
 
265
 
            if file_class == '?':
 
291
            except NoWorkingTree:
 
292
                continue
 
293
            # Refresh the list of filestatuses in the working tree
 
294
            if path not in wtfiles.keys():
 
295
                tree.lock_read()
 
296
                for rpath, file_class, kind, id, entry in tree.list_files():
 
297
                    wtfiles[rpath] = file_class
 
298
                tree.unlock()
 
299
                wtfiles[u''] = 'V'
 
300
 
 
301
            if wtfiles[path] == '?':
266
302
                item = nautilus.MenuItem('BzrNautilus::add',
267
303
                                     'Add',
268
304
                                     'Add as versioned file')
274
310
                                     'Ignore file for versioning')
275
311
                item.connect('activate', self.ignore_cb, vfs_file)
276
312
                items.append(item)
277
 
            elif file_class == 'I':
 
313
            elif wtfiles[path] == 'I':
278
314
                item = nautilus.MenuItem('BzrNautilus::unignore',
279
315
                                     'Unignore',
280
316
                                     'Unignore file for versioning')
281
317
                item.connect('activate', self.unignore_cb, vfs_file)
282
318
                items.append(item)
283
 
            elif file_class == 'V':
 
319
            elif wtfiles[path] == 'V':
284
320
                item = nautilus.MenuItem('BzrNautilus::log',
285
321
                                 'Log',
286
322
                                 'List changes')
327
363
            tree, path = WorkingTree.open_containing(file.get_uri())
328
364
        except NotBranchError:
329
365
            return
 
366
        except NoWorkingTree:
 
367
            return
330
368
 
331
369
        emblem = None
332
370
        status = None
333
371
 
334
372
        if tree.has_filename(path):
335
 
            emblem = 'cvs-controlled'
 
373
            emblem = 'bzr-controlled'
336
374
            status = 'unchanged'
337
375
            id = tree.path2id(path)
338
376
 
339
377
            delta = tree.changes_from(tree.branch.basis_tree())
340
378
            if delta.touches_file_id(id):
341
 
                emblem = 'cvs-modified'
 
379
                emblem = 'bzr-modified'
342
380
                status = 'modified'
343
381
            for f, _, _ in delta.added:
344
382
                if f == path:
345
 
                    emblem = 'cvs-added'
 
383
                    emblem = 'bzr-added'
346
384
                    status = 'added'
347
385
 
348
386
            for of, f, _, _, _, _ in delta.renamed:
350
388
                    status = 'renamed from %s' % f
351
389
 
352
390
        elif tree.branch.basis_tree().has_filename(path):
353
 
            emblem = 'cvs-removed'
 
391
            emblem = 'bzr-removed'
354
392
            status = 'removed'
355
393
        else:
356
394
            # FIXME: Check for ignored files
357
395
            status = 'unversioned'
 
396
            emblem = 'bzr-unversioned'
358
397
        
359
398
        if emblem is not None:
360
399
            file.add_emblem(emblem)