diff options
author | Gonzalo Odiard <godiard@sugarlabs.org> | 2010-11-17 12:06:23 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@sugarlabs.org> | 2010-11-17 12:34:15 (GMT) |
commit | ba4c042918ff828c14ba18130bbeb70026129b8e (patch) | |
tree | 18fc006fc717527dcb805e249c00592b1f547315 /AbiWordActivity.py | |
parent | 865b2c7150f14150c83552022dd4ee0ff60628a7 (diff) |
OLPC #8972 - Open rtf and html files like rich text
The mime types from files rtf and html have text/plain in mime_parents.
We need to modify the criteria to open them like rich text.
Diffstat (limited to 'AbiWordActivity.py')
-rw-r--r-- | AbiWordActivity.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/AbiWordActivity.py b/AbiWordActivity.py index 8d17904..abc2d54 100644 --- a/AbiWordActivity.py +++ b/AbiWordActivity.py @@ -400,9 +400,7 @@ class AbiWordActivity(activity.Activity): def read_file(self, file_path): logging.debug('AbiWordActivity.read_file: %s, mimetype: %s', file_path, self.metadata['mime_type']) - mime_parents = mime.get_mime_parents(self.metadata['mime_type']) - if self.metadata['mime_type'] in ['text/plain', 'text/csv'] or \ - 'text/plain' in mime_parents: + if self._is_plain_text(self.metadata['mime_type']): self.abiword_canvas.load_file('file://' + file_path, 'text/plain') else: # we pass no mime/file type, let libabiword autodetect it, @@ -413,9 +411,7 @@ class AbiWordActivity(activity.Activity): logging.debug('AbiWordActivity.write_file: %s, mimetype: %s', file_path, self.metadata['mime_type']) # if we were editing a text file save as plain text - mime_parents = mime.get_mime_parents(self.metadata['mime_type']) - if self.metadata['mime_type'] in ['text/plain', 'text/csv'] or \ - 'text/plain' in mime_parents: + if self._is_plain_text(self.metadata['mime_type']): logger.debug('Writing file as type source (text/plain)') self.abiword_canvas.save('file://' + file_path, 'text/plain', '') else: @@ -434,3 +430,13 @@ class AbiWordActivity(activity.Activity): self.metadata['fulltext'] = \ self.abiword_canvas.get_content(extension_or_mimetype=".txt") \ [:3000] + + def _is_plain_text(self, mime_type): + # These types have 'text/plain' in their mime_parents but we need + # use it like rich text + if mime_type in ['application/rtf', 'text/rtf', 'text/html']: + return False + + mime_parents = mime.get_mime_parents(self.metadata['mime_type']) + return self.metadata['mime_type'] in ['text/plain', 'text/csv'] or \ + 'text/plain' in mime_parents |