Files
vectorcraft/crates/ui-egui/src/dialogs/save_symbol_library.rs
T
Taha-Mahmoodi 7da5e3062d Symbols: Window › Symbol Libraries opens symbol libraries whose symbols click into the document's Symbols
Window › Symbol Libraries and the Symbols panel's Symbol Libraries Menu open each symbol library
in a library panel of its own, on the shared library panel code the swatch and graphic style
libraries use (https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/create-or-import-symbol-libraries.html,
.../symbols-panel-options.html, .../create-and-place-symbols.html).

- Basic Shapes: one original library generated in code (circle, squares, triangle, diamond,
  hexagon, star, burst, arrow); no other app's libraries.
- A click adds a library symbol to the document's Symbols as one undo step, with its Symbol
  Options and the resources it uses (nested symbols, patterns, swatches, brushes, graphic styles,
  images), and makes it the current symbol; one already there isn't added again, a clash of
  names numbers the library's. Shift/Cmd-clicks select for Add to Symbols. Dragging a library
  symbol onto the canvas adds it and places an instance there, in the same step.
- Save Symbols… (library menu, Window menu) and Save Symbol Library… (Symbols panel menu) write
  the document's symbols as a .vectorcraft document holding only them, into the user library
  folder (User Defined, window.userSymbolLibrary1-10) or a file; Other Library… reads the symbols
  of any document VectorCraft opens, and a file it can't read is an error.

Commands: symbol.libraries, symbol.library, symbol.addFromLibrary (place, x, y),
symbol.saveLibrary, symbol.loadLibrary; UI: window.symbolLibrary (.other), ui.saveSymbolLibrary
(dialog saveSymbolLibrary). i18n rows in every complete catalog; docs updated.
2026-10-24 03:09:10 +07:00

41 lines
1.6 KiB
Rust

//! Save Symbol Library: a name and where it goes: the user library folder (listed under Window →
//! Symbol Libraries → User Defined) or a `.vectorcraft` file picked in a save dialog (a download
//! on the web). OK runs `symbol.saveLibrary`.
//!
//! Fields: `name`, `user` (save to the user library folder), `selectedOnly` and `names` (the
//! symbol selected in the Symbols panel), `__user` (there is a user library folder).
use serde_json::Value;
use vectorcraft_engine::cmd::symbollib::SYMBOLS_EXT;
use super::DialogSpec;
use super::save_swatch_library::{destination, fields, name_row, params, save};
use super::swatch_options::grid;
use crate::VectorcraftApp;
use crate::state::Dialog;
/// The dialog kind of Save Symbol Library.
pub const KIND: &str = "saveSymbolLibrary";
pub(super) const SPEC: DialogSpec =
DialogSpec { heading: |_| tl!("Save Symbol Library").into(), body, confirm, min_width: 360.0, ..DialogSpec::FORM };
/// Open Save Symbol Library for the document's symbols (`names`: the one selected in the panel).
pub fn open(app: &mut VectorcraftApp, names: Vec<String>) -> Result<Value, String> {
let fields = fields(app, app.session.symbol_libraries.user_dir().is_some(), names)?;
app.ui.dialog = Some(Dialog::new(KIND, fields));
Ok(Value::Null)
}
fn body(_: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool {
grid(ui, |ui| {
name_row(ui, d);
destination(ui, d, tl!("Selected Symbols Only"));
});
false
}
fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result<Value, String> {
save(app, d, "symbol.saveLibrary", SYMBOLS_EXT, params(d))
}