/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 olive/menu.py

  • Committer: Jelmer Vernooij
  • Date: 2007-03-09 17:47:28 UTC
  • Revision ID: jelmer@samba.org-20070309174728-gljlmt9b7fu0rrn9
Add simple test for tortoise_bzr

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
 
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
 
        if sys.platform == 'win32':
40
 
            self.uifile = os.path.dirname(sys.executable) + "/share/olive/cmenu.ui"
41
 
        else:
42
 
            self.uifile = "/usr/share/olive/cmenu.ui"
43
 
        
44
 
        if not os.path.exists(self.uifile):
45
 
            # Load from current directory if not installed
46
 
            self.uifile = "cmenu.ui"
47
 
            # Check again
48
 
            if not os.path.exists(self.uifile):
49
 
                # Fail
50
 
                print _('UI description file cannot be found.')
51
 
                sys.exit(1)
52
 
        
 
40
        from guifiles import UIFILENAME
 
41
 
 
42
        self.uifile = UIFILENAME
 
43
 
53
44
        # Preferences handler
54
 
        self.pref = OlivePreferences()
 
45
        self.pref = Preferences()
55
46
        
56
47
        # Set default values
57
48
        self.path = path
58
49
        self.selected = selected
 
50
        self.app = app
59
51
        
60
52
        # Create the file list context menu
61
53
        self.ui = gtk.UIManager()
69
61
                                       _('Remove'), None,
70
62
                                       _('Remove the selected file'),
71
63
                                       self.remove_file),
 
64
                                      ('rename', None,
 
65
                                       _('Rename'), None,
 
66
                                       _('Rename the selected file'),
 
67
                                       self.rename_file),
72
68
                                      ('open', gtk.STOCK_OPEN,
73
69
                                       _('Open'), None,
74
70
                                       _('Open the selected file'),
75
71
                                       self.open_file),
 
72
                                      ('revert', None,
 
73
                                       _('Revert'), None,
 
74
                                       _('Revert the changes'),
 
75
                                       self.revert),
76
76
                                      ('commit', None,
77
77
                                       _('Commit'), None,
78
78
                                       _('Commit the changes'),
135
135
    def left_context_menu(self):
136
136
        return self.cmenu_left
137
137
    
 
138
    @show_bzr_error
138
139
    def add_file(self, action):
139
140
        """ Right context menu -> Add """
140
141
        import bzrlib.add
148
149
                         _('Please select a file from the list,\nor choose the other option.'))
149
150
            return
150
151
        
151
 
        try:
152
 
            bzrlib.add.smart_add([directory + '/' + filename])
153
 
        except errors.NotBranchError:
154
 
            error_dialog(_('Directory is not a branch'),
155
 
                         _('You can perform this action only in a branch.'))
156
 
            return
 
152
        bzrlib.add.smart_add([os.path.join(directory, filename)])
157
153
    
 
154
    @show_bzr_error
158
155
    def remove_file(self, action):
159
156
        """ Right context menu -> Remove """
160
157
        # Remove only the selected file
166
163
                         _('Please select a file from the list,\nor choose the other option.'))
167
164
            return
168
165
        
169
 
        try:
170
 
            wt, path = WorkingTree.open_containing(directory + os.sep + filename)
171
 
            wt.remove(path)
172
 
 
173
 
        except errors.NotBranchError:
174
 
            error_dialog(_('Directory is not a branch'),
175
 
                         _('You can perform this action only in a branch.'))
176
 
            return
177
 
        except errors.NotVersionedError:
178
 
            error_dialog(_('File not versioned'),
179
 
                         _('The selected file is not versioned.'))
180
 
            return
181
 
 
 
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()
 
170
 
 
171
    def rename_file(self, action):
 
172
        """ Right context menu -> Rename """
 
173
        from rename import OliveRename
 
174
        wt = WorkingTree.open_containing(self.path + os.sep + self.selected)[0]
 
175
        rename = OliveRename(wt, wt.relpath(self.path), self.selected)
 
176
        rename.display()
 
177
    
182
178
    def open_file(self, action):
183
179
        """ Right context menu -> Open """
184
180
        # Open only the selected file
201
197
            else:
202
198
                launch(fullpath) 
203
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
    
204
212
    def commit(self, action):
205
213
        """ Right context menu -> Commit """
206
214
        from commit import CommitDialog
207
 
        wt, path = WorkingTree.open_containing(self.path)
208
 
        commit = CommitDialog(wt, path)
209
 
        commit.display()
 
215
        branch = None
 
216
        try:
 
217
            wt, path = WorkingTree.open_containing(self.path)
 
218
            branch = wt.branch
 
219
        except NotBranchError, e:
 
220
            path = e.path
 
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()
210
231
    
 
232
    @show_bzr_error
211
233
    def diff(self, action):
212
234
        """ Right context menu -> Diff """
213
 
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
214
 
        
215
 
        try:
216
 
            wt = WorkingTree.open_containing(self.path)[0]
217
 
        except errors.NotBranchError:
218
 
            error_dialog(_('File is not in a branch'),
219
 
                         _('The selected file is not in a branch.'))
220
 
            return
221
 
        
 
235
        wt = WorkingTree.open_containing(self.path)[0]
222
236
        window = DiffWindow()
223
237
        parent_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
224
238
        window.set_diff(wt.branch.nick, wt, parent_tree)
 
239
        window.set_file(wt.relpath(self.path + os.sep + self.selected))
225
240
        window.show()
226
241
    
227
242
    def bookmark(self, action):
233
248
        else:
234
249
            warning_dialog(_('Location already bookmarked'),
235
250
                           _('The current directory is already bookmarked.\nSee the left panel for reference.'))
 
251
        
 
252
        self.app.refresh_left()
236
253
 
237
254
    def edit_bookmark(self, action):
238
255
        """ Left context menu -> Edit """
239
 
        from bookmark import OliveBookmark
240
 
 
 
256
        from bookmark import BookmarkDialog
 
257
        
241
258
        if self.selected != None:
242
 
            bookmark = OliveBookmark(self.selected)
243
 
            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()
244
269
 
245
270
    def remove_bookmark(self, action):
246
271
        """ Left context menu -> Remove """
247
272
        
248
273
        if self.selected != None:
249
 
            self.pref.remove_bookmark(self.comm.get_selected_left())
250
 
            self.comm.refresh_left()
 
274
            self.pref.remove_bookmark(self.selected)
 
275
            self.pref.write()
 
276
        
 
277
        self.app.refresh_left()
251
278
    
252
279
    def open_folder(self, action):
253
280
        """ Left context menu -> Open Folder """