/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: 2008-01-13 14:12:49 UTC
  • mto: (423.1.2 trunk)
  • mto: This revision was merged to the branch mainline in revision 429.
  • Revision ID: daniel.schierbeck@gmail.com-20080113141249-gd0i2lknr3yik55r
Moved branch view to its own package.

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 Jelmer Vernooij
 
6
#
 
7
# Published under the GNU GPL
 
8
 
 
9
import gtk
1
10
import nautilus
2
11
import bzrlib
3
12
from bzrlib.bzrdir import BzrDir
4
13
from bzrlib.errors import NotBranchError
 
14
from bzrlib.errors import NoWorkingTree
 
15
from bzrlib.errors import UnsupportedProtocol
5
16
from bzrlib.workingtree import WorkingTree
 
17
from bzrlib.branch import Branch
6
18
from bzrlib.tree import file_status
7
19
 
8
20
from bzrlib.plugin import load_plugins
70
82
        except NotBranchError:
71
83
            return
72
84
 
73
 
        from bzrlib.plugins.gtk.viz.diff import DiffWindow
 
85
        from bzrlib.plugins.gtk.diff import DiffWindow
74
86
        window = DiffWindow()
75
87
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
76
88
        window.show()
88
100
        try:
89
101
            tree, path = WorkingTree.open_containing(file)
90
102
        except NotBranchError:
91
 
            BzrDir.create_branch_and_repo(file)
 
103
            BzrDir.create_standalone_workingtree(file)
92
104
 
93
105
    def remove_cb(self, menu, vfs_file):
94
106
        # We can only cope with local files
121
133
        from bzrlib.plugins.gtk.branch import BranchDialog
122
134
        
123
135
        dialog = BranchDialog(vfs_file.get_name())
124
 
        dialog.display()
 
136
        response = dialog.run()
 
137
        if response != gtk.RESPONSE_NONE:
 
138
            dialog.hide()
 
139
            dialog.destroy()
125
140
 
126
141
    def commit_cb(self, menu, vfs_file=None):
127
142
        # We can only cope with local files
129
144
            return
130
145
 
131
146
        file = vfs_file.get_uri()
 
147
        tree = None
 
148
        branch = None
132
149
        try:
133
150
            tree, path = WorkingTree.open_containing(file)
134
 
        except NotBranchError:
135
 
            return
 
151
            branch = tree.branch
 
152
        except NotBranchError, e:
 
153
            path = e.path
 
154
            #return
 
155
        except NoWorkingTree, e:
 
156
            path = e.base
 
157
            try:
 
158
                (branch, path) = Branch.open_containing(path)
 
159
            except NotBranchError, e:
 
160
                path = e.path
136
161
 
137
162
        from bzrlib.plugins.gtk.commit import CommitDialog
138
 
        dialog = CommitDialog(tree, path)
139
 
        dialog.display()
140
 
        gtk.main()
 
163
        dialog = CommitDialog(tree, path, not branch)
 
164
        response = dialog.run()
 
165
        if response != gtk.RESPONSE_NONE:
 
166
            dialog.hide()
 
167
            dialog.destroy()
141
168
 
142
169
    def log_cb(self, menu, vfs_file):
143
170
        # We can only cope with local files
198
225
        file = vfs_file.get_uri()
199
226
        try:
200
227
            tree, path = WorkingTree.open_containing(file)
 
228
        except UnsupportedProtocol:
 
229
            return
201
230
        except NotBranchError:
202
231
            item = nautilus.MenuItem('BzrNautilus::newtree',
203
232
                                 'Make directory versioned',
243
272
    def get_file_items(self, window, files):
244
273
        items = []
245
274
 
 
275
        wtfiles = {}
246
276
        for vfs_file in files:
247
277
            # We can only cope with local files
248
278
            if vfs_file.get_uri_scheme() != 'file':
259
289
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
260
290
                item.connect('activate', self.newtree_cb, vfs_file)
261
291
                return item,
262
 
 
263
 
            file_class = tree.file_class(path)
264
 
 
265
 
            if file_class == '?':
 
292
            # Refresh the list of filestatuses in the working tree
 
293
            if path not in wtfiles.keys():
 
294
                tree.lock_read()
 
295
                for rpath, file_class, kind, id, entry in tree.list_files():
 
296
                    wtfiles[rpath] = file_class
 
297
                tree.unlock()
 
298
                wtfiles[u''] = 'V'
 
299
 
 
300
            if wtfiles[path] == '?':
266
301
                item = nautilus.MenuItem('BzrNautilus::add',
267
302
                                     'Add',
268
303
                                     'Add as versioned file')
274
309
                                     'Ignore file for versioning')
275
310
                item.connect('activate', self.ignore_cb, vfs_file)
276
311
                items.append(item)
277
 
            elif file_class == 'I':
 
312
            elif wtfiles[path] == 'I':
278
313
                item = nautilus.MenuItem('BzrNautilus::unignore',
279
314
                                     'Unignore',
280
315
                                     'Unignore file for versioning')
281
316
                item.connect('activate', self.unignore_cb, vfs_file)
282
317
                items.append(item)
283
 
            elif file_class == 'V':
 
318
            elif wtfiles[path] == 'V':
284
319
                item = nautilus.MenuItem('BzrNautilus::log',
285
320
                                 'Log',
286
321
                                 'List changes')