/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: 2006-09-27 20:30:59 UTC
  • mto: (0.12.2 olive)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060927203059-85792ae0a81db524
Bunch of small fixes, cleanups and simplifications.

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