/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-06 00:23:46 UTC
  • mto: (0.8.83 merge)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060906002346-73aa11b52d4d7b96
Load plugins on startup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
except:
28
28
    sys.exit(1)
29
29
 
30
 
from olive.backend.info import is_branch
31
 
import olive.backend.errors as errors
 
30
import bzrlib.errors as errors
 
31
from bzrlib.branch import Branch
32
32
 
33
33
from dialog import OliveDialog
34
34
from menu import OliveMenu
35
 
from launch import launch
36
35
 
37
36
class OliveHandler:
38
37
    """ Signal handler class for Olive. """
73
72
    
74
73
    def on_menuitem_branch_missing_revisions_activate(self, widget):
75
74
        """ Branch/Missing revisions menu handler. """
76
 
        import olive.backend.update as update
77
75
        
78
76
        self.comm.set_busy(self.comm.window_main)
79
77
        
80
78
        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:
 
79
            import bzrlib
 
80
            
 
81
            try:
 
82
                local_branch = Branch.open_containing(self.comm.get_path())[0]
 
83
            except NotBranchError:
 
84
                self.dialog.error_dialog(_('Directory is not a branch'),
 
85
                                         _('You can perform this action only in a branch.'))
 
86
                return
 
87
            
 
88
            other_branch = local_branch.get_parent()
 
89
            if other_branch is None:
 
90
                self.dialog.error_dialog(_('Parent location is unknown'),
 
91
                                         _('Cannot determine missing revisions if no parent location is known.'))
 
92
                return
 
93
            
 
94
            remote_branch = Branch.open(other_branch)
 
95
            
 
96
            if remote_branch.base == local_branch.base:
 
97
                remote_branch = local_branch
 
98
 
 
99
            ret = len(local_branch.missing_revisions(remote_branch))
 
100
 
92
101
            if ret > 0:
93
102
                self.dialog.info_dialog(_('There are missing revisions'),
94
103
                                        _('%d revision(s) missing.') % ret)
95
104
            else:
96
105
                self.dialog.info_dialog(_('Local branch up to date'),
97
106
                                        _('There are no missing revisions.'))
98
 
        
99
 
        self.comm.set_busy(self.comm.window_main, False)
 
107
        finally:
 
108
            self.comm.set_busy(self.comm.window_main, False)
100
109
    
101
110
    def on_menuitem_branch_pull_activate(self, widget):
102
111
        """ Branch/Pull menu handler. """
103
 
        import olive.backend.update as update
104
112
        
105
113
        self.comm.set_busy(self.comm.window_main)
106
 
        
 
114
 
107
115
        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
            try:
 
117
                from bzrlib.workingtree import WorkingTree
 
118
                tree_to = WorkingTree.open_containing(self.comm.get_path())[0]
 
119
                branch_to = tree_to.branch
 
120
            except errors.NoWorkingTree:
 
121
                tree_to = None
 
122
                branch_to = Branch.open_containing(self.comm.get_path())[0]
 
123
            except errors.NotBranchError:
 
124
                 self.dialog.error_dialog(_('Directory is not a branch'),
 
125
                                         _('You can perform this action only in a branch.'))
 
126
 
 
127
            location = branch_to.get_parent()
 
128
            if location is None:
 
129
                self.dialog.error_dialog(_('Parent location is unknown'),
 
130
                                         _('Pulling is not possible until there is a parent location.'))
 
131
                return
 
132
 
 
133
            try:
 
134
                branch_from = Branch.open(location)
 
135
            except errors.NotBranchError:
 
136
                self.dialog.error_dialog(_('Directory is not a branch'),
 
137
                                         _('You can perform this action only in a branch.'))
 
138
 
 
139
            if branch_to.get_parent() is None:
 
140
                branch_to.set_parent(branch_from.base)
 
141
 
 
142
            old_rh = branch_to.revision_history()
 
143
            if tree_to is not None:
 
144
                tree_to.pull(branch_from)
 
145
            else:
 
146
                branch_to.pull(branch_from)
 
147
            
116
148
            self.dialog.info_dialog(_('Pull successful'),
117
149
                                    _('%d revision(s) pulled.') % ret)
118
 
        
119
 
        self.comm.set_busy(self.comm.window_main, False)
 
150
            
 
151
        finally:
 
152
            self.comm.set_busy(self.comm.window_main, False)
120
153
    
121
154
    def on_menuitem_branch_push_activate(self, widget):
122
155
        """ Branch/Push... menu handler. """
132
165
    
133
166
    def on_menuitem_branch_initialize_activate(self, widget):
134
167
        """ Initialize current directory. """
135
 
        import olive.backend.init as init
136
 
        
137
168
        try:
138
 
            init.init(self.comm.get_path())
 
169
            location = self.comm.get_path()
 
170
            from bzrlib.builtins import get_format_type
 
171
 
 
172
            format = get_format_type('default')
 
173
 
 
174
            if not os.path.exists(location):
 
175
                os.mkdir(location)
 
176
     
 
177
            try:
 
178
                existing_bzrdir = bzrdir.BzrDir.open(location)
 
179
            except NotBranchError:
 
180
                bzrdir.BzrDir.create_branch_convenience(location, format=format)
 
181
            else:
 
182
                if existing_bzrdir.has_branch():
 
183
                    if existing_bzrdir.has_workingtree():
 
184
                        raise AlreadyBranchError(location)
 
185
                    else:
 
186
                        raise BranchExistsWithoutWorkingTree(location)
 
187
                else:
 
188
                    existing_bzrdir.create_branch()
 
189
                    existing_bzrdir.create_workingtree()
139
190
        except errors.AlreadyBranchError, errmsg:
140
191
            self.dialog.error_dialog(_('Directory is already a branch'),
141
192
                                     _('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
142
193
        except errors.BranchExistsWithoutWorkingTree, errmsg:
143
194
            self.dialog.error_dialog(_('Branch without a working tree'),
144
195
                                     _('The current directory (%s)\nis a branch without a working tree.') % errmsg)
145
 
        except:
146
 
            raise
147
196
        else:
148
 
            self.dialog.info_dialog(_('Ininialize successful'),
 
197
            self.dialog.info_dialog(_('Initialize successful'),
149
198
                                    _('Directory successfully initialized.'))
150
199
            self.comm.refresh_right()
151
200
        
214
263
    def on_treeview_left_button_press_event(self, widget, event):
215
264
        """ Occurs when somebody right-clicks in the bookmark list. """
216
265
        if event.button == 3:
217
 
            # Don't show context with nothing selected
218
 
            if self.comm.get_selected_left() == None:
219
 
                return
220
 
 
221
266
            self.menu.left_context_menu().popup(None, None, None, 0,
222
267
                                                event.time)
223
268
        
224
269
    def on_treeview_left_row_activated(self, treeview, path, view_column):
225
270
        """ Occurs when somebody double-clicks or enters an item in the
226
271
        bookmark list. """
227
 
 
 
272
        self.comm.set_busy(treeview)
 
273
        
228
274
        newdir = self.comm.get_selected_left()
229
 
        if newdir == None:
230
 
            return
231
 
 
232
 
        self.comm.set_busy(treeview)
233
275
        self.comm.set_path(newdir)
 
276
        
234
277
        self.comm.refresh_right()
 
278
        
235
279
        self.comm.set_busy(treeview, False)
236
280
    
237
281
    def on_treeview_right_button_press_event(self, widget, event):
243
287
            m_commit = self.menu.ui.get_widget('/context_right/commit')
244
288
            m_diff = self.menu.ui.get_widget('/context_right/diff')
245
289
            # check if we're in a branch
246
 
            if not is_branch(self.comm.get_path()):
 
290
            try:
 
291
                from bzrlib.branch import Branch
 
292
                Branch.open_containing(self.comm.get_path())
247
293
                m_add.set_sensitive(False)
248
294
                m_remove.set_sensitive(False)
249
295
                m_commit.set_sensitive(False)
250
296
                m_diff.set_sensitive(False)
251
 
            else:
 
297
            except errors.NotBranchError:
252
298
                m_add.set_sensitive(True)
253
299
                m_remove.set_sensitive(True)
254
300
                m_commit.set_sensitive(True)
266
312
        if newdir == '..':
267
313
            self.comm.set_path(os.path.split(self.comm.get_path())[0])
268
314
        else:
269
 
            fullpath = self.comm.get_path() + os.sep + newdir
 
315
            fullpath = self.comm.get_path() + '/' + newdir
270
316
            if os.path.isdir(fullpath):
271
317
                # selected item is an existant directory
272
318
                self.comm.set_path(fullpath)
273
319
            else:
274
 
                launch(fullpath) 
 
320
                if sys.platform == 'win32':
 
321
                    # open the file with the default application
 
322
                    os.startfile(fullpath)
 
323
                else:
 
324
                    # TODO: support other OSes
 
325
                    print "DEBUG: double-click on non-Win32 platforms not supported."
275
326
        
276
327
        self.comm.refresh_right()
277
328