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