Source code for simvx.ide.panels.file_browser

"""IDE File Browser -- project directory tree sidebar."""


from __future__ import annotations

import logging
from typing import TYPE_CHECKING

from simvx.core.ui.file_browser import FileBrowserPanel as _BaseFileBrowserPanel

if TYPE_CHECKING:
    from ..state import IDEState

log = logging.getLogger(__name__)

__all__ = ["FileBrowserPanel"]


[docs] class FileBrowserPanel(_BaseFileBrowserPanel): """IDE file browser that opens files via goto_requested.""" def __init__(self, state: IDEState, **kwargs): super().__init__(title="Files", show_icons=True, drag_enabled=False, **kwargs) self.name = "Files" self._state = state # Wire file activation to IDE goto self.file_activated.connect(self._on_file_activated) @property def _file_tree(self) -> object: """Backward-compat alias: IDE tests reference ``_file_tree``.""" return self._tree_view def _on_file_activated(self, path: str): """Open file in IDE editor via goto_requested.""" self._state.goto_requested.emit(path, 0, 0) # Override _on_item_selected to also match original IDE behaviour # where single-click on a file triggers file_selected + goto_requested def _on_item_activated(self, item): """IDE-compat: single-click on file triggers file_selected and goto. Called from tests that simulate the original IDE item_selected callback. """ if not item.data: return path = item.data.get("path", "") is_dir = item.data.get("is_dir", False) if not is_dir and path: self.file_selected.emit(path) self._state.goto_requested.emit(path, 0, 0)