Skip to content

Commit

Permalink
ENH: 未保存時のダイアログを改善 (#1238)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabonerune authored Feb 28, 2023
1 parent 2c4d7a6 commit 6db58f3
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ ipcMainHandle("SHOW_MESSAGE_DIALOG", (_, { type, title, message }) => {

ipcMainHandle(
"SHOW_QUESTION_DIALOG",
(_, { type, title, message, buttons, cancelId }) => {
(_, { type, title, message, buttons, cancelId, defaultId }) => {
return dialog
.showMessageBox(win, {
type,
Expand All @@ -681,6 +681,7 @@ ipcMainHandle(
message,
noLink: true,
cancelId,
defaultId,
})
.then((value) => {
return value.response;
Expand Down
10 changes: 9 additions & 1 deletion src/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,21 @@ const api: Sandbox = {
return ipcRendererInvoke("SHOW_MESSAGE_DIALOG", { type, title, message });
},

showQuestionDialog: ({ type, title, message, buttons, cancelId }) => {
showQuestionDialog: ({
type,
title,
message,
buttons,
cancelId,
defaultId,
}) => {
return ipcRendererInvoke("SHOW_QUESTION_DIALOG", {
type,
title,
message,
buttons,
cancelId,
defaultId,
});
},

Expand Down
7 changes: 5 additions & 2 deletions src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
},

SAVE_PROJECT_FILE: {
/**
* プロジェクトファイルを保存する。保存の成否が返る。
*/
action: createUILockAction(
async (context, { overwrite }: { overwrite?: boolean }) => {
let filePath = context.state.projectFilePath;
Expand All @@ -396,7 +399,7 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
defaultPath,
});
if (ret == undefined) {
return;
return false;
}
filePath = ret;
}
Expand Down Expand Up @@ -427,7 +430,7 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
"SET_SAVED_LAST_COMMAND_UNIX_MILLISEC",
context.getters.LAST_COMMAND_UNIX_MILLISEC
);
return;
return true;
}
),
},
Expand Down
2 changes: 1 addition & 1 deletion src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ export type ProjectStoreTypes = {
};

SAVE_PROJECT_FILE: {
action(payload: { overwrite?: boolean }): void;
action(payload: { overwrite?: boolean }): boolean;
};

IS_EDITED: {
Expand Down
17 changes: 12 additions & 5 deletions src/store/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,25 @@ export const uiStore = createPartialStore<UiStoreTypes>({
},

CHECK_EDITED_AND_NOT_SAVE: {
async action({ getters }) {
async action({ dispatch, getters }) {
if (getters.IS_EDITED) {
const result: number = await window.electron.showQuestionDialog({
type: "info",
title: "警告",
message:
"プロジェクトの変更が保存されていません。\n" +
"変更を破棄してもよろしいですか?",
buttons: ["破棄", "キャンセル"],
cancelId: 1,
"変更を保存しますか?",
buttons: ["保存", "破棄", "キャンセル"],
cancelId: 2,
defaultId: 2,
});
if (result == 1) {
if (result == 0) {
const saved = await dispatch("SAVE_PROJECT_FILE", {
overwrite: true,
});
if (saved == false) return;
}
if (result == 2) {
return;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/type/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export type IpcIHData = {
message: string;
buttons: string[];
cancelId?: number;
defaultId?: number;
}
];
return: number;
Expand Down
1 change: 1 addition & 0 deletions src/type/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export interface Sandbox {
message: string;
buttons: string[];
cancelId?: number;
defaultId?: number;
}): Promise<number>;
showImportFileDialog(obj: { title: string }): Promise<string | undefined>;
writeFile(obj: {
Expand Down

0 comments on commit 6db58f3

Please sign in to comment.