Source code for simvx.editor.panels.filesystem
"""FileSystem Panel -- project file browser for the editor.
Thin subclass of the core ``FileBrowserPanel`` that wires double-click
to open scenes via ``EditorState.open_scene`` and scripts via the
``file_opened`` signal.
"""
from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING
from simvx.core.ui.file_browser import FileBrowserPanel as _BaseFileBrowserPanel
if TYPE_CHECKING:
from ..state import EditorState
__all__ = ["FileSystemPanel"]
[docs]
class FileSystemPanel(_BaseFileBrowserPanel):
"""Editor file browser -- opens scenes and scripts on double-click.
Drop-in replacement for the old standalone implementation. Now shares
tree view, filter, context menu, rename, and drag logic with the core
``FileBrowserPanel`` base class (same base the IDE uses).
Signals (inherited):
file_selected(path) -- single-click selection
file_activated(path) -- double-click open
file_opened(path) -- alias for file_activated
file_created(path) -- after creation
file_deleted(path) -- after deletion
file_renamed(old, new) -- after rename
"""
def __init__(self, editor_state: EditorState | None = None, **kwargs):
super().__init__(title="Files", show_icons=True, drag_enabled=True, show_scene_actions=True, **kwargs)
self.state = editor_state
self.file_activated.connect(self._on_file_activated)
# ------------------------------------------------------------------ compat
[docs]
def set_root_path(self, path: str | Path):
"""Alias for ``set_root`` (backward-compat with old editor API)."""
self.set_root(path)
# ------------------------------------------------------------ activation
def _on_file_activated(self, path: str):
"""Open scenes via editor state, scripts via file_opened signal."""
p = Path(path)
if p.suffix.lower() == ".json" and self.state:
self.state.open_scene(p)
elif p.suffix.lower() == ".py":
self.file_opened.emit(path)