diff --git a/crates/ui-egui/src/dialogs/action_batch.rs b/crates/ui-egui/src/dialogs/action_batch.rs index 3bf7d2efd0..ffc2531d78 100644 --- a/crates/ui-egui/src/dialogs/action_batch.rs +++ b/crates/ui-egui/src/dialogs/action_batch.rs @@ -1,181 +1,256 @@ //! Actions panel menu › Batch…: play the selected action on every file in a //! folder, or on every data set of the open document (`action.batch`). +//! +//! Fields: `set` and `action` (the action's place), `actionName`, `source` (`folder` or +//! `datasets`), `datasetFileNaming`, `folder`, `includeSubdirs`, `destination` (`none`, +//! `saveAndClose` or `folder`), `destinationFolder`, `overrideOpen`, `overrideSave`, +//! `overrideExport` and `stopOnError`. OK plays the action; a source or destination folder left +//! empty, or Data Sets without a document, is an error and the dialog stays open. +use std::hash::Hash; + +use craft::automation::actions::Action; +use craft::host::PickRequest; +use craft::ui::choice::Checkbox; +use craft::ui::contract::{Bind, Entry, Show as _, ShowContainer as _}; +use craft::ui::dialog::{DialogId, DialogResult, DialogStack, FieldRefusal, HeldOk, StackDialog, dialog_id}; +use craft::ui::display::{Shade, Text}; +use craft::ui::form::{Field, FieldGroup}; +use craft::ui::patterns::form_dialogs::PathRow; +use craft::ui::pickers::Select; +use craft::ui::runtime::env::Label; +use egui::{Context, Ui}; +use serde::{Deserialize, Serialize}; use serde_json::{Value, json}; -use super::{DialogSpec, form}; -use crate::state::Dialog; -use crate::theme::Tokens; -use crate::{VectorcraftApp, widgets}; +use super::actions::{ActionDialog, Form, label, merged, set_index}; +use crate::VectorcraftApp; +use crate::file_asks::{self, Owner}; +use crate::panels::actions::{has_stop, is_ui_step, model}; +// PLAN: assumed `playback::included_commands(&Action) -> Vec` (menus-w15) is reachable from here (`pub(crate) mod playback` or a re-export). +use crate::panels::actions::playback::included_commands; -pub const KIND: &str = "actionBatch"; -const LABEL: f32 = 130.0; +/// The key the dialog answers for. +const KEY: &str = "actionBatch"; -pub(super) const SPEC: DialogSpec = - DialogSpec { heading: |_| tl!("Batch").into(), body, confirm, ok: Some("OK"), min_width: 420.0, max_width: Some(460.0), ..DialogSpec::FORM }; +/// What Batch plays on. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub enum BatchSource { + /// Every file of a folder. + #[default] + #[serde(rename = "folder")] + Folder, + /// Every data set of the open document. + #[serde(rename = "datasets")] + DataSets, +} -/// Open the Batch dialog for the selected action (`set`, `action` indexes into `action_sets`). +/// What Batch does with each file or data set when the action is done. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum BatchDestination { + /// Leaves it open. + None, + /// Saves it and closes it. + SaveAndClose, + /// Saves a copy in a folder. + #[default] + Folder, +} + +/// How the files of a data set batch into a folder are named. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum DatasetNaming { + /// The document's name and a number. + #[default] + FileNumber, + /// The document's name and the data set's. + FileDataSetName, + /// The data set's name. + DataSetName, +} + +/// What Batch edits. +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct BatchFields { + /// What the action plays on. + pub source: BatchSource, + /// The names of the files a data set batch saves into a folder. + pub dataset_file_naming: DatasetNaming, + /// The source folder. + pub folder: String, + /// Whether the source folder's subfolders play too. + pub include_subdirs: bool, + /// What happens to each file or data set afterwards. + pub destination: BatchDestination, + /// The destination folder. + pub destination_folder: String, + /// Whether the action's Open steps open the batch's file instead of their own. + pub override_open: bool, + /// Whether the action's Save steps save into the destination folder. + pub override_save: bool, + /// Whether the action's Export steps export into the destination folder. + pub override_export: bool, + /// Whether an error ends the batch. + pub stop_on_error: bool, +} + +impl Default for BatchFields { + fn default() -> Self { + BatchFields { + source: BatchSource::default(), + dataset_file_naming: DatasetNaming::default(), + folder: String::new(), + include_subdirs: false, + destination: BatchDestination::default(), + destination_folder: String::new(), + override_open: true, + override_save: true, + override_export: true, + stop_on_error: true, + } + } +} + +/// Batch asks for no check of its own: its refusals come with OK, from the command. +fn check(_: &BatchFields) -> Option