mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Use both name and mime type to decide file syntax
This commit is contained in:
parent
b02c37bf8c
commit
d25a6e3c35
@ -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'),
|
||||
|
@ -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:
|
||||
|
@ -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): # {{{
|
||||
|
Loading…
x
Reference in New Issue
Block a user