aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/button
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2023-05-16 14:50:29 -0400
committerbobzel <zzzman@gmail.com>2023-05-16 14:50:29 -0400
commit46cf6c823ca8ab628cd8c5bd7fdfe8945344a014 (patch)
tree1e49ff8b3c29a3e31ad96ec39dd337cb58136426 /src/client/views/nodes/button
parentdf7257d1b39f51a7e00a495f0d4a2366f0e21f7d (diff)
fixed bugs with goldenlayout dragging and undoing. fixed searching for filter values in sidebars. Stopped creating empty list for collections when datafield() is accessed because it messes up undo of a collection. fixed tab title editing. from marquee. Added UndoStack UI and additional naming support in code.
Diffstat (limited to 'src/client/views/nodes/button')
-rw-r--r--src/client/views/nodes/button/FontIconBox.tsx60
1 files changed, 24 insertions, 36 deletions
diff --git a/src/client/views/nodes/button/FontIconBox.tsx b/src/client/views/nodes/button/FontIconBox.tsx
index 57aa852ac..b07cf7e00 100644
--- a/src/client/views/nodes/button/FontIconBox.tsx
+++ b/src/client/views/nodes/button/FontIconBox.tsx
@@ -16,7 +16,7 @@ import { CollectionViewType, DocumentType } from '../../../documents/DocumentTyp
import { LinkManager } from '../../../util/LinkManager';
import { ScriptingGlobals } from '../../../util/ScriptingGlobals';
import { SelectionManager } from '../../../util/SelectionManager';
-import { undoBatch, UndoManager } from '../../../util/UndoManager';
+import { undoable, undoBatch, UndoManager } from '../../../util/UndoManager';
import { CollectionFreeFormView } from '../../collections/collectionFreeForm';
import { ContextMenu } from '../../ContextMenu';
import { DocComponent } from '../../DocComponent';
@@ -129,29 +129,27 @@ export class FontIconBox extends DocComponent<ButtonProps>() {
* Number button
*/
@computed get numberSliderButton() {
- const numScript = ScriptCast(this.rootDoc.script);
- const setValue = (value: number) => UndoManager.RunInBatch(() => numScript?.script.run({ self: this.rootDoc, value, _readOnly_: false }), 'set num value');
-
+ const numScript = (value?: number) => ScriptCast(this.rootDoc.script).script.run({ self: this.rootDoc, value, _readOnly_: value === undefined });
// Script for checking the outcome of the toggle
- const checkResult = Number(numScript?.script.run({ self: this.rootDoc, value: 0, _readOnly_: true }).result ?? 0).toPrecision(NumCast(this.dataDoc.numPrecision, 3));
-
+ const checkResult = Number(numScript().result ?? 0).toPrecision(NumCast(this.dataDoc.numPrecision, 3));
const label = !FontIconBox.GetShowLabels() ? null : <div className="fontIconBox-label">{this.label}</div>;
const dropdown = (
<div className="menuButton-dropdownBox" onPointerDown={e => e.stopPropagation()}>
<input
+ className="menu-slider"
type="range"
step="1"
min={NumCast(this.rootDoc.numBtnMin, 0)}
max={NumCast(this.rootDoc.numBtnMax, 100)}
+ //readOnly={true}
value={checkResult}
- className="menu-slider"
- onPointerDown={() => (this._batch = UndoManager.StartBatch('presDuration'))}
+ onPointerDown={() => (this._batch = UndoManager.StartBatch('num slider changing'))}
onPointerUp={() => this._batch?.end()}
- onChange={e => {
+ onChange={undoable(e => {
e.stopPropagation();
- setValue(Number(e.target.value));
- }}
+ numScript(Number(e.target.value));
+ }, 'set num value')}
/>
</div>
);
@@ -174,20 +172,13 @@ export class FontIconBox extends DocComponent<ButtonProps>() {
* Number button
*/
@computed get numberDropdownButton() {
- const numScript = ScriptCast(this.rootDoc.script);
- const setValue = (value: number) => UndoManager.RunInBatch(() => numScript?.script.run({ self: this.rootDoc, value, _readOnly_: false }), 'set num value');
-
- // Script for checking the outcome of the toggle
- const checkResult = Number(numScript?.script.run({ self: this.rootDoc, value: 0, _readOnly_: true }).result ?? 0).toPrecision(NumCast(this.dataDoc.numPrecision, 3));
+ const numScript = (value?: number) => ScriptCast(this.rootDoc.script)?.script.run({ self: this.rootDoc, value, _readOnly_: value === undefined });
- const label = !FontIconBox.GetShowLabels() ? null : <div className="fontIconBox-label">{this.label}</div>;
+ const checkResult = Number(numScript().result ?? 0).toPrecision(NumCast(this.dataDoc.numPrecision, 3));
const items: number[] = [];
- for (let i = 0; i < 100; i++) {
- if (i % 2 === 0) {
- items.push(i);
- }
- }
+ for (let i = 0; i < 100; i += 2) items.push(i);
+
const list = items.map(value => {
return (
<div
@@ -196,15 +187,15 @@ export class FontIconBox extends DocComponent<ButtonProps>() {
style={{
backgroundColor: value.toString() === checkResult ? Colors.LIGHT_BLUE : undefined,
}}
- onClick={() => setValue(value)}>
+ onClick={undoable(value => numScript(value), `${this.rootDoc.title} button set from list`)}>
{value}
</div>
);
});
return (
<div className="menuButton numBtn list">
- <div className="button" onClick={action(e => setValue(Number(checkResult) - 1))}>
- <FontAwesomeIcon className={`fontIconBox-icon-${this.type}`} icon={'minus'} />
+ <div className="button" onClick={undoable(e => numScript(Number(checkResult) - 1), `${this.rootDoc.title} decrement value`)}>
+ <FontAwesomeIcon className={`fontIconBox-icon-${this.type}`} icon="minus" />
</div>
<div
className={`button ${'number'}`}
@@ -217,9 +208,9 @@ export class FontIconBox extends DocComponent<ButtonProps>() {
this.noTooltip = this.rootDoc.dropDownOpen;
Doc.UnBrushAllDocs();
})}>
- <input style={{ width: 30 }} className="button-input" type="number" value={checkResult} onChange={undoBatch(action(e => setValue(Number(e.target.value))))} />
+ <input style={{ width: 30 }} className="button-input" type="number" value={checkResult} readOnly={true} onChange={undoable(e => numScript(Number(e.target.value)), `${this.rootDoc.title} button set value`)} />
</div>
- <div className={`button`} onClick={action(e => setValue(Number(checkResult) + 1))}>
+ <div className={`button`} onClick={undoable(e => numScript(Number(checkResult) + 1), `${this.rootDoc.title} increment value`)}>
<FontAwesomeIcon className={`fontIconBox-icon-${this.type}`} icon={'plus'} />
</div>
@@ -322,12 +313,12 @@ export class FontIconBox extends DocComponent<ButtonProps>() {
.map(value => (
<div
className="list-item"
- key={`${value}`}
+ key={value}
style={{
fontFamily: script.script.originalScript.startsWith('{ return setFont') ? value : undefined,
backgroundColor: value === text ? Colors.LIGHT_BLUE : undefined,
}}
- onClick={undoBatch(() => script.script.run({ self: this.rootDoc, value }))}>
+ onClick={undoable(() => script.script.run({ self: this.rootDoc, value }), value)}>
{value[0].toUpperCase() + value.slice(1)}
</div>
));
@@ -640,29 +631,26 @@ ScriptingGlobals.add(function toggleOverlay(checkResult?: boolean) {
ScriptingGlobals.add(function showFreeform(attr: 'grid' | 'snaplines' | 'clusters' | 'arrange' | 'viewAll', checkResult?: boolean) {
const selected = SelectionManager.Docs().lastElement();
// prettier-ignore
- const map: Map<'grid' | 'snaplines' | 'clusters' | 'arrange'| 'viewAll', { undo: boolean, checkResult: (doc:Doc) => any; setDoc: (doc:Doc) => void;}> = new Map([
+ const map: Map<'grid' | 'snaplines' | 'clusters' | 'arrange'| 'viewAll', { waitForRender?: boolean, checkResult: (doc:Doc) => any; setDoc: (doc:Doc) => void;}> = new Map([
['grid', {
- undo: false,
checkResult: (doc:Doc) => doc._freeform_backgroundGrid,
setDoc: (doc:Doc) => doc._freeform_backgroundGrid = !doc._freeform_backgroundGrid,
}],
['snaplines', {
- undo: false,
checkResult: (doc:Doc) => doc._freeform_snapLines,
setDoc: (doc:Doc) => doc._freeform_snapLines = !doc._freeform_snapLines,
}],
['viewAll', {
- undo: false,
checkResult: (doc:Doc) => doc._freeform_fitContentsToBox,
setDoc: (doc:Doc) => doc._freeform_fitContentsToBox = !doc._freeform_fitContentsToBox,
}],
['clusters', {
- undo: false,
+ waitForRender: true, // flags that undo batch should terminate after a re-render giving the script the chance to fire
checkResult: (doc:Doc) => doc._freeform_useClusters,
setDoc: (doc:Doc) => doc._freeform_useClusters = !doc._freeform_useClusters,
}],
['arrange', {
- undo: true,
+ waitForRender: true, // flags that undo batch should terminate after a re-render giving the script the chance to fire
checkResult: (doc:Doc) => doc._autoArrange,
setDoc: (doc:Doc) => doc._autoArrange = !doc._autoArrange,
}],
@@ -671,7 +659,7 @@ ScriptingGlobals.add(function showFreeform(attr: 'grid' | 'snaplines' | 'cluster
if (checkResult) {
return map.get(attr)?.checkResult(selected) ? Colors.MEDIUM_BLUE : 'transparent';
}
- const batch = map.get(attr)?.undo ? UndoManager.StartBatch('set feature') : { end: () => {} };
+ const batch = map.get(attr)?.waitForRender ? UndoManager.StartBatch('set freeform attribute') : { end: () => {} };
SelectionManager.Docs().map(dv => map.get(attr)?.setDoc(dv));
setTimeout(() => batch.end(), 100);
});