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

アプリのUIサイズを変更するショートカットの追加 #2380

Merged
merged 9 commits into from
Dec 3, 2024
6 changes: 6 additions & 0 deletions public/howtouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ GPU をお持ちの方は、音声の生成がずっと速い GPU モードを
- 元に戻す
- `Ctrl` + `Y`
- やり直す
- `Ctrl` + `+`
- 拡大
- `Ctrl` + `-`
- 縮小
- `Ctrl` + `Alt` + `0`
- 拡大率のリセット
- `Esc`
- テキスト欄からカーソルを外す
- 1
Expand Down
17 changes: 16 additions & 1 deletion src/backend/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,22 @@ registerIpcMainHandle<IpcMainHandle>({
win.maximize();
}
},

// UIの拡大率拡大
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちょっとコメントの形を変えさせていただいて、コメントの中身を統一させていただきます!

ZOOM_IN: () => {
win.webContents.setZoomFactor(
Math.min(Math.max(win.webContents.getZoomFactor() + 0.1, 0.5), 3),
);
},
// UIの拡大率縮小
ZOOM_OUT: () => {
win.webContents.setZoomFactor(
Math.min(Math.max(win.webContents.getZoomFactor() - 0.1, 0.5), 3),
);
},
// UIの拡大率リセット
ZOOM_RESET: () => {
win.webContents.setZoomFactor(1);
},
OPEN_LOG_DIRECTORY: () => {
void shell.openPath(app.getPath("logs"));
},
Expand Down
10 changes: 10 additions & 0 deletions src/backend/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ const api: Sandbox = {
void ipcRendererInvokeProxy.MAXIMIZE_WINDOW();
},

zoomIn: () => {
void ipcRendererInvokeProxy.ZOOM_IN();
},
zoomOut: () => {
void ipcRendererInvokeProxy.ZOOM_OUT();
},
zoomReset: () => {
void ipcRendererInvokeProxy.ZOOM_RESET();
},

logError: (...params) => {
console.error(...params);
// 経緯 https://github.com/VOICEVOX/voicevox/pull/1620#discussion_r1371804569
Expand Down
27 changes: 27 additions & 0 deletions src/components/Menu/MenuBar/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ const importProject = () => {
}
};

// UIの拡大(キーボードショートカット)
const zoomIn = () => {
window.backend.zoomIn();
};

// UIの縮小(キーボードショートカット)
const zoomOut = () => {
window.backend.zoomOut();
};

// UIのリセット(キーボードショートカット)
const zoomReset = () => {
window.backend.zoomReset();
};

// 「最近使ったプロジェクト」のメニュー
const recentProjectsSubMenuData = ref<MenuItemData[]>([]);
const updateRecentProjects = async () => {
Expand Down Expand Up @@ -547,6 +562,18 @@ registerHotkeyForAllEditors({
callback: importProject,
name: "プロジェクトを読み込む",
});
registerHotkeyForAllEditors({
callback: zoomIn,
name: "拡大",
});
registerHotkeyForAllEditors({
callback: zoomOut,
name: "縮小",
});
registerHotkeyForAllEditors({
callback: zoomReset,
name: "拡大率のリセット",
});
</script>

<style lang="scss">
Expand Down
25 changes: 25 additions & 0 deletions src/components/Sing/menuBarData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,31 @@ export const useMenuBarData = () => {
const [showSingCharacterPortrait, setShowSingCharacterPortrait] =
useRootMiscSetting(store, "showSingCharacterPortrait");
const viewSubMenuData = computed<MenuItemData[]>(() => [
{
type: "button",
label: "拡大",
onClick: () => {
void window.backend.zoomIn();
},
disableWhenUiLocked: false,
},
{
type: "button",
label: "縮小",
onClick: () => {
void window.backend.zoomOut();
},
disableWhenUiLocked: true,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sing/talkで統一のメニューは統一して書くこともできるので、その形に変えさせていただきます!

{
type: "button",
label: "拡大率のリセット",
onClick: () => {
void window.backend.zoomReset();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あ、あとwindow.backendを.vueとかから直接呼ぶのは避ける方針にしているのでそれも反映させていただきます!
ちなみにVuexを経由するようになっていて、そのVuexの実装がなかったからエラーが出ている感じでした!
(より正確には型定義だけされていた感じでした)

},
disableWhenUiLocked: true,
},
{ type: "separator" },
{
type: "button",
label: showSingCharacterPortrait.value
Expand Down
25 changes: 25 additions & 0 deletions src/components/Talk/menuBarData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,31 @@ export const useMenuBarData = () => {
"showTextLineNumber",
);
const viewSubMenuData = computed<MenuItemData[]>(() => [
{
type: "button",
label: "拡大",
onClick: () => {
void window.backend.zoomIn();
},
disableWhenUiLocked: false,
},
{
type: "button",
label: "縮小",
onClick: () => {
void window.backend.zoomOut();
},
disableWhenUiLocked: true,
},
{
type: "button",
label: "拡大率のリセット",
onClick: () => {
void window.backend.zoomReset();
},
disableWhenUiLocked: true,
},
{ type: "separator" },
{
type: "button",
label: showTextLineNumber.value ? "行番号を非表示" : "行番号を表示",
Expand Down
12 changes: 12 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2087,6 +2087,18 @@ export type UiStoreTypes = {
getter: boolean;
};

ZOOM_IN: {
action(): void;
};

ZOOM_OUT: {
action(): void;
};

ZOOM_RESET: {
action(): void;
};

CHECK_EDITED_AND_NOT_SAVE: {
action(
obj:
Expand Down
15 changes: 15 additions & 0 deletions src/type/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ export type IpcIHData = {
return: void;
};

ZOOM_IN: {
args: [];
return: void;
};

ZOOM_OUT: {
args: [];
return: void;
};

ZOOM_RESET: {
args: [];
return: void;
};

OPEN_LOG_DIRECTORY: {
args: [];
return: void;
Expand Down
18 changes: 18 additions & 0 deletions src/type/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ export const defaultHotkeySettings: HotkeySettingType[] = [
action: "やり直す",
combination: HotkeyCombination(!isMac ? "Ctrl Y" : "Shift Meta Z"),
},
{
action: "拡大",
combination: HotkeyCombination(!isMac ? "Ctrl +" : "Meta +"),
},
{
action: "縮小",
combination: HotkeyCombination(!isMac ? "Ctrl -" : "Meta -"),
},
{
action: "拡大率のリセット",
combination: HotkeyCombination(!isMac ? "Ctrl Alt 0" : "Meta Alt 0"),
},
{
action: "新規プロジェクト",
combination: HotkeyCombination(!isMac ? "Ctrl N" : "Meta N"),
Expand Down Expand Up @@ -238,6 +250,9 @@ export interface Sandbox {
closeWindow(): void;
minimizeWindow(): void;
maximizeWindow(): void;
zoomIn(): void;
zoomOut(): void;
zoomReset(): void;
logError(...params: unknown[]): void;
logWarn(...params: unknown[]): void;
logInfo(...params: unknown[]): void;
Expand Down Expand Up @@ -433,6 +448,9 @@ export const hotkeyActionNameSchema = z.enum([
"テキスト欄にフォーカスを戻す",
"元に戻す",
"やり直す",
"拡大",
"縮小",
"拡大率のリセット",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちょっと後ろの方にさせていただきます!
(特に問題ないはずですが、まぁ追加の順序が分かりやすいようにぐらいのきもちです)

"新規プロジェクト",
"プロジェクトを名前を付けて保存",
"プロジェクトを上書き保存",
Expand Down
Loading