/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 19:52:46 UTC
  • mto: (0.12.2 olive)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060927195246-9354d7ccf56127f5
Don't pass around gladefile all the time. 
Fix bug in status information when files have been removed.

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
 
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
34
from menu import OliveMenu
35
35
from launch import launch
36
36
 
37
37
class OliveHandler:
38
38
    """ Signal handler class for Olive. """
39
 
    def __init__(self, gladefile, comm):
40
 
        self.gladefile = gladefile
 
39
    def __init__(self,  comm):
41
40
        self.comm = comm
42
41
        
43
 
        self.dialog = OliveDialog(self.gladefile)
44
 
        
45
 
        self.menu = OliveMenu(self.gladefile, self.comm, self.dialog)
 
42
        self.menu = OliveMenu(self.comm)
46
43
    
47
44
    def on_about_activate(self, widget):
48
 
        self.dialog.about()
 
45
        about()
49
46
        
50
47
    def on_menuitem_add_files_activate(self, widget):
51
48
        """ Add file(s)... menu handler. """
52
49
        from add import OliveAdd
53
 
        add = OliveAdd(self.gladefile, self.comm, self.dialog)
 
50
        wt, path = WorkingTree.open_containing(self.comm.get_path())
 
51
        add = OliveAdd(wt, path, 
 
52
                self.comm.get_selected_right())
54
53
        add.display()
55
54
    
56
55
    def on_menuitem_branch_get_activate(self, widget):
57
56
        """ Branch/Get... menu handler. """
58
57
        from branch import OliveBranch
59
 
        branch = OliveBranch(self.gladefile, self.comm, self.dialog)
 
58
        branch = OliveBranch(self.comm)
60
59
        branch.display()
61
60
    
62
61
    def on_menuitem_branch_checkout_activate(self, widget):
63
62
        """ Branch/Checkout... menu handler. """
64
63
        from checkout import OliveCheckout
65
 
        checkout = OliveCheckout(self.gladefile, self.comm, self.dialog)
 
64
        checkout = OliveCheckout(self.comm)
66
65
        checkout.display()
67
66
    
68
67
    def on_menuitem_branch_commit_activate(self, widget):
69
68
        """ Branch/Commit... menu handler. """
70
69
        from commit import OliveCommit
71
 
        commit = OliveCommit(self.gladefile, self.comm, self.dialog)
 
70
        wt, path = WorkingTree.open_containing(self.comm.get_path())
 
71
        commit = OliveCommit(wt, path)
72
72
        commit.display()
73
73
    
74
74
    def on_menuitem_branch_missing_revisions_activate(self, widget):
75
75
        """ Branch/Missing revisions menu handler. """
76
 
        import olive.backend.update as update
77
76
        
78
77
        self.comm.set_busy(self.comm.window_main)
79
78
        
80
79
        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:
 
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
 
92
102
            if ret > 0:
93
 
                self.dialog.info_dialog(_('There are missing revisions'),
 
103
                info_dialog(_('There are missing revisions'),
94
104
                                        _('%d revision(s) missing.') % ret)
95
105
            else:
96
 
                self.dialog.info_dialog(_('Local branch up to date'),
 
106
                info_dialog(_('Local branch up to date'),
97
107
                                        _('There are no missing revisions.'))
98
 
        
99
 
        self.comm.set_busy(self.comm.window_main, False)
 
108
        finally:
 
109
            self.comm.set_busy(self.comm.window_main, False)
100
110
    
101
111
    def on_menuitem_branch_pull_activate(self, widget):
102
112
        """ Branch/Pull menu handler. """
103
 
        import olive.backend.update as update
104
113
        
105
114
        self.comm.set_busy(self.comm.window_main)
106
 
        
 
115
 
107
116
        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'),
 
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'),
117
150
                                    _('%d revision(s) pulled.') % ret)
118
 
        
119
 
        self.comm.set_busy(self.comm.window_main, False)
 
151
            
 
152
        finally:
 
153
            self.comm.set_busy(self.comm.window_main, False)
120
154
    
121
155
    def on_menuitem_branch_push_activate(self, widget):
122
156
        """ Branch/Push... menu handler. """
123
157
        from push import OlivePush
124
 
        push = OlivePush(self.gladefile, self.comm, self.dialog)
 
158
        push = OlivePush(self.comm)
125
159
        push.display()
126
160
    
127
161
    def on_menuitem_branch_status_activate(self, widget):
128
162
        """ Branch/Status... menu handler. """
129
163
        from status import OliveStatus
130
 
        status = OliveStatus(self.gladefile, self.comm, self.dialog)
 
164
        wt, wtpath = WorkingTree.open_containing(self.comm.get_path())
 
165
        status = OliveStatus(wt, wtpath)
131
166
        status.display()
132
167
    
133
168
    def on_menuitem_branch_initialize_activate(self, widget):
134
169
        """ Initialize current directory. """
135
 
        import olive.backend.init as init
136
 
        
137
170
        try:
138
 
            init.init(self.comm.get_path())
 
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()
139
192
        except errors.AlreadyBranchError, errmsg:
140
 
            self.dialog.error_dialog(_('Directory is already a branch'),
 
193
            error_dialog(_('Directory is already a branch'),
141
194
                                     _('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
142
195
        except errors.BranchExistsWithoutWorkingTree, errmsg:
143
 
            self.dialog.error_dialog(_('Branch without a working tree'),
 
196
            error_dialog(_('Branch without a working tree'),
144
197
                                     _('The current directory (%s)\nis a branch without a working tree.') % errmsg)
145
 
        except:
146
 
            raise
147
198
        else:
148
 
            self.dialog.info_dialog(_('Ininialize successful'),
 
199
            info_dialog(_('Initialize successful'),
149
200
                                    _('Directory successfully initialized.'))
150
201
            self.comm.refresh_right()
151
202
        
152
203
    def on_menuitem_file_make_directory_activate(self, widget):
153
204
        """ File/Make directory... menu handler. """
154
205
        from mkdir import OliveMkdir
155
 
        mkdir = OliveMkdir(self.gladefile, self.comm, self.dialog)
 
206
        mkdir = OliveMkdir(self.comm)
156
207
        mkdir.display()
157
208
    
158
209
    def on_menuitem_file_move_activate(self, widget):
159
210
        """ File/Move... menu handler. """
160
211
        from move import OliveMove
161
 
        move = OliveMove(self.gladefile, self.comm, self.dialog)
 
212
        move = OliveMove(self.comm)
162
213
        move.display()
163
214
    
164
215
    def on_menuitem_file_rename_activate(self, widget):
165
216
        """ File/Rename... menu handler. """
166
217
        from rename import OliveRename
167
 
        rename = OliveRename(self.gladefile, self.comm, self.dialog)
 
218
        rename = OliveRename(self.comm)
168
219
        rename.display()
169
220
 
170
221
    def on_menuitem_remove_file_activate(self, widget):
171
222
        """ Remove (unversion) selected file. """
172
223
        from remove import OliveRemove
173
 
        remove = OliveRemove(self.gladefile, self.comm, self.dialog)
 
224
        remove = OliveRemove(self.comm)
174
225
        remove.display()
175
226
    
176
227
    def on_menuitem_stats_diff_activate(self, widget):
177
228
        """ Statistics/Differences... menu handler. """
178
 
        from diff import OliveDiff
179
 
        diff = OliveDiff(self.gladefile, self.comm, self.dialog)
180
 
        diff.display()
 
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()
181
235
    
182
236
    def on_menuitem_stats_infos_activate(self, widget):
183
237
        """ Statistics/Informations... menu handler. """
184
238
        from info import OliveInfo
185
 
        info = OliveInfo(self.gladefile, self.comm, self.dialog)
 
239
        info = OliveInfo(self.comm)
186
240
        info.display()
187
241
    
188
242
    def on_menuitem_stats_log_activate(self, widget):
189
243
        """ Statistics/Log... menu handler. """
190
244
        from log import OliveLog
191
 
        log = OliveLog(self.gladefile, self.comm, self.dialog)
 
245
        log = OliveLog(self.comm)
192
246
        log.display()
193
247
    
194
248
    def on_menuitem_view_refresh_activate(self, widget):
243
297
            m_commit = self.menu.ui.get_widget('/context_right/commit')
244
298
            m_diff = self.menu.ui.get_widget('/context_right/diff')
245
299
            # check if we're in a branch
246
 
            if not is_branch(self.comm.get_path()):
 
300
            try:
 
301
                from bzrlib.branch import Branch
 
302
                Branch.open_containing(self.comm.get_path())
247
303
                m_add.set_sensitive(False)
248
304
                m_remove.set_sensitive(False)
249
305
                m_commit.set_sensitive(False)
250
306
                m_diff.set_sensitive(False)
251
 
            else:
 
307
            except errors.NotBranchError:
252
308
                m_add.set_sensitive(True)
253
309
                m_remove.set_sensitive(True)
254
310
                m_commit.set_sensitive(True)
289
345
        self.comm.pref.write()
290
346
        self.comm.window_main.destroy()
291
347
 
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
348