Allow removing items from query history
This commit is contained in:
@@ -161,7 +161,11 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"command": "codeQLQueryHistory.openQuery",
|
"command": "codeQLQueryHistory.openQuery",
|
||||||
"title": "CodeQL: Open Query"
|
"title": "Open Query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "codeQLQueryHistory.removeHistoryItem",
|
||||||
|
"title": "Remove History Item"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"command": "codeQLQueryHistory.itemClicked",
|
"command": "codeQLQueryHistory.itemClicked",
|
||||||
@@ -196,6 +200,11 @@
|
|||||||
"command": "codeQLQueryHistory.openQuery",
|
"command": "codeQLQueryHistory.openQuery",
|
||||||
"group": "9_qlCommands",
|
"group": "9_qlCommands",
|
||||||
"when": "view == codeQLQueryHistory"
|
"when": "view == codeQLQueryHistory"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "codeQLQueryHistory.removeHistoryItem",
|
||||||
|
"group": "9_qlCommands",
|
||||||
|
"when": "view == codeQLQueryHistory"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"explorer/context": [
|
"explorer/context": [
|
||||||
@@ -235,6 +244,10 @@
|
|||||||
"command": "codeQLQueryHistory.openQuery",
|
"command": "codeQLQueryHistory.openQuery",
|
||||||
"when": "false"
|
"when": "false"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "codeQLQueryHistory.removeHistoryItem",
|
||||||
|
"when": "false"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "codeQLQueryHistory.itemClicked",
|
"command": "codeQLQueryHistory.itemClicked",
|
||||||
"when": "false"
|
"when": "false"
|
||||||
|
|||||||
@@ -115,6 +115,21 @@ class HistoryTreeDataProvider implements vscode.TreeDataProvider<QueryHistoryIte
|
|||||||
setCurrentItem(item: QueryHistoryItem) {
|
setCurrentItem(item: QueryHistoryItem) {
|
||||||
this.current = item;
|
this.current = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove(item: QueryHistoryItem) {
|
||||||
|
if (this.current === item)
|
||||||
|
this.current = undefined;
|
||||||
|
const index = this.history.findIndex(i => i === item);
|
||||||
|
if (index >= 0) {
|
||||||
|
this.history.splice(index, 1);
|
||||||
|
if (this.current === undefined && this.history.length > 0) {
|
||||||
|
// Try to keep a current item, near the deleted item if there
|
||||||
|
// are any available.
|
||||||
|
this.current = this.history[Math.min(index, this.history.length - 1)];
|
||||||
|
}
|
||||||
|
this._onDidChangeTreeData.fire();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -130,11 +145,27 @@ export class QueryHistoryManager {
|
|||||||
selectedCallback: ((item: QueryHistoryItem) => void) | undefined;
|
selectedCallback: ((item: QueryHistoryItem) => void) | undefined;
|
||||||
lastItemClick: { time: Date, item: QueryHistoryItem } | undefined;
|
lastItemClick: { time: Date, item: QueryHistoryItem } | undefined;
|
||||||
|
|
||||||
|
async invokeCallbackOn(queryHistoryItem: QueryHistoryItem) {
|
||||||
|
if (this.selectedCallback !== undefined) {
|
||||||
|
const sc = this.selectedCallback;
|
||||||
|
await sc(queryHistoryItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async handleOpenQuery(queryHistoryItem: QueryHistoryItem) {
|
async handleOpenQuery(queryHistoryItem: QueryHistoryItem) {
|
||||||
const textDocument = await vscode.workspace.openTextDocument(vscode.Uri.file(queryHistoryItem.info.query.program.queryPath));
|
const textDocument = await vscode.workspace.openTextDocument(vscode.Uri.file(queryHistoryItem.info.query.program.queryPath));
|
||||||
await vscode.window.showTextDocument(textDocument, vscode.ViewColumn.One);
|
await vscode.window.showTextDocument(textDocument, vscode.ViewColumn.One);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async handleRemoveHistoryItem(queryHistoryItem: QueryHistoryItem) {
|
||||||
|
this.treeDataProvider.remove(queryHistoryItem);
|
||||||
|
const current = this.treeDataProvider.getCurrent();
|
||||||
|
if (current !== undefined) {
|
||||||
|
this.treeView.reveal(current);
|
||||||
|
await this.invokeCallbackOn(current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async handleItemClicked(queryHistoryItem: QueryHistoryItem) {
|
async handleItemClicked(queryHistoryItem: QueryHistoryItem) {
|
||||||
this.treeDataProvider.setCurrentItem(queryHistoryItem);
|
this.treeDataProvider.setCurrentItem(queryHistoryItem);
|
||||||
|
|
||||||
@@ -150,10 +181,7 @@ export class QueryHistoryManager {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// show results on single click
|
// show results on single click
|
||||||
if (this.selectedCallback !== undefined) {
|
await this.invokeCallbackOn(queryHistoryItem);
|
||||||
const sc = this.selectedCallback;
|
|
||||||
await sc(queryHistoryItem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,6 +198,7 @@ export class QueryHistoryManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.openQuery', this.handleOpenQuery));
|
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.openQuery', this.handleOpenQuery));
|
||||||
|
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.removeHistoryItem', this.handleRemoveHistoryItem.bind(this)));
|
||||||
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.itemClicked', async (item) => {
|
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.itemClicked', async (item) => {
|
||||||
return this.handleItemClicked(item);
|
return this.handleItemClicked(item);
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user