/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to commit.py

  • Committer: John Arbash Meinel
  • Date: 2007-10-02 19:15:41 UTC
  • mto: (322.1.1 trunk) (330.3.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 368.
  • Revision ID: john@arbash-meinel.com-20071002191541-qra1s73obzvgrf7j
Ensure that we can set per-file messages even during a merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
107
107
        self._question_dialog = question_dialog
108
108
 
109
109
        self._wt = wt
110
 
        # TODO: Do something with this value, it is used by Olive
111
 
        #       It used to set all changes but this one to False
112
110
        self._selected = selected
113
 
        self._enable_per_file_commits = True
114
 
        self._commit_all_changes = True
115
111
        self.committed_revision_id = None # Nothing has been committed yet
116
112
 
117
113
        self.setup_params()
132
128
        self._fill_in_diff()
133
129
        self._fill_in_files()
134
130
        self._fill_in_checkout()
135
 
        self._fill_in_per_file_info()
136
131
 
137
132
    def _fill_in_pending(self):
138
133
        if not self._pending:
159
154
        self._pending_box.show()
160
155
 
161
156
    def _fill_in_files(self):
162
 
        # We should really use add a progress bar of some kind.
 
157
        # We should really use _iter_changes, and then add a progress bar of
 
158
        # some kind.
163
159
        # While we fill in the view, hide the store
164
160
        store = self._files_store
165
161
        self._treeview_files.set_model(None)
178
174
        #  changed_content, versioned, parent, name, kind,
179
175
        #  executable)
180
176
 
181
 
        all_enabled = (self._selected is None)
182
177
        # The first entry is always the 'whole tree'
183
 
        all_iter = store.append([None, None, all_enabled, 'All Files', '', ''])
184
 
        initial_cursor = store.get_path(all_iter)
 
178
        store.append([None, None, True, 'All Files', '', ''])
185
179
        # should we pass specific_files?
186
180
        self._wt.lock_read()
187
181
        self._basis_tree.lock_read()
188
182
        try:
189
 
            from diff import _iter_changes_to_status
190
 
            for (file_id, real_path, change_type, display_path
191
 
                ) in _iter_changes_to_status(self._basis_tree, self._wt):
192
 
                if self._selected and real_path != self._selected:
193
 
                    enabled = False
194
 
                else:
195
 
                    enabled = True
196
 
                item_iter = store.append([
197
 
                    file_id,
198
 
                    real_path.encode('UTF-8'),
199
 
                    enabled,
200
 
                    display_path.encode('UTF-8'),
201
 
                    change_type,
202
 
                    '', # Initial comment
203
 
                    ])
204
 
                if self._selected and enabled:
205
 
                    initial_cursor = store.get_path(item_iter)
 
183
            for (file_id, paths, changed_content, versioned, parent_ids, names,
 
184
                 kinds, executables) in self._wt._iter_changes(self._basis_tree):
 
185
 
 
186
                # Skip the root entry.
 
187
                if parent_ids == (None, None):
 
188
                    continue
 
189
 
 
190
                change_type = None
 
191
                if kinds[0] is None:
 
192
                    source_marker = ''
 
193
                else:
 
194
                    source_marker = osutils.kind_marker(kinds[0])
 
195
                if kinds[1] is None:
 
196
                    assert kinds[0] is not None
 
197
                    marker = osutils.kind_marker(kinds[0])
 
198
                else:
 
199
                    marker = osutils.kind_marker(kinds[1])
 
200
 
 
201
                real_path = paths[1]
 
202
                if real_path is None:
 
203
                    real_path = paths[0]
 
204
                assert real_path is not None
 
205
                display_path = real_path + marker
 
206
 
 
207
                present_source = versioned[0] and kinds[0] is not None
 
208
                present_target = versioned[1] and kinds[1] is not None
 
209
 
 
210
                if present_source != present_target:
 
211
                    if present_target:
 
212
                        change_type = added
 
213
                    else:
 
214
                        change_type = removed
 
215
                elif names[0] != names[1] or parent_ids[0] != parent_ids[1]:
 
216
                    # Renamed
 
217
                    if changed_content or executables[0] != executables[1]:
 
218
                        # and modified
 
219
                        change_type = renamed_and_modified
 
220
                    else:
 
221
                        change_type = renamed
 
222
                    display_path = (paths[0] + source_marker
 
223
                                    + ' => ' + paths[1] + marker)
 
224
                elif kinds[0] != kinds[1]:
 
225
                    change_type = kind_changed
 
226
                    display_path = (paths[0] + source_marker
 
227
                                    + ' => ' + paths[1] + marker)
 
228
                elif changed_content is True or executables[0] != executables[1]:
 
229
                    change_type = modified
 
230
                else:
 
231
                    assert False, "How did we get here?"
 
232
 
 
233
                store.append([file_id, real_path, True, display_path,
 
234
                              change_type, ''])
206
235
        finally:
207
236
            self._basis_tree.unlock()
208
237
            self._wt.unlock()
209
238
 
210
239
        self._treeview_files.set_model(store)
211
240
        self._last_selected_file = None
212
 
        # This sets the cursor, which causes the expander to close, which
213
 
        # causes the _file_message_text_view to never get realized. So we have
214
 
        # to give it a little kick, or it warns when we try to grab the focus
215
 
        self._treeview_files.set_cursor(initial_cursor)
216
 
 
217
 
        def _realize_file_message_tree_view(*args):
218
 
            self._file_message_text_view.realize()
219
 
        self.connect_after('realize', _realize_file_message_tree_view)
 
241
        self._treeview_files.set_cursor(0)
220
242
 
221
243
    def _fill_in_diff(self):
222
244
        self._diff_view.set_trees(self._wt, self._basis_tree)
240
262
                mutter("unable to get networkmanager state: %r" % e)
241
263
        self._check_local.show()
242
264
 
243
 
    def _fill_in_per_file_info(self):
244
 
        config = self._wt.branch.get_config()
245
 
        enable_per_file_commits = config.get_user_option('per_file_commits')
246
 
        if (enable_per_file_commits is None
247
 
            or enable_per_file_commits.lower()
248
 
                not in ('y', 'yes', 'on', 'enable', '1', 't', 'true')):
249
 
            self._enable_per_file_commits = False
250
 
        else:
251
 
            self._enable_per_file_commits = True
252
 
        if not self._enable_per_file_commits:
253
 
            self._file_message_expander.hide()
254
 
            self._global_message_label.set_markup(_('<b>Commit Message</b>'))
255
 
 
256
265
    def _compute_delta(self):
257
266
        self._delta = self._wt.changes_from(self._basis_tree)
258
267
 
270
279
        self._hpane.show()
271
280
        self.set_focus(self._global_message_text_view)
272
281
 
273
 
        self._construct_accelerators()
274
 
        self._set_sizes()
275
 
 
276
 
    def _set_sizes(self):
277
282
        # This seems like a reasonable default, we might like it to
278
283
        # be a bit wider, so that by default we can fit an 80-line diff in the
279
284
        # diff window.
290
295
        self.set_default_size(width, height)
291
296
        self._hpane.set_position(300)
292
297
 
293
 
    def _construct_accelerators(self):
294
 
        group = gtk.AccelGroup()
295
 
        group.connect_group(gtk.gdk.keyval_from_name('N'),
296
 
                            gtk.gdk.CONTROL_MASK, 0, self._on_accel_next)
297
 
        self.add_accel_group(group)
298
 
 
299
298
    def _construct_left_pane(self):
300
299
        self._left_pane_box = gtk.VBox(homogeneous=False, spacing=5)
301
300
        self._construct_file_list()
355
354
    def _construct_file_list(self):
356
355
        self._files_box = gtk.VBox(homogeneous=False, spacing=0)
357
356
        file_label = gtk.Label(_('Files'))
358
 
        # file_label.show()
 
357
        file_label.show()
359
358
        self._files_box.pack_start(file_label, expand=False)
360
359
 
361
 
        self._commit_all_files_radio = gtk.RadioButton(
362
 
            None, _("Commit all changes"))
363
 
        self._files_box.pack_start(self._commit_all_files_radio, expand=False)
364
 
        self._commit_all_files_radio.show()
365
 
        self._commit_all_files_radio.connect('toggled',
366
 
            self._toggle_commit_selection)
367
 
        self._commit_selected_radio = gtk.RadioButton(
368
 
            self._commit_all_files_radio, _("Only commit selected changes"))
369
 
        self._files_box.pack_start(self._commit_selected_radio, expand=False)
370
 
        self._commit_selected_radio.show()
371
 
        self._commit_selected_radio.connect('toggled',
372
 
            self._toggle_commit_selection)
373
 
        if self._pending:
374
 
            self._commit_all_files_radio.set_label(_('Commit all changes*'))
375
 
            self._commit_all_files_radio.set_sensitive(False)
376
 
            self._commit_selected_radio.set_sensitive(False)
377
 
 
378
360
        scroller = gtk.ScrolledWindow()
379
361
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
380
362
        self._treeview_files = gtk.TreeView()
381
363
        self._treeview_files.show()
382
364
        scroller.add(self._treeview_files)
 
365
        scroller.show()
383
366
        scroller.set_shadow_type(gtk.SHADOW_IN)
384
 
        scroller.show()
385
367
        self._files_box.pack_start(scroller,
386
368
                                   expand=True, fill=True)
387
369
        self._files_box.show()
388
370
        self._left_pane_box.pack_start(self._files_box)
389
371
 
390
 
        # Keep note that all strings stored in a ListStore must be UTF-8
391
 
        # strings. GTK does not support directly setting and restoring Unicode
392
 
        # objects.
393
372
        liststore = gtk.ListStore(
394
373
            gobject.TYPE_STRING,  # [0] file_id
395
374
            gobject.TYPE_STRING,  # [1] real path
401
380
        self._files_store = liststore
402
381
        self._treeview_files.set_model(liststore)
403
382
        crt = gtk.CellRendererToggle()
404
 
        crt.set_property('activatable', not bool(self._pending))
 
383
        crt.set_active(not bool(self._pending))
405
384
        crt.connect("toggled", self._toggle_commit, self._files_store)
406
385
        if self._pending:
407
386
            name = _('Commit*')
408
387
        else:
409
388
            name = _('Commit')
410
 
        commit_col = gtk.TreeViewColumn(name, crt, active=2)
411
 
        commit_col.set_visible(False)
412
 
        self._treeview_files.append_column(commit_col)
 
389
        self._treeview_files.append_column(gtk.TreeViewColumn(name,
 
390
                                           crt, active=2))
413
391
        self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
414
392
                                           gtk.CellRendererText(), text=3))
415
393
        self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
425
403
        else:
426
404
            model[path][2] = not model[path][2]
427
405
 
428
 
    def _toggle_commit_selection(self, button):
429
 
        all_files = self._commit_all_files_radio.get_active()
430
 
        if self._commit_all_changes != all_files:
431
 
            checked_col = self._treeview_files.get_column(0)
432
 
            self._commit_all_changes = all_files
433
 
            if all_files:
434
 
                checked_col.set_visible(False)
435
 
            else:
436
 
                checked_col.set_visible(True)
437
 
            renderer = checked_col.get_cell_renderers()[0]
438
 
            renderer.set_property('activatable', not all_files)
439
 
 
440
406
    def _construct_pending_list(self):
441
407
        # Pending information defaults to hidden, we put it all in 1 box, so
442
408
        # that we can show/hide all of them at once
457
423
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
458
424
        self._treeview_pending = gtk.TreeView()
459
425
        scroller.add(self._treeview_pending)
 
426
        scroller.show()
460
427
        scroller.set_shadow_type(gtk.SHADOW_IN)
461
 
        scroller.show()
462
428
        self._pending_box.pack_start(scroller,
463
429
                                     expand=True, fill=True, padding=5)
464
430
        self._treeview_pending.show()
481
447
    def _construct_diff_view(self):
482
448
        from diff import DiffView
483
449
 
484
 
        # TODO: jam 2007-10-30 The diff label is currently disabled. If we
485
 
        #       decide that we really don't ever want to display it, we should
486
 
        #       actually remove it, and other references to it, along with the
487
 
        #       tests that it is set properly.
488
450
        self._diff_label = gtk.Label(_('Diff for whole tree'))
489
451
        self._diff_label.set_alignment(0, 0)
490
452
        self._right_pane_table.set_row_spacing(self._right_pane_table_row, 0)
491
453
        self._add_to_right_table(self._diff_label, 1, False)
492
 
        # self._diff_label.show()
 
454
        self._diff_label.show()
493
455
 
494
456
        self._diff_view = DiffView()
495
457
        self._add_to_right_table(self._diff_view, 4, True)
496
458
        self._diff_view.show()
497
459
 
498
460
    def _construct_file_message(self):
 
461
        file_message_box = gtk.VBox()
499
462
        scroller = gtk.ScrolledWindow()
500
463
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
501
464
 
502
465
        self._file_message_text_view = gtk.TextView()
503
466
        scroller.add(self._file_message_text_view)
 
467
        scroller.show()
504
468
        scroller.set_shadow_type(gtk.SHADOW_IN)
505
 
        scroller.show()
 
469
        file_message_box.pack_start(scroller, expand=True, fill=True)
506
470
 
507
471
        self._file_message_text_view.modify_font(pango.FontDescription("Monospace"))
508
472
        self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD)
510
474
        self._file_message_text_view.show()
511
475
 
512
476
        self._file_message_expander = gtk.Expander(_('File commit message'))
513
 
        self._file_message_expander.set_expanded(True)
514
 
        self._file_message_expander.add(scroller)
 
477
        self._file_message_expander.add(file_message_box)
 
478
        file_message_box.show()
515
479
        self._add_to_right_table(self._file_message_expander, 1, False)
516
480
        self._file_message_expander.show()
517
481
 
518
482
    def _construct_global_message(self):
519
483
        self._global_message_label = gtk.Label(_('Global Commit Message'))
520
 
        self._global_message_label.set_markup(_('<b>Global Commit Message</b>'))
521
484
        self._global_message_label.set_alignment(0, 0)
522
485
        self._right_pane_table.set_row_spacing(self._right_pane_table_row, 0)
523
486
        self._add_to_right_table(self._global_message_label, 1, False)
530
493
        self._global_message_text_view = gtk.TextView()
531
494
        self._global_message_text_view.modify_font(pango.FontDescription("Monospace"))
532
495
        scroller.add(self._global_message_text_view)
 
496
        scroller.show()
533
497
        scroller.set_shadow_type(gtk.SHADOW_IN)
534
 
        scroller.show()
535
498
        self._add_to_right_table(scroller, 2, True)
536
499
        self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD)
537
500
        self._file_message_text_view.set_accepts_tab(False)
547
510
            if path is None:
548
511
                self._diff_view.show_diff(None)
549
512
            else:
550
 
                self._diff_view.show_diff([path.decode('UTF-8')])
 
513
                self._diff_view.show_diff([path])
551
514
            self._update_per_file_info(selection)
552
515
 
553
 
    def _on_accel_next(self, accel_group, window, keyval, modifier):
554
 
        # We don't really care about any of the parameters, because we know
555
 
        # where this message came from
556
 
        tree_selection = self._treeview_files.get_selection()
557
 
        (model, selection) = tree_selection.get_selected()
558
 
        if selection is None:
559
 
            next = None
560
 
        else:
561
 
            next = model.iter_next(selection)
562
 
 
563
 
        if next is None:
564
 
            # We have either made it to the end of the list, or nothing was
565
 
            # selected. Either way, select All Files, and jump to the global
566
 
            # commit message.
567
 
            self._treeview_files.set_cursor((0,))
568
 
            self._global_message_text_view.grab_focus()
569
 
        else:
570
 
            # Set the cursor to this entry, and jump to the per-file commit
571
 
            # message
572
 
            self._treeview_files.set_cursor(model.get_path(next))
573
 
            self._file_message_text_view.grab_focus()
574
 
 
575
516
    def _save_current_file_message(self):
576
517
        if self._last_selected_file is None:
577
518
            return # Nothing to save
583
524
 
584
525
    def _update_per_file_info(self, selection):
585
526
        # The node is changing, so cache the current message
586
 
        if not self._enable_per_file_commits:
587
 
            return
588
 
 
589
527
        self._save_current_file_message()
590
528
        text_buffer = self._file_message_text_view.get_buffer()
591
529
        file_id, display_path, message = self._files_store.get(selection, 0, 3, 5)
604
542
            self._last_selected_file = self._files_store.get_path(selection)
605
543
 
606
544
    def _get_specific_files(self):
607
 
        """Return the list of selected paths, and file info.
608
 
 
609
 
        :return: ([unicode paths], [{utf-8 file info}]
610
 
        """
611
545
        self._save_current_file_message()
612
546
        files = []
613
547
        records = iter(self._files_store)
616
550
 
617
551
        file_info = []
618
552
        for record in records:
619
 
            if self._commit_all_changes or record[2]:# [2] checkbox
620
 
                file_id = record[0] # [0] file_id
621
 
                path = record[1]    # [1] real path
622
 
                file_message = record[5] # [5] commit message
623
 
                files.append(path.decode('UTF-8'))
624
 
                if self._enable_per_file_commits and file_message:
625
 
                    # All of this needs to be utf-8 information
 
553
            if record[2]: # [2] checkbox
 
554
                file_id = record[0]
 
555
                path = record[1]
 
556
                file_message = record[5]
 
557
                files.append(record[1]) # [1] real path
 
558
                if file_message:
626
559
                    file_info.append({'path':path, 'file_id':file_id,
627
560
                                     'message':file_message})
628
561
        file_info.sort(key=lambda x:(x['path'], x['file_id']))
629
 
        if self._enable_per_file_commits:
630
 
            return files, file_info
631
 
        else:
632
 
            return files, []
 
562
        return files, file_info
633
563
 
634
564
    @show_bzr_error
635
565
    def _on_commit_clicked(self, button):
670
600
        rev_id = None
671
601
        revprops = {}
672
602
        if file_info:
673
 
            revprops['file-info'] = bencode.bencode(file_info).decode('UTF-8')
 
603
            revprops['file-info'] = bencode.bencode(file_info)
674
604
        try:
675
605
            rev_id = self._wt.commit(message,
676
606
                       allow_pointless=False,
700
630
 
701
631
    def _set_global_commit_message(self, message):
702
632
        """Just a helper for the test suite."""
703
 
        if isinstance(message, unicode):
704
 
            message = message.encode('UTF-8')
705
633
        self._global_message_text_view.get_buffer().set_text(message)
706
634
 
707
635
    def _set_file_commit_message(self, message):
708
636
        """Helper for the test suite."""
709
 
        if isinstance(message, unicode):
710
 
            message = message.encode('UTF-8')
711
637
        self._file_message_text_view.get_buffer().set_text(message)
712
638
 
713
639
    @staticmethod
714
640
    def _rev_to_pending_info(rev):
715
641
        """Get the information from a pending merge."""
716
642
        from bzrlib.osutils import format_date
 
643
 
717
644
        rev_dict = {}
718
645
        rev_dict['committer'] = re.sub('<.*@.*>', '', rev.committer).strip(' ')
719
646
        rev_dict['summary'] = rev.get_summary()
723
650
                                       show_offset=False)
724
651
        rev_dict['revision_id'] = rev.revision_id
725
652
        return rev_dict
 
653
 
 
654
 
 
655
# class CommitDialog(gtk.Dialog):
 
656
#     """ New implementation of the Commit dialog. """
 
657
#     def __init__(self, wt, wtpath, notbranch, selected=None, parent=None):
 
658
#         """ Initialize the Commit Dialog. """
 
659
#         gtk.Dialog.__init__(self, title="Commit - Olive",
 
660
#                                   parent=parent,
 
661
#                                   flags=0,
 
662
#                                   buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
 
663
#         
 
664
#         # Get arguments
 
665
#         self.wt = wt
 
666
#         self.wtpath = wtpath
 
667
#         self.notbranch = notbranch
 
668
#         self.selected = selected
 
669
#         
 
670
#         # Set the delta
 
671
#         self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
 
672
#         self.delta = self.wt.changes_from(self.old_tree)
 
673
#         
 
674
#         # Get pending merges
 
675
#         self.pending = self._pending_merges(self.wt)
 
676
#         
 
677
#         # Do some preliminary checks
 
678
#         self._is_checkout = False
 
679
#         self._is_pending = False
 
680
#         if self.wt is None and not self.notbranch:
 
681
#             error_dialog(_('Directory does not have a working tree'),
 
682
#                          _('Operation aborted.'))
 
683
#             self.close()
 
684
#             return
 
685
 
686
#         if self.notbranch:
 
687
#             error_dialog(_('Directory is not a branch'),
 
688
#                          _('You can perform this action only in a branch.'))
 
689
#             self.close()
 
690
#             return
 
691
#         else:
 
692
#             if self.wt.branch.get_bound_location() is not None:
 
693
#                 # we have a checkout, so the local commit checkbox must appear
 
694
#                 self._is_checkout = True
 
695
#             
 
696
#             if self.pending:
 
697
#                 # There are pending merges, file selection not supported
 
698
#                 self._is_pending = True
 
699
#         
 
700
#         # Create the widgets
 
701
#         # This is the main horizontal box, which is used to separate the commit
 
702
#         # info from the diff window.
 
703
#         self._hpane = gtk.HPaned()
 
704
#         self._button_commit = gtk.Button(_("Comm_it"), use_underline=True)
 
705
#         self._expander_files = gtk.Expander(_("File(s) to commit"))
 
706
#         self._vpaned_main = gtk.VPaned()
 
707
#         self._scrolledwindow_files = gtk.ScrolledWindow()
 
708
#         self._scrolledwindow_message = gtk.ScrolledWindow()
 
709
#         self._treeview_files = gtk.TreeView()
 
710
#         self._vbox_message = gtk.VBox()
 
711
#         self._label_message = gtk.Label(_("Commit message:"))
 
712
#         self._textview_message = gtk.TextView()
 
713
#         
 
714
#         if self._is_pending:
 
715
#             self._expander_merges = gtk.Expander(_("Pending merges"))
 
716
#             self._vpaned_list = gtk.VPaned()
 
717
#             self._scrolledwindow_merges = gtk.ScrolledWindow()
 
718
#             self._treeview_merges = gtk.TreeView()
 
719
 
720
#         # Set callbacks
 
721
#         self._button_commit.connect('clicked', self._on_commit_clicked)
 
722
#         self._treeview_files.connect('cursor-changed', self._on_treeview_files_cursor_changed)
 
723
#         self._treeview_files.connect('row-activated', self._on_treeview_files_row_activated)
 
724
#         
 
725
#         # Set properties
 
726
#         self._scrolledwindow_files.set_policy(gtk.POLICY_AUTOMATIC,
 
727
#                                               gtk.POLICY_AUTOMATIC)
 
728
#         self._scrolledwindow_message.set_policy(gtk.POLICY_AUTOMATIC,
 
729
#                                                 gtk.POLICY_AUTOMATIC)
 
730
#         self._textview_message.modify_font(pango.FontDescription("Monospace"))
 
731
#         self.set_default_size(500, 500)
 
732
#         self._vpaned_main.set_position(200)
 
733
#         self._button_commit.set_flags(gtk.CAN_DEFAULT)
 
734
 
735
#         if self._is_pending:
 
736
#             self._scrolledwindow_merges.set_policy(gtk.POLICY_AUTOMATIC,
 
737
#                                                    gtk.POLICY_AUTOMATIC)
 
738
#             self._treeview_files.set_sensitive(False)
 
739
#         
 
740
#         # Construct the dialog
 
741
#         self.action_area.pack_end(self._button_commit)
 
742
#         
 
743
#         self._scrolledwindow_files.add(self._treeview_files)
 
744
#         self._scrolledwindow_message.add(self._textview_message)
 
745
#         
 
746
#         self._expander_files.add(self._scrolledwindow_files)
 
747
#         
 
748
#         self._vbox_message.pack_start(self._label_message, False, False)
 
749
#         self._vbox_message.pack_start(self._scrolledwindow_message, True, True)
 
750
#         
 
751
#         if self._is_pending:        
 
752
#             self._expander_merges.add(self._scrolledwindow_merges)
 
753
#             self._scrolledwindow_merges.add(self._treeview_merges)
 
754
#             self._vpaned_list.add1(self._expander_files)
 
755
#             self._vpaned_list.add2(self._expander_merges)
 
756
#             self._vpaned_main.add1(self._vpaned_list)
 
757
#         else:
 
758
#             self._vpaned_main.add1(self._expander_files)
 
759
 
760
#         self._vpaned_main.add2(self._vbox_message)
 
761
#         
 
762
#         self._hpane.pack1(self._vpaned_main)
 
763
#         self.vbox.pack_start(self._hpane, expand=True, fill=True)
 
764
#         if self._is_checkout: 
 
765
#             self._check_local = gtk.CheckButton(_("_Only commit locally"),
 
766
#                                                 use_underline=True)
 
767
#             self.vbox.pack_start(self._check_local, False, False)
 
768
#             if have_dbus:
 
769
#                 bus = dbus.SystemBus()
 
770
#                 proxy_obj = bus.get_object('org.freedesktop.NetworkManager', 
 
771
#                               '/org/freedesktop/NetworkManager')
 
772
#                 dbus_iface = dbus.Interface(
 
773
#                         proxy_obj, 'org.freedesktop.NetworkManager')
 
774
#                 try:
 
775
#                     # 3 is the enum value for STATE_CONNECTED
 
776
#                     self._check_local.set_active(dbus_iface.state() != 3)
 
777
#                 except dbus.DBusException, e:
 
778
#                     # Silently drop errors. While DBus may be 
 
779
#                     # available, NetworkManager doesn't necessarily have to be
 
780
#                     mutter("unable to get networkmanager state: %r" % e)
 
781
#                 
 
782
#         # Create the file list
 
783
#         self._create_file_view()
 
784
#         # Create the pending merges
 
785
#         self._create_pending_merges()
 
786
#         self._create_diff_view()
 
787
#         
 
788
#         # Expand the corresponding expander
 
789
#         if self._is_pending:
 
790
#             self._expander_merges.set_expanded(True)
 
791
#         else:
 
792
#             self._expander_files.set_expanded(True)
 
793
#         
 
794
#         # Display dialog
 
795
#         self.vbox.show_all()
 
796
#         
 
797
#         # Default to Commit button
 
798
#         self._button_commit.grab_default()
 
799
#     
 
800
#     def _show_diff_view(self, treeview):
 
801
#         # FIXME: the diff window freezes for some reason
 
802
#         treeselection = treeview.get_selection()
 
803
#         (model, iter) = treeselection.get_selected()
 
804
 
805
#         if iter is not None:
 
806
#             selected = model.get_value(iter, 3) # Get the real_path attribute
 
807
#             self._diff_display.show_diff([selected])
 
808
 
809
#     def _on_treeview_files_cursor_changed(self, treeview):
 
810
#         self._show_diff_view(treeview)
 
811
#         
 
812
#     def _on_treeview_files_row_activated(self, treeview, path, view_column):
 
813
#         self._show_diff_view(treeview)
 
814
#     
 
815
#     @show_bzr_error
 
816
#     def _on_commit_clicked(self, button):
 
817
#         """ Commit button clicked handler. """
 
818
#         textbuffer = self._textview_message.get_buffer()
 
819
#         start, end = textbuffer.get_bounds()
 
820
#         message = textbuffer.get_text(start, end).decode('utf-8')
 
821
#         
 
822
#         if not self.pending:
 
823
#             specific_files = self._get_specific_files()
 
824
#         else:
 
825
#             specific_files = None
 
826
 
827
#         if message == '':
 
828
#             response = question_dialog(_('Commit with an empty message?'),
 
829
#                                        _('You can describe your commit intent in the message.'))
 
830
#             if response == gtk.RESPONSE_NO:
 
831
#                 # Kindly give focus to message area
 
832
#                 self._textview_message.grab_focus()
 
833
#                 return
 
834
 
835
#         if self._is_checkout:
 
836
#             local = self._check_local.get_active()
 
837
#         else:
 
838
#             local = False
 
839
 
840
#         if list(self.wt.unknowns()) != []:
 
841
#             response = question_dialog(_("Commit with unknowns?"),
 
842
#                _("Unknown files exist in the working tree. Commit anyway?"))
 
843
#             if response == gtk.RESPONSE_NO:
 
844
#                 return
 
845
#         
 
846
#         try:
 
847
#             self.wt.commit(message,
 
848
#                        allow_pointless=False,
 
849
#                        strict=False,
 
850
#                        local=local,
 
851
#                        specific_files=specific_files)
 
852
#         except errors.PointlessCommit:
 
853
#             response = question_dialog(_('Commit with no changes?'),
 
854
#                                        _('There are no changes in the working tree.'))
 
855
#             if response == gtk.RESPONSE_YES:
 
856
#                 self.wt.commit(message,
 
857
#                                allow_pointless=True,
 
858
#                                strict=False,
 
859
#                                local=local,
 
860
#                                specific_files=specific_files)
 
861
#         self.response(gtk.RESPONSE_OK)
 
862
 
863
#     def _pending_merges(self, wt):
 
864
#         """ Return a list of pending merges or None if there are none of them. """
 
865
#         parents = wt.get_parent_ids()
 
866
#         if len(parents) < 2:
 
867
#             return None
 
868
#         
 
869
#         import re
 
870
#         from bzrlib.osutils import format_date
 
871
#         
 
872
#         pending = parents[1:]
 
873
#         branch = wt.branch
 
874
#         last_revision = parents[0]
 
875
#         
 
876
#         if last_revision is not None:
 
877
#             try:
 
878
#                 ignore = set(branch.repository.get_ancestry(last_revision))
 
879
#             except errors.NoSuchRevision:
 
880
#                 # the last revision is a ghost : assume everything is new 
 
881
#                 # except for it
 
882
#                 ignore = set([None, last_revision])
 
883
#         else:
 
884
#             ignore = set([None])
 
885
#         
 
886
#         pm = []
 
887
#         for merge in pending:
 
888
#             ignore.add(merge)
 
889
#             try:
 
890
#                 m_revision = branch.repository.get_revision(merge)
 
891
#                 
 
892
#                 rev = {}
 
893
#                 rev['committer'] = re.sub('<.*@.*>', '', m_revision.committer).strip(' ')
 
894
#                 rev['summary'] = m_revision.get_summary()
 
895
#                 rev['date'] = format_date(m_revision.timestamp,
 
896
#                                           m_revision.timezone or 0, 
 
897
#                                           'original', date_fmt="%Y-%m-%d",
 
898
#                                           show_offset=False)
 
899
#                 
 
900
#                 pm.append(rev)
 
901
#                 
 
902
#                 inner_merges = branch.repository.get_ancestry(merge)
 
903
#                 assert inner_merges[0] is None
 
904
#                 inner_merges.pop(0)
 
905
#                 inner_merges.reverse()
 
906
#                 for mmerge in inner_merges:
 
907
#                     if mmerge in ignore:
 
908
#                         continue
 
909
#                     mm_revision = branch.repository.get_revision(mmerge)
 
910
#                     
 
911
#                     rev = {}
 
912
#                     rev['committer'] = re.sub('<.*@.*>', '', mm_revision.committer).strip(' ')
 
913
#                     rev['summary'] = mm_revision.get_summary()
 
914
#                     rev['date'] = format_date(mm_revision.timestamp,
 
915
#                                               mm_revision.timezone or 0, 
 
916
#                                               'original', date_fmt="%Y-%m-%d",
 
917
#                                               show_offset=False)
 
918
#                 
 
919
#                     pm.append(rev)
 
920
#                     
 
921
#                     ignore.add(mmerge)
 
922
#             except errors.NoSuchRevision:
 
923
#                 print "DEBUG: NoSuchRevision:", merge
 
924
#         
 
925
#         return pm
 
926
 
927
#     def _create_file_view(self):
 
928
#         self._file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,   # [0] checkbox
 
929
#                                          gobject.TYPE_STRING,    # [1] path to display
 
930
#                                          gobject.TYPE_STRING,    # [2] changes type
 
931
#                                          gobject.TYPE_STRING)    # [3] real path
 
932
#         self._treeview_files.set_model(self._file_store)
 
933
#         crt = gtk.CellRendererToggle()
 
934
#         crt.set_property("activatable", True)
 
935
#         crt.connect("toggled", self._toggle_commit, self._file_store)
 
936
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Commit'),
 
937
#                                      crt, active=0))
 
938
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
 
939
#                                      gtk.CellRendererText(), text=1))
 
940
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
 
941
#                                      gtk.CellRendererText(), text=2))
 
942
 
943
#         for path, id, kind in self.delta.added:
 
944
#             marker = osutils.kind_marker(kind)
 
945
#             if self.selected is not None:
 
946
#                 if path == os.path.join(self.wtpath, self.selected):
 
947
#                     self._file_store.append([ True, path+marker, _('added'), path ])
 
948
#                 else:
 
949
#                     self._file_store.append([ False, path+marker, _('added'), path ])
 
950
#             else:
 
951
#                 self._file_store.append([ True, path+marker, _('added'), path ])
 
952
 
953
#         for path, id, kind in self.delta.removed:
 
954
#             marker = osutils.kind_marker(kind)
 
955
#             if self.selected is not None:
 
956
#                 if path == os.path.join(self.wtpath, self.selected):
 
957
#                     self._file_store.append([ True, path+marker, _('removed'), path ])
 
958
#                 else:
 
959
#                     self._file_store.append([ False, path+marker, _('removed'), path ])
 
960
#             else:
 
961
#                 self._file_store.append([ True, path+marker, _('removed'), path ])
 
962
 
963
#         for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
 
964
#             marker = osutils.kind_marker(kind)
 
965
#             if text_modified or meta_modified:
 
966
#                 changes = _('renamed and modified')
 
967
#             else:
 
968
#                 changes = _('renamed')
 
969
#             if self.selected is not None:
 
970
#                 if newpath == os.path.join(self.wtpath, self.selected):
 
971
#                     self._file_store.append([ True,
 
972
#                                               oldpath+marker + '  =>  ' + newpath+marker,
 
973
#                                               changes,
 
974
#                                               newpath
 
975
#                                             ])
 
976
#                 else:
 
977
#                     self._file_store.append([ False,
 
978
#                                               oldpath+marker + '  =>  ' + newpath+marker,
 
979
#                                               changes,
 
980
#                                               newpath
 
981
#                                             ])
 
982
#             else:
 
983
#                 self._file_store.append([ True,
 
984
#                                           oldpath+marker + '  =>  ' + newpath+marker,
 
985
#                                           changes,
 
986
#                                           newpath
 
987
#                                         ])
 
988
 
989
#         for path, id, kind, text_modified, meta_modified in self.delta.modified:
 
990
#             marker = osutils.kind_marker(kind)
 
991
#             if self.selected is not None:
 
992
#                 if path == os.path.join(self.wtpath, self.selected):
 
993
#                     self._file_store.append([ True, path+marker, _('modified'), path ])
 
994
#                 else:
 
995
#                     self._file_store.append([ False, path+marker, _('modified'), path ])
 
996
#             else:
 
997
#                 self._file_store.append([ True, path+marker, _('modified'), path ])
 
998
#     
 
999
#     def _create_pending_merges(self):
 
1000
#         if not self.pending:
 
1001
#             return
 
1002
#         
 
1003
#         liststore = gtk.ListStore(gobject.TYPE_STRING,
 
1004
#                                   gobject.TYPE_STRING,
 
1005
#                                   gobject.TYPE_STRING)
 
1006
#         self._treeview_merges.set_model(liststore)
 
1007
#         
 
1008
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Date'),
 
1009
#                                             gtk.CellRendererText(), text=0))
 
1010
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Committer'),
 
1011
#                                             gtk.CellRendererText(), text=1))
 
1012
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Summary'),
 
1013
#                                             gtk.CellRendererText(), text=2))
 
1014
#         
 
1015
#         for item in self.pending:
 
1016
#             liststore.append([ item['date'],
 
1017
#                                item['committer'],
 
1018
#                                item['summary'] ])
 
1019
#     
 
1020
 
1021
#     def _create_diff_view(self):
 
1022
#         from diff import DiffView
 
1023
 
1024
#         self._diff_display = DiffView()
 
1025
#         self._diff_display.set_trees(self.wt, self.wt.basis_tree())
 
1026
#         self._diff_display.show_diff(None)
 
1027
#         self._diff_display.show()
 
1028
#         self._hpane.pack2(self._diff_display)
 
1029
 
1030
#     def _get_specific_files(self):
 
1031
#         ret = []
 
1032
#         it = self._file_store.get_iter_first()
 
1033
#         while it:
 
1034
#             if self._file_store.get_value(it, 0):
 
1035
#                 # get real path from hidden column 3
 
1036
#                 ret.append(self._file_store.get_value(it, 3))
 
1037
#             it = self._file_store.iter_next(it)
 
1038
 
1039
#         return ret
 
1040
#     
 
1041
#     def _toggle_commit(self, cell, path, model):
 
1042
#         model[path][0] = not model[path][0]
 
1043
#         return