/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: Szilveszter Farkas (Phanatic)
  • Date: 2006-09-27 19:10:00 UTC
  • mto: (0.14.1 main)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: Szilveszter.Farkas@gmail.com-20060927191000-2b5382eda85d82e4
Fixed a context menu bug; set release date.

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
32
33
 
33
34
from dialog import OliveDialog
34
35
from menu import OliveMenu
 
36
from launch import launch
35
37
 
36
38
class OliveHandler:
37
39
    """ Signal handler class for Olive. """
70
72
        commit = OliveCommit(self.gladefile, self.comm, self.dialog)
71
73
        commit.display()
72
74
    
 
75
    def on_menuitem_branch_missing_revisions_activate(self, widget):
 
76
        """ Branch/Missing revisions menu handler. """
 
77
        
 
78
        self.comm.set_busy(self.comm.window_main)
 
79
        
 
80
        try:
 
81
            import bzrlib
 
82
            
 
83
            try:
 
84
                local_branch = Branch.open_containing(self.comm.get_path())[0]
 
85
            except NotBranchError:
 
86
                self.dialog.error_dialog(_('Directory is not a branch'),
 
87
                                         _('You can perform this action only in a branch.'))
 
88
                return
 
89
            
 
90
            other_branch = local_branch.get_parent()
 
91
            if other_branch is None:
 
92
                self.dialog.error_dialog(_('Parent location is unknown'),
 
93
                                         _('Cannot determine missing revisions if no parent location is known.'))
 
94
                return
 
95
            
 
96
            remote_branch = Branch.open(other_branch)
 
97
            
 
98
            if remote_branch.base == local_branch.base:
 
99
                remote_branch = local_branch
 
100
 
 
101
            ret = len(local_branch.missing_revisions(remote_branch))
 
102
 
 
103
            if ret > 0:
 
104
                self.dialog.info_dialog(_('There are missing revisions'),
 
105
                                        _('%d revision(s) missing.') % ret)
 
106
            else:
 
107
                self.dialog.info_dialog(_('Local branch up to date'),
 
108
                                        _('There are no missing revisions.'))
 
109
        finally:
 
110
            self.comm.set_busy(self.comm.window_main, False)
 
111
    
73
112
    def on_menuitem_branch_pull_activate(self, widget):
74
113
        """ Branch/Pull menu handler. """
75
 
        import olive.backend.update as update
76
114
        
77
115
        self.comm.set_busy(self.comm.window_main)
78
 
        
 
116
 
79
117
        try:
80
 
            ret = update.pull(self.comm.get_path())
81
 
        except errors.NotBranchError:
82
 
            self.dialog.error_dialog(_('Directory is not a branch'),
83
 
                                     _('You can perform this action only in a branch.'))
84
 
        except errors.NoLocationKnown:
85
 
            self.dialog.error_dialog(_('Parent location is unknown'),
86
 
                                     _('Pulling is not possible until there is no parent location.'))
87
 
        else:
 
118
            try:
 
119
                from bzrlib.workingtree import WorkingTree
 
120
                tree_to = WorkingTree.open_containing(self.comm.get_path())[0]
 
121
                branch_to = tree_to.branch
 
122
            except errors.NoWorkingTree:
 
123
                tree_to = None
 
124
                branch_to = Branch.open_containing(self.comm.get_path())[0]
 
125
            except errors.NotBranchError:
 
126
                 self.dialog.error_dialog(_('Directory is not a branch'),
 
127
                                         _('You can perform this action only in a branch.'))
 
128
 
 
129
            location = branch_to.get_parent()
 
130
            if location is None:
 
131
                self.dialog.error_dialog(_('Parent location is unknown'),
 
132
                                         _('Pulling is not possible until there is a parent location.'))
 
133
                return
 
134
 
 
135
            try:
 
136
                branch_from = Branch.open(location)
 
137
            except errors.NotBranchError:
 
138
                self.dialog.error_dialog(_('Directory is not a branch'),
 
139
                                         _('You can perform this action only in a branch.'))
 
140
 
 
141
            if branch_to.get_parent() is None:
 
142
                branch_to.set_parent(branch_from.base)
 
143
 
 
144
            old_rh = branch_to.revision_history()
 
145
            if tree_to is not None:
 
146
                tree_to.pull(branch_from)
 
147
            else:
 
148
                branch_to.pull(branch_from)
 
149
            
88
150
            self.dialog.info_dialog(_('Pull successful'),
89
151
                                    _('%d revision(s) pulled.') % ret)
90
 
        
91
 
        self.comm.set_busy(self.comm.window_main, False)
 
152
            
 
153
        finally:
 
154
            self.comm.set_busy(self.comm.window_main, False)
92
155
    
93
156
    def on_menuitem_branch_push_activate(self, widget):
94
157
        """ Branch/Push... menu handler. """
104
167
    
105
168
    def on_menuitem_branch_initialize_activate(self, widget):
106
169
        """ Initialize current directory. """
107
 
        import olive.backend.init as init
108
 
        
109
170
        try:
110
 
            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()
111
192
        except errors.AlreadyBranchError, errmsg:
112
193
            self.dialog.error_dialog(_('Directory is already a branch'),
113
194
                                     _('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
114
195
        except errors.BranchExistsWithoutWorkingTree, errmsg:
115
196
            self.dialog.error_dialog(_('Branch without a working tree'),
116
197
                                     _('The current directory (%s)\nis a branch without a working tree.') % errmsg)
117
 
        except:
118
 
            raise
119
198
        else:
120
 
            self.dialog.info_dialog(_('Ininialize successful'),
 
199
            self.dialog.info_dialog(_('Initialize successful'),
121
200
                                    _('Directory successfully initialized.'))
122
201
            self.comm.refresh_right()
123
202
        
186
265
    def on_treeview_left_button_press_event(self, widget, event):
187
266
        """ Occurs when somebody right-clicks in the bookmark list. """
188
267
        if event.button == 3:
 
268
            # Don't show context with nothing selected
 
269
            if self.comm.get_selected_left() == None:
 
270
                return
 
271
 
189
272
            self.menu.left_context_menu().popup(None, None, None, 0,
190
273
                                                event.time)
191
274
        
192
275
    def on_treeview_left_row_activated(self, treeview, path, view_column):
193
276
        """ Occurs when somebody double-clicks or enters an item in the
194
277
        bookmark list. """
 
278
 
 
279
        newdir = self.comm.get_selected_left()
 
280
        if newdir == None:
 
281
            return
 
282
 
195
283
        self.comm.set_busy(treeview)
196
 
        
197
 
        newdir = self.comm.get_selected_left()
198
284
        self.comm.set_path(newdir)
199
 
        
200
285
        self.comm.refresh_right()
201
 
        
202
286
        self.comm.set_busy(treeview, False)
203
287
    
204
288
    def on_treeview_right_button_press_event(self, widget, event):
210
294
            m_commit = self.menu.ui.get_widget('/context_right/commit')
211
295
            m_diff = self.menu.ui.get_widget('/context_right/diff')
212
296
            # check if we're in a branch
213
 
            if not is_branch(self.comm.get_path()):
 
297
            try:
 
298
                from bzrlib.branch import Branch
 
299
                Branch.open_containing(self.comm.get_path())
 
300
                m_add.set_sensitive(True)
 
301
                m_remove.set_sensitive(True)
 
302
                m_commit.set_sensitive(True)
 
303
                m_diff.set_sensitive(True)
 
304
            except errors.NotBranchError:
214
305
                m_add.set_sensitive(False)
215
306
                m_remove.set_sensitive(False)
216
307
                m_commit.set_sensitive(False)
217
308
                m_diff.set_sensitive(False)
218
 
            else:
219
 
                m_add.set_sensitive(True)
220
 
                m_remove.set_sensitive(True)
221
 
                m_commit.set_sensitive(True)
222
 
                m_diff.set_sensitive(True)
223
309
            self.menu.right_context_menu().popup(None, None, None, 0,
224
310
                                                 event.time)
225
311
        
233
319
        if newdir == '..':
234
320
            self.comm.set_path(os.path.split(self.comm.get_path())[0])
235
321
        else:
236
 
            fullpath = self.comm.get_path() + '/' + newdir
 
322
            fullpath = self.comm.get_path() + os.sep + newdir
237
323
            if os.path.isdir(fullpath):
238
324
                # selected item is an existant directory
239
325
                self.comm.set_path(fullpath)
240
326
            else:
241
 
                if sys.platform == 'win32':
242
 
                    # open the file with the default application
243
 
                    os.startfile(fullpath)
244
 
                else:
245
 
                    # TODO: support other OSes
246
 
                    print "DEBUG: double-click on non-Win32 platforms not supported."
 
327
                launch(fullpath) 
247
328
        
248
329
        self.comm.refresh_right()
249
330