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
pathparameter; 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 nametrimmed, if it can name a new macro inwb; 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_MACROSalready, 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
muntil 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 themacroslist as the file held them. - kept_
name - The name of the macro kept in a newer format called
name(compared asfindcompares), 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.getreturns andmacro.savetakes). - 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.saveand 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'.Nonewhen 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
namecannot 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, orname (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 withincrate::model::MAX_MACRO_NAMEcharacters. The result still goes throughcheck.- with_
names - A copy of
wbfor xlsx with each macro in hidden names (_gc_macro_<n>_<k>) instead of the field, orNonewhen there is nothing to change. The macros keep their order; the indexnis this build’s choice, so it steps around any a person’s own visible name already uses.