Fix: hide CypherQueryBox in SQLite mode

- RightPanel: add use_embedded_db parameter, conditionally mount CypherQueryBox
- RightPanel.get_cypher_query_box(): return None if not exists
- RightPanel.has_cypher_query_box(): check if Cypher UI is available
- app.py: pass USE_EMBEDDED_DB to RightPanel
- app.py: action_focus_query shows notification when Cypher unavailable
- Update help text to note F4 is Neo4j-only
This commit is contained in:
root
2026-04-12 16:44:26 +08:00
parent 0d8a7592ad
commit 0ae8238ac8
2 changed files with 28 additions and 15 deletions

View File

@ -26,6 +26,7 @@ from .core.imports import (
NEO4J_USER, NEO4J_USER,
NEO4J_PASSWORD, NEO4J_PASSWORD,
MODEL_NAME, MODEL_NAME,
USE_EMBEDDED_DB,
) )
from .core.tools.tool_limiter import ToolLimiter from .core.tools.tool_limiter import ToolLimiter
@ -70,7 +71,7 @@ class GraphMemoryApp(App[None]):
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
"""构建组件树""" """构建组件树"""
yield LeftPanel() yield LeftPanel()
yield RightPanel(self._config) yield RightPanel(self._config, use_embedded_db=USE_EMBEDDED_DB)
yield StatusBar() yield StatusBar()
def on_mount(self) -> None: def on_mount(self) -> None:
@ -131,7 +132,7 @@ class GraphMemoryApp(App[None]):
F1 - 帮助 F1 - 帮助
F2 - 切换侧边栏 F2 - 切换侧边栏
F3 - 工具详情 F3 - 工具详情
F4 - 查询框 F4 - 查询框(仅 Neo4j 模式)
F5 - 清屏 F5 - 清屏
F6 - 退出 F6 - 退出
@ -151,16 +152,20 @@ F6 - 退出
history.toggle_latest_tool_details() history.toggle_latest_tool_details()
def action_focus_query(self) -> None: def action_focus_query(self) -> None:
"""聚焦查询框""" """聚焦查询框(仅 Neo4j 模式可用)"""
sidebar = self.query_one(RightPanel) sidebar = self.query_one(RightPanel)
if not sidebar.has_cypher_query_box():
self.notify("查询框仅在 Neo4j 模式下可用", title="提示", timeout=3)
return
if sidebar.is_collapsed(): if sidebar.is_collapsed():
sidebar.toggle() sidebar.toggle()
sidebar.update_title() sidebar.update_title()
try:
query_box = sidebar.get_cypher_query_box() query_box = sidebar.get_cypher_query_box()
if query_box:
query_box.focus() query_box.focus()
except:
pass
def action_clear_history(self) -> None: def action_clear_history(self) -> None:
"""清屏""" """清屏"""

View File

@ -1,6 +1,7 @@
"""右侧面板""" """右侧面板"""
from textual.containers import Container, Vertical from textual.containers import Container, ScrollableContainer
from textual.css.query import NoMatches
from textual.widgets import Static from textual.widgets import Static
from textual.app import ComposeResult from textual.app import ComposeResult
from .config_section import ConfigSection from .config_section import ConfigSection
@ -12,20 +13,20 @@ from ..models.config import AppConfig
class RightPanel(Container): class RightPanel(Container):
"""右侧边栏""" """右侧边栏"""
def __init__(self, config: AppConfig | None = None, **kwargs): def __init__(self, config: AppConfig | None = None, use_embedded_db: bool = True, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self._is_collapsed = False self._is_collapsed = False
self._config = config or AppConfig() self._config = config or AppConfig()
self._use_embedded_db = use_embedded_db
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
"""构建右侧面板""" """构建右侧面板"""
from textual.containers import ScrollableContainer
yield Static("F2:隐藏侧边栏", classes="sidebar-title") yield Static("F2:隐藏侧边栏", classes="sidebar-title")
with ScrollableContainer(): with ScrollableContainer():
yield ConfigSection(self._config) yield ConfigSection(self._config)
yield OperationLog() yield OperationLog()
yield CypherQueryBox() if not self._use_embedded_db:
yield CypherQueryBox()
def toggle(self) -> None: def toggle(self) -> None:
"""切换折叠/展开""" """切换折叠/展开"""
@ -49,9 +50,16 @@ class RightPanel(Container):
"""获取操作日志组件""" """获取操作日志组件"""
return self.query_one(OperationLog) return self.query_one(OperationLog)
def get_cypher_query_box(self) -> CypherQueryBox: def get_cypher_query_box(self) -> CypherQueryBox | None:
"""获取Cypher查询框组件""" """获取Cypher查询框组件(可能不存在)"""
return self.query_one(CypherQueryBox) try:
return self.query_one(CypherQueryBox)
except NoMatches:
return None
def has_cypher_query_box(self) -> bool:
"""检查是否存在Cypher查询框"""
return not self._use_embedded_db
def update_title(self) -> None: def update_title(self) -> None:
"""更新标题""" """更新标题"""