/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 18:08:35 UTC
  • mto: (0.12.2 olive)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060927180835-4c295d9bb936623a
Turn some windows into dialogs.
Remove the diffwindow code from olive, 
switched to using the one from bzr-gtk instead.

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:
27
28
except:
28
29
    sys.exit(1)
29
30
 
30
 
from olive.backend.info import is_branch
31
 
import olive.backend.errors as errors
 
31
import bzrlib.errors as errors
 
32
from bzrlib.branch import Branch
 
33
from bzrlib.workingtree import WorkingTree
32
34
 
33
 
from dialog import OliveDialog
 
35
from dialog import about, error_dialog, info_dialog
34
36
from menu import OliveMenu
35
37
from launch import launch
36
38
 
40
42
        self.gladefile = gladefile
41
43
        self.comm = comm
42
44
        
43
 
        self.dialog = OliveDialog(self.gladefile)
44
 
        
45
 
        self.menu = OliveMenu(self.gladefile, self.comm, self.dialog)
 
45
        self.menu = OliveMenu(self.gladefile, self.comm)
46
46
    
47
47
    def on_about_activate(self, widget):
48
 
        self.dialog.about()
 
48
        about()
49
49
        
50
50
    def on_menuitem_add_files_activate(self, widget):
51
51
        """ Add file(s)... menu handler. """
52
52
        from add import OliveAdd
53
 
        add = OliveAdd(self.gladefile, self.comm, self.dialog)
 
53
        wt, path = WorkingTree.open_containing(self.comm.get_path())
 
54
        add = OliveAdd(self.gladefile, wt, path, 
 
55
                self.comm.get_selected_right())
54
56
        add.display()
55
57
    
56
58
    def on_menuitem_branch_get_activate(self, widget):
57
59
        """ Branch/Get... menu handler. """
58
60
        from branch import OliveBranch
59
 
        branch = OliveBranch(self.gladefile, self.comm, self.dialog)
 
61
        branch = OliveBranch(self.gladefile, self.comm)
60
62
        branch.display()
61
63
    
62
64
    def on_menuitem_branch_checkout_activate(self, widget):
63
65
        """ Branch/Checkout... menu handler. """
64
66
        from checkout import OliveCheckout
65
 
        checkout = OliveCheckout(self.gladefile, self.comm, self.dialog)
 
67
        checkout = OliveCheckout(self.gladefile, self.comm)
66
68
        checkout.display()
67
69
    
68
70
    def on_menuitem_branch_commit_activate(self, widget):
69
71
        """ Branch/Commit... menu handler. """
70
72
        from commit import OliveCommit
71
 
        commit = OliveCommit(self.gladefile, self.comm, self.dialog)
 
73
        wt, path = WorkingTree.open_containing(self.comm.get_path())
 
74
        commit = OliveCommit(self.gladefile, wt, path)
72
75
        commit.display()
73
76
    
74
77
    def on_menuitem_branch_missing_revisions_activate(self, widget):
75
78
        """ Branch/Missing revisions menu handler. """
76
 
        import olive.backend.update as update
77
79
        
78
80
        self.comm.set_busy(self.comm.window_main)
79
81
        
80
82
        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'),
90
 
                                     _('Cannot determine missing revisions if no parent location is known.'))
91
 
        else:
 
83
            import bzrlib
 
84
            
 
85
            try:
 
86
                local_branch = Branch.open_containing(self.comm.get_path())[0]
 
87
            except NotBranchError:
 
88
                error_dialog(_('Directory is not a branch'),
 
89
                                         _('You can perform this action only in a branch.'))
 
90
                return
 
91
            
 
92
            other_branch = local_branch.get_parent()
 
93
            if other_branch is None:
 
94
                error_dialog(_('Parent location is unknown'),
 
95
                                         _('Cannot determine missing revisions if no parent location is known.'))
 
96
                return
 
97
            
 
98
            remote_branch = Branch.open(other_branch)
 
99
            
 
100
            if remote_branch.base == local_branch.base:
 
101
                remote_branch = local_branch
 
102
 
 
103
            ret = len(local_branch.missing_revisions(remote_branch))
 
104
 
92
105
            if ret > 0:
93
 
                self.dialog.info_dialog(_('There are missing revisions'),
 
106
                info_dialog(_('There are missing revisions'),
94
107
                                        _('%d revision(s) missing.') % ret)
95
108
            else:
96
 
                self.dialog.info_dialog(_('Local branch up to date'),
 
109
                info_dialog(_('Local branch up to date'),
97
110
                                        _('There are no missing revisions.'))
98
 
        
99
 
        self.comm.set_busy(self.comm.window_main, False)
 
111
        finally:
 
112
            self.comm.set_busy(self.comm.window_main, False)
100
113
    
101
114
    def on_menuitem_branch_pull_activate(self, widget):
102
115
        """ Branch/Pull menu handler. """
103
 
        import olive.backend.update as update
104
116
        
105
117
        self.comm.set_busy(self.comm.window_main)
106
 
        
 
118
 
107
119
        try:
108
 
            ret = update.pull(self.comm.get_path())
109
 
        except errors.NotBranchError:
110
 
            self.dialog.error_dialog(_('Directory is not a branch'),
111
 
                                     _('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.'))
115
 
        else:
116
 
            self.dialog.info_dialog(_('Pull successful'),
 
120
            try:
 
121
                from bzrlib.workingtree import WorkingTree
 
122
                tree_to = WorkingTree.open_containing(self.comm.get_path())[0]
 
123
                branch_to = tree_to.branch
 
124
            except errors.NoWorkingTree:
 
125
                tree_to = None
 
126
                branch_to = Branch.open_containing(self.comm.get_path())[0]
 
127
            except errors.NotBranchError:
 
128
                 error_dialog(_('Directory is not a branch'),
 
129
                                         _('You can perform this action only in a branch.'))
 
130
 
 
131
            location = branch_to.get_parent()
 
132
            if location is None:
 
133
                error_dialog(_('Parent location is unknown'),
 
134
                                         _('Pulling is not possible until there is a parent location.'))
 
135
                return
 
136
 
 
137
            try:
 
138
                branch_from = Branch.open(location)
 
139
            except errors.NotBranchError:
 
140
                error_dialog(_('Directory is not a branch'),
 
141
                                         _('You can perform this action only in a branch.'))
 
142
 
 
143
            if branch_to.get_parent() is None:
 
144
                branch_to.set_parent(branch_from.base)
 
145
 
 
146
            old_rh = branch_to.revision_history()
 
147
            if tree_to is not None:
 
148
                tree_to.pull(branch_from)
 
149
            else:
 
150
                branch_to.pull(branch_from)
 
151
            
 
152
            info_dialog(_('Pull successful'),
117
153
                                    _('%d revision(s) pulled.') % ret)
118
 
        
119
 
        self.comm.set_busy(self.comm.window_main, False)
 
154
            
 
155
        finally:
 
156
            self.comm.set_busy(self.comm.window_main, False)
120
157
    
121
158
    def on_menuitem_branch_push_activate(self, widget):
122
159
        """ Branch/Push... menu handler. """
123
160
        from push import OlivePush
124
 
        push = OlivePush(self.gladefile, self.comm, self.dialog)
 
161
        push = OlivePush(self.gladefile, self.comm)
125
162
        push.display()
126
163
    
127
164
    def on_menuitem_branch_status_activate(self, widget):
128
165
        """ Branch/Status... menu handler. """
129
166
        from status import OliveStatus
130
 
        status = OliveStatus(self.gladefile, self.comm, self.dialog)
 
167
        wt, wtpath = WorkingTree.open_containing(self.comm.get_path())
 
168
        status = OliveStatus(self.gladefile, wt, wtpath)
131
169
        status.display()
132
170
    
133
171
    def on_menuitem_branch_initialize_activate(self, widget):
134
172
        """ Initialize current directory. """
135
 
        import olive.backend.init as init
136
 
        
137
173
        try:
138
 
            init.init(self.comm.get_path())
 
174
            location = self.comm.get_path()
 
175
            from bzrlib.builtins import get_format_type
 
176
 
 
177
            format = get_format_type('default')
 
178
 
 
179
            if not os.path.exists(location):
 
180
                os.mkdir(location)
 
181
     
 
182
            try:
 
183
                existing_bzrdir = bzrdir.BzrDir.open(location)
 
184
            except NotBranchError:
 
185
                bzrdir.BzrDir.create_branch_convenience(location, format=format)
 
186
            else:
 
187
                if existing_bzrdir.has_branch():
 
188
                    if existing_bzrdir.has_workingtree():
 
189
                        raise AlreadyBranchError(location)
 
190
                    else:
 
191
                        raise BranchExistsWithoutWorkingTree(location)
 
192
                else:
 
193
                    existing_bzrdir.create_branch()
 
194
                    existing_bzrdir.create_workingtree()
139
195
        except errors.AlreadyBranchError, errmsg:
140
 
            self.dialog.error_dialog(_('Directory is already a branch'),
 
196
            error_dialog(_('Directory is already a branch'),
141
197
                                     _('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
142
198
        except errors.BranchExistsWithoutWorkingTree, errmsg:
143
 
            self.dialog.error_dialog(_('Branch without a working tree'),
 
199
            error_dialog(_('Branch without a working tree'),
144
200
                                     _('The current directory (%s)\nis a branch without a working tree.') % errmsg)
145
 
        except:
146
 
            raise
147
201
        else:
148
 
            self.dialog.info_dialog(_('Ininialize successful'),
 
202
            info_dialog(_('Initialize successful'),
149
203
                                    _('Directory successfully initialized.'))
150
204
            self.comm.refresh_right()
151
205
        
152
206
    def on_menuitem_file_make_directory_activate(self, widget):
153
207
        """ File/Make directory... menu handler. """
154
208
        from mkdir import OliveMkdir
155
 
        mkdir = OliveMkdir(self.gladefile, self.comm, self.dialog)
 
209
        mkdir = OliveMkdir(self.gladefile, self.comm)
156
210
        mkdir.display()
157
211
    
158
212
    def on_menuitem_file_move_activate(self, widget):
159
213
        """ File/Move... menu handler. """
160
214
        from move import OliveMove
161
 
        move = OliveMove(self.gladefile, self.comm, self.dialog)
 
215
        move = OliveMove(self.gladefile, self.comm)
162
216
        move.display()
163
217
    
164
218
    def on_menuitem_file_rename_activate(self, widget):
165
219
        """ File/Rename... menu handler. """
166
220
        from rename import OliveRename
167
 
        rename = OliveRename(self.gladefile, self.comm, self.dialog)
 
221
        rename = OliveRename(self.gladefile, self.comm)
168
222
        rename.display()
169
223
 
170
224
    def on_menuitem_remove_file_activate(self, widget):
171
225
        """ Remove (unversion) selected file. """
172
226
        from remove import OliveRemove
173
 
        remove = OliveRemove(self.gladefile, self.comm, self.dialog)
 
227
        remove = OliveRemove(self.gladefile, self.comm)
174
228
        remove.display()
175
229
    
176
230
    def on_menuitem_stats_diff_activate(self, widget):
177
231
        """ Statistics/Differences... menu handler. """
178
 
        from diff import OliveDiff
179
 
        diff = OliveDiff(self.gladefile, self.comm, self.dialog)
180
 
        diff.display()
 
232
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
 
233
        window = DiffWindow()
 
234
        wt = WorkingTree.open_containing(self.comm.get_path())[0]
 
235
        parent_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
 
236
        window.set_diff(wt.branch.nick, wt, parent_tree)
 
237
        window.show()
181
238
    
182
239
    def on_menuitem_stats_infos_activate(self, widget):
183
240
        """ Statistics/Informations... menu handler. """
184
241
        from info import OliveInfo
185
 
        info = OliveInfo(self.gladefile, self.comm, self.dialog)
 
242
        info = OliveInfo(self.gladefile, self.comm)
186
243
        info.display()
187
244
    
188
245
    def on_menuitem_stats_log_activate(self, widget):
189
246
        """ Statistics/Log... menu handler. """
190
247
        from log import OliveLog
191
 
        log = OliveLog(self.gladefile, self.comm, self.dialog)
 
248
        log = OliveLog(self.gladefile, self.comm)
192
249
        log.display()
193
250
    
194
251
    def on_menuitem_view_refresh_activate(self, widget):
243
300
            m_commit = self.menu.ui.get_widget('/context_right/commit')
244
301
            m_diff = self.menu.ui.get_widget('/context_right/diff')
245
302
            # check if we're in a branch
246
 
            if not is_branch(self.comm.get_path()):
 
303
            try:
 
304
                from bzrlib.branch import Branch
 
305
                Branch.open_containing(self.comm.get_path())
247
306
                m_add.set_sensitive(False)
248
307
                m_remove.set_sensitive(False)
249
308
                m_commit.set_sensitive(False)
250
309
                m_diff.set_sensitive(False)
251
 
            else:
 
310
            except errors.NotBranchError:
252
311
                m_add.set_sensitive(True)
253
312
                m_remove.set_sensitive(True)
254
313
                m_commit.set_sensitive(True)
289
348
        self.comm.pref.write()
290
349
        self.comm.window_main.destroy()
291
350
 
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
351