-
Notifications
You must be signed in to change notification settings - Fork 349
feat: プロジェクトの複製を保存する機能を追加 #2571
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
Changes from 5 commits
5090efc
e8f2fdc
e1d6cae
79f66d9
02d5074
ad592b0
ef5758f
4c95435
49853a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,7 @@ import { | |||||||||||||||
| } from "@/components/Dialog/Dialog"; | ||||||||||||||||
| import { uuid4 } from "@/helpers/random"; | ||||||||||||||||
| import { getAppInfos } from "@/domain/appInfo"; | ||||||||||||||||
| import { errorToMessage } from "@/helpers/errorHelper"; | ||||||||||||||||
|
|
||||||||||||||||
| export const projectStoreState: ProjectStoreState = { | ||||||||||||||||
| savedLastCommandIds: { talk: null, song: null }, | ||||||||||||||||
|
|
@@ -246,108 +247,136 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({ | |||||||||||||||
| ), | ||||||||||||||||
| }, | ||||||||||||||||
|
|
||||||||||||||||
| SAVE_PROJECT_FILE: { | ||||||||||||||||
| SAVE_PROJECT_FILE_AS_COPY: { | ||||||||||||||||
| /** | ||||||||||||||||
| * プロジェクトファイルを保存する。保存の成否が返る。 | ||||||||||||||||
| * プロジェクトファイルを複製として保存する。保存の成否が返る。 | ||||||||||||||||
| * エラー発生時はダイアログが表示される。 | ||||||||||||||||
| */ | ||||||||||||||||
| action: createUILockAction(async (context, { filePath: filePathArg }) => { | ||||||||||||||||
| let filePath = filePathArg; | ||||||||||||||||
| try { | ||||||||||||||||
| if (!filePath) { | ||||||||||||||||
| filePath = await context.actions.PROMPT_PROJECT_SAVE_FILE_PATH({}); | ||||||||||||||||
| if (!filePath) { | ||||||||||||||||
| return false; | ||||||||||||||||
| } | ||||||||||||||||
Hiroshiba marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| return true; | ||||||||||||||||
| } catch (err) { | ||||||||||||||||
| window.backend.logError(err); | ||||||||||||||||
| await showAlertDialog({ | ||||||||||||||||
| title: "エラー", | ||||||||||||||||
| message: `プロジェクトファイルの保存に失敗しました。\n${errorToMessage(err)}`, | ||||||||||||||||
| }); | ||||||||||||||||
| return false; | ||||||||||||||||
| } | ||||||||||||||||
| }), | ||||||||||||||||
| }, | ||||||||||||||||
|
|
||||||||||||||||
| SAVE_PROJECT_FILE: { | ||||||||||||||||
| /** | ||||||||||||||||
| * プロジェクトファイルを保存し、現在のプロジェクトファイルのパスを更新する。保存の成否が返る。 | ||||||||||||||||
| */ | ||||||||||||||||
| action: createUILockAction( | ||||||||||||||||
| async (context, { overwrite }: { overwrite?: boolean }) => { | ||||||||||||||||
| let filePath = context.state.projectFilePath; | ||||||||||||||||
| try { | ||||||||||||||||
| if (!overwrite || !filePath) { | ||||||||||||||||
| let defaultPath: string; | ||||||||||||||||
|
|
||||||||||||||||
| if (!filePath) { | ||||||||||||||||
| // if new project: use generated name | ||||||||||||||||
| defaultPath = `${context.getters.DEFAULT_PROJECT_FILE_BASE_NAME}.vvproj`; | ||||||||||||||||
| } else { | ||||||||||||||||
| // if saveAs for existing project: use current project path | ||||||||||||||||
| defaultPath = filePath; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Write the current status to a project file. | ||||||||||||||||
| const ret = await window.backend.showSaveFileDialog({ | ||||||||||||||||
| title: "プロジェクトファイルの保存", | ||||||||||||||||
| name: "VOICEVOX Project file", | ||||||||||||||||
| extensions: ["vvproj"], | ||||||||||||||||
| defaultPath, | ||||||||||||||||
| }); | ||||||||||||||||
| if (ret == undefined) { | ||||||||||||||||
| return false; | ||||||||||||||||
| } | ||||||||||||||||
| filePath = ret; | ||||||||||||||||
| } | ||||||||||||||||
| if ( | ||||||||||||||||
| context.state.projectFilePath && | ||||||||||||||||
| context.state.projectFilePath != filePath | ||||||||||||||||
| ) { | ||||||||||||||||
| await showMessageDialog({ | ||||||||||||||||
| type: "info", | ||||||||||||||||
| title: "保存", | ||||||||||||||||
| message: `編集中のプロジェクトが ${filePath} に切り替わりました。`, | ||||||||||||||||
| }); | ||||||||||||||||
| if (!overwrite || !filePath) { | ||||||||||||||||
| filePath = await context.actions.PROMPT_PROJECT_SAVE_FILE_PATH({ | ||||||||||||||||
| defaultFilePath: filePath, | ||||||||||||||||
| }); | ||||||||||||||||
| if (!filePath) { | ||||||||||||||||
| return false; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| await context.actions.APPEND_RECENTLY_USED_PROJECT({ | ||||||||||||||||
| filePath, | ||||||||||||||||
| } | ||||||||||||||||
| if ( | ||||||||||||||||
| context.state.projectFilePath && | ||||||||||||||||
| context.state.projectFilePath != filePath | ||||||||||||||||
| ) { | ||||||||||||||||
| await showMessageDialog({ | ||||||||||||||||
| type: "info", | ||||||||||||||||
| title: "保存", | ||||||||||||||||
| message: `編集中のプロジェクトが ${filePath} に切り替わりました。`, | ||||||||||||||||
| }); | ||||||||||||||||
| const appVersion = getAppInfos().version; | ||||||||||||||||
| const { | ||||||||||||||||
| audioItems, | ||||||||||||||||
| audioKeys, | ||||||||||||||||
| tpqn, | ||||||||||||||||
| tempos, | ||||||||||||||||
| timeSignatures, | ||||||||||||||||
| tracks, | ||||||||||||||||
| trackOrder, | ||||||||||||||||
| } = context.state; | ||||||||||||||||
| const projectData: LatestProjectType = { | ||||||||||||||||
| appVersion, | ||||||||||||||||
| talk: { | ||||||||||||||||
| audioKeys, | ||||||||||||||||
| audioItems, | ||||||||||||||||
| }, | ||||||||||||||||
| song: { | ||||||||||||||||
| tpqn, | ||||||||||||||||
| tempos, | ||||||||||||||||
| timeSignatures, | ||||||||||||||||
| tracks: Object.fromEntries(tracks), | ||||||||||||||||
| trackOrder, | ||||||||||||||||
| }, | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| const buf = new TextEncoder().encode( | ||||||||||||||||
| JSON.stringify(projectData), | ||||||||||||||||
| ).buffer; | ||||||||||||||||
| await window.backend | ||||||||||||||||
| .writeFile({ | ||||||||||||||||
| filePath, | ||||||||||||||||
| buffer: buf, | ||||||||||||||||
| }) | ||||||||||||||||
| .then(getValueOrThrow); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| await context.actions.APPEND_RECENTLY_USED_PROJECT({ | ||||||||||||||||
| filePath, | ||||||||||||||||
| }); | ||||||||||||||||
| const result = await context.actions.SAVE_PROJECT_FILE_AS_COPY({ | ||||||||||||||||
| filePath, | ||||||||||||||||
| }); | ||||||||||||||||
sevenc-nanashi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||
| const result = await context.actions.SAVE_PROJECT_FILE_AS_COPY({ | |
| filePath, | |
| }); | |
| // FIXME: SAVE_PROJECT_FILE_AS_COPYへの依存をやめる | |
| const result = await context.actions.SAVE_PROJECT_FILE_AS_COPY({ | |
| filePath, | |
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.