mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add UI for search and replace
This commit is contained in:
parent
eac1e8b182
commit
774890af68
@ -5,7 +5,7 @@ from __python__ import bound_methods, hash_literals
|
|||||||
from elementmaker import E
|
from elementmaker import E
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
from dom import add_extra_css, build_rule, ensure_id
|
from dom import add_extra_css, build_rule, clear, ensure_id
|
||||||
from utils import safe_set_inner_html
|
from utils import safe_set_inner_html
|
||||||
from widgets import create_button
|
from widgets import create_button
|
||||||
|
|
||||||
@ -88,7 +88,6 @@ def create_simple_widget(name, text, tooltip, input_widget_, getter, setter, suf
|
|||||||
}
|
}
|
||||||
registry[name] = ops
|
registry[name] = ops
|
||||||
ops.set(label, get_option_value(name))
|
ops.set(label, get_option_value(name))
|
||||||
ops.set(label, get_option_value(name))
|
|
||||||
if is_option_disabled(name):
|
if is_option_disabled(name):
|
||||||
ops.set_disabled(label, True)
|
ops.set_disabled(label, True)
|
||||||
input_widget(label).addEventListener('change', on_change.bind(None, name))
|
input_widget(label).addEventListener('change', on_change.bind(None, name))
|
||||||
@ -354,7 +353,56 @@ def toc(container):
|
|||||||
# Search & replace {{{
|
# Search & replace {{{
|
||||||
@ep
|
@ep
|
||||||
def search_and_replace(container):
|
def search_and_replace(container):
|
||||||
pass
|
|
||||||
|
def add(val):
|
||||||
|
c = container_for_option('search_replace')
|
||||||
|
c.appendChild(E.div(
|
||||||
|
class_='simple-group sr-instance',
|
||||||
|
style='border-bottom: solid 1px currentColor; margin-bottom: 1ex',
|
||||||
|
E.label(
|
||||||
|
E.span(_('Search:')), E.input(type='text', name='search')
|
||||||
|
),
|
||||||
|
E.label(
|
||||||
|
E.span(_('Replace:')), E.input(type='text', name='replace')
|
||||||
|
),
|
||||||
|
))
|
||||||
|
if val and val[0]:
|
||||||
|
c.lastChild.querySelector('input[name="search"]').value = val[0]
|
||||||
|
c.lastChild.querySelector('input[name="replace"]').value = val[1]
|
||||||
|
return c.lastChild
|
||||||
|
|
||||||
|
container.appendChild(E.div(data_option_name='search_replace'))
|
||||||
|
|
||||||
|
ops = {
|
||||||
|
'get': def get(container): # noqa: unused-local
|
||||||
|
ans = v'[]'
|
||||||
|
for div in container.querySelectorAll('.sr-instance'):
|
||||||
|
search, replace = div.querySelectorAll('input')
|
||||||
|
if search.value:
|
||||||
|
r = replace.value or '' # noqa: unused-local
|
||||||
|
ans.push(v'[search.value, r]')
|
||||||
|
return JSON.stringify(ans)
|
||||||
|
,
|
||||||
|
'set': def set(container, encval): # noqa: unused-local
|
||||||
|
try:
|
||||||
|
vals = JSON.parse(encval)
|
||||||
|
except:
|
||||||
|
vals = v'[]'
|
||||||
|
vals = vals or v'[]'
|
||||||
|
clear(container)
|
||||||
|
for val in vals:
|
||||||
|
add(val)
|
||||||
|
add()
|
||||||
|
,
|
||||||
|
'set_disabled': def set_disabled(container, disabled): # noqa: unused-local
|
||||||
|
pass
|
||||||
|
}
|
||||||
|
registry['search_replace'] = ops
|
||||||
|
ops.set(container.lastChild, get_option_value('search_replace'))
|
||||||
|
|
||||||
|
container.appendChild(E.div(
|
||||||
|
create_button(_('Add'), 'plus', action=def(): add();)
|
||||||
|
))
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user