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

  • Committer: Jelmer Vernooij
  • Date: 2008-06-28 17:13:46 UTC
  • mto: This revision was merged to the branch mainline in revision 517.
  • Revision ID: jelmer@samba.org-20080628171346-ob42iggcc663s4xz
Show full license details in about dialog.

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
 
import bzrlib.errors as errors
31
 
from bzrlib.branch import Branch
32
 
 
33
 
from dialog import OliveDialog
34
 
from menu import OliveMenu
35
 
 
36
 
class OliveHandler:
37
 
    """ Signal handler class for Olive. """
38
 
    def __init__(self, gladefile, comm):
39
 
        self.gladefile = gladefile
40
 
        self.comm = comm
41
 
        
42
 
        self.dialog = OliveDialog(self.gladefile)
43
 
        
44
 
        self.menu = OliveMenu(self.gladefile, self.comm, self.dialog)
45
 
    
46
 
    def on_about_activate(self, widget):
47
 
        self.dialog.about()
48
 
        
49
 
    def on_menuitem_add_files_activate(self, widget):
50
 
        """ Add file(s)... menu handler. """
51
 
        from add import OliveAdd
52
 
        add = OliveAdd(self.gladefile, self.comm, self.dialog)
53
 
        add.display()
54
 
    
55
 
    def on_menuitem_branch_get_activate(self, widget):
56
 
        """ Branch/Get... menu handler. """
57
 
        from branch import OliveBranch
58
 
        branch = OliveBranch(self.gladefile, self.comm, self.dialog)
59
 
        branch.display()
60
 
    
61
 
    def on_menuitem_branch_checkout_activate(self, widget):
62
 
        """ Branch/Checkout... menu handler. """
63
 
        from checkout import OliveCheckout
64
 
        checkout = OliveCheckout(self.gladefile, self.comm, self.dialog)
65
 
        checkout.display()
66
 
    
67
 
    def on_menuitem_branch_commit_activate(self, widget):
68
 
        """ Branch/Commit... menu handler. """
69
 
        from commit import OliveCommit
70
 
        commit = OliveCommit(self.gladefile, self.comm, self.dialog)
71
 
        commit.display()
72
 
    
73
 
    def on_menuitem_branch_missing_revisions_activate(self, widget):
74
 
        """ Branch/Missing revisions menu handler. """
75
 
        
76
 
        self.comm.set_busy(self.comm.window_main)
77
 
        
78
 
        try:
79
 
            import bzrlib
80
 
            
81
 
            try:
82
 
                local_branch = Branch.open_containing(self.comm.get_path())[0]
83
 
            except NotBranchError:
84
 
                self.dialog.error_dialog(_('Directory is not a branch'),
85
 
                                         _('You can perform this action only in a branch.'))
86
 
                return
87
 
            
88
 
            other_branch = local_branch.get_parent()
89
 
            if other_branch is None:
90
 
                self.dialog.error_dialog(_('Parent location is unknown'),
91
 
                                         _('Cannot determine missing revisions if no parent location is known.'))
92
 
                return
93
 
            
94
 
            remote_branch = Branch.open(other_branch)
95
 
            
96
 
            if remote_branch.base == local_branch.base:
97
 
                remote_branch = local_branch
98
 
 
99
 
            ret = len(local_branch.missing_revisions(remote_branch))
100
 
 
101
 
            if ret > 0:
102
 
                self.dialog.info_dialog(_('There are missing revisions'),
103
 
                                        _('%d revision(s) missing.') % ret)
104
 
            else:
105
 
                self.dialog.info_dialog(_('Local branch up to date'),
106
 
                                        _('There are no missing revisions.'))
107
 
        finally:
108
 
            self.comm.set_busy(self.comm.window_main, False)
109
 
    
110
 
    def on_menuitem_branch_pull_activate(self, widget):
111
 
        """ Branch/Pull menu handler. """
112
 
        
113
 
        self.comm.set_busy(self.comm.window_main)
114
 
 
115
 
        try:
116
 
            try:
117
 
                from bzrlib.workingtree import WorkingTree
118
 
                tree_to = WorkingTree.open_containing(self.comm.get_path())[0]
119
 
                branch_to = tree_to.branch
120
 
            except errors.NoWorkingTree:
121
 
                tree_to = None
122
 
                branch_to = Branch.open_containing(self.comm.get_path())[0]
123
 
            except errors.NotBranchError:
124
 
                 self.dialog.error_dialog(_('Directory is not a branch'),
125
 
                                         _('You can perform this action only in a branch.'))
126
 
 
127
 
            location = branch_to.get_parent()
128
 
            if location is None:
129
 
                self.dialog.error_dialog(_('Parent location is unknown'),
130
 
                                         _('Pulling is not possible until there is a parent location.'))
131
 
                return
132
 
 
133
 
            try:
134
 
                branch_from = Branch.open(location)
135
 
            except errors.NotBranchError:
136
 
                self.dialog.error_dialog(_('Directory is not a branch'),
137
 
                                         _('You can perform this action only in a branch.'))
138
 
 
139
 
            if branch_to.get_parent() is None:
140
 
                branch_to.set_parent(branch_from.base)
141
 
 
142
 
            old_rh = branch_to.revision_history()
143
 
            if tree_to is not None:
144
 
                tree_to.pull(branch_from)
145
 
            else:
146
 
                branch_to.pull(branch_from)
147
 
            
148
 
            self.dialog.info_dialog(_('Pull successful'),
149
 
                                    _('%d revision(s) pulled.') % ret)
150
 
            
151
 
        finally:
152
 
            self.comm.set_busy(self.comm.window_main, False)
153
 
    
154
 
    def on_menuitem_branch_push_activate(self, widget):
155
 
        """ Branch/Push... menu handler. """
156
 
        from push import OlivePush
157
 
        push = OlivePush(self.gladefile, self.comm, self.dialog)
158
 
        push.display()
159
 
    
160
 
    def on_menuitem_branch_status_activate(self, widget):
161
 
        """ Branch/Status... menu handler. """
162
 
        from status import OliveStatus
163
 
        status = OliveStatus(self.gladefile, self.comm, self.dialog)
164
 
        status.display()
165
 
    
166
 
    def on_menuitem_branch_initialize_activate(self, widget):
167
 
        """ Initialize current directory. """
168
 
        try:
169
 
            location = self.comm.get_path()
170
 
            from bzrlib.builtins import get_format_type
171
 
 
172
 
            format = get_format_type('default')
173
 
 
174
 
            if not os.path.exists(location):
175
 
                os.mkdir(location)
176
 
     
177
 
            try:
178
 
                existing_bzrdir = bzrdir.BzrDir.open(location)
179
 
            except NotBranchError:
180
 
                bzrdir.BzrDir.create_branch_convenience(location, format=format)
181
 
            else:
182
 
                if existing_bzrdir.has_branch():
183
 
                    if existing_bzrdir.has_workingtree():
184
 
                        raise AlreadyBranchError(location)
185
 
                    else:
186
 
                        raise BranchExistsWithoutWorkingTree(location)
187
 
                else:
188
 
                    existing_bzrdir.create_branch()
189
 
                    existing_bzrdir.create_workingtree()
190
 
        except errors.AlreadyBranchError, errmsg:
191
 
            self.dialog.error_dialog(_('Directory is already a branch'),
192
 
                                     _('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
193
 
        except errors.BranchExistsWithoutWorkingTree, errmsg:
194
 
            self.dialog.error_dialog(_('Branch without a working tree'),
195
 
                                     _('The current directory (%s)\nis a branch without a working tree.') % errmsg)
196
 
        else:
197
 
            self.dialog.info_dialog(_('Initialize successful'),
198
 
                                    _('Directory successfully initialized.'))
199
 
            self.comm.refresh_right()
200
 
        
201
 
    def on_menuitem_file_make_directory_activate(self, widget):
202
 
        """ File/Make directory... menu handler. """
203
 
        from mkdir import OliveMkdir
204
 
        mkdir = OliveMkdir(self.gladefile, self.comm, self.dialog)
205
 
        mkdir.display()
206
 
    
207
 
    def on_menuitem_file_move_activate(self, widget):
208
 
        """ File/Move... menu handler. """
209
 
        from move import OliveMove
210
 
        move = OliveMove(self.gladefile, self.comm, self.dialog)
211
 
        move.display()
212
 
    
213
 
    def on_menuitem_file_rename_activate(self, widget):
214
 
        """ File/Rename... menu handler. """
215
 
        from rename import OliveRename
216
 
        rename = OliveRename(self.gladefile, self.comm, self.dialog)
217
 
        rename.display()
218
 
 
219
 
    def on_menuitem_remove_file_activate(self, widget):
220
 
        """ Remove (unversion) selected file. """
221
 
        from remove import OliveRemove
222
 
        remove = OliveRemove(self.gladefile, self.comm, self.dialog)
223
 
        remove.display()
224
 
    
225
 
    def on_menuitem_stats_diff_activate(self, widget):
226
 
        """ Statistics/Differences... menu handler. """
227
 
        from diff import OliveDiff
228
 
        diff = OliveDiff(self.gladefile, self.comm, self.dialog)
229
 
        diff.display()
230
 
    
231
 
    def on_menuitem_stats_infos_activate(self, widget):
232
 
        """ Statistics/Informations... menu handler. """
233
 
        from info import OliveInfo
234
 
        info = OliveInfo(self.gladefile, self.comm, self.dialog)
235
 
        info.display()
236
 
    
237
 
    def on_menuitem_stats_log_activate(self, widget):
238
 
        """ Statistics/Log... menu handler. """
239
 
        from log import OliveLog
240
 
        log = OliveLog(self.gladefile, self.comm, self.dialog)
241
 
        log.display()
242
 
    
243
 
    def on_menuitem_view_refresh_activate(self, widget):
244
 
        """ View/Refresh menu handler. """
245
 
        # Refresh the left pane
246
 
        self.comm.refresh_left()
247
 
        # Refresh the right pane
248
 
        self.comm.refresh_right()
249
 
    
250
 
    def on_menuitem_view_show_hidden_files_activate(self, widget):
251
 
        """ View/Show hidden files menu handler. """
252
 
        if widget.get_active():
253
 
            # Show hidden files
254
 
            self.comm.pref.set_preference('dotted_files', True)
255
 
            self.comm.pref.refresh()
256
 
            self.comm.refresh_right()
257
 
        else:
258
 
            # Do not show hidden files
259
 
            self.comm.pref.set_preference('dotted_files', False)
260
 
            self.comm.pref.refresh()
261
 
            self.comm.refresh_right()
262
 
 
263
 
    def on_treeview_left_button_press_event(self, widget, event):
264
 
        """ Occurs when somebody right-clicks in the bookmark list. """
265
 
        if event.button == 3:
266
 
            self.menu.left_context_menu().popup(None, None, None, 0,
267
 
                                                event.time)
268
 
        
269
 
    def on_treeview_left_row_activated(self, treeview, path, view_column):
270
 
        """ Occurs when somebody double-clicks or enters an item in the
271
 
        bookmark list. """
272
 
        self.comm.set_busy(treeview)
273
 
        
274
 
        newdir = self.comm.get_selected_left()
275
 
        self.comm.set_path(newdir)
276
 
        
277
 
        self.comm.refresh_right()
278
 
        
279
 
        self.comm.set_busy(treeview, False)
280
 
    
281
 
    def on_treeview_right_button_press_event(self, widget, event):
282
 
        """ Occurs when somebody right-clicks in the file list. """
283
 
        if event.button == 3:
284
 
            # get the menu items
285
 
            m_add = self.menu.ui.get_widget('/context_right/add')
286
 
            m_remove = self.menu.ui.get_widget('/context_right/remove')
287
 
            m_commit = self.menu.ui.get_widget('/context_right/commit')
288
 
            m_diff = self.menu.ui.get_widget('/context_right/diff')
289
 
            # check if we're in a branch
290
 
            try:
291
 
                from bzrlib.branch import Branch
292
 
                Branch.open_containing(self.comm.get_path())
293
 
                m_add.set_sensitive(False)
294
 
                m_remove.set_sensitive(False)
295
 
                m_commit.set_sensitive(False)
296
 
                m_diff.set_sensitive(False)
297
 
            except errors.NotBranchError:
298
 
                m_add.set_sensitive(True)
299
 
                m_remove.set_sensitive(True)
300
 
                m_commit.set_sensitive(True)
301
 
                m_diff.set_sensitive(True)
302
 
            self.menu.right_context_menu().popup(None, None, None, 0,
303
 
                                                 event.time)
304
 
        
305
 
    def on_treeview_right_row_activated(self, treeview, path, view_column):
306
 
        """ Occurs when somebody double-clicks or enters an item in the
307
 
        file list. """
308
 
        import os.path
309
 
        
310
 
        newdir = self.comm.get_selected_right()
311
 
        
312
 
        if newdir == '..':
313
 
            self.comm.set_path(os.path.split(self.comm.get_path())[0])
314
 
        else:
315
 
            fullpath = self.comm.get_path() + '/' + newdir
316
 
            if os.path.isdir(fullpath):
317
 
                # selected item is an existant directory
318
 
                self.comm.set_path(fullpath)
319
 
            else:
320
 
                if sys.platform == 'win32':
321
 
                    # open the file with the default application
322
 
                    os.startfile(fullpath)
323
 
                else:
324
 
                    # TODO: support other OSes
325
 
                    print "DEBUG: double-click on non-Win32 platforms not supported."
326
 
        
327
 
        self.comm.refresh_right()
328
 
    
329
 
    def on_window_main_delete_event(self, widget, event=None):
330
 
        """ Do some stuff before exiting. """
331
 
        width, height = self.comm.window_main.get_size()
332
 
        self.comm.pref.set_preference('window_width', width)
333
 
        self.comm.pref.set_preference('window_height', height)
334
 
        x, y = self.comm.window_main.get_position()
335
 
        self.comm.pref.set_preference('window_x', x)
336
 
        self.comm.pref.set_preference('window_y', y)
337
 
        self.comm.pref.set_preference('paned_position',
338
 
                                      self.comm.hpaned_main.get_position())
339
 
        
340
 
        self.comm.pref.write()
341
 
        self.comm.window_main.destroy()
342
 
 
343
 
    def not_implemented(self, widget):
344
 
        """ Display a Not implemented error message. """
345
 
        self.dialog.error_dialog(_('We feel sorry'),
346
 
                                 _('This feature is not yet implemented.'))
347