Pārlūkot izejas kodu

Improved options handling

Namal Bambarasinghe 3 gadi atpakaļ
vecāks
revīzija
4f6e4e388d
4 mainītis faili ar 32 papildinājumiem un 36 dzēšanām
  1. 6 12
      assets/explorer.lua
  2. 4 4
      assets/explorer/options.js
  3. 12 0
      package.json
  4. 10 20
      src/explorer.ts

+ 6 - 12
assets/explorer.lua

@@ -9,11 +9,11 @@ function main ()
     config.load()
     -- config.dump()
 
-    --local f = io.open("project.txt", "w")
-    --local original_output = io.output()
-    --io.output(f)
-    --print(project.options())
-    --io.output(original_output)
+    -- local f = io.open("project.txt", "w")
+    -- local original_output = io.output()
+    -- io.output(f)
+    -- print(project.options())
+    -- io.output(original_output)
 
     print("{")
     print("  \"targets\":[")
@@ -101,13 +101,7 @@ function main ()
             end 
 
             print("      \"name\":\"%s\",", name)
-
-            local default = "auto"
-            if option:get("default") ~= nil then
-                default = option:get("default")
-            end
-
-            print("      \"default\":\"%s\",", default)
+            print("      \"value\":\"%s\",", config.get(name))
 
             print("      \"values\":[")
 

+ 4 - 4
assets/explorer/options.js

@@ -49,7 +49,7 @@
             labelItem.textContent = option.name;
             optionsItem.append(labelItem);
 
-            const optionValues = findOptionValues(option.default, option.values);
+            const optionValues = findOptionValues(option.value, option.values);
 
             // create the value input
             // if there is a list of values then a drop down combo is used
@@ -66,7 +66,7 @@
                     optionElement.value = value;
                     optionElement.textContent = value;
 
-                    if(option.default == value)
+                    if(option.value == value)
                         optionElement.selected = true;
 
                     selectItem.append(optionElement);
@@ -80,7 +80,7 @@
                 const inputItem = document.createElement("input");
                 inputItem.id = option.name + "Input";
                 inputItem.type = "text";
-                inputItem.value = option.default;
+                inputItem.value = option.value;
                 inputItem.oninput = onOptionsChange;
                 optionsItem.append(inputItem);
             }
@@ -110,7 +110,7 @@
     // Otherwise a list cannot be formed, a text input needs to be shown instead of a select.
     function findOptionValues(defaultValue, values){
         if(values.length > 0)
-            return defaultValue;
+            return values;
         else if(defaultValue == 'y' || defaultValue == 'n')
             return ['y', 'n'];
         else if(defaultValue == 'yes' || defaultValue == 'no')

+ 12 - 0
package.json

@@ -264,6 +264,13 @@
         "title": "Debug",
         "category": "XMake",
         "enablement": "view == xmakeExplorer"
+      },
+      {
+        "command": "xmakeExplorer.configure",
+        "title": "Configure",
+        "category": "XMake",
+        "enablement": "view == xmakeOptions",
+        "icon": "$(gear)"
       }
     ],
     "menus": {
@@ -352,6 +359,11 @@
         {
           "command": "xmakeExplorer.runAll",
           "when": "view == xmakeExplorer"
+        },
+        {
+          "command": "xmakeExplorer.configure",
+          "when": "view == xmakeOptions",
+          "group": "navigation"
         }
       ],
       "view/item/context": [

+ 10 - 20
src/explorer.ts

@@ -542,7 +542,6 @@ class XMakeOptionsProvider implements vscode.WebviewViewProvider {
             switch (message.type) {
                 case 'options':
                     {
-                        console.log(message.data);
                         this._optionValues = message.data;
                         this._optionsChanged = true;
                         break;
@@ -558,13 +557,13 @@ class XMakeOptionsProvider implements vscode.WebviewViewProvider {
 
     public async refresh(optionDefinitions: any) {
         this._optionDefinitions = optionDefinitions;
-        this.updateDefaults();
+
         this.extractOptionValues();
+        this._optionsChanged = false;
 
         if (this._view)
             this._view.webview.postMessage({ type: 'options', data: optionDefinitions });
 
-        this._optionsChanged = true;
     }
 
     // Return the options string suitable for the xmake command
@@ -585,19 +584,6 @@ class XMakeOptionsProvider implements vscode.WebviewViewProvider {
         this._optionsChanged = changed;
     }
 
-    // Copy values from optionValues to optionDefinitions so that next refresh is going to show the correct values
-
-    private updateDefaults() {
-        if (!this._optionValues)
-            return;
-
-        for (let option of this._optionValues) {
-            const definition = this._optionDefinitions.find(def => def.name = option.name);
-            if (definition)
-                definition.default = option.value;
-        }
-    }
-
     // Extract option values from option definitions. This is done when new option definitions are received so add/remove options from option values.
 
     private extractOptionValues() {
@@ -609,7 +595,7 @@ class XMakeOptionsProvider implements vscode.WebviewViewProvider {
 
         // re-populate option values
         for (let option of this._optionDefinitions) {
-            this._optionValues.push({ name: option.name, value: option.default });
+            this._optionValues.push({ name: option.name, value: option.value });
         }
     }
 
@@ -701,9 +687,9 @@ export class XMakeExplorer implements vscode.Disposable {
         // Open file command for files in the tree view
 
         vscode.commands.registerCommand('xmakeExplorer.openFile', (file_path: string) => {
-            const uri = vscode.Uri.file(file_path);
-            vscode.workspace.openTextDocument(uri).then(doc => vscode.window.showTextDocument(uri));
-        }
+                const uri = vscode.Uri.file(file_path);
+                vscode.workspace.openTextDocument(uri).then(doc => vscode.window.showTextDocument(uri));
+            }
         );
 
         // Options panel
@@ -766,6 +752,10 @@ export class XMakeExplorer implements vscode.Disposable {
                 vscode.commands.executeCommand("xmake.onDebug", item.info.target);
             }
         });
+
+        vscode.commands.registerCommand('xmakeExplorer.configure', (item: XMakeExplorerItem) => {
+                vscode.commands.executeCommand("xmake.onConfigure");
+        });
     }
 
     dispose() {