refactor(spotlight): replace custom SVGs with themed symbolic icons
Remove _ICON_SVG_MAP and _icon_to_svg. Use Gtk themed icons directly via fabric Image widget with set_from_icon_name instead of loading custom SVG files. Fixes crash when plugin icon SVG is missing.
This commit is contained in:
1 file changed
+8
-36
@@ -13,7 +13,6 @@ from shared.widgets.clipping_box import ClippingBox
|
||||
from shared.window.animated_scrollwindow import AnimatedScrollable
|
||||
from utils.debounce import debounce
|
||||
from utils.functions import get_children_height_limit
|
||||
from utils.gtk_utils import svg_file
|
||||
from window.spotlight.api.context import PluginContext
|
||||
from window.spotlight.api.result import SearchResult
|
||||
from window.spotlight.core.loader import PluginLoader
|
||||
@@ -21,33 +20,6 @@ from window.spotlight.core.manager import PluginManager
|
||||
from window.spotlight.core.registry import PluginRegistry
|
||||
from window.spotlight.core.search import SearchPipeline
|
||||
|
||||
# Map GTK theme icon names to SVG asset paths
|
||||
_ICON_SVG_MAP = {
|
||||
"system-search-symbolic": "misc/search.svg",
|
||||
"system-shutdown-symbolic": "misc/shutdown.svg",
|
||||
"system-reboot-symbolic": "misc/reboot.svg",
|
||||
"system-suspend-symbolic": "misc/suspend.svg",
|
||||
"system-hibernate-symbolic": "misc/hibernate.svg",
|
||||
"system-log-out-symbolic": "misc/logout.svg",
|
||||
"system-lock-screen-symbolic": "misc/lock.svg",
|
||||
"edit-find-symbolic": "misc/search.svg",
|
||||
"edit-paste-symbolic": "misc/paste.svg",
|
||||
"video-x-generic-symbolic": "misc/video.svg",
|
||||
"insert-link-symbolic": "misc/link.svg",
|
||||
"face-smile-symbolic": "misc/emoji.svg",
|
||||
"accessories-calculator-symbolic": "misc/calculator.svg",
|
||||
"user-available-symbolic": "misc/coffee-on.svg",
|
||||
"user-away-symbolic": "misc/coffee-off.svg",
|
||||
}
|
||||
|
||||
|
||||
def _icon_to_svg(icon_name: str, size: int = 32):
|
||||
"""Return an Svg widget for a GTK theme icon name, or None if unmapped."""
|
||||
path = _ICON_SVG_MAP.get(icon_name)
|
||||
if path:
|
||||
return svg_file(path, size=size)
|
||||
return None
|
||||
|
||||
|
||||
class PluginService:
|
||||
"""Owns plugin lifecycle and search pipeline. Plain class, no GObject."""
|
||||
@@ -90,7 +62,9 @@ class Spotlight(Box):
|
||||
|
||||
self.plugin_service = PluginService()
|
||||
|
||||
self.header_icon = svg_file("misc/search.svg", size=16)
|
||||
self.header_icon = Image(
|
||||
icon_name="system-search-symbolic", icon_size=16, size=16
|
||||
)
|
||||
self.header_entry = Entry(
|
||||
placeholder="Search...",
|
||||
style_classes="app-search-entry",
|
||||
@@ -146,15 +120,14 @@ class Spotlight(Box):
|
||||
|
||||
if not text.strip():
|
||||
self._clear_viewport()
|
||||
self.header_icon.set_from_file("misc/search.svg")
|
||||
self.header_icon.set_from_icon_name("system-search-symbolic", 16)
|
||||
return
|
||||
|
||||
for pe in self.plugin_service.manager.registry.get_searchable():
|
||||
inst = pe.instance
|
||||
if inst and inst.detect(text):
|
||||
icon = getattr(inst, "icon", "") or "system-search-symbolic"
|
||||
svg_path = _ICON_SVG_MAP.get(icon, "misc/search.svg")
|
||||
self.header_icon.set_from_file(svg_path)
|
||||
self.header_icon.set_from_icon_name(icon, 16)
|
||||
# Scope to the detected plugin only — a global search would
|
||||
# mix in unrelated plugins' results.
|
||||
self.plugin_service.pipeline.search_single(
|
||||
@@ -162,7 +135,7 @@ class Spotlight(Box):
|
||||
)
|
||||
return
|
||||
|
||||
self.header_icon.set_from_file("misc/search.svg")
|
||||
self.header_icon.set_from_icon_name("system-search-symbolic", 16)
|
||||
self.plugin_service.pipeline.search(text, self._on_search_results)
|
||||
|
||||
def _activate_keyword_plugin(self, entry, keyword: str, query: str):
|
||||
@@ -182,8 +155,7 @@ class Spotlight(Box):
|
||||
keyword_icons.get(keyword, getattr(inst, "icon", ""))
|
||||
or "system-search-symbolic"
|
||||
)
|
||||
svg_path = _ICON_SVG_MAP.get(icon_name, "misc/search.svg")
|
||||
self.header_icon.set_from_file(svg_path)
|
||||
self.header_icon.set_from_icon_name(icon_name, 16)
|
||||
|
||||
if getattr(inst, "full_viewport_clear", False):
|
||||
self._clear_viewport()
|
||||
@@ -740,7 +712,7 @@ class SpotlightWindow(Window):
|
||||
self.spotlight_box.scrolled_window.animate_size(0)
|
||||
self.spotlight_box.scrolled_window.hide()
|
||||
self.spotlight_box.scrolled_clip.hide()
|
||||
self.spotlight_box.header_icon.set_from_file("misc/search.svg")
|
||||
self.spotlight_box.header_icon.set_from_icon_name("system-search-symbolic", 16)
|
||||
self.spotlight_box._deactivate_keyword_plugin()
|
||||
self.spotlight_box.plugin_service.manager.release_memory_all()
|
||||
self.hide()
|
||||
|
||||
Reference in new issue
Block a user