/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: Szilveszter Farkas
  • Date: 2009-05-27 09:19:42 UTC
  • mfrom: (625.8.1 LP316310)
  • mto: This revision was merged to the branch mainline in revision 639.
  • Revision ID: szilveszter.farkas@gmail.com-20090527091942-oqeaopqm7ei3wsn8
Merge Jasper's fix for Olive status dialog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
import os.path
 
18
import re
 
19
 
17
20
try:
18
21
    import pygtk
19
22
    pygtk.require("2.0")
24
27
import gobject
25
28
import pango
26
29
 
27
 
import os.path
28
 
import re
29
 
 
30
30
from bzrlib import errors, osutils
31
31
from bzrlib.trace import mutter
32
32
from bzrlib.util import bencode
33
33
 
34
34
from bzrlib.plugins.gtk import _i18n
35
 
from dialog import error_dialog, question_dialog
36
 
from errors import show_bzr_error
 
35
from bzrlib.plugins.gtk.dialog import question_dialog
 
36
from bzrlib.plugins.gtk.errors import show_bzr_error
37
37
 
38
38
try:
39
39
    import dbus
97
97
    return pm
98
98
 
99
99
 
 
100
_newline_variants_re = re.compile(r'\r\n?')
 
101
def _sanitize_and_decode_message(utf8_message):
 
102
    """Turn a utf-8 message into a sanitized Unicode message."""
 
103
    fixed_newline = _newline_variants_re.sub('\n', utf8_message)
 
104
    return fixed_newline.decode('utf-8')
 
105
 
 
106
 
100
107
class CommitDialog(gtk.Dialog):
101
108
    """Implementation of Commit."""
102
109
 
103
110
    def __init__(self, wt, selected=None, parent=None):
104
 
        gtk.Dialog.__init__(self, title="Commit - Olive",
 
111
        gtk.Dialog.__init__(self, title="Commit to %s" % wt.basedir,
105
112
                                  parent=parent,
106
113
                                  flags=0,
107
 
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
 
114
                                  buttons=(gtk.STOCK_CANCEL,
 
115
                                           gtk.RESPONSE_CANCEL))
108
116
        self._question_dialog = question_dialog
 
117
        
 
118
        self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
109
119
 
110
120
        self._wt = wt
111
121
        # TODO: Do something with this value, it is used by Olive
630
640
            if self._commit_all_changes or record[2]:# [2] checkbox
631
641
                file_id = record[0] # [0] file_id
632
642
                path = record[1]    # [1] real path
633
 
                file_message = record[5] # [5] commit message
 
643
                # [5] commit message
 
644
                file_message = _sanitize_and_decode_message(record[5])
634
645
                files.append(path.decode('UTF-8'))
635
646
                if self._enable_per_file_commits and file_message:
636
647
                    # All of this needs to be utf-8 information
 
648
                    file_message = file_message.encode('UTF-8')
637
649
                    file_info.append({'path':path, 'file_id':file_id,
638
650
                                     'message':file_message})
639
651
        file_info.sort(key=lambda x:(x['path'], x['file_id']))
653
665
        if message == '':
654
666
            response = self._question_dialog(
655
667
                _i18n('Commit with an empty message?'),
656
 
                _i18n('You can describe your commit intent in the message.'))
 
668
                _i18n('You can describe your commit intent in the message.'),
 
669
                parent=self)
657
670
            if response == gtk.RESPONSE_NO:
658
671
                # Kindly give focus to message area
659
672
                self._global_message_text_view.grab_focus()
673
686
        for path in self._wt.unknowns():
674
687
            response = self._question_dialog(
675
688
                _i18n("Commit with unknowns?"),
676
 
                _i18n("Unknown files exist in the working tree. Commit anyway?"))
 
689
                _i18n("Unknown files exist in the working tree. Commit anyway?"),
 
690
                parent=self)
 
691
                # Doesn't set a parent for the dialog..
677
692
            if response == gtk.RESPONSE_NO:
678
693
                return
679
694
            break
693
708
            response = self._question_dialog(
694
709
                _i18n('Commit with no changes?'),
695
710
                _i18n('There are no changes in the working tree.'
696
 
                      ' Do you want to commit anyway?'))
 
711
                      ' Do you want to commit anyway?'),
 
712
                parent=self)
697
713
            if response == gtk.RESPONSE_YES:
698
714
                rev_id = self._wt.commit(message,
699
715
                               allow_pointless=True,
707
723
    def _get_global_commit_message(self):
708
724
        buf = self._global_message_text_view.get_buffer()
709
725
        start, end = buf.get_bounds()
710
 
        return buf.get_text(start, end).decode('utf-8')
 
726
        text = buf.get_text(start, end)
 
727
        return _sanitize_and_decode_message(text)
711
728
 
712
729
    def _set_global_commit_message(self, message):
713
730
        """Just a helper for the test suite."""