/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-07-15 18:12:57 UTC
  • Revision ID: jelmer@samba.org-20070715181257-g264qus2zyi3v39z
Add RevisionSelectionBox widget, use in TagDialog.

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 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
32
36
from launch import launch
33
 
from olive import OlivePreferences
 
37
from olive import Preferences
34
38
 
35
39
class OliveMenu:
36
40
    """ This class is responsible for building the context menus. """
37
 
    def __init__(self, path, selected):
 
41
    def __init__(self, path, selected, app=None):
38
42
        # 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
 
        
 
43
        from guifiles import UIFILENAME
 
44
 
 
45
        self.uifile = UIFILENAME
 
46
 
53
47
        # Preferences handler
54
 
        self.pref = OlivePreferences()
 
48
        self.pref = Preferences()
55
49
        
56
50
        # Set default values
57
51
        self.path = path
58
52
        self.selected = selected
 
53
        self.app = app
59
54
        
60
55
        # Create the file list context menu
61
56
        self.ui = gtk.UIManager()
69
64
                                       _('Remove'), None,
70
65
                                       _('Remove the selected file'),
71
66
                                       self.remove_file),
 
67
                                      ('rename', None,
 
68
                                       _('Rename'), None,
 
69
                                       _('Rename the selected file'),
 
70
                                       self.rename_file),
72
71
                                      ('open', gtk.STOCK_OPEN,
73
72
                                       _('Open'), None,
74
73
                                       _('Open the selected file'),
75
74
                                       self.open_file),
 
75
                                      ('revert', None,
 
76
                                       _('Revert'), None,
 
77
                                       _('Revert the changes'),
 
78
                                       self.revert),
76
79
                                      ('commit', None,
77
80
                                       _('Commit'), None,
78
81
                                       _('Commit the changes'),
79
82
                                       self.commit),
 
83
                                      ('annotate', None,
 
84
                                       _('Annotate'), None,
 
85
                                       _('Annotate the selected file'),
 
86
                                       self.annotate),
80
87
                                      ('diff', None,
81
88
                                       _('Diff'), None,
82
89
                                       _('Show the diff of the file'),
104
111
                                      ('diff_all', None,
105
112
                                       _('All...'), None,
106
113
                                       _('Show the differences of all files'),
107
 
                                       self.diff_all)
 
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)
108
127
                                     ])
109
128
        
110
129
        self.ui.insert_action_group(self.actiongroup, 0)
113
132
        self.cmenu_right = self.ui.get_widget('/context_right')
114
133
        self.cmenu_left = self.ui.get_widget('/context_left')
115
134
        self.toolbar_diff = self.ui.get_widget('/toolbar_diff')
 
135
        self.cmenu_remote = self.ui.get_widget('/context_remote')
116
136
        
117
137
        # Set icons
118
138
        # TODO: do it without using deprecated comm
135
155
    def left_context_menu(self):
136
156
        return self.cmenu_left
137
157
    
 
158
    def remote_context_menu(self):
 
159
        return self.cmenu_remote
 
160
    
 
161
    @show_bzr_error
138
162
    def add_file(self, action):
139
163
        """ Right context menu -> Add """
140
164
        import bzrlib.add
148
172
                         _('Please select a file from the list,\nor choose the other option.'))
149
173
            return
150
174
        
 
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()
151
198
        try:
152
 
            bzrlib.add.smart_add([directory + os.sep + 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
 
199
            window.annotate(wt, branch, file_id)
 
200
        finally:
 
201
            branch.unlock()
157
202
    
 
203
    @show_bzr_error
158
204
    def remove_file(self, action):
159
205
        """ Right context menu -> Remove """
160
206
        # Remove only the selected file
166
212
                         _('Please select a file from the list,\nor choose the other option.'))
167
213
            return
168
214
        
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
 
 
 
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
    
182
227
    def open_file(self, action):
183
228
        """ Right context menu -> Open """
184
229
        # Open only the selected file
201
246
            else:
202
247
                launch(fullpath) 
203
248
 
 
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
    
204
261
    def commit(self, action):
205
262
        """ Right context menu -> Commit """
206
 
        from commit import OliveCommit
207
 
        wt, path = WorkingTree.open_containing(self.path)
208
 
        commit = OliveCommit(wt, path)
209
 
        commit.display()
 
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()
210
280
    
 
281
    @show_bzr_error
211
282
    def diff(self, action):
212
283
        """ 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
 
        
 
284
        wt = WorkingTree.open_containing(self.path)[0]
222
285
        window = DiffWindow()
223
286
        parent_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
224
287
        window.set_diff(wt.branch.nick, wt, parent_tree)
 
288
        window.set_file(wt.relpath(self.path + os.sep + self.selected))
225
289
        window.show()
226
290
    
227
291
    def bookmark(self, action):
233
297
        else:
234
298
            warning_dialog(_('Location already bookmarked'),
235
299
                           _('The current directory is already bookmarked.\nSee the left panel for reference.'))
 
300
        
 
301
        self.app.refresh_left()
236
302
 
237
303
    def edit_bookmark(self, action):
238
304
        """ Left context menu -> Edit """
239
 
        from bookmark import OliveBookmark
240
 
 
 
305
        from bookmark import BookmarkDialog
 
306
        
241
307
        if self.selected != None:
242
 
            bookmark = OliveBookmark(self.selected)
243
 
            bookmark.display()
 
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()
244
318
 
245
319
    def remove_bookmark(self, action):
246
320
        """ Left context menu -> Remove """
247
321
        
248
322
        if self.selected != None:
249
 
            self.pref.remove_bookmark(self.comm.get_selected_left())
250
 
            self.comm.refresh_left()
 
323
            self.pref.remove_bookmark(self.selected)
 
324
            self.pref.write()
 
325
        
 
326
        self.app.refresh_left()
251
327
    
252
328
    def open_folder(self, action):
253
329
        """ Left context menu -> Open Folder """
265
341
        from diff import OliveDiff
266
342
        diff = OliveDiff(self.comm)
267
343
        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."