/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 bzrlib.plugins.gtk.errors import show_bzr_error
33
 
from bzrlib.plugins.gtk.annotate.gannotate import GAnnotateWindow
34
 
from bzrlib.plugins.gtk.annotate.config import GAnnotateConfig
35
 
from bzrlib.plugins.gtk.diff import DiffWindow
 
31
from dialog import error_dialog, info_dialog, warning_dialog
36
32
from launch import launch
37
 
from olive import Preferences
 
33
from olive import OlivePreferences
38
34
 
39
35
class OliveMenu:
40
36
    """ This class is responsible for building the context menus. """
41
 
    def __init__(self, path, selected, app=None):
 
37
    def __init__(self, path, selected):
42
38
        # Load the UI file
43
 
        from guifiles import UIFILENAME
44
 
 
45
 
        self.uifile = UIFILENAME
46
 
 
 
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
        
47
53
        # Preferences handler
48
 
        self.pref = Preferences()
 
54
        self.pref = OlivePreferences()
49
55
        
50
56
        # Set default values
51
57
        self.path = path
52
58
        self.selected = selected
53
 
        self.app = app
 
59
        print "DEBUG: path =", self.path
 
60
        print "DEBUG: selected =", self.selected
54
61
        
55
62
        # Create the file list context menu
56
63
        self.ui = gtk.UIManager()
64
71
                                       _('Remove'), None,
65
72
                                       _('Remove the selected file'),
66
73
                                       self.remove_file),
67
 
                                      ('rename', None,
68
 
                                       _('Rename'), None,
69
 
                                       _('Rename the selected file'),
70
 
                                       self.rename_file),
71
74
                                      ('open', gtk.STOCK_OPEN,
72
75
                                       _('Open'), None,
73
76
                                       _('Open the selected file'),
74
77
                                       self.open_file),
75
 
                                      ('revert', None,
76
 
                                       _('Revert'), None,
77
 
                                       _('Revert the changes'),
78
 
                                       self.revert),
79
78
                                      ('commit', None,
80
79
                                       _('Commit'), None,
81
80
                                       _('Commit the changes'),
82
81
                                       self.commit),
83
 
                                      ('annotate', None,
84
 
                                       _('Annotate'), None,
85
 
                                       _('Annotate the selected file'),
86
 
                                       self.annotate),
87
82
                                      ('diff', None,
88
83
                                       _('Diff'), None,
89
84
                                       _('Show the diff of the file'),
111
106
                                      ('diff_all', None,
112
107
                                       _('All...'), None,
113
108
                                       _('Show the differences of all files'),
114
 
                                       self.diff_all),
115
 
                                      ('view_remote', None,
116
 
                                       _('View contents'), None,
117
 
                                       _('View the contents of the file in a builtin viewer'),
118
 
                                       self.view_remote),
119
 
                                      ('diff_remote', None,
120
 
                                       _('Show differences'), None,
121
 
                                       _('Show the differences between two revisions of the file'),
122
 
                                       self.diff_remote),
123
 
                                      ('revert_remote', None,
124
 
                                       _('Revert to this revision'), None,
125
 
                                       _('Revert the selected file to the selected revision'),
126
 
                                       self.revert_remote)
 
109
                                       self.diff_all)
127
110
                                     ])
128
111
        
129
112
        self.ui.insert_action_group(self.actiongroup, 0)
132
115
        self.cmenu_right = self.ui.get_widget('/context_right')
133
116
        self.cmenu_left = self.ui.get_widget('/context_left')
134
117
        self.toolbar_diff = self.ui.get_widget('/toolbar_diff')
135
 
        self.cmenu_remote = self.ui.get_widget('/context_remote')
136
118
        
137
119
        # Set icons
138
120
        # TODO: do it without using deprecated comm
155
137
    def left_context_menu(self):
156
138
        return self.cmenu_left
157
139
    
158
 
    def remote_context_menu(self):
159
 
        return self.cmenu_remote
160
 
    
161
 
    @show_bzr_error
162
140
    def add_file(self, action):
163
141
        """ Right context menu -> Add """
164
142
        import bzrlib.add
172
150
                         _('Please select a file from the list,\nor choose the other option.'))
173
151
            return
174
152
        
175
 
        bzrlib.add.smart_add([os.path.join(directory, filename)])
176
 
    
177
 
    @show_bzr_error
178
 
    def annotate(self, action):
179
 
        """ Right context menu -> Annotate """
180
 
        directory = self.path
181
 
        filename = self.selected
182
 
        
183
 
        if filename is None:
184
 
            error_dialog(_('No file was selected'),
185
 
                         _('Please select a file from the list.'))
186
 
            return
187
 
        
188
 
        wt, path = WorkingTree.open_containing(os.path.join(directory, filename))
189
 
        
190
 
        branch = wt.branch
191
 
        file_id = wt.path2id(wt.relpath(os.path.join(directory, filename)))
192
 
        
193
 
        window = GAnnotateWindow(all=False, plain=False)
194
 
        window.set_title(os.path.join(directory, filename) + " - Annotate")
195
 
        config = GAnnotateConfig(window)
196
 
        window.show()
197
 
        branch.lock_read()
198
153
        try:
199
 
            window.annotate(wt, branch, file_id)
200
 
        finally:
201
 
            branch.unlock()
 
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
202
159
    
203
 
    @show_bzr_error
204
160
    def remove_file(self, action):
205
161
        """ Right context menu -> Remove """
206
162
        # Remove only the selected file
212
168
                         _('Please select a file from the list,\nor choose the other option.'))
213
169
            return
214
170
        
215
 
        wt, path = WorkingTree.open_containing(os.path.join(directory, filename))
216
 
        wt.remove(path)
217
 
        self.app.set_path(self.path)
218
 
        self.app.refresh_right()
219
 
 
220
 
    def rename_file(self, action):
221
 
        """ Right context menu -> Rename """
222
 
        from rename import OliveRename
223
 
        wt = WorkingTree.open_containing(self.path + os.sep + self.selected)[0]
224
 
        rename = OliveRename(wt, wt.relpath(self.path), self.selected)
225
 
        rename.display()
226
 
    
 
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
 
227
184
    def open_file(self, action):
228
185
        """ Right context menu -> Open """
229
186
        # Open only the selected file
246
203
            else:
247
204
                launch(fullpath) 
248
205
 
249
 
    def revert(self, action):
250
 
        """ Right context menu -> Revert """
251
 
        wt, path = WorkingTree.open_containing(self.path)
252
 
        ret = wt.revert([os.path.join(path, self.selected)])
253
 
        if ret:
254
 
            warning_dialog(_('Conflicts detected'),
255
 
                           _('Please have a look at the working tree before continuing.'))
256
 
        else:
257
 
            info_dialog(_('Revert successful'),
258
 
                        _('All files reverted to last revision.'))
259
 
        self.app.refresh_right()       
260
 
    
261
206
    def commit(self, action):
262
207
        """ Right context menu -> Commit """
263
 
        from commit import CommitDialog
264
 
        branch = None
265
 
        try:
266
 
            wt, path = WorkingTree.open_containing(self.path)
267
 
            branch = wt.branch
268
 
        except NotBranchError, e:
269
 
            path = e.path
270
 
        
271
 
        commit = CommitDialog(wt, path, not branch, self.selected)
272
 
        response = commit.run()
273
 
        if response != gtk.RESPONSE_NONE:
274
 
            commit.hide()
275
 
        
276
 
            if response == gtk.RESPONSE_OK:
277
 
                self.app.refresh_right()
278
 
            
279
 
            commit.destroy()
 
208
        from commit import OliveCommit
 
209
        wt, path = WorkingTree.open_containing(self.path)
 
210
        commit = OliveCommit(wt, path)
 
211
        commit.display()
280
212
    
281
 
    @show_bzr_error
282
213
    def diff(self, action):
283
214
        """ Right context menu -> Diff """
284
 
        wt = WorkingTree.open_containing(self.path)[0]
285
 
        window = DiffWindow()
286
 
        parent_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
287
 
        window.set_diff(wt.branch.nick, wt, parent_tree)
288
 
        window.set_file(wt.relpath(self.path + os.sep + self.selected))
289
 
        window.show()
 
215
        from diff import OliveDiff
 
216
        diff = OliveDiff(self.comm)
 
217
        diff.display()
290
218
    
291
219
    def bookmark(self, action):
292
220
        """ Right context menu -> Bookmark """
293
 
        if self.pref.add_bookmark(self.path):
 
221
        if self.pref.add_bookmark(self.comm.get_path()):
294
222
            info_dialog(_('Bookmark successfully added'),
295
223
                        _('The current directory was bookmarked. You can reach\nit by selecting it from the left panel.'))
296
 
            self.pref.write()
297
224
        else:
298
225
            warning_dialog(_('Location already bookmarked'),
299
226
                           _('The current directory is already bookmarked.\nSee the left panel for reference.'))
300
 
        
301
 
        self.app.refresh_left()
302
227
 
303
228
    def edit_bookmark(self, action):
304
229
        """ Left context menu -> Edit """
305
 
        from bookmark import BookmarkDialog
306
 
        
 
230
        from bookmark import OliveBookmark
 
231
 
307
232
        if self.selected != None:
308
 
            bookmark = BookmarkDialog(self.selected, self.app.window)
309
 
            response = bookmark.run()
310
 
            
311
 
            if response != gtk.RESPONSE_NONE:
312
 
                bookmark.hide()
313
 
        
314
 
                if response == gtk.RESPONSE_OK:
315
 
                    self.app.refresh_left()
316
 
            
317
 
                bookmark.destroy()
 
233
            bookmark = OliveBookmark(self.selected)
 
234
            bookmark.display()
318
235
 
319
236
    def remove_bookmark(self, action):
320
237
        """ Left context menu -> Remove """
321
238
        
322
239
        if self.selected != None:
323
 
            self.pref.remove_bookmark(self.selected)
324
 
            self.pref.write()
325
 
        
326
 
        self.app.refresh_left()
 
240
            self.pref.remove_bookmark(self.comm.get_selected_left())
 
241
            self.comm.refresh_left()
327
242
    
328
243
    def open_folder(self, action):
329
244
        """ Left context menu -> Open Folder """
341
256
        from diff import OliveDiff
342
257
        diff = OliveDiff(self.comm)
343
258
        diff.display()
344
 
    
345
 
    def view_remote(self, action):
346
 
        """ Remote context menu -> View contents """
347
 
        print "DEBUG: view contents."
348
 
    
349
 
    def diff_remote(self, action):
350
 
        """ Remote context menu -> Show differences """
351
 
        print "DEBUG: show differences."
352
 
    
353
 
    def revert_remote(self, action):
354
 
        """ Remote context menu -> Revert to this revision """
355
 
        print "DEBUG: revert to this revision."