From 418a3445badd341c1ea9625559490e099072acb2 Mon Sep 17 00:00:00 2001 From: Noscere Date: Mon, 7 Nov 2022 02:19:09 +0000 Subject: [PATCH 1/3] Addressing issue #6, making assets location user-configurable via a new configuration setting, xmlEditor.resourcesPath, which is accessible via the File->Settings menu within VSCode. package.json: Add new configuration properties for xmlEditor.resourcesPath, as a string with a default value to match the existing hard-coded location (modified to reflect the standard location of /res/ rather than /resources/). Added a markdownDescription for this setting, which explains the default value and that this path is relative to the workspace root. Note that when you add settings (or remove them) into an extension package.json, you need to reboot vscode to re-build the settings menu, then reboot vscode a second time to actually see it. src/extension.ts: + Modified the createOrShow() function to get the configuration via vscode API, and get the resources path from the settings configuration object. If this path is not defined or empty, we fall back to the (modified) hard-coded path. + Replaced the hard-coded path with the new variable from the settings. This commit addresses issue #6, change 1. --- package.json | 12 ++++++++++++ src/extension.ts | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 09b9e37..a3d714c 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,18 @@ }, "main": "./out/extension.js", "contributes": { + "configuration": { + "type": "object", + "title": "Android XML Editor", + "properties": { + "xmlEditor.resourcesPath": { + "type": "string", + "default": "src/main/res/drawable", + "markdownDescription": "The location of project assets (**I.E.** *images & media*), relative to the root of the open workspace.\n\nThe default location is `src/main/res/drawable`", + "order": 1 + } + } + }, "configurationDefaults": { "[xml]": { "editor.mouseWheelZoom": true diff --git a/src/extension.ts b/src/extension.ts index 3236851..6c6d5ee 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -62,9 +62,15 @@ class AppPanel { let workspaceFolder = vscode.workspace.getWorkspaceFolder(editor.document.uri); let rootUri = workspaceFolder?.uri + let extensionConfig = vscode.workspace.getConfiguration('xmlEditor'); + let resourcesPath = extensionConfig?.resourcesPath; + if(!resourcesPath || resourcesPath == "") { + // fall back to hard-coded path + resourcesPath = "src/main/res/drawable"; + } const fse = require('fs-extra'); //@ts-ignore. - var sourceDir = path.join(rootUri?.path, "src/main/resources/drawable") + var sourceDir = path.join(rootUri?.path, resourcesPath) var destinationDir = path.join(extensionUri.path, "/media/drawable") fs.rmdirSync(destinationDir, { recursive: true }); From 06a422d9fab826c3139223b9589f0cab65d0966f Mon Sep 17 00:00:00 2001 From: Noscere Date: Mon, 7 Nov 2022 03:49:56 +0000 Subject: [PATCH 2/3] This fully addresses issue #5 and contributes to my issue #6 The /media/drawable directory does not exist when the extension is initially installed, yet the createOrShow() function calls fs.rmdirSync recursively, which throws an error on the non-existing drawable directory (media exists). I've wrapped this call up with an fs.existsSync, which will perform the existing action if the directory exists, otherwise it calls fs.mkdirSync with the same options as the call to fs.rmdirSync (i.e, recursive: true) The extension will now execute successfully on an initial install without the user having to create the subdirectory tree manually. --- src/extension.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 6c6d5ee..db2c24a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -68,12 +68,17 @@ class AppPanel { // fall back to hard-coded path resourcesPath = "src/main/res/drawable"; } + const fse = require('fs-extra'); //@ts-ignore. var sourceDir = path.join(rootUri?.path, resourcesPath) var destinationDir = path.join(extensionUri.path, "/media/drawable") - fs.rmdirSync(destinationDir, { recursive: true }); - + if (fs.existsSync(destinationDir)) { + fs.rmdirSync(destinationDir, { recursive: true }); + } else { + // Create cache location + fs.mkdirSync(destinationDir, { recursive: true }); + } // To copy a folder or file fse.copySync(sourceDir, destinationDir) From 743d9adf07a40cf0db6a7850ea567f0db069be1a Mon Sep 17 00:00:00 2001 From: Nos78 <44951782+Nos78@users.noreply.github.com> Date: Mon, 7 Nov 2022 18:10:17 +0000 Subject: [PATCH 3/3] Update README.md Added instructions for the new assets directory configuration. --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2391627..eeed9b5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ + 1 Closed +Author +Label +Projects Milestones +Assignee +Sort Issues list +Assets (& cache) location should be user configurable +#6 opened 16 hours ago by Nos78
android and totalcross logo together
@@ -29,9 +37,14 @@ Extension that interprets the XML file - transforming it into HTML - and display ## 🚨 Requirements * VS Code 1.47+; -* All images and media (assets) must be in this `src/main/resources/drawable` directory; +* By default, the plugin looks for images and media (assets) in this `src/main/res/drawable` directory; * **As this is an alpha version, the plugin only supports `content-layout`**. + +**NEW:** Resources Path now user-configurable +* The assets location can now be configured at the user (all workspaces) or per-workspace level by using vscode *File->Settings*, and navigating to *Android XML Editor* within the extensions tab. The new path should be relative to the workspace root. VSCode workspace settings override any user setting. +* **Example:** A workspace opened at `~/src/android/helloWorld/` contains the default android project sub-directories. The workspace resources path setting would need to be `app/src/main./res/drawable` + ## 👩‍💻 Using Android-XML-Editor plugin 1. Open your XML file on VSCode