/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: Jelmer Vernooij
  • Date: 2011-12-20 16:47:38 UTC
  • Revision ID: jelmer@canonical.com-20111220164738-l6tgnbttkxmq6877
Cope with some strings being unicode when returned by some versions of gtk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from bzrlib import (
25
25
    bencode,
26
26
    errors,
 
27
    osutils,
27
28
    trace,
28
29
    )
29
30
from bzrlib.plugins.gtk.dialog import question_dialog
92
93
def _sanitize_and_decode_message(utf8_message):
93
94
    """Turn a utf-8 message into a sanitized Unicode message."""
94
95
    fixed_newline = _newline_variants_re.sub('\n', utf8_message)
95
 
    return fixed_newline.decode('utf-8')
 
96
    return osutils.safe_unicode(fixed_newline)
96
97
 
97
98
 
98
99
class CommitDialog(Gtk.Dialog):
186
187
 
187
188
        all_enabled = (self._selected is None)
188
189
        # The first entry is always the 'whole tree'
189
 
        all_iter = store.append([None, None, all_enabled, 'All Files', '', ''])
 
190
        all_iter = store.append(["", "", all_enabled, 'All Files', '', ''])
190
191
        initial_cursor = store.get_path(all_iter)
191
192
        # should we pass specific_files?
192
193
        self._wt.lock_read()
443
444
                                     self._on_treeview_files_cursor_changed)
444
445
 
445
446
    def _toggle_commit(self, cell, path, model):
446
 
        if model[path][0] is None: # No file_id means 'All Files'
 
447
        if model[path][0] == "": # No file_id means 'All Files'
447
448
            new_val = not model[path][2]
448
449
            for node in model:
449
450
                node[2] = new_val
571
572
        if selection is not None:
572
573
            path, display_path = model.get(selection, 1, 3)
573
574
            self._diff_label.set_text(_i18n('Diff for ') + display_path)
574
 
            if path is None:
 
575
            if path == "":
575
576
                self._diff_view.show_diff(None)
576
577
            else:
577
 
                self._diff_view.show_diff([path.decode('UTF-8')])
 
578
                self._diff_view.show_diff([osutils.safe_unicode(path)])
578
579
            self._update_per_file_info(selection)
579
580
 
580
581
    def _on_accel_next(self, accel_group, window, keyval, modifier):
592
593
            # selected. Either way, select All Files, and jump to the global
593
594
            # commit message.
594
595
            self._treeview_files.set_cursor(
595
 
                Gtk.TreePath(path=0), None, False)
 
596
                Gtk.TreePath(path=0), "", False)
596
597
            self._global_message_text_view.grab_focus()
597
598
        else:
598
599
            # Set the cursor to this entry, and jump to the per-file commit
617
618
        self._save_current_file_message()
618
619
        text_buffer = self._file_message_text_view.get_buffer()
619
620
        file_id, display_path, message = self._files_store.get(selection, 0, 3, 5)
620
 
        if file_id is None: # Whole tree
 
621
        if file_id == "": # Whole tree
621
622
            self._file_message_expander.set_label(_i18n('File commit message'))
622
623
            self._file_message_expander.set_expanded(False)
623
624
            self._file_message_expander.set_sensitive(False)
640
641
        files = []
641
642
        records = iter(self._files_store)
642
643
        rec = records.next() # Skip the All Files record
643
 
        assert rec[0] is None, "Are we skipping the wrong record?"
 
644
        assert rec[0] == "", "Are we skipping the wrong record?"
644
645
 
645
646
        file_info = []
646
647
        for record in records:
647
648
            if self._commit_all_changes or record[2]:# [2] checkbox
648
 
                file_id = record[0] # [0] file_id
649
 
                path = record[1]    # [1] real path
 
649
                file_id = osutils.safe_utf8(record[0]) # [0] file_id
 
650
                path = osutils.safe_utf8(record[1])    # [1] real path
650
651
                # [5] commit message
651
652
                file_message = _sanitize_and_decode_message(record[5])
652
653
                files.append(path.decode('UTF-8'))