mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-15 02:48:30 -05:00
This reverts commit d15a3fcc98.
This commit is contained in:
@@ -67,81 +67,74 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
|
||||
|
||||
}
|
||||
|
||||
private async saveUntitedBeforeShutdown(reason: ShutdownReason): Promise<boolean> {
|
||||
private saveUntitedBeforeShutdown(reason: ShutdownReason): Promise<boolean> | undefined {
|
||||
if (reason !== ShutdownReason.LOAD && reason !== ShutdownReason.CLOSE) {
|
||||
return false; // only interested when window is closing or loading
|
||||
return undefined; // only interested when window is closing or loading
|
||||
}
|
||||
|
||||
const workspaceIdentifier = this.getCurrentWorkspaceIdentifier();
|
||||
if (!workspaceIdentifier || !isEqualOrParent(workspaceIdentifier.configPath, this.environmentService.untitledWorkspacesHome)) {
|
||||
return false; // only care about untitled workspaces to ask for saving
|
||||
return undefined; // only care about untitled workspaces to ask for saving
|
||||
}
|
||||
|
||||
const windowCount = await this.windowsService.getWindowCount();
|
||||
|
||||
if (reason === ShutdownReason.CLOSE && !isMacintosh && windowCount === 1) {
|
||||
return false; // Windows/Linux: quits when last window is closed, so do not ask then
|
||||
}
|
||||
|
||||
enum ConfirmResult {
|
||||
SAVE,
|
||||
DONT_SAVE,
|
||||
CANCEL
|
||||
}
|
||||
|
||||
const save = { label: mnemonicButtonLabel(nls.localize('save', "Save")), result: ConfirmResult.SAVE };
|
||||
const dontSave = { label: mnemonicButtonLabel(nls.localize('doNotSave', "Don't Save")), result: ConfirmResult.DONT_SAVE };
|
||||
const cancel = { label: nls.localize('cancel', "Cancel"), result: ConfirmResult.CANCEL };
|
||||
|
||||
const buttons: { label: string; result: ConfirmResult; }[] = [];
|
||||
if (isWindows) {
|
||||
buttons.push(save, dontSave, cancel);
|
||||
} else if (isLinux) {
|
||||
buttons.push(dontSave, cancel, save);
|
||||
} else {
|
||||
buttons.push(save, cancel, dontSave);
|
||||
}
|
||||
|
||||
const message = nls.localize('saveWorkspaceMessage', "Do you want to save your workspace configuration as a file?");
|
||||
const detail = nls.localize('saveWorkspaceDetail', "Save your workspace if you plan to open it again.");
|
||||
const cancelId = buttons.indexOf(cancel);
|
||||
|
||||
const res = await this.dialogService.show(Severity.Warning, message, buttons.map(button => button.label), { detail, cancelId });
|
||||
|
||||
switch (buttons[res].result) {
|
||||
|
||||
// Cancel: veto unload
|
||||
case ConfirmResult.CANCEL:
|
||||
return true;
|
||||
|
||||
// Don't Save: delete workspace
|
||||
case ConfirmResult.DONT_SAVE:
|
||||
this.workspaceService.deleteUntitledWorkspace(workspaceIdentifier);
|
||||
return false;
|
||||
|
||||
// Save: save workspace, but do not veto unload if path provided
|
||||
case ConfirmResult.SAVE: {
|
||||
const newWorkspacePath = await this.pickNewWorkspacePath();
|
||||
if (!newWorkspacePath) {
|
||||
return true; // keep veto if no target was provided
|
||||
}
|
||||
|
||||
try {
|
||||
await this.saveWorkspaceAs(workspaceIdentifier, newWorkspacePath);
|
||||
|
||||
const newWorkspaceIdentifier = await this.workspaceService.getWorkspaceIdentifier(newWorkspacePath);
|
||||
|
||||
const label = this.labelService.getWorkspaceLabel(newWorkspaceIdentifier, { verbose: true });
|
||||
this.windowsService.addRecentlyOpened([{ label, workspace: newWorkspaceIdentifier }]);
|
||||
|
||||
this.workspaceService.deleteUntitledWorkspace(workspaceIdentifier);
|
||||
} catch (error) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return false;
|
||||
return this.windowsService.getWindowCount().then(windowCount => {
|
||||
if (reason === ShutdownReason.CLOSE && !isMacintosh && windowCount === 1) {
|
||||
return false; // Windows/Linux: quits when last window is closed, so do not ask then
|
||||
}
|
||||
}
|
||||
enum ConfirmResult {
|
||||
SAVE,
|
||||
DONT_SAVE,
|
||||
CANCEL
|
||||
}
|
||||
|
||||
const save = { label: mnemonicButtonLabel(nls.localize('save', "Save")), result: ConfirmResult.SAVE };
|
||||
const dontSave = { label: mnemonicButtonLabel(nls.localize('doNotSave', "Don't Save")), result: ConfirmResult.DONT_SAVE };
|
||||
const cancel = { label: nls.localize('cancel', "Cancel"), result: ConfirmResult.CANCEL };
|
||||
|
||||
const buttons: { label: string; result: ConfirmResult; }[] = [];
|
||||
if (isWindows) {
|
||||
buttons.push(save, dontSave, cancel);
|
||||
} else if (isLinux) {
|
||||
buttons.push(dontSave, cancel, save);
|
||||
} else {
|
||||
buttons.push(save, cancel, dontSave);
|
||||
}
|
||||
|
||||
const message = nls.localize('saveWorkspaceMessage', "Do you want to save your workspace configuration as a file?");
|
||||
const detail = nls.localize('saveWorkspaceDetail', "Save your workspace if you plan to open it again.");
|
||||
const cancelId = buttons.indexOf(cancel);
|
||||
|
||||
return this.dialogService.show(Severity.Warning, message, buttons.map(button => button.label), { detail, cancelId }).then(res => {
|
||||
switch (buttons[res].result) {
|
||||
|
||||
// Cancel: veto unload
|
||||
case ConfirmResult.CANCEL:
|
||||
return true;
|
||||
|
||||
// Don't Save: delete workspace
|
||||
case ConfirmResult.DONT_SAVE:
|
||||
this.workspaceService.deleteUntitledWorkspace(workspaceIdentifier);
|
||||
return false;
|
||||
|
||||
// Save: save workspace, but do not veto unload
|
||||
case ConfirmResult.SAVE: {
|
||||
return this.pickNewWorkspacePath().then(newWorkspacePath => {
|
||||
if (newWorkspacePath) {
|
||||
return this.saveWorkspaceAs(workspaceIdentifier, newWorkspacePath).then(_ => {
|
||||
return this.workspaceService.getWorkspaceIdentifier(newWorkspacePath).then(newWorkspaceIdentifier => {
|
||||
const label = this.labelService.getWorkspaceLabel(newWorkspaceIdentifier, { verbose: true });
|
||||
this.windowsService.addRecentlyOpened([{ label, workspace: newWorkspaceIdentifier }]);
|
||||
this.workspaceService.deleteUntitledWorkspace(workspaceIdentifier);
|
||||
return false;
|
||||
});
|
||||
}, () => false);
|
||||
}
|
||||
return true; // keep veto if no target was provided
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pickNewWorkspacePath(): Promise<URI | undefined> {
|
||||
@@ -225,7 +218,7 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
|
||||
newWorkspaceFolders = distinct(newWorkspaceFolders, folder => getComparisonKey(folder.uri));
|
||||
|
||||
if (state === WorkbenchState.EMPTY && newWorkspaceFolders.length === 0 || state === WorkbenchState.FOLDER && newWorkspaceFolders.length === 1) {
|
||||
return; // return if the operation is a no-op for the current state
|
||||
return Promise.resolve(); // return if the operation is a no-op for the current state
|
||||
}
|
||||
|
||||
return this.createAndEnterWorkspace(newWorkspaceFolders);
|
||||
@@ -274,7 +267,7 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
|
||||
|
||||
async createAndEnterWorkspace(folders: IWorkspaceFolderCreationData[], path?: URI): Promise<void> {
|
||||
if (path && !await this.isValidTargetWorkspacePath(path)) {
|
||||
return;
|
||||
return Promise.reject(null);
|
||||
}
|
||||
const remoteAuthority = this.environmentService.configuration.remoteAuthority;
|
||||
const untitledWorkspace = await this.workspaceService.createUntitledWorkspace(folders, remoteAuthority);
|
||||
@@ -288,11 +281,11 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
|
||||
|
||||
async saveAndEnterWorkspace(path: URI): Promise<void> {
|
||||
if (!await this.isValidTargetWorkspacePath(path)) {
|
||||
return;
|
||||
return Promise.reject(null);
|
||||
}
|
||||
const workspaceIdentifier = this.getCurrentWorkspaceIdentifier();
|
||||
if (!workspaceIdentifier) {
|
||||
return;
|
||||
return Promise.reject(null);
|
||||
}
|
||||
await this.saveWorkspaceAs(workspaceIdentifier, path);
|
||||
|
||||
@@ -325,7 +318,7 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
|
||||
|
||||
// Return early if target is same as source
|
||||
if (isEqual(configPathURI, targetConfigPathURI)) {
|
||||
return;
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
// Read the contents of the workspace file, update it to new location and save it.
|
||||
@@ -334,17 +327,18 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
|
||||
await this.textFileService.create(targetConfigPathURI, newRawWorkspaceContents, { overwrite: true });
|
||||
}
|
||||
|
||||
private handleWorkspaceConfigurationEditingError(error: JSONEditingError): void {
|
||||
private handleWorkspaceConfigurationEditingError(error: JSONEditingError): Promise<void> {
|
||||
switch (error.code) {
|
||||
case JSONEditingErrorCode.ERROR_INVALID_FILE:
|
||||
this.onInvalidWorkspaceConfigurationFileError();
|
||||
break;
|
||||
return Promise.resolve();
|
||||
case JSONEditingErrorCode.ERROR_FILE_DIRTY:
|
||||
this.onWorkspaceConfigurationFileDirtyError();
|
||||
break;
|
||||
default:
|
||||
this.notificationService.error(error.message);
|
||||
return Promise.resolve();
|
||||
}
|
||||
this.notificationService.error(error.message);
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
private onInvalidWorkspaceConfigurationFileError(): void {
|
||||
@@ -368,7 +362,7 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
|
||||
|
||||
async enterWorkspace(path: URI): Promise<void> {
|
||||
if (!!this.environmentService.extensionTestsLocationURI) {
|
||||
throw new Error('Entering a new workspace is not possible in tests.');
|
||||
return Promise.reject(new Error('Entering a new workspace is not possible in tests.'));
|
||||
}
|
||||
|
||||
const workspace = await this.workspaceService.getWorkspaceIdentifier(path);
|
||||
|
||||
Reference in New Issue
Block a user