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