mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
address some feedback
This commit is contained in:
@@ -13,21 +13,14 @@ import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { MainThreadWorkspaceShape, ExtHostWorkspaceShape, ExtHostContext, MainContext, IExtHostContext } from '../node/extHost.protocol';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
|
||||
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
|
||||
import { IMessageService, IConfirmation } from 'vs/platform/message/common/message';
|
||||
import { localize } from 'vs/nls';
|
||||
import { getPathLabel } from 'vs/base/common/labels';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { Extensions as ConfigurationExtensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
|
||||
|
||||
@extHostNamedCustomer(MainContext.MainThreadWorkspace)
|
||||
export class MainThreadWorkspace implements MainThreadWorkspaceShape {
|
||||
|
||||
private static CONFIRM_CHANGES_TO_WORKSPACES_KEY = 'workbench.confirmChangesToWorkspaceFromExtensions';
|
||||
|
||||
private readonly _toDispose: IDisposable[] = [];
|
||||
private readonly _activeSearches: { [id: number]: TPromise<URI[]> } = Object.create(null);
|
||||
private readonly _proxy: ExtHostWorkspaceShape;
|
||||
@@ -39,9 +32,7 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
|
||||
@ITextFileService private readonly _textFileService: ITextFileService,
|
||||
@IConfigurationService private _configurationService: IConfigurationService,
|
||||
@IWorkspaceEditingService private _workspaceEditingService: IWorkspaceEditingService,
|
||||
@IMessageService private _messageService: IMessageService,
|
||||
@IStatusbarService private _statusbarService: IStatusbarService,
|
||||
@IEnvironmentService private _environmentService: IEnvironmentService,
|
||||
@IStatusbarService private _statusbarService: IStatusbarService
|
||||
) {
|
||||
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostWorkspace);
|
||||
this._contextService.onDidChangeWorkspaceFolders(this._onDidChangeWorkspace, this, this._toDispose);
|
||||
@@ -59,7 +50,7 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
|
||||
|
||||
// --- workspace ---
|
||||
|
||||
$updateWorkspaceFolders(extensionName: string, index: number, deleteCount?: number, add?: { uri: UriComponents, name?: string }[]): Thenable<boolean> {
|
||||
$updateWorkspaceFolders(extensionName: string, index: number, deleteCount: number, ...add: { uri: UriComponents, name?: string }[]): Thenable<boolean> {
|
||||
let workspaceFoldersToAdd: { uri: URI, name?: string }[] = [];
|
||||
if (Array.isArray(add)) {
|
||||
workspaceFoldersToAdd = add.map(f => ({ uri: URI.revive(f.uri), name: f.name }));
|
||||
@@ -74,33 +65,10 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
|
||||
return TPromise.as(false); // return early if we neither have folders to add nor remove
|
||||
}
|
||||
|
||||
return this.confirmUpdateWorkspaceFolders(extensionName, workspaceFoldersToAdd.map(f => f.uri), workspaceFoldersToRemove).then(confirmed => {
|
||||
if (!confirmed) {
|
||||
return TPromise.as(false); // return if not confirmed by the user
|
||||
}
|
||||
// Indicate in status message
|
||||
this._statusbarService.setStatusMessage(this.getStatusMessage(extensionName, workspaceFoldersToAdd.map(f => f.uri), workspaceFoldersToRemove), 10 * 1000 /* 10s */);
|
||||
|
||||
return this._workspaceEditingService.updateFolders(index, deleteCount, workspaceFoldersToAdd, true).then(() => true);
|
||||
});
|
||||
}
|
||||
|
||||
private confirmUpdateWorkspaceFolders(extensionName: string, workspaceFoldersToAdd?: URI[], workspaceFoldersToRemove?: URI[]): Thenable<boolean> {
|
||||
if (!this._configurationService.getValue<boolean>(MainThreadWorkspace.CONFIRM_CHANGES_TO_WORKSPACES_KEY)) {
|
||||
|
||||
// Indicate in status message
|
||||
this._statusbarService.setStatusMessage(this.getStatusMessage(extensionName, workspaceFoldersToAdd, workspaceFoldersToRemove), 10 * 1000 /* 10s */);
|
||||
|
||||
// return confirmed if the setting indicates this
|
||||
return TPromise.as(true);
|
||||
}
|
||||
|
||||
return this._messageService.confirmWithCheckbox(this.getConfirmationOptions(extensionName, workspaceFoldersToAdd, workspaceFoldersToRemove)).then(confirmation => {
|
||||
let updateConfirmSettingsPromise: TPromise<void> = TPromise.as(void 0);
|
||||
if (confirmation.confirmed && confirmation.checkboxChecked === true) {
|
||||
updateConfirmSettingsPromise = this._configurationService.updateValue(MainThreadWorkspace.CONFIRM_CHANGES_TO_WORKSPACES_KEY, false, ConfigurationTarget.USER);
|
||||
}
|
||||
|
||||
return updateConfirmSettingsPromise.then(() => confirmation.confirmed);
|
||||
});
|
||||
return this._workspaceEditingService.updateFolders(index, deleteCount, workspaceFoldersToAdd, true).then(() => true);
|
||||
}
|
||||
|
||||
private getStatusMessage(extensionName, workspaceFoldersToAdd?: URI[], workspaceFoldersToRemove?: URI[]): string {
|
||||
@@ -135,71 +103,6 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
|
||||
return message;
|
||||
}
|
||||
|
||||
private getConfirmationOptions(extensionName, workspaceFoldersToAdd?: URI[], workspaceFoldersToRemove?: URI[]): IConfirmation {
|
||||
const wantsToDelete = Array.isArray(workspaceFoldersToRemove) && workspaceFoldersToRemove.length;
|
||||
const wantsToAdd = Array.isArray(workspaceFoldersToAdd) && workspaceFoldersToAdd.length;
|
||||
|
||||
let message: string;
|
||||
let detail: string;
|
||||
let primaryButton: string;
|
||||
|
||||
// Add Folders
|
||||
if (wantsToAdd && !wantsToDelete) {
|
||||
if (workspaceFoldersToAdd.length === 1) {
|
||||
message = localize('folderMessageAddSingleFolder', "Extension '{0}' wants to add a folder to the workspace. Please confirm.", extensionName);
|
||||
primaryButton = localize('addFolder', "&&Add Folder");
|
||||
} else {
|
||||
message = localize('folderMessageAddMultipleFolders', "Extension '{0}' wants to add {1} folders to the workspace. Please confirm.", extensionName, workspaceFoldersToAdd.length);
|
||||
primaryButton = localize('addFolders', "&&Add Folders");
|
||||
}
|
||||
|
||||
detail = this.getConfirmationDetail(workspaceFoldersToAdd, false);
|
||||
}
|
||||
|
||||
// Delete Folders
|
||||
else if (wantsToDelete && !wantsToAdd) {
|
||||
if (workspaceFoldersToRemove.length === 1) {
|
||||
message = localize('folderMessageRemoveSingleFolder', "Extension '{0}' wants to remove a folder from the workspace. Please confirm.", extensionName);
|
||||
primaryButton = localize('removeFolder', "&&Remove Folder");
|
||||
} else {
|
||||
message = localize('folderMessageRemoveMultipleFolders', "Extension '{0}' wants to remove {1} folders from the workspace. Please confirm.", extensionName, workspaceFoldersToRemove.length);
|
||||
primaryButton = localize('removeFolders', "&&Remove Folders");
|
||||
}
|
||||
|
||||
detail = this.getConfirmationDetail(workspaceFoldersToRemove, true);
|
||||
}
|
||||
|
||||
// Change Folders
|
||||
else {
|
||||
message = localize('folderChangeFolder', "Extension '{0}' wants to change the folders of the workspace. Please confirm.", extensionName);
|
||||
primaryButton = localize('changeFolders', "&&Change Folders");
|
||||
|
||||
detail = [this.getConfirmationDetail(workspaceFoldersToAdd, false), this.getConfirmationDetail(workspaceFoldersToRemove, true)].join('\n\n');
|
||||
}
|
||||
|
||||
return { message, detail, type: 'question', primaryButton, checkbox: { label: localize('doNotAskAgain', "Do not ask me again") } };
|
||||
}
|
||||
|
||||
private getConfirmationDetail(folders: URI[], isRemove: boolean): string {
|
||||
const getFolderName = uri => {
|
||||
return uri.scheme === 'file' ? getPathLabel(uri.fsPath, null, this._environmentService) : uri.toString();
|
||||
};
|
||||
|
||||
if (folders.length === 1) {
|
||||
if (isRemove) {
|
||||
return [localize('folderToRemove', "Folder to remove:"), ...folders.map(f => getFolderName(f))].join('\n');
|
||||
}
|
||||
|
||||
return [localize('folderToAdd', "Folder to add:"), ...folders.map(f => getFolderName(f))].join('\n');
|
||||
}
|
||||
|
||||
if (isRemove) {
|
||||
return [localize('foldersToRemove', "Folders to remove:"), ...folders.map(f => getFolderName(f))].join('\n');
|
||||
}
|
||||
|
||||
return [localize('foldersToAdd', "Folders to add:"), ...folders.map(f => getFolderName(f))].join('\n');
|
||||
}
|
||||
|
||||
private _onDidChangeWorkspace(): void {
|
||||
this._proxy.$acceptWorkspaceData(this._contextService.getWorkbenchState() === WorkbenchState.EMPTY ? null : this._contextService.getWorkspace());
|
||||
}
|
||||
@@ -277,20 +180,4 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
|
||||
return result.results.every(each => each.success === true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
|
||||
|
||||
configurationRegistry.registerConfiguration({
|
||||
'id': 'workbench',
|
||||
'order': 7,
|
||||
'title': localize('workbenchConfigurationTitle', "Workbench"),
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'workbench.confirmChangesToWorkspaceFromExtensions': {
|
||||
'type': 'boolean',
|
||||
'description': localize('confirmChangesFromExtensions', "Controls if a confirmation should be shown for extensions that add or remove workspace folders."),
|
||||
'default': true
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user