/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/commit.py

  • Committer: Jelmer Vernooij
  • Date: 2006-09-27 17:40:05 UTC
  • mto: (0.12.2 olive)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060927174005-5dfa27de4081ed19
Handle non-bzr unknown errors as well.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
import sys
 
18
 
 
19
try:
 
20
    import pygtk
 
21
    pygtk.require("2.0")
 
22
except:
 
23
    pass
 
24
try:
 
25
    import gtk
 
26
    import gtk.glade
 
27
    import gobject
 
28
    import pango
 
29
except:
 
30
    sys.exit(1)
 
31
 
 
32
from bzrlib import version_info
 
33
 
 
34
import bzrlib.errors as errors
 
35
from bzrlib.workingtree import WorkingTree
 
36
 
 
37
from dialog import error_dialog
 
38
 
 
39
class OliveCommit:
 
40
    """ Display Commit dialog and perform the needed actions. """
 
41
    def __init__(self, gladefile, wt, wtpath):
 
42
        """ Initialize the Commit dialog. """
 
43
        self.gladefile = gladefile
 
44
        self.glade = gtk.glade.XML(self.gladefile, 'window_commit', 'olive-gtk')
 
45
        
 
46
        self.wt = wt
 
47
        self.wtpath = wtpath
 
48
 
 
49
        # Get some important widgets
 
50
        self.window = self.glade.get_widget('window_commit')
 
51
        self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
 
52
        self.textview = self.glade.get_widget('textview_commit')
 
53
        self.file_view = self.glade.get_widget('treeview_commit_select')
 
54
 
 
55
        file_id = self.wt.path2id(wtpath)
 
56
 
 
57
        self.notbranch = False
 
58
        if file_id is None:
 
59
            self.notbranch = True
 
60
            return
 
61
        
 
62
        # Set the delta
 
63
        self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
 
64
        if version_info < (0, 9):
 
65
            self.delta = compare_trees(self.old_tree, self.wt)
 
66
        else:
 
67
            self.delta = self.wt.changes_from(self.old_tree)
 
68
        
 
69
        # Dictionary for signal_autoconnect
 
70
        dic = { "on_button_commit_commit_clicked": self.commit,
 
71
                "on_button_commit_cancel_clicked": self.close }
 
72
        
 
73
        # Connect the signals to the handlers
 
74
        self.glade.signal_autoconnect(dic)
 
75
        
 
76
        # Create the file list
 
77
        self._create_file_view()
 
78
    
 
79
    def display(self):
 
80
        """ Display the Push dialog. """
 
81
        if self.notbranch:
 
82
            error_dialog(_('Directory is not a branch'),
 
83
                                     _('You can perform this action only in a branch.'))
 
84
            self.close()
 
85
        else:
 
86
            if self.wt.branch.get_bound_location() is not None:
 
87
                # we have a checkout, so the local commit checkbox must appear
 
88
                self.checkbutton_local.show()
 
89
            
 
90
            self.textview.modify_font(pango.FontDescription("Monospace"))
 
91
            self.window.show()
 
92
            
 
93
    
 
94
    def _create_file_view(self):
 
95
        self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,
 
96
                                        gobject.TYPE_STRING,
 
97
                                        gobject.TYPE_STRING)
 
98
        self.file_view.set_model(self.file_store)
 
99
        crt = gtk.CellRendererToggle()
 
100
        crt.set_property("activatable", True)
 
101
        crt.connect("toggled", self._toggle_commit, self.file_store)
 
102
        self.file_view.append_column(gtk.TreeViewColumn(_('Commit'),
 
103
                                     crt, active=0))
 
104
        self.file_view.append_column(gtk.TreeViewColumn(_('Path'),
 
105
                                     gtk.CellRendererText(), text=1))
 
106
        self.file_view.append_column(gtk.TreeViewColumn(_('Type'),
 
107
                                     gtk.CellRendererText(), text=2))
 
108
 
 
109
        for path, id, kind in self.delta.added:
 
110
            self.file_store.append([ True, path, _('added') ])
 
111
 
 
112
        for path, id, kind in self.delta.removed:
 
113
            self.file_store.append([ True, path, _('removed') ])
 
114
 
 
115
        for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
 
116
            self.file_store.append([ True, oldpath, _('renamed') ])
 
117
 
 
118
        for path, id, kind, text_modified, meta_modified in self.delta.modified:
 
119
            self.file_store.append([ True, path, _('modified') ])
 
120
    
 
121
    def _get_specific_files(self):
 
122
        ret = []
 
123
        it = self.file_store.get_iter_first()
 
124
        while it:
 
125
            if self.file_store.get_value(it, 0):
 
126
                ret.append(self.file_store.get_value(it, 1))
 
127
            it = self.file_store.iter_next(it)
 
128
 
 
129
        return ret
 
130
    # end of bzr-gtk code
 
131
    
 
132
    def _toggle_commit(self, cell, path, model):
 
133
        model[path][0] = not model[path][0]
 
134
        return
 
135
    
 
136
    def commit(self, widget):
 
137
        textbuffer = self.textview.get_buffer()
 
138
        start, end = textbuffer.get_bounds()
 
139
        message = textbuffer.get_text(start, end)
 
140
        
 
141
        checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
 
142
        checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
 
143
        
 
144
        specific_files = self._get_specific_files()
 
145
        
 
146
        try:
 
147
            self.wt.commit(message, 
 
148
                           allow_pointless=checkbutton_force.get_active(),
 
149
                           strict=checkbutton_strict.get_active(),
 
150
                           local=self.checkbutton_local.get_active(),
 
151
                           specific_files=specific_files)
 
152
        except errors.NotBranchError:
 
153
            error_dialog(_('Directory is not a branch'),
 
154
                                     _('You can perform this action only in a branch.'))
 
155
            return
 
156
        except errors.LocalRequiresBoundBranch:
 
157
            error_dialog(_('Directory is not a checkout'),
 
158
                                     _('You can perform local commit only on checkouts.'))
 
159
            return
 
160
        except errors.PointlessCommit:
 
161
            error_dialog(_('No changes to commit'),
 
162
                                     _('Try force commit if you want to commit anyway.'))
 
163
            return
 
164
        except errors.ConflictsInTree:
 
165
            error_dialog(_('Conflicts in tree'),
 
166
                                     _('You need to resolve the conflicts before committing.'))
 
167
            return
 
168
        except errors.StrictCommitFailed:
 
169
            error_dialog(_('Strict commit failed'),
 
170
                                     _('There are unknown files in the working tree.\nPlease add or delete them.'))
 
171
            return
 
172
        except errors.BoundBranchOutOfDate, errmsg:
 
173
            error_dialog(_('Bound branch is out of date'),
 
174
                                     _('%s') % errmsg)
 
175
            return
 
176
        except errors.BzrError, msg:
 
177
            error_dialog(_('Unknown bzr error'), str(msg))
 
178
            return
 
179
        except Exception, msg:
 
180
            error_dialog(_('Unknown error'), str(msg))
 
181
            return
 
182
        
 
183
        self.close()
 
184
        self.comm.refresh_right()
 
185
        
 
186
    def close(self, widget=None):
 
187
        self.window.destroy()