Fix a serialization bug (inversed tags)

This commit is contained in:
Marco Pesenti Gritti 2006-04-24 15:00:58 -04:00
parent 9f0348c002
commit 13b2219223
2 changed files with 19 additions and 15 deletions

View File

@ -213,7 +213,4 @@ class WebActivity(activity.Activity):
web_activity = WebActivity()
web_activity.activity_connect_to_shell()
try:
gtk.main()
except KeyboardInterrupt:
pass
gtk.main()

View File

@ -128,24 +128,24 @@ class RichTextSerializer:
if not next_it.forward_to_tag_toggle(None):
next_it = buf.get_end_iter()
reopen_tags = []
tags_to_reopen = []
for tag in it.get_toggled_tags(False):
while 1:
open_tag = self._open_tags.pop()
if open_tag != tag:
xml += self.serialize_tag_end(open_tag)
reopen_tags.append(open_tag)
else:
xml += self.serialize_tag_end(tag)
xml += self.serialize_tag_end(tag)
if open_tag == tag:
break
tags_to_reopen.append(open_tag)
for tag in reopen_tags + it.get_toggled_tags(True):
for tag in tags_to_reopen + it.get_toggled_tags(True):
self._open_tags.append(tag)
xml += self.serialize_tag_start(tag)
xml += buf.get_text(it, next_it)
if next_it.is_end():
self._open_tags.reverse()
for tag in self._open_tags:
xml += self.serialize_tag_end(tag)
@ -172,7 +172,14 @@ if __name__ == "__main__":
rich_buf = RichTextBuffer()
xml_string = "<richtext><bold><italic>Hello</italic>World</bold></richtext>"
xml_string = "<richtext>"
#xml_string += "<bold><italic>Test</italic>one</bold>\n"
xml_string += "<bold><italic>Test two</italic></bold>"
xml_string += "</richtext>"
RichTextSerializer().deserialize(xml_string, rich_buf)
view = gtk.TextView(rich_buf)