workspace: tree dirs only, left 280px, right filler

This commit is contained in:
p 2026-08-12 15:17:06 +08:00
parent 5dcd8cea5a
commit 222d3e2e75
2 changed files with 3 additions and 12 deletions

View File

@ -42,7 +42,7 @@ async with DBPools().sqlorContext(dbname) as sor:
"subwidgets": [
{
"widgettype": "VBox",
"options": {"width": "30%"},
"options": {"width": "280px"},
"subwidgets": [{
"widgettype": "Tree",
"id": "ws_tree",

View File

@ -1,4 +1,4 @@
# workspace_tree.dspy - 返回 Tree widget 需要的 {id, parentid, label, path} 格式
# workspace_tree.dspy - 只返回目录树,不含文件
uid = await get_user()
if not uid:
@ -28,7 +28,6 @@ async with DBPools().sqlorContext(dbname) as sor:
if not ws_dir or not os.path.isdir(ws_dir):
return [{"id": "__root__", "parentid": "", "label": "📁 工作空间(不可用)", "path": ""}]
# 递归扫描目录id 只含相对路径full path 存 path 字段
items = [{"id": "__root__", "parentid": "", "label": "📁 " + os.path.basename(ws_dir), "path": ws_dir, "is_leaf": False}]
def scan_dir(path, parent_id, rel_prefix):
@ -40,8 +39,8 @@ def scan_dir(path, parent_id, rel_prefix):
full = os.path.join(path, name)
if name.startswith('.') or name == '__pycache__':
continue
rel_path = rel_prefix + '/' + name if rel_prefix else name
if os.path.isdir(full):
rel_path = rel_prefix + '/' + name if rel_prefix else name
items.append({
"id": rel_path,
"parentid": parent_id,
@ -50,14 +49,6 @@ def scan_dir(path, parent_id, rel_prefix):
"is_leaf": False
})
scan_dir(full, rel_path, rel_path)
else:
items.append({
"id": rel_path,
"parentid": parent_id,
"label": "📄 " + name,
"path": full,
"is_leaf": True
})
scan_dir(ws_dir, "__root__", "")
return items