Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to namespace nodes to create category folders #254

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,16 @@
"command": "intersystems-community.servermanager.viewWebApp",
"title": "View Files in Web Application",
"icon": "$(eye)"
},
{
"command": "intersystems-community.servermanager.editCategories",
"title": "Edit Code in Namespace by Category",
"icon": "$(list-tree)"
},
{
"command": "intersystems-community.servermanager.viewCategories",
"title": "View Code in Namespace by Category",
"icon": "$(list-tree)"
}
],
"submenus": [
Expand Down Expand Up @@ -503,6 +513,14 @@
{
"command": "intersystems-community.servermanager.viewWebApp",
"when": "false"
},
{
"command": "intersystems-community.servermanager.editCategories",
"when": "false"
},
{
"command": "intersystems-community.servermanager.viewCategories",
"when": "false"
}
],
"view/title": [
Expand Down Expand Up @@ -614,6 +632,12 @@
"command": "intersystems-community.servermanager.removeFromRecent",
"when": "view == intersystems-community_servermanager && viewItem =~ /^recent.server./",
"group": "2_manage@10"
},
{
"command": "intersystems-community.servermanager.editCategories",
"alt": "intersystems-community.servermanager.viewCategories",
"when": "view == intersystems-community_servermanager && viewItem =~ /namespace$/",
"group": "inline@30"
}
]
}
Expand Down
62 changes: 58 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,19 @@ export function activate(context: vscode.ExtensionContext) {
if (!isfsExtension.isActive) {
await isfsExtension.activate();
if (!isfsExtension.isActive) {
vscode.window.showErrorMessage(`${OBJECTSCRIPT_EXTENSIONID} could not be activated.`, "Close");
vscode.window.showErrorMessage(`${OBJECTSCRIPT_EXTENSIONID} could not be activated.`, "Dismiss");
return;
}
}
} else {
vscode.window.showErrorMessage(`${OBJECTSCRIPT_EXTENSIONID} is not installed.`, "Close");
vscode.window.showErrorMessage(`${OBJECTSCRIPT_EXTENSIONID} is not installed.`, "Dismiss");
return;
}

const params = [csp ? "csp" : "", project ? `project=${project}` : ""].filter(e => e != "").join("&");
const uri = vscode.Uri.parse(`isfs${readonly ? "-readonly" : ""}://${serverName}:${namespace}${csp && webApp ? webApp : "/"}${params ? `?${params}` : ""}`);
if ((vscode.workspace.workspaceFolders || []).filter((workspaceFolder) => workspaceFolder.uri.toString() === uri.toString()).length === 0) {
const uriString = uri.toString(true);
if (!(vscode.workspace.workspaceFolders || []).some((workspaceFolder) => workspaceFolder.uri.toString(true) == uriString)) {
const label = `${project ? `${project} - ${serverName}:${namespace}` : !csp ? `${serverName}:${namespace}` : ["", "/"].includes(uri.path) ? `${serverName}:${namespace} web files` : `${serverName} (${uri.path})`}${readonly && project == undefined ? " (read-only)" : ""}`;
const added = vscode.workspace.updateWorkspaceFolders(
vscode.workspace.workspaceFolders ? vscode.workspace.workspaceFolders.length : 0,
Expand All @@ -291,7 +292,7 @@ export function activate(context: vscode.ExtensionContext) {
if (added) {
await view.addToRecents(serverName);
} else {
vscode.window.showErrorMessage(`Folder ${uri.toString()} could not be added.`, "Close");
vscode.window.showErrorMessage(`Folder ${uriString} could not be added.`, "Dismiss");
}
}
// Switch to Explorer view and focus on the folder
Expand Down Expand Up @@ -353,6 +354,59 @@ export function activate(context: vscode.ExtensionContext) {
})
);

const addCategoriesFolders = async (namespaceTreeItem?: NamespaceTreeItem, readonly = false) => {
if (!namespaceTreeItem) return;
const idArray = namespaceTreeItem.id?.split(':');
if (!idArray || idArray?.length != 4) return;
const serverId = idArray[1];
const namespace = idArray[3];
const serverSpec = await getServerSpec(serverId);
if (!serverSpec) return;
const isfsExtension = vscode.extensions.getExtension(OBJECTSCRIPT_EXTENSIONID);
if (isfsExtension) {
if (!isfsExtension.isActive) {
await isfsExtension.activate();
if (!isfsExtension.isActive) {
vscode.window.showErrorMessage(`${OBJECTSCRIPT_EXTENSIONID} could not be activated.`, "Dismiss");
return;
}
}
} else {
vscode.window.showErrorMessage(`${OBJECTSCRIPT_EXTENSIONID} is not installed.`, "Dismiss");
return;
}

const baseUri = vscode.Uri.from({ scheme: `isfs${readonly ? "-readonly" : ""}`, authority: `${serverId}:${namespace.toLowerCase()}` });
const folders: Array<{ name: string, uri: vscode.Uri }> = [];
folders.push({
name: `${serverId}:${namespace} > Classes${readonly ? " (read-only)" : ""}`,
uri: baseUri.with({ query: 'filter=*.cls' })
});
folders.push({
name: `${serverId}:${namespace} > Routines${readonly ? " (read-only)" : ""}`,
uri: baseUri.with({ query: 'filter=*.mac,*.inc,*.int,*.bas,*.mvb,*.mvi' })
});
folders.push({
name: `${serverId}:${namespace} > Web${readonly ? " (read-only)" : ""}`,
uri: baseUri.with({ query: 'csp' })
});
folders.push({
name: `${serverId}:${namespace} > Other${readonly ? " (read-only)" : ""}`,
uri: baseUri.with({ query: "filter=*.other" })
});

if (vscode.workspace.updateWorkspaceFolders(vscode.workspace.workspaceFolders?.length ?? 0, null, ...folders)) {
await view.addToRecents(serverId);
} else {
vscode.window.showErrorMessage("Failed to add folders.", "Dismiss");
}
};

context.subscriptions.push(
vscode.commands.registerCommand("intersystems-community.servermanager.editCategories", (item) => { addCategoriesFolders(item) }),
vscode.commands.registerCommand("intersystems-community.servermanager.viewCategories", (item) => { addCategoriesFolders(item, true) })
);

// Listen for relevant configuration changes
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration("intersystems.servers") || e.affectsConfiguration("objectscript.conn")) {
Expand Down