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