Skip to main content

Module macros

Module macros 

Source
Expand description

GridCraft macros: typed, declarative command lists, not VBA. The model is plain data in crate::model::Macro; this module reads and writes it and keeps it within its limits.

Storage: the JSON format keeps Workbook::macros as a field. In xlsx each macro is one item of GridCraft’s hidden workbook data (crate::engine::cmd::stash), _gc_macro_<n>_<k>, written when the file is saved and taken back out of the names when it is opened, so the names never linger in the open document. Scripts made with Automate › New Script or Record Actions are a separate, older feature with their own storage; macros neither read nor change it. A recording keeps the steps a script run ran while it recorded, as the run reported them.

Modules§

debug
The macro debugger: a run that stops between steps.
policy
What a macro step may run. Macros run commands, so this keeps a macro from saving, opening or closing files, driving the app, running other macros, or reading and writing files without the person knowing. It goes by command id and the path parameter; the runner also runs every step except an approved file step inside the scripts’ file sandbox, so a command that touches a file under another parameter can’t either.
recorder
Turning a recording into a macro.
resolve
Macro tokens: references in step parameters that are worked out when the step runs, so a macro made on one block of data works on another.
run
Running a macro.

Constants§

RESERVED_SHORTCUTS
Ctrl+Shift (Cmd+Shift on a Mac) letters that GridCraft already uses, on any platform, which a macro cannot take.

Functions§

check
Every check a macro must pass before it is kept in a workbook: the model’s limits (Macro::check_limits) and the size an xlsx file can hold. Every path that adds a macro, from JSON, from a file or built in code, goes through this one check.
check_new_name
name trimmed, if it can name a new macro in wb; otherwise why not: it is empty, too long, holds line breaks or another macro has it.
check_room
Refuses one more macro in a workbook that holds crate::model::MAX_MACROS already, counting the kept ones, so a save never holds more than the next open keeps.
command_steps
Every command step of steps (inside Repeat and If too), with its path.
count
How many macros the workbook holds: the readable ones and the ones kept in a newer format (Workbook::macros_unread), which a save writes back and the next open counts too.
find
The index of the macro called name (case-insensitive).
fingerprint
A macro’s content as canonical JSON text (object keys sorted): approval to run a macro holds until the macro changes. It is the text itself rather than a hash, so no two different macros share it.
fit_size
Leaves out the last top-level steps of m until it fits the size [check_size] allows, and returns how many steps it left out (a recording cut to fit, as at the step limit). Each step’s JSON is measured once.
json_bytes
The JSON format’s bytes for wb: the workbook, with the macros in a newer format put back into the macros list as the file held them.
kept_name
The name of the macro kept in a newer format called name (compared as find compares), as the file held it. Its name is taken: a new or renamed macro with it would clash when the newer version reads the file.
load
After a file is opened: moves macros out of hidden names into Workbook::macros, keeps macros in a newer format unread (Workbook::macros_unread), and drops macros that are damaged or over the limits. Returns a warning for what was kept unread and one for what was dropped.
macro_json
A macro as JSON (the shape macro.get returns and macro.save takes).
next_name
The first free Macro1, Macro2… name, also free among the kept macros (kept_name).
parse_macro
Reads a macro from JSON, as macro.save and files give it. A command step may also use the short form {"command": "cell.set", "params": {…}}.
parse_shortcut
The letter of a macro shortcut: "Ctrl+Shift+M", "Cmd+Shift+M", "⌘⇧M" and "m" all give 'M'. None when it is not one letter from A to Z, alone or after Ctrl+Shift (Cmd+Shift): other modifiers ("Ctrl+Alt+M") are refused rather than read as Ctrl+Shift.
shortcut_conflict
Why macro name cannot use Ctrl+Shift+letter: GridCraft uses it, or another macro has it.
shortcut_text
How a shortcut is stored and shown: Ctrl+Shift+M.
unique_name
name, or name (2), name (3)… if a macro already has it, a kept one too. A free name comes back as it is; a renamed one is shortened to make room for the suffix, so it stays within crate::model::MAX_MACRO_NAME characters. The result still goes through check.
with_names
A copy of wb for xlsx with each macro in hidden names (_gc_macro_<n>_<k>) instead of the field, or None when there is nothing to change. The macros keep their order; the index n is this build’s choice, so it steps around any a person’s own visible name already uses.