~ubuntu-branches/ubuntu/feisty/bzr-gtk/feisty

« back to all changes in this revision

Viewing changes to olive/menu.py

  • Committer: Bazaar Package Importer
  • Author(s): Etienne Goyer
  • Date: 2007-03-09 13:50:53 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070309135053-rdmh5yk3hgapkir7
Tags: 0.15.0-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import bzrlib.errors as errors
29
29
from bzrlib.workingtree import WorkingTree
30
30
 
31
 
from dialog import error_dialog, info_dialog, warning_dialog
 
31
from bzrlib.plugins.gtk.dialog import error_dialog, info_dialog, warning_dialog
 
32
from errors import show_bzr_error
32
33
from launch import launch
33
 
from olive import OlivePreferences, DiffWindow
 
34
from olive import Preferences, DiffWindow
34
35
 
35
36
class OliveMenu:
36
37
    """ This class is responsible for building the context menus. """
37
 
    def __init__(self, path, selected):
 
38
    def __init__(self, path, selected, app=None):
38
39
        # Load the UI file
39
40
        from guifiles import UIFILENAME
40
41
 
41
42
        self.uifile = UIFILENAME
42
43
 
43
44
        # Preferences handler
44
 
        self.pref = OlivePreferences()
 
45
        self.pref = Preferences()
45
46
        
46
47
        # Set default values
47
48
        self.path = path
48
49
        self.selected = selected
 
50
        self.app = app
49
51
        
50
52
        # Create the file list context menu
51
53
        self.ui = gtk.UIManager()
67
69
                                       _('Open'), None,
68
70
                                       _('Open the selected file'),
69
71
                                       self.open_file),
 
72
                                      ('revert', None,
 
73
                                       _('Revert'), None,
 
74
                                       _('Revert the changes'),
 
75
                                       self.revert),
70
76
                                      ('commit', None,
71
77
                                       _('Commit'), None,
72
78
                                       _('Commit the changes'),
129
135
    def left_context_menu(self):
130
136
        return self.cmenu_left
131
137
    
 
138
    @show_bzr_error
132
139
    def add_file(self, action):
133
140
        """ Right context menu -> Add """
134
141
        import bzrlib.add
142
149
                         _('Please select a file from the list,\nor choose the other option.'))
143
150
            return
144
151
        
145
 
        try:
146
 
            bzrlib.add.smart_add([os.path.join(directory, filename)])
147
 
        except errors.NotBranchError:
148
 
            error_dialog(_('Directory is not a branch'),
149
 
                         _('You can perform this action only in a branch.'))
150
 
            return
 
152
        bzrlib.add.smart_add([os.path.join(directory, filename)])
151
153
    
 
154
    @show_bzr_error
152
155
    def remove_file(self, action):
153
156
        """ Right context menu -> Remove """
154
157
        # Remove only the selected file
160
163
                         _('Please select a file from the list,\nor choose the other option.'))
161
164
            return
162
165
        
163
 
        try:
164
 
            wt, path = WorkingTree.open_containing(directory + os.sep + filename)
165
 
            wt.remove(path)
166
 
 
167
 
        except errors.NotBranchError:
168
 
            error_dialog(_('Directory is not a branch'),
169
 
                         _('You can perform this action only in a branch.'))
170
 
            return
171
 
        except errors.NotVersionedError:
172
 
            error_dialog(_('File not versioned'),
173
 
                         _('The selected file is not versioned.'))
174
 
            return
 
166
        wt, path = WorkingTree.open_containing(os.path.join(directory, filename))
 
167
        wt.remove(path)
 
168
        self.app.set_path(self.path)
 
169
        self.app.refresh_right()
175
170
 
176
171
    def rename_file(self, action):
177
172
        """ Right context menu -> Rename """
202
197
            else:
203
198
                launch(fullpath) 
204
199
 
 
200
    def revert(self, action):
 
201
        """ Right context menu -> Revert """
 
202
        wt, path = WorkingTree.open_containing(self.path)
 
203
        ret = wt.revert([os.path.join(path, self.selected)])
 
204
        if ret:
 
205
            warning_dialog(_('Conflicts detected'),
 
206
                           _('Please have a look at the working tree before continuing.'))
 
207
        else:
 
208
            info_dialog(_('Revert successful'),
 
209
                        _('All files reverted to last revision.'))
 
210
        self.app.refresh_right()       
 
211
    
205
212
    def commit(self, action):
206
213
        """ Right context menu -> Commit """
207
214
        from commit import CommitDialog
211
218
            branch = wt.branch
212
219
        except NotBranchError, e:
213
220
            path = e.path
214
 
        commit = CommitDialog(wt, path, not branch)
215
 
        commit.display()
 
221
        
 
222
        commit = CommitDialog(wt, path, not branch, self.selected)
 
223
        response = commit.run()
 
224
        if response != gtk.RESPONSE_NONE:
 
225
            commit.hide()
 
226
        
 
227
            if response == gtk.RESPONSE_OK:
 
228
                self.app.refresh_right()
 
229
            
 
230
            commit.destroy()
216
231
    
 
232
    @show_bzr_error
217
233
    def diff(self, action):
218
234
        """ Right context menu -> Diff """
219
 
        try:
220
 
            wt = WorkingTree.open_containing(self.path)[0]
221
 
        except errors.NotBranchError:
222
 
            error_dialog(_('File is not in a branch'),
223
 
                         _('The selected file is not in a branch.'))
224
 
            return
225
 
        
 
235
        wt = WorkingTree.open_containing(self.path)[0]
226
236
        window = DiffWindow()
227
237
        parent_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
228
238
        window.set_diff(wt.branch.nick, wt, parent_tree)
229
 
        try:
230
 
            window.set_file(wt.relpath(self.path + os.sep + self.selected))
231
 
        except errors.NoSuchFile:
232
 
            pass
 
239
        window.set_file(wt.relpath(self.path + os.sep + self.selected))
233
240
        window.show()
234
241
    
235
242
    def bookmark(self, action):
241
248
        else:
242
249
            warning_dialog(_('Location already bookmarked'),
243
250
                           _('The current directory is already bookmarked.\nSee the left panel for reference.'))
 
251
        
 
252
        self.app.refresh_left()
244
253
 
245
254
    def edit_bookmark(self, action):
246
255
        """ Left context menu -> Edit """
247
 
        from bookmark import OliveBookmark
248
 
 
 
256
        from bookmark import BookmarkDialog
 
257
        
249
258
        if self.selected != None:
250
 
            bookmark = OliveBookmark(self.selected)
251
 
            bookmark.display()
 
259
            bookmark = BookmarkDialog(self.selected, self.app.window)
 
260
            response = bookmark.run()
 
261
            
 
262
            if response != gtk.RESPONSE_NONE:
 
263
                bookmark.hide()
 
264
        
 
265
                if response == gtk.RESPONSE_OK:
 
266
                    self.app.refresh_left()
 
267
            
 
268
                bookmark.destroy()
252
269
 
253
270
    def remove_bookmark(self, action):
254
271
        """ Left context menu -> Remove """
256
273
        if self.selected != None:
257
274
            self.pref.remove_bookmark(self.selected)
258
275
            self.pref.write()
 
276
        
 
277
        self.app.refresh_left()
259
278
    
260
279
    def open_folder(self, action):
261
280
        """ Left context menu -> Open Folder """