/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
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
28
import re
126.1.10 by Szilveszter Farkas (Phanatic)
Allow to commit single files from the context menu (Fixed: #54983)
29
248 by Jelmer Vernooij
Merge fixes for #127392 and #127381)
30
from bzrlib import errors, osutils
235.1.5 by Mateusz Korniak
Missing mutter import added.
31
from bzrlib.trace import mutter
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
32
153 by Jelmer Vernooij
Fix references to dialog.
33
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.
34
from errors import show_bzr_error
93.1.6 by Alexander Belchenko
detecting name of glade file doing in separate module (olive.gladefile)
35
158 by Jelmer Vernooij
If available, use NetworkManager to find out whether a commit should be local or not.
36
try:
37
    import dbus
38
    import dbus.glib
180 by Jelmer Vernooij
Don't obtain handle to network manager until it's actually needed.
39
    have_dbus = True
158 by Jelmer Vernooij
If available, use NetworkManager to find out whether a commit should be local or not.
40
except ImportError:
180 by Jelmer Vernooij
Don't obtain handle to network manager until it's actually needed.
41
    have_dbus = False
158 by Jelmer Vernooij
If available, use NetworkManager to find out whether a commit should be local or not.
42
278.1.4 by John Arbash Meinel
Just playing around.
43
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
44
def pending_revisions(wt):
45
    """Return a list of pending merges or None if there are none of them.
46
47
    Arguably this should be a core function, and
48
    ``bzrlib.status.show_pending_merges`` should be built on top of it.
49
50
    :return: [(rev, [children])]
51
    """
52
    parents = wt.get_parent_ids()
53
    if len(parents) < 2:
54
        return None
55
56
    # The basic pending merge algorithm uses the same algorithm as
57
    # bzrlib.status.show_pending_merges
58
    pending = parents[1:]
59
    branch = wt.branch
60
    last_revision = parents[0]
61
62
    if last_revision is not None:
63
        try:
64
            ignore = set(branch.repository.get_ancestry(last_revision,
65
                                                        topo_sorted=False))
66
        except errors.NoSuchRevision:
67
            # the last revision is a ghost : assume everything is new
68
            # except for it
69
            ignore = set([None, last_revision])
70
    else:
71
        ignore = set([None])
72
73
    pm = []
74
    for merge in pending:
75
        ignore.add(merge)
76
        try:
77
            rev = branch.repository.get_revision(merge)
78
            children = []
79
            pm.append((rev, children))
80
81
            # This does need to be topo sorted, so we search backwards
82
            inner_merges = branch.repository.get_ancestry(merge)
83
            assert inner_merges[0] is None
84
            inner_merges.pop(0)
85
            for mmerge in reversed(inner_merges):
86
                if mmerge in ignore:
87
                    continue
88
                rev = branch.repository.get_revision(mmerge)
89
                children.append(rev)
90
91
                ignore.add(mmerge)
92
        except errors.NoSuchRevision:
93
            print "DEBUG: NoSuchRevision:", merge
94
95
    return pm
96
97
135 by Jelmer Vernooij
Throw out the old CommitDialog code and use the new code instead, also for 'gcommit'.
98
class CommitDialog(gtk.Dialog):
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
99
    """Implementation of Commit."""
100
101
    def __init__(self, wt, selected=None, parent=None):
102
         gtk.Dialog.__init__(self, title="Commit - Olive",
103
                                   parent=parent,
104
                                   flags=0,
105
                                   buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
106
         self._wt = wt
107
         self._selected = selected
108
109
         self.setup_params()
110
         self.construct()
111
         self.set_default_size(800, 600)
112
113
    def setup_params(self):
114
        """Setup the member variables for state."""
115
        self._basis_tree = self._wt.basis_tree()
116
        self._delta = self._wt.changes_from(self._basis_tree)
117
118
        self._pending = pending_revisions(self._wt)
119
120
        self._is_checkout = (self._wt.branch.get_bound_location() is not None)
121
122
    def construct(self):
123
        """Build up the dialog widgets."""
124
        # The primary pane which splits it into left and right (adjustable)
125
        # sections.
278.1.4 by John Arbash Meinel
Just playing around.
126
        self._hpane = gtk.HPaned()
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
127
128
        self._construct_left_pane()
129
        self._construct_right_pane()
130
131
        self.vbox.pack_start(self._hpane)
132
        self._hpane.show()
133
        self.set_focus(self._global_message_text_view)
134
135
    def _construct_left_pane(self):
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
136
        self._left_pane_box = gtk.VBox(homogeneous=False, spacing=5)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
137
        self._construct_file_list()
138
        self._construct_pending_list()
139
140
        self._pending_box.show()
141
        self._hpane.pack1(self._left_pane_box, resize=False, shrink=True)
142
        self._left_pane_box.show()
143
144
    def _construct_right_pane(self):
145
        # TODO: I really want to make it so the diff view gets more space than
146
        # the global commit message, and the per-file commit message gets even
147
        # less. When I did it with wxGlade, I set it to 4 for diff, 2 for
148
        # commit, and 1 for file commit, and it looked good. But I don't seem
149
        # to have a way to do that with the gtk boxes... :( (Which is extra
150
        # weird since wx uses gtk on Linux...)
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
151
        self._right_pane_table = gtk.Table(rows=10, columns=1, homogeneous=False)
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
152
        self._right_pane_table.set_row_spacings(5)
153
        self._right_pane_table.set_col_spacings(5)
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
154
        self._right_pane_table_row = 0
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
155
        self._construct_diff_view()
156
        self._construct_file_message()
157
        self._construct_global_message()
158
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
159
        self._right_pane_table.show()
160
        self._hpane.pack2(self._right_pane_table, resize=True, shrink=True)
161
162
    def _add_to_right_table(self, widget, weight, expanding=False):
163
        """Add another widget to the table
164
165
        :param widget: The object to add
166
        :param weight: How many rows does this widget get to request
167
        :param expanding: Should expand|fill|shrink be set?
168
        """
169
        end_row = self._right_pane_table_row + weight
170
        options = 0
171
        expand_opts = gtk.EXPAND | gtk.FILL | gtk.SHRINK
172
        if expanding:
173
            options = expand_opts
174
        self._right_pane_table.attach(widget, 0, 1,
175
                                      self._right_pane_table_row, end_row,
176
                                      xoptions=expand_opts, yoptions=options)
177
        self._right_pane_table_row = end_row
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
178
179
    def _construct_file_list(self):
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
180
        self._files_box = gtk.VBox(homogeneous=False, spacing=0)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
181
        file_label = gtk.Label()
182
        file_label.set_markup(_('<b>Files</b>'))
183
        file_label.show()
184
        self._files_box.pack_start(file_label, expand=False)
185
186
        scroller = gtk.ScrolledWindow()
187
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
188
        self._treeview_files = gtk.TreeView()
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
189
        self._treeview_files.show()
190
        scroller.add(self._treeview_files)
191
        scroller.show()
192
        scroller.set_shadow_type(gtk.SHADOW_IN)
193
        self._files_box.pack_start(scroller,
194
                                   expand=True, fill=True)
195
        self._files_box.show()
196
        self._left_pane_box.pack_start(self._files_box)
197
198
    def _construct_pending_list(self):
199
        # Pending information defaults to hidden, we put it all in 1 box, so
200
        # that we can show/hide all of them at once
201
        self._pending_box = gtk.VBox()
202
        self._pending_box.hide()
203
204
        # TODO: This message should be centered
205
        pending_message = gtk.Label()
206
        pending_message.set_markup(
207
            _('<i>Cannot select specific files when merging</i>'))
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
208
        self._pending_box.pack_start(pending_message, expand=False, padding=5)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
209
        pending_message.show()
210
211
        pending_label = gtk.Label()
212
        pending_label.set_markup(_('<b>Pending Revisions</b>'))
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
213
        self._pending_box.pack_start(pending_label, expand=False, padding=0)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
214
        pending_label.show()
215
216
        scroller = gtk.ScrolledWindow()
217
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
218
        self._treeview_pending = gtk.TreeView()
219
        scroller.add(self._treeview_pending)
220
        scroller.show()
221
        scroller.set_shadow_type(gtk.SHADOW_IN)
222
        self._pending_box.pack_start(scroller,
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
223
                                     expand=True, fill=True, padding=5)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
224
        self._treeview_pending.show()
225
        self._left_pane_box.pack_start(self._pending_box)
226
227
    def _construct_diff_view(self):
228
        from diff import DiffDisplay
229
230
        self._diff_label = gtk.Label(_('Diff for whole tree'))
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
231
        self._diff_label.set_alignment(0, 0)
232
        self._right_pane_table.set_row_spacing(self._right_pane_table_row, 0)
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
233
        self._add_to_right_table(self._diff_label, 1, False)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
234
        self._diff_label.show()
235
236
        self._diff_view = DiffDisplay()
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
237
        self._add_to_right_table(self._diff_view, 4, True)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
238
        self._diff_view.show()
239
240
    def _construct_file_message(self):
241
        file_message_box = gtk.VBox()
278.1.9 by John Arbash Meinel
Move all text entry boxes into a ScrolledWindow, so that they don't change size constantly.
242
        scroller = gtk.ScrolledWindow()
243
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
244
245
        self._file_message_text_view = gtk.TextView()
246
        scroller.add(self._file_message_text_view)
247
        scroller.show()
248
        scroller.set_shadow_type(gtk.SHADOW_IN)
249
        file_message_box.pack_start(scroller, expand=True, fill=True)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
250
251
        self._file_message_text_view.modify_font(pango.FontDescription("Monospace"))
252
        self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD)
253
        self._file_message_text_view.set_accepts_tab(False)
254
        self._file_message_text_view.show()
255
256
        self._file_message_expander = gtk.Expander(_('Message for XXX'))
257
        self._file_message_expander.add(file_message_box)
258
        file_message_box.show()
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
259
        self._add_to_right_table(self._file_message_expander, 1, False)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
260
        self._file_message_expander.show()
261
262
    def _construct_global_message(self):
263
        self._global_message_label = gtk.Label(_('Global Commit Message'))
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
264
        self._global_message_label.set_alignment(0, 0)
265
        self._right_pane_table.set_row_spacing(self._right_pane_table_row, 0)
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
266
        self._add_to_right_table(self._global_message_label, 1, False)
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
267
        # Can we remove the spacing between the label and the box?
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
268
        self._global_message_label.show()
269
278.1.9 by John Arbash Meinel
Move all text entry boxes into a ScrolledWindow, so that they don't change size constantly.
270
        scroller = gtk.ScrolledWindow()
271
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
272
273
        self._global_message_text_view = gtk.TextView()
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
274
        self._global_message_text_view.modify_font(pango.FontDescription("Monospace"))
278.1.9 by John Arbash Meinel
Move all text entry boxes into a ScrolledWindow, so that they don't change size constantly.
275
        scroller.add(self._global_message_text_view)
276
        scroller.show()
277
        scroller.set_shadow_type(gtk.SHADOW_IN)
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
278
        self._add_to_right_table(scroller, 2, True)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
279
        self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD)
280
        self._file_message_text_view.set_accepts_tab(False)
281
        self._global_message_text_view.show()
282
283
    @staticmethod
284
    def _rev_to_pending_info(rev):
285
        """Get the information from a pending merge."""
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
286
        from bzrlib.osutils import format_date
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
287
288
        rev_dict = {}
289
        rev_dict['committer'] = re.sub('<.*@.*>', '', rev.committer).strip(' ')
290
        rev_dict['summary'] = rev.get_summary()
291
        rev_dict['date'] = format_date(rev.timestamp,
292
                                       rev.timezone or 0,
293
                                       'original', date_fmt="%Y-%m-%d",
294
                                       show_offset=False)
295
        rev_dict['revision_id'] = rev.revision_id
296
        return rev_dict
297
298
299
# class CommitDialog(gtk.Dialog):
300
#     """ New implementation of the Commit dialog. """
301
#     def __init__(self, wt, wtpath, notbranch, selected=None, parent=None):
302
#         """ Initialize the Commit Dialog. """
303
#         gtk.Dialog.__init__(self, title="Commit - Olive",
304
#                                   parent=parent,
305
#                                   flags=0,
306
#                                   buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
307
#         
308
#         # Get arguments
309
#         self.wt = wt
310
#         self.wtpath = wtpath
311
#         self.notbranch = notbranch
312
#         self.selected = selected
313
#         
314
#         # Set the delta
315
#         self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
316
#         self.delta = self.wt.changes_from(self.old_tree)
317
#         
318
#         # Get pending merges
319
#         self.pending = self._pending_merges(self.wt)
320
#         
321
#         # Do some preliminary checks
322
#         self._is_checkout = False
323
#         self._is_pending = False
324
#         if self.wt is None and not self.notbranch:
325
#             error_dialog(_('Directory does not have a working tree'),
326
#                          _('Operation aborted.'))
327
#             self.close()
328
#             return
329
# 
330
#         if self.notbranch:
331
#             error_dialog(_('Directory is not a branch'),
332
#                          _('You can perform this action only in a branch.'))
333
#             self.close()
334
#             return
335
#         else:
336
#             if self.wt.branch.get_bound_location() is not None:
337
#                 # we have a checkout, so the local commit checkbox must appear
338
#                 self._is_checkout = True
339
#             
340
#             if self.pending:
341
#                 # There are pending merges, file selection not supported
342
#                 self._is_pending = True
343
#         
344
#         # Create the widgets
345
#         # This is the main horizontal box, which is used to separate the commit
346
#         # info from the diff window.
347
#         self._hpane = gtk.HPaned()
348
#         self._button_commit = gtk.Button(_("Comm_it"), use_underline=True)
349
#         self._expander_files = gtk.Expander(_("File(s) to commit"))
350
#         self._vpaned_main = gtk.VPaned()
351
#         self._scrolledwindow_files = gtk.ScrolledWindow()
352
#         self._scrolledwindow_message = gtk.ScrolledWindow()
353
#         self._treeview_files = gtk.TreeView()
354
#         self._vbox_message = gtk.VBox()
355
#         self._label_message = gtk.Label(_("Commit message:"))
356
#         self._textview_message = gtk.TextView()
357
#         
358
#         if self._is_pending:
359
#             self._expander_merges = gtk.Expander(_("Pending merges"))
360
#             self._vpaned_list = gtk.VPaned()
361
#             self._scrolledwindow_merges = gtk.ScrolledWindow()
362
#             self._treeview_merges = gtk.TreeView()
363
# 
364
#         # Set callbacks
365
#         self._button_commit.connect('clicked', self._on_commit_clicked)
366
#         self._treeview_files.connect('cursor-changed', self._on_treeview_files_cursor_changed)
367
#         self._treeview_files.connect('row-activated', self._on_treeview_files_row_activated)
368
#         
369
#         # Set properties
370
#         self._scrolledwindow_files.set_policy(gtk.POLICY_AUTOMATIC,
371
#                                               gtk.POLICY_AUTOMATIC)
372
#         self._scrolledwindow_message.set_policy(gtk.POLICY_AUTOMATIC,
373
#                                                 gtk.POLICY_AUTOMATIC)
374
#         self._textview_message.modify_font(pango.FontDescription("Monospace"))
375
#         self.set_default_size(500, 500)
376
#         self._vpaned_main.set_position(200)
377
#         self._button_commit.set_flags(gtk.CAN_DEFAULT)
378
# 
379
#         if self._is_pending:
380
#             self._scrolledwindow_merges.set_policy(gtk.POLICY_AUTOMATIC,
381
#                                                    gtk.POLICY_AUTOMATIC)
382
#             self._treeview_files.set_sensitive(False)
383
#         
384
#         # Construct the dialog
385
#         self.action_area.pack_end(self._button_commit)
386
#         
387
#         self._scrolledwindow_files.add(self._treeview_files)
388
#         self._scrolledwindow_message.add(self._textview_message)
389
#         
390
#         self._expander_files.add(self._scrolledwindow_files)
391
#         
392
#         self._vbox_message.pack_start(self._label_message, False, False)
393
#         self._vbox_message.pack_start(self._scrolledwindow_message, True, True)
394
#         
395
#         if self._is_pending:        
396
#             self._expander_merges.add(self._scrolledwindow_merges)
397
#             self._scrolledwindow_merges.add(self._treeview_merges)
398
#             self._vpaned_list.add1(self._expander_files)
399
#             self._vpaned_list.add2(self._expander_merges)
400
#             self._vpaned_main.add1(self._vpaned_list)
401
#         else:
402
#             self._vpaned_main.add1(self._expander_files)
403
# 
404
#         self._vpaned_main.add2(self._vbox_message)
405
#         
406
#         self._hpane.pack1(self._vpaned_main)
407
#         self.vbox.pack_start(self._hpane, expand=True, fill=True)
408
#         if self._is_checkout: 
409
#             self._check_local = gtk.CheckButton(_("_Only commit locally"),
410
#                                                 use_underline=True)
411
#             self.vbox.pack_start(self._check_local, False, False)
412
#             if have_dbus:
413
#                 bus = dbus.SystemBus()
414
#                 proxy_obj = bus.get_object('org.freedesktop.NetworkManager', 
415
#                               '/org/freedesktop/NetworkManager')
416
#                 dbus_iface = dbus.Interface(
417
#                         proxy_obj, 'org.freedesktop.NetworkManager')
418
#                 try:
419
#                     # 3 is the enum value for STATE_CONNECTED
420
#                     self._check_local.set_active(dbus_iface.state() != 3)
421
#                 except dbus.DBusException, e:
422
#                     # Silently drop errors. While DBus may be 
423
#                     # available, NetworkManager doesn't necessarily have to be
424
#                     mutter("unable to get networkmanager state: %r" % e)
425
#                 
426
#         # Create the file list
427
#         self._create_file_view()
428
#         # Create the pending merges
429
#         self._create_pending_merges()
430
#         self._create_diff_view()
431
#         
432
#         # Expand the corresponding expander
433
#         if self._is_pending:
434
#             self._expander_merges.set_expanded(True)
435
#         else:
436
#             self._expander_files.set_expanded(True)
437
#         
438
#         # Display dialog
439
#         self.vbox.show_all()
440
#         
441
#         # Default to Commit button
442
#         self._button_commit.grab_default()
443
#     
444
#     def _show_diff_view(self, treeview):
445
#         # FIXME: the diff window freezes for some reason
446
#         treeselection = treeview.get_selection()
447
#         (model, iter) = treeselection.get_selected()
448
# 
449
#         if iter is not None:
450
#             selected = model.get_value(iter, 3) # Get the real_path attribute
451
#             self._diff_display.show_diff([selected])
452
# 
453
#     def _on_treeview_files_cursor_changed(self, treeview):
454
#         self._show_diff_view(treeview)
455
#         
456
#     def _on_treeview_files_row_activated(self, treeview, path, view_column):
457
#         self._show_diff_view(treeview)
458
#     
459
#     @show_bzr_error
460
#     def _on_commit_clicked(self, button):
461
#         """ Commit button clicked handler. """
462
#         textbuffer = self._textview_message.get_buffer()
463
#         start, end = textbuffer.get_bounds()
464
#         message = textbuffer.get_text(start, end).decode('utf-8')
465
#         
466
#         if not self.pending:
467
#             specific_files = self._get_specific_files()
468
#         else:
469
#             specific_files = None
470
# 
471
#         if message == '':
472
#             response = question_dialog(_('Commit with an empty message?'),
473
#                                        _('You can describe your commit intent in the message.'))
474
#             if response == gtk.RESPONSE_NO:
475
#                 # Kindly give focus to message area
476
#                 self._textview_message.grab_focus()
477
#                 return
478
# 
479
#         if self._is_checkout:
480
#             local = self._check_local.get_active()
481
#         else:
482
#             local = False
483
# 
484
#         if list(self.wt.unknowns()) != []:
485
#             response = question_dialog(_("Commit with unknowns?"),
486
#                _("Unknown files exist in the working tree. Commit anyway?"))
487
#             if response == gtk.RESPONSE_NO:
488
#                 return
489
#         
490
#         try:
491
#             self.wt.commit(message,
492
#                        allow_pointless=False,
493
#                        strict=False,
494
#                        local=local,
495
#                        specific_files=specific_files)
496
#         except errors.PointlessCommit:
497
#             response = question_dialog(_('Commit with no changes?'),
498
#                                        _('There are no changes in the working tree.'))
499
#             if response == gtk.RESPONSE_YES:
500
#                 self.wt.commit(message,
501
#                                allow_pointless=True,
502
#                                strict=False,
503
#                                local=local,
504
#                                specific_files=specific_files)
505
#         self.response(gtk.RESPONSE_OK)
506
# 
507
#     def _pending_merges(self, wt):
508
#         """ Return a list of pending merges or None if there are none of them. """
509
#         parents = wt.get_parent_ids()
510
#         if len(parents) < 2:
511
#             return None
512
#         
513
#         import re
514
#         from bzrlib.osutils import format_date
515
#         
516
#         pending = parents[1:]
517
#         branch = wt.branch
518
#         last_revision = parents[0]
519
#         
520
#         if last_revision is not None:
521
#             try:
522
#                 ignore = set(branch.repository.get_ancestry(last_revision))
523
#             except errors.NoSuchRevision:
524
#                 # the last revision is a ghost : assume everything is new 
525
#                 # except for it
526
#                 ignore = set([None, last_revision])
527
#         else:
528
#             ignore = set([None])
529
#         
530
#         pm = []
531
#         for merge in pending:
532
#             ignore.add(merge)
533
#             try:
534
#                 m_revision = branch.repository.get_revision(merge)
535
#                 
536
#                 rev = {}
537
#                 rev['committer'] = re.sub('<.*@.*>', '', m_revision.committer).strip(' ')
538
#                 rev['summary'] = m_revision.get_summary()
539
#                 rev['date'] = format_date(m_revision.timestamp,
540
#                                           m_revision.timezone or 0, 
541
#                                           'original', date_fmt="%Y-%m-%d",
542
#                                           show_offset=False)
543
#                 
544
#                 pm.append(rev)
545
#                 
546
#                 inner_merges = branch.repository.get_ancestry(merge)
547
#                 assert inner_merges[0] is None
548
#                 inner_merges.pop(0)
549
#                 inner_merges.reverse()
550
#                 for mmerge in inner_merges:
551
#                     if mmerge in ignore:
552
#                         continue
553
#                     mm_revision = branch.repository.get_revision(mmerge)
554
#                     
555
#                     rev = {}
556
#                     rev['committer'] = re.sub('<.*@.*>', '', mm_revision.committer).strip(' ')
557
#                     rev['summary'] = mm_revision.get_summary()
558
#                     rev['date'] = format_date(mm_revision.timestamp,
559
#                                               mm_revision.timezone or 0, 
560
#                                               'original', date_fmt="%Y-%m-%d",
561
#                                               show_offset=False)
562
#                 
563
#                     pm.append(rev)
564
#                     
565
#                     ignore.add(mmerge)
566
#             except errors.NoSuchRevision:
567
#                 print "DEBUG: NoSuchRevision:", merge
568
#         
569
#         return pm
570
# 
571
#     def _create_file_view(self):
572
#         self._file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,   # [0] checkbox
573
#                                          gobject.TYPE_STRING,    # [1] path to display
574
#                                          gobject.TYPE_STRING,    # [2] changes type
575
#                                          gobject.TYPE_STRING)    # [3] real path
576
#         self._treeview_files.set_model(self._file_store)
577
#         crt = gtk.CellRendererToggle()
578
#         crt.set_property("activatable", True)
579
#         crt.connect("toggled", self._toggle_commit, self._file_store)
580
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Commit'),
581
#                                      crt, active=0))
582
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
583
#                                      gtk.CellRendererText(), text=1))
584
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
585
#                                      gtk.CellRendererText(), text=2))
586
# 
587
#         for path, id, kind in self.delta.added:
588
#             marker = osutils.kind_marker(kind)
589
#             if self.selected is not None:
590
#                 if path == os.path.join(self.wtpath, self.selected):
591
#                     self._file_store.append([ True, path+marker, _('added'), path ])
592
#                 else:
593
#                     self._file_store.append([ False, path+marker, _('added'), path ])
594
#             else:
595
#                 self._file_store.append([ True, path+marker, _('added'), path ])
596
# 
597
#         for path, id, kind in self.delta.removed:
598
#             marker = osutils.kind_marker(kind)
599
#             if self.selected is not None:
600
#                 if path == os.path.join(self.wtpath, self.selected):
601
#                     self._file_store.append([ True, path+marker, _('removed'), path ])
602
#                 else:
603
#                     self._file_store.append([ False, path+marker, _('removed'), path ])
604
#             else:
605
#                 self._file_store.append([ True, path+marker, _('removed'), path ])
606
# 
607
#         for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
608
#             marker = osutils.kind_marker(kind)
609
#             if text_modified or meta_modified:
610
#                 changes = _('renamed and modified')
611
#             else:
612
#                 changes = _('renamed')
613
#             if self.selected is not None:
614
#                 if newpath == os.path.join(self.wtpath, self.selected):
615
#                     self._file_store.append([ True,
616
#                                               oldpath+marker + '  =>  ' + newpath+marker,
617
#                                               changes,
618
#                                               newpath
619
#                                             ])
620
#                 else:
621
#                     self._file_store.append([ False,
622
#                                               oldpath+marker + '  =>  ' + newpath+marker,
623
#                                               changes,
624
#                                               newpath
625
#                                             ])
626
#             else:
627
#                 self._file_store.append([ True,
628
#                                           oldpath+marker + '  =>  ' + newpath+marker,
629
#                                           changes,
630
#                                           newpath
631
#                                         ])
632
# 
633
#         for path, id, kind, text_modified, meta_modified in self.delta.modified:
634
#             marker = osutils.kind_marker(kind)
635
#             if self.selected is not None:
636
#                 if path == os.path.join(self.wtpath, self.selected):
637
#                     self._file_store.append([ True, path+marker, _('modified'), path ])
638
#                 else:
639
#                     self._file_store.append([ False, path+marker, _('modified'), path ])
640
#             else:
641
#                 self._file_store.append([ True, path+marker, _('modified'), path ])
642
#     
643
#     def _create_pending_merges(self):
644
#         if not self.pending:
645
#             return
646
#         
647
#         liststore = gtk.ListStore(gobject.TYPE_STRING,
648
#                                   gobject.TYPE_STRING,
649
#                                   gobject.TYPE_STRING)
650
#         self._treeview_merges.set_model(liststore)
651
#         
652
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Date'),
653
#                                             gtk.CellRendererText(), text=0))
654
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Committer'),
655
#                                             gtk.CellRendererText(), text=1))
656
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Summary'),
657
#                                             gtk.CellRendererText(), text=2))
658
#         
659
#         for item in self.pending:
660
#             liststore.append([ item['date'],
661
#                                item['committer'],
662
#                                item['summary'] ])
663
#     
664
# 
665
#     def _create_diff_view(self):
666
#         from diff import DiffDisplay
667
# 
668
#         self._diff_display = DiffDisplay()
669
#         self._diff_display.set_trees(self.wt, self.wt.basis_tree())
670
#         self._diff_display.show_diff(None)
671
#         self._diff_display.show()
672
#         self._hpane.pack2(self._diff_display)
673
# 
674
#     def _get_specific_files(self):
675
#         ret = []
676
#         it = self._file_store.get_iter_first()
677
#         while it:
678
#             if self._file_store.get_value(it, 0):
679
#                 # get real path from hidden column 3
680
#                 ret.append(self._file_store.get_value(it, 3))
681
#             it = self._file_store.iter_next(it)
682
# 
683
#         return ret
684
#     
685
#     def _toggle_commit(self, cell, path, model):
686
#         model[path][0] = not model[path][0]
687
#         return