mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-02 04:22:15 +00:00
parent
44c26f1570
commit
0af42ee6f9
3 changed files with 18 additions and 19 deletions
|
@ -13,12 +13,8 @@
|
||||||
|
|
||||||
let self: FloatingMenu | undefined;
|
let self: FloatingMenu | undefined;
|
||||||
|
|
||||||
export function dismiss() {
|
|
||||||
dialog.dismissDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
// Focus the first button in the popup
|
// Focus the button which is marked as emphasized, or otherwise the first button, in the popup
|
||||||
const emphasizedOrFirstButton = (self?.div()?.querySelector("[data-emphasized]") || self?.div()?.querySelector("[data-text-button]") || undefined) as HTMLButtonElement | undefined;
|
const emphasizedOrFirstButton = (self?.div()?.querySelector("[data-emphasized]") || self?.div()?.querySelector("[data-text-button]") || undefined) as HTMLButtonElement | undefined;
|
||||||
emphasizedOrFirstButton?.focus();
|
emphasizedOrFirstButton?.focus();
|
||||||
});
|
});
|
||||||
|
@ -34,9 +30,9 @@
|
||||||
{#if $dialog.widgets.layout.length > 0}
|
{#if $dialog.widgets.layout.length > 0}
|
||||||
<WidgetLayout layout={$dialog.widgets} class="details" />
|
<WidgetLayout layout={$dialog.widgets} class="details" />
|
||||||
{/if}
|
{/if}
|
||||||
{#if ($dialog.jsCallbackBasedButtons?.length || NaN) > 0}
|
{#if ($dialog.crashDialogButtons?.length || NaN) > 0}
|
||||||
<LayoutRow class="panic-buttons-row">
|
<LayoutRow class="panic-buttons-row">
|
||||||
{#each $dialog.jsCallbackBasedButtons || [] as button, index (index)}
|
{#each $dialog.crashDialogButtons || [] as button, index (index)}
|
||||||
<TextButton action={() => button.callback?.()} {...button.props} />
|
<TextButton action={() => button.callback?.()} {...button.props} />
|
||||||
{/each}
|
{/each}
|
||||||
</LayoutRow>
|
</LayoutRow>
|
||||||
|
|
|
@ -19,12 +19,12 @@ export function createPanicManager(editor: Editor, dialogState: DialogState): vo
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error(panicDetails);
|
console.error(panicDetails);
|
||||||
|
|
||||||
const panicDialog = preparePanicDialog(displayDialogPanic.header, displayDialogPanic.description, panicDetails);
|
const crashDialog = prepareCrashDialog(displayDialogPanic.header, displayDialogPanic.description, panicDetails);
|
||||||
dialogState.createPanicDialog(...panicDialog);
|
dialogState.createCrashDialog(...crashDialog);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function preparePanicDialog(header: string, details: string, panicDetails: string): [IconName, WidgetLayout, TextButtonWidget[]] {
|
function prepareCrashDialog(header: string, details: string, panicDetails: string): [IconName, WidgetLayout, TextButtonWidget[]] {
|
||||||
const headerLabel: TextLabel = { kind: "TextLabel", value: header, disabled: false, bold: true, italic: false, tableAlign: false, minWidth: 0, multiline: false, tooltip: "" };
|
const headerLabel: TextLabel = { kind: "TextLabel", value: header, disabled: false, bold: true, italic: false, tableAlign: false, minWidth: 0, multiline: false, tooltip: "" };
|
||||||
const detailsLabel: TextLabel = { kind: "TextLabel", value: details, disabled: false, bold: false, italic: false, tableAlign: false, minWidth: 0, multiline: true, tooltip: "" };
|
const detailsLabel: TextLabel = { kind: "TextLabel", value: details, disabled: false, bold: false, italic: false, tableAlign: false, minWidth: 0, multiline: true, tooltip: "" };
|
||||||
|
|
||||||
|
@ -52,9 +52,9 @@ function preparePanicDialog(header: string, details: string, panicDetails: strin
|
||||||
},
|
},
|
||||||
props: { kind: "TextButton", label: "Clear Saved Data", emphasized: false, minWidth: 96 },
|
props: { kind: "TextButton", label: "Clear Saved Data", emphasized: false, minWidth: 96 },
|
||||||
};
|
};
|
||||||
const jsCallbackBasedButtons = [reloadButton, copyErrorLogButton, reportOnGithubButton, clearPersistedDataButton];
|
const crashDialogButtons = [reloadButton, copyErrorLogButton, reportOnGithubButton, clearPersistedDataButton];
|
||||||
|
|
||||||
return ["Warning", widgets, jsCallbackBasedButtons];
|
return ["Warning", widgets, crashDialogButtons];
|
||||||
}
|
}
|
||||||
|
|
||||||
function githubUrl(panicDetails: string): string {
|
function githubUrl(panicDetails: string): string {
|
||||||
|
|
|
@ -11,24 +11,27 @@ export function createDialogState(editor: Editor) {
|
||||||
icon: "" as IconName,
|
icon: "" as IconName,
|
||||||
widgets: defaultWidgetLayout(),
|
widgets: defaultWidgetLayout(),
|
||||||
// Special case for the crash dialog because we cannot handle button widget callbacks from Rust once the editor instance has panicked
|
// Special case for the crash dialog because we cannot handle button widget callbacks from Rust once the editor instance has panicked
|
||||||
jsCallbackBasedButtons: undefined as undefined | TextButtonWidget[],
|
crashDialogButtons: undefined as undefined | TextButtonWidget[],
|
||||||
});
|
});
|
||||||
|
|
||||||
function dismissDialog(): void {
|
function dismissDialog(): void {
|
||||||
|
|
||||||
update((state) => {
|
update((state) => {
|
||||||
state.visible = false;
|
// Disallow dismissing the crash dialog since it can confuse users why the app stopped responding if they dismiss it without realizing what it means
|
||||||
|
if (!state.crashDialogButtons) state.visible = false;
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a panic dialog from JS.
|
// Creates a crash dialog from JS once the editor has panicked.
|
||||||
// Normal dialogs are created in the Rust backend, but for the crash dialog, the editor instance has panicked so it cannot respond to widget callbacks.
|
// Normal dialogs are created in the Rust backend, but for the crash dialog, the editor instance has panicked so it cannot respond to widget callbacks.
|
||||||
function createPanicDialog(icon: IconName, widgets: WidgetLayout, jsCallbackBasedButtons: TextButtonWidget[]): void {
|
function createCrashDialog(icon: IconName, widgets: WidgetLayout, crashDialogButtons: TextButtonWidget[]): void {
|
||||||
update((state) => {
|
update((state) => {
|
||||||
state.visible = true;
|
state.visible = true;
|
||||||
state.icon = icon;
|
state.icon = icon;
|
||||||
state.widgets = widgets;
|
state.widgets = widgets;
|
||||||
state.jsCallbackBasedButtons = jsCallbackBasedButtons;
|
state.crashDialogButtons = crashDialogButtons;
|
||||||
return state;
|
return state;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -45,7 +48,7 @@ export function createDialogState(editor: Editor) {
|
||||||
update((state) => {
|
update((state) => {
|
||||||
patchWidgetLayout(state.widgets, updateDialogDetails);
|
patchWidgetLayout(state.widgets, updateDialogDetails);
|
||||||
|
|
||||||
state.jsCallbackBasedButtons = undefined;
|
state.crashDialogButtons = undefined;
|
||||||
return state;
|
return state;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -54,7 +57,7 @@ export function createDialogState(editor: Editor) {
|
||||||
return {
|
return {
|
||||||
subscribe,
|
subscribe,
|
||||||
dismissDialog,
|
dismissDialog,
|
||||||
createPanicDialog,
|
createCrashDialog: createCrashDialog,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export type DialogState = ReturnType<typeof createDialogState>;
|
export type DialogState = ReturnType<typeof createDialogState>;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue