Browse Source

Fixes issue with toggling "Compile on Save" menu item. Now it no longer removes and re-adds the entire menu, but just updates the text of the menu item.

Shaddock Heath 9 years ago
parent
commit
851030e2a6

+ 14 - 7
Script/AtomicEditor/hostExtensions/languageExtensions/TypscriptLanguageExtension.ts

@@ -35,6 +35,9 @@ export default class TypescriptLanguageExtension implements Editor.HostExtension
      */
     private isTypescriptProject = false;
     private serviceRegistry: Editor.HostExtensions.HostServiceLocator = null;
+    private extensionMenu: Atomic.UIMenuItemSource = null;
+    private compileOnSaveMenuItem: Atomic.UIMenuItem;
+
     /**
      * Determines if the file name/path provided is something we care about
      * @param  {string} path
@@ -197,22 +200,26 @@ export default class TypescriptLanguageExtension implements Editor.HostExtension
         this.rebuildMenu();
     }
 
-
     /**
      * Rebuilds the plugin menu.  This is needed to toggle the CompileOnSave true or false
      */
     rebuildMenu() {
         if (this.isTypescriptProject) {
-            this.serviceRegistry.uiServices.removePluginMenuItemSource("TypeScript");
+
+            if (!this.extensionMenu) {
+                // First build up an empty menu then manually add the items so we can have reference to them
+                this.extensionMenu = this.serviceRegistry.uiServices.createPluginMenuItemSource("TypeScript", {});
+                this.compileOnSaveMenuItem = new Atomic.UIMenuItem("Compile on Save", `${this.name}.compileonsave`);
+                this.extensionMenu.addItem(this.compileOnSaveMenuItem);
+                this.extensionMenu.addItem(new Atomic.UIMenuItem("Compile Project", `${this.name}.compileproject`));
+            }
+
             const isCompileOnSave = this.serviceRegistry.projectServices.getUserPreference(this.name, "CompileOnSave", false);
-            let subMenu = {};
             if (isCompileOnSave) {
-                subMenu["Compile on Save: On"] = [`${this.name}.compileonsave`];
+                this.compileOnSaveMenuItem.string = "Compile on Save: On";
             } else {
-                subMenu["Compile on Save: Off"] = [`${this.name}.compileonsave`];
+                this.compileOnSaveMenuItem.string = "Compile on Save: Off";
             }
-            subMenu["Compile Project"] = [`${this.name}.compileproject`];
-            this.serviceRegistry.uiServices.createPluginMenuItemSource("TypeScript", subMenu);
         }
     }