/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: Szilveszter Farkas (Phanatic)
  • Date: 2008-03-03 17:24:22 UTC
  • mto: This revision was merged to the branch mainline in revision 435.
  • Revision ID: szilveszter.farkas@gmail.com-20080303172422-y1u0gg7kyirrxuun
Installing an olive package is pretty useless. (Fixed: #136432)

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