mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 21:42:59 -05:00
Merge main into feat/scripts-layer-text-frames
This commit is contained in:
commit
ef52adf1b6
115 files changed
+11200
-581
No files matched your search
@@ -99,6 +99,7 @@ use super::{HISTORY_LOST, Host, Link, Savepoint, command, command_value, current
|
||||
use crate::{DocState, Document, NodeId, NodeKind, Session, WindowView};
|
||||
|
||||
pub(super) mod layers;
|
||||
mod save_open;
|
||||
mod tags;
|
||||
mod text;
|
||||
mod variables;
|
||||
@@ -215,6 +216,8 @@ pub(super) struct State {
|
||||
pub(super) active_artboards: RefCell<Vec<u64>>,
|
||||
/// Each open document's uid and the index of its active artboard when the run started.
|
||||
pub(super) boards_at_start: Vec<(u64, usize)>,
|
||||
/// `app.userInteractionLevel` ([`save_open`]).
|
||||
save_options: save_open::State,
|
||||
text: text::TextState,
|
||||
presets: RefCell<Vec<Vec<(String, Data)>>>,
|
||||
preset_bytes: Cell<u64>,
|
||||
@@ -2957,7 +2960,7 @@ const ENUMS: &[(&str, &[&str])] = &[
|
||||
/// holds.
|
||||
pub(super) fn install(realm: &mut Realm, link: &Link) -> std::result::Result<(), RunError> {
|
||||
text::install_enums(realm)?;
|
||||
for (name, members) in ENUMS {
|
||||
for (name, members) in ENUMS.iter().chain(save_open::ENUMS) {
|
||||
let items = members.iter().map(|m| (m.to_string(), HostItem::Value(text(format!("{name}.{m}"))))).collect();
|
||||
realm.define_host_object(name, items)?;
|
||||
}
|
||||
@@ -2995,6 +2998,7 @@ fn classes(link: &Link) -> Vec<HostClass> {
|
||||
]);
|
||||
application.push(("textFonts".into(), text::app_text_fonts(l), MemberInfo { collection: true, ..typed("TextFonts") }));
|
||||
application.push(later(l, "Application", "beep"));
|
||||
application.extend(save_open::application_members(l));
|
||||
application.extend(super::actions::app_members(l));
|
||||
let preset = {
|
||||
let l = link.clone();
|
||||
@@ -3072,8 +3076,9 @@ fn classes(link: &Link) -> Vec<HostClass> {
|
||||
]);
|
||||
document.extend(defaults::document_members(l));
|
||||
document.extend(text::styles::doc_members(l));
|
||||
document.extend(["swatches", "symbols", "saveAs", "close"].into_iter().map(|m| later(l, "Document", m)));
|
||||
document.extend(["swatches", "symbols"].into_iter().map(|m| later(l, "Document", m)));
|
||||
document.extend(layers::document_members(l));
|
||||
document.extend(save_open::document_members(l));
|
||||
document.extend(variables::document_members(l));
|
||||
document.push(("tags".into(), get(l, tags::doc_tags), MemberInfo { collection: true, ..typed("Tags") }));
|
||||
classes.push(class("Document", None, document, None));
|
||||
@@ -3186,6 +3191,7 @@ fn classes(link: &Link) -> Vec<HostClass> {
|
||||
classes.extend(text::classes(l));
|
||||
classes.extend(variables::classes(l));
|
||||
classes.extend(layers::classes(l));
|
||||
classes.extend(save_open::classes(l));
|
||||
classes.extend(tags::classes(l));
|
||||
classes
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -124,6 +124,8 @@ pub(crate) const MASK_TOO_COSTLY: &str = "Script folder mask takes too many step
|
||||
pub(crate) const NOT_WRITABLE: &str = "Script file is not open for writing";
|
||||
pub(crate) const UNENCODABLE: &str = "Script file cannot encode the text";
|
||||
pub(crate) const WRITE_FAILED: &str = "Script file could not be written";
|
||||
pub(crate) const READ_ONLY: &str = "Script file is read-only";
|
||||
pub(crate) const OPEN_FOR_WRITING: &str = "Script file is open for writing";
|
||||
pub(crate) const NOT_EMPTY: &str = "Script folder is not empty";
|
||||
pub(crate) const NAME_TAKEN: &str = "Script file name is already in use";
|
||||
pub(crate) const BAD_NAME: &str = "Script file name must be a name without a folder";
|
||||
@@ -281,6 +283,9 @@ pub(crate) struct Disk {
|
||||
/// when they were last written to the grants file.
|
||||
kept: Vec<(std::path::PathBuf, bool, bool)>,
|
||||
recorded: usize,
|
||||
/// While set, the gate of a command the script runs leaves out the files of the open documents
|
||||
/// ([`Disk::gate`]): the command reads and writes only where the script's `File` objects may.
|
||||
pub(crate) exact: bool,
|
||||
/// The write bits setting `readonly` cleared from each file in this run, by its device and
|
||||
/// inode, which a rename keeps, at most [`MAX_ENTRIES`] files: clearing `readonly` gives them back.
|
||||
#[cfg(unix)]
|
||||
@@ -334,6 +339,7 @@ impl Disk {
|
||||
ran_too_much: setup.engine_code.1,
|
||||
kept: Vec::new(),
|
||||
recorded: 0,
|
||||
exact: false,
|
||||
#[cfg(unix)]
|
||||
cleared: HashMap::new(),
|
||||
};
|
||||
@@ -466,9 +472,12 @@ impl Disk {
|
||||
|
||||
/// The gate for a command the script runs: the places it reads and writes now, the files the
|
||||
/// person gave the open documents, `documents`, and the files it may only read because the documents open when
|
||||
/// the run began link to them, `linked`.
|
||||
/// the run began link to them, `linked`, but not the files its `File` objects hold open for writing.
|
||||
pub(crate) fn gate(&self, documents: Vec<String>, linked: crate::file_access::LinkedFiles) -> crate::file_access::ScriptGate {
|
||||
crate::file_access::ScriptGate { read: self.scope.clone(), write: self.writes.clone(), documents, linked, also: None }
|
||||
// A save, export or open of a `File` the script names reads and writes as its `File` would.
|
||||
let (documents, linked) = if self.exact { (Vec::new(), Default::default()) } else { (documents, linked) };
|
||||
let held = self.open.values().filter_map(|o| o.target.clone()).collect();
|
||||
crate::file_access::ScriptGate { read: self.scope.clone(), write: self.writes.clone(), documents, held, linked, also: None }
|
||||
}
|
||||
|
||||
/// The files written since this was last asked, to name in the report.
|
||||
@@ -687,6 +696,39 @@ impl Disk {
|
||||
}
|
||||
}
|
||||
|
||||
/// The real path a save or export of the document to `path` writes, as a `File` opened for
|
||||
/// writing would write it ([`Disk::target`]), or why it may not: a folder is not a file, a
|
||||
/// read-only file is not written over, and neither is a file a `File` object holds open for
|
||||
/// writing, whose bytes the run's end would write over the saved file.
|
||||
pub(crate) fn save_target(&self, path: &str) -> Result<std::path::PathBuf, &'static str> {
|
||||
let real = self.target(path, true)?;
|
||||
if self.open.values().any(|o| o.target.as_deref() == Some(real.as_path())) {
|
||||
return Err(OPEN_FOR_WRITING);
|
||||
}
|
||||
match std::fs::metadata(&real) {
|
||||
Ok(m) if !m.is_file() => Err(NOT_REGULAR),
|
||||
Ok(m) if m.permissions().readonly() => Err(READ_ONLY),
|
||||
_ => Ok(real),
|
||||
}
|
||||
}
|
||||
|
||||
/// The real path of the file `path` that opening it as a document reads, as a `File` reads it
|
||||
/// ([`ScriptScope::locate`]), or why it may not: it is not there, it is not a regular file, or
|
||||
/// the script may not read it.
|
||||
pub(crate) fn open_target(&self, path: &str) -> Result<std::path::PathBuf, &'static str> {
|
||||
let p = self.checked(path)?;
|
||||
let real = match self.scope.locate(p) {
|
||||
Ok(real) => real,
|
||||
Err(ScriptRead::Missing) => return Err(NOT_FOUND),
|
||||
Err(ScriptRead::Refused | ScriptRead::TooLarge) => return Err(ACCESS_DENIED),
|
||||
Err(ScriptRead::Failed(_)) => return Err(READ_FAILED),
|
||||
};
|
||||
if !real.is_file() {
|
||||
return Err(NOT_REGULAR);
|
||||
}
|
||||
Ok(real)
|
||||
}
|
||||
|
||||
/// Counts `n` more bytes written in the run, which ends past [`MAX_RUN_BYTES`].
|
||||
fn charge_write(&mut self, n: usize) -> Result<(), HostError> {
|
||||
self.written = self.written.saturating_add(n);
|
||||
|
||||
Reference in new issue
Block a user