/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/frontend/gtk/handler.py

Merge from Richard Ferguson's development branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
import sys
 
18
 
 
19
try:
 
20
    import pygtk
 
21
    pygtk.require("2.0")
 
22
except:
 
23
    pass
 
24
try:
 
25
    import gtk
 
26
    import gtk.glade
 
27
except:
 
28
    sys.exit(1)
 
29
 
 
30
from olive.backend.info import is_branch
 
31
import olive.backend.errors as errors
 
32
 
 
33
from dialog import OliveDialog
 
34
from menu import OliveMenu
 
35
from launch import launch
 
36
 
 
37
class OliveHandler:
 
38
    """ Signal handler class for Olive. """
 
39
    def __init__(self, gladefile, comm):
 
40
        self.gladefile = gladefile
 
41
        self.comm = comm
 
42
        
 
43
        self.dialog = OliveDialog(self.gladefile)
 
44
        
 
45
        self.menu = OliveMenu(self.gladefile, self.comm, self.dialog)
 
46
    
 
47
    def on_about_activate(self, widget):
 
48
        self.dialog.about()
 
49
        
 
50
    def on_menuitem_add_files_activate(self, widget):
 
51
        """ Add file(s)... menu handler. """
 
52
        from add import OliveAdd
 
53
        add = OliveAdd(self.gladefile, self.comm, self.dialog)
 
54
        add.display()
 
55
    
 
56
    def on_menuitem_branch_get_activate(self, widget):
 
57
        """ Branch/Get... menu handler. """
 
58
        from branch import OliveBranch
 
59
        branch = OliveBranch(self.gladefile, self.comm, self.dialog)
 
60
        branch.display()
 
61
    
 
62
    def on_menuitem_branch_checkout_activate(self, widget):
 
63
        """ Branch/Checkout... menu handler. """
 
64
        from checkout import OliveCheckout
 
65
        checkout = OliveCheckout(self.gladefile, self.comm, self.dialog)
 
66
        checkout.display()
 
67
    
 
68
    def on_menuitem_branch_commit_activate(self, widget):
 
69
        """ Branch/Commit... menu handler. """
 
70
        from commit import OliveCommit
 
71
        commit = OliveCommit(self.gladefile, self.comm, self.dialog)
 
72
        commit.display()
 
73
    
 
74
    def on_menuitem_branch_missing_revisions_activate(self, widget):
 
75
        """ Branch/Missing revisions menu handler. """
 
76
        import olive.backend.update as update
 
77
        
 
78
        self.comm.set_busy(self.comm.window_main)
 
79
        
 
80
        try:
 
81
            ret = update.missing(self.comm.get_path())
 
82
        except errors.NotBranchError:
 
83
            self.dialog.error_dialog(_('Directory is not a branch'),
 
84
                                     _('You can perform this action only in a branch.'))
 
85
        except errors.ConnectionError:
 
86
            self.dialog.error_dialog(_('Connection error'),
 
87
                                     _('Cannot connect to remote location.\nPlease try again later.'))
 
88
        except errors.NoLocationKnown:
 
89
            self.dialog.error_dialog(_('Parent location is unknown'),
 
90
                                     _('Cannot determine missing revisions if no parent location is known.'))
 
91
        else:
 
92
            if ret > 0:
 
93
                self.dialog.info_dialog(_('There are missing revisions'),
 
94
                                        _('%d revision(s) missing.') % ret)
 
95
            else:
 
96
                self.dialog.info_dialog(_('Local branch up to date'),
 
97
                                        _('There are no missing revisions.'))
 
98
        
 
99
        self.comm.set_busy(self.comm.window_main, False)
 
100
    
 
101
    def on_menuitem_branch_pull_activate(self, widget):
 
102
        """ Branch/Pull menu handler. """
 
103
        import olive.backend.update as update
 
104
        
 
105
        self.comm.set_busy(self.comm.window_main)
 
106
        
 
107
        try:
 
108
            ret = update.pull(self.comm.get_path())
 
109
        except errors.NotBranchError:
 
110
            self.dialog.error_dialog(_('Directory is not a branch'),
 
111
                                     _('You can perform this action only in a branch.'))
 
112
        except errors.NoLocationKnown:
 
113
            self.dialog.error_dialog(_('Parent location is unknown'),
 
114
                                     _('Pulling is not possible until there is no parent location.'))
 
115
        else:
 
116
            self.dialog.info_dialog(_('Pull successful'),
 
117
                                    _('%d revision(s) pulled.') % ret)
 
118
        
 
119
        self.comm.set_busy(self.comm.window_main, False)
 
120
    
 
121
    def on_menuitem_branch_push_activate(self, widget):
 
122
        """ Branch/Push... menu handler. """
 
123
        from push import OlivePush
 
124
        push = OlivePush(self.gladefile, self.comm, self.dialog)
 
125
        push.display()
 
126
    
 
127
    def on_menuitem_branch_status_activate(self, widget):
 
128
        """ Branch/Status... menu handler. """
 
129
        from status import OliveStatus
 
130
        status = OliveStatus(self.gladefile, self.comm, self.dialog)
 
131
        status.display()
 
132
    
 
133
    def on_menuitem_branch_initialize_activate(self, widget):
 
134
        """ Initialize current directory. """
 
135
        import olive.backend.init as init
 
136
        
 
137
        try:
 
138
            init.init(self.comm.get_path())
 
139
        except errors.AlreadyBranchError, errmsg:
 
140
            self.dialog.error_dialog(_('Directory is already a branch'),
 
141
                                     _('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
 
142
        except errors.BranchExistsWithoutWorkingTree, errmsg:
 
143
            self.dialog.error_dialog(_('Branch without a working tree'),
 
144
                                     _('The current directory (%s)\nis a branch without a working tree.') % errmsg)
 
145
        except:
 
146
            raise
 
147
        else:
 
148
            self.dialog.info_dialog(_('Ininialize successful'),
 
149
                                    _('Directory successfully initialized.'))
 
150
            self.comm.refresh_right()
 
151
        
 
152
    def on_menuitem_file_make_directory_activate(self, widget):
 
153
        """ File/Make directory... menu handler. """
 
154
        from mkdir import OliveMkdir
 
155
        mkdir = OliveMkdir(self.gladefile, self.comm, self.dialog)
 
156
        mkdir.display()
 
157
    
 
158
    def on_menuitem_file_move_activate(self, widget):
 
159
        """ File/Move... menu handler. """
 
160
        from move import OliveMove
 
161
        move = OliveMove(self.gladefile, self.comm, self.dialog)
 
162
        move.display()
 
163
    
 
164
    def on_menuitem_file_rename_activate(self, widget):
 
165
        """ File/Rename... menu handler. """
 
166
        from rename import OliveRename
 
167
        rename = OliveRename(self.gladefile, self.comm, self.dialog)
 
168
        rename.display()
 
169
 
 
170
    def on_menuitem_remove_file_activate(self, widget):
 
171
        """ Remove (unversion) selected file. """
 
172
        from remove import OliveRemove
 
173
        remove = OliveRemove(self.gladefile, self.comm, self.dialog)
 
174
        remove.display()
 
175
    
 
176
    def on_menuitem_stats_diff_activate(self, widget):
 
177
        """ Statistics/Differences... menu handler. """
 
178
        from diff import OliveDiff
 
179
        diff = OliveDiff(self.gladefile, self.comm, self.dialog)
 
180
        diff.display()
 
181
    
 
182
    def on_menuitem_stats_infos_activate(self, widget):
 
183
        """ Statistics/Informations... menu handler. """
 
184
        from info import OliveInfo
 
185
        info = OliveInfo(self.gladefile, self.comm, self.dialog)
 
186
        info.display()
 
187
    
 
188
    def on_menuitem_stats_log_activate(self, widget):
 
189
        """ Statistics/Log... menu handler. """
 
190
        from log import OliveLog
 
191
        log = OliveLog(self.gladefile, self.comm, self.dialog)
 
192
        log.display()
 
193
    
 
194
    def on_menuitem_view_refresh_activate(self, widget):
 
195
        """ View/Refresh menu handler. """
 
196
        # Refresh the left pane
 
197
        self.comm.refresh_left()
 
198
        # Refresh the right pane
 
199
        self.comm.refresh_right()
 
200
    
 
201
    def on_menuitem_view_show_hidden_files_activate(self, widget):
 
202
        """ View/Show hidden files menu handler. """
 
203
        if widget.get_active():
 
204
            # Show hidden files
 
205
            self.comm.pref.set_preference('dotted_files', True)
 
206
            self.comm.pref.refresh()
 
207
            self.comm.refresh_right()
 
208
        else:
 
209
            # Do not show hidden files
 
210
            self.comm.pref.set_preference('dotted_files', False)
 
211
            self.comm.pref.refresh()
 
212
            self.comm.refresh_right()
 
213
 
 
214
    def on_treeview_left_button_press_event(self, widget, event):
 
215
        """ Occurs when somebody right-clicks in the bookmark list. """
 
216
        if event.button == 3:
 
217
            # Don't show context with nothing selected
 
218
            if self.comm.get_selected_left() == None:
 
219
                return
 
220
 
 
221
            self.menu.left_context_menu().popup(None, None, None, 0,
 
222
                                                event.time)
 
223
        
 
224
    def on_treeview_left_row_activated(self, treeview, path, view_column):
 
225
        """ Occurs when somebody double-clicks or enters an item in the
 
226
        bookmark list. """
 
227
 
 
228
        newdir = self.comm.get_selected_left()
 
229
        if newdir == None:
 
230
            return
 
231
 
 
232
        self.comm.set_busy(treeview)
 
233
        self.comm.set_path(newdir)
 
234
        self.comm.refresh_right()
 
235
        self.comm.set_busy(treeview, False)
 
236
    
 
237
    def on_treeview_right_button_press_event(self, widget, event):
 
238
        """ Occurs when somebody right-clicks in the file list. """
 
239
        if event.button == 3:
 
240
            # get the menu items
 
241
            m_add = self.menu.ui.get_widget('/context_right/add')
 
242
            m_remove = self.menu.ui.get_widget('/context_right/remove')
 
243
            m_commit = self.menu.ui.get_widget('/context_right/commit')
 
244
            m_diff = self.menu.ui.get_widget('/context_right/diff')
 
245
            # check if we're in a branch
 
246
            if not is_branch(self.comm.get_path()):
 
247
                m_add.set_sensitive(False)
 
248
                m_remove.set_sensitive(False)
 
249
                m_commit.set_sensitive(False)
 
250
                m_diff.set_sensitive(False)
 
251
            else:
 
252
                m_add.set_sensitive(True)
 
253
                m_remove.set_sensitive(True)
 
254
                m_commit.set_sensitive(True)
 
255
                m_diff.set_sensitive(True)
 
256
            self.menu.right_context_menu().popup(None, None, None, 0,
 
257
                                                 event.time)
 
258
        
 
259
    def on_treeview_right_row_activated(self, treeview, path, view_column):
 
260
        """ Occurs when somebody double-clicks or enters an item in the
 
261
        file list. """
 
262
        import os.path
 
263
        
 
264
        newdir = self.comm.get_selected_right()
 
265
        
 
266
        if newdir == '..':
 
267
            self.comm.set_path(os.path.split(self.comm.get_path())[0])
 
268
        else:
 
269
            fullpath = self.comm.get_path() + os.sep + newdir
 
270
            if os.path.isdir(fullpath):
 
271
                # selected item is an existant directory
 
272
                self.comm.set_path(fullpath)
 
273
            else:
 
274
                launch(fullpath) 
 
275
        
 
276
        self.comm.refresh_right()
 
277
    
 
278
    def on_window_main_delete_event(self, widget, event=None):
 
279
        """ Do some stuff before exiting. """
 
280
        width, height = self.comm.window_main.get_size()
 
281
        self.comm.pref.set_preference('window_width', width)
 
282
        self.comm.pref.set_preference('window_height', height)
 
283
        x, y = self.comm.window_main.get_position()
 
284
        self.comm.pref.set_preference('window_x', x)
 
285
        self.comm.pref.set_preference('window_y', y)
 
286
        self.comm.pref.set_preference('paned_position',
 
287
                                      self.comm.hpaned_main.get_position())
 
288
        
 
289
        self.comm.pref.write()
 
290
        self.comm.window_main.destroy()
 
291
 
 
292
    def not_implemented(self, widget):
 
293
        """ Display a Not implemented error message. """
 
294
        self.dialog.error_dialog(_('We feel sorry'),
 
295
                                 _('This feature is not yet implemented.'))
 
296