/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: Szilveszter Farkas (Phanatic)
  • Date: 2006-10-03 06:44:48 UTC
  • mfrom: (0.8.98 merge)
  • mto: (93.1.1 win32.bialix)
  • mto: This revision was merged to the branch mainline in revision 103.
  • Revision ID: Szilveszter.Farkas@gmail.com-20061003064448-8cf3c9cc653346ab
Merge from the merge branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    pygtk.require("2.0")
23
23
except:
24
24
    pass
25
 
try:
26
 
    import gtk
27
 
    import gtk.glade
28
 
except:
29
 
    sys.exit(1)
 
25
 
 
26
import gtk
30
27
 
31
28
import bzrlib.errors as errors
 
29
from bzrlib.workingtree import WorkingTree
32
30
 
 
31
from dialog import error_dialog, info_dialog, warning_dialog
33
32
from launch import launch
 
33
from olive import OlivePreferences
34
34
 
35
35
class OliveMenu:
36
36
    """ This class is responsible for building the context menus. """
37
 
    def __init__(self, gladefile, comm, dialog):
 
37
    def __init__(self, path, selected):
38
38
        # Load the UI file
39
39
        if sys.platform == 'win32':
40
40
            self.uifile = os.path.dirname(sys.executable) + "/share/olive/cmenu.ui"
50
50
                print _('UI description file cannot be found.')
51
51
                sys.exit(1)
52
52
        
53
 
        self.gladefile = gladefile
54
 
        self.comm = comm
55
 
        self.dialog = dialog
 
53
        # Preferences handler
 
54
        self.pref = OlivePreferences()
 
55
        
 
56
        # Set default values
 
57
        self.path = path
 
58
        self.selected = selected
56
59
        
57
60
        # Create the file list context menu
58
61
        self.ui = gtk.UIManager()
112
115
        self.toolbar_diff = self.ui.get_widget('/toolbar_diff')
113
116
        
114
117
        # Set icons
115
 
        commit_menu = self.ui.get_widget('/context_right/commit')
116
 
        commit_image = self.comm.menuitem_branch_commit.get_image()
117
 
        commit_pixbuf = commit_image.get_pixbuf()
118
 
        commit_icon = gtk.Image()
119
 
        commit_icon.set_from_pixbuf(commit_pixbuf)
120
 
        commit_menu.set_image(commit_icon)
121
 
        diff_menu = self.ui.get_widget('/context_right/diff')
122
 
        diff_image = self.comm.menuitem_stats_diff.get_image()
123
 
        diff_pixbuf = diff_image.get_pixbuf()
124
 
        diff_icon = gtk.Image()
125
 
        diff_icon.set_from_pixbuf(diff_pixbuf)
126
 
        diff_menu.set_image(diff_icon)
 
118
        # TODO: do it without using deprecated comm
 
119
        #commit_menu = self.ui.get_widget('/context_right/commit')
 
120
        #commit_image = self.comm.menuitem_branch_commit.get_image()
 
121
        #commit_pixbuf = commit_image.get_pixbuf()
 
122
        #commit_icon = gtk.Image()
 
123
        #commit_icon.set_from_pixbuf(commit_pixbuf)
 
124
        #commit_menu.set_image(commit_icon)
 
125
        #diff_menu = self.ui.get_widget('/context_right/diff')
 
126
        #diff_image = self.comm.menuitem_stats_diff.get_image()
 
127
        #diff_pixbuf = diff_image.get_pixbuf()
 
128
        #diff_icon = gtk.Image()
 
129
        #diff_icon.set_from_pixbuf(diff_pixbuf)
 
130
        #diff_menu.set_image(diff_icon)
127
131
 
128
132
    def right_context_menu(self):
129
133
        return self.cmenu_right
133
137
    
134
138
    def add_file(self, action):
135
139
        """ Right context menu -> Add """
 
140
        import bzrlib.add
 
141
        
136
142
        # Add only the selected file
137
 
        directory = self.comm.get_path()
138
 
        filename = self.comm.get_selected_right()
 
143
        directory = self.path
 
144
        filename = self.selected
139
145
            
140
146
        if filename is None:
141
 
            self.dialog.error_dialog(_('No file was selected'),
142
 
                                     _('Please select a file from the list,\nor choose the other option.'))
 
147
            error_dialog(_('No file was selected'),
 
148
                         _('Please select a file from the list,\nor choose the other option.'))
143
149
            return
144
150
        
145
151
        try:
146
152
            bzrlib.add.smart_add([directory + os.sep + filename])
147
153
        except errors.NotBranchError:
148
 
            self.dialog.error_dialog(_('Directory is not a branch'),
149
 
                                     _('You can perform this action only in a branch.'))
 
154
            error_dialog(_('Directory is not a branch'),
 
155
                         _('You can perform this action only in a branch.'))
150
156
            return
151
 
        
152
 
        self.comm.refresh_right()
153
157
    
154
158
    def remove_file(self, action):
155
159
        """ Right context menu -> Remove """
156
160
        # Remove only the selected file
157
 
        directory = self.comm.get_path()
158
 
        filename = self.comm.get_selected_right()
 
161
        directory = self.path
 
162
        filename = self.selected
159
163
        
160
164
        if filename is None:
161
 
            self.dialog.error_dialog(_('No file was selected'),
162
 
                                     _('Please select a file from the list,\nor choose the other option.'))
 
165
            error_dialog(_('No file was selected'),
 
166
                         _('Please select a file from the list,\nor choose the other option.'))
163
167
            return
164
168
        
165
169
        try:
167
171
            wt.remove(path)
168
172
 
169
173
        except errors.NotBranchError:
170
 
            self.dialog.error_dialog(_('Directory is not a branch'),
171
 
                                     _('You can perform this action only in a branch.'))
 
174
            error_dialog(_('Directory is not a branch'),
 
175
                         _('You can perform this action only in a branch.'))
172
176
            return
173
177
        except errors.NotVersionedError:
174
 
            self.dialog.error_dialog(_('File not versioned'),
175
 
                                     _('The selected file is not versioned.'))
 
178
            error_dialog(_('File not versioned'),
 
179
                         _('The selected file is not versioned.'))
176
180
            return
177
 
        except:
178
 
            raise
179
 
        
180
 
        self.comm.refresh_right()
181
181
 
182
182
    def open_file(self, action):
183
183
        """ Right context menu -> Open """
184
184
        # Open only the selected file
185
 
        filename = self.comm.get_selected_right()
 
185
        filename = self.selected
186
186
        
187
187
        if filename is None:
188
 
            self.dialog.error_dialog(_('No file was selected'),
189
 
                                     _('Please select a file from the list,\nor choose the other option.'))
 
188
            error_dialog(_('No file was selected'),
 
189
                         _('Please select a file from the list,\nor choose the other option.'))
190
190
            return
191
191
 
192
192
        if filename == '..':
193
 
            self.comm.set_path(os.path.split(self.comm.get_path())[0])
 
193
            # TODO: how to enter a directory?
 
194
            return
194
195
        else:
195
 
            fullpath = self.comm.get_path() + os.sep + filename
 
196
            fullpath = self.path + os.sep + filename
196
197
            if os.path.isdir(fullpath):
197
198
                # selected item is an existant directory
198
 
                self.comm.set_path(fullpath)
 
199
                # TODO: how to enter a directory?
 
200
                return
199
201
            else:
200
202
                launch(fullpath) 
201
 
        
202
 
        self.comm.refresh_right()
203
203
 
204
204
    def commit(self, action):
205
205
        """ Right context menu -> Commit """
206
206
        from commit import OliveCommit
207
 
        commit = OliveCommit(self.gladefile, self.comm, self.dialog)
 
207
        wt, path = WorkingTree.open_containing(self.path)
 
208
        commit = OliveCommit(wt, path)
208
209
        commit.display()
209
210
    
210
211
    def diff(self, action):
211
212
        """ Right context menu -> Diff """
212
 
        from diff import OliveDiff
213
 
        diff = OliveDiff(self.gladefile, self.comm, self.dialog)
214
 
        diff.display()
 
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
        
 
222
        window = DiffWindow()
 
223
        parent_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
 
224
        window.set_diff(wt.branch.nick, wt, parent_tree)
 
225
        window.show()
215
226
    
216
227
    def bookmark(self, action):
217
228
        """ Right context menu -> Bookmark """
218
 
        if self.comm.pref.add_bookmark(self.comm.get_path()):
219
 
            self.dialog.info_dialog(_('Bookmark successfully added'),
220
 
                                    _('The current directory was bookmarked. You can reach\nit by selecting it from the left panel.'))
 
229
        if self.pref.add_bookmark(self.path):
 
230
            info_dialog(_('Bookmark successfully added'),
 
231
                        _('The current directory was bookmarked. You can reach\nit by selecting it from the left panel.'))
 
232
            self.pref.write()
221
233
        else:
222
 
            self.dialog.warning_dialog(_('Location already bookmarked'),
223
 
                                       _('The current directory is already bookmarked.\nSee the left panel for reference.'))
224
 
        
225
 
        self.comm.refresh_left()
 
234
            warning_dialog(_('Location already bookmarked'),
 
235
                           _('The current directory is already bookmarked.\nSee the left panel for reference.'))
226
236
 
227
237
    def edit_bookmark(self, action):
228
238
        """ Left context menu -> Edit """
229
239
        from bookmark import OliveBookmark
230
240
 
231
 
        if self.comm.get_selected_left() != None:
232
 
            bookmark = OliveBookmark(self.gladefile, self.comm, self.dialog)
 
241
        if self.selected != None:
 
242
            bookmark = OliveBookmark(self.selected)
233
243
            bookmark.display()
234
244
 
235
245
    def remove_bookmark(self, action):
236
246
        """ Left context menu -> Remove """
237
247
        
238
 
        if self.comm.get_selected_left() != None:
239
 
            self.comm.pref.remove_bookmark(self.comm.get_selected_left())
 
248
        if self.selected != None:
 
249
            self.pref.remove_bookmark(self.comm.get_selected_left())
240
250
            self.comm.refresh_left()
241
251
    
242
252
    def open_folder(self, action):
243
253
        """ Left context menu -> Open Folder """
244
 
        path = self.comm.get_selected_left()
 
254
        path = self.selected
245
255
 
246
256
        if path != None:
247
257
            launch(path)
253
263
    def diff_all(self, action):
254
264
        """ Diff toolbutton -> All... """
255
265
        from diff import OliveDiff
256
 
        diff = OliveDiff(self.gladefile, self.comm, self.dialog)
 
266
        diff = OliveDiff(self.comm)
257
267
        diff.display()