/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: 2006-09-30 10:21:43 UTC
  • Revision ID: jelmer@samba.org-20060930102143-c0ef64d6ca860c21
Merge some files from Olive and bzr-gtk.

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
1
import nautilus
10
2
import bzrlib
11
3
from bzrlib.bzrdir import BzrDir
12
4
from bzrlib.errors import NotBranchError
13
5
from bzrlib.workingtree import WorkingTree
14
 
from bzrlib.tree import file_status
15
6
 
16
7
from bzrlib.plugin import load_plugins
17
8
load_plugins()
18
9
 
19
10
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
20
11
 
21
 
class BzrExtension(nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.InfoProvider):
 
12
class BzrExtension(nautilus.MenuProvider):
22
13
    def __init__(self):
23
14
        pass
24
15
 
78
69
        except NotBranchError:
79
70
            return
80
71
 
81
 
        from bzrlib.plugins.gtk.viz.diff import DiffWindow
 
72
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
82
73
        window = DiffWindow()
83
 
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
 
74
        window.set_diff(tree.branch, tree, tree.branch.revision_tree())
84
75
        window.show()
85
76
 
86
77
        return
126
117
        if vfs_file.get_uri_scheme() != 'file':
127
118
            return
128
119
 
129
 
        from bzrlib.plugins.gtk.branch import BranchDialog
130
 
        
131
 
        dialog = BranchDialog(vfs_file.get_name())
132
 
        dialog.display()
 
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
131
 
134
132
    def commit_cb(self, menu, vfs_file=None):
135
133
        # We can only cope with local files
142
140
        except NotBranchError:
143
141
            return
144
142
 
145
 
        from bzrlib.plugins.gtk.commit import CommitDialog
146
 
        dialog = CommitDialog(tree, path)
147
 
        dialog.display()
148
 
        gtk.main()
 
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)
149
149
 
150
150
    def log_cb(self, menu, vfs_file):
151
151
        # We can only cope with local files
165
165
 
166
166
        return
167
167
 
168
 
    def pull_cb(self, menu, vfs_file):
169
 
        # We can only cope with local files
170
 
        if vfs_file.get_uri_scheme() != 'file':
171
 
            return
172
 
 
173
 
        file = vfs_file.get_uri()
174
 
 
175
 
        # We only want to continue here if we get a NotBranchError
176
 
        try:
177
 
            tree, path = WorkingTree.open_containing(file)
178
 
        except NotBranchError:
179
 
            return
180
 
 
181
 
        from bzrlib.plugins.gtk.pull import PullDialog
182
 
        dialog = PullDialog(tree, path)
183
 
        dialog.display()
184
 
        gtk.main()
185
 
 
186
 
    def merge_cb(self, menu, vfs_file):
187
 
        # We can only cope with local files
188
 
        if vfs_file.get_uri_scheme() != 'file':
189
 
            return
190
 
 
191
 
        file = vfs_file.get_uri()
192
 
 
193
 
        # We only want to continue here if we get a NotBranchError
194
 
        try:
195
 
            tree, path = WorkingTree.open_containing(file)
196
 
        except NotBranchError:
197
 
            return
198
 
 
199
 
        from bzrlib.plugins.gtk.merge import MergeDialog
200
 
        dialog = MergeDialog(tree, path)
201
 
        dialog.display()
202
 
        gtk.main()
203
 
 
204
168
    def get_background_items(self, window, vfs_file):
205
 
        items = []
206
169
        file = vfs_file.get_uri()
207
170
        try:
208
171
            tree, path = WorkingTree.open_containing(file)
209
172
        except NotBranchError:
210
173
            item = nautilus.MenuItem('BzrNautilus::newtree',
211
 
                                 'Make directory versioned',
 
174
                                 'Create new Bazaar tree',
212
175
                                 'Create new Bazaar tree in this folder')
213
176
            item.connect('activate', self.newtree_cb, vfs_file)
214
177
            items.append(item)
215
178
 
216
179
            item = nautilus.MenuItem('BzrNautilus::clone',
217
 
                                 'Checkout Bazaar branch',
 
180
                                 'Checkout',
218
181
                                 'Checkout Existing Bazaar Branch')
219
182
            item.connect('activate', self.clone_cb, vfs_file)
220
183
            items.append(item)
221
184
 
222
185
            return items
223
186
 
 
187
        items = []
224
188
        item = nautilus.MenuItem('BzrNautilus::log',
225
189
                             'Log',
226
190
                             'Show Bazaar history')
227
191
        item.connect('activate', self.log_cb, vfs_file)
228
192
        items.append(item)
229
193
 
230
 
        item = nautilus.MenuItem('BzrNautilus::pull',
231
 
                             'Pull',
232
 
                             'Pull from another branch')
233
 
        item.connect('activate', self.pull_cb, vfs_file)
234
 
        items.append(item)
235
 
 
236
 
        item = nautilus.MenuItem('BzrNautilus::merge',
237
 
                             'Merge',
238
 
                             'Merge from another branch')
239
 
        item.connect('activate', self.merge_cb, vfs_file)
240
 
        items.append(item)
241
 
 
242
194
        item = nautilus.MenuItem('BzrNautilus::commit',
243
195
                             'Commit',
244
196
                             'Commit Changes')
263
215
                if not vfs_file.is_directory():
264
216
                    return
265
217
                item = nautilus.MenuItem('BzrNautilus::newtree',
266
 
                                     'Make directory versioned',
 
218
                                     'Create new Bazaar tree',
267
219
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
268
220
                item.connect('activate', self.newtree_cb, vfs_file)
269
221
                return item,
320
272
                items.append(item)
321
273
 
322
274
        return items
323
 
 
324
 
    def get_columns(self):
325
 
        return nautilus.Column("BzrNautilus::bzr_status",
326
 
                               "bzr_status",
327
 
                               "Bzr Status",
328
 
                               "Version control status"),
329
 
 
330
 
    def update_file_info(self, file):
331
 
        if file.get_uri_scheme() != 'file':
332
 
            return
333
 
        
334
 
        try:
335
 
            tree, path = WorkingTree.open_containing(file.get_uri())
336
 
        except NotBranchError:
337
 
            return
338
 
 
339
 
        emblem = None
340
 
        status = None
341
 
 
342
 
        if tree.has_filename(path):
343
 
            emblem = 'cvs-controlled'
344
 
            status = 'unchanged'
345
 
            id = tree.path2id(path)
346
 
 
347
 
            delta = tree.changes_from(tree.branch.basis_tree())
348
 
            if delta.touches_file_id(id):
349
 
                emblem = 'cvs-modified'
350
 
                status = 'modified'
351
 
            for f, _, _ in delta.added:
352
 
                if f == path:
353
 
                    emblem = 'cvs-added'
354
 
                    status = 'added'
355
 
 
356
 
            for of, f, _, _, _, _ in delta.renamed:
357
 
                if f == path:
358
 
                    status = 'renamed from %s' % f
359
 
 
360
 
        elif tree.branch.basis_tree().has_filename(path):
361
 
            emblem = 'cvs-removed'
362
 
            status = 'removed'
363
 
        else:
364
 
            # FIXME: Check for ignored files
365
 
            status = 'unversioned'
366
 
        
367
 
        if emblem is not None:
368
 
            file.add_emblem(emblem)
369
 
        file.add_string_attribute('bzr_status', status)