Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implementations into One time action handler #643

Merged
merged 2 commits into from
Dec 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import { singleOrNull } from "$libs/sequence";
import type { OneTimeActionType } from "$mono/action-manager/one-time-actions";
import type { MonoBitmapManager } from "$mono/monobitmap/manager/mono-bitmap-manager";
import type { ChangeOrderType } from "$mono/shape/command/shape-manager-commands";
import { ChangeExtra } from "$mono/shape/command/general-shape-commands";
import { ChangeOrder, type ChangeOrderType } from "$mono/shape/command/shape-manager-commands";
import { MakeTextEditable, UpdateTextEditingMode } from "$mono/shape/command/text-commands";
import { type TextHorizontalAlign, TextVerticalAlign } from "$mono/shape/extra/style";
import { ShapeExtraManager } from "$mono/shape/extra/extra-manager";
import { TextAlign, type TextHorizontalAlign, TextVerticalAlign } from "$mono/shape/extra/style";
import type { ShapeClipboardManager } from "$mono/shape/shape-clipboard-manager";
import type { AbstractShape } from "$mono/shape/shape/abstract-shape";
import type { Line } from "$mono/shape/shape/line";
import { Text } from "$mono/shape/shape/text";
import { ClipboardManager } from "$mono/state-manager/clipboard-manager";
import type { CommandEnvironment } from "$mono/state-manager/command-environment";
Expand Down Expand Up @@ -182,14 +185,28 @@
}

private setTextAlignment(newHorizontalAlign: TextHorizontalAlign, newVerticalAlign: TextVerticalAlign) {

const textShape = this.singleSelectedShape() as Text | null;
if (textShape === null) {
ShapeExtraManager.setDefaultValues({
textHorizontalAlign: newHorizontalAlign,
textVerticalAlign: newVerticalAlign,
});
return;
}
const extra = textShape.extra;
const newTextAlign = new TextAlign(
newHorizontalAlign ?? extra.textAlign.horizontalAlign,
newVerticalAlign ?? extra.textAlign.verticalAlign,
);
const newExtra = extra.copy({ textAlign: newTextAlign });
this.environment.shapeManager.execute(new ChangeExtra(textShape, newExtra));
}

private moveSelectedShapes(offsetRow: number, offsetCol: number) {

Check warning on line 205 in monosketch-svelte/src/lib/mono/state-manager/one-time-action-handler.ts

View workflow job for this annotation

GitHub Actions / lint

'offsetRow' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 205 in monosketch-svelte/src/lib/mono/state-manager/one-time-action-handler.ts

View workflow job for this annotation

GitHub Actions / lint

'offsetCol' is defined but never used. Allowed unused args must match /^_/u

}

private setSelectedShapeBound(newLeft: number, newTop: number, newWidth: number, newHeight: number) {

Check warning on line 209 in monosketch-svelte/src/lib/mono/state-manager/one-time-action-handler.ts

View workflow job for this annotation

GitHub Actions / lint

'newLeft' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 209 in monosketch-svelte/src/lib/mono/state-manager/one-time-action-handler.ts

View workflow job for this annotation

GitHub Actions / lint

'newTop' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 209 in monosketch-svelte/src/lib/mono/state-manager/one-time-action-handler.ts

View workflow job for this annotation

GitHub Actions / lint

'newWidth' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 209 in monosketch-svelte/src/lib/mono/state-manager/one-time-action-handler.ts

View workflow job for this annotation

GitHub Actions / lint

'newHeight' is defined but never used. Allowed unused args must match /^_/u

}

Expand Down Expand Up @@ -218,18 +235,66 @@
}

private setSelectedLineStrokeCornerExtra(isRoundedCorner: boolean) {

const line = this.singleSelectedShape() as Line | null;
if (line === null) {
ShapeExtraManager.setDefaultValues({ isLineStrokeRoundedCorner: isRoundedCorner });
return;
}
const currentExtra = line.extra;
const newExtra = currentExtra.copy({ isRoundedCorner: isRoundedCorner });
this.environment.shapeManager.execute(new ChangeExtra(line, newExtra));
}

private setSelectedShapeStartAnchorExtra(isEnabled: boolean, newHeadId: string | null) {

const line = this.singleSelectedShape() as Line | null;
if (line === null) {
ShapeExtraManager.setDefaultValues({
isStartHeadAnchorCharEnabled: isEnabled,
startHeadAnchorCharId: newHeadId ?? undefined,
});
return;
}
const currentExtra = line.extra;
const newAnchor = ShapeExtraManager.getStartHeadAnchorChar(
newHeadId ?? undefined,
currentExtra.userSelectedEndAnchor,
);
const newExtra = currentExtra.copy({
isStartAnchorEnabled: isEnabled ?? currentExtra.isEndAnchorEnabled,
userSelectedStartAnchor: newAnchor,
});
this.environment.shapeManager.execute(new ChangeExtra(line, newExtra));
}

private setSelectedShapeEndAnchorExtra(isEnabled: boolean, newHeadId: string | null) {

const line = this.singleSelectedShape() as Line | null;
if (line === null) {
ShapeExtraManager.setDefaultValues({
isEndHeadAnchorCharEnabled: isEnabled,
endHeadAnchorCharId: newHeadId ?? undefined,
});
return;
}
const currentExtra = line.extra;
const newAnchor = ShapeExtraManager.getEndHeadAnchorChar(
newHeadId ?? undefined,
currentExtra.userSelectedEndAnchor,
);
const newExtra = currentExtra.copy({
isEndAnchorEnabled: isEnabled ?? currentExtra.isEndAnchorEnabled,
userSelectedEndAnchor: newAnchor,
});
this.environment.shapeManager.execute(new ChangeExtra(line, newExtra));
}

private changeShapeOrder(orderType: ChangeOrderType) {
const singleSelectedShape = this.singleSelectedShape();
if (singleSelectedShape !== null) {
this.environment.shapeManager.execute(new ChangeOrder(singleSelectedShape, orderType));
}
}

private singleSelectedShape(): AbstractShape | null {
return singleOrNull(this.environment.getSelectedShapes());
}
}
Loading