/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 18:12:29 UTC
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629181229-1l2m4cf7vvbyh8qg
Simplify progress bar code, use embedded progress bar inside viz window.

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