mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Add Clear All Query History command/action (#7408)
* Add clear all query history action/command * Fix display issue when clearing * Change localize ID and fix registration
This commit is contained in:
@@ -22,6 +22,22 @@
|
|||||||
},
|
},
|
||||||
"extensionDependencies": [
|
"extensionDependencies": [
|
||||||
],
|
],
|
||||||
|
"contributes": {
|
||||||
|
"commands": [
|
||||||
|
{
|
||||||
|
"command": "queryHistory.clear",
|
||||||
|
"title": "%queryHistory.clear%",
|
||||||
|
"category": "%queryHistory.displayName%"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"menus": {
|
||||||
|
"commandPalette": [
|
||||||
|
{
|
||||||
|
"command": "queryHistory.clear"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"queryHistory.displayName": "Query History",
|
"queryHistory.displayName": "Query History",
|
||||||
"queryHistory.description": "View and run previously executed queries"
|
"queryHistory.description": "View and run previously executed queries",
|
||||||
|
"queryHistory.clear": "Clear All History"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,5 +21,6 @@ export interface IQueryHistoryService {
|
|||||||
|
|
||||||
getQueryHistoryInfos(): QueryHistoryInfo[];
|
getQueryHistoryInfos(): QueryHistoryInfo[];
|
||||||
deleteQueryHistoryInfo(info: QueryHistoryInfo): void;
|
deleteQueryHistoryInfo(info: QueryHistoryInfo): void;
|
||||||
|
clearQueryHistory(): void;
|
||||||
start(): void;
|
start(): void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,14 @@ export class QueryHistoryService extends Disposable implements IQueryHistoryServ
|
|||||||
this._onInfosUpdated.fire(this._infos);
|
this._onInfosUpdated.fire(this._infos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all infos from the cache
|
||||||
|
*/
|
||||||
|
public clearQueryHistory() {
|
||||||
|
this._infos = [];
|
||||||
|
this._onInfosUpdated.fire(this._infos);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to force initialization of the service so that it can start tracking query events
|
* Method to force initialization of the service so that it can start tracking query events
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
import { DeleteAction, OpenQueryAction, RunQueryAction } from 'sql/workbench/parts/queryHistory/browser/queryHistoryActions';
|
import { DeleteAction, OpenQueryAction, RunQueryAction, ClearHistoryAction } from 'sql/workbench/parts/queryHistory/browser/queryHistoryActions';
|
||||||
import { ITree } from 'vs/base/parts/tree/browser/tree';
|
import { ITree } from 'vs/base/parts/tree/browser/tree';
|
||||||
import { ContributableActionProvider } from 'vs/workbench/browser/actions';
|
import { ContributableActionProvider } from 'vs/workbench/browser/actions';
|
||||||
import { IAction } from 'vs/base/common/actions';
|
import { IAction } from 'vs/base/common/actions';
|
||||||
@@ -15,40 +15,46 @@ import { QueryHistoryNode } from 'sql/workbench/parts/queryHistory/browser/query
|
|||||||
*/
|
*/
|
||||||
export class QueryHistoryActionProvider extends ContributableActionProvider {
|
export class QueryHistoryActionProvider extends ContributableActionProvider {
|
||||||
|
|
||||||
|
private _actions: {
|
||||||
|
openQueryAction: IAction,
|
||||||
|
runQueryAction: IAction,
|
||||||
|
deleteAction: IAction,
|
||||||
|
clearAction: IAction
|
||||||
|
};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@IInstantiationService private _instantiationService: IInstantiationService
|
@IInstantiationService instantiationService: IInstantiationService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
this._actions = {
|
||||||
|
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)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public hasActions(tree: ITree, element: any): boolean {
|
public hasActions(element: any): boolean {
|
||||||
return element instanceof QueryHistoryNode;
|
return element instanceof QueryHistoryNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return actions given an element in the tree
|
* Return actions for a selected node - or the default actions if no node is selected
|
||||||
*/
|
*/
|
||||||
public getActions(tree: ITree, element: any): IAction[] {
|
public getActions(element: any): IAction[] {
|
||||||
|
const actions: IAction[] = [];
|
||||||
if (element instanceof QueryHistoryNode && element.info) {
|
if (element instanceof QueryHistoryNode && element.info) {
|
||||||
return this.getQueryHistoryActions(tree, element);
|
if (element.info && element.info.queryText && element.info.queryText !== '') {
|
||||||
|
actions.push(this._actions.openQueryAction);
|
||||||
|
actions.push(this._actions.runQueryAction);
|
||||||
|
}
|
||||||
|
actions.push(this._actions.deleteAction);
|
||||||
}
|
}
|
||||||
return [];
|
actions.push(this._actions.clearAction);
|
||||||
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public hasSecondaryActions(tree: ITree, element: any): boolean {
|
public hasSecondaryActions(tree: ITree, element: any): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return actions for query history task
|
|
||||||
*/
|
|
||||||
public getQueryHistoryActions(tree: ITree, element: QueryHistoryNode): IAction[] {
|
|
||||||
const actions: IAction[] = [];
|
|
||||||
if (element.info && element.info.queryText && element.info.queryText !== '') {
|
|
||||||
actions.push(this._instantiationService.createInstance(OpenQueryAction, OpenQueryAction.ID, OpenQueryAction.LABEL));
|
|
||||||
actions.push(this._instantiationService.createInstance(RunQueryAction, RunQueryAction.ID, RunQueryAction.LABEL));
|
|
||||||
}
|
|
||||||
actions.push(this._instantiationService.createInstance(DeleteAction, DeleteAction.ID, DeleteAction.LABEL));
|
|
||||||
return actions;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { IQueryHistoryService } from 'sql/platform/queryHistory/common/queryHist
|
|||||||
import { QueryHistoryNode } from 'sql/workbench/parts/queryHistory/browser/queryHistoryNode';
|
import { QueryHistoryNode } from 'sql/workbench/parts/queryHistory/browser/queryHistoryNode';
|
||||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||||
import { openNewQuery } from 'sql/workbench/parts/query/browser/queryActions';
|
import { openNewQuery } from 'sql/workbench/parts/query/browser/queryActions';
|
||||||
|
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||||
|
|
||||||
export class ToggleQueryHistoryAction extends TogglePanelAction {
|
export class ToggleQueryHistoryAction extends TogglePanelAction {
|
||||||
|
|
||||||
@@ -42,11 +43,27 @@ export class DeleteAction extends Action {
|
|||||||
super(id, label);
|
super(id, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async run(element: QueryHistoryNode): Promise<boolean> {
|
public async run(element: QueryHistoryNode): Promise<void> {
|
||||||
if (element instanceof QueryHistoryNode && element.info) {
|
if (element instanceof QueryHistoryNode && element.info) {
|
||||||
this._queryHistoryService.deleteQueryHistoryInfo(element.info);
|
this._queryHistoryService.deleteQueryHistoryInfo(element.info);
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ClearHistoryAction extends Action {
|
||||||
|
public static ID = 'queryHistory.clear';
|
||||||
|
public static LABEL = localize('queryHistory.clearLabel', "Clear All History");
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
id: string,
|
||||||
|
label: string,
|
||||||
|
@ICommandService private _commandService: ICommandService
|
||||||
|
) {
|
||||||
|
super(id, label, 'clear-query-history-action codicon-clear-all');
|
||||||
|
}
|
||||||
|
|
||||||
|
public async run(): Promise<void> {
|
||||||
|
this._commandService.executeCommand('queryHistory.clear');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,11 +80,10 @@ export class OpenQueryAction extends Action {
|
|||||||
super(id, label);
|
super(id, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async run(element: QueryHistoryNode): Promise<boolean> {
|
public async run(element: QueryHistoryNode): Promise<void> {
|
||||||
if (element instanceof QueryHistoryNode && element.info) {
|
if (element instanceof QueryHistoryNode && element.info) {
|
||||||
return this._instantiationService.invokeFunction(openNewQuery, element.info.connectionProfile, element.info.queryText, RunQueryOnConnectionMode.none).then(() => true, () => false);
|
return this._instantiationService.invokeFunction(openNewQuery, element.info.connectionProfile, element.info.queryText, RunQueryOnConnectionMode.none).then(() => true, () => false);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,11 +99,10 @@ export class RunQueryAction extends Action {
|
|||||||
super(id, label);
|
super(id, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async run(element: QueryHistoryNode): Promise<boolean> {
|
public async run(element: QueryHistoryNode): Promise<void> {
|
||||||
if (element instanceof QueryHistoryNode && element.info) {
|
if (element instanceof QueryHistoryNode && element.info) {
|
||||||
return this._instantiationService.invokeFunction(openNewQuery, element.info.connectionProfile, element.info.queryText, RunQueryOnConnectionMode.executeQuery).catch(() => true, () => false);
|
return this._instantiationService.invokeFunction(openNewQuery, element.info.connectionProfile, element.info.queryText, RunQueryOnConnectionMode.executeQuery).catch(() => true, () => false);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export class QueryHistoryController extends treeDefaults.DefaultController {
|
|||||||
let anchor = { x: event.posx + 1, y: event.posy };
|
let anchor = { x: event.posx + 1, y: event.posy };
|
||||||
this.contextMenuService.showContextMenu({
|
this.contextMenuService.showContextMenu({
|
||||||
getAnchor: () => anchor,
|
getAnchor: () => anchor,
|
||||||
getActions: () => this.actionProvider.getActions(tree, element),
|
getActions: () => this.actionProvider.getActions(element),
|
||||||
getKeyBinding: (action) => this.keybindingService.lookupKeybinding(action.id),
|
getKeyBinding: (action) => this.keybindingService.lookupKeybinding(action.id),
|
||||||
onHide: (wasCancelled?: boolean) => {
|
onHide: (wasCancelled?: boolean) => {
|
||||||
if (wasCancelled) {
|
if (wasCancelled) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { QueryHistoryView } from 'sql/workbench/parts/queryHistory/browser/query
|
|||||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||||
import { Panel } from 'vs/workbench/browser/panel';
|
import { Panel } from 'vs/workbench/browser/panel';
|
||||||
import { QUERY_HISTORY_PANEL_ID } from 'sql/workbench/parts/queryHistory/common/constants';
|
import { QUERY_HISTORY_PANEL_ID } from 'sql/workbench/parts/queryHistory/common/constants';
|
||||||
|
import { IAction } from 'vs/base/common/actions';
|
||||||
|
|
||||||
export class QueryHistoryPanel extends Panel {
|
export class QueryHistoryPanel extends Panel {
|
||||||
|
|
||||||
@@ -40,4 +41,8 @@ export class QueryHistoryPanel extends Panel {
|
|||||||
public layout({ height }: Dimension): void {
|
public layout({ height }: Dimension): void {
|
||||||
this._queryHistoryView.layout(height);
|
this._queryHistoryView.layout(height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getActions(): IAction[] {
|
||||||
|
return this._queryHistoryView.getActions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { ITree } from 'vs/base/parts/tree/browser/tree';
|
|||||||
import { Disposable } from 'vs/base/common/lifecycle';
|
import { Disposable } from 'vs/base/common/lifecycle';
|
||||||
import { DefaultFilter, DefaultDragAndDrop, DefaultAccessibilityProvider } from 'vs/base/parts/tree/browser/treeDefaults';
|
import { DefaultFilter, DefaultDragAndDrop, DefaultAccessibilityProvider } from 'vs/base/parts/tree/browser/treeDefaults';
|
||||||
import { localize } from 'vs/nls';
|
import { localize } from 'vs/nls';
|
||||||
import { hide, $, append } from 'vs/base/browser/dom';
|
import { hide, $, append, show } from 'vs/base/browser/dom';
|
||||||
import { QueryHistoryRenderer } from 'sql/workbench/parts/queryHistory/browser/queryHistoryRenderer';
|
import { QueryHistoryRenderer } from 'sql/workbench/parts/queryHistory/browser/queryHistoryRenderer';
|
||||||
import { QueryHistoryDataSource } from 'sql/workbench/parts/queryHistory/browser/queryHistoryDataSource';
|
import { QueryHistoryDataSource } from 'sql/workbench/parts/queryHistory/browser/queryHistoryDataSource';
|
||||||
import { QueryHistoryController } from 'sql/workbench/parts/queryHistory/browser/queryHistoryController';
|
import { QueryHistoryController } from 'sql/workbench/parts/queryHistory/browser/queryHistoryController';
|
||||||
@@ -21,12 +21,14 @@ import { IExpandableTree } from 'sql/workbench/parts/objectExplorer/browser/tree
|
|||||||
import { IQueryHistoryService } from 'sql/platform/queryHistory/common/queryHistoryService';
|
import { IQueryHistoryService } from 'sql/platform/queryHistory/common/queryHistoryService';
|
||||||
import { QueryHistoryNode } from 'sql/workbench/parts/queryHistory/browser/queryHistoryNode';
|
import { QueryHistoryNode } from 'sql/workbench/parts/queryHistory/browser/queryHistoryNode';
|
||||||
import { QueryHistoryInfo } from 'sql/platform/queryHistory/common/queryHistoryInfo';
|
import { QueryHistoryInfo } from 'sql/platform/queryHistory/common/queryHistoryInfo';
|
||||||
|
import { IAction } from 'vs/base/common/actions';
|
||||||
/**
|
/**
|
||||||
* QueryHistoryView implements the dynamic tree view for displaying Query History
|
* QueryHistoryView implements the dynamic tree view for displaying Query History
|
||||||
*/
|
*/
|
||||||
export class QueryHistoryView extends Disposable {
|
export class QueryHistoryView extends Disposable {
|
||||||
private _messages: HTMLElement;
|
private _messages: HTMLElement;
|
||||||
private _tree: ITree;
|
private _tree: ITree;
|
||||||
|
private _actionProvider: QueryHistoryActionProvider;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@IInstantiationService private _instantiationService: IInstantiationService,
|
@IInstantiationService private _instantiationService: IInstantiationService,
|
||||||
@@ -34,6 +36,7 @@ export class QueryHistoryView extends Disposable {
|
|||||||
@IQueryHistoryService private readonly _queryHistoryService: IQueryHistoryService
|
@IQueryHistoryService private readonly _queryHistoryService: IQueryHistoryService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
this._actionProvider = this._instantiationService.createInstance(QueryHistoryActionProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,9 +67,8 @@ export class QueryHistoryView extends Disposable {
|
|||||||
*/
|
*/
|
||||||
public createQueryHistoryTree(treeContainer: HTMLElement, instantiationService: IInstantiationService): Tree {
|
public createQueryHistoryTree(treeContainer: HTMLElement, instantiationService: IInstantiationService): Tree {
|
||||||
const dataSource = instantiationService.createInstance(QueryHistoryDataSource);
|
const dataSource = instantiationService.createInstance(QueryHistoryDataSource);
|
||||||
const actionProvider = instantiationService.createInstance(QueryHistoryActionProvider);
|
|
||||||
const renderer = instantiationService.createInstance(QueryHistoryRenderer);
|
const renderer = instantiationService.createInstance(QueryHistoryRenderer);
|
||||||
const controller = instantiationService.createInstance(QueryHistoryController, actionProvider);
|
const controller = instantiationService.createInstance(QueryHistoryController, this._actionProvider);
|
||||||
const dnd = new DefaultDragAndDrop();
|
const dnd = new DefaultDragAndDrop();
|
||||||
const filter = new DefaultFilter();
|
const filter = new DefaultFilter();
|
||||||
const sorter = null;
|
const sorter = null;
|
||||||
@@ -85,9 +87,6 @@ export class QueryHistoryView extends Disposable {
|
|||||||
let selectedElement: any;
|
let selectedElement: any;
|
||||||
let targetsToExpand: any[];
|
let targetsToExpand: any[];
|
||||||
|
|
||||||
// Focus
|
|
||||||
this._tree.domFocus();
|
|
||||||
|
|
||||||
if (this._tree) {
|
if (this._tree) {
|
||||||
const selection = this._tree.getSelection();
|
const selection = this._tree.getSelection();
|
||||||
if (selection && selection.length === 1) {
|
if (selection && selection.length === 1) {
|
||||||
@@ -102,6 +101,8 @@ export class QueryHistoryView extends Disposable {
|
|||||||
|
|
||||||
if (nodes.length > 0) {
|
if (nodes.length > 0) {
|
||||||
hide(this._messages);
|
hide(this._messages);
|
||||||
|
} else {
|
||||||
|
show(this._messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the tree input - root node is just an empty container node
|
// Set the tree input - root node is just an empty container node
|
||||||
@@ -117,7 +118,6 @@ export class QueryHistoryView extends Disposable {
|
|||||||
if (selectedElement) {
|
if (selectedElement) {
|
||||||
this._tree.select(selectedElement);
|
this._tree.select(selectedElement);
|
||||||
}
|
}
|
||||||
this._tree.getFocus();
|
|
||||||
}, errors.onUnexpectedError);
|
}, errors.onUnexpectedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,4 +138,9 @@ export class QueryHistoryView extends Disposable {
|
|||||||
this._tree.onHidden();
|
this._tree.onHidden();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public getActions(): IAction[] {
|
||||||
|
return this._actionProvider.getActions(undefined);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,6 @@ export class QueryHistoryWorkbenchContribution implements IWorkbenchContribution
|
|||||||
constructor(
|
constructor(
|
||||||
@IQueryHistoryService _queryHistoryService: IQueryHistoryService
|
@IQueryHistoryService _queryHistoryService: IQueryHistoryService
|
||||||
) {
|
) {
|
||||||
// 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
|
|
||||||
_queryHistoryService.start();
|
|
||||||
|
|
||||||
// This feature is in preview so for now hide it behind a flag. We expose this as a command
|
// This feature is in preview so for now hide it behind a flag. We expose this as a command
|
||||||
// so that the query-history extension can call it. We eventually want to move all this into
|
// so that the query-history extension can call it. We eventually want to move all this into
|
||||||
// the extension itself so this should be a temporary workaround
|
// the extension itself so this should be a temporary workaround
|
||||||
@@ -38,6 +33,20 @@ export class QueryHistoryWorkbenchContribution implements IWorkbenchContribution
|
|||||||
// we don't want to try and register multiple times
|
// we don't want to try and register multiple times
|
||||||
if (!this.queryHistoryEnabled) {
|
if (!this.queryHistoryEnabled) {
|
||||||
this.queryHistoryEnabled = true;
|
this.queryHistoryEnabled = true;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
_queryHistoryService.start();
|
||||||
|
|
||||||
|
CommandsRegistry.registerCommand({
|
||||||
|
id: 'queryHistory.clear',
|
||||||
|
handler: (accessor) => {
|
||||||
|
const queryHistoryService = accessor.get(IQueryHistoryService);
|
||||||
|
queryHistoryService.clearQueryHistory();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
|
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
|
||||||
registry.registerWorkbenchAction(
|
registry.registerWorkbenchAction(
|
||||||
new SyncActionDescriptor(
|
new SyncActionDescriptor(
|
||||||
|
|||||||
Reference in New Issue
Block a user