/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: Aaron Bentley
  • Date: 2008-02-23 06:39:14 UTC
  • Revision ID: aaron@aaronbentley.com-20080223063914-49gdt7ed630rug9b
Add handle-patch script

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
6
18
from bzrlib.tree import file_status
7
19
 
8
20
from bzrlib.plugin import load_plugins
70
82
        except NotBranchError:
71
83
            return
72
84
 
73
 
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
 
85
        from bzrlib.plugins.gtk.diff import DiffWindow
74
86
        window = DiffWindow()
75
87
        window.set_diff(tree.branch.nick, tree, tree.branch.basis_tree())
76
88
        window.show()
88
100
        try:
89
101
            tree, path = WorkingTree.open_containing(file)
90
102
        except NotBranchError:
91
 
            BzrDir.create_branch_and_repo(file)
 
103
            BzrDir.create_standalone_workingtree(file)
92
104
 
93
105
    def remove_cb(self, menu, vfs_file):
94
106
        # We can only cope with local files
118
130
        if vfs_file.get_uri_scheme() != 'file':
119
131
            return
120
132
 
121
 
        from bzrlib.plugins.gtk.olive.branch import BranchDialog
 
133
        from bzrlib.plugins.gtk.branch import BranchDialog
122
134
        
123
135
        dialog = BranchDialog(vfs_file.get_name())
124
 
        dialog.display()
 
136
        response = dialog.run()
 
137
        if response != gtk.RESPONSE_NONE:
 
138
            dialog.hide()
 
139
            dialog.destroy()
125
140
 
126
141
    def commit_cb(self, menu, vfs_file=None):
127
142
        # We can only cope with local files
129
144
            return
130
145
 
131
146
        file = vfs_file.get_uri()
 
147
        tree = None
 
148
        branch = None
132
149
        try:
133
150
            tree, path = WorkingTree.open_containing(file)
134
 
        except NotBranchError:
135
 
            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
136
161
 
137
 
        from bzrlib.plugins.gtk.olive.commit import CommitDialog
138
 
        dialog = CommitDialog(tree, path)
139
 
        dialog.display()
140
 
        gtk.main()
 
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()
141
168
 
142
169
    def log_cb(self, menu, vfs_file):
143
170
        # We can only cope with local files
157
184
 
158
185
        return
159
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
 
160
223
    def get_background_items(self, window, vfs_file):
161
224
        items = []
162
225
        file = vfs_file.get_uri()
163
226
        try:
164
227
            tree, path = WorkingTree.open_containing(file)
 
228
        except UnsupportedProtocol:
 
229
            return
165
230
        except NotBranchError:
166
231
            item = nautilus.MenuItem('BzrNautilus::newtree',
167
232
                                 'Make directory versioned',
183
248
        item.connect('activate', self.log_cb, vfs_file)
184
249
        items.append(item)
185
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
 
186
263
        item = nautilus.MenuItem('BzrNautilus::commit',
187
264
                             'Commit',
188
265
                             'Commit Changes')
195
272
    def get_file_items(self, window, files):
196
273
        items = []
197
274
 
 
275
        wtfiles = {}
198
276
        for vfs_file in files:
199
277
            # We can only cope with local files
200
278
            if vfs_file.get_uri_scheme() != 'file':
211
289
                                     'Create new Bazaar tree in %s' % vfs_file.get_name())
212
290
                item.connect('activate', self.newtree_cb, vfs_file)
213
291
                return item,
214
 
 
215
 
            file_class = tree.file_class(path)
216
 
 
217
 
            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] == '?':
218
301
                item = nautilus.MenuItem('BzrNautilus::add',
219
302
                                     'Add',
220
303
                                     'Add as versioned file')
226
309
                                     'Ignore file for versioning')
227
310
                item.connect('activate', self.ignore_cb, vfs_file)
228
311
                items.append(item)
229
 
            elif file_class == 'I':
 
312
            elif wtfiles[path] == 'I':
230
313
                item = nautilus.MenuItem('BzrNautilus::unignore',
231
314
                                     'Unignore',
232
315
                                     'Unignore file for versioning')
233
316
                item.connect('activate', self.unignore_cb, vfs_file)
234
317
                items.append(item)
235
 
            elif file_class == 'V':
 
318
            elif wtfiles[path] == 'V':
236
319
                item = nautilus.MenuItem('BzrNautilus::log',
237
320
                                 'Log',
238
321
                                 'List changes')