/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-29 16:11:12 UTC
  • mfrom: (475.2.2 gtk)
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629161112-3j4zp0r0e7cv6cds
Merge Chad's progress bar in viz patch.

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