From d25a6e3c35ef48702f2fc4311b44cada4db8d415 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 22 Nov 2013 20:39:08 +0530 Subject: [PATCH] Use both name and mime type to decide file syntax --- src/calibre/gui2/tweak_book/boss.py | 4 ++-- src/calibre/gui2/tweak_book/editor/__init__.py | 2 +- src/calibre/gui2/tweak_book/file_list.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 00e38df3bf..ed2758a3c9 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -190,7 +190,7 @@ class Boss(QObject): if c.opf_name in editors: editors[c.opf_name].replace_data(c.raw_data(c.opf_name)) mt = c.mime_map[d.file_name] - syntax = syntax_from_mime(mt) + syntax = syntax_from_mime(d.file_name, mt) if syntax: if d.using_template: self.edit_file(d.file_name, syntax, use_template=d.file_data.decode('utf-8')) @@ -578,7 +578,7 @@ class Boss(QObject): if name in editors: self.gui.central.show_editor(editors[name]) return - syntax = syntax or syntax_from_mime(mime) + syntax = syntax or syntax_from_mime(name, mime) if not syntax: return error_dialog( self.gui, _('Unsupported file format'), diff --git a/src/calibre/gui2/tweak_book/editor/__init__.py b/src/calibre/gui2/tweak_book/editor/__init__.py index 96f1a47a1e..651733da00 100644 --- a/src/calibre/gui2/tweak_book/editor/__init__.py +++ b/src/calibre/gui2/tweak_book/editor/__init__.py @@ -11,7 +11,7 @@ from PyQt4.Qt import QTextCharFormat from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES from calibre.ebooks.oeb.polish.container import guess_type -def syntax_from_mime(mime): +def syntax_from_mime(name, mime): if mime in OEB_DOCS: return 'html' if mime in OEB_STYLES: diff --git a/src/calibre/gui2/tweak_book/file_list.py b/src/calibre/gui2/tweak_book/file_list.py index f98f2b10cc..876e8b7be4 100644 --- a/src/calibre/gui2/tweak_book/file_list.py +++ b/src/calibre/gui2/tweak_book/file_list.py @@ -416,11 +416,11 @@ class FileList(QTreeWidget): name = unicode(item.data(0, NAME_ROLE).toString()) ok = category in {'text', 'styles'} if ok: - ans[category][name] = syntax_from_mime(mime) + ans[category][name] = syntax_from_mime(name, mime) if not ok and category == 'misc': ok = mime in {guess_type('a.'+x) for x in ('opf', 'ncx', 'txt', 'xml')} if ok and item.isSelected(): - ans['selected'][name] = syntax_from_mime(mime) + ans['selected'][name] = syntax_from_mime(name, mime) return ans class NewFileDialog(QDialog): # {{{