Workspace (client) spec create + edit
- File -> New workspace... (name -> template -> edit -> create & switch) - File -> Edit current workspace... (edit View/Root/Options as spec text) - Backend p4 client -o/-i Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -1821,6 +1821,39 @@ async fn p4_latest_change(state: State<'_, AppState>, scope: String) -> Result<V
|
||||
Ok(v.into_iter().next().unwrap_or(Value::Null))
|
||||
}
|
||||
|
||||
/// Get a workspace (client) spec as editable text. An unknown name returns a
|
||||
/// fresh template — used to create a new workspace.
|
||||
#[tauri::command]
|
||||
async fn p4_client_spec(state: State<'_, AppState>, client: String) -> Result<String, String> {
|
||||
let conn = current(&state)?;
|
||||
if client.trim().is_empty() {
|
||||
return Err("No workspace name".into());
|
||||
}
|
||||
run_text(&conn, &["client", "-o", client.trim()])
|
||||
}
|
||||
|
||||
/// Save a workspace (client) spec (`p4 client -i`). Creates it if new.
|
||||
#[tauri::command]
|
||||
async fn p4_client_save(state: State<'_, AppState>, spec: String) -> Result<String, String> {
|
||||
let conn = current(&state)?;
|
||||
let mut child = p4_cmd(&conn, false)
|
||||
.args(["client", "-i"])
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.map_err(|e| format!("Failed to start p4: {e}"))?;
|
||||
if let Some(si) = child.stdin.as_mut() {
|
||||
si.write_all(spec.as_bytes()).map_err(|e| e.to_string())?;
|
||||
}
|
||||
let out = child.wait_with_output().map_err(|e| e.to_string())?;
|
||||
if !out.status.success() {
|
||||
let err = decode(&out.stderr);
|
||||
return Err(if err.trim().is_empty() { decode(&out.stdout).trim().to_string() } else { err.trim().to_string() });
|
||||
}
|
||||
Ok(decode(&out.stdout).trim().to_string())
|
||||
}
|
||||
|
||||
/// Switch the active workspace (client) without re-authenticating.
|
||||
#[tauri::command]
|
||||
async fn p4_switch_client(state: State<'_, AppState>, client: String) -> Result<Value, String> {
|
||||
@ -2025,6 +2058,8 @@ pub fn run() {
|
||||
p4_typemap_set,
|
||||
p4_reopen_type,
|
||||
p4_sync_to,
|
||||
p4_client_spec,
|
||||
p4_client_save,
|
||||
uasset_thumbnail,
|
||||
uasset_export_3d,
|
||||
p4_shelve,
|
||||
|
||||
Reference in New Issue
Block a user