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

ショートカットキーを初期値に戻すボタンの追加 #472

Merged
merged 16 commits into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
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
146 changes: 76 additions & 70 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,77 @@ protocol.registerSchemesAsPrivileged([
{ scheme: "app", privileges: { secure: true, standard: true, stream: true } },
]);

const defaultHotkeySettings: HotkeySetting[] = [
{
action: "音声書き出し",
combination: "Ctrl E",
},
{
action: "一つだけ書き出し",
combination: "E",
},
{
action: "再生/停止",
combination: "Space",
},
{
action: "連続再生/停止",
combination: "Shift Space",
},
{
action: "アクセント欄を表示",
combination: "1",
},
{
action: "イントネーション欄を表示",
combination: "2",
},
{
action: "テキスト欄を追加",
combination: "Shift Enter",
},
{
action: "テキスト欄を削除",
combination: "Shift Delete",
},
{
action: "テキスト欄からフォーカスを外す",
combination: "Escape",
},
{
action: "テキスト欄にフォーカスを戻す",
combination: "Enter",
},
{
action: "元に戻す",
combination: "Ctrl Z",
},
{
action: "やり直す",
combination: "Ctrl Y",
},
{
action: "新規プロジェクト",
combination: "Ctrl N",
},
{
action: "プロジェクトを名前を付けて保存",
combination: "Ctrl Shift S",
},
{
action: "プロジェクトを上書き保存",
combination: "Ctrl S",
},
{
action: "プロジェクト読み込み",
combination: "Ctrl O",
},
{
action: "テキスト読み込む",
combination: "",
},
];

// 設定ファイル
const store = new Store<{
useGpu: boolean;
Expand Down Expand Up @@ -118,76 +189,7 @@ const store = new Store<{
combination: { type: "string" },
},
},
default: [
{
action: "音声書き出し",
combination: "Ctrl E",
},
{
action: "一つだけ書き出し",
combination: "E",
},
{
action: "再生/停止",
combination: "Space",
},
{
action: "連続再生/停止",
combination: "Shift Space",
},
{
action: "アクセント欄を表示",
combination: "1",
},
{
action: "イントネーション欄を表示",
combination: "2",
},
{
action: "テキスト欄を追加",
combination: "Shift Enter",
},
{
action: "テキスト欄を削除",
combination: "Shift Delete",
},
{
action: "テキスト欄からフォーカスを外す",
combination: "Escape",
},
{
action: "テキスト欄にフォーカスを戻す",
combination: "Enter",
},
{
action: "元に戻す",
combination: "Ctrl Z",
},
{
action: "やり直す",
combination: "Ctrl Y",
},
{
action: "新規プロジェクト",
combination: "Ctrl N",
},
{
action: "プロジェクトを名前を付けて保存",
combination: "Ctrl Shift S",
},
{
action: "プロジェクトを上書き保存",
combination: "Ctrl S",
},
{
action: "プロジェクト読み込み",
combination: "Ctrl O",
},
{
action: "テキスト読み込む",
combination: "",
},
],
default: defaultHotkeySettings,
},
defaultStyleIds: {
type: "array",
Expand Down Expand Up @@ -697,6 +699,10 @@ ipcMainHandle("SET_DEFAULT_STYLE_IDS", (_, defaultStyleIds) => {
store.set("defaultStyleIds", defaultStyleIds);
});

ipcMainHandle("GET_DEFAULT_HOTKEY_SETTINGS", () => {
return defaultHotkeySettings;
});

// app callback
app.on("web-contents-created", (e, contents) => {
// リンククリック時はブラウザを開く
Expand Down
60 changes: 59 additions & 1 deletion src/components/HotkeySettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@
"
@click="openHotkeyDialog(props.row.action)"
/>
<q-btn
rounded
flat
icon="settings_backup_restore"
padding="none sm"
size="1em"
:disable="checkHotkeyReadonly(props.row.action)"
@click="resetHotkey(props.row.action)"
>
<q-tooltip :delay="500">デフォルトに戻す</q-tooltip>
</q-btn>
</q-td>
</q-tr>
</template>
Expand Down Expand Up @@ -182,7 +193,8 @@
import { defineComponent, computed, ref } from "vue";
import { useStore } from "@/store";
import { parseCombo } from "@/store/setting";
import { HotkeyAction } from "@/type/preload";
import { HotkeyAction, HotkeySetting } from "@/type/preload";
import { useQuasar } from "quasar";

export default defineComponent({
name: "HotkeySettingDialog",
Expand All @@ -196,6 +208,7 @@ export default defineComponent({

setup(props, { emit }) {
const store = useStore();
const $q = useQuasar();

const hotkeySettingDialogOpenComputed = computed({
get: () => props.modelValue,
Expand Down Expand Up @@ -308,6 +321,35 @@ export default defineComponent({
);
});

const resetHotkey = (action: string) => {
$q.dialog({
title: "ショートカットキーを初期値に戻します",
message: `${action}のショートカットキーを初期値に戻します。<br/>本当に戻しますか?`,
html: true,
ok: {
label: "初期値に戻す",
flat: true,
textColor: "secondary",
},
cancel: {
label: "初期値に戻さない",
flat: true,
textColor: "secondary",
},
}).onOk(() => {
window.electron
.getDefaultHotkeySettings()
.then((defaultSettings: HotkeySetting[]) => {
const setting = defaultSettings.find(
(value) => value.action == action
);
if (setting) {
changeHotkeySettings(action, setting.combination);
}
});
});
};

return {
hotkeySettingDialogOpenComputed,
isHotkeyDialogOpened,
Expand All @@ -326,6 +368,7 @@ export default defineComponent({
changeHotkeySettings,
confirmBtnEnabled,
checkHotkeyReadonly,
resetHotkey,
};
},
});
Expand All @@ -351,6 +394,21 @@ export default defineComponent({
overflow-x: hidden;
}

tbody tr {
td button:last-child {
float: right;
display: none;
}
&:hover td button:last-child {
display: inline-flex;
color: var(--color-display);
opacity: 0.5;
&:hover {
opacity: 1;
}
}
}

thead tr th {
position: sticky;
top: 0;
Expand Down
4 changes: 4 additions & 0 deletions src/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ const api: Sandbox = {
await ipcRendererInvoke("SET_DEFAULT_STYLE_IDS", defaultStyleIds);
},

getDefaultHotkeySettings: async () => {
return await ipcRendererInvoke("GET_DEFAULT_HOTKEY_SETTINGS");
},

theme: (newData) => {
return ipcRenderer.invoke("THEME", { newData });
},
Expand Down
5 changes: 5 additions & 0 deletions src/type/ipc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ type IpcIHData = {
return: void;
};

GET_DEFAULT_HOTKEY_SETTINGS: {
args: [];
return: import("@/type/preload").HotkeySetting[];
};

THEME: {
args: [obj: { newData?: string }];
return: import("@/type/preload").ThemeSetting | void;
Expand Down
1 change: 1 addition & 0 deletions src/type/preload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface Sandbox {
setDefaultStyleIds(
defaultStyleIds: { speakerUuid: string; defaultStyleId: number }[]
): Promise<void>;
getDefaultHotkeySettings(): Promise<HotKeySetting[]>;
theme(newData?: string): Promise<ThemeSetting | void>;
vuexReady(): void;
}
Expand Down