Skip to content

Commit 15f38c6

Browse files
committed
Add icons for various query history view commands
And show these commands in the title bar.
1 parent 4adbfa4 commit 15f38c6

8 files changed

Lines changed: 89 additions & 13 deletions

File tree

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

extensions/ql-vscode/package.json

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,27 @@
295295
},
296296
{
297297
"command": "codeQLQueryHistory.openQuery",
298-
"title": "Open Query"
298+
"title": "Open Query",
299+
"icon": {
300+
"light": "media/light/edit.svg",
301+
"dark": "media/dark/edit.svg"
302+
}
299303
},
300304
{
301-
"command": "codeQLQueryHistory.removeHistoryItem",
302-
"title": "Remove History Item"
305+
"command": "codeQLQueryHistory.itemClicked",
306+
"title": "Open Query Results",
307+
"icon": {
308+
"light": "media/light/preview.svg",
309+
"dark": "media/dark/preview.svg"
310+
}
303311
},
304312
{
305-
"command": "codeQLQueryHistory.itemClicked",
306-
"title": "Query History Item"
313+
"command": "codeQLQueryHistory.removeHistoryItem",
314+
"title": "Remove History Item(s)",
315+
"icon": {
316+
"light": "media/light/trash.svg",
317+
"dark": "media/dark/trash.svg"
318+
}
307319
},
308320
{
309321
"command": "codeQLQueryHistory.showQueryLog",
@@ -390,6 +402,21 @@
390402
"when": "view == codeQLDatabases",
391403
"group": "navigation"
392404
},
405+
{
406+
"command": "codeQLQueryHistory.openQuery",
407+
"when": "view == codeQLQueryHistory",
408+
"group": "navigation"
409+
},
410+
{
411+
"command": "codeQLQueryHistory.itemClicked",
412+
"when": "view == codeQLQueryHistory",
413+
"group": "navigation"
414+
},
415+
{
416+
"command": "codeQLQueryHistory.removeHistoryItem",
417+
"when": "view == codeQLQueryHistory",
418+
"group": "navigation"
419+
},
393420
{
394421
"command": "codeQLAstViewer.clear",
395422
"when": "view == codeQLAstViewer && config.codeQL.experimentalAstViewer == true",

extensions/ql-vscode/src/query-history.ts

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,19 +289,20 @@ export class QueryHistoryManager {
289289
singleItem: CompletedQuery,
290290
multiSelect: CompletedQuery[]
291291
): Promise<void> {
292-
if (!this.assertSingleQuery(multiSelect)) {
292+
const { finalSingleItem, finalMultiSelect } = this.determineSelection(singleItem, multiSelect);
293+
if (!this.assertSingleQuery(finalMultiSelect)) {
293294
return;
294295
}
295296

296297
const textDocument = await vscode.workspace.openTextDocument(
297-
vscode.Uri.file(singleItem.query.program.queryPath)
298+
vscode.Uri.file(finalSingleItem.query.program.queryPath)
298299
);
299300
const editor = await vscode.window.showTextDocument(
300301
textDocument,
301302
vscode.ViewColumn.One
302303
);
303-
const queryText = singleItem.options.queryText;
304-
if (queryText !== undefined && singleItem.options.isQuickQuery) {
304+
const queryText = finalSingleItem.options.queryText;
305+
if (queryText !== undefined && finalSingleItem.options.isQuickQuery) {
305306
await editor.edit((edit) =>
306307
edit.replace(
307308
textDocument.validateRange(
@@ -317,7 +318,9 @@ export class QueryHistoryManager {
317318
singleItem: CompletedQuery,
318319
multiSelect: CompletedQuery[]
319320
) {
320-
(multiSelect || [singleItem]).forEach((item) => {
321+
const { finalSingleItem, finalMultiSelect } = this.determineSelection(singleItem, multiSelect);
322+
323+
(finalMultiSelect || [finalSingleItem]).forEach((item) => {
321324
this.treeDataProvider.remove(item);
322325
item.dispose();
323326
});
@@ -375,14 +378,15 @@ export class QueryHistoryManager {
375378
singleItem: CompletedQuery,
376379
multiSelect: CompletedQuery[]
377380
) {
378-
if (!this.assertSingleQuery(multiSelect)) {
381+
const { finalSingleItem, finalMultiSelect } = this.determineSelection(singleItem, multiSelect);
382+
if (!this.assertSingleQuery(finalMultiSelect)) {
379383
return;
380384
}
381-
this.treeDataProvider.setCurrentItem(singleItem);
385+
this.treeDataProvider.setCurrentItem(finalSingleItem);
382386

383387
const now = new Date();
384388
const prevItemClick = this.lastItemClick;
385-
this.lastItemClick = { time: now, item: singleItem };
389+
this.lastItemClick = { time: now, item: finalSingleItem };
386390

387391
if (
388392
prevItemClick !== undefined &&
@@ -629,6 +633,33 @@ the file in the file explorer and dragging it into the workspace.`
629633
}
630634
}
631635

636+
/**
637+
* If no items are selected, attempt to grab the selection from the treeview.
638+
* We need to use this method because when clicking on commands from the view title
639+
* bar, the selections are not passed in.
640+
*
641+
* @param singleItem the single item selected, or undefined if no item is selected
642+
* @param multiSelect a multi-select or undefined if no items are selected
643+
*/
644+
private determineSelection(
645+
singleItem: CompletedQuery,
646+
multiSelect: CompletedQuery[]
647+
): { finalSingleItem: CompletedQuery; finalMultiSelect: CompletedQuery[] } {
648+
if (singleItem === undefined && (multiSelect === undefined || multiSelect.length === 0 || multiSelect[0] === undefined)) {
649+
const selection = this.treeView.selection;
650+
if (selection) {
651+
return {
652+
finalSingleItem: selection[0],
653+
finalMultiSelect: selection
654+
};
655+
}
656+
}
657+
return {
658+
finalSingleItem: singleItem,
659+
finalMultiSelect: multiSelect
660+
};
661+
}
662+
632663
async updateTreeItemContextValue(element: CompletedQuery): Promise<void> {
633664
this.treeDataProvider.updateTreeItemContextValue(element);
634665
}

0 commit comments

Comments
 (0)