/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

Merged an approved request (single clicking bookmark).

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
17
 
7
18
from bzrlib.plugin import load_plugins
9
20
 
10
21
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
11
22
 
12
 
class BzrExtension(nautilus.MenuProvider):
 
23
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
13
24
    def __init__(self):
14
25
        pass
15
26
 
69
80
        except NotBranchError:
70
81
            return
71
82
 
72
 
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
 
83
        from bzrlib.plugins.gtk.diff import DiffWindow
73
84
        window = DiffWindow()
74
 
        window.set_diff(tree.branch, tree, tree.branch.revision_tree())
 
85
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
75
86
        window.show()
76
87
 
77
88
        return
87
98
        try:
88
99
            tree, path = WorkingTree.open_containing(file)
89
100
        except NotBranchError:
90
 
            BzrDir.create_branch_and_repo(file)
 
101
            BzrDir.create_standalone_workingtree(file)
91
102
 
92
103
    def remove_cb(self, menu, vfs_file):
93
104
        # We can only cope with local files
117
128
        if vfs_file.get_uri_scheme() != 'file':
118
129
            return
119
130
 
120
 
        file = vfs_file.get_uri()
121
 
        try:
122
 
            tree, path = WorkingTree.open_containing(file)
123
 
        except NotBranchError:
124
 
            return
125
 
 
126
 
        from bzrlib.plugins.gtk.clone import CloneDialog
127
 
        dialog = CloneDialog(file)
128
 
        if dialog.run() != gtk.RESPONSE_CANCEL:
129
 
            bzrdir = BzrDir.open(dialog.url)
130
 
            bzrdir.sprout(dialog.dest_path)
 
131
        from bzrlib.plugins.gtk.branch import BranchDialog
 
132
        
 
133
        dialog = BranchDialog(vfs_file.get_name())
 
134
        response = dialog.run()
 
135
        if response != gtk.RESPONSE_NONE:
 
136
            dialog.hide()
 
137
            dialog.destroy()
131
138
 
132
139
    def commit_cb(self, menu, vfs_file=None):
133
140
        # We can only cope with local files
135
142
            return
136
143
 
137
144
        file = vfs_file.get_uri()
 
145
        tree = None
 
146
        branch = None
138
147
        try:
139
148
            tree, path = WorkingTree.open_containing(file)
140
 
        except NotBranchError:
141
 
            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
142
159
 
143
 
        from bzrlib.plugins.gtk.commit import GCommitDialog
144
 
        dialog = GCommitDialog(tree)
145
 
        dialog.set_title(path + " - Commit")
146
 
        if dialog.run() != gtk.RESPONSE_CANCEL:
147
 
            Commit().commit(working_tree=wt,message=dialog.message,
148
 
                            specific_files=dialog.specific_files)
 
160
        from bzrlib.plugins.gtk.commit import CommitDialog
 
161
        dialog = CommitDialog(tree, path)
 
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
165
182
 
166
183
        return
167
184
 
 
185
    def pull_cb(self, menu, vfs_file):
 
186
        # We can only cope with local files
 
187
        if vfs_file.get_uri_scheme() != 'file':
 
188
            return
 
189
 
 
190
        file = vfs_file.get_uri()
 
191
 
 
192
        # We only want to continue here if we get a NotBranchError
 
193
        try:
 
194
            tree, path = WorkingTree.open_containing(file)
 
195
        except NotBranchError:
 
196
            return
 
197
 
 
198
        from bzrlib.plugins.gtk.pull import PullDialog
 
199
        dialog = PullDialog(tree, path)
 
200
        dialog.display()
 
201
        gtk.main()
 
202
 
 
203
    def merge_cb(self, menu, vfs_file):
 
204
        # We can only cope with local files
 
205
        if vfs_file.get_uri_scheme() != 'file':
 
206
            return
 
207
 
 
208
        file = vfs_file.get_uri()
 
209
 
 
210
        # We only want to continue here if we get a NotBranchError
 
211
        try:
 
212
            tree, path = WorkingTree.open_containing(file)
 
213
        except NotBranchError:
 
214
            return
 
215
 
 
216
        from bzrlib.plugins.gtk.merge import MergeDialog
 
217
        dialog = MergeDialog(tree, path)
 
218
        dialog.display()
 
219
        gtk.main()
 
220
 
168
221
    def get_background_items(self, window, vfs_file):
 
222
        items = []
169
223
        file = vfs_file.get_uri()
170
224
        try:
171
225
            tree, path = WorkingTree.open_containing(file)
 
226
        except UnsupportedProtocol:
 
227
            return
172
228
        except NotBranchError:
173
229
            item = nautilus.MenuItem('BzrNautilus::newtree',
174
 
                                 'Create new Bazaar tree',
 
230
                                 'Make directory versioned',
175
231
                                 'Create new Bazaar tree in this folder')
176
232
            item.connect('activate', self.newtree_cb, vfs_file)
177
233
            items.append(item)
178
234
 
179
235
            item = nautilus.MenuItem('BzrNautilus::clone',
180
 
                                 'Checkout',
 
236
                                 'Checkout Bazaar branch',
181
237
                                 'Checkout Existing Bazaar Branch')
182
238
            item.connect('activate', self.clone_cb, vfs_file)
183
239
            items.append(item)
184
240
 
185
241
            return items
 
242
        except NoWorkingTree:
 
243
            return
186
244
 
187
 
        items = []
188
245
        item = nautilus.MenuItem('BzrNautilus::log',
189
246
                             'Log',
190
247
                             'Show Bazaar history')
191
248
        item.connect('activate', self.log_cb, vfs_file)
192
249
        items.append(item)
193
250
 
 
251
        item = nautilus.MenuItem('BzrNautilus::pull',
 
252
                             'Pull',
 
253
                             'Pull from another branch')
 
254
        item.connect('activate', self.pull_cb, vfs_file)
 
255
        items.append(item)
 
256
 
 
257
        item = nautilus.MenuItem('BzrNautilus::merge',
 
258
                             'Merge',
 
259
                             'Merge from another branch')
 
260
        item.connect('activate', self.merge_cb, vfs_file)
 
261
        items.append(item)
 
262
 
194
263
        item = nautilus.MenuItem('BzrNautilus::commit',
195
264
                             'Commit',
196
265
                             'Commit Changes')
199
268
 
200
269
        return items
201
270
 
202
 
 
203
271
    def get_file_items(self, window, files):
204
272
        items = []
205
273
 
 
274
        wtfiles = {}
206
275
        for vfs_file in files:
207
276
            # We can only cope with local files
208
277
            if vfs_file.get_uri_scheme() != 'file':
209
 
                return
 
278
                continue
210
279
 
211
280
            file = vfs_file.get_uri()
212
281
            try:
213
282
                tree, path = WorkingTree.open_containing(file)
214
283
            except NotBranchError:
215
284
                if not vfs_file.is_directory():
216
 
                    return
 
285
                    continue
217
286
                item = nautilus.MenuItem('BzrNautilus::newtree',
218
 
                                     'Create new Bazaar tree',
 
287
                                     'Make directory versioned',
219
288
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
220
289
                item.connect('activate', self.newtree_cb, vfs_file)
221
290
                return item,
222
 
 
223
 
            file_class = tree.file_class(path)
224
 
 
225
 
            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] == '?':
226
302
                item = nautilus.MenuItem('BzrNautilus::add',
227
303
                                     'Add',
228
304
                                     'Add as versioned file')
234
310
                                     'Ignore file for versioning')
235
311
                item.connect('activate', self.ignore_cb, vfs_file)
236
312
                items.append(item)
237
 
            elif file_class == 'I':
 
313
            elif wtfiles[path] == 'I':
238
314
                item = nautilus.MenuItem('BzrNautilus::unignore',
239
315
                                     'Unignore',
240
316
                                     'Unignore file for versioning')
241
317
                item.connect('activate', self.unignore_cb, vfs_file)
242
318
                items.append(item)
243
 
            elif file_class == 'V':
 
319
            elif wtfiles[path] == 'V':
244
320
                item = nautilus.MenuItem('BzrNautilus::log',
245
321
                                 'Log',
246
322
                                 'List changes')
272
348
                items.append(item)
273
349
 
274
350
        return items
 
351
 
 
352
    def get_columns(self):
 
353
        return nautilus.Column("BzrNautilus::bzr_status",
 
354
                               "bzr_status",
 
355
                               "Bzr Status",
 
356
                               "Version control status"),
 
357
 
 
358
    def update_file_info(self, file):
 
359
        if file.get_uri_scheme() != 'file':
 
360
            return
 
361
        
 
362
        try:
 
363
            tree, path = WorkingTree.open_containing(file.get_uri())
 
364
        except NotBranchError:
 
365
            return
 
366
        except NoWorkingTree:
 
367
            return
 
368
 
 
369
        emblem = None
 
370
        status = None
 
371
 
 
372
        if tree.has_filename(path):
 
373
            emblem = 'bzr-controlled'
 
374
            status = 'unchanged'
 
375
            id = tree.path2id(path)
 
376
 
 
377
            delta = tree.changes_from(tree.branch.basis_tree())
 
378
            if delta.touches_file_id(id):
 
379
                emblem = 'bzr-modified'
 
380
                status = 'modified'
 
381
            for f, _, _ in delta.added:
 
382
                if f == path:
 
383
                    emblem = 'bzr-added'
 
384
                    status = 'added'
 
385
 
 
386
            for of, f, _, _, _, _ in delta.renamed:
 
387
                if f == path:
 
388
                    status = 'renamed from %s' % f
 
389
 
 
390
        elif tree.branch.basis_tree().has_filename(path):
 
391
            emblem = 'bzr-removed'
 
392
            status = 'removed'
 
393
        else:
 
394
            # FIXME: Check for ignored files
 
395
            status = 'unversioned'
 
396
            emblem = 'bzr-unversioned'
 
397
        
 
398
        if emblem is not None:
 
399
            file.add_emblem(emblem)
 
400
        file.add_string_attribute('bzr_status', status)