/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 21:05:19 UTC
  • mto: (0.12.2 olive)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060927210519-7bc2662211808af5
Bunch of other small updates, add more items to 
the TODO list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
import os
17
18
import sys
18
19
 
19
20
try:
21
22
    pygtk.require("2.0")
22
23
except:
23
24
    pass
24
 
try:
25
 
    import gtk
26
 
    import gtk.glade
27
 
except:
28
 
    sys.exit(1)
29
 
 
30
 
from olive.backend.info import is_branch
31
 
import olive.backend.errors as errors
32
 
 
33
 
from dialog import OliveDialog
34
 
from menu import OliveMenu
 
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
35
34
from launch import launch
36
35
 
37
36
class OliveHandler:
38
37
    """ Signal handler class for Olive. """
39
 
    def __init__(self, gladefile, comm):
40
 
        self.gladefile = gladefile
41
 
        self.comm = comm
42
 
        
43
 
        self.dialog = OliveDialog(self.gladefile)
44
 
        
45
 
        self.menu = OliveMenu(self.gladefile, self.comm, self.dialog)
 
38
    def __init__(self, path):
 
39
        self.wt, self.path = WorkingTree.open_containing(path)
46
40
    
47
41
    def on_about_activate(self, widget):
48
 
        self.dialog.about()
 
42
        about()
49
43
        
50
44
    def on_menuitem_add_files_activate(self, widget):
51
45
        """ Add file(s)... menu handler. """
52
46
        from add import OliveAdd
53
 
        add = OliveAdd(self.gladefile, self.comm, self.dialog)
 
47
        add = OliveAdd(self.wt, self.path, self.comm.get_selected_right())
54
48
        add.display()
55
49
    
56
50
    def on_menuitem_branch_get_activate(self, widget):
57
51
        """ Branch/Get... menu handler. """
58
52
        from branch import OliveBranch
59
 
        branch = OliveBranch(self.gladefile, self.comm, self.dialog)
 
53
        branch = OliveBranch()
60
54
        branch.display()
61
55
    
62
56
    def on_menuitem_branch_checkout_activate(self, widget):
63
57
        """ Branch/Checkout... menu handler. """
64
58
        from checkout import OliveCheckout
65
 
        checkout = OliveCheckout(self.gladefile, self.comm, self.dialog)
 
59
        checkout = OliveCheckout()
66
60
        checkout.display()
67
61
    
68
62
    def on_menuitem_branch_commit_activate(self, widget):
69
63
        """ Branch/Commit... menu handler. """
70
64
        from commit import OliveCommit
71
 
        commit = OliveCommit(self.gladefile, self.comm, self.dialog)
 
65
        commit = OliveCommit(self.wt, self.path)
72
66
        commit.display()
73
67
    
74
68
    def on_menuitem_branch_missing_revisions_activate(self, widget):
75
69
        """ Branch/Missing revisions menu handler. """
76
 
        import olive.backend.update as update
77
 
        
78
 
        self.comm.set_busy(self.comm.window_main)
79
 
        
80
 
        try:
81
 
            ret = update.missing(self.comm.get_path())
82
 
        except errors.NotBranchError:
83
 
            self.dialog.error_dialog(_('Directory is not a branch'),
84
 
                                     _('You can perform this action only in a branch.'))
85
 
        except errors.ConnectionError:
86
 
            self.dialog.error_dialog(_('Connection error'),
87
 
                                     _('Cannot connect to remote location.\nPlease try again later.'))
88
 
        except errors.NoLocationKnown:
89
 
            self.dialog.error_dialog(_('Parent location is unknown'),
 
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'),
90
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
91
        else:
92
 
            if ret > 0:
93
 
                self.dialog.info_dialog(_('There are missing revisions'),
94
 
                                        _('%d revision(s) missing.') % ret)
95
 
            else:
96
 
                self.dialog.info_dialog(_('Local branch up to date'),
97
 
                                        _('There are no missing revisions.'))
98
 
        
99
 
        self.comm.set_busy(self.comm.window_main, False)
100
 
    
 
92
            info_dialog(_('Local branch up to date'),
 
93
                                    _('There are no missing revisions.'))
 
94
 
101
95
    def on_menuitem_branch_pull_activate(self, widget):
102
96
        """ Branch/Pull menu handler. """
103
 
        import olive.backend.update as update
104
 
        
105
 
        self.comm.set_busy(self.comm.window_main)
106
 
        
 
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
 
107
106
        try:
108
 
            ret = update.pull(self.comm.get_path())
 
107
            branch_from = Branch.open(location)
109
108
        except errors.NotBranchError:
110
 
            self.dialog.error_dialog(_('Directory is not a branch'),
 
109
            error_dialog(_('Directory is not a branch'),
111
110
                                     _('You can perform this action only in a branch.'))
112
 
        except errors.NoLocationKnown:
113
 
            self.dialog.error_dialog(_('Parent location is unknown'),
114
 
                                     _('Pulling is not possible until there is no parent location.'))
 
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)
115
118
        else:
116
 
            self.dialog.info_dialog(_('Pull successful'),
117
 
                                    _('%d revision(s) pulled.') % ret)
 
119
            branch_to.pull(branch_from)
118
120
        
119
 
        self.comm.set_busy(self.comm.window_main, False)
 
121
        info_dialog(_('Pull successful'), _('%d revision(s) pulled.') % ret)
120
122
    
121
123
    def on_menuitem_branch_push_activate(self, widget):
122
124
        """ Branch/Push... menu handler. """
123
125
        from push import OlivePush
124
 
        push = OlivePush(self.gladefile, self.comm, self.dialog)
 
126
        push = OlivePush(self.comm)
125
127
        push.display()
126
128
    
127
129
    def on_menuitem_branch_status_activate(self, widget):
128
130
        """ Branch/Status... menu handler. """
129
131
        from status import OliveStatus
130
 
        status = OliveStatus(self.gladefile, self.comm, self.dialog)
 
132
        status = OliveStatus(self.wt, self.path)
131
133
        status.display()
132
134
    
133
135
    def on_menuitem_branch_initialize_activate(self, widget):
134
136
        """ Initialize current directory. """
135
 
        import olive.backend.init as init
136
 
        
137
137
        try:
138
 
            init.init(self.comm.get_path())
 
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()
139
159
        except errors.AlreadyBranchError, errmsg:
140
 
            self.dialog.error_dialog(_('Directory is already a branch'),
 
160
            error_dialog(_('Directory is already a branch'),
141
161
                                     _('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
142
162
        except errors.BranchExistsWithoutWorkingTree, errmsg:
143
 
            self.dialog.error_dialog(_('Branch without a working tree'),
 
163
            error_dialog(_('Branch without a working tree'),
144
164
                                     _('The current directory (%s)\nis a branch without a working tree.') % errmsg)
145
 
        except:
146
 
            raise
147
165
        else:
148
 
            self.dialog.info_dialog(_('Ininialize successful'),
 
166
            info_dialog(_('Initialize successful'),
149
167
                                    _('Directory successfully initialized.'))
150
168
            self.comm.refresh_right()
151
169
        
152
170
    def on_menuitem_file_make_directory_activate(self, widget):
153
171
        """ File/Make directory... menu handler. """
154
172
        from mkdir import OliveMkdir
155
 
        mkdir = OliveMkdir(self.gladefile, self.comm, self.dialog)
 
173
        mkdir = OliveMkdir(self.comm)
156
174
        mkdir.display()
157
175
    
158
176
    def on_menuitem_file_move_activate(self, widget):
159
177
        """ File/Move... menu handler. """
160
178
        from move import OliveMove
161
 
        move = OliveMove(self.gladefile, self.comm, self.dialog)
 
179
        move = OliveMove(self.comm)
162
180
        move.display()
163
181
    
164
182
    def on_menuitem_file_rename_activate(self, widget):
165
183
        """ File/Rename... menu handler. """
166
184
        from rename import OliveRename
167
 
        rename = OliveRename(self.gladefile, self.comm, self.dialog)
 
185
        rename = OliveRename(self.comm)
168
186
        rename.display()
169
187
 
170
188
    def on_menuitem_remove_file_activate(self, widget):
171
189
        """ Remove (unversion) selected file. """
172
190
        from remove import OliveRemove
173
 
        remove = OliveRemove(self.gladefile, self.comm, self.dialog)
 
191
        remove = OliveRemove(self.comm)
174
192
        remove.display()
175
193
    
176
194
    def on_menuitem_stats_diff_activate(self, widget):
177
195
        """ Statistics/Differences... menu handler. """
178
 
        from diff import OliveDiff
179
 
        diff = OliveDiff(self.gladefile, self.comm, self.dialog)
180
 
        diff.display()
 
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()
181
201
    
182
202
    def on_menuitem_stats_infos_activate(self, widget):
183
203
        """ Statistics/Informations... menu handler. """
184
204
        from info import OliveInfo
185
 
        info = OliveInfo(self.gladefile, self.comm, self.dialog)
 
205
        info = OliveInfo(self.wt)
186
206
        info.display()
187
207
    
188
208
    def on_menuitem_stats_log_activate(self, widget):
189
209
        """ Statistics/Log... menu handler. """
190
 
        from log import OliveLog
191
 
        log = OliveLog(self.gladefile, self.comm, self.dialog)
192
 
        log.display()
 
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()
193
214
    
194
215
    def on_menuitem_view_refresh_activate(self, widget):
195
216
        """ View/Refresh menu handler. """
229
250
        if newdir == None:
230
251
            return
231
252
 
232
 
        self.comm.set_busy(treeview)
233
253
        self.comm.set_path(newdir)
234
254
        self.comm.refresh_right()
235
 
        self.comm.set_busy(treeview, False)
236
255
    
237
256
    def on_treeview_right_button_press_event(self, widget, event):
238
257
        """ Occurs when somebody right-clicks in the file list. """
243
262
            m_commit = self.menu.ui.get_widget('/context_right/commit')
244
263
            m_diff = self.menu.ui.get_widget('/context_right/diff')
245
264
            # check if we're in a branch
246
 
            if not is_branch(self.comm.get_path()):
 
265
            try:
 
266
                from bzrlib.branch import Branch
 
267
                Branch.open_containing(self.comm.get_path())
247
268
                m_add.set_sensitive(False)
248
269
                m_remove.set_sensitive(False)
249
270
                m_commit.set_sensitive(False)
250
271
                m_diff.set_sensitive(False)
251
 
            else:
 
272
            except errors.NotBranchError:
252
273
                m_add.set_sensitive(True)
253
274
                m_remove.set_sensitive(True)
254
275
                m_commit.set_sensitive(True)
289
310
        self.comm.pref.write()
290
311
        self.comm.window_main.destroy()
291
312
 
292
 
    def not_implemented(self, widget):
293
 
        """ Display a Not implemented error message. """
294
 
        self.dialog.error_dialog(_('We feel sorry'),
295
 
                                 _('This feature is not yet implemented.'))
296
313