Edit book: Insert link: Add history for the template

This commit is contained in:
Kovid Goyal 2019-01-04 10:58:18 +05:30
parent 8ef42dafc5
commit cb5b06c556
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -24,7 +24,7 @@ from calibre.ebooks.oeb.polish.cover import get_raster_cover_name
from calibre.ebooks.oeb.polish.utils import lead_text, guess_type from calibre.ebooks.oeb.polish.utils import lead_text, guess_type
from calibre.gui2 import error_dialog, choose_files, choose_save_file, info_dialog, choose_images from calibre.gui2 import error_dialog, choose_files, choose_save_file, info_dialog, choose_images
from calibre.gui2.tweak_book import tprefs, current_container from calibre.gui2.tweak_book import tprefs, current_container
from calibre.gui2.widgets2 import Dialog as BaseDialog from calibre.gui2.widgets2 import Dialog as BaseDialog, HistoryComboBox
from calibre.utils.icu import primary_sort_key, sort_key, primary_contains, numeric_sort_key from calibre.utils.icu import primary_sort_key, sort_key, primary_contains, numeric_sort_key
from calibre.utils.matcher import get_char, Matcher from calibre.utils.matcher import get_char, Matcher
from calibre.gui2.complete2 import EditWithComplete from calibre.gui2.complete2 import EditWithComplete
@ -671,7 +671,9 @@ class InsertLink(Dialog):
t.setText(self.initial_text or '') t.setText(self.initial_text or '')
t.setPlaceholderText(_('The (optional) text for the link')) t.setPlaceholderText(_('The (optional) text for the link'))
self.template_edit = t = QLineEdit(self) self.template_edit = t = HistoryComboBox(self)
t.lineEdit().setClearButtonEnabled(True)
t.initialize('edit_book_insert_link_template_history')
tl.addRow(_('Tem&plate:'), t) tl.addRow(_('Tem&plate:'), t)
from calibre.gui2.tweak_book.editor.smarts.html import DEFAULT_LINK_TEMPLATE from calibre.gui2.tweak_book.editor.smarts.html import DEFAULT_LINK_TEMPLATE
t.setText(tprefs.get('insert-hyperlink-template', None) or DEFAULT_LINK_TEMPLATE) t.setText(tprefs.get('insert-hyperlink-template', None) or DEFAULT_LINK_TEMPLATE)
@ -759,8 +761,8 @@ class InsertLink(Dialog):
target = target.split('#', 1)[0] target = target.split('#', 1)[0]
target = self.container.href_to_name(target) target = self.container.href_to_name(target)
ans = ans.replace('_SOURCE_FILENAME_', self.source_name) ans = ans.replace('_SOURCE_FILENAME_', self.source_name)
ans = ans.replace('_DEST_FILENAME_', target) ans = ans.replace('_DEST_FILENAME_', target or '')
ans = ans.replace('_ANCHOR_', frag) ans = ans.replace('_ANCHOR_', frag or '')
return ans return ans
@classmethod @classmethod