diff options
author | Gonzalo Odiard <godiard@sugarlabs.org> | 2010-11-17 11:52:41 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@sugarlabs.org> | 2010-11-17 12:34:52 (GMT) |
commit | e3467bfcad1eedaf123df2e2f0c1e92d70c5c394 (patch) | |
tree | 4729a5064fd1560767c6b77546848505ab5070b2 | |
parent | 756c917bbb1f5af1f0cea527295816c91cf3721d (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.
-rw-r--r-- | AbiWordActivity.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/AbiWordActivity.py b/AbiWordActivity.py index 5a9206d..1e40024 100644 --- a/AbiWordActivity.py +++ b/AbiWordActivity.py @@ -326,9 +326,7 @@ class AbiWordActivity (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']): logger.debug('Opening file in view source mode') self.abiword_canvas.load_file('file://' + file_path, 'text/plain') else: @@ -340,9 +338,7 @@ class AbiWordActivity (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: @@ -362,6 +358,16 @@ class AbiWordActivity (Activity): 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 + def _selection_cb(self, abi, b): self._edit_toolbar.copy.set_sensitive(True) |