mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-21 01:25:37 -05:00
Add toggle query history capture command/action (#7427)
* Add toggle query history capture command/action * Add extension updates
This commit is contained in:
committed by
Karl Burtram
parent
7cbc268c52
commit
4018a29a16
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { DeleteAction, OpenQueryAction, RunQueryAction, ClearHistoryAction } from 'sql/workbench/parts/queryHistory/browser/queryHistoryActions';
|
||||
import { DeleteAction, OpenQueryAction, RunQueryAction, ClearHistoryAction, ToggleQueryHistoryCaptureAction } from 'sql/workbench/parts/queryHistory/browser/queryHistoryActions';
|
||||
import { ITree } from 'vs/base/parts/tree/browser/tree';
|
||||
import { ContributableActionProvider } from 'vs/workbench/browser/actions';
|
||||
import { IAction } from 'vs/base/common/actions';
|
||||
@@ -19,7 +19,8 @@ export class QueryHistoryActionProvider extends ContributableActionProvider {
|
||||
openQueryAction: IAction,
|
||||
runQueryAction: IAction,
|
||||
deleteAction: IAction,
|
||||
clearAction: IAction
|
||||
clearAction: IAction,
|
||||
toggleCaptureAction: IAction
|
||||
};
|
||||
|
||||
constructor(
|
||||
@@ -30,7 +31,8 @@ export class QueryHistoryActionProvider extends ContributableActionProvider {
|
||||
openQueryAction: instantiationService.createInstance(OpenQueryAction, OpenQueryAction.ID, OpenQueryAction.LABEL),
|
||||
runQueryAction: instantiationService.createInstance(RunQueryAction, RunQueryAction.ID, RunQueryAction.LABEL),
|
||||
deleteAction: instantiationService.createInstance(DeleteAction, DeleteAction.ID, DeleteAction.LABEL),
|
||||
clearAction: instantiationService.createInstance(ClearHistoryAction, ClearHistoryAction.ID, ClearHistoryAction.LABEL)
|
||||
clearAction: instantiationService.createInstance(ClearHistoryAction, ClearHistoryAction.ID, ClearHistoryAction.LABEL),
|
||||
toggleCaptureAction: instantiationService.createInstance(ToggleQueryHistoryCaptureAction, ToggleQueryHistoryCaptureAction.ID, ToggleQueryHistoryCaptureAction.LABEL)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -43,6 +45,7 @@ export class QueryHistoryActionProvider extends ContributableActionProvider {
|
||||
*/
|
||||
public getActions(element: any): IAction[] {
|
||||
const actions: IAction[] = [];
|
||||
// Actions we only want to display if we're on a valid QueryHistoryNode
|
||||
if (element instanceof QueryHistoryNode && element.info) {
|
||||
if (element.info && element.info.queryText && element.info.queryText !== '') {
|
||||
actions.push(this._actions.openQueryAction);
|
||||
@@ -50,7 +53,8 @@ export class QueryHistoryActionProvider extends ContributableActionProvider {
|
||||
}
|
||||
actions.push(this._actions.deleteAction);
|
||||
}
|
||||
actions.push(this._actions.clearAction);
|
||||
// Common actions we want to always display
|
||||
actions.push(this._actions.clearAction, this._actions.toggleCaptureAction);
|
||||
return actions;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ export class ClearHistoryAction extends Action {
|
||||
}
|
||||
|
||||
public async run(): Promise<void> {
|
||||
this._commandService.executeCommand('queryHistory.clear');
|
||||
return this._commandService.executeCommand('queryHistory.clear');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,3 +106,33 @@ export class RunQueryAction extends Action {
|
||||
}
|
||||
}
|
||||
|
||||
export class ToggleQueryHistoryCaptureAction extends Action {
|
||||
public static ID = 'queryHistory.toggleCapture';
|
||||
public static LABEL = localize('queryHistory.toggleCaptureLabel', "Toggle Query History capture");
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
label: string,
|
||||
@ICommandService private _commandService: ICommandService,
|
||||
@IQueryHistoryService queryHistoryService: IQueryHistoryService
|
||||
) {
|
||||
super(id, label);
|
||||
this.setClassAndLabel(queryHistoryService.captureEnabled);
|
||||
this._register(queryHistoryService.onQueryHistoryCaptureChanged((captureEnabled: boolean) => { this.setClassAndLabel(captureEnabled); }));
|
||||
}
|
||||
|
||||
public async run(): Promise<void> {
|
||||
return this._commandService.executeCommand('queryHistory.toggleCapture');
|
||||
}
|
||||
|
||||
private setClassAndLabel(enabled: boolean) {
|
||||
if (enabled) {
|
||||
this.class = 'toggle-query-history-capture-action codicon-pause';
|
||||
this.label = localize('queryHistory.disableCapture', "Pause Query History capture");
|
||||
} else {
|
||||
this.class = 'toggle-query-history-capture-action codicon-play';
|
||||
this.label = localize('queryHistory.enableCapture', "Start Query History capture");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import { PanelRegistry, Extensions as PanelExtensions, PanelDescriptor } from 'v
|
||||
import { QUERY_HISTORY_PANEL_ID } from 'sql/workbench/parts/queryHistory/common/constants';
|
||||
import { ToggleQueryHistoryAction } from 'sql/workbench/parts/queryHistory/browser/queryHistoryActions';
|
||||
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { IConfigurationRegistry, ConfigurationScope, Extensions } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
|
||||
export class QueryHistoryWorkbenchContribution implements IWorkbenchContribution {
|
||||
|
||||
@@ -34,6 +35,21 @@ export class QueryHistoryWorkbenchContribution implements IWorkbenchContribution
|
||||
if (!this.queryHistoryEnabled) {
|
||||
this.queryHistoryEnabled = true;
|
||||
|
||||
const configurationRegistry = Registry.as<IConfigurationRegistry>(Extensions.Configuration);
|
||||
configurationRegistry.registerConfiguration({
|
||||
id: 'queryHistory',
|
||||
title: localize('queryHistoryConfigurationTitle', "QueryHistory"),
|
||||
type: 'object',
|
||||
properties: {
|
||||
'queryHistory.captureEnabled': {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
scope: ConfigurationScope.APPLICATION,
|
||||
description: localize('queryHistoryCaptureEnabled', "Whether Query History capture is enabled. If false queries executed will not be captured.")
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// We need this to be running in the background even if the Panel (which is currently the only thing using it)
|
||||
// isn't shown yet. Otherwise the service won't be initialized until the Panel is which means we might miss out
|
||||
// on some events
|
||||
@@ -47,6 +63,14 @@ export class QueryHistoryWorkbenchContribution implements IWorkbenchContribution
|
||||
}
|
||||
});
|
||||
|
||||
CommandsRegistry.registerCommand({
|
||||
id: 'queryHistory.toggleCapture',
|
||||
handler: (accessor) => {
|
||||
const queryHistoryService = accessor.get(IQueryHistoryService);
|
||||
queryHistoryService.toggleCaptureEnabled();
|
||||
}
|
||||
});
|
||||
|
||||
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
|
||||
registry.registerWorkbenchAction(
|
||||
new SyncActionDescriptor(
|
||||
|
||||
Reference in New Issue
Block a user