Beispiel #1
0
        public void append()
        {
            GuiEditorGui.GuiEditor GuiEditor          = "GuiEditor";
            GuiControl             GuiEditorContent   = "GuiEditorContent";
            GuiEditorStatusBar     GuiEditorStatusBar = "GuiEditorStatusBar";

            // Get filename.

            string openFileName = console.Call_Classname("GuiBuilder", "getOpenName");

            if (openFileName == "" ||
                (!Util.isFile(openFileName) &&
                 !Util.isFile(openFileName + ".dso")))
            {
                return;
            }

            // Exec file.

            string oldRedefineBehavior = sGlobal["$Con::redefineBehavior"];

            sGlobal["$Con::redefineBehavior"] = "renameNew";

            //TODO
            GuiControl guiContent = Util.eval(openFileName);

            sGlobal["$Con::redefineBehavior"] = oldRedefineBehavior;

            // Find guiContent.

            if (!guiContent.isObject())
            {
                Util.messageBox("Error loading GUI file",
                                "The GUI content controls could not be found.  This function can only be used with files saved by the GUI editor.",
                                "Ok", "Error");
                return;
            }

            if (GuiEditorContent.getCount() == 0)
            {
                GuiEditor.openForEditing(guiContent);
            }
            else
            {
                ((SimSet)GuiEditor.getCurrentAddSet()).add(guiContent);
                GuiEditor.readGuides(guiContent);
                GuiEditor.onAddNewCtrl(guiContent);
                GuiEditor.onHierarchyChanged();
            }

            GuiEditorStatusBar.print("Appended controls from '" + openFileName + "'");
        }
Beispiel #2
0
        public void load(string filename)
        {
            GuiEditorStatusBar GuiEditorStatusBar = "GuiEditorStatusBar";

            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

            string newRedefineBehavior = "replaceExisting";

            if (Util.isDefined("$GuiEditor::loadRedefineBehavior"))
            {
                // This trick allows to choose different redefineBehaviors when loading
                // GUIs.  This is useful, for example, when loading GUIs that would lead to
                // problems when loading with their correct names because script behavior
                // would immediately attach.
                //
                // This allows to also edit the GUI editor's own GUI inside itself.

                newRedefineBehavior = sGlobal["$GuiEditor::loadRedefineBehavior"];
            }

            // Allow stomping objects while exec'ing the GUI file as we want to
            // pull the file's objects even if we have another version of the GUI
            // already loaded.

            string oldRedefineBehavior = sGlobal["$Con::redefineBehavior"];

            sGlobal["$Con::redefineBehavior"] = newRedefineBehavior;

            // Load up the gui.
            Util.exec(filename);
            GuiControl guiContent = Util.eval("return %guiContent;");

            //GuiControl guiContent = Util.eval(filename);

            sGlobal["$Con::redefineBehavior"] = oldRedefineBehavior;

            // The GUI file should have contained a GUIControl which should now be in the instant
            // group. And, it should be the only thing in the group.
            //TODO
            if (!guiContent.isObject())
            {
                Util.messageBox(Util.getEngineName(),
                                "You have loaded a Gui file that was created before this version.  It has been loaded but you must open it manually from the content list dropdown",
                                "Ok", "Information");
                return;
            }

            GuiEditor.openForEditing(guiContent);

            GuiEditorStatusBar.print("Loaded '" + filename + "'");
        }
Beispiel #3
0
        public void save(bool selectedOnly, bool noPrompt)
        {
            GuiEditorGui.GuiEditor GuiEditor          = "GuiEditor";
            GuiControl             GuiEditorContent   = "GuiEditorContent";
            GuiEditorStatusBar     GuiEditorStatusBar = "GuiEditorStatusBar";

            SimObject currentObject;

            // Get the control we should save.

            if (selectedOnly)
            {
                SimSet selected = GuiEditor.getSelection();
                if (selected.getCount() == 0)
                {
                    return;
                }
                else if (selected.getCount() > 1)
                {
                    Util.messageBox("Invalid selection", "Only a single control hierarchy can be saved to a file.  Make sure you have selected only one control in the tree view.", "", "");
                    return;
                }

                currentObject = selected.getObject(0);
            }
            else if (GuiEditorContent.getCount() > 0)
            {
                currentObject = GuiEditorContent.getObject(0);
            }
            else
            {
                return;
            }

            // Store the current guide set on the control.

            GuiEditor.writeGuides(currentObject);
            currentObject.canSaveDynamicFields = true; // Make sure the guides get saved out.

            // Construct a base filename.

            string name;

            if (currentObject.getName() != "")
            {
                name = currentObject.getName() + ".gui";
            }
            else
            {
                name = "Untitled.gui";
            }

            // Construct a path.

            string currentFile;

            if (selectedOnly && currentObject != GuiEditorContent.getObject(0) && currentObject.getFilename() == ((SimObject)GuiEditorContent.getObject(0)).getFilename())
            {
                // Selected child control that hasn't been yet saved to its own file.

                currentFile = GuiEditor["LastPath"] + "/" + name;
                currentFile = Util.makeRelativePath(currentFile, Util.getMainDotCsDir());
            }
            else
            {
                currentFile = currentObject.getFilename();
                if (currentFile == "")
                {
                    // No file name set on control.  Force a prompt.
                    noPrompt = false;

                    if (GuiEditor["LastPath"] != "")
                    {
                        currentFile = GuiEditor["LastPath"] + "/" + name;
                        currentFile = Util.makeRelativePath(currentFile, Util.getMainDotCsDir());
                    }
                    else
                    {
                        currentFile = Util._expandFilename(name);
                    }
                }
                else
                {
                    currentFile = Util._expandFilename(currentFile);
                }
            }

            // Get the filename.

            string filename;

            if (!noPrompt)
            {
                filename = GuiEditorFileDialog.GuiBuilder.GetSaveName(currentFile);
                // console.Call_Classname("GuiBuilder", "getSaveName", new string[] {currentFile} );
                if (filename == "")
                {
                    return;
                }
            }
            else
            {
                filename = currentFile;
            }

            // Save the Gui.

            if (Util.isWriteableFileName(filename))
            {
                //
                // Extract any existent TorqueScript before writing out to disk
                //
                FileObject fileObject = new ObjectCreator("FileObject").Create();
                fileObject.openForRead(filename);
                bool skipLines    = true;
                bool beforeObject = true;
                // var++ does not post-increment var, in torquescript, it pre-increments it,
                // because ++var is illegal.
                //int lines = -1;
                //int beforeLines = -1;
                skipLines = false;

                //string[] beforeNewFileLines = new string[]{};
                //string[] newFileLines = new string[]{};

                List <string> beforeNewFileLines = new List <string>();
                List <string> newFileLines       = new List <string>();

                while (!fileObject.isEOF())
                {
                    string line = fileObject.readLine();
                    if (line == "//--- OBJECT WRITE BEGIN ---")
                    {
                        skipLines = true;
                    }
                    else if (line == "//--- OBJECT WRITE END ---")
                    {
                        skipLines    = false;
                        beforeObject = false;
                    }
                    else if (skipLines == false)
                    {
                        if (beforeObject)
                        {
                            beforeNewFileLines.Add(line);
                        }
                        //beforeNewFileLines[ beforeLines++ ] = line;
                        else
                        {
                            //newFileLines[ lines++ ] = line;
                            newFileLines.Add(line);
                        }
                    }
                }
                fileObject.close();
                fileObject.delete();

                FileObject fo = new ObjectCreator("FileObject").Create();
                fo.openForWrite(filename);

                // Write out the captured TorqueScript that was before the object before the object
                foreach (string line in beforeNewFileLines)
                {
                    fo.writeLine(line);
                }

                //for(int i = 0; i <= beforeLines; i++)
                //    fo.writeLine( beforeNewFileLines[ i ] );

                fo.writeLine("//--- OBJECT WRITE BEGIN ---");
                fo.writeObject(currentObject, "%guiContent = ");
                fo.writeLine("//--- OBJECT WRITE END ---");

                // Write out captured TorqueScript below Gui object
                //for( int i = 0; i <= lines; i++ )
                //    fo.writeLine( newFileLines[ i ] );
                foreach (string line in newFileLines)
                {
                    fo.writeLine(line);
                }

                fo.close();
                fo.delete();

                currentObject.setFilename(Util.makeRelativePath(filename, Util.getMainDotCsDir()));

                GuiEditorStatusBar.print("Saved file '" + currentObject.getFilename() + "'");
            }
            else
            {
                Util.messageBox("Error writing to file", "There was an error writing to file '" + currentFile + "'. The file may be read-only.", "Ok", "Error");
            }
        }