/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 gobject
25
import pango
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
26
126.1.10 by Szilveszter Farkas (Phanatic)
Allow to commit single files from the context menu (Fixed: #54983)
27
import os.path
28
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
29
import bzrlib.errors as errors
93.1.10 by Alexander Belchenko
- Show file kind marker with path (i.e. directory path ends with '/')
30
from bzrlib import osutils
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
31
153 by Jelmer Vernooij
Fix references to dialog.
32
from dialog import error_dialog, question_dialog
132 by Jelmer Vernooij
Use decorator for catching and showing bzr-gtk errors graphically. Eventually, this should go away and should be handled by the ui factory.
33
from errors import show_bzr_error
93.1.6 by Alexander Belchenko
detecting name of glade file doing in separate module (olive.gladefile)
34
135 by Jelmer Vernooij
Throw out the old CommitDialog code and use the new code instead, also for 'gcommit'.
35
class CommitDialog(gtk.Dialog):
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
36
    """ New implementation of the Commit dialog. """
37
    def __init__(self, wt, wtpath, notbranch, selected=None, parent=None):
38
        """ Initialize the Commit Dialog. """
39
        gtk.Dialog.__init__(self, title="Commit - Olive",
40
                                  parent=parent,
41
                                  flags=0,
42
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
43
        
44
        # Get arguments
45
        self.wt = wt
46
        self.wtpath = wtpath
47
        self.notbranch = notbranch
48
        self.selected = selected
49
        
50
        # Set the delta
51
        self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
52
        self.delta = self.wt.changes_from(self.old_tree)
53
        
54
        # Get pending merges
55
        self.pending = self._pending_merges(self.wt)
56
        
57
        # Do some preliminary checks
58
        self._is_checkout = False
59
        self._is_pending = False
60
        if self.wt is None and not self.notbranch:
61
            error_dialog(_('Directory does not have a working tree'),
62
                         _('Operation aborted.'))
63
            self.close()
64
            return
65
66
        if self.notbranch:
67
            error_dialog(_('Directory is not a branch'),
68
                         _('You can perform this action only in a branch.'))
69
            self.close()
70
            return
71
        else:
72
            if self.wt.branch.get_bound_location() is not None:
73
                # we have a checkout, so the local commit checkbox must appear
74
                self._is_checkout = True
75
            
76
            if self.pending:
77
                # There are pending merges, file selection not supported
78
                self._is_pending = True
79
        
80
        # Create the widgets
81
        self._button_commit = gtk.Button(_("Comm_it"), use_underline=True)
82
        if self._is_checkout:
145 by Jelmer Vernooij
Fix some strings, import.
83
            self._check_local = gtk.CheckButton(_("_Only commit locally"),
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
84
                                                use_underline=True)
145 by Jelmer Vernooij
Fix some strings, import.
85
        self._check_strict = gtk.CheckButton(_("_Allow unknown files"),
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
86
                                             use_underline=True)
145 by Jelmer Vernooij
Fix some strings, import.
87
        self._expander_files = gtk.Expander(_("File(s) to commit"))
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
88
        self._vpaned_main = gtk.VPaned()
89
        self._scrolledwindow_files = gtk.ScrolledWindow()
90
        self._scrolledwindow_message = gtk.ScrolledWindow()
91
        self._treeview_files = gtk.TreeView()
92
        self._vbox_message = gtk.VBox()
145 by Jelmer Vernooij
Fix some strings, import.
93
        self._label_message = gtk.Label(_("Commit message:"))
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
94
        self._textview_message = gtk.TextView()
95
        
96
        if self._is_pending:
97
            self._expander_merges = gtk.Expander(_("Pending merges"))
98
            self._vpaned_list = gtk.VPaned()
99
            self._scrolledwindow_merges = gtk.ScrolledWindow()
100
            self._treeview_merges = gtk.TreeView()
101
102
        # Set callbacks
103
        self._button_commit.connect('clicked', self._on_commit_clicked)
104
        self._treeview_files.connect('row_activated', self._on_treeview_files_row_activated)
105
        
106
        # Set properties
107
        self._scrolledwindow_files.set_policy(gtk.POLICY_AUTOMATIC,
108
                                              gtk.POLICY_AUTOMATIC)
109
        self._scrolledwindow_message.set_policy(gtk.POLICY_AUTOMATIC,
110
                                                gtk.POLICY_AUTOMATIC)
111
        self._textview_message.modify_font(pango.FontDescription("Monospace"))
112
        self.set_default_size(500, 500)
113
        self._vpaned_main.set_position(200)
114
115
        if self._is_pending:
116
            self._scrolledwindow_merges.set_policy(gtk.POLICY_AUTOMATIC,
117
                                                   gtk.POLICY_AUTOMATIC)
118
            self._treeview_files.set_sensitive(False)
119
        
120
        # Construct the dialog
121
        self.action_area.pack_end(self._button_commit)
122
        
123
        self._scrolledwindow_files.add(self._treeview_files)
124
        self._scrolledwindow_message.add(self._textview_message)
125
        
126
        self._expander_files.add(self._scrolledwindow_files)
127
        
128
        self._vbox_message.pack_start(self._label_message, False, False)
129
        self._vbox_message.pack_start(self._scrolledwindow_message, True, True)
130
        
131
        if self._is_pending:        
132
            self._expander_merges.add(self._scrolledwindow_merges)
133
            self._scrolledwindow_merges.add(self._treeview_merges)
134
            self._vpaned_list.add1(self._expander_files)
135
            self._vpaned_list.add2(self._expander_merges)
136
            self._vpaned_main.add1(self._vpaned_list)
137
        else:
138
            self._vpaned_main.add1(self._expander_files)
139
140
        self._vpaned_main.add2(self._vbox_message)
141
        
142
        self.vbox.pack_start(self._vpaned_main, True, True)
143
        if self._is_checkout:
144
            self.vbox.pack_start(self._check_local, False, False)
145
        self.vbox.pack_start(self._check_strict, False, False)
146
        
147
        # Create the file list
148
        self._create_file_view()
149
        # Create the pending merges
150
        self._create_pending_merges()
151
        
152
        # Expand the corresponding expander
153
        if self._is_pending:
154
            self._expander_merges.set_expanded(True)
155
        else:
156
            self._expander_files.set_expanded(True)
157
        
158
        # Display dialog
159
        self.vbox.show_all()
160
    
161
    def _on_treeview_files_row_activated(self, treeview, path, view_column):
162
        # FIXME: the diff window freezes for some reason
163
        treeselection = treeview.get_selection()
164
        (model, iter) = treeselection.get_selected()
165
        
166
        if iter is not None:
153 by Jelmer Vernooij
Fix references to dialog.
167
            from diff import DiffWindow
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
168
            
169
            _selected = model.get_value(iter, 1)
170
            
171
            diff = DiffWindow()
126.1.28 by Szilveszter Farkas (Phanatic)
The Diff window won't freeze when calling from the Commit dialog.
172
            diff.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
173
            diff.set_modal(True)
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
174
            parent_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
175
            diff.set_diff(self.wt.branch.nick, self.wt, parent_tree)
176
            try:
177
                diff.set_file(_selected)
178
            except errors.NoSuchFile:
179
                pass
180
            diff.show()
181
    
132 by Jelmer Vernooij
Use decorator for catching and showing bzr-gtk errors graphically. Eventually, this should go away and should be handled by the ui factory.
182
    @show_bzr_error
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
183
    def _on_commit_clicked(self, button):
184
        """ Commit button clicked handler. """
185
        textbuffer = self._textview_message.get_buffer()
186
        start, end = textbuffer.get_bounds()
187
        message = textbuffer.get_text(start, end).decode('utf-8')
188
        
189
        if not self.pending:
190
            specific_files = self._get_specific_files()
191
        else:
192
            specific_files = None
193
194
        if message == '':
195
            response = question_dialog(_('Commit with an empty message?'),
196
                                       _('You can describe your commit intent in the message.'))
197
            if response == gtk.RESPONSE_NO:
198
                # Kindly give focus to message area
199
                self._textview_message.grab_focus()
200
                return
201
202
        if self._is_checkout:
203
            local = self._check_local.get_active()
204
        else:
205
            local = False
206
        
207
        try:
208
            self.wt.commit(message,
132 by Jelmer Vernooij
Use decorator for catching and showing bzr-gtk errors graphically. Eventually, this should go away and should be handled by the ui factory.
209
                       allow_pointless=False,
210
                       strict=self._check_strict.get_active(),
211
                       local=local,
212
                       specific_files=specific_files)
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
213
        except errors.PointlessCommit:
214
            response = question_dialog(_('Commit with no changes?'),
215
                                       _('There are no changes in the working tree.'))
216
            if response == gtk.RESPONSE_YES:
132 by Jelmer Vernooij
Use decorator for catching and showing bzr-gtk errors graphically. Eventually, this should go away and should be handled by the ui factory.
217
                self.wt.commit(message,
218
                               allow_pointless=True,
219
                               strict=self._check_strict.get_active(),
220
                               local=local,
221
                               specific_files=specific_files)
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
222
        self.response(gtk.RESPONSE_OK)
223
224
    def _pending_merges(self, wt):
225
        """ Return a list of pending merges or None if there are none of them. """
226
        parents = wt.get_parent_ids()
227
        if len(parents) < 2:
228
            return None
229
        
230
        import re
231
        from bzrlib.osutils import format_date
232
        
233
        pending = parents[1:]
234
        branch = wt.branch
235
        last_revision = parents[0]
236
        
237
        if last_revision is not None:
238
            try:
239
                ignore = set(branch.repository.get_ancestry(last_revision))
240
            except errors.NoSuchRevision:
241
                # the last revision is a ghost : assume everything is new 
242
                # except for it
243
                ignore = set([None, last_revision])
244
        else:
245
            ignore = set([None])
246
        
247
        pm = []
248
        for merge in pending:
249
            ignore.add(merge)
250
            try:
251
                m_revision = branch.repository.get_revision(merge)
252
                
253
                rev = {}
254
                rev['committer'] = re.sub('<.*@.*>', '', m_revision.committer).strip(' ')
255
                rev['summary'] = m_revision.get_summary()
256
                rev['date'] = format_date(m_revision.timestamp,
257
                                          m_revision.timezone or 0, 
258
                                          'original', date_fmt="%Y-%m-%d",
259
                                          show_offset=False)
260
                
261
                pm.append(rev)
262
                
263
                inner_merges = branch.repository.get_ancestry(merge)
264
                assert inner_merges[0] is None
265
                inner_merges.pop(0)
266
                inner_merges.reverse()
267
                for mmerge in inner_merges:
268
                    if mmerge in ignore:
269
                        continue
270
                    mm_revision = branch.repository.get_revision(mmerge)
271
                    
272
                    rev = {}
273
                    rev['committer'] = re.sub('<.*@.*>', '', mm_revision.committer).strip(' ')
274
                    rev['summary'] = mm_revision.get_summary()
275
                    rev['date'] = format_date(mm_revision.timestamp,
276
                                              mm_revision.timezone or 0, 
277
                                              'original', date_fmt="%Y-%m-%d",
278
                                              show_offset=False)
279
                
280
                    pm.append(rev)
281
                    
282
                    ignore.add(mmerge)
283
            except errors.NoSuchRevision:
284
                print "DEBUG: NoSuchRevision:", merge
285
        
286
        return pm
287
288
    def _create_file_view(self):
289
        self._file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,   # [0] checkbox
290
                                         gobject.TYPE_STRING,    # [1] path to display
291
                                         gobject.TYPE_STRING,    # [2] changes type
292
                                         gobject.TYPE_STRING)    # [3] real path
293
        self._treeview_files.set_model(self._file_store)
294
        crt = gtk.CellRendererToggle()
295
        crt.set_property("activatable", True)
296
        crt.connect("toggled", self._toggle_commit, self._file_store)
297
        self._treeview_files.append_column(gtk.TreeViewColumn(_('Commit'),
298
                                     crt, active=0))
299
        self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
300
                                     gtk.CellRendererText(), text=1))
301
        self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
302
                                     gtk.CellRendererText(), text=2))
303
304
        for path, id, kind in self.delta.added:
305
            marker = osutils.kind_marker(kind)
126.1.10 by Szilveszter Farkas (Phanatic)
Allow to commit single files from the context menu (Fixed: #54983)
306
            if self.selected is not None:
307
                if path == os.path.join(self.wtpath, self.selected):
308
                    self._file_store.append([ True, path+marker, _('added'), path ])
309
                else:
310
                    self._file_store.append([ False, path+marker, _('added'), path ])
311
            else:
312
                self._file_store.append([ True, path+marker, _('added'), path ])
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
313
314
        for path, id, kind in self.delta.removed:
315
            marker = osutils.kind_marker(kind)
126.1.10 by Szilveszter Farkas (Phanatic)
Allow to commit single files from the context menu (Fixed: #54983)
316
            if self.selected is not None:
317
                if path == os.path.join(self.wtpath, self.selected):
318
                    self._file_store.append([ True, path+marker, _('removed'), path ])
319
                else:
320
                    self._file_store.append([ False, path+marker, _('removed'), path ])
321
            else:
322
                self._file_store.append([ True, path+marker, _('removed'), path ])
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
323
324
        for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
325
            marker = osutils.kind_marker(kind)
326
            if text_modified or meta_modified:
327
                changes = _('renamed and modified')
328
            else:
329
                changes = _('renamed')
126.1.10 by Szilveszter Farkas (Phanatic)
Allow to commit single files from the context menu (Fixed: #54983)
330
            if self.selected is not None:
331
                if newpath == os.path.join(self.wtpath, self.selected):
332
                    self._file_store.append([ True,
333
                                              oldpath+marker + '  =>  ' + newpath+marker,
334
                                              changes,
335
                                              newpath
336
                                            ])
337
                else:
338
                    self._file_store.append([ False,
339
                                              oldpath+marker + '  =>  ' + newpath+marker,
340
                                              changes,
341
                                              newpath
342
                                            ])
343
            else:
344
                self._file_store.append([ True,
345
                                          oldpath+marker + '  =>  ' + newpath+marker,
346
                                          changes,
347
                                          newpath
348
                                        ])
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
349
350
        for path, id, kind, text_modified, meta_modified in self.delta.modified:
351
            marker = osutils.kind_marker(kind)
126.1.10 by Szilveszter Farkas (Phanatic)
Allow to commit single files from the context menu (Fixed: #54983)
352
            if self.selected is not None:
353
                if path == os.path.join(self.wtpath, self.selected):
354
                    self._file_store.append([ True, path+marker, _('modified'), path ])
355
                else:
356
                    self._file_store.append([ False, path+marker, _('modified'), path ])
357
            else:
358
                self._file_store.append([ True, path+marker, _('modified'), path ])
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
359
    
360
    def _create_pending_merges(self):
361
        if not self.pending:
362
            return
363
        
364
        liststore = gtk.ListStore(gobject.TYPE_STRING,
365
                                  gobject.TYPE_STRING,
366
                                  gobject.TYPE_STRING)
367
        self._treeview_merges.set_model(liststore)
368
        
369
        self._treeview_merges.append_column(gtk.TreeViewColumn(_('Date'),
370
                                            gtk.CellRendererText(), text=0))
371
        self._treeview_merges.append_column(gtk.TreeViewColumn(_('Committer'),
372
                                            gtk.CellRendererText(), text=1))
373
        self._treeview_merges.append_column(gtk.TreeViewColumn(_('Summary'),
374
                                            gtk.CellRendererText(), text=2))
375
        
376
        for item in self.pending:
377
            liststore.append([ item['date'],
378
                               item['committer'],
379
                               item['summary'] ])
380
    
381
    def _get_specific_files(self):
382
        ret = []
383
        it = self._file_store.get_iter_first()
384
        while it:
385
            if self._file_store.get_value(it, 0):
386
                # get real path from hidden column 3
387
                ret.append(self._file_store.get_value(it, 3))
388
            it = self._file_store.iter_next(it)
389
390
        return ret
391
    
392
    def _toggle_commit(self, cell, path, model):
393
        model[path][0] = not model[path][0]
394
        return