예제 #1
0
        // Called once an asyncronous compiling task has completed.
        private void OnCompileComplete(ScriptCompileResult results)
        {
            // Update the script object.
            script.Code     = codeEditor.Text;
            script.Errors   = results.Errors;
            script.Warnings = results.Warnings;

            // Update the error message status-strip.
            if (script.HasErrors)
            {
                displayedError          = script.Errors[0];
                labelErrorMessage.Text  = displayedError.ToString();
                labelErrorMessage.Image = ZeldaEditor.ResourceProperties.Resources.exclamation;
            }
            else
            {
                displayedError          = null;
                labelErrorMessage.Text  = "";
                labelErrorMessage.Image = null;
            }

            // Update the world-tree-view's scripts (if there is an error icon for a failed compile).
            if (!script.IsHidden)
            {
                editorControl.EditorForm.worldTreeView.RefreshScripts();
            }
        }
예제 #2
0
        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------

        public ScriptEditor(Script script, EditorControl editorControl)
        {
            InitializeComponent();

            this.script           = script;
            this.editorControl    = editorControl;
            this.previousName     = script.Name;
            this.previousCode     = script.Code;
            this.autoCompile      = true;
            this.compileOnClose   = true;
            this.needsRecompiling = false;
            this.compileTask      = null;

            if (script.HasErrors)
            {
                displayedError          = script.Errors[0];
                labelErrorMessage.Text  = displayedError.ToString();
                labelErrorMessage.Image = ZeldaEditor.ResourceProperties.Resources.exclamation;
            }
            else
            {
                displayedError          = null;
                labelErrorMessage.Text  = "";
                labelErrorMessage.Image = null;
            }

            // Set some UI text.
            base.Text        = "Script Editor: " + script.Name;
            textBoxName.Text = script.Name;

            // Create the code editor text box.
            codeEditor = new FastColoredTextBox();
            panelCode.Controls.Add(codeEditor);
            codeEditor.Dock     = DockStyle.Fill;
            codeEditor.Language = Language.CSharp;
            codeEditor.Text     = script.Code;
            codeEditor.ReservedCountOfLineNumberChars = 4;
            codeEditor.IsChanged = false;
            codeEditor.ClearUndo();
            codeEditor.TextChanged          += codeEditor_TextChanged;
            codeEditor.SelectionChanged     += codeEditor_SelectionChanged;
            codeEditor.UndoRedoStateChanged += UpdateUndoRedoButtonStates;

            // Create the auto-complete menu.
            autoCompleteMenu               = new AutocompleteMenu(codeEditor);
            autoCompleteMenu.ForeColor     = Color.Black;
            autoCompleteMenu.BackColor     = Color.White;
            autoCompleteMenu.SelectedColor = Color.Orange;
            autoCompleteMenu.SearchPattern = @"[\w\.]";
            autoCompleteMenu.AllowTabKey   = true;
            autoCompleteMenu.Items.SetAutocompleteItems(new DynamicCollection(autoCompleteMenu, script, codeEditor));

            // Start a timer to auto-compile the script every 2 seconds.
            if (autoCompile)
            {
                /*
                 * timer = new System.Timers.Timer(2000);
                 * timer.AutoReset = true;
                 * timer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e) {
                 *
                 *      //if (needsRecompiling && compileTask == null) {
                 *      if (needsRecompiling && !editorControl.IsBusyCompiling) {
                 *              //BeginCompilingScript();
                 *              editorControl.CompileScript(script, OnCompileComplete);
                 *              editorControl.NeedsRecompiling = true;
                 *      }
                 * };
                 * timer.Start();
                 */
                // Add an idle method to check for compile task completion.
                Application.Idle += RecompileUpdate;
            }

            // Setup the initial undo/redo button states.
            UpdateUndoRedoButtonStates(this, EventArgs.Empty);
        }