/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: Aaron Bentley
  • Date: 2007-01-17 06:42:55 UTC
  • mto: This revision was merged to the branch mainline in revision 129.
  • Revision ID: aaron.bentley@utoronto.ca-20070117064255-x4gznz5e0lyjq3gk
Remove usused span selector

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
from dialog import error_dialog, info_dialog, warning_dialog
32
32
from launch import launch
33
 
from olive import OlivePreferences
 
33
from olive import OlivePreferences, DiffWindow
34
34
 
35
35
class OliveMenu:
36
36
    """ This class is responsible for building the context menus. """
37
 
    def __init__(self, path, selected):
 
37
    def __init__(self, path, selected, app=None):
38
38
        # 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
 
        
 
39
        from guifiles import UIFILENAME
 
40
 
 
41
        self.uifile = UIFILENAME
 
42
 
53
43
        # Preferences handler
54
44
        self.pref = OlivePreferences()
55
45
        
56
46
        # Set default values
57
47
        self.path = path
58
48
        self.selected = selected
 
49
        self.app = app
59
50
        
60
51
        # Create the file list context menu
61
52
        self.ui = gtk.UIManager()
69
60
                                       _('Remove'), None,
70
61
                                       _('Remove the selected file'),
71
62
                                       self.remove_file),
 
63
                                      ('rename', None,
 
64
                                       _('Rename'), None,
 
65
                                       _('Rename the selected file'),
 
66
                                       self.rename_file),
72
67
                                      ('open', gtk.STOCK_OPEN,
73
68
                                       _('Open'), None,
74
69
                                       _('Open the selected file'),
149
144
            return
150
145
        
151
146
        try:
152
 
            bzrlib.add.smart_add([directory + '/' + filename])
 
147
            bzrlib.add.smart_add([os.path.join(directory, filename)])
153
148
        except errors.NotBranchError:
154
149
            error_dialog(_('Directory is not a branch'),
155
150
                         _('You can perform this action only in a branch.'))
167
162
            return
168
163
        
169
164
        try:
170
 
            wt, path = WorkingTree.open_containing(directory + os.sep + filename)
 
165
            wt, path = WorkingTree.open_containing(os.path.join(directory, filename))
171
166
            wt.remove(path)
172
167
 
173
168
        except errors.NotBranchError:
179
174
                         _('The selected file is not versioned.'))
180
175
            return
181
176
 
 
177
        self.app.set_path(self.path)
 
178
        self.app.refresh_right()
 
179
 
 
180
    def rename_file(self, action):
 
181
        """ Right context menu -> Rename """
 
182
        from rename import OliveRename
 
183
        wt = WorkingTree.open_containing(self.path + os.sep + self.selected)[0]
 
184
        rename = OliveRename(wt, wt.relpath(self.path), self.selected)
 
185
        rename.display()
 
186
    
182
187
    def open_file(self, action):
183
188
        """ Right context menu -> Open """
184
189
        # Open only the selected file
204
209
    def commit(self, action):
205
210
        """ Right context menu -> Commit """
206
211
        from commit import CommitDialog
207
 
        wt, path = WorkingTree.open_containing(self.path)
208
 
        commit = CommitDialog(wt, path)
 
212
        branch = None
 
213
        try:
 
214
            wt, path = WorkingTree.open_containing(self.path)
 
215
            branch = wt.branch
 
216
        except NotBranchError, e:
 
217
            path = e.path
 
218
        commit = CommitDialog(wt, path, not branch)
209
219
        commit.display()
210
220
    
211
221
    def diff(self, action):
212
222
        """ Right context menu -> Diff """
213
 
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
214
 
        
215
223
        try:
216
224
            wt = WorkingTree.open_containing(self.path)[0]
217
225
        except errors.NotBranchError:
222
230
        window = DiffWindow()
223
231
        parent_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
224
232
        window.set_diff(wt.branch.nick, wt, parent_tree)
 
233
        try:
 
234
            window.set_file(wt.relpath(self.path + os.sep + self.selected))
 
235
        except errors.NoSuchFile:
 
236
            pass
225
237
        window.show()
226
238
    
227
239
    def bookmark(self, action):
233
245
        else:
234
246
            warning_dialog(_('Location already bookmarked'),
235
247
                           _('The current directory is already bookmarked.\nSee the left panel for reference.'))
 
248
        
 
249
        self.app.refresh_left()
236
250
 
237
251
    def edit_bookmark(self, action):
238
252
        """ Left context menu -> Edit """
239
 
        from bookmark import OliveBookmark
240
 
 
 
253
        from bookmark import OliveBookmarkDialog
 
254
        
241
255
        if self.selected != None:
242
 
            bookmark = OliveBookmark(self.selected)
243
 
            bookmark.display()
 
256
            bookmark = OliveBookmarkDialog(self.selected, self.app.window)
 
257
            response = bookmark.run()
 
258
            
 
259
            if response != gtk.RESPONSE_NONE:
 
260
                bookmark.hide()
 
261
        
 
262
                if response == gtk.RESPONSE_OK:
 
263
                    self.app.refresh_left()
 
264
            
 
265
                bookmark.destroy()
244
266
 
245
267
    def remove_bookmark(self, action):
246
268
        """ Left context menu -> Remove """
247
269
        
248
270
        if self.selected != None:
249
 
            self.pref.remove_bookmark(self.comm.get_selected_left())
250
 
            self.comm.refresh_left()
 
271
            self.pref.remove_bookmark(self.selected)
 
272
            self.pref.write()
 
273
        
 
274
        self.app.refresh_left()
251
275
    
252
276
    def open_folder(self, action):
253
277
        """ Left context menu -> Open Folder """