/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-28 06:35:56 UTC
  • mto: (0.12.2 olive)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060928063556-62ec354cb06ba38c
Update TODO
integrate the handle and communicator functions into a main class.

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