Example #1
0
        public bool Compile(EditForm editForm)
        {
            this.editForm = editForm;

            ResetScriptEvent                = new AutoResetEvent(false);
            ResetScriptWatcher              = new Thread(new ThreadStart(ResetScriptWatch));
            ResetScriptWatcher.Name         = "ResetScriptWatch";
            ResetScriptWatcher.IsBackground = true;
            ResetScriptWatcher.Start();

            string lsl = editForm.SourceCode;

            // If not hidden and not readonly
            if (!editForm.IsHidden && !this.mainForm.IsReadOnly(editForm))
            {
                if (LSLIPathHelper.IsLSLI(editForm.ScriptName)) // Expand LSLI to LSL
                {
                    lsl = ConvertLSLI();
                }
            }
            else
            {
                this.editForm.StopCompiler();
                return(false);
            }

            CSharpCode = MakeSharp(editForm.ConfLSL, lsl);

            return(GetNewHost());
        }
Example #2
0
        private void EditForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.parent.CancelClosing = false;
            this.parent.ActivateMdiForm(this);
            if (this.Dirty)
            {
                string scriptToSave = ScriptName;
                if (LSLIPathHelper.IsExpandedLSL(ScriptName))
                {
                    // Expanded scripts will always be saved as LSLI's
                    scriptToSave = LSLIPathHelper.CreateCollapsedScriptName(scriptToSave);
                }

                DialogResult dialogResult = MessageBox.Show(this, @"Save """ + scriptToSave + @"""?", "File has changed", MessageBoxButtons.YesNoCancel);
                if (dialogResult == DialogResult.Yes)
                {
                    e.Cancel = !this.parent.SaveFile(this, false);
                }
                else
                {
                    e.Cancel = (dialogResult == DialogResult.Cancel);
                }
            }

            if (!e.Cancel)
            {
                // Close related readonly's if this is an expanded script
                if (LSLIPathHelper.IsExpandedLSL(ScriptName))
                {
                    // Check if a LSLI readonly is open
                    EditForm readOnlyLSLI = (EditForm)parent.GetForm(Path.GetFileName(LSLIPathHelper.GetReadOnlyTabName(ScriptName)));

                    if (readOnlyLSLI != null)
                    {
                        readOnlyLSLI.Close();
                    }
                }

                if (!this.parent.IsReadOnly(this)) // If this is not a readonly (LSLI)
                {
                    // Delete expanded file when closing
                    string   expandedFile = LSLIPathHelper.CreateExpandedPathAndScriptName(FullPathName);
                    EditForm expandedForm = (EditForm)parent.GetForm(LSLIPathHelper.GetExpandedTabName(Path.GetFileName(expandedFile)));

                    if (expandedForm != null && !LSLIPathHelper.IsExpandedLSL(ScriptName))
                    {
                        expandedForm.Close();
                    }

                    if (File.Exists(expandedFile))
                    {
                        File.Delete(expandedFile);
                    }
                }
            }
            this.parent.CancelClosing = e.Cancel;
        }
Example #3
0
        /// <summary>
        /// Converts this script (when it's LSLI) to expanded lsl and writes it.
        /// </summary>
        /// <returns></returns>
        private string ConvertLSLI()
        {
            LSLIConverter lsliConverter = new LSLIConverter();
            string        lsl           = lsliConverter.ExpandToLSL(editForm);
            string        nameExpanded  = LSLIPathHelper.CreateExpandedScriptName(editForm.FullPathName);
            string        path          = LSLIPathHelper.CreateExpandedPathAndScriptName(editForm.FullPathName);

            LSLIPathHelper.DeleteFile(path);

            using (StreamWriter sw = new StreamWriter(path))
            {
                sw.Write(lsl);
            }

            LSLIPathHelper.HideFile(path);
            return(lsl);
        }
Example #4
0
        public bool SyntaxCheck()
        {
            bool blnResult = false;

            //if (this.disableCompilesyntaxCheckToolStripMenuItem.Checked)
            //	return false;

            if (this.IsScript)
            {
                string lsl = SourceCode;

                // If it is LSLI, it needs to import scripts first, before it recognizes imported functions
                if (LSLIPathHelper.IsLSLI(this.FullPathName))
                {
                    LSLIConverter converter = new LSLIConverter();
                    lsl = converter.ExpandToLSL(this);
                }

                LSL2CSharp translator = new LSL2CSharp(ConfLSL);
                string     strCSharp  = translator.Parse(lsl);

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    for (int intI = this.tabControl1.TabPages.Count - 1; intI > 0; intI--)
                    {
                        this.tabControl1.TabPages.RemoveAt(intI);
                    }

                    // TODO
                    TabPage tabPage = new TabPage("C#");
                    NumberedTextBox.NumberedTextBoxUC numberedTextBoxUC1 = new NumberedTextBox.NumberedTextBoxUC();
                    numberedTextBoxUC1.TextBox.Init(null, this.ConfCSharp);
                    numberedTextBoxUC1.TextBox.Text     = strCSharp;
                    numberedTextBoxUC1.TextBox.ReadOnly = true;
                    numberedTextBoxUC1.Dock             = DockStyle.Fill;
                    tabPage.Controls.Add(numberedTextBoxUC1);
                    this.tabControl.TabPages.Add(tabPage);
                }
                blnResult = (null != CompilerHelper.CompileCSharp(this, strCSharp));
            }
            return(blnResult);
        }
Example #5
0
        void TextBox_OnDirtyChanged(object sender, EventArgs e)
        {
            if (parent.IsReadOnly(this))
            {
                Dirty = false;
                return;
            }
            if (this.Text == null || this.ScriptName == null)
            {
                this.Text = this.ScriptName;
            }
            if (LSLIPathHelper.GetExpandedTabName(this.ScriptName) == this.Text)
            {
                if (this.numberedTextBoxUC1.TextBox.Dirty)
                {
                    this.Text = this.Text.Trim() + "*  ";
                }
            }
            else
            {
                this.Text = this.ScriptName;
                if (this.numberedTextBoxUC1.TextBox.Dirty)
                {
                    this.Text = this.Text.Trim() + "*  ";
                }
                else
                {
                    this.Text = this.Text.Trim() + "   ";
                }
            }

            TabPage tabPage = this.Tag as TabPage;

            if (tabPage != null)
            {
                tabPage.Text = this.Text;
            }

            this.parent.OnDirtyChanged(this.numberedTextBoxUC1.TextBox.Dirty);
        }
Example #6
0
        public void SaveCurrentFile(string strPath)
        {
            // Check if this is an expanded.lsl
            if (LSLIPathHelper.IsExpandedLSL(strPath))
            {
                string LSLIfilePath = LSLIPathHelper.CreateCollapsedPathAndScriptName(strPath);
                // Check if an LSLI version of this script exists
                if (File.Exists(LSLIfilePath))
                {
                    // Save the LSLI file as well
                    File.WriteAllText(LSLIfilePath, LSLIConverter.CollapseToLSLI(this.numberedTextBoxUC1.TextBox.Text));
                    EditForm form = null;

                    // If it's currently open, then refresh it
                    for (int i = 0; i < Application.OpenForms.Count; i++)
                    {
                        Form   openForm = Application.OpenForms[i];
                        string filename = LSLIPathHelper.TrimStarsAndWhiteSpace(openForm.Text);
                        if (filename == Path.GetFileName(LSLIfilePath))
                        {
                            form = (EditForm)openForm;
                        }
                    }

                    if (form != null && form.Enabled)
                    {
                        parent.OpenFile(LSLIfilePath, Guid.NewGuid(), true);
                        form.Close();
                    }
                }
                this.numberedTextBoxUC1.TextBox.Dirty = false;
                this.Text = LSLIPathHelper.GetExpandedTabName(strPath);
            }
            else
            {
                this.FullPathName = strPath;
                Encoding encodeAs = this.encodedAs;
                if (this.IsScript && encodeAs == null)
                {
                    switch (Properties.Settings.Default.OutputFormat)
                    {
                    case "UTF8":
                        encodeAs = Encoding.UTF8;
                        break;

                    case "Unicode":
                        encodeAs = Encoding.Unicode;
                        break;

                    case "BigEndianUnicode":
                        encodeAs = Encoding.BigEndianUnicode;
                        break;

                    default:
                        encodeAs = Encoding.Default;
                        break;
                    }
                }
                else if (encodeAs == null)
                {
                    encodeAs = Encoding.UTF8;
                }

                this.numberedTextBoxUC1.TextBox.SaveCurrentFile(strPath, encodeAs);
                this.encodedAs = encodeAs;
            }
            this.m_IsNew = false;
        }