"""Cây thư mục của workspace — R08-T12. Chọn thư mục gốc và bấm vào file để mở. Phần hiển thị nội dung nằm ở ``document_preview_manager.py``. """ from __future__ import annotations import os from pathlib import Path from PySide6.QtCore import Qt from PySide6.QtWidgets import QFileDialog from ...i18n import tr class WorkspaceFileTreeMixin: """Trộn vào FolderTab.""" def set_root(self, path: str) -> None: p = str(path or "").strip() if not p or not os.path.isdir(p): return self._root = p self.path_lbl.setText(p) self.path_lbl.setToolTip(p) self.model.setRootPath(p) self.tree.setRootIndex(self.model.index(p)) if getattr(self, "terminal", None) is not None: self.terminal.set_cwd(p) # terminal follows the workspace folder def _pick_root(self) -> None: chosen = QFileDialog.getExistingDirectory(self, tr("folder.open_folder"), self._root) if chosen: self.set_root(chosen) def _on_tree_clicked(self, index) -> None: path = self.model.filePath(index) if path and os.path.isfile(path): self.open_file(path)