/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
2
#
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
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.
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
7
#
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
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.
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
12
#
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
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
try:
18
    import pygtk
19
    pygtk.require("2.0")
20
except:
21
    pass
0.8.98 by Szilveszter Farkas (Phanatic)
Loads of fixes. Pyflakes cleanup.
22
0.13.11 by Jelmer Vernooij
Bunch of small fixes, cleanups and simplifications.
23
import gtk
24
import gtk.glade
25
import gobject
26
import pango
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
27
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
28
import bzrlib.errors as errors
29
0.13.3 by Jelmer Vernooij
Start removing dialog context (it's not required).
30
from dialog import error_dialog
93.1.6 by Alexander Belchenko
detecting name of glade file doing in separate module (olive.gladefile)
31
from gladefile import GLADEFILENAME
32
0.13.3 by Jelmer Vernooij
Start removing dialog context (it's not required).
33
89 by Jelmer Vernooij
Rename OliveBranch -> BranchDialog.
34
class CommitDialog:
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
35
    """ Display Commit dialog and perform the needed actions. """
0.13.10 by Jelmer Vernooij
Don't pass around gladefile all the time.
36
    def __init__(self, wt, wtpath):
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
37
        """ Initialize the Commit dialog. """
93.1.6 by Alexander Belchenko
detecting name of glade file doing in separate module (olive.gladefile)
38
        self.glade = gtk.glade.XML(GLADEFILENAME, 'window_commit', 'olive-gtk')
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
39
        
0.13.1 by Jelmer Vernooij
Remove communicator use from Commit.
40
        self.wt = wt
41
        self.wtpath = wtpath
42
0.8.55 by Szilveszter Farkas (Phanatic)
Gettext support added.
43
        # Get some important widgets
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
44
        self.window = self.glade.get_widget('window_commit')
0.8.55 by Szilveszter Farkas (Phanatic)
Gettext support added.
45
        self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
46
        self.textview = self.glade.get_widget('textview_commit')
47
        self.file_view = self.glade.get_widget('treeview_commit_select')
95 by Szilveszter Farkas (Phanatic)
Added pending merges to Commit dialog. Fixed bug #66091.
48
        self.pending_label = self.glade.get_widget('label_commit_pending')
49
        self.pending_view = self.glade.get_widget('treeview_commit_pending')
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
50
0.13.1 by Jelmer Vernooij
Remove communicator use from Commit.
51
        file_id = self.wt.path2id(wtpath)
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
52
53
        self.notbranch = False
54
        if file_id is None:
55
            self.notbranch = True
56
            return
57
        
58
        # Set the delta
59
        self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
0.13.6 by Jelmer Vernooij
Don't pass along dialog context everywhere.
60
        self.delta = self.wt.changes_from(self.old_tree)
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
61
        
95 by Szilveszter Farkas (Phanatic)
Added pending merges to Commit dialog. Fixed bug #66091.
62
        # Get pending merges
63
        self.pending = self._pending_merges(self.wt)
64
        
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
65
        # Dictionary for signal_autoconnect
66
        dic = { "on_button_commit_commit_clicked": self.commit,
67
                "on_button_commit_cancel_clicked": self.close }
68
        
69
        # Connect the signals to the handlers
70
        self.glade.signal_autoconnect(dic)
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
71
        
72
        # Create the file list
73
        self._create_file_view()
95 by Szilveszter Farkas (Phanatic)
Added pending merges to Commit dialog. Fixed bug #66091.
74
        # Create the pending merges
75
        self._create_pending_merges()
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
76
    
77
    def display(self):
78
        """ Display the Push dialog. """
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
79
        if self.notbranch:
0.13.3 by Jelmer Vernooij
Start removing dialog context (it's not required).
80
            error_dialog(_('Directory is not a branch'),
0.8.98 by Szilveszter Farkas (Phanatic)
Loads of fixes. Pyflakes cleanup.
81
                         _('You can perform this action only in a branch.'))
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
82
            self.close()
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
83
        else:
0.13.1 by Jelmer Vernooij
Remove communicator use from Commit.
84
            if self.wt.branch.get_bound_location() is not None:
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
85
                # we have a checkout, so the local commit checkbox must appear
86
                self.checkbutton_local.show()
87
            
95 by Szilveszter Farkas (Phanatic)
Added pending merges to Commit dialog. Fixed bug #66091.
88
            if self.pending:
89
                # There are pending merges, file selection not supported
90
                self.file_view.set_sensitive(False)
91
            else:
92
                # No pending merges
93
                self.pending_view.set_sensitive(False)
94
            
0.8.26 by Szilveszter Farkas (Phanatic)
Implemented Diff window; added menu.py (was missing from last commit)
95
            self.textview.modify_font(pango.FontDescription("Monospace"))
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
96
            self.window.show()
97
            
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
98
    
99
    def _create_file_view(self):
0.8.21 by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
100
        self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,
101
                                        gobject.TYPE_STRING,
102
                                        gobject.TYPE_STRING)
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
103
        self.file_view.set_model(self.file_store)
104
        crt = gtk.CellRendererToggle()
105
        crt.set_property("activatable", True)
106
        crt.connect("toggled", self._toggle_commit, self.file_store)
0.8.55 by Szilveszter Farkas (Phanatic)
Gettext support added.
107
        self.file_view.append_column(gtk.TreeViewColumn(_('Commit'),
0.8.21 by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
108
                                     crt, active=0))
0.8.55 by Szilveszter Farkas (Phanatic)
Gettext support added.
109
        self.file_view.append_column(gtk.TreeViewColumn(_('Path'),
0.8.21 by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
110
                                     gtk.CellRendererText(), text=1))
0.8.55 by Szilveszter Farkas (Phanatic)
Gettext support added.
111
        self.file_view.append_column(gtk.TreeViewColumn(_('Type'),
0.8.21 by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
112
                                     gtk.CellRendererText(), text=2))
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
113
0.8.55 by Szilveszter Farkas (Phanatic)
Gettext support added.
114
        for path, id, kind in self.delta.added:
115
            self.file_store.append([ True, path, _('added') ])
116
117
        for path, id, kind in self.delta.removed:
118
            self.file_store.append([ True, path, _('removed') ])
119
120
        for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
121
            self.file_store.append([ True, oldpath, _('renamed') ])
122
123
        for path, id, kind, text_modified, meta_modified in self.delta.modified:
124
            self.file_store.append([ True, path, _('modified') ])
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
125
    
95 by Szilveszter Farkas (Phanatic)
Added pending merges to Commit dialog. Fixed bug #66091.
126
    def _create_pending_merges(self):
127
        liststore = gtk.ListStore(gobject.TYPE_STRING,
128
                                  gobject.TYPE_STRING,
129
                                  gobject.TYPE_STRING)
130
        self.pending_view.set_model(liststore)
131
        
132
        self.pending_view.append_column(gtk.TreeViewColumn(_('Date'),
133
                                        gtk.CellRendererText(), text=0))
134
        self.pending_view.append_column(gtk.TreeViewColumn(_('Committer'),
135
                                        gtk.CellRendererText(), text=1))
136
        self.pending_view.append_column(gtk.TreeViewColumn(_('Summary'),
137
                                        gtk.CellRendererText(), text=2))
138
        
139
        if not self.pending:
140
            return
141
        
142
        for item in self.pending:
143
            liststore.append([ item['date'],
144
                               item['committer'],
145
                               item['summary'] ])
146
    
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
147
    def _get_specific_files(self):
148
        ret = []
149
        it = self.file_store.get_iter_first()
150
        while it:
151
            if self.file_store.get_value(it, 0):
0.8.21 by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
152
                ret.append(self.file_store.get_value(it, 1))
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
153
            it = self.file_store.iter_next(it)
154
155
        return ret
156
    
157
    def _toggle_commit(self, cell, path, model):
158
        model[path][0] = not model[path][0]
159
        return
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
160
    
95 by Szilveszter Farkas (Phanatic)
Added pending merges to Commit dialog. Fixed bug #66091.
161
    def _pending_merges(self, wt):
162
        """ Return a list of pending merges or None if there are none of them. """
163
        parents = wt.get_parent_ids()
164
        if len(parents) < 2:
165
            return None
166
        
167
        import re
168
        from bzrlib.osutils import format_date
169
        
170
        pending = parents[1:]
171
        branch = wt.branch
172
        last_revision = parents[0]
173
        
174
        if last_revision is not None:
175
            try:
176
                ignore = set(branch.repository.get_ancestry(last_revision))
177
            except errors.NoSuchRevision:
178
                # the last revision is a ghost : assume everything is new 
179
                # except for it
180
                ignore = set([None, last_revision])
181
        else:
182
            ignore = set([None])
183
        
184
        pm = []
185
        for merge in pending:
186
            ignore.add(merge)
187
            try:
188
                m_revision = branch.repository.get_revision(merge)
189
                
190
                rev = {}
191
                rev['committer'] = re.sub('<.*@.*>', '', m_revision.committer).strip(' ')
192
                rev['summary'] = m_revision.get_summary()
193
                rev['date'] = format_date(m_revision.timestamp,
194
                                          m_revision.timezone or 0, 
195
                                          'original', date_fmt="%Y-%m-%d",
196
                                          show_offset=False)
197
                
198
                pm.append(rev)
199
                
200
                inner_merges = branch.repository.get_ancestry(merge)
201
                assert inner_merges[0] is None
202
                inner_merges.pop(0)
203
                inner_merges.reverse()
204
                for mmerge in inner_merges:
205
                    if mmerge in ignore:
206
                        continue
207
                    mm_revision = branch.repository.get_revision(mmerge)
208
                    
209
                    rev = {}
210
                    rev['committer'] = re.sub('<.*@.*>', '', mm_revision.committer).strip(' ')
211
                    rev['summary'] = mm_revision.get_summary()
212
                    rev['date'] = format_date(mm_revision.timestamp,
213
                                              mm_revision.timezone or 0, 
214
                                              'original', date_fmt="%Y-%m-%d",
215
                                              show_offset=False)
216
                
217
                    pm.append(rev)
218
                    
219
                    ignore.add(mmerge)
220
            except errors.NoSuchRevision:
221
                print "DEBUG: NoSuchRevision:", merge
222
        
223
        return pm
224
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
225
    def commit(self, widget):
0.8.26 by Szilveszter Farkas (Phanatic)
Implemented Diff window; added menu.py (was missing from last commit)
226
        textbuffer = self.textview.get_buffer()
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
227
        start, end = textbuffer.get_bounds()
228
        message = textbuffer.get_text(start, end)
229
        
230
        checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
231
        checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
232
        
95 by Szilveszter Farkas (Phanatic)
Added pending merges to Commit dialog. Fixed bug #66091.
233
        if not self.pending:
234
            specific_files = self._get_specific_files()
235
        else:
236
            specific_files = None
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
237
        
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
238
        try:
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
239
            self.wt.commit(message, 
240
                           allow_pointless=checkbutton_force.get_active(),
241
                           strict=checkbutton_strict.get_active(),
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
242
                           local=self.checkbutton_local.get_active(),
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
243
                           specific_files=specific_files)
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
244
        except errors.NotBranchError:
0.13.3 by Jelmer Vernooij
Start removing dialog context (it's not required).
245
            error_dialog(_('Directory is not a branch'),
0.8.98 by Szilveszter Farkas (Phanatic)
Loads of fixes. Pyflakes cleanup.
246
                         _('You can perform this action only in a branch.'))
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
247
            return
248
        except errors.LocalRequiresBoundBranch:
0.13.3 by Jelmer Vernooij
Start removing dialog context (it's not required).
249
            error_dialog(_('Directory is not a checkout'),
0.8.98 by Szilveszter Farkas (Phanatic)
Loads of fixes. Pyflakes cleanup.
250
                         _('You can perform local commit only on checkouts.'))
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
251
            return
252
        except errors.PointlessCommit:
0.13.3 by Jelmer Vernooij
Start removing dialog context (it's not required).
253
            error_dialog(_('No changes to commit'),
0.8.98 by Szilveszter Farkas (Phanatic)
Loads of fixes. Pyflakes cleanup.
254
                         _('Try force commit if you want to commit anyway.'))
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
255
            return
256
        except errors.ConflictsInTree:
0.13.3 by Jelmer Vernooij
Start removing dialog context (it's not required).
257
            error_dialog(_('Conflicts in tree'),
0.8.98 by Szilveszter Farkas (Phanatic)
Loads of fixes. Pyflakes cleanup.
258
                         _('You need to resolve the conflicts before committing.'))
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
259
            return
260
        except errors.StrictCommitFailed:
0.13.3 by Jelmer Vernooij
Start removing dialog context (it's not required).
261
            error_dialog(_('Strict commit failed'),
0.8.98 by Szilveszter Farkas (Phanatic)
Loads of fixes. Pyflakes cleanup.
262
                         _('There are unknown files in the working tree.\nPlease add or delete them.'))
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
263
            return
264
        except errors.BoundBranchOutOfDate, errmsg:
0.13.3 by Jelmer Vernooij
Start removing dialog context (it's not required).
265
            error_dialog(_('Bound branch is out of date'),
0.8.98 by Szilveszter Farkas (Phanatic)
Loads of fixes. Pyflakes cleanup.
266
                         _('%s') % errmsg)
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
267
            return
0.13.2 by Jelmer Vernooij
Handle unknown errors in commit.
268
        except errors.BzrError, msg:
0.13.4 by Jelmer Vernooij
Handle non-bzr unknown errors as well.
269
            error_dialog(_('Unknown bzr error'), str(msg))
270
            return
271
        except Exception, msg:
0.13.3 by Jelmer Vernooij
Start removing dialog context (it's not required).
272
            error_dialog(_('Unknown error'), str(msg))
0.13.2 by Jelmer Vernooij
Handle unknown errors in commit.
273
            return
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
274
        
275
        self.close()
276
        
277
    def close(self, widget=None):
278
        self.window.destroy()