/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-05-20 16:05:21 UTC
  • mto: This revision was merged to the branch mainline in revision 80.
  • Revision ID: jelmer@samba.org-20060520160521-f0d266f204d4bfc1
Add 'Commit' entries

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