GreenXenith / minetest-tools

Minetest extension for Visual Studio Code
MIT License
27 stars 6 forks source link

Optional automatic support of Material Icon Theme for minetest files and folder #34

Open AFCMS opened 1 year ago

AFCMS commented 1 year ago

https://marketplace.visualstudio.com/items?itemName=PKief.material-icon-theme

ex: textures folder should be mapped to the images icon instead of the default folder icon

GreenXenith commented 1 year ago

I think I used to do this with a user setting, I wasn't aware it was possible with an extension. Is there a way to make this generic rather than specific to this icon theme, or do we have to just specifically choose a subset to support?

AFCMS commented 1 year ago

I implemented a prototype in my local branch:

/**
 * Return true if Material Icon Theme configuration is configured for Minetest context in the {@linkcode vscode.WorkspaceFolder WorkspaceFolder}
 */
function getMaterialIconThemeSupport(): boolean {
  let r = vscode.workspace.getConfiguration("minetest-tools").get<boolean>("material-icon-theme-support");
  return r ? r : false;
}
import * as vscode from "vscode";
import { getMaterialIconThemeSupport } from "./settings";

const materialIconThemeConfigFolders = {
  textures: "images",
  models: "container",
};

/* eslint-disable @typescript-eslint/naming-convention */
const materialIconThemeConfigFiles = {
  "locale/template.txt": "i18n",
  "*.tr": "i18n",
};
/* eslint-enable @typescript-eslint/naming-convention */

function extensionPresent(): boolean {
  return vscode.extensions.getExtension("PKief.material-icon-theme") !== undefined;
}

/**
 * Update `Material Icon Theme` configuration if enabled in the workspace folder
 */
function updateMaterialIconTheme() {
  if (getMaterialIconThemeSupport() && extensionPresent()) {
    let config = vscode.workspace.getConfiguration("material-icon-theme");
    config.update("folders.associations", materialIconThemeConfigFolders);
    config.update("files.associations", materialIconThemeConfigFiles);
  }
}

export { updateMaterialIconTheme };

Basically it updates the associations in the workspace config if the workspace or user setting is true, the extension is present. The associations are only made in the workspace (the extension doesn't support workspace folder configuration for multi-folder workspaces sadly), so it doesn't conflict with any possible other usecase of the folder names (like models for databases)

I don't think we can use an association between a folder/file and an icon without depending on a theme extension. But since it should be optional and off by default we can support multiple extensions like this.