Browse Source

Save and Load Improvements

Saving and Loading now support Taml files. This also fixes a number of problems with the first responder. It also get's most of the Layout menu items working.
Peter Robinson 2 years ago
parent
commit
d8306ac011

+ 29 - 23
editor/EditorCore/EditorCore.cs

@@ -96,7 +96,7 @@ function EditorCore::initGui(%this)
 			Active = "0";
 			Active = "0";
 
 
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
-				Text = "New Gui...";
+				Text = "New Gui";
 				Command = "GuiEditor.NewGui();";
 				Command = "GuiEditor.NewGui();";
 				Accelerator = "Ctrl N";
 				Accelerator = "Ctrl N";
 			};
 			};
@@ -111,6 +111,11 @@ function EditorCore::initGui(%this)
 				Command = "GuiEditor.SaveGui();";
 				Command = "GuiEditor.SaveGui();";
 				Accelerator = "Ctrl S";
 				Accelerator = "Ctrl S";
 			};
 			};
+			new GuiMenuItemCtrl() {
+				Text = "Save Gui As...";
+				Command = "GuiEditor.SaveGuiAs();";
+				Accelerator = "Ctrl-Shift S";
+			};
 		};
 		};
 		new GuiMenuItemCtrl() {
 		new GuiMenuItemCtrl() {
 			Text = "Edit";
 			Text = "Edit";
@@ -157,48 +162,38 @@ function EditorCore::initGui(%this)
 				Command = "GuiEditor.brain.moveSelection(0,1);";
 				Command = "GuiEditor.brain.moveSelection(0,1);";
 				Accelerator = "Down";
 				Accelerator = "Down";
 			};
 			};
-			new GuiMenuItemCtrl() {
-				Text = "Nudge Right";
-				Command = "GuiEditor.brain.moveSelection(1,0);";
-				Accelerator = "Right";
-			};
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
 				Text = "Nudge Left";
 				Text = "Nudge Left";
 				Command = "GuiEditor.brain.moveSelection(-1,0);";
 				Command = "GuiEditor.brain.moveSelection(-1,0);";
 				Accelerator = "Left";
 				Accelerator = "Left";
 			};
 			};
-			new GuiMenuItemCtrl() { Text = "-"; };
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
-				Text = "Expand Height";
-				Command = "GuiEditor.changeExtent(0, 1)";
-				Accelerator = "Ctrl Up";
+				Text = "Nudge Right";
+				Command = "GuiEditor.brain.moveSelection(1,0);";
+				Accelerator = "Right";
 			};
 			};
+			new GuiMenuItemCtrl() { Text = "-"; };
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
 				Text = "Shrink Height";
 				Text = "Shrink Height";
 				Command = "GuiEditor.changeExtent(0,-1);";
 				Command = "GuiEditor.changeExtent(0,-1);";
-				Accelerator = "Ctrl Down";
+				Accelerator = "Ctrl Up";
 			};
 			};
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
-				Text = "Expand Width";
-				Command = "GuiEditor.changeExtent(1,0);";
-				Accelerator = "Ctrl Right";
+				Text = "Expand Height";
+				Command = "GuiEditor.changeExtent(0, 1);";
+				Accelerator = "Ctrl Down";
 			};
 			};
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
 				Text = "Shrink Width";
 				Text = "Shrink Width";
 				Command = "GuiEditor.changeExtent(-1,0);";
 				Command = "GuiEditor.changeExtent(-1,0);";
 				Accelerator = "Ctrl Left";
 				Accelerator = "Ctrl Left";
 			};
 			};
-			new GuiMenuItemCtrl() { Text = "-"; };
-			new GuiMenuItemCtrl() {
-				Text = "Align Left";
-				Command = "GuiEditor.brain.Justify(0);";
-				Accelerator = "Ctrl L";
-			};
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
-				Text = "Align Right";
-				Command = "GuiEditor.brain.Justify(2);";
-				Accelerator = "Ctrl R";
+				Text = "Expand Width";
+				Command = "GuiEditor.changeExtent(1,0);";
+				Accelerator = "Ctrl Right";
 			};
 			};
+			new GuiMenuItemCtrl() { Text = "-"; };
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
 				Text = "Align Top";
 				Text = "Align Top";
 				Command = "GuiEditor.brain.Justify(3);";
 				Command = "GuiEditor.brain.Justify(3);";
@@ -209,6 +204,16 @@ function EditorCore::initGui(%this)
 				Command = "GuiEditor.brain.Justify(4);";
 				Command = "GuiEditor.brain.Justify(4);";
 				Accelerator = "Ctrl B";
 				Accelerator = "Ctrl B";
 			};
 			};
+			new GuiMenuItemCtrl() {
+				Text = "Align Left";
+				Command = "GuiEditor.brain.Justify(0);";
+				Accelerator = "Ctrl L";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Align Right";
+				Command = "GuiEditor.brain.Justify(2);";
+				Accelerator = "Ctrl R";
+			};
 			new GuiMenuItemCtrl() { Text = "-"; };
 			new GuiMenuItemCtrl() { Text = "-"; };
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
 				Text = "Center Horizontally";
 				Text = "Center Horizontally";
@@ -237,6 +242,7 @@ function EditorCore::initGui(%this)
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
 				Text = "Set Grid Size...";
 				Text = "Set Grid Size...";
 				Command = "GuiEditor.SetGridSize();";
 				Command = "GuiEditor.SetGridSize();";
+				Accelerator = "Ctrl-Shift G";
 			};
 			};
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
 				Text = "Snap to Grid";
 				Text = "Snap to Grid";

+ 3 - 0
editor/EditorCore/Themes/BaseTheme/BaseTheme.cs

@@ -2026,6 +2026,9 @@ function BaseTheme::makeGuiEditorProfile(%this)
 		fillColorNA = %this.color5; //Used for the add set control and ruler lines
 		fillColorNA = %this.color5; //Used for the add set control and ruler lines
 		
 		
 		borderDefault = %border;
 		borderDefault = %border;
+
+		tab = false;
+		canKeyFocus = true;
 	};
 	};
 }
 }
 
 

+ 135 - 35
editor/GuiEditor/GuiEditor.cs

@@ -133,7 +133,24 @@ function GuiEditor::create( %this )
     %this.guiPage.add(%this.explorerWindow);
     %this.guiPage.add(%this.explorerWindow);
     %this.explorerWindow.startListening(%this.brain);
     %this.explorerWindow.startListening(%this.brain);
 
 
-    %this.NewGui();
+    %this.rootGui = new GuiControl()
+    {
+        HorizSizing = "width";
+        VertSizing = "height";
+        Position = "0 0";
+        Extent = %this.content.getExtent();
+        Profile = GuiDefaultProfile;
+        class = "SimulatedCanvas";
+    };
+    %this.content.add(%this.rootGui);
+    %this.fileName = "";
+    %this.filePath = "";
+    %this.formatIndex = 0;
+    %this.folder = "";
+    %this.module = "";
+    %this.brain.setRoot(%this.rootGui);
+    %this.brain.root = %this.rootGui;
+    %this.explorerWindow.inspect(%this.rootGui);
 
 
     EditorCore.FinishRegistration(%this.guiPage);
     EditorCore.FinishRegistration(%this.guiPage);
 }
 }
@@ -142,10 +159,7 @@ function GuiEditor::create( %this )
 
 
 function GuiEditor::destroy( %this )
 function GuiEditor::destroy( %this )
 {
 {
-    if(isObject(%this.rootGui))
-    {
-        %this.content.removeIfMember(%this.rootGui);
-    }
+
 }
 }
 
 
 function GuiEditor::open(%this, %content)
 function GuiEditor::open(%this, %content)
@@ -167,15 +181,14 @@ function GuiEditor::close(%this)
 //MENU FUNCTIONS---------------------------------------------------------------
 //MENU FUNCTIONS---------------------------------------------------------------
 function GuiEditor::NewGui(%this)
 function GuiEditor::NewGui(%this)
 {
 {
-    %content = new GuiControl()
-    {
-        HorizSizing = "width";
-        VertSizing = "height";
-        Position = "0 0";
-        Extent = %this.guiPage.getExtent();
-        Profile = GuiDefaultProfile;
-    };
-    %this.DisplayGuiContent(%content);
+    %this.rootGui.clear();
+    %this.fileName = "";
+    %this.filePath = "";
+    %this.formatIndex = 0;
+    %this.folder = "";
+    %this.module = "";
+    %this.brain.clearSelection();
+    %this.explorerWindow.tree.refresh();
 }
 }
 
 
 function GuiEditor::OpenGui(%this)
 function GuiEditor::OpenGui(%this)
@@ -183,7 +196,7 @@ function GuiEditor::OpenGui(%this)
     %path = pathConcat(getMainDotCsDir(), ProjectManager.getProjectFolder());
     %path = pathConcat(getMainDotCsDir(), ProjectManager.getProjectFolder());
 	%dialog = new OpenFileDialog()
 	%dialog = new OpenFileDialog()
 	{
 	{
-		Filters = "GUI (*.GUI;*.GUI.DSO)|*.GUI;*.GUI.DSO";
+		Filters = "ALL (*.GUI;*.GUI.DSO;*.GUI.TAML)|*.GUI;*.GUI.DSO;*.GUI.TAML|GUI (*.GUI;*.GUI.DSO)|*.GUI;*.GUI.DSO|TAML (*.GUI.TAML)|*.GUI.TAML";
 		ChangePath = false;
 		ChangePath = false;
 		MultipleFiles = false;
 		MultipleFiles = false;
 		DefaultFile = "";
 		DefaultFile = "";
@@ -194,44 +207,85 @@ function GuiEditor::OpenGui(%this)
 
 
 	if ( %result )
 	if ( %result )
 	{
 	{
-        exec(%dialog.fileName);
+        if(fileExt(%dialog.fileName) $= ".taml")
+        {
+            %guiContent = TAMLRead(%dialog.fileName);
+            %includesSimulatedCanvas = (%guiContent.class $= "SimulatedCanvas");
+        }
+        else 
+        {
+            exec(%dialog.fileName);
+        }
+        if(%includesSimulatedCanvas $= "")
+        {
+            %includesSimulatedCanvas = true;
+        }
         if(isObject(%guiContent))
         if(isObject(%guiContent))
         {
         {
-            %this.DisplayGuiContent(%guiContent, %dialog.fileName);
+            %this.fileName = fileName(%dialog.fileName);
+            %this.filePath = %dialog.fileName;
+            %this.formatIndex = 0;
+            if(getSubStr(%dialog.fileName, strlen(%dialog.fileName) - 5, 5) $= ".taml")
+            {
+                %this.formatIndex = 1;
+            }
+            %this.folder = makeRelativePath(filePath(%dialog.fileName), getMainDotCsDir());
+            %this.module = EditorCore.findModuleOfPath(%dialog.fileName);
+            %this.DisplayGuiContent(%guiContent, %includesSimulatedCanvas);
         }
         }
         else 
         else 
         {
         {
             EditorCore.alert("Something went wrong while opening the Gui File. Gui Files should be structures with the root object assigned to %guiContent. If this file was made outside of the editor, you can change it manually and then open it in the Gui Editor.");
             EditorCore.alert("Something went wrong while opening the Gui File. Gui Files should be structures with the root object assigned to %guiContent. If this file was made outside of the editor, you can change it manually and then open it in the Gui Editor.");
         }
         }
-	}
+    }
 	// Cleanup
 	// Cleanup
 	%dialog.delete();
 	%dialog.delete();
 }
 }
 
 
-function GuiEditor::DisplayGuiContent(%this, %content, %filePath)
+function GuiEditor::DisplayGuiContent(%this, %content, %includesSimulatedCanvas)
 {
 {
-    if(isObject(%this.rootGui))
+    %this.rootGui.deleteObjects();
+    %this.brain.clearSelection();
+
+    if(%includesSimulatedCanvas)
     {
     {
-        %this.filePath = "";
-        %this.content.removeIfMember(%this.rootGui);
-        %this.explorerWindow.tree.uninspect();
-        %this.prevGui = %this.rootGui;
+        %count = %content.getCount();
+        for(%i = 0; %i < %count; %i++)
+        {
+            %obj[%i] = %content.getObject(%i);
+        }
+        for(%i = 0; %i < %count; %i++)
+        {
+            %this.rootGui.add(%obj[%i]);
+        }
+        %content.delete();
+        %this.explorerWindow.tree.refresh();
+        %this.brain.onSelect(%this.rootGui.getObject(0));
+    }
+    else 
+    {
+        %this.rootGui.add(%content);
+        %this.explorerWindow.tree.refresh();
+        %this.brain.onSelect(%content);
     }
     }
-
-    %this.filePath = %filePath;
-    %this.rootGui = %content;
-    %this.content.add(%content);
-    %this.brain.setRoot(%content);
-    %this.brain.root = %content;
-    %this.explorerWindow.inspect(%content);
-
-    %this.brain.onSelect(%content);
 }
 }
 
 
 function GuiEditor::SaveGui(%this)
 function GuiEditor::SaveGui(%this)
+{
+    if(%this.fileName $= "")
+    {
+        %this.SaveGuiAs();
+    }
+    else 
+    {
+        %this.SaveCore(%this.filePath, %this.formatIndex, %this.folder, %this.module);
+    }
+}
+
+function GuiEditor::SaveGuiAs(%this)
 {
 {
     %width = 700;
     %width = 700;
-	%height = 340;
+	%height = 390;
 	%dialog = new GuiControl()
 	%dialog = new GuiControl()
 	{
 	{
 		class = "GuiEditorSaveGuiDialog";
 		class = "GuiEditorSaveGuiDialog";
@@ -239,6 +293,10 @@ function GuiEditor::SaveGui(%this)
 		dialogSize = (%width + 8) SPC (%height + 8);
 		dialogSize = (%width + 8) SPC (%height + 8);
 		dialogCanClose = true;
 		dialogCanClose = true;
 		dialogText = "Save Gui";
 		dialogText = "Save Gui";
+        defaultFileName = %this.fileName;
+        formatIndex = %this.formatIndex;
+        defaultFolder = %this.folder;
+        defaultModule = %this.module;
 	};
 	};
 	%dialog.init(%width, %height);
 	%dialog.init(%width, %height);
 	%this.startListening(%dialog);
 	%this.startListening(%dialog);
@@ -246,6 +304,48 @@ function GuiEditor::SaveGui(%this)
 	Canvas.pushDialog(%dialog);
 	Canvas.pushDialog(%dialog);
 }
 }
 
 
+function GuiEditor::SaveCore(%this, %filePath, %formatIndex, %folder, %module)
+{
+    if(%formatIndex == 0)
+    {
+        %fo = new FileObject();
+        %fo.openForWrite(%filePath);
+        %fo.writeLine("//--- Created with the GuiEditor ---//");
+        if(%this.rootGui.getCount() == 1)
+        {
+            //Saved without the simulated canvas
+            %fo.writeLine("%includesSimulatedCanvas = false;");
+            %fo.writeObject(%this.rootGui.getObject(0), "%guiContent = ");
+        }
+        else 
+        {
+            //We have multiple top level objects so include the containing simulated canvas
+            %fo.writeLine("%includesSimulatedCanvas = true;");
+            %fo.writeObject(%this.rootGui, "%guiContent = ");
+        }
+        %fo.writeLine("//--- GuiEditor End ---//");
+        %fo.close();
+        %fo.delete();
+    }
+    else 
+    {
+        if(GuiEditor.rootGui.getCount() == 1)
+        {
+            //Saved without the Simulated Canvas
+            TAMLWrite(%this.rootGui.getObject(0), %filePath);
+        }
+        else 
+        {
+            TAMLWrite(%this.rootGui, %filePath);
+        }
+    }
+    %this.fileName = fileName(%filePath);
+    %this.filePath = %filePath;
+    %this.formatIndex = %formatIndex;
+    %this.folder = %folder;
+    %this.module = %module;
+}
+
 function GuiEditor::Undo(%this)
 function GuiEditor::Undo(%this)
 {
 {
     %undoManager = %this.brain.getUndoManager();
     %undoManager = %this.brain.getUndoManager();
@@ -279,7 +379,7 @@ function GuiEditor::Paste(%this)
 function GuiEditor::changeExtent(%this, %x, %y)
 function GuiEditor::changeExtent(%this, %x, %y)
 {
 {
     %set = %this.brain.getSelected();
     %set = %this.brain.getSelected();
-    if(%set.getCount() == 1)
+    if(%set.getCount() >= 1)
     {
     {
         %obj = %set.getObject(0);
         %obj = %set.getObject(0);
         %ext = %obj.getExtent();
         %ext = %obj.getExtent();

+ 35 - 17
editor/GuiEditor/scripts/GuiEditorBrain.cs

@@ -66,37 +66,37 @@ function GuiEditorBrain::onSelect(%this, %ctrl)
 	%this.clearSelection();
 	%this.clearSelection();
 	%this.select(%ctrl);
 	%this.select(%ctrl);
     %this.postEvent("Inspect", %ctrl);
     %this.postEvent("Inspect", %ctrl);
-    %this.toggleDeselect();
+    %this.toggleMenuItems();
 }
 }
 
 
 function GuiEditorBrain::onRemoveSelected(%this,%ctrl)
 function GuiEditorBrain::onRemoveSelected(%this,%ctrl)
 {
 {
     %this.postEvent("ClearInspect", %ctrl);
     %this.postEvent("ClearInspect", %ctrl);
-    %this.toggleDeselect();
+    %this.toggleMenuItems();
 }
 }
 
 
 function GuiEditorBrain::onClearSelected(%this)
 function GuiEditorBrain::onClearSelected(%this)
 {
 {
     %this.postEvent("ClearInspectAll");
     %this.postEvent("ClearInspectAll");
-    %this.toggleDeselect();
+    %this.toggleMenuItems();
 }
 }
 
 
 function GuiEditorBrain::onAddSelected(%this, %ctrl)
 function GuiEditorBrain::onAddSelected(%this, %ctrl)
 {
 {
     %this.postEvent("AlsoInspect", %ctrl);
     %this.postEvent("AlsoInspect", %ctrl);
-    %this.toggleDeselect();
+    %this.toggleMenuItems();
 }
 }
 
 
 function GuiEditorBrain::onDelete(%this)
 function GuiEditorBrain::onDelete(%this)
 {
 {
-	%this.postEvent("ObjectRemoved", %ctrl);
-    %this.toggleDeselect();
+	%this.postEvent("ObjectRemoved");
+    %this.toggleMenuItems();
 }
 }
 
 
 function GuiEditorBrain::onSelectionParentChange(%this, %parent)
 function GuiEditorBrain::onSelectionParentChange(%this, %parent)
 {
 {
     %this.postEvent("ParentChange", %parent);
     %this.postEvent("ParentChange", %parent);
-    %this.toggleDeselect();
+    %this.toggleMenuItems();
 }
 }
 
 
 //Receiving Callbacks - Events that happened at other controls and need to be reflected with this control.
 //Receiving Callbacks - Events that happened at other controls and need to be reflected with this control.
@@ -106,7 +106,7 @@ function GuiEditorBrain::onInspect(%this, %ctrl)
     %this.clearSelection();
     %this.clearSelection();
 	%this.select(%ctrl);
 	%this.select(%ctrl);
     %this.endRadioSilence();
     %this.endRadioSilence();
-    %this.toggleDeselect();
+    %this.toggleMenuItems();
 }
 }
 
 
 function GuiEditorBrain::onAlsoInspect(%this, %ctrl)
 function GuiEditorBrain::onAlsoInspect(%this, %ctrl)
@@ -114,7 +114,7 @@ function GuiEditorBrain::onAlsoInspect(%this, %ctrl)
     %this.startRadioSilence();
     %this.startRadioSilence();
 	%this.addSelection(%ctrl);
 	%this.addSelection(%ctrl);
     %this.endRadioSilence();
     %this.endRadioSilence();
-    %this.toggleDeselect();
+    %this.toggleMenuItems();
 }
 }
 
 
 function GuiEditorBrain::onClearInspect(%this, %ctrl)
 function GuiEditorBrain::onClearInspect(%this, %ctrl)
@@ -122,7 +122,7 @@ function GuiEditorBrain::onClearInspect(%this, %ctrl)
     %this.startRadioSilence();
     %this.startRadioSilence();
 	%this.removeSelection(%ctrl);
 	%this.removeSelection(%ctrl);
     %this.endRadioSilence();
     %this.endRadioSilence();
-    %this.toggleDeselect();
+    %this.toggleMenuItems();
 }
 }
 
 
 function GuiEditorBrain::onClearInspectAll(%this)
 function GuiEditorBrain::onClearInspectAll(%this)
@@ -130,7 +130,7 @@ function GuiEditorBrain::onClearInspectAll(%this)
     %this.startRadioSilence();
     %this.startRadioSilence();
 	%this.clearSelection();
 	%this.clearSelection();
     %this.endRadioSilence();
     %this.endRadioSilence();
-    %this.toggleDeselect();
+    %this.toggleMenuItems();
 }
 }
 
 
 function GuiEditorBrain::onObjectRemoved(%this, %ctrl)
 function GuiEditorBrain::onObjectRemoved(%this, %ctrl)
@@ -138,10 +138,28 @@ function GuiEditorBrain::onObjectRemoved(%this, %ctrl)
     %this.startRadioSilence();
     %this.startRadioSilence();
 	%this.deleteSelection();
 	%this.deleteSelection();
     %this.endRadioSilence();
     %this.endRadioSilence();
-    %this.toggleDeselect();
-}
-
-function GuiEditorBrain::toggleDeselect(%this)
-{
-    EditorCore.menuBar.setMenuActive("Deselect", %this.getSelected().getCount() != 0);
+    %this.toggleMenuItems();
+}
+
+function GuiEditorBrain::toggleMenuItems(%this)
+{
+    %count = %this.getSelected().getCount();
+    EditorCore.menuBar.setMenuActive("Deselect", %count != 0);
+    EditorCore.menuBar.setMenuActive("Nudge Up", %count != 0);
+    EditorCore.menuBar.setMenuActive("Nudge Down", %count != 0);
+    EditorCore.menuBar.setMenuActive("Nudge Left", %count != 0);
+    EditorCore.menuBar.setMenuActive("Nudge Right", %count != 0);
+    EditorCore.menuBar.setMenuActive("Expand Height", %count != 0);
+    EditorCore.menuBar.setMenuActive("Shrink Height", %count != 0);
+    EditorCore.menuBar.setMenuActive("Expand Width", %count != 0);
+    EditorCore.menuBar.setMenuActive("Shrink Width", %count != 0);
+    EditorCore.menuBar.setMenuActive("Align Top", %count > 1);
+    EditorCore.menuBar.setMenuActive("Align Bottom", %count > 1);
+    EditorCore.menuBar.setMenuActive("Align Left", %count > 1);
+    EditorCore.menuBar.setMenuActive("Align Right", %count > 1);
+    EditorCore.menuBar.setMenuActive("Center Horizontally", %count > 1);
+    EditorCore.menuBar.setMenuActive("Space Vertically", %count > 2);
+    EditorCore.menuBar.setMenuActive("Space Horizontally", %count > 2);
+    EditorCore.menuBar.setMenuActive("Bring to Front", %count == 1);
+    EditorCore.menuBar.setMenuActive("Push to Back", %count == 1);
 }
 }

+ 2 - 5
editor/GuiEditor/scripts/GuiEditorExplorerWindow.cs

@@ -69,12 +69,9 @@ function GuiEditorExplorerWindow::onClearInspectAll(%this)
 	%this.tree.endRadioSilence();
 	%this.tree.endRadioSilence();
 }
 }
 
 
-function GuiEditorExplorerWindow::onObjectRemoved(%this, %ctrl)
+function GuiEditorExplorerWindow::onObjectRemoved(%this)
 {
 {
-	%this.tree.startRadioSilence();
-	%index = %this.tree.findItemID(%ctrl.getID());
-	%this.tree.deleteItem(%index);
-	%this.tree.endRadioSilence();
+	%this.tree.refresh();
 }
 }
 
 
 function GuiEditorExplorerWindow::onAddControl(%this, %ctrl)
 function GuiEditorExplorerWindow::onAddControl(%this, %ctrl)

+ 6 - 0
editor/GuiEditor/scripts/GuiEditorInspectorWindow.cs

@@ -53,6 +53,7 @@ function GuiEditorInspectorWindow::onAdd(%this)
     %this.inspectList = new SimSet();
     %this.inspectList = new SimSet();
 
 
 	%this.inspector.addHiddenField("isContainer");
 	%this.inspector.addHiddenField("isContainer");
+	%this.inspector.addHiddenField("BindToGuiEditor");
 }
 }
 
 
 function GuiEditorInspectorWindow::onRemove(%this)
 function GuiEditorInspectorWindow::onRemove(%this)
@@ -94,4 +95,9 @@ function GuiEditorInspectorWindow::onAlsoInspect(%this, %object)
 {
 {
     %this.inspectList.add(%object);
     %this.inspectList.add(%object);
     %this.inspector.inspect(%object);
     %this.inspector.inspect(%object);
+}
+
+function GuiEditorInspectorWindow::onObjectRemoved(%this)
+{
+	%this.onClearInspectAll(%this);
 }
 }

+ 70 - 18
editor/GuiEditor/scripts/GuiEditorSaveGuiDialog.cs

@@ -19,9 +19,13 @@ function GuiEditorSaveGuiDialog::init(%this, %width, %height)
 	%this.guiNameBox = %form.createTextEditItem(%item);
 	%this.guiNameBox = %form.createTextEditItem(%item);
 	%this.guiNameBox.Command = %this.getId() @ ".Validate();";
 	%this.guiNameBox.Command = %this.getId() @ ".Validate();";
 
 
-	if(GuiEditor.rootGui.getName() !$= "")
+	if(%this.defaultFileName !$= "")
 	{
 	{
-		%name = %this.blankGui.getName() @ ".gui";
+		%name = %this.defaultFileName;
+	}
+	else if(GuiEditor.rootGui.getName() !$= "")
+	{
+		%name = GuiEditor.rootGui.getName() @ ".gui";
 	}
 	}
 	else
 	else
 	{
 	{
@@ -29,13 +33,27 @@ function GuiEditorSaveGuiDialog::init(%this, %width, %height)
 	}
 	}
 	%this.guiNameBox.text = %name;
 	%this.guiNameBox.text = %name;
 
 
+	%item = %form.addFormItem("Save Format", %width SPC 30);
+	%this.guiFormatDropDown = %form.createDropDownItem(%item);
+	%this.guiFormatDropDown.Command = %this.getId() @ ".Validate();";
+	%this.populateFormatDropDown();
+	%this.guiFormatDropDown.setSelected(%this.formatIndex);
+
 	%item = %form.addFormItem("Target Folder", %width SPC 30);
 	%item = %form.addFormItem("Target Folder", %width SPC 30);
 	%this.folderBox = %form.createFolderOpenItem(%item, "Select Target Folder");
 	%this.folderBox = %form.createFolderOpenItem(%item, "Select Target Folder");
 	%this.folderBox.Command = %this.getId() @ ".Validate();";
 	%this.folderBox.Command = %this.getId() @ ".Validate();";
+	if(%this.defaultFolder !$= "")
+	{
+		%this.folderBox.setText(%this.defaultFolder);
+	}
 
 
 	%item = %form.addFormItem("Target Module", %width SPC 30);
 	%item = %form.addFormItem("Target Module", %width SPC 30);
 	%this.moduleNameBox = %form.createTextEditItem(%item);
 	%this.moduleNameBox = %form.createTextEditItem(%item);
 	%this.moduleNameBox.setActive(false);
 	%this.moduleNameBox.setActive(false);
+	if(%this.defaultModule !$= "")
+	{
+		%this.moduleNameBox.setText(%this.defaultModule);
+	}
 
 
 	%content.add(%form);
 	%content.add(%form);
 
 
@@ -43,7 +61,7 @@ function GuiEditorSaveGuiDialog::init(%this, %width, %height)
 	{
 	{
 		HorizSizing = "right";
 		HorizSizing = "right";
 		VertSizing = "bottom";
 		VertSizing = "bottom";
-		Position = "12 170";
+		Position = "12 220";
 		Extent = (%width - 24) SPC 80;
 		Extent = (%width - 24) SPC 80;
 		text = "Select a name and target folder!";
 		text = "Select a name and target folder!";
 		textWrap = true;
 		textWrap = true;
@@ -55,7 +73,7 @@ function GuiEditorSaveGuiDialog::init(%this, %width, %height)
 	{
 	{
 		HorizSizing = "right";
 		HorizSizing = "right";
 		VertSizing = "bottom";
 		VertSizing = "bottom";
-		Position = "478 270";
+		Position = "478 320";
 		Extent = "100 30";
 		Extent = "100 30";
 		Text = "Cancel";
 		Text = "Cancel";
 		Command = %this.getID() @ ".onClose();";
 		Command = %this.getID() @ ".onClose();";
@@ -66,7 +84,7 @@ function GuiEditorSaveGuiDialog::init(%this, %width, %height)
 	{
 	{
 		HorizSizing = "right";
 		HorizSizing = "right";
 		VertSizing = "bottom";
 		VertSizing = "bottom";
-		Position = "588 268";
+		Position = "588 318";
 		Extent = "100 34";
 		Extent = "100 34";
 		Text = "Save";
 		Text = "Save";
 		Command = %this.getID() @ ".onSave();";
 		Command = %this.getID() @ ".onSave();";
@@ -78,6 +96,8 @@ function GuiEditorSaveGuiDialog::init(%this, %width, %height)
 	%content.add(%this.saveButton);
 	%content.add(%this.saveButton);
 
 
 	%this.prevFolder = "";
 	%this.prevFolder = "";
+
+	%this.validate();
 }
 }
 
 
 function GuiEditorSaveGuiDialog::Validate(%this)
 function GuiEditorSaveGuiDialog::Validate(%this)
@@ -161,14 +181,9 @@ function GuiEditorSaveGuiDialog::onSave(%this)
 {
 {
 	if(%this.validate())
 	if(%this.validate())
 	{
 	{
-		%filePath = %this.getFilePath();
-		%fo = new FileObject();
-		%fo.openForWrite(%filePath);
-		%fo.writeLine("//--- Created with the GuiEditor ---//");
-		%fo.writeObject(GuiEditor.rootGui, "%guiContent = ");
-		%fo.writeLine("//--- GuiEditor End ---//");
-		%fo.close();
-		%fo.delete();
+    	%filePath = %this.getFilePath();
+		%formatIndex = %this.guiFormatDropDown.getSelectedItem();
+		GuiEditor.SaveCore(%filePath, %formatIndex, %this.folderBox.getText(), %this.moduleNameBox.getText());
 
 
 		%this.onClose();
 		%this.onClose();
 	}
 	}
@@ -185,14 +200,38 @@ function GuiEditorSaveGuiDialog::getFilePath(%this)
 	%fileName = %this.guiNameBox.getText();
 	%fileName = %this.guiNameBox.getText();
 	%filePath = pathConcat(%folderPath, %fileName);
 	%filePath = pathConcat(%folderPath, %fileName);
 	%length = strlen(%filePath);
 	%length = strlen(%filePath);
-	%sub = "";
-	if(%length >= 4)
+	if(%this.guiFormatDropDown.getSelectedItem() == 0)
 	{
 	{
-		%sub = getSubStr(%filePath, %length - 4, 4);
+		if(%length >= 4)
+		{
+			%sub = getSubStr(%filePath, %length - 4, 4);
+		}
+		if(%sub !$= ".gui")
+		{
+			%filePath = %filePath @ ".gui";
+		}
 	}
 	}
-	if(%sub !$= ".gui")
+	else 
 	{
 	{
-		%filePath = %filePath @ ".gui";
+		if(%length >= 4)
+		{
+			%sub4 = getSubStr(%filePath, %length - 4, 4);
+		}
+		if(%length >= 9)
+		{
+			%sub9 = getSubStr(%filePath, %length - 9, 9);
+		}
+		if(%sub9 !$= ".gui.taml")
+		{
+			if(%sub4 $= ".gui")
+			{
+				%filePath = %filePath @ ".taml";
+			}
+			else
+			{
+				%filePath = %filePath @ ".gui.taml";
+			}
+		}
 	}
 	}
 
 
 	return %filePath;
 	return %filePath;
@@ -209,3 +248,16 @@ function GuiEditorSaveGuiDialog::getFolderPath(%this)
 	}
 	}
 	return %folderPath @ "/";
 	return %folderPath @ "/";
 }
 }
+
+function GuiEditorSaveGuiDialog::onDropDownClosed(%this, %dropDown)
+{
+	%this.validate();
+}
+
+function GuiEditorSaveGuiDialog::populateFormatDropDown(%this)
+{
+	%this.guiFormatDropDown.clearItems();
+	%this.guiFormatDropDown.addItem("GUI File (*.gui)");
+	%this.guiFormatDropDown.addItem("TAML (*.gui.taml)");
+	%this.guiFormatDropDown.setSelected(0);
+}

+ 18 - 42
engine/source/gui/editor/guiEditCtrl.cc

@@ -34,7 +34,7 @@ IMPLEMENT_CONOBJECT(GuiEditCtrl);
 
 
 GuiEditCtrl::GuiEditCtrl(): mCurrentAddSet(NULL),
 GuiEditCtrl::GuiEditCtrl(): mCurrentAddSet(NULL),
                             mContentControl(NULL),
                             mContentControl(NULL),
-                            mGridSnap(0,0),
+                            mGridSnap(10,10),
                             mDragBeginPoint(-1,-1)                            
                             mDragBeginPoint(-1,-1)                            
 {
 {
    VECTOR_SET_ASSOCIATION(mSelectedControls);
    VECTOR_SET_ASSOCIATION(mSelectedControls);
@@ -43,6 +43,7 @@ GuiEditCtrl::GuiEditCtrl(): mCurrentAddSet(NULL),
    mActive = true;
    mActive = true;
    mDragBeginPoints.clear();
    mDragBeginPoints.clear();
    mSelectedControls.clear();
    mSelectedControls.clear();
+   mUseGridSnap = true;
 
 
    mDefaultCursor    = NULL;
    mDefaultCursor    = NULL;
    mLeftRightCursor  = NULL;
    mLeftRightCursor  = NULL;
@@ -538,7 +539,7 @@ void GuiEditCtrl::onRender(Point2I offset, const RectI &updateRect)
 
 
    renderChildControls(offset, mBounds, updateRect);
    renderChildControls(offset, mBounds, updateRect);
 
 
-   if(mActive && mCurrentAddSet && (mGridSnap.x && mGridSnap.y) && 
+   if(mActive && mCurrentAddSet && mUseGridSnap && 
        (mMouseDownMode == MovingSelection || mMouseDownMode == SizingSelection))
        (mMouseDownMode == MovingSelection || mMouseDownMode == SizingSelection))
    {
    {
       Point2I cext = mCurrentAddSet->getExtent();
       Point2I cext = mCurrentAddSet->getExtent();
@@ -1409,60 +1410,27 @@ bool GuiEditCtrl::onKeyDown(const GuiEvent &event)
             deleteSelection();
             deleteSelection();
             Con::executef(this,1,"onDelete");
             Con::executef(this,1,"onDelete");
             return true;
             return true;
-		 case KEY_LEFT:
-			moveSelection(Point2I(-1, 0));
-			return true;
-		 case KEY_RIGHT:
-			 moveSelection(Point2I(1, 0));
-			 return true;
-		 case KEY_UP:
-			 moveSelection(Point2I(0, -1));
-			 return true;
-		 case KEY_DOWN:
-			 moveSelection(Point2I(0, 1));
-			 return true;
       }
       }
    }
    }
-   else if (event.modifier & SI_SHIFT)
+   else if (event.modifier & SI_SHIFT && !(event.modifier & SI_CTRL))
    {
    {
+	   //holding shift while using arrow keys toggles the grid snap
 	   switch (event.keyCode)
 	   switch (event.keyCode)
 	   {
 	   {
 	   case KEY_LEFT:
 	   case KEY_LEFT:
-		   moveSelection(Point2I(mGridSnap.x != 0 ? -mGridSnap.x : -10, 0));
+		   moveSelection(Point2I(mUseGridSnap ? -1 : -mGridSnap.x, 0));
 		   return true;
 		   return true;
 	   case KEY_RIGHT:
 	   case KEY_RIGHT:
-		   moveSelection(Point2I(mGridSnap.x != 0 ? mGridSnap.x : 10, 0));
+		   moveSelection(Point2I(mUseGridSnap ? 1 : mGridSnap.x, 0));
 		   return true;
 		   return true;
 	   case KEY_UP:
 	   case KEY_UP:
-		   moveSelection(Point2I(0, mGridSnap.y != 0 ? -mGridSnap.y : -10));
+		   moveSelection(Point2I(0, mUseGridSnap ? -1 : -mGridSnap.y));
 		   return true;
 		   return true;
 	   case KEY_DOWN:
 	   case KEY_DOWN:
-		   moveSelection(Point2I(0, mGridSnap.y != 0 ? mGridSnap.y : 10));
+		   moveSelection(Point2I(0, mUseGridSnap ? 1 : mGridSnap.y));
 		   return true;
 		   return true;
 	   }
 	   }
    }
    }
-   else if (event.modifier & SI_CTRL)
-   {
-		if(mSelectedControls.size() == 1)
-		{
-			GuiControl* ctrl = mSelectedControls.first();
-			switch (event.keyCode)
-			{
-			case KEY_LEFT:
-				ctrl->resize(ctrl->mBounds.point, Point2I(ctrl->mBounds.extent.x - 1, ctrl->mBounds.extent.y));
-				return true;
-			case KEY_RIGHT:
-				ctrl->resize(ctrl->mBounds.point, Point2I(ctrl->mBounds.extent.x + 1, ctrl->mBounds.extent.y));
-				return true;
-			case KEY_UP:
-				ctrl->resize(ctrl->mBounds.point, Point2I(ctrl->mBounds.extent.x, ctrl->mBounds.extent.y - 1));
-				return true;
-			case KEY_DOWN:
-				ctrl->resize(ctrl->mBounds.point, Point2I(ctrl->mBounds.extent.x, ctrl->mBounds.extent.y + 1));
-				return true;
-			}
-		}
-   }
    return false;
    return false;
 }
 }
 
 
@@ -1475,7 +1443,15 @@ ConsoleMethod(GuiEditCtrl, setSnapToGrid, void, 3, 3, "(gridsize) Set the size o
 
 
 void GuiEditCtrl::setSnapToGrid(U32 gridsize)
 void GuiEditCtrl::setSnapToGrid(U32 gridsize)
 {
 {
-   mGridSnap.set(gridsize, gridsize);
+	if (gridsize == 0)
+	{
+		mUseGridSnap = false;
+	}
+	else 
+	{
+		mGridSnap.set(gridsize, gridsize);
+		mUseGridSnap = true;
+	}
 }
 }
 
 
 
 

+ 2 - 1
engine/source/gui/editor/guiEditCtrl.h

@@ -36,6 +36,7 @@ class GuiEditCtrl : public GuiControl
    Point2I              mLastMousePos;
    Point2I              mLastMousePos;
    Point2I              mSelectionAnchor;
    Point2I              mSelectionAnchor;
    Point2I              mGridSnap;
    Point2I              mGridSnap;
+   bool					mUseGridSnap;
    Point2I				   mDragBeginPoint;
    Point2I				   mDragBeginPoint;
    Vector<Point2I>		mDragBeginPoints;
    Vector<Point2I>		mDragBeginPoints;
 
 
@@ -134,7 +135,7 @@ class GuiEditCtrl : public GuiControl
    void bringToFront();
    void bringToFront();
    void pushToBack();
    void pushToBack();
    void setSnapToGrid(U32 gridsize);
    void setSnapToGrid(U32 gridsize);
-   bool hasSnapToGrid() { return mGridSnap.x && mGridSnap.y; }
+   bool hasSnapToGrid() { return mUseGridSnap; }
    void moveSelectionToCtrl(GuiControl*);
    void moveSelectionToCtrl(GuiControl*);
 };
 };
 
 

+ 7 - 4
engine/source/gui/guiCanvas.cc

@@ -393,8 +393,10 @@ bool GuiCanvas::processInputEvent(const InputEvent *event)
       else if(event->action == SI_BREAK)
       else if(event->action == SI_BREAK)
       {
       {
          if(mFirstResponder)
          if(mFirstResponder)
+		 {
             if(mFirstResponder->onKeyUp(mLastEvent))
             if(mFirstResponder->onKeyUp(mLastEvent))
                return true;
                return true;
+		 }
 
 
          //see if there's an accelerator
          //see if there's an accelerator
          for (U32 i = 0; i < (U32)mAcceleratorMap.size(); i++)
          for (U32 i = 0; i < (U32)mAcceleratorMap.size(); i++)
@@ -408,6 +410,11 @@ bool GuiCanvas::processInputEvent(const InputEvent *event)
       }
       }
       else if(event->action == SI_REPEAT)
       else if(event->action == SI_REPEAT)
       {
       {
+		  if (mFirstResponder)
+		  {
+			  if (mFirstResponder->onKeyRepeat(mLastEvent))
+				  return true;
+		  }
 
 
          //if not handled, search for an accelerator
          //if not handled, search for an accelerator
          for (U32 i = 0; i < (U32)mAcceleratorMap.size(); i++)
          for (U32 i = 0; i < (U32)mAcceleratorMap.size(); i++)
@@ -418,10 +425,6 @@ bool GuiCanvas::processInputEvent(const InputEvent *event)
                return true;
                return true;
             }
             }
          }
          }
-
-         if(mFirstResponder)
-            mFirstResponder->onKeyRepeat(mLastEvent);
-         return true;
       }
       }
    }
    }
    else if(event->deviceType == MouseDeviceType && cursorON)
    else if(event->deviceType == MouseDeviceType && cursorON)

+ 1 - 3
engine/source/gui/guiControl.cc

@@ -221,8 +221,6 @@ void GuiControl::initPersistFields()
    addField("canSave",           TypeBool,			Offset(mCanSave, GuiControl));
    addField("canSave",           TypeBool,			Offset(mCanSave, GuiControl));
    addField("Visible",           TypeBool,			Offset(mVisible, GuiControl));
    addField("Visible",           TypeBool,			Offset(mVisible, GuiControl));
    addField("useInput",          TypeBool,          Offset(mUseInput, GuiControl));
    addField("useInput",          TypeBool,          Offset(mUseInput, GuiControl));
-   addDepricatedField("Modal");
-   addField("SetFirstResponder", TypeBool, Offset(mFirstResponder, GuiControl));
 
 
    addField("Variable",          TypeString,		Offset(mConsoleVariable, GuiControl));
    addField("Variable",          TypeString,		Offset(mConsoleVariable, GuiControl));
    addField("Command",           TypeString,		Offset(mConsoleCommand, GuiControl));
    addField("Command",           TypeString,		Offset(mConsoleCommand, GuiControl));
@@ -1775,7 +1773,7 @@ bool GuiControl::isFirstResponder()
 
 
 void GuiControl::setFirstResponder( GuiControl* firstResponder )
 void GuiControl::setFirstResponder( GuiControl* firstResponder )
 {
 {
-   if ( firstResponder && firstResponder->mProfile->mCanKeyFocus )
+   if ( firstResponder && firstResponder->mProfile && firstResponder->mProfile->mCanKeyFocus )
       mFirstResponder = firstResponder;
       mFirstResponder = firstResponder;
 
 
    GuiControl *parent = getParent();
    GuiControl *parent = getParent();

+ 1 - 1
engine/source/gui/guiControl.h

@@ -161,7 +161,7 @@ public:
 
 
     /// @name Keyboard Input
     /// @name Keyboard Input
     /// @{
     /// @{
-    SimObjectPtr<GuiControl> mFirstResponder;
+    GuiControl* mFirstResponder;
     static GuiControl *smPrevResponder;
     static GuiControl *smPrevResponder;
     static GuiControl *smCurResponder;
     static GuiControl *smCurResponder;
     /// @}
     /// @}

+ 11 - 6
engine/source/gui/guiListBoxCtrl.cc

@@ -876,17 +876,19 @@ bool GuiListBoxCtrl::onKeyDown(const GuiEvent &event)
 	case KEY_RETURN:
 	case KEY_RETURN:
 		if (mAltConsoleCommand[0])
 		if (mAltConsoleCommand[0])
 			Con::evaluate(mAltConsoleCommand, false);
 			Con::evaluate(mAltConsoleCommand, false);
-		break;
+		return true;
 	case KEY_LEFT:
 	case KEY_LEFT:
 	case KEY_UP:
 	case KEY_UP:
 		if (index == -1)
 		if (index == -1)
 		{
 		{
 			//Select the bottom item
 			//Select the bottom item
 			addSelection(mItems.size() - 1);
 			addSelection(mItems.size() - 1);
+			return true;
 		}
 		}
 		else if(index != 0)
 		else if(index != 0)
 		{
 		{
 			addSelection(index - 1);
 			addSelection(index - 1);
+			return true;
 		}
 		}
 		break;
 		break;
 	case KEY_DOWN:
 	case KEY_DOWN:
@@ -895,26 +897,29 @@ bool GuiListBoxCtrl::onKeyDown(const GuiEvent &event)
 		{
 		{
 			//Select the top item
 			//Select the top item
 			addSelection(0);
 			addSelection(0);
+			return true;
 		}
 		}
 		else if (index != (mItems.size() - 1))
 		else if (index != (mItems.size() - 1))
 		{
 		{
 			addSelection(index + 1);
 			addSelection(index + 1);
+			return true;
 		}
 		}
 		break;
 		break;
 	case KEY_HOME:
 	case KEY_HOME:
 		addSelection(0);
 		addSelection(0);
-		break;
+		return true;
 	case KEY_END:
 	case KEY_END:
 		addSelection(mItems.size() - 1);
 		addSelection(mItems.size() - 1);
-		break;
+		return true;
 	case KEY_DELETE:
 	case KEY_DELETE:
 		if (index != -1 && isMethod("onDeleteKey"))
 		if (index != -1 && isMethod("onDeleteKey"))
 			Con::executef(caller, 4, "onDeleteKey", Con::getIntArg(index), getItemText(index), Con::getIntArg(getItemID(index)));
 			Con::executef(caller, 4, "onDeleteKey", Con::getIntArg(index), getItemText(index), Con::getIntArg(getItemID(index)));
-		break;
+
+		return true;
 	default:
 	default:
-		return(Parent::onKeyDown(event));
-		break;
+		return Parent::onKeyDown(event);
 	};
 	};
+	return false;
 }
 }
 #pragma endregion
 #pragma endregion