/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-09 13:47:52 UTC
  • mto: This revision was merged to the branch mainline in revision 447.
  • Revision ID: jelmer@samba.org-20080309134752-syf9kwzy6e919jhj
Add note about python-nautilus requiring a libpythonXX.so symlink.

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
import gtk
9
10
import nautilus
10
11
import bzrlib
 
12
from bzrlib.branch import Branch
11
13
from bzrlib.bzrdir import BzrDir
12
 
from bzrlib.errors import NotBranchError
 
14
from bzrlib.errors import NotBranchError, NoWorkingTree, UnsupportedProtocol
 
15
from bzrlib.tree import file_status
13
16
from bzrlib.workingtree import WorkingTree
14
 
from bzrlib.tree import file_status
15
17
 
16
18
from bzrlib.plugin import load_plugins
17
19
load_plugins()
78
80
        except NotBranchError:
79
81
            return
80
82
 
81
 
        from bzrlib.plugins.gtk.viz.diff import DiffWindow
 
83
        from bzrlib.plugins.gtk.diff import DiffWindow
82
84
        window = DiffWindow()
83
85
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
84
86
        window.show()
96
98
        try:
97
99
            tree, path = WorkingTree.open_containing(file)
98
100
        except NotBranchError:
99
 
            BzrDir.create_branch_and_repo(file)
 
101
            BzrDir.create_standalone_workingtree(file)
100
102
 
101
103
    def remove_cb(self, menu, vfs_file):
102
104
        # We can only cope with local files
129
131
        from bzrlib.plugins.gtk.branch import BranchDialog
130
132
        
131
133
        dialog = BranchDialog(vfs_file.get_name())
132
 
        dialog.display()
 
134
        response = dialog.run()
 
135
        if response != gtk.RESPONSE_NONE:
 
136
            dialog.hide()
 
137
            dialog.destroy()
133
138
 
134
139
    def commit_cb(self, menu, vfs_file=None):
135
140
        # We can only cope with local files
137
142
            return
138
143
 
139
144
        file = vfs_file.get_uri()
 
145
        tree = None
 
146
        branch = None
140
147
        try:
141
148
            tree, path = WorkingTree.open_containing(file)
142
 
        except NotBranchError:
143
 
            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
144
159
 
145
160
        from bzrlib.plugins.gtk.commit import CommitDialog
146
161
        dialog = CommitDialog(tree, path)
147
 
        dialog.display()
148
 
        gtk.main()
 
162
        response = dialog.run()
 
163
        if response != gtk.RESPONSE_NONE:
 
164
            dialog.hide()
 
165
            dialog.destroy()
149
166
 
150
167
    def log_cb(self, menu, vfs_file):
151
168
        # We can only cope with local files
206
223
        file = vfs_file.get_uri()
207
224
        try:
208
225
            tree, path = WorkingTree.open_containing(file)
 
226
        except UnsupportedProtocol:
 
227
            return
209
228
        except NotBranchError:
210
229
            item = nautilus.MenuItem('BzrNautilus::newtree',
211
230
                                 'Make directory versioned',
220
239
            items.append(item)
221
240
 
222
241
            return items
 
242
        except NoWorkingTree:
 
243
            return
223
244
 
224
245
        item = nautilus.MenuItem('BzrNautilus::log',
225
246
                             'Log',
247
268
 
248
269
        return items
249
270
 
250
 
 
251
271
    def get_file_items(self, window, files):
252
272
        items = []
253
273
 
 
274
        wtfiles = {}
254
275
        for vfs_file in files:
255
276
            # We can only cope with local files
256
277
            if vfs_file.get_uri_scheme() != 'file':
257
 
                return
 
278
                continue
258
279
 
259
280
            file = vfs_file.get_uri()
260
281
            try:
261
282
                tree, path = WorkingTree.open_containing(file)
262
283
            except NotBranchError:
263
284
                if not vfs_file.is_directory():
264
 
                    return
 
285
                    continue
265
286
                item = nautilus.MenuItem('BzrNautilus::newtree',
266
287
                                     'Make directory versioned',
267
288
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
268
289
                item.connect('activate', self.newtree_cb, vfs_file)
269
290
                return item,
270
 
 
271
 
            file_class = tree.file_class(path)
272
 
 
273
 
            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] == '?':
274
302
                item = nautilus.MenuItem('BzrNautilus::add',
275
303
                                     'Add',
276
304
                                     'Add as versioned file')
282
310
                                     'Ignore file for versioning')
283
311
                item.connect('activate', self.ignore_cb, vfs_file)
284
312
                items.append(item)
285
 
            elif file_class == 'I':
 
313
            elif wtfiles[path] == 'I':
286
314
                item = nautilus.MenuItem('BzrNautilus::unignore',
287
315
                                     'Unignore',
288
316
                                     'Unignore file for versioning')
289
317
                item.connect('activate', self.unignore_cb, vfs_file)
290
318
                items.append(item)
291
 
            elif file_class == 'V':
 
319
            elif wtfiles[path] == 'V':
292
320
                item = nautilus.MenuItem('BzrNautilus::log',
293
321
                                 'Log',
294
322
                                 'List changes')
335
363
            tree, path = WorkingTree.open_containing(file.get_uri())
336
364
        except NotBranchError:
337
365
            return
 
366
        except NoWorkingTree:
 
367
            return
338
368
 
339
369
        emblem = None
340
370
        status = None