Team Hoa, EPIC R08 (UI/Application Separation) - Team Hoa scope only
(R08-T11 -> T14; R08-T01->T10 belong to Team Duy/Team Nam).
- R08-T11: ui/schedule_task_tab.py (795 lines) -> presentation/scheduling/
{kanban_board_widget,calendar_view_widget,ai_task_creator_dialog,
ai_task_import_dialog,run_history_dialog}.py + schedule_task_tab.py
shell. Kanban CRUD/drag-drop now goes through
application/scheduling/task_application_service.py (R07-T04) instead of
~30 lines of inline if/elif per drag target.
- R08-T12: ui/folder_tab.py (1587 lines, the largest of the four) ->
presentation/folder/{workspace_file_tree,document_preview_manager,
code_editor,office_document_renderer,ai_file_editor_dialog,
ai_edit_model_resolver,ai_edit_pipeline}.py + folder_tab.py shell.
Closes the R06-T05 loop: FileWorkspaceService existed since R06 with
zero production call sites (confirmed by grep); every plain-text write
(save/create/write_content) now goes through it, gaining path
containment and a Python-syntax warning the original code never had.
Pure helpers (_read_text, _is_probably_text, _pptx_available,
_split_code_block, _parse_ai_output) moved to
application/workspaces/{file_preview_helpers,ai_edit_output}.py.
- R08-T13: ui/dashboard_tab.py (437 lines) -> presentation/dashboard/
{token_usage_card_widget,usage_chart_widget,habits_widget}.py +
dashboard_tab.py shell, backed by a new
application/monitoring/dashboard_query_service.py (pricing/period/
summary queries the three widgets used to each recompute separately).
Directory-ownership note left in the checklist for Team Nam.
- R08-T14: ui/structure_graph_view.py (1035 lines) ->
presentation/graph/{graph_scene_items,graph_renderer,
graph_messages_view,graph_qa_widget}.py + structure_graph_view.py
shell. Extraction helpers (_pdf_to_markdown, _extract_file_contents)
moved to application/workspaces/graph_index_service.py (pure Python).
Renderer and Q&A panel talk only through signals
(node_selected/graph_rendered/raw_json_ready/project_changed) - neither
imports the other.
- presentation/shared/web_engine_support.py: HAS_WEB_ENGINE, previously
duplicated (folder_tab imported it FROM structure_graph_view.py) - now
one shared flag instead of one screen importing another screen's module.
All four old ui/*.py files deleted; app.py and ui/workspace_tab.py updated
to the new import paths (each god-file only had 1-2 real construction
sites, so import sites were updated directly rather than kept as a
strangler-fig shim - unlike core/tools.py at R05, which had dozens).
pytest: 377 pass (+94 vs the R07 baseline of 328; same 4 pre-existing
failures as the R05/R06 baseline, unrelated to this work).
scripts/check_imports.py: PASS. python -c "import cowork_local.app": OK.
Every new file < 400 lines (largest: graph_renderer.py, 391).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
98 lines
3.4 KiB
Python
98 lines
3.4 KiB
Python
"""WorkspaceFileTree — the folder-picker bar + directory tree pane of the
|
|
Folder Explorer (R08-T12, extracted from ``ui/folder_tab.py::FolderTab``,
|
|
lines 264-293/386-408 of the original 1587-line file).
|
|
|
|
Owns navigation only: which root is browsed and which file was clicked.
|
|
Rendering/editing the SELECTED file is
|
|
``document_preview_manager.py::DocumentPreviewManager``'s job — this widget
|
|
just emits :attr:`file_selected`.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
from PySide6.QtCore import Qt, Signal
|
|
from PySide6.QtWidgets import (
|
|
QFileDialog, QFileSystemModel, QHBoxLayout, QLabel, QPushButton,
|
|
QTreeView, QVBoxLayout, QWidget,
|
|
)
|
|
|
|
from cowork_local.i18n import tr
|
|
from cowork_local.ui.icons import icon
|
|
|
|
|
|
class WorkspaceFileTree(QWidget):
|
|
"""The left-hand tree pane: a path bar (label + "open folder" button)
|
|
above a ``QFileSystemModel``-backed ``QTreeView``."""
|
|
|
|
file_selected = Signal(str) # absolute path of the clicked file
|
|
root_changed = Signal(str) # absolute path of the new root
|
|
|
|
def __init__(self, initial_root: str, parent=None):
|
|
super().__init__(parent)
|
|
self._root = initial_root
|
|
|
|
root_layout = QVBoxLayout(self)
|
|
root_layout.setContentsMargins(0, 0, 0, 0)
|
|
|
|
# The path IS the title of this screen, so it is written as one
|
|
# rather than shown in a read-only text box that looks editable.
|
|
# Full path on hover; the button still opens the folder picker.
|
|
bar = QHBoxLayout()
|
|
self.path_lbl = QLabel(self._root)
|
|
self.path_lbl.setObjectName("folderTitle")
|
|
self.path_lbl.setTextInteractionFlags(Qt.TextSelectableByMouse)
|
|
self.path_lbl.setToolTip(self._root)
|
|
self._open_btn = QPushButton()
|
|
self._open_btn.setIcon(icon("folder"))
|
|
self._open_btn.setObjectName("primary")
|
|
self._open_btn.clicked.connect(self._pick_root)
|
|
bar.addWidget(self.path_lbl, 1)
|
|
bar.addWidget(self._open_btn)
|
|
root_layout.addLayout(bar)
|
|
|
|
self.model = QFileSystemModel()
|
|
self.model.setRootPath(self._root)
|
|
self.tree = QTreeView()
|
|
self.tree.setModel(self.model)
|
|
self.tree.setRootIndex(self.model.index(self._root))
|
|
for col in (1, 2, 3): # hide Size / Type / Date-modified columns
|
|
self.tree.hideColumn(col)
|
|
self.tree.setHeaderHidden(True)
|
|
self.tree.clicked.connect(self._on_tree_clicked)
|
|
root_layout.addWidget(self.tree, 1)
|
|
|
|
self.retranslate()
|
|
|
|
def retranslate(self) -> None:
|
|
self._open_btn.setToolTip(tr("folder.path_placeholder"))
|
|
self._open_btn.setText(tr("folder.open_folder"))
|
|
|
|
@property
|
|
def root(self) -> str:
|
|
return self._root
|
|
|
|
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))
|
|
self.root_changed.emit(p)
|
|
|
|
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.file_selected.emit(path)
|
|
|
|
|
|
__all__ = ["WorkspaceFileTree"]
|