/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
import nautilus
 
2
import bzrlib
 
3
from bzrlib.bzrdir import BzrDir
 
4
from bzrlib.errors import NotBranchError
 
5
from bzrlib.workingtree import WorkingTree
 
6
 
 
7
from bzrlib.plugin import load_plugins
 
8
load_plugins()
 
9
 
 
10
from bzrlib.plugins.gtk import cmd_visualise, cmd_gannotate
 
11
 
 
12
class BzrExtension(nautilus.MenuProvider):
 
13
    def __init__(self):
 
14
        pass
 
15
 
 
16
    def add_cb(self, menu, vfs_file):
 
17
        # We can only cope with local files
 
18
        if vfs_file.get_uri_scheme() != 'file':
 
19
            return
 
20
 
 
21
        file = vfs_file.get_uri()
 
22
        try:
 
23
            tree, path = WorkingTree.open_containing(file)
 
24
        except NotBranchError:
 
25
            return
 
26
 
 
27
        tree.add(path)
 
28
 
 
29
        return
 
30
 
 
31
    def ignore_cb(self, menu, vfs_file):
 
32
        # We can only cope with local files
 
33
        if vfs_file.get_uri_scheme() != 'file':
 
34
            return
 
35
 
 
36
        file = vfs_file.get_uri()
 
37
        try:
 
38
            tree, path = WorkingTree.open_containing(file)
 
39
        except NotBranchError:
 
40
            return
 
41
 
 
42
        #FIXME
 
43
 
 
44
        return
 
45
 
 
46
    def unignore_cb(self, menu, vfs_file):
 
47
        # We can only cope with local files
 
48
        if vfs_file.get_uri_scheme() != 'file':
 
49
            return
 
50
 
 
51
        file = vfs_file.get_uri()
 
52
        try:
 
53
            tree, path = WorkingTree.open_containing(file)
 
54
        except NotBranchError:
 
55
            return
 
56
 
 
57
        #FIXME
 
58
 
 
59
        return
 
60
 
 
61
    def diff_cb(self, menu, vfs_file):
 
62
        # We can only cope with local files
 
63
        if vfs_file.get_uri_scheme() != 'file':
 
64
            return
 
65
 
 
66
        file = vfs_file.get_uri()
 
67
        try:
 
68
            tree, path = WorkingTree.open_containing(file)
 
69
        except NotBranchError:
 
70
            return
 
71
 
 
72
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
 
73
        window = DiffWindow()
 
74
        window.set_diff(tree.branch, tree, tree.branch.revision_tree())
 
75
        window.show()
 
76
 
 
77
        return
 
78
 
 
79
    def newtree_cb(self, menu, vfs_file):
 
80
        # We can only cope with local files
 
81
        if vfs_file.get_uri_scheme() != 'file':
 
82
            return
 
83
 
 
84
        file = vfs_file.get_uri()
 
85
 
 
86
        # We only want to continue here if we get a NotBranchError
 
87
        try:
 
88
            tree, path = WorkingTree.open_containing(file)
 
89
        except NotBranchError:
 
90
            BzrDir.create_branch_and_repo(file)
 
91
 
 
92
    def remove_cb(self, menu, vfs_file):
 
93
        # We can only cope with local files
 
94
        if vfs_file.get_uri_scheme() != 'file':
 
95
            return
 
96
 
 
97
        file = vfs_file.get_uri()
 
98
        try:
 
99
            tree, path = WorkingTree.open_containing(file)
 
100
        except NotBranchError:
 
101
            return
 
102
 
 
103
        tree.remove(path)
 
104
 
 
105
    def annotate_cb(self, menu, vfs_file):
 
106
        # We can only cope with local files
 
107
        if vfs_file.get_uri_scheme() != 'file':
 
108
            return
 
109
 
 
110
        file = vfs_file.get_uri()
 
111
 
 
112
        vis = cmd_gannotate()
 
113
        vis.run(file)
 
114
 
 
115
    def clone_cb(self, menu, vfs_file=None):
 
116
        # We can only cope with local files
 
117
        if vfs_file.get_uri_scheme() != 'file':
 
118
            return
 
119
 
 
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
 
 
132
    def commit_cb(self, menu, vfs_file=None):
 
133
        # We can only cope with local files
 
134
        if vfs_file.get_uri_scheme() != 'file':
 
135
            return
 
136
 
 
137
        file = vfs_file.get_uri()
 
138
        try:
 
139
            tree, path = WorkingTree.open_containing(file)
 
140
        except NotBranchError:
 
141
            return
 
142
 
 
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
 
 
150
    def log_cb(self, menu, vfs_file):
 
151
        # We can only cope with local files
 
152
        if vfs_file.get_uri_scheme() != 'file':
 
153
            return
 
154
 
 
155
        file = vfs_file.get_uri()
 
156
 
 
157
        # We only want to continue here if we get a NotBranchError
 
158
        try:
 
159
            tree, path = WorkingTree.open_containing(file)
 
160
        except NotBranchError:
 
161
            return
 
162
 
 
163
        vis = cmd_visualise()
 
164
        vis.run(file)
 
165
 
 
166
        return
 
167
 
 
168
    def get_background_items(self, window, vfs_file):
 
169
        file = vfs_file.get_uri()
 
170
        try:
 
171
            tree, path = WorkingTree.open_containing(file)
 
172
        except NotBranchError:
 
173
            item = nautilus.MenuItem('BzrNautilus::newtree',
 
174
                                 'Create new Bazaar tree',
 
175
                                 'Create new Bazaar tree in this folder')
 
176
            item.connect('activate', self.newtree_cb, vfs_file)
 
177
            items.append(item)
 
178
 
 
179
            item = nautilus.MenuItem('BzrNautilus::clone',
 
180
                                 'Checkout',
 
181
                                 'Checkout Existing Bazaar Branch')
 
182
            item.connect('activate', self.clone_cb, vfs_file)
 
183
            items.append(item)
 
184
 
 
185
            return items
 
186
 
 
187
        items = []
 
188
        item = nautilus.MenuItem('BzrNautilus::log',
 
189
                             'Log',
 
190
                             'Show Bazaar history')
 
191
        item.connect('activate', self.log_cb, vfs_file)
 
192
        items.append(item)
 
193
 
 
194
        item = nautilus.MenuItem('BzrNautilus::commit',
 
195
                             'Commit',
 
196
                             'Commit Changes')
 
197
        item.connect('activate', self.commit_cb, vfs_file)
 
198
        items.append(item)
 
199
 
 
200
        return items
 
201
 
 
202
 
 
203
    def get_file_items(self, window, files):
 
204
        items = []
 
205
 
 
206
        for vfs_file in files:
 
207
            # We can only cope with local files
 
208
            if vfs_file.get_uri_scheme() != 'file':
 
209
                return
 
210
 
 
211
            file = vfs_file.get_uri()
 
212
            try:
 
213
                tree, path = WorkingTree.open_containing(file)
 
214
            except NotBranchError:
 
215
                if not vfs_file.is_directory():
 
216
                    return
 
217
                item = nautilus.MenuItem('BzrNautilus::newtree',
 
218
                                     'Create new Bazaar tree',
 
219
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
 
220
                item.connect('activate', self.newtree_cb, vfs_file)
 
221
                return item,
 
222
 
 
223
            file_class = tree.file_class(path)
 
224
 
 
225
            if file_class == '?':
 
226
                item = nautilus.MenuItem('BzrNautilus::add',
 
227
                                     'Add',
 
228
                                     'Add as versioned file')
 
229
                item.connect('activate', self.add_cb, vfs_file)
 
230
                items.append(item)
 
231
 
 
232
                item = nautilus.MenuItem('BzrNautilus::ignore',
 
233
                                     'Ignore',
 
234
                                     'Ignore file for versioning')
 
235
                item.connect('activate', self.ignore_cb, vfs_file)
 
236
                items.append(item)
 
237
            elif file_class == 'I':
 
238
                item = nautilus.MenuItem('BzrNautilus::unignore',
 
239
                                     'Unignore',
 
240
                                     'Unignore file for versioning')
 
241
                item.connect('activate', self.unignore_cb, vfs_file)
 
242
                items.append(item)
 
243
            elif file_class == 'V':
 
244
                item = nautilus.MenuItem('BzrNautilus::log',
 
245
                                 'Log',
 
246
                                 'List changes')
 
247
                item.connect('activate', self.log_cb, vfs_file)
 
248
                items.append(item)
 
249
 
 
250
                item = nautilus.MenuItem('BzrNautilus::diff',
 
251
                                 'Diff',
 
252
                                 'Show differences')
 
253
                item.connect('activate', self.diff_cb, vfs_file)
 
254
                items.append(item)
 
255
 
 
256
                item = nautilus.MenuItem('BzrNautilus::remove',
 
257
                                     'Remove',
 
258
                                     'Remove this file from versioning')
 
259
                item.connect('activate', self.remove_cb, vfs_file)
 
260
                items.append(item)
 
261
 
 
262
                item = nautilus.MenuItem('BzrNautilus::annotate',
 
263
                             'Annotate',
 
264
                             'Annotate File Data')
 
265
                item.connect('activate', self.annotate_cb, vfs_file)
 
266
                items.append(item)
 
267
 
 
268
                item = nautilus.MenuItem('BzrNautilus::commit',
 
269
                             'Commit',
 
270
                             'Commit Changes')
 
271
                item.connect('activate', self.commit_cb, vfs_file)
 
272
                items.append(item)
 
273
 
 
274
        return items