mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 09:35:40 -05:00
Refresh master with initial release/0.24 snapshot (#332)
* Initial port of release/0.24 source code * Fix additional headers * Fix a typo in launch.json
This commit is contained in:
@@ -6,9 +6,9 @@
|
||||
'use strict';
|
||||
|
||||
import * as data from 'data';
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {IThreadService} from 'vs/workbench/services/thread/common/threadService';
|
||||
import {Disposable} from 'vs/workbench/api/node/extHostTypes';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { Disposable } from 'vs/workbench/api/node/extHostTypes';
|
||||
import {
|
||||
ExtHostAccountManagementShape,
|
||||
MainThreadAccountManagementShape,
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
export class ExtHostAccountManagement extends ExtHostAccountManagementShape {
|
||||
private _handlePool: number = 0;
|
||||
private _proxy: MainThreadAccountManagementShape;
|
||||
private _providers: {[handle: number]: AccountProviderWithMetadata} = {};
|
||||
private _providers: { [handle: number]: AccountProviderWithMetadata } = {};
|
||||
|
||||
constructor(threadService: IThreadService) {
|
||||
super();
|
||||
@@ -47,9 +47,21 @@ export class ExtHostAccountManagement extends ExtHostAccountManagementShape {
|
||||
return this._withProvider(handle, (provider: data.AccountProvider) => provider.refresh(account));
|
||||
}
|
||||
|
||||
public $autoOAuthCancelled(handle: number): Thenable<void> {
|
||||
return this._withProvider(handle, (provider: data.AccountProvider) => provider.autoOAuthCancelled());
|
||||
}
|
||||
|
||||
// - EXTENSION HOST AVAILABLE METHODS //////////////////////////////////
|
||||
public $performOAuthAuthorization(url: string, silent: boolean): Thenable<string> {
|
||||
return this._proxy.$performOAuthAuthorization(url, silent);
|
||||
public $beginAutoOAuthDeviceCode(providerId: string, title: string, message: string, userCode: string, uri: string): Thenable<void> {
|
||||
return this._proxy.$beginAutoOAuthDeviceCode(providerId, title, message, userCode, uri);
|
||||
}
|
||||
|
||||
public $endAutoOAuthDeviceCode(): void {
|
||||
this._proxy.$endAutoOAuthDeviceCode();
|
||||
}
|
||||
|
||||
public $accountUpdated(updatedAccount: data.Account): void {
|
||||
this._proxy.$accountUpdated(updatedAccount);
|
||||
}
|
||||
|
||||
public $registerAccountProvider(providerMetadata: data.AccountProviderMetadata, provider: data.AccountProvider): Disposable {
|
||||
|
||||
@@ -339,37 +339,10 @@ export class ExtHostDataProtocol extends ExtHostDataProtocolShape {
|
||||
}
|
||||
|
||||
// Scripting handlers
|
||||
public $scriptAsSelect(handle: number, connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> {
|
||||
return this._runWithProvider(handle, provider => {
|
||||
return provider.scriptingProvider ? provider.scriptingProvider.scriptAsSelect(connectionUri, metadata, paramDetails)
|
||||
: Promise.resolve(undefined);
|
||||
});
|
||||
}
|
||||
|
||||
public $scriptAsCreate(handle: number, connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> {
|
||||
public $scriptAsOperation(handle: number, connectionUri: string, operation: data.ScriptOperation, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> {
|
||||
return this._runWithProvider(handle, provider => {
|
||||
return provider.scriptingProvider ? provider.scriptingProvider.scriptAsCreate(connectionUri, metadata, paramDetails)
|
||||
: Promise.resolve(undefined);
|
||||
});
|
||||
}
|
||||
|
||||
public $scriptAsUpdate(handle: number, connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> {
|
||||
return this._runWithProvider(handle, provider => {
|
||||
return provider.scriptingProvider ? provider.scriptingProvider.scriptAsUpdate(connectionUri, metadata, paramDetails)
|
||||
: Promise.resolve(undefined);
|
||||
});
|
||||
}
|
||||
|
||||
public $scriptAsInsert(handle: number, connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> {
|
||||
return this._runWithProvider(handle, provider => {
|
||||
return provider.scriptingProvider ? provider.scriptingProvider.scriptAsInsert(connectionUri, metadata, paramDetails)
|
||||
: Promise.resolve(undefined);
|
||||
});
|
||||
}
|
||||
|
||||
public $scriptAsDelete(handle: number, connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> {
|
||||
return this._runWithProvider(handle, provider => {
|
||||
return provider.scriptingProvider ? provider.scriptingProvider.scriptAsDelete(connectionUri, metadata, paramDetails)
|
||||
return provider.scriptingProvider ? provider.scriptingProvider.scriptAsOperation(connectionUri, operation, metadata, paramDetails)
|
||||
: Promise.resolve(undefined);
|
||||
});
|
||||
}
|
||||
@@ -538,4 +511,35 @@ export class ExtHostDataProtocol extends ExtHostDataProtocolShape {
|
||||
: Promise.resolve(undefined);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Profiler Provider methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Start a profiler session
|
||||
*/
|
||||
public $startSession(handle: number, sessionId: string): Thenable<boolean> {
|
||||
return this._runWithProvider(handle, provider => {
|
||||
return provider.profilerProvider ? provider.profilerProvider.startSession(sessionId)
|
||||
: Promise.resolve(undefined);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop a profiler session
|
||||
*/
|
||||
public $stopSession(handle: number, sessionId: string): Thenable<boolean> {
|
||||
return this._runWithProvider(handle, provider => {
|
||||
return provider.profilerProvider ? provider.profilerProvider.stopSession(sessionId)
|
||||
: Promise.resolve(undefined);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Profiler session events available notification
|
||||
*/
|
||||
public $onSessionEventsAvailable(handle: number, response: data.ProfilerSessionEvents): void {
|
||||
this._proxy.$onSessionEventsAvailable(handle, response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
'use strict';
|
||||
|
||||
import * as data from 'data';
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {IAccountManagementService} from 'sql/services/accountManagement/interfaces';
|
||||
import {dispose, IDisposable} from 'vs/base/common/lifecycle';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IAccountManagementService } from 'sql/services/accountManagement/interfaces';
|
||||
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import {
|
||||
ExtHostAccountManagementShape,
|
||||
MainThreadAccountManagementShape,
|
||||
@@ -20,7 +20,7 @@ import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostC
|
||||
|
||||
@extHostNamedCustomer(SqlMainContext.MainThreadAccountManagement)
|
||||
export class MainThreadAccountManagement extends MainThreadAccountManagementShape {
|
||||
private _providerMetadata: {[handle: number]: data.AccountProviderMetadata};
|
||||
private _providerMetadata: { [handle: number]: data.AccountProviderMetadata };
|
||||
private _proxy: ExtHostAccountManagementShape;
|
||||
private _toDispose: IDisposable[];
|
||||
|
||||
@@ -36,8 +36,16 @@ export class MainThreadAccountManagement extends MainThreadAccountManagementShap
|
||||
this._toDispose = [];
|
||||
}
|
||||
|
||||
public $performOAuthAuthorization(url, silent: boolean): Thenable<string> {
|
||||
return this._accountManagementService.performOAuthAuthorization(url, silent);
|
||||
public $beginAutoOAuthDeviceCode(providerId: string, title: string, message: string, userCode: string, uri: string): Thenable<void> {
|
||||
return this._accountManagementService.beginAutoOAuthDeviceCode(providerId, title, message, userCode, uri);
|
||||
}
|
||||
|
||||
public $endAutoOAuthDeviceCode(): void {
|
||||
return this._accountManagementService.endAutoOAuthDeviceCode();
|
||||
}
|
||||
|
||||
$accountUpdated(updatedAccount: data.Account): void {
|
||||
this._accountManagementService.accountUpdated(updatedAccount);
|
||||
}
|
||||
|
||||
public $registerAccountProvider(providerMetadata: data.AccountProviderMetadata, handle: number): Thenable<any> {
|
||||
@@ -45,6 +53,9 @@ export class MainThreadAccountManagement extends MainThreadAccountManagementShap
|
||||
|
||||
// Create the account provider that interfaces with the extension via the proxy and register it
|
||||
let accountProvider: data.AccountProvider = {
|
||||
autoOAuthCancelled(): Thenable<void> {
|
||||
return self._proxy.$autoOAuthCancelled(handle);
|
||||
},
|
||||
clear(accountKey: data.AccountKey): Thenable<void> {
|
||||
return self._proxy.$clear(handle, accountKey);
|
||||
},
|
||||
|
||||
@@ -201,20 +201,8 @@ export class MainThreadDataProtocol extends MainThreadDataProtocolShape {
|
||||
});
|
||||
|
||||
this._scriptingService.registerProvider(providerId, <data.ScriptingProvider>{
|
||||
scriptAsSelect(connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> {
|
||||
return self._proxy.$scriptAsSelect(handle, connectionUri, metadata, paramDetails);
|
||||
},
|
||||
scriptAsCreate(connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> {
|
||||
return self._proxy.$scriptAsCreate(handle, connectionUri, metadata, paramDetails);
|
||||
},
|
||||
scriptAsInsert(connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> {
|
||||
return self._proxy.$scriptAsInsert(handle, connectionUri, metadata, paramDetails);
|
||||
},
|
||||
scriptAsUpdate(connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> {
|
||||
return self._proxy.$scriptAsUpdate(handle, connectionUri, metadata, paramDetails);
|
||||
},
|
||||
scriptAsDelete(connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> {
|
||||
return self._proxy.$scriptAsDelete(handle, connectionUri, metadata, paramDetails);
|
||||
scriptAsOperation(connectionUri: string, operation: data.ScriptOperation, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> {
|
||||
return self._proxy.$scriptAsOperation(handle, connectionUri, operation, metadata, paramDetails);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -269,6 +257,24 @@ export class MainThreadDataProtocol extends MainThreadDataProtocolShape {
|
||||
}
|
||||
});
|
||||
|
||||
this._profilerService.registerProvider(providerId, <data.ProfilerProvider>{
|
||||
startSession(sessionId: string): Thenable<boolean> {
|
||||
return self._proxy.$startSession(handle, sessionId);
|
||||
},
|
||||
stopSession(sessionId: string): Thenable<boolean> {
|
||||
return self._proxy.$stopSession(handle, sessionId);
|
||||
},
|
||||
pauseSession(sessionId: string): Thenable<boolean> {
|
||||
return TPromise.as(true);
|
||||
},
|
||||
connectSession(sessionId: string): Thenable<boolean> {
|
||||
return TPromise.as(true);
|
||||
},
|
||||
disconnectSession(sessionId: string): Thenable<boolean> {
|
||||
return TPromise.as(true);
|
||||
}
|
||||
});
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -341,6 +347,14 @@ export class MainThreadDataProtocol extends MainThreadDataProtocolShape {
|
||||
this._fileBrowserService.onFilePathsValidated(handle, response);
|
||||
}
|
||||
|
||||
// Profiler handlers
|
||||
public $onSessionEventsAvailable(handle: number, response: data.ProfilerSessionEvents): void {
|
||||
|
||||
this._profilerService.onMoreRows(response);
|
||||
//this._profilerService.onMoreRows
|
||||
//this._taskService.onNewTaskCreated(handle, taskInfo);
|
||||
}
|
||||
|
||||
public $unregisterProvider(handle: number): TPromise<any> {
|
||||
let capabilitiesRegistration = this._capabilitiesRegistrations[handle];
|
||||
if (capabilitiesRegistration) {
|
||||
@@ -350,4 +364,6 @@ export class MainThreadDataProtocol extends MainThreadDataProtocolShape {
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
'use strict';
|
||||
|
||||
import * as extHostApi from 'vs/workbench/api/node/extHost.api.impl';
|
||||
import { TrieMap } from 'vs/base/common/map';
|
||||
import { TrieMap } from 'sql/base/common/map';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IInitData } from 'vs/workbench/api/node/extHost.protocol';
|
||||
import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService';
|
||||
@@ -23,6 +23,8 @@ import { ExtHostSerializationProvider } from 'sql/workbench/api/node/extHostSeri
|
||||
import { ExtHostResourceProvider } from 'sql/workbench/api/node/extHostResourceProvider';
|
||||
import { ExtHostThreadService } from 'vs/workbench/services/thread/node/extHostThreadService';
|
||||
import * as sqlExtHostTypes from 'sql/workbench/api/node/sqlExtHostTypes';
|
||||
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
|
||||
import { ExtHostConfiguration } from 'vs/workbench/api/node/extHostConfiguration';
|
||||
|
||||
export interface ISqlExtensionApiFactory {
|
||||
vsCodeFactory(extension: IExtensionDescription): typeof vscode;
|
||||
@@ -35,9 +37,13 @@ export interface ISqlExtensionApiFactory {
|
||||
export function createApiFactory(
|
||||
initData: IInitData,
|
||||
threadService: ExtHostThreadService,
|
||||
extHostWorkspace: ExtHostWorkspace,
|
||||
extHostConfiguration: ExtHostConfiguration,
|
||||
extensionService: ExtHostExtensionService
|
||||
|
||||
|
||||
): ISqlExtensionApiFactory {
|
||||
let vsCodeFactory = extHostApi.createApiFactory(initData, threadService, extensionService);
|
||||
let vsCodeFactory = extHostApi.createApiFactory(initData, threadService, extHostWorkspace, extHostConfiguration, extensionService);
|
||||
|
||||
// Addressable instances
|
||||
const extHostAccountManagement = threadService.set(SqlExtHostContext.ExtHostAccountManagement, new ExtHostAccountManagement(threadService));
|
||||
@@ -51,12 +57,18 @@ export function createApiFactory(
|
||||
dataFactory: function (extension: IExtensionDescription): typeof data {
|
||||
// namespace: accounts
|
||||
const accounts: typeof data.accounts = {
|
||||
performOAuthAuthorization(url: string, silent: boolean): Thenable<string> {
|
||||
return extHostAccountManagement.$performOAuthAuthorization(url, silent);
|
||||
},
|
||||
registerAccountProvider(providerMetadata: data.AccountProviderMetadata, provider: data.AccountProvider): vscode.Disposable {
|
||||
return extHostAccountManagement.$registerAccountProvider(providerMetadata, provider);
|
||||
},
|
||||
beginAutoOAuthDeviceCode(providerId: string, title: string, message: string, userCode: string, uri: string): Thenable<void> {
|
||||
return extHostAccountManagement.$beginAutoOAuthDeviceCode(providerId, title, message, userCode, uri);
|
||||
},
|
||||
endAutoOAuthDeviceCode(): void {
|
||||
return extHostAccountManagement.$endAutoOAuthDeviceCode();
|
||||
},
|
||||
accountUpdated(updatedAccount: data.Account): void {
|
||||
return extHostAccountManagement.$accountUpdated(updatedAccount);
|
||||
}
|
||||
};
|
||||
|
||||
// namespace: credentials
|
||||
@@ -161,6 +173,11 @@ export function createApiFactory(
|
||||
extHostDataProvider.$onScriptingComplete(provider.handle, response);
|
||||
});
|
||||
|
||||
// Profiler callbacks
|
||||
provider.profilerProvider.registerOnSessionEventsAvailable((response: data.ProfilerSessionEvents) => {
|
||||
extHostDataProvider.$onSessionEventsAvailable(provider.handle, response);
|
||||
});
|
||||
|
||||
// Complete registration
|
||||
return extHostDataProvider.$registerProvider(provider);
|
||||
},
|
||||
@@ -180,7 +197,8 @@ export function createApiFactory(
|
||||
EditRowState: sqlExtHostTypes.EditRowState,
|
||||
MetadataType: sqlExtHostTypes.MetadataType,
|
||||
TaskStatus: sqlExtHostTypes.TaskStatus,
|
||||
TaskExecutionMode: sqlExtHostTypes.TaskExecutionMode
|
||||
TaskExecutionMode: sqlExtHostTypes.TaskExecutionMode,
|
||||
ScriptOperation: sqlExtHostTypes.ScriptOperation
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,6 +15,7 @@ import * as data from 'data';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
|
||||
export abstract class ExtHostAccountManagementShape {
|
||||
$autoOAuthCancelled(handle: number): Thenable<void> { throw ni(); }
|
||||
$clear(handle: number, accountKey: data.AccountKey): Thenable<void> { throw ni(); }
|
||||
$getSecurityToken(handle: number, account: data.Account): Thenable<{}> { throw ni(); }
|
||||
$initialize(handle: number, restoredAccounts: data.Account[]): Thenable<data.Account[]> { throw ni(); }
|
||||
@@ -103,11 +104,7 @@ export abstract class ExtHostDataProtocolShape {
|
||||
/**
|
||||
* Scripting methods
|
||||
*/
|
||||
$scriptAsSelect(handle: number, connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> { throw ni(); }
|
||||
$scriptAsCreate(handle: number, connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> { throw ni(); }
|
||||
$scriptAsUpdate(handle: number, connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> { throw ni(); }
|
||||
$scriptAsInsert(handle: number, connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> { throw ni(); }
|
||||
$scriptAsDelete(handle: number, connectionUri: string, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> { throw ni(); }
|
||||
$scriptAsOperation(handle: number, connectionUri: string, operation: data.ScriptOperation, metadata: data.ObjectMetadata, paramDetails: data.ScriptingParamDetails): Thenable<data.ScriptingResult> { throw ni(); }
|
||||
|
||||
/**
|
||||
* Cancels the currently running query for a URI
|
||||
@@ -288,6 +285,20 @@ export abstract class ExtHostDataProtocolShape {
|
||||
* Close file browser
|
||||
*/
|
||||
$closeFileBrowser(handle: number, ownerUri: string): Thenable<data.FileBrowserCloseResponse> { throw ni(); }
|
||||
|
||||
/**
|
||||
* Profiler Provider methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Start a profiler session
|
||||
*/
|
||||
$startSession(handle: number, sessionId: string): Thenable<boolean> { throw ni(); }
|
||||
|
||||
/**
|
||||
* Stop a profiler session
|
||||
*/
|
||||
$stopSession(handle: number, sessionId: string): Thenable<boolean> { throw ni(); }
|
||||
}
|
||||
|
||||
|
||||
@@ -329,7 +340,10 @@ export abstract class MainThreadAccountManagementShape {
|
||||
$registerAccountProvider(providerMetadata: data.AccountProviderMetadata, handle: number): Thenable<any> { throw ni(); }
|
||||
$unregisterAccountProvider(handle: number): Thenable<any> { throw ni(); }
|
||||
|
||||
$performOAuthAuthorization(url: string, silent: boolean): Thenable<string> { throw ni(); }
|
||||
$beginAutoOAuthDeviceCode(providerId: string, title: string, message: string, userCode: string, uri: string): Thenable<void> { throw ni(); }
|
||||
$endAutoOAuthDeviceCode(): void { throw ni(); }
|
||||
|
||||
$accountUpdated(updatedAccount: data.Account): void { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class MainThreadResourceProviderShape {
|
||||
@@ -356,6 +370,7 @@ export abstract class MainThreadDataProtocolShape {
|
||||
$onFolderNodeExpanded(handle: number, response: data.FileBrowserExpandedParams): void { throw ni(); }
|
||||
$onFilePathsValidated(handle: number, response: data.FileBrowserValidatedParams): void { throw ni(); }
|
||||
$onScriptingComplete(handle: number, message: data.ScriptingCompleteResult): void { throw ni(); }
|
||||
$onSessionEventsAvailable(handle: number, response: data.ProfilerSessionEvents): void { throw ni(); }
|
||||
|
||||
/**
|
||||
* Callback when a session has completed initialization
|
||||
|
||||
@@ -60,5 +60,7 @@ export enum ScriptOperation {
|
||||
Create = 1,
|
||||
Insert = 2,
|
||||
Update = 3,
|
||||
Delete = 4
|
||||
Delete = 4,
|
||||
Execute = 5,
|
||||
Alter = 6
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import * as nls from 'vs/nls';
|
||||
|
||||
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
|
||||
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
|
||||
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
|
||||
import { ShowCurrentReleaseNotesAction, ProductContribution } from 'sql/workbench/update/releaseNotes';
|
||||
|
||||
@@ -41,6 +41,7 @@ const configureDashboardSchema: IJSONSchema = {
|
||||
registerTask('backup', '', backupSchema, Actions.BackupAction);
|
||||
registerTask('restore', '', restoreSchema, Actions.RestoreAction);
|
||||
registerTask('new-query', '', newQuerySchema, Actions.NewQueryAction);
|
||||
|
||||
registerTask('configure-dashboard', '', configureDashboardSchema, Actions.ConfigureDashboardAction);
|
||||
|
||||
// add product update and release notes contributions
|
||||
|
||||
@@ -7,7 +7,6 @@ import { IConnectionManagementService, IErrorMessageService } from 'sql/parts/co
|
||||
import * as TaskUtilities from './taskUtilities';
|
||||
import { IQueryEditorService } from 'sql/parts/query/common/queryEditorService';
|
||||
import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
|
||||
import { ConnectionManagementInfo } from 'sql/parts/connection/common/connectionManagementInfo';
|
||||
import { IInsightsConfig } from 'sql/parts/dashboard/widgets/insights/interfaces';
|
||||
import { IScriptingService } from 'sql/services/scripting/scriptingService';
|
||||
import { IDisasterRecoveryUiService, IRestoreDialogController } from 'sql/parts/disasterRecovery/common/interfaces';
|
||||
@@ -17,6 +16,7 @@ import { IAdminService } from 'sql/parts/admin/common/adminService';
|
||||
import * as Constants from 'sql/common/constants';
|
||||
import { ObjectMetadata } from 'data';
|
||||
import { ScriptOperation } from 'sql/workbench/common/taskUtilities';
|
||||
import { TaskAction } from 'sql/platform/tasks/taskRegistry';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
@@ -24,30 +24,19 @@ import { IWindowsService } from 'vs/platform/windows/common/windows';
|
||||
|
||||
import * as nls from 'vs/nls';
|
||||
|
||||
export class TaskAction extends Action {
|
||||
constructor(id: string, label: string, private _icon: string) {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
get icon(): string {
|
||||
return this._icon;
|
||||
}
|
||||
}
|
||||
|
||||
export interface BaseActionContext extends ITaskActionContext {
|
||||
uri?: string;
|
||||
export interface BaseActionContext {
|
||||
object?: ObjectMetadata;
|
||||
connInfo?: ConnectionManagementInfo;
|
||||
}
|
||||
|
||||
export interface ITaskActionContext {
|
||||
profile: IConnectionProfile;
|
||||
profile?: IConnectionProfile;
|
||||
}
|
||||
|
||||
export interface InsightActionContext extends BaseActionContext {
|
||||
insight: IInsightsConfig;
|
||||
}
|
||||
|
||||
export interface ManageActionContext extends BaseActionContext {
|
||||
uri: string;
|
||||
}
|
||||
|
||||
// --- actions
|
||||
export class NewQueryAction extends TaskAction {
|
||||
public static ID = 'newQuery';
|
||||
@@ -62,7 +51,7 @@ export class NewQueryAction extends TaskAction {
|
||||
super(id, label, icon);
|
||||
}
|
||||
|
||||
public run(actionContext: ITaskActionContext): TPromise<boolean> {
|
||||
public run(actionContext: BaseActionContext): TPromise<boolean> {
|
||||
return new TPromise<boolean>((resolve, reject) => {
|
||||
TaskUtilities.newQuery(
|
||||
actionContext.profile,
|
||||
@@ -98,7 +87,6 @@ export class ScriptSelectAction extends Action {
|
||||
TaskUtilities.scriptSelect(
|
||||
actionContext.profile,
|
||||
actionContext.object,
|
||||
actionContext.uri,
|
||||
this._connectionManagementService,
|
||||
this._queryEditorService,
|
||||
this._scriptingService
|
||||
@@ -113,6 +101,78 @@ export class ScriptSelectAction extends Action {
|
||||
}
|
||||
}
|
||||
|
||||
export class ScriptExecuteAction extends Action {
|
||||
public static ID = 'scriptExecute';
|
||||
public static LABEL = nls.localize('scriptExecute', 'Script As Execute');
|
||||
|
||||
constructor(
|
||||
id: string, label: string,
|
||||
@IQueryEditorService protected _queryEditorService: IQueryEditorService,
|
||||
@IConnectionManagementService protected _connectionManagementService: IConnectionManagementService,
|
||||
@IScriptingService protected _scriptingService: IScriptingService,
|
||||
@IErrorMessageService protected _errorMessageService: IErrorMessageService
|
||||
) {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
public run(actionContext: BaseActionContext): TPromise<boolean> {
|
||||
return new TPromise<boolean>((resolve, reject) => {
|
||||
TaskUtilities.script(
|
||||
actionContext.profile,
|
||||
actionContext.object,
|
||||
this._connectionManagementService,
|
||||
this._queryEditorService,
|
||||
this._scriptingService,
|
||||
ScriptOperation.Execute,
|
||||
this._errorMessageService
|
||||
).then(
|
||||
result => {
|
||||
resolve(true);
|
||||
},
|
||||
error => {
|
||||
resolve(false);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class ScriptAlterAction extends Action {
|
||||
public static ID = 'scriptAlter';
|
||||
public static LABEL = nls.localize('scriptAlter', 'Script As Alter');
|
||||
|
||||
constructor(
|
||||
id: string, label: string,
|
||||
@IQueryEditorService protected _queryEditorService: IQueryEditorService,
|
||||
@IConnectionManagementService protected _connectionManagementService: IConnectionManagementService,
|
||||
@IScriptingService protected _scriptingService: IScriptingService,
|
||||
@IErrorMessageService protected _errorMessageService: IErrorMessageService
|
||||
) {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
public run(actionContext: BaseActionContext): TPromise<boolean> {
|
||||
return new TPromise<boolean>((resolve, reject) => {
|
||||
TaskUtilities.script(
|
||||
actionContext.profile,
|
||||
actionContext.object,
|
||||
this._connectionManagementService,
|
||||
this._queryEditorService,
|
||||
this._scriptingService,
|
||||
ScriptOperation.Alter,
|
||||
this._errorMessageService
|
||||
).then(
|
||||
result => {
|
||||
resolve(true);
|
||||
},
|
||||
error => {
|
||||
resolve(false);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class EditDataAction extends Action {
|
||||
public static ID = 'editData';
|
||||
public static LABEL = nls.localize('editData', 'Edit Data');
|
||||
@@ -164,7 +224,6 @@ export class ScriptCreateAction extends Action {
|
||||
TaskUtilities.script(
|
||||
actionContext.profile,
|
||||
actionContext.object,
|
||||
actionContext.uri,
|
||||
this._connectionManagementService,
|
||||
this._queryEditorService,
|
||||
this._scriptingService,
|
||||
@@ -201,7 +260,6 @@ export class ScriptDeleteAction extends Action {
|
||||
TaskUtilities.script(
|
||||
actionContext.profile,
|
||||
actionContext.object,
|
||||
actionContext.uri,
|
||||
this._connectionManagementService,
|
||||
this._queryEditorService,
|
||||
this._scriptingService,
|
||||
@@ -231,7 +289,7 @@ export class BackupAction extends TaskAction {
|
||||
super(id, label, icon);
|
||||
}
|
||||
|
||||
run(actionContext: ITaskActionContext): TPromise<boolean> {
|
||||
run(actionContext: BaseActionContext): TPromise<boolean> {
|
||||
return new TPromise<boolean>((resolve, reject) => {
|
||||
TaskUtilities.showBackup(
|
||||
actionContext.profile,
|
||||
@@ -260,7 +318,7 @@ export class RestoreAction extends TaskAction {
|
||||
super(id, label, icon);
|
||||
}
|
||||
|
||||
run(actionContext: ITaskActionContext): TPromise<boolean> {
|
||||
run(actionContext: BaseActionContext): TPromise<boolean> {
|
||||
return new TPromise<boolean>((resolve, reject) => {
|
||||
TaskUtilities.showRestore(
|
||||
actionContext.profile,
|
||||
@@ -289,7 +347,7 @@ export class ManageAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
run(actionContext: BaseActionContext): TPromise<boolean> {
|
||||
run(actionContext: ManageActionContext): TPromise<boolean> {
|
||||
let self = this;
|
||||
return new TPromise<boolean>((resolve, reject) => {
|
||||
self._connectionManagementService.connect(actionContext.profile, actionContext.uri, { showDashboard: true, saveTheConnection: false, params: undefined, showConnectionDialogOnError: false, showFirewallRuleOnError: true }).then(
|
||||
@@ -338,7 +396,7 @@ export class NewDatabaseAction extends TaskAction {
|
||||
super(id, label, icon);
|
||||
}
|
||||
|
||||
run(actionContext: ITaskActionContext): TPromise<boolean> {
|
||||
run(actionContext: BaseActionContext): TPromise<boolean> {
|
||||
return new TPromise<boolean>((resolve, reject) => {
|
||||
TaskUtilities.showCreateDatabase(actionContext.profile, this._adminService, this._errorMessageService);
|
||||
});
|
||||
@@ -357,7 +415,7 @@ export class ConfigureDashboardAction extends TaskAction {
|
||||
super(id, label, icon);
|
||||
}
|
||||
|
||||
run(actionContext: ITaskActionContext): TPromise<boolean> {
|
||||
run(actionContext: BaseActionContext): TPromise<boolean> {
|
||||
return new TPromise<boolean>((resolve, reject) => {
|
||||
this._windowsService.openExternal(ConfigureDashboardAction.configHelpUri).then((result) => {
|
||||
resolve(result);
|
||||
|
||||
@@ -30,31 +30,10 @@ export function getSqlConfigValue<T>(workspaceConfigService: IWorkspaceConfigura
|
||||
return config[configName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a copy operation for an arbitrary string, by creating a temp div, copying
|
||||
* the text to it, and calling copy on the document. This will clear any existing selection
|
||||
* so if being called where selection state needs to be preserved, it's recommended to
|
||||
* cache the existing selection first and re-set it after this method is called
|
||||
*
|
||||
* @export
|
||||
* @param {string} text
|
||||
*/
|
||||
export function executeCopy(text: string): void {
|
||||
let input = document.createElement('textarea');
|
||||
document.body.appendChild(input);
|
||||
input.value = text;
|
||||
input.style.position = 'absolute';
|
||||
input.style.bottom = '100%';
|
||||
input.focus();
|
||||
input.select();
|
||||
document.execCommand('copy');
|
||||
input.remove();
|
||||
}
|
||||
|
||||
export function getEditorUri(input: IEditorInput): string{
|
||||
export function getEditorUri(input: IEditorInput): string {
|
||||
let uri: URI;
|
||||
if (input instanceof QueryInput) {
|
||||
let queryCast: QueryInput = <QueryInput> input;
|
||||
let queryCast: QueryInput = <QueryInput>input;
|
||||
if (queryCast) {
|
||||
uri = queryCast.getResource();
|
||||
}
|
||||
|
||||
@@ -25,61 +25,66 @@ import os = require('os');
|
||||
import path = require('path');
|
||||
|
||||
// map for the version of SQL Server (default is 140)
|
||||
let scriptCompatibilityOptionMap = new Map<number, string>();
|
||||
scriptCompatibilityOptionMap.set(90, "Script90Compat");
|
||||
scriptCompatibilityOptionMap.set(100, "Script100Compat");
|
||||
scriptCompatibilityOptionMap.set(105, "Script105Compat");
|
||||
scriptCompatibilityOptionMap.set(110, "Script110Compat");
|
||||
scriptCompatibilityOptionMap.set(120, "Script120Compat");
|
||||
scriptCompatibilityOptionMap.set(130, "Script130Compat");
|
||||
scriptCompatibilityOptionMap.set(140, "Script140Compat");
|
||||
const scriptCompatibilityOptionMap = {
|
||||
90: 'Script90Compat',
|
||||
100: 'Script100Compat',
|
||||
105: 'Script105Compat',
|
||||
110: 'Script110Compat',
|
||||
120: 'Script120Compat',
|
||||
130: 'Script130Compat',
|
||||
140: 'Script140Compat'
|
||||
};
|
||||
|
||||
// map for the target database engine edition (default is Enterprise)
|
||||
let targetDatabaseEngineEditionMap = new Map<number, string>();
|
||||
targetDatabaseEngineEditionMap.set(0, "SqlServerEnterpriseEdition");
|
||||
targetDatabaseEngineEditionMap.set(1, "SqlServerPersonalEdition");
|
||||
targetDatabaseEngineEditionMap.set(2, "SqlServerStandardEdition");
|
||||
targetDatabaseEngineEditionMap.set(3, "SqlServerEnterpriseEdition");
|
||||
targetDatabaseEngineEditionMap.set(4, "SqlServerExpressEdition");
|
||||
targetDatabaseEngineEditionMap.set(5, "SqlAzureDatabaseEdition");
|
||||
targetDatabaseEngineEditionMap.set(6, "SqlDatawarehouseEdition");
|
||||
targetDatabaseEngineEditionMap.set(7, "SqlServerStretchEdition");
|
||||
const targetDatabaseEngineEditionMap = {
|
||||
0: 'SqlServerEnterpriseEdition',
|
||||
1: 'SqlServerPersonalEdition',
|
||||
2: 'SqlServerStandardEdition',
|
||||
3: 'SqlServerEnterpriseEdition',
|
||||
4: 'SqlServerExpressEdition',
|
||||
5: 'SqlAzureDatabaseEdition',
|
||||
6: 'SqlDatawarehouseEdition',
|
||||
7: 'SqlServerStretchEdition'
|
||||
};
|
||||
|
||||
// map for object types for scripting
|
||||
let objectScriptMap = new Map<string, string>();
|
||||
objectScriptMap.set("Table", "Table");
|
||||
objectScriptMap.set("View", "View");
|
||||
objectScriptMap.set("StoredProcedure", "Procedure");
|
||||
objectScriptMap.set("UserDefinedFunction", "Function");
|
||||
objectScriptMap.set("UserDefinedDataType", "Type");
|
||||
objectScriptMap.set("User", "User");
|
||||
objectScriptMap.set("Default", "Default");
|
||||
objectScriptMap.set("Rule", "Rule");
|
||||
objectScriptMap.set("DatabaseRole", "Role");
|
||||
objectScriptMap.set("ApplicationRole", "Application Role");
|
||||
objectScriptMap.set("SqlAssembly", "Assembly");
|
||||
objectScriptMap.set("DdlTrigger", "Trigger");
|
||||
objectScriptMap.set("Synonym", "Synonym");
|
||||
objectScriptMap.set("XmlSchemaCollection", "Xml Schema Collection");
|
||||
objectScriptMap.set("Schema", "Schema");
|
||||
objectScriptMap.set("PlanGuide", "sp_create_plan_guide");
|
||||
objectScriptMap.set("UserDefinedType", "Type");
|
||||
objectScriptMap.set("UserDefinedAggregate", "Aggregate");
|
||||
objectScriptMap.set("FullTextCatalog", "Fulltext Catalog");
|
||||
objectScriptMap.set("UserDefinedTableType", "Type");
|
||||
objectScriptMap.set("MaterializedView", "Materialized View");
|
||||
const objectScriptMap = {
|
||||
Table: 'Table',
|
||||
View: 'View',
|
||||
StoredProcedure: 'Procedure',
|
||||
UserDefinedFunction: 'Function',
|
||||
UserDefinedDataType: 'Type',
|
||||
User: 'User',
|
||||
Default: 'Default',
|
||||
Rule: 'Rule',
|
||||
DatabaseRole: 'Role',
|
||||
ApplicationRole: 'Application Role',
|
||||
SqlAssembly: 'Assembly',
|
||||
DdlTrigger: 'Trigger',
|
||||
Synonym: 'Synonym',
|
||||
XmlSchemaCollection: 'Xml Schema Collection',
|
||||
Schema: 'Schema',
|
||||
PlanGuide: 'sp_create_plan_guide',
|
||||
UserDefinedType: 'Type',
|
||||
UserDefinedAggregate: 'Aggregate',
|
||||
FullTextCatalog: 'Fulltext Catalog',
|
||||
UserDefinedTableType: 'Type',
|
||||
MaterializedView: 'Materialized View'
|
||||
};
|
||||
|
||||
export enum ScriptOperation {
|
||||
Select = 0,
|
||||
Create = 1,
|
||||
Insert = 2,
|
||||
Update = 3,
|
||||
Delete = 4
|
||||
Delete = 4,
|
||||
Execute = 5,
|
||||
Alter = 6
|
||||
}
|
||||
|
||||
export function GetScriptOperationName(operation: ScriptOperation) {
|
||||
let defaultName: string = ScriptOperation[operation];
|
||||
switch(operation) {
|
||||
switch (operation) {
|
||||
case ScriptOperation.Select:
|
||||
return nls.localize('selectOperationName', 'Select');
|
||||
case ScriptOperation.Create:
|
||||
@@ -124,11 +129,11 @@ export function connectIfNotAlreadyConnected(connectionProfile: IConnectionProfi
|
||||
/**
|
||||
* Select the top rows from an object
|
||||
*/
|
||||
export function scriptSelect(connectionProfile: IConnectionProfile, metadata: data.ObjectMetadata, ownerUri: string, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<void> {
|
||||
export function scriptSelect(connectionProfile: IConnectionProfile, metadata: data.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
connectIfNotAlreadyConnected(connectionProfile, connectionService).then(connectionResult => {
|
||||
let paramDetails: data.ScriptingParamDetails = getScriptingParamDetails(connectionService, ownerUri, metadata);
|
||||
scriptingService.script(ownerUri, metadata, ScriptOperation.Select, paramDetails).then(result => {
|
||||
connectionService.connectIfNotConnected(connectionProfile).then(connectionResult => {
|
||||
let paramDetails: data.ScriptingParamDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
|
||||
scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails).then(result => {
|
||||
if (result.script) {
|
||||
queryEditorService.newSqlEditor(result.script).then((owner: IConnectableInput) => {
|
||||
// Connect our editor to the input connection
|
||||
@@ -151,7 +156,7 @@ export function scriptSelect(connectionProfile: IConnectionProfile, metadata: da
|
||||
}
|
||||
}, scriptError => {
|
||||
reject(scriptError);
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -180,24 +185,20 @@ export function editData(connectionProfile: IConnectionProfile, tableName: strin
|
||||
/**
|
||||
* Script the object as a statement based on the provided action (except Select)
|
||||
*/
|
||||
export function script(connectionProfile: IConnectionProfile, metadata: data.ObjectMetadata, ownerUri: string,
|
||||
export function script(connectionProfile: IConnectionProfile, metadata: data.ObjectMetadata,
|
||||
connectionService: IConnectionManagementService,
|
||||
queryEditorService: IQueryEditorService,
|
||||
scriptingService: IScriptingService,
|
||||
operation: ScriptOperation,
|
||||
errorMessageService: IErrorMessageService): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
connectIfNotAlreadyConnected(connectionProfile, connectionService).then(connectionResult => {
|
||||
let paramDetails = getScriptingParamDetails(connectionService, ownerUri, metadata);
|
||||
scriptingService.script(ownerUri, metadata, operation, paramDetails).then(result => {
|
||||
connectionService.connectIfNotConnected(connectionProfile).then(connectionResult => {
|
||||
let paramDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
|
||||
scriptingService.script(connectionResult, metadata, operation, paramDetails).then(result => {
|
||||
if (result) {
|
||||
let script: string = result.script;
|
||||
let startPos: number = 0;
|
||||
if (connectionProfile.providerName === "MSSQL") {
|
||||
startPos = getStartPos(script, operation, metadata.metadataTypeName);
|
||||
}
|
||||
if (startPos >= 0) {
|
||||
script = script.substring(startPos);
|
||||
|
||||
if (script) {
|
||||
queryEditorService.newSqlEditor(script, connectionProfile.providerName).then(() => {
|
||||
resolve();
|
||||
}).catch(editorError => {
|
||||
@@ -206,14 +207,16 @@ export function script(connectionProfile: IConnectionProfile, metadata: data.Obj
|
||||
}
|
||||
else {
|
||||
let scriptNotFoundMsg = nls.localize('scriptNotFoundForObject', 'No script was returned when scripting as {0} on object {1}',
|
||||
GetScriptOperationName(operation), metadata.metadataTypeName);
|
||||
GetScriptOperationName(operation), metadata.metadataTypeName);
|
||||
let messageDetail = '';
|
||||
let operationResult = scriptingService.getOperationFailedResult(result.operationId);
|
||||
if (operationResult && operationResult.hasError && operationResult.errorMessage) {
|
||||
scriptNotFoundMsg = operationResult.errorMessage;
|
||||
messageDetail = operationResult.errorDetails;
|
||||
}
|
||||
if (errorMessageService) {
|
||||
let title = nls.localize('scriptingFailed', 'Scripting Failed');
|
||||
errorMessageService.showDialog(Severity.Error, title, scriptNotFoundMsg);
|
||||
errorMessageService.showDialog(Severity.Error, title, scriptNotFoundMsg, messageDetail);
|
||||
}
|
||||
reject(scriptNotFoundMsg);
|
||||
}
|
||||
@@ -258,7 +261,8 @@ export function replaceConnection(oldUri: string, newUri: string, connectionServ
|
||||
let defaultResult: IConnectionResult = {
|
||||
connected: false,
|
||||
errorMessage: undefined,
|
||||
errorCode: undefined
|
||||
errorCode: undefined,
|
||||
callStack: undefined
|
||||
};
|
||||
if (connectionService) {
|
||||
let connectionProfile = connectionService.getConnectionProfile(oldUri);
|
||||
@@ -328,7 +332,7 @@ export function openInsight(query: IInsightsConfig, profile: IConnectionProfile,
|
||||
|
||||
/* Helper Methods */
|
||||
function getStartPos(script: string, operation: ScriptOperation, typeName: string): number {
|
||||
let objectTypeName = objectScriptMap.get(typeName);
|
||||
let objectTypeName = objectScriptMap[typeName];
|
||||
if (objectTypeName && script) {
|
||||
let scriptTypeName = objectTypeName.toLowerCase();
|
||||
switch (operation) {
|
||||
@@ -353,7 +357,7 @@ function getScriptingParamDetails(connectionService: IConnectionManagementServic
|
||||
scriptCompatibilityOption: scriptCompatibilityOptionMap[serverInfo.serverMajorVersion],
|
||||
targetDatabaseEngineEdition: targetDatabaseEngineEditionMap[serverInfo.engineEditionId],
|
||||
targetDatabaseEngineType: serverInfo.isCloud ? 'SqlAzure' : 'SingleInstance'
|
||||
}
|
||||
};
|
||||
return paramDetails;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,25 +6,37 @@
|
||||
'use strict';
|
||||
import 'vs/css!sql/media/icons/common-icons';
|
||||
import 'vs/css!./media/errorMessageDialog';
|
||||
import { Button } from 'sql/base/browser/ui/button/button';
|
||||
import { Modal } from 'sql/base/browser/ui/modal/modal';
|
||||
import * as TelemetryKeys from 'sql/common/telemetryKeys';
|
||||
import { attachModalDialogStyler } from 'sql/common/theme/styler';
|
||||
import { attachButtonStyler, attachModalDialogStyler } from 'sql/common/theme/styler';
|
||||
|
||||
import { Builder } from 'vs/base/browser/builder';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { attachButtonStyler } from 'vs/platform/theme/common/styler';
|
||||
import { SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
|
||||
import { IPartService } from 'vs/workbench/services/part/common/partService';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
import { localize } from 'vs/nls';
|
||||
import { IAction } from 'vs/base/common/actions';
|
||||
|
||||
const maxActions = 1;
|
||||
|
||||
export class ErrorMessageDialog extends Modal {
|
||||
|
||||
private _body: HTMLElement;
|
||||
private _okButton: Button;
|
||||
private _copyButton: Button;
|
||||
private _actionButtons: Button[];
|
||||
private _actions: IAction[];
|
||||
private _severity: Severity;
|
||||
private _message: string;
|
||||
private _messageDetails: string;
|
||||
private _okLabel: string;
|
||||
private _closeLabel: string;
|
||||
|
||||
private _onOk = new Emitter<void>();
|
||||
public onOk: Event<void> = this._onOk.event;
|
||||
@@ -37,6 +49,8 @@ export class ErrorMessageDialog extends Modal {
|
||||
@IContextKeyService contextKeyService: IContextKeyService
|
||||
) {
|
||||
super('', TelemetryKeys.ErrorMessage, partService, telemetryService, contextKeyService, { isFlyout: false, hasTitleIcon: true });
|
||||
this._okLabel = localize('OK', 'OK');
|
||||
this._closeLabel = localize('close', 'Close');
|
||||
}
|
||||
|
||||
protected renderBody(container: HTMLElement) {
|
||||
@@ -47,12 +61,37 @@ export class ErrorMessageDialog extends Modal {
|
||||
|
||||
public render() {
|
||||
super.render();
|
||||
attachModalDialogStyler(this, this._themeService);
|
||||
let copyButton = this.addFooterButton('Copy to Clipboard', () => this._clipboardService.writeText(this._message), 'left');
|
||||
copyButton.icon = 'icon scriptToClipboard';
|
||||
attachButtonStyler(copyButton, this._themeService, { buttonBackground: SIDE_BAR_BACKGROUND, buttonHoverBackground: SIDE_BAR_BACKGROUND });
|
||||
let okButton = this.addFooterButton('OK', () => this.ok());
|
||||
attachButtonStyler(okButton, this._themeService);
|
||||
this._register(attachModalDialogStyler(this, this._themeService));
|
||||
this.createCopyButton();
|
||||
this._actionButtons = [];
|
||||
for (let i = 0; i < maxActions; i++) {
|
||||
this._actionButtons.unshift(this.createStandardButton('Action', () => this.onActionSelected(i)));
|
||||
}
|
||||
this._okButton = this.addFooterButton(this._okLabel, () => this.ok());
|
||||
this._register(attachButtonStyler(this._okButton, this._themeService));
|
||||
}
|
||||
|
||||
private createCopyButton() {
|
||||
let copyButtonLabel = localize('copyDetails', 'Copy details');
|
||||
this._copyButton = this.addFooterButton(copyButtonLabel, () => this._clipboardService.writeText(this._messageDetails), 'left');
|
||||
this._copyButton.icon = 'icon scriptToClipboard';
|
||||
this._copyButton.getElement().title = copyButtonLabel;
|
||||
this._register(attachButtonStyler(this._copyButton, this._themeService, { buttonBackground: SIDE_BAR_BACKGROUND, buttonHoverBackground: SIDE_BAR_BACKGROUND }));
|
||||
}
|
||||
|
||||
private createStandardButton(label: string, onSelect: () => void): Button {
|
||||
let button = this.addFooterButton(label, onSelect, 'right');
|
||||
this._register(attachButtonStyler(button, this._themeService));
|
||||
return button;
|
||||
}
|
||||
|
||||
private onActionSelected(index: number): void {
|
||||
// Call OK so it always closes
|
||||
this.ok();
|
||||
// Run the action if possible
|
||||
if (this._actions && index < this._actions.length) {
|
||||
this._actions[index].run();
|
||||
}
|
||||
}
|
||||
|
||||
protected layout(height?: number): void {
|
||||
@@ -99,13 +138,39 @@ export class ErrorMessageDialog extends Modal {
|
||||
this.hide();
|
||||
}
|
||||
|
||||
public open(severity: Severity, headerTitle: string, message: string) {
|
||||
public open(severity: Severity, headerTitle: string, message: string, messageDetails: string, actions: IAction[]) {
|
||||
this._severity = severity;
|
||||
this._message = message;
|
||||
this.title = headerTitle;
|
||||
this._messageDetails = messageDetails;
|
||||
if (this._messageDetails) {
|
||||
this._copyButton.getElement().style.visibility = 'visible';
|
||||
} else {
|
||||
this._copyButton.getElement().style.visibility = 'hidden';
|
||||
}
|
||||
this.resetActions();
|
||||
if (actions && actions.length > 0) {
|
||||
for (let i = 0; i < maxActions && i < actions.length; i++) {
|
||||
this._actions.push(actions[i]);
|
||||
let button = this._actionButtons[i];
|
||||
button.label = actions[i].label;
|
||||
button.getElement().style.visibility = 'visible';
|
||||
}
|
||||
this._okButton.label = this._closeLabel;
|
||||
} else {
|
||||
this._okButton.label = this._okLabel;
|
||||
}
|
||||
this.updateIconTitle();
|
||||
this.updateDialogBody();
|
||||
this.show();
|
||||
this._okButton.focus();
|
||||
}
|
||||
|
||||
private resetActions(): void {
|
||||
this._actions = [];
|
||||
for(let actionButton of this._actionButtons) {
|
||||
actionButton.getElement().style.visibility = 'hidden';
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
|
||||
@@ -11,6 +11,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
|
||||
|
||||
import { IErrorMessageService } from 'sql/parts/connection/common/connectionManagement';
|
||||
import { ErrorMessageDialog } from 'sql/workbench/errorMessageDialog/errorMessageDialog';
|
||||
import { IAction } from 'vs/base/common/actions';
|
||||
|
||||
export class ErrorMessageService implements IErrorMessageService {
|
||||
|
||||
@@ -25,11 +26,11 @@ export class ErrorMessageService implements IErrorMessageService {
|
||||
@IInstantiationService private _instantiationService: IInstantiationService
|
||||
) { }
|
||||
|
||||
public showDialog(severity: Severity, headerTitle: string, message: string): void {
|
||||
this.doShowDialog(severity, headerTitle, message);
|
||||
public showDialog(severity: Severity, headerTitle: string, message: string, messageDetails?: string, actions?: IAction[]): void {
|
||||
this.doShowDialog(severity, headerTitle, message, messageDetails, actions);
|
||||
}
|
||||
|
||||
private doShowDialog(severity: Severity, headerTitle: string, message: string): void {
|
||||
private doShowDialog(severity: Severity, headerTitle: string, message: string, messageDetails: string, actions?: IAction[]): void {
|
||||
if (!this._errorDialog) {
|
||||
this._errorDialog = this._instantiationService.createInstance(ErrorMessageDialog);
|
||||
this._errorDialog.onOk(() => this.handleOnOk());
|
||||
@@ -37,7 +38,7 @@ export class ErrorMessageService implements IErrorMessageService {
|
||||
}
|
||||
|
||||
let title = headerTitle ? headerTitle : this.getDefaultTitle(severity);
|
||||
return this._errorDialog.open(severity, title, message);
|
||||
return this._errorDialog.open(severity, title, message, messageDetails, actions);
|
||||
}
|
||||
|
||||
private getDefaultTitle(severity: Severity) {
|
||||
|
||||
@@ -13,4 +13,14 @@
|
||||
height: 20px;
|
||||
float: left;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
/* Make the test selectable*/
|
||||
.error-dialog .error-message {
|
||||
-webkit-user-select: text;
|
||||
user-select: text;
|
||||
}
|
||||
|
||||
.modal .footer-button a.monaco-button.monaco-text-button.icon.scriptToClipboard {
|
||||
width: 120px;
|
||||
}
|
||||
Reference in New Issue
Block a user