Skip to content

Commit

Permalink
set new patch unsaved, handle rename and save
Browse files Browse the repository at this point in the history
  • Loading branch information
steam0r committed Nov 12, 2024
1 parent 8e00381 commit 636002e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
16 changes: 6 additions & 10 deletions src/electron/electron_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ class ElectronApi
if (topicConfig.needsProjectFile)
{
const projectFile = settings.getCurrentProjectFile();
if (!projectFile || !projectFile.endsWith(projectsUtil.CABLES_PROJECT_FILE_EXTENSION))
if (!projectFile)
{
const newProjectFile = await electronApp.saveProjectFileDialog();
const newProjectFile = await electronApp.saveProjectFileDialog(data.name);
if (newProjectFile)
{
let patchData = null;
Expand All @@ -126,7 +126,7 @@ class ElectronApi
}
else
{
return this.error("no directory chosen", null, "info");
return this.error("CANCELLED", null, "info");
}
}
}
Expand Down Expand Up @@ -1262,9 +1262,9 @@ class ElectronApi
return this.success("OK", { "assets": [], "countPatches": 0, "countOps": 0 }, true);
}

async saveProjectAs()
async saveProjectAs(data)
{
const projectFile = await electronApp.saveProjectFileDialog();
const projectFile = await electronApp.saveProjectFileDialog(data.name);
if (!projectFile)
{
return this.error("no project dir chosen", null, "info");
Expand Down Expand Up @@ -1386,12 +1386,8 @@ class ElectronApi
{
currentProject = projectsUtil.addOpDir(currentProject, opDir, true);
projectsUtil.writeProjectToFile(settings.getCurrentProjectFile(), currentProject);
return this.success("OK", projectsUtil.getProjectOpDirs(currentProject, true));
}
else
{
return this.error("no directory chosen", [], "info");
}
return this.success("OK", projectsUtil.getProjectOpDirs(currentProject, true));
}

async removeProjectOpDir(dirName)
Expand Down
4 changes: 3 additions & 1 deletion src/electron/electron_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ class ElectronSettings

getCurrentProjectFile()
{
return this.get(this.PROJECTFILE_FIELD);
const projectFile = this.get(this.PROJECTFILE_FIELD);
if (projectFile && projectFile.endsWith(projectsUtil.CABLES_PROJECT_FILE_EXTENSION)) return projectFile;
return null;
}

getBuildInfo()
Expand Down
3 changes: 2 additions & 1 deletion src/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class ElectronApp
});
}

async saveProjectFileDialog()
async saveProjectFileDialog(defaultPath)
{
const extensions = [];
extensions.push(projectsUtil.CABLES_PROJECT_FILE_EXTENSION);
Expand All @@ -339,6 +339,7 @@ class ElectronApp
return dialog.showSaveDialog(this.editorWindow, {
"title": title,
"properties": properties,
"defaultPath": defaultPath,
"filters": [{
"name": "cables project",
"extensions": extensions,
Expand Down
5 changes: 5 additions & 0 deletions src/utils/projects_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class ProjectsUtil extends SharedProjectsUtil
};
}

getNewProjectName(randomize = false)
{
return "untitled";
}

getProjectOpDirs(project, includeOsDir = true, reverse = false, addLocalCoreIfPackaged = true)
{
let opsDirs = [];
Expand Down
5 changes: 3 additions & 2 deletions src_client/cmd_electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,10 @@ CABLES_CMD_STANDALONE.addOpPackage = (options, next) =>
};

CABLES_CMD_STANDALONE_OVERRIDES.PATCH = {};
CABLES_CMD_STANDALONE_OVERRIDES.PATCH.saveAs = () =>
CABLES_CMD_STANDALONE_OVERRIDES.PATCH.saveAs = (data) =>
{
standalone.editor.api("saveProjectAs", { }, (_err, r) => {});
let patchName = standalone.gui.project() ? standalone.gui.project().name : null;
standalone.editor.api("saveProjectAs", { "name": patchName }, (_err, r) => {});
};
CABLES_CMD_STANDALONE_OVERRIDES.PATCH.uploadFileDialog = () =>
{
Expand Down
2 changes: 1 addition & 1 deletion src_client/electron_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export default class ElectronEditor
"opSaveLayout": { },
"opSetSummary": { },
"checkNumAssetPatches": {},
"saveProjectAs": {},
"saveProjectAs": { },
"gotoPatch": {},
"getProjectOpDirs": {},
"openDir": {},
Expand Down
7 changes: 7 additions & 0 deletions src_client/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ export default class CablesStandalone
});
}
waitForAce();
if (this.gui)
{
this.gui.on("uiloaded", () =>
{
if (this.editor && this.editor.config && !this.editor.config.patchFile) this.gui.setStateUnsaved();
});
}
});
};
if (this._settings.uiLoadStart) this.editorWindow.CABLESUILOADER.uiLoadStart -= this._settings.uiLoadStart;
Expand Down

0 comments on commit 636002e

Please sign in to comment.