Skip to content

Commit d80cfc3

Browse files
committed
Add activated state handling in solution load change events
1 parent 06d332e commit d80cfc3

2 files changed

Lines changed: 8 additions & 26 deletions

File tree

src/solutions/solution-manager.factories.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ export const idleSolutionLoadStateFactory = makeFactory<SolutionLoadState>({
2828
solutionPath: () => undefined,
2929
loaded: () => undefined,
3030
converted: () => undefined,
31+
activated: () => undefined,
3132
});
3233

3334
export const activeSolutionLoadStateFactory = makeFactory<SolutionLoadState>({
3435
solutionPath: () => path.join(faker.system.filePath(), `${faker.word.noun()}.csolution.yml`),
3536
loaded: () => undefined,
3637
converted: () => undefined,
38+
activated: () => undefined,
3739
});
3840

3941
const fireOnDidChangeLoadState = (emitter: vscode.EventEmitter<SolutionLoadStateChangeEvent>) => {

src/views/manage-solution/manage-solution-webview-main.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ export class ManageSolutionWebviewMain {
8484
}
8585

8686
private async handleSolutionLoadChange(e: SolutionLoadStateChangeEvent): Promise<void> {
87-
const { solutionPath: newPath, converted: newConverted, loaded: newLoaded } = e.newState;
88-
const { solutionPath: prevPath, converted: prevConverted, loaded: prevLoaded } = e.previousState;
87+
const { solutionPath: newPath, converted: newConverted, loaded: newLoaded, activated: newActivated } = e.newState;
88+
const { solutionPath: prevPath, converted: prevConverted, loaded: prevLoaded, activated: prevActivated } = e.previousState;
8989

9090
if (!this.webviewManager.isPanelActive || (newPath === prevPath && newConverted !== prevConverted)) {
9191
return;
@@ -103,6 +103,8 @@ export class ManageSolutionWebviewMain {
103103
this.setBusyState(false);
104104
return;
105105
}
106+
} else if (newActivated !== prevActivated) {
107+
csolutionChanged = true;
106108
} else if (newLoaded !== prevLoaded) {
107109
csolutionChanged = true;
108110
}
@@ -169,10 +171,6 @@ export class ManageSolutionWebviewMain {
169171
return dirname(this.controller?.solutionPath ?? '');
170172
}
171173

172-
private getSolutionBasename(): string {
173-
return path.basename(this.controller?.solutionPath ?? '') || 'the solution';
174-
}
175-
176174
public attachToPanel(panel: vscode.WebviewPanel): void {
177175
this.webviewManager.attachPanel(panel);
178176
}
@@ -323,8 +321,8 @@ export class ManageSolutionWebviewMain {
323321
await this.updateDebuggerParameter('', 'start-pname', name);
324322
}
325323

326-
public async saveChanges(): Promise<void> {
327-
if (!this.isDirty) {
324+
public async saveChanges(force: boolean = false): Promise<void> {
325+
if (!this.isDirty && !force) {
328326
return;
329327
}
330328
await this.setBusyState(true);
@@ -347,31 +345,13 @@ export class ManageSolutionWebviewMain {
347345
});
348346
}
349347

350-
protected async querySaveModified(): Promise<void> {
351-
if (!this.isDirty) {
352-
return;
353-
}
354-
// for now only yes/no answers are supported, cancel can be only triggered externally when changing solution
355-
// todo: query all modifications from this and component views
356-
const result = await vscode.window.showWarningMessage(
357-
`Manage Solution: You have unsaved changes in ${this.getSolutionBasename()}. Do you want to save them?`,
358-
{ modal: true },
359-
'Yes',
360-
'No'
361-
);
362-
if (result === 'Yes') {
363-
await this.saveChanges();
364-
}
365-
}
366-
367348
/**
368349
* Loads csolution.ym file for editing
369350
* @returns true if solution file is successfully loaded
370351
*/
371352
protected async loadSolution(): Promise<ETextFileResult> {
372353
const globalSolution = this.solutionManager.getCsolution(); // get global csolution
373354
if (this.controller.solutionPath !== globalSolution?.solutionPath) {
374-
// await this.querySaveModified();
375355
this._controller = this.createController(); // todo: use clear instead
376356
}
377357
if (!globalSolution) { // no solution is loaded in workspace

0 commit comments

Comments
 (0)