Skip to content

Commit

Permalink
Introduce Separate Assay Sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstinalin authored and willdurand committed Jul 9, 2024
1 parent 087359b commit aaca245
Show file tree
Hide file tree
Showing 15 changed files with 443 additions and 55 deletions.
1 change: 1 addition & 0 deletions media/assay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/tabler-icons.woff
Binary file not shown.
159 changes: 139 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,64 @@
],
"main": "./dist/extension.js",
"contributes": {
"icons": {
"assay-edit": {
"description": "edit",
"default": {
"fontPath": "media/tabler-icons.woff",
"fontCharacter": "\\eb04"
}
},
"assay-export": {
"description": "export",
"default": {
"fontPath": "media/tabler-icons.woff",
"fontCharacter": "\\eb47"
}
},
"assay-share": {
"description": "share",
"default": {
"fontPath": "media/tabler-icons.woff",
"fontCharacter": "\\eb21"
}
},
"assay-delete": {
"description": "close",
"default": {
"fontPath": "media/tabler-icons.woff",
"fontCharacter": "\\eb55"
}
},
"assay-add": {
"description": "add",
"default": {
"fontPath": "media/tabler-icons.woff",
"fontCharacter": "\\eb0b"
}
},
"assay-addon": {
"description": "addon",
"default": {
"fontPath": "media/tabler-icons.woff",
"fontCharacter": "\\eb10"
}
},
"assay-refresh": {
"description": "refresh",
"default": {
"fontPath": "media/tabler-icons.woff",
"fontCharacter": "\\eb13"
}
},
"assay-view": {
"description": "view",
"default": {
"fontPath": "media/tabler-icons.woff",
"fontCharacter": "\\fb79"
}
}
},
"configuration": {
"title": "Assay",
"properties": {
Expand All @@ -43,6 +101,34 @@
}
},
"menus": {
"view/title": [
{
"command": "assay.get",
"group": "navigation@2",
"when": "view == assayCommands"
},
{
"command": "assay.refresh",
"group": "navigation@1",
"when": "view == assayCommands"
}

],
"view/item/context": [
{
"command": "assay.sidebarDiff",
"when": "viewItem !== guidDirectory && view == assayCommands && listDoubleSelection"
},
{
"command": "assay.sidebarDelete",
"when": "view == assayCommands"
},
{
"command": "assay.viewAddon",
"group": "inline",
"when": "viewItem !== guidDirectory && view == assayCommands"
}
],
"explorer/context": [
{

Expand All @@ -51,7 +137,6 @@
"when": "assay.commentsEnabled && explorerResourceIsFolder && listDoubleSelection"
},
{

"command": "assay.exportCommentsFromContext",
"group": "navigation",
"when": "assay.commentsEnabled && explorerResourceIsFolder"
Expand Down Expand Up @@ -112,14 +197,29 @@
}
]
},
"viewsContainers": {
"activitybar": [
{
"id": "assay-menu",
"title": "Assay",
"icon": "media/assay.svg"
}
]
},
"views": {
"explorer": [
"assay-menu": [
{
"id": "assayCommands",
"name": "Assay"
"name": "Addons"
}
]
},
"viewsWelcome": [
{
"view": "assayCommands",
"contents": "You do not have any addons installed.\n[+ Review New Addon](command:assay.get)\n In order to use Assay, you must generate an API key and secret in the [Reviewer Tools](https://addons.mozilla.org/en-US/firefox/) section of AMO. \n[Enter API Key](command:assay.getApiKey)\n[Enter Secret](command:assay.getSecret)\nYou can [Test API Credentials](command:assay.testApiCredentials) if needed.\nNew to Assay? [View Instructions](command:assay.welcome)"
}
],
"commands": [
{
"command": "assay.welcome",
Expand All @@ -141,6 +241,37 @@
"command": "assay.checkForUpdates",
"title": "(Assay) Check For Updates"
},
{
"command": "assay.get",
"title": "(Assay) Review New Addon",
"icon": "$(assay-add)"
},
{
"command": "assay.refresh",
"title": "Refresh Addons",
"icon": "$(assay-refresh)"
},
{
"command": "assay.sidebarDiff",
"title": "Open Versions in Diff Tool"
},
{
"command": "assay.sidebarDelete",
"title": "Delete"
},
{
"command": "assay.viewAddon",
"title": "View Addon in New Window",
"icon": "$(assay-view)"
},
{
"command": "assay.getApiKey",
"title": "(Assay) Enter API Key"
},
{
"command": "assay.getSecret",
"title": "(Assay) Enter Secret Key"
},
{
"command": "assay.copyLinkFromReply",
"title": "Copy Link"
Expand All @@ -152,18 +283,12 @@
{
"command": "assay.editComment",
"title": "Edit Comment",
"icon": {
"dark": "media/commentIcons/edit_inverse.svg",
"light": "media/commentIcons/edit.svg"
}
"icon": "$(assay-edit)"
},
{
"command": "assay.deleteComment",
"title": "Delete",
"icon": {
"dark": "media/commentIcons/close_inverse.svg",
"light": "media/commentIcons/close.svg"
}
"icon": "$(assay-delete)"
},
{
"command": "assay.saveComment",
Expand All @@ -180,18 +305,12 @@
{
"command": "assay.exportComments",
"title": "Export Version Comments",
"icon": {
"dark": "media/commentIcons/export_inverse.svg",
"light": "media/commentIcons/export.svg"
}
"icon": "$(assay-export)"
},
{
"command": "assay.copyLinkFromThread",
"title": "Copy Link",
"icon": {
"dark": "media/commentIcons/link_inverse.svg",
"light": "media/commentIcons/link.svg"
}
"icon": "$(assay-share)"
}
]
},
Expand Down Expand Up @@ -255,4 +374,4 @@
"jsonwebtoken": "^9.0.1",
"jszip": "^3.10.1"
}
}
}
6 changes: 5 additions & 1 deletion src/controller/addonController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as vscode from "vscode";
import { AddonCacheController } from "./addonCacheController";
import { CredentialController } from "./credentialController";
import { DirectoryController } from "./directoryController";
import { SidebarController } from "./sidebarController";
import constants from "../config/config";
import { AddonInfoResponse, AddonVersion, ErrorMessages } from "../types";
import { AddonView } from "../views/addonView";
Expand All @@ -15,7 +16,8 @@ export class AddonController {
constructor(
private credentialController: CredentialController,
private addonCacheController: AddonCacheController,
private directoryController: DirectoryController
private directoryController: DirectoryController,
private sidebarController: SidebarController
) {}

/**
Expand Down Expand Up @@ -100,6 +102,8 @@ export class AddonController {
`${workspaceFolder}/${guid}/${version}`
);

this.sidebarController.refresh();

return { workspaceFolder, guid, version };
} catch (error) {
console.error(error);
Expand Down
16 changes: 14 additions & 2 deletions src/controller/diffController.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import { spawn } from "child_process";
import * as vscode from "vscode";

import { AddonTreeItem } from "../model/sidebarTreeDataProvider";
import { DiffView } from "../views/diffView";

export class DiffController {
/**
* Open an addon for view from a TreeView<AddonTreeItem>.
* @param _ The specific AddonTreeItem the user opened the context menu on.
* @param list Selected AddonTreeItems
* @returns Whether the diff tool successfully launched.
*/
async diffFromSidebar(_: unknown, list: AddonTreeItem[]) {
const [first, second] = list;
return this.openInDiffTool([first.uri, second.uri]);
}

/**
* Launches the external diff tool.
* @param uris The files to compare.
* @returns Whether the diff tool successfully launched.
*/
async openInDiffTool(uris: [vscode.Uri, vscode.Uri]) {
private async openInDiffTool(uris: [vscode.Uri, vscode.Uri]) {
const [left, right] = uris;
const leftUri = vscode.Uri.parse(left.toString());
const rightUri = vscode.Uri.parse(right.toString());
Expand Down Expand Up @@ -48,7 +60,7 @@ export class DiffController {
*/
private async setDiffCommand() {
try {
const input = await DiffView.promptDiffCommand();
const input = DiffView.promptDiffCommand();
const config = vscode.workspace.getConfiguration("assay");
await config.update("diffTool", input, true);
return input;
Expand Down
15 changes: 15 additions & 0 deletions src/controller/directoryController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from "fs";
import * as vscode from "vscode";

import { AddonTreeItem } from "../model/sidebarTreeDataProvider";
import { FilesReadonlyIncludeConfig } from "../types";
import { RootView } from "../views/rootView";

Expand Down Expand Up @@ -100,6 +101,20 @@ export class DirectoryController {
}
}

/**
* Deletes the associated uri of all selected AddonTreeItems.
* @param list Selected AddonTreeItems
* @returns whether all were successfully deleted.
*/
static async deleteUri(list: AddonTreeItem[]) {
let success = false;
list.forEach(async (item) => {
await vscode.workspace.fs.delete(item.uri, { recursive: true });
success = true;
});
return success;
}

/**
* Sets the root to read-only.
*/
Expand Down
35 changes: 35 additions & 0 deletions src/controller/sidebarController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as vscode from "vscode";

import { DirectoryController } from "./directoryController";
import { AddonTreeDataProvider, AddonTreeItem } from "../model/sidebarTreeDataProvider";

export class SidebarController {
public refresh: () => void;
public treeView: vscode.TreeView<vscode.TreeItem>;

constructor(public id: string, rootFolderPath: string) {
const treeProvider = new AddonTreeDataProvider(rootFolderPath);

this.refresh = () => {
treeProvider.refresh();
};

this.treeView = vscode.window.createTreeView(this.id, {
treeDataProvider: treeProvider,
canSelectMany: true,
});
}

/**
* Deletes the selected uris and refreshes the sidebar.
* @param treeItem The specific AddonTreeItem the user opened the context menu on.
* @param list Selected AddonTreeItems
* @returns whether all were successfully deleted.
*/
async delete(treeItem: AddonTreeItem, list: AddonTreeItem[] | undefined) {
list = list || [treeItem];
const result = await DirectoryController.deleteUri(list);
this.refresh();
return result;
}
}
12 changes: 12 additions & 0 deletions src/controller/urlController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as vscode from "vscode";
import { AddonController } from "./addonController";
import { DirectoryController } from "./directoryController";
import { RangeHelper } from "../helper/rangeHelper";
import { AddonTreeItem } from "../model/sidebarTreeDataProvider";

export class UrlController implements vscode.UriHandler {
constructor(
Expand All @@ -12,6 +13,17 @@ export class UrlController implements vscode.UriHandler {
private directoryController: DirectoryController
) {}

/**
* Open an addon for view from a TreeView<AddonTreeItem>.
* @param item the user-chosen add-on.
*/
async viewAddon(item: AddonTreeItem) {
const { versionPath } = await this.directoryController.splitUri(item.uri);
if (versionPath) {
this.openWorkspace(versionPath);
}
}

/**
* Given a file and line(s), focuses VS Code onto the file and line(s).
* @param uri The URI of the file.
Expand Down
Loading

0 comments on commit aaca245

Please sign in to comment.