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
@@ -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
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..db2c24a 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -62,12 +62,23 @@ 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 });
-
+ 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)