Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Show a pin's folder from its right-click menu (#215)

muraa-pa7a04333c06b
diff --git a/crates/engine/src/tools/project_tools.rs b/crates/engine/src/tools/project_tools.rs
index 47791598..05e7c3bd 100644
--- a/crates/engine/src/tools/project_tools.rs
+++ b/crates/engine/src/tools/project_tools.rs
@@ -78,7 +78,7 @@ pub fn specs() -> Vec<ToolSpec> {
ToolSpec {
id: "project_open_folder",
title: "Open a project's folder",
- summary: "Open the project's folder (or its app/ folder) in the file manager.",
+ summary: "Open the project's folder (or its app/ folder) in the file manager, or one of its pinned builds' folders.",
beginner: "Opens the project's files.",
toolset: Toolset::Projects,
effects: Effects::LAUNCHES_PROCESS,
@@ -287,6 +287,9 @@ pub struct FolderParams {
/// Open the app/ folder (what was built) instead of the project folder.
#[serde(default)]
pub app: bool,
+ /// Open a pinned build's folder.
+ #[serde(default)]
+ pub pin: Option<u32>,
}
/// Websites being previewed in this session, by project folder (kept serving until it ends).
@@ -538,11 +541,23 @@ fn project_preview(ctx: &mut Ctx<'_>, params: Value) -> Result<ToolOutput, ToolE
fn project_open_folder(_ctx: &mut Ctx<'_>, params: Value) -> Result<ToolOutput, ToolError> {
let p: FolderParams = parse_params(params)?;
let ws = open(&p.project)?;
- let dir = if p.app { ws.app_dir() } else { ws.root.clone() };
+ let dir = folder_to_open(&ws, p.app, p.pin)?;
craft_anything_platform::open_path(&dir)?;
Ok(ToolOutput::Value(json!({"opened": dir.display().to_string()})))
}
+/// The folder `project_open_folder` opens: the project, its app, or a pinned build's copy.
+fn folder_to_open(ws: &Workspace, app: bool, pin: Option<u32>) -> Result<PathBuf, ToolError> {
+ Ok(match (pin, app) {
+ (Some(id), app) => {
+ let pin = crate::pins::get(ws, id)?;
+ if app { pin.app_dir(ws) } else { pin.dir(ws) }
+ }
+ (None, true) => ws.app_dir(),
+ (None, false) => ws.root.clone(),
+ })
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -642,4 +657,18 @@ mod tests {
// Playing runs the builder's code: refused without consent.
assert!(e.call("project_play", json!({"project": ws.root}), CallOptions::new(Caller::Mcp)).is_err());
}
+
+ #[test]
+ fn a_pinned_builds_folder_is_opened_from_its_project() {
+ let d = tempfile::tempdir().unwrap();
+ let ws = Workspace::create(d.path(), "Snake", "A snake game", TargetRef::None).unwrap();
+ let pin = ws.root.join(crate::pins::PINNED).join("7");
+ std::fs::create_dir_all(pin.join("app")).unwrap();
+ std::fs::write(pin.join(crate::pins::PIN_FILE), r#"{"version":1,"id":7,"name":"Pinned","mode":"frozen","created_ms":0}"#).unwrap();
+ assert_eq!(folder_to_open(&ws, false, Some(7)).unwrap(), pin);
+ assert_eq!(folder_to_open(&ws, true, Some(7)).unwrap(), pin.join("app"));
+ assert_eq!(folder_to_open(&ws, false, None).unwrap(), ws.root);
+ assert_eq!(folder_to_open(&ws, true, None).unwrap(), ws.app_dir());
+ assert!(folder_to_open(&ws, false, Some(8)).is_err(), "no such pin");
+ }
}
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index 9bb18f84..314e821c 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -979,12 +979,14 @@ Set up a builder 配置构建助手
Settings 设置
Show a build's activity 显示构建活动
Show a project 显示项目
+Show folder 显示文件夹
Show me everything 显示全部内容
Show me the proof 查看证据
Show pinned builds 显示固定的构建
Show settings 显示设置
Show the answer 显示回答
Show the console 显示控制台
+Show the folder 显示该文件夹
Show the ones that are met 显示已满足的要求
Show the sidebar 显示侧栏
Show the welcome again 再次显示欢迎界面
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 16dd4ea8..613c41f4 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -979,12 +979,14 @@ Set up a builder 設定建置助手
Settings 設定
Show a build's activity 顯示建置活動
Show a project 顯示專案
+Show folder 顯示資料夾
Show me everything 顯示全部內容
Show me the proof 檢視證據
Show pinned builds 顯示釘選的建置
Show settings 顯示設定
Show the answer 顯示回答
Show the console 顯示主控台
+Show the folder 顯示該資料夾
Show the ones that are met 顯示已滿足的要求
Show the sidebar 顯示側邊欄
Show the welcome again 再次顯示歡迎畫面
diff --git a/crates/ui-egui/src/pins.rs b/crates/ui-egui/src/pins.rs
index e47dd134..058f2030 100644
--- a/crates/ui-egui/src/pins.rs
+++ b/crates/ui-egui/src/pins.rs
@@ -206,6 +206,10 @@ fn menu(app: &mut CraftApp, ui: &mut Ui, row: &PinRow) {
app.open_pin(row, false);
ui.close();
}
+ if ui.button(tr("Show folder")).clicked() {
+ app.act("project_open_folder", json!({"project": row.project, "pin": row.pin.id}), tr("Show the folder"));
+ ui.close();
+ }
if ui.button(tr("Go to the project")).clicked() {
if let Some(ws) = app.projects.iter().find(|w| w.root == row.project).cloned() {
app.open_workspace(ws);
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index bc9ada4a..6b0d9700 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -936,7 +936,8 @@ to the project next. Pins are the engine's (tools), kept in the project's `pinne
page with the frozen/light choice and each copy's size; the pin tools are in the command
palette with every other tool
- [ ] Opening a pin that's already running brings its window to the front, instead of a message
-- [ ] Show a pin's folder (the right-click menu), and how much space pins take in Settings
+- [ ] How much space pins take in Settings. Showing a pin's folder is done in the right-click menu,
+ through `project_open_folder` with `pin` — claimed: muraa-p, branch bugfix/r2.10-pin-folder
- [ ] Live check on Windows: rebuild a project while its frozen pin runs, and the build isn't blocked
## M3 Engine depth