mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Completion for url() in CSS files
This commit is contained in:
parent
b30441093a
commit
3d0859432e
@ -77,6 +77,7 @@ def complete_names(names_data, data_conn):
|
|||||||
names_cache['stylesheet'] = frozenset(n for n in all_names if n.mime_type in OEB_STYLES)
|
names_cache['stylesheet'] = frozenset(n for n in all_names if n.mime_type in OEB_STYLES)
|
||||||
names_cache['image'] = frozenset(n for n in all_names if n.mime_type.startswith('image/'))
|
names_cache['image'] = frozenset(n for n in all_names if n.mime_type.startswith('image/'))
|
||||||
names_cache['font'] = frozenset(n for n in all_names if n.mime_type in OEB_FONTS)
|
names_cache['font'] = frozenset(n for n in all_names if n.mime_type in OEB_FONTS)
|
||||||
|
names_cache['css_resource'] = names_cache['image'] | names_cache['font']
|
||||||
names_cache['descriptions'] = d = {}
|
names_cache['descriptions'] = d = {}
|
||||||
for x, desc in {'text_link':_('Text'), 'stylesheet':_('Stylesheet'), 'image':_('Image'), 'font':_('Font')}.iteritems():
|
for x, desc in {'text_link':_('Text'), 'stylesheet':_('Stylesheet'), 'image':_('Image'), 'font':_('Font')}.iteritems():
|
||||||
for n in names_cache[x]:
|
for n in names_cache[x]:
|
||||||
|
@ -6,8 +6,11 @@ from __future__ import (unicode_literals, division, absolute_import,
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
from PyQt5.Qt import Qt
|
from PyQt5.Qt import Qt
|
||||||
|
|
||||||
|
from calibre.gui2.tweak_book import current_container
|
||||||
from calibre.gui2.tweak_book.editor.smarts import NullSmarts
|
from calibre.gui2.tweak_book.editor.smarts import NullSmarts
|
||||||
from calibre.gui2.tweak_book.editor.smarts.utils import (
|
from calibre.gui2.tweak_book.editor.smarts.utils import (
|
||||||
no_modifiers, get_leading_whitespace_on_block, get_text_before_cursor,
|
no_modifiers, get_leading_whitespace_on_block, get_text_before_cursor,
|
||||||
@ -33,6 +36,12 @@ def find_rule(raw, rule_address):
|
|||||||
|
|
||||||
class Smarts(NullSmarts):
|
class Smarts(NullSmarts):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
if not hasattr(Smarts, 'regexps_compiled'):
|
||||||
|
Smarts.regexps_compiled = True
|
||||||
|
Smarts.complete_attr_pat = re.compile(r'''url\s*\(\s*['"]{0,1}([^)]*)$''')
|
||||||
|
NullSmarts.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
def handle_key_press(self, ev, editor):
|
def handle_key_press(self, ev, editor):
|
||||||
key = ev.key()
|
key = ev.key()
|
||||||
|
|
||||||
@ -65,4 +74,14 @@ class Smarts(NullSmarts):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def get_completion_data(self, editor, ev=None):
|
||||||
|
c = editor.textCursor()
|
||||||
|
c.movePosition(c.StartOfLine, c.KeepAnchor)
|
||||||
|
text = c.selectedText()
|
||||||
|
m = self.complete_attr_pat.search(text)
|
||||||
|
if m is None:
|
||||||
|
return
|
||||||
|
query = m.group(1) or ''
|
||||||
|
doc_name = editor.completion_doc_name
|
||||||
|
if doc_name:
|
||||||
|
return 'complete_names', ('css_resource', doc_name, current_container().root), query
|
||||||
|
Loading…
x
Reference in New Issue
Block a user