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

🚩 PR: Added partial preset load and element override #765

Merged
merged 7 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
54 changes: 28 additions & 26 deletions src/renderer/main/grid-layout/grid-modules/Device.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script>
import { ClipboardKey } from "./../../../runtime/clipboard.store.ts";
import { runtime } from "./../../../runtime/runtime.store.js";
import { Analytics } from "./../../../runtime/analytics.js";
import {
contextMenu,
Expand Down Expand Up @@ -33,7 +31,7 @@
import ModuleSelection from "./underlays/ModuleBorder.svelte";
import { ConfigTarget } from "../../panels/configuration/Configuration.store";
import { EventType, EventTypeToNumber } from "grid-protocol";
import { get } from "svelte/store";
import { get, writable } from "svelte/store";
import {
loadPreset,
loadProfile,
Expand All @@ -42,12 +40,18 @@
discardElement,
clearElement,
} from "../../../main/panels/configuration/configuration-actions";
import { appClipboard } from "../../../runtime/clipboard.store";
import {
createCopyAllDisabledStore,
createOverwriteDisabledStore,
createDiscardElementDisabledStore,
createClearElementDisabledStore,
} from "../../panels/configuration/configuration-actions";

export let device = undefined;
export let width = 225;

let component = undefined;
let elementNumber = undefined;

onMount(() => {
const components = [
Expand Down Expand Up @@ -254,46 +258,44 @@
let:isLeftCut
let:isRightCut
>
{@const target = writable(
ConfigTarget.create({
device: {
dx: device.dx,
dy: device.dy,
},
page: get(user_input).pagenumber,
element: elementNumber,
eventType: EventTypeToNumber(EventType.INIT),
})
)}
{@const overwriteElementDisabled = createOverwriteDisabledStore(target)}
{@const copyElementDisabled = createCopyAllDisabledStore(target)}
{@const discardElementDisabled =
createDiscardElementDisabledStore(target)}
{@const clearElementDisabled = createClearElementDisabledStore(target)}
<button
use:contextTarget={{
items: [
{
text: "Copy Element",
handler: () => handleCopyElement(elementNumber),
isDisabled: () => get(copyElementDisabled),
},
{
text: "Overwrite Element",
handler: () => handleOverwriteElement(elementNumber),
isDisabled: () => {
const clipboard = get(appClipboard);
const current = ConfigTarget.getCurrent();

if (clipboard?.key !== ClipboardKey.ELEMENT) {
return true;
}

return current.elementType !== clipboard.elementType;
},
isDisabled: () => get(overwriteElementDisabled),
},
{
text: "Discard Element Changes",
handler: () => handleDiscardElement(elementNumber),
isDisabled: () => {
const target = ConfigTarget.create({
device: {
dx: device.dx,
dy: device.dy,
},
page: get(user_input).pagenumber,
element: elementNumber,
eventType: EventTypeToNumber(EventType.INIT),
});
return !target.hasChanges();
},
isDisabled: () => get(discardElementDisabled),
},
{
text: "Clear Element",
handler: handleClearElement,
isDisabled: () => get(clearElementDisabled),
},
],
}}
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/main/panels/configuration/Configuration.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ export class ConfigTarget {
return currentTarget;
}

watch() {
return new ConfigTargetWatcher(this);
}

hasChanges() {
for (const event of this.events) {
if (event.config !== event.stored) {
Expand Down
Loading