public void RefreshEditor()
        {
            string _text = _tb.Text;

            _tb.Clear();
            _tb.ClearUndo();
            _tb.Text = _text;
        }
Example #2
0
        private void _innerTextbox_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                Text = _innerTextbox.Text;
                SharedEventHandler.GetInstance().RaiseOnTextboxTextChanged();

                if (_oldFilePath != _newFilePath)
                {
                    // If _oldFilePath is null, it means we opened a new document for the first time
                    // When a new document is open there is no need for us to look for the empty string and the document loaded cases
                    if (_oldFilePath != null)
                    {
                        _textBoxLoadedWithEmptyString     = true;
                        _textBoxLoadedWithNewDocumentText = true;
                    }
                    else
                    {
                        _textBoxLoadedWithEmptyString     = false;
                        _textBoxLoadedWithNewDocumentText = false;
                    }

                    _innerTextbox.ClearUndo();
                    _oldFilePath = _newFilePath;
                }
                else
                {
                    if (!_textBoxLoadedWithEmptyString && !_textBoxLoadedWithNewDocumentText)
                    {
                        History   = _innerTextbox.TextSource.Manager.History.ToOveObservableCollection();
                        RedoStack = _innerTextbox.TextSource.Manager.RedoStack.ToObservableCollection();
                    }
                    else
                    {
                        if (!_textBoxLoadedWithEmptyString)
                        {
                            _textBoxLoadedWithNewDocumentText = false;
                        }
                        else
                        {
                            _textBoxLoadedWithEmptyString = false;
                        }
                        _innerTextbox.ClearUndo();
                    }
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
Example #3
0
        /// <summary>
        /// Creates a new document and loads its content from the specified file.
        /// </summary>
        /// <param name="textBox">The text box used to edit the document.</param>
        /// <param name="filename">The filename from which the content shall be loaded.</param>
        /// <returns>The created document.</returns>
        public static Document CreateFromFile(FastColoredTextBox textBox, string filename)
        {
            var document = new Document(textBox);

            document.Load(filename);
            textBox.IsChanged = false;
            textBox.ClearUndo();
            return(document);
        }
Example #4
0
        /// <summary>
        /// Создаёт новую вкладку
        /// </summary>
        /// <param name="fileName">Название файла</param>
        private void CreateTab(string fileName)
        {
            //Необходимо проверять расширение fileName и автоматически устанавливать
            //язык подсветки currentLang

            try
            {
                var tb = new FastColoredTextBox();
                tb.Font             = new Font("Consolas", 9.75f);
                tb.ContextMenuStrip = cmMain;
                tb.Dock             = DockStyle.Fill;
                tb.BorderStyle      = BorderStyle.Fixed3D;
                tb.VirtualSpace     = true;
                tb.LeftPadding      = 17;
                tb.Language         = currentLang;
                tb.AddStyle(new MarkerStyle(new SolidBrush(Color.FromArgb(50, Color.Gray))));//same words style
                var tab = new FATabStripItem(fileName != null?Path.GetFileName(fileName):"[новый]", tb);
                tab.Tag = fileName;
                if (fileName != null)
                {
                    tb.Text = File.ReadAllText(fileName);
                }
                tb.ClearUndo();
                tb.Tag       = new TbInfo();
                tb.IsChanged = false;
                tsFiles.AddTab(tab);
                tsFiles.SelectedItem = tab;
                tb.Focus();
                tb.DelayedTextChangedInterval = 1000;
                tb.DelayedEventsInterval      = 1000;
                tb.TextChangedDelayed        += new EventHandler <TextChangedEventArgs>(tb_TextChangedDelayed);
                tb.SelectionChangedDelayed   += new EventHandler(tb_SelectionChangedDelayed);
                tb.KeyDown         += new KeyEventHandler(tb_KeyDown);
                tb.MouseMove       += new MouseEventHandler(tb_MouseMove);
                tb.ChangedLineColor = changedLineColor;
                if (btHighlightCurrentLine.Checked)
                {
                    tb.CurrentLineColor = currentLineColor;
                }
                tb.ShowFoldingLines      = btShowFoldingLines.Checked;
                tb.HighlightingRangeType = HighlightingRangeType.VisibleRange;
                //create autocomplete popup menu
                AutocompleteMenu popupMenu = new AutocompleteMenu(tb);
                popupMenu.Items.ImageList = ilAutocomplete;
                popupMenu.Opening        += new EventHandler <CancelEventArgs>(popupMenu_Opening);
                BuildAutocompleteMenu(popupMenu);
                (tb.Tag as TbInfo).popupMenu = popupMenu;
            }
            catch (Exception ex)
            {
                if (MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Retry)
                {
                    CreateTab(fileName);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Creates a new document.
        /// </summary>
        /// <param name="textBox">The text box used to edit the document.</param>
        /// <returns>The created document.</returns>
        public static Document CreateNew(FastColoredTextBox textBox)
        {
            var document = new Document(textBox)
            {
                DisplayName = "Untitled", Content = string.Empty
            };

            textBox.IsChanged = false;
            textBox.ClearUndo();
            return(document);
        }
Example #6
0
 private void CreateTab(string fileName)
 {
     try
     {
         var tb = new FastColoredTextBox();
         tb.ContextMenuStrip = cmMain;
         tb.Dock             = DockStyle.Fill;
         tb.BorderStyle      = BorderStyle.Fixed3D;
         tb.LeftPadding      = 17;
         tb.Language         = Language.CSharp;
         tb.AddStyle(new MarkerStyle(new SolidBrush(Color.FromArgb(50, Color.Gray))));//same words style
         var tab = new FATabStripItem(fileName != null?Path.GetFileName(fileName):"[new]", tb);
         tab.Tag = fileName;
         if (fileName != null)
         {
             tb.Text = File.ReadAllText(fileName);
         }
         tb.ClearUndo();
         tb.Tag       = new TbInfo();
         tb.IsChanged = false;
         tsFiles.AddTab(tab);
         tsFiles.SelectedItem = tab;
         tb.Focus();
         tb.DelayedTextChangedInterval = 1000;
         tb.DelayedEventsInterval      = 1000;
         tb.TextChangedDelayed        += new EventHandler <TextChangedEventArgs>(tb_TextChangedDelayed);
         tb.SelectionChangedDelayed   += new EventHandler(tb_SelectionChangedDelayed);
         tb.KeyDown         += new KeyEventHandler(tb_KeyDown);
         tb.MouseMove       += new MouseEventHandler(tb_MouseMove);
         tb.LineRemoved     += new EventHandler <LineRemovedEventArgs>(tb_LineRemoved);
         tb.PaintLine       += new EventHandler <PaintLineEventArgs>(tb_PaintLine);
         tb.ChangedLineColor = changedLineColor;
         if (btHighlightCurrentLine.Checked)
         {
             tb.CurrentLineColor = currentLineColor;
         }
         tb.HighlightingRangeType = HighlightingRangeType.VisibleRange;
         //create autocomplete popup menu
         AutocompleteMenu popupMenu = new AutocompleteMenu(tb);
         popupMenu.Items.ImageList = ilAutocomplete;
         popupMenu.Opening        += new EventHandler <CancelEventArgs>(popupMenu_Opening);
         BuildAutocompleteMenu(popupMenu);
         (tb.Tag as TbInfo).popupMenu = popupMenu;
     }
     catch (Exception ex)
     {
         if (MessageBox.Show(ex.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Retry)
         {
             CreateTab(fileName);
         }
     }
 }
Example #7
0
        public void CreateTB(string fileName)
        {
            try
            {
                tb             = new FastColoredTextBox();
                tb.Dock        = DockStyle.Fill;
                tb.BorderStyle = BorderStyle.Fixed3D;
                tb.LeftPadding = 17;
                tb.Language    = Language.CSharp;
                tb.AddStyle(new MarkerStyle(new SolidBrush(Color.FromArgb(50, Color.Gray))));//same words style
                this.Tag = fileName;
                if (fileName != null)
                {
                    try
                    {
                        tb.Text = File.ReadAllText(fileName);
                    }
                    catch (Exception e)
                    {
                    }
                }
                tb.ClearUndo();
                tb.IsChanged = false;
                //
                tb.ImeMode = System.Windows.Forms.ImeMode.On;

                tb.Focus();
                tb.DelayedTextChangedInterval = 1000;
                tb.DelayedEventsInterval      = 1000;
                tb.TextChangedDelayed        += new EventHandler <TextChangedEventArgs>(tb_TextChangedDelayed);
                tb.HighlightingRangeType      = HighlightingRangeType.VisibleRange;
                AutocompleteMenu popupMenu = new AutocompleteMenu(tb);
            }
            catch (Exception ex)
            {
                if (MessageBox.Show(ex.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Retry)
                {
                    CreateTB(fileName);
                }
            }
            Controls.Add(this.tb);
        }
Example #8
0
 /// <summary>
 /// Open text file
 /// </summary>
 public static void OpenFile(FastColoredTextBox textbox, string fileName, Encoding enc)
 {
     var ts = textbox.CreateTextSource();
     try
     {
         textbox.InitTextSource(ts);
         textbox.Text = File.ReadAllText(fileName, enc);
         textbox.ClearUndo();
         textbox.IsChanged = false;
         textbox.OnVisibleRangeChanged();
     }
     catch
     {
         // failed, show an empty file
         textbox.InitTextSource(textbox.CreateTextSource());
         textbox.lines.InsertLine(0, textbox.TextSource.CreateLine());
         textbox.IsChanged = false;
         throw;
     }
     textbox.Selection.Start = Place.Empty;
     textbox.DoSelectionVisible();
 }
Example #9
0
        private void LeerArchivo(string path)
        {
            TabPage            sPage      = tabArchivo.SelectedTab;
            FastColoredTextBox ctbArchivo = (FastColoredTextBox)sPage.Controls[0];

            if (ctbArchivo.Text.Equals("") && ctbArchivo.Name.Equals(""))
            {
                StreamReader reader = null;

                try
                {
                    reader          = new StreamReader(path);
                    ctbArchivo.Text = null;
                    ctbArchivo.ClearUndo();
                    ctbArchivo.Text = reader.ReadToEnd();
                    ctbArchivo.SetVisibleState(0, FastColoredTextBoxNS.VisibleState.Visible);
                    ctbArchivo.Selection = ctbArchivo.GetRange(0, 0);
                    ctbArchivo.Name      = path;
                    ctbArchivo.IsChanged = false;
                    sPage.Text           = Path.GetFileName(path);
                }
                catch (Exception e)
                {
                    MessageBox.Show("Error al abrir el archivo. \n" + e.Message + "Error");
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
            }
            else
            {
                NuevoArchivo();
                LeerArchivo(path);
            }
        }
Example #10
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);
        }
Example #11
0
        //private string LocateFile(string filename, string msg1, string msg2, string template, bool mandatory, string capt)
        //{
        //    if (File.Exists(filename))
        //        return filename;
        //    else
        //    {
        //MessageBox.Show(msg1, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        //filename = OpenFile(capt, template);
        //if (filename != null)
        //    return filename;
        //else
        //{
        //    if (!mandatory)
        //    {
        //        var res = MessageBox.Show(msg2, "Information", MessageBoxButtons.OKCancel,
        //            MessageBoxIcon.Question);
        //        if (res == DialogResult.Cancel)
        //            Close();
        //        return null;
        //    }
        //    else
        //    {
        //        Close();
        //        return null;
        //    }
        //}
        //}
        //}

        private void CreateTab(string fileName, string text = "", bool tryLoad = true)
        {
            try
            {
                var tb = new FastColoredTextBox
                {
                    Font         = new Font("Consolas", 9.75f),
                    Dock         = DockStyle.Fill,
                    BorderStyle  = BorderStyle.Fixed3D,
                    VirtualSpace = true,
                    LeftPadding  = 9,
                    Language     = Language.Custom,
                    Text         = text
                };

                var tab = new FATabStripItem(fileName != null ? Path.GetFileName(fileName) : "[new]", tb)
                {
                    Tag = fileName
                };
                if (fileName != null && tryLoad == true)
                {
                    tb.Text = File.ReadAllText(fileName);
                }
                //else
                //    tb.Text = "\n";
                //else
                //    tb.Text = "\n"; //bug?
                tb.ClearUndo();
                tb.Tag       = new TbInfo();
                tb.IsChanged = false;
                tsFiles.AddTab(tab);
                tsFiles.SelectedItem = tab;
                tb.Focus();
                tb.DelayedTextChangedInterval = 500;
                tb.DelayedEventsInterval      = 500;
                //tb.SizeChanged += TbOnSizeChanged;
                tb.HintClick += tb_HintClick;
                //tb.LineInserted += tb_LineInserted;
                //tb.TextChangedDelayed += new EventHandler<TextChangedEventArgs>(tb_TextChangedDelayed);
                tb.SelectionChangedDelayed += tb_SelectionChangedDelayed;
                tb.KeyDown += new KeyEventHandler(tb_KeyDown);
                //tb.MouseMove += new MouseEventHandler(tb_MouseMove);
                //tb.ChangedLineColor = changedLineColor;
                //if (btHighlightCurrentLine.Checked)
                //    tb.CurrentLineColor = currentLineColor;
                //tb.ShowFoldingLines = btShowFoldingLines.Checked;
                tb.DescriptionFile = DescFile;

                tb.HighlightingRangeType = HighlightingRangeType.VisibleRange;
                var popupMenu = new AutocompleteMenu(tb)
                {
                    MinFragmentLength = 2
                };
                popupMenu.Items.Width = 100;
                popupMenu.Items.SetAutocompleteItems(Constants.Commands);
                //create autocomplete popup menu
                //AutocompleteMenu popupMenu = new AutocompleteMenu(tb);
                //popupMenu.Items.ImageList = ilAutocomplete;
                popupMenu.Opening += new EventHandler <CancelEventArgs>(popupMenu_Opening);
                //BuildAutocompleteMenu(popupMenu);
                (tb.Tag as TbInfo).popupMenu = popupMenu;
            }
            catch (Exception ex)
            {
                if (MessageBox.Show(ex.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) ==
                    DialogResult.Retry)
                {
                    CreateTab(fileName);
                }
            }
        }
        private void CreateTab(string fileName)
        {
            if (ScriptCommunityPack.keywordsInformation.Count == 0)
            {
                MessageBox.Show("primarily load keywords");
                return;
            }
            try
            {
                FastColoredTextBox tb = new FastColoredTextBox();
                tb.AutoScroll = true;
                tb.BorderStyle = BorderStyle.None;
                tb.Font = new Font("Consolas", 9.75f);
                tb.BackgroundImage = Properties.Resources.bg1;
                tb.ForeColor = Color.White;
                tb.LineNumberColor = Color.White;
                tb.IndentBackColor = Color.FromArgb(80, Color.Gray);
                tb.ContextMenuStrip = cmMain;
                tb.Dock = DockStyle.Fill;
                tb.LeftPadding = 5;
                tb.Language = Language.Scp;
                tb.AddStyle(new MarkerStyle(new SolidBrush(Color.FromArgb(50, Color.Gray))));//same words style
                if (fileName != null)
                    tb.OpenFile(fileName);
                tb.Name = Path.GetFileName(fileName);
                tb.ClearUndo();
                tb.Tag = new PopupMenu();
                tb.Focus();
                tb.DelayedTextChangedInterval = 1;
                tb.DelayedEventsInterval = 500;
                tb.TextChangedDelayed += new EventHandler<TextChangedEventArgs>(tb_TextChangedDelayed);
                tb.SelectionChangedDelayed += new EventHandler(tb_SelectionChangedDelayed);
                tb.ToolTipNeeded += tb_ToolTipNeeded;
                tb.KeyDown += new KeyEventHandler(tb_KeyDown);
                tb.MouseMove += new MouseEventHandler(tb_MouseMove);
                tb.ChangedLineColor = changedLineColor;
                if (btHighlightCurrentLine.Checked)
                    tb.CurrentLineColor = currentLineColor;
                tb.ShowFoldingLines = btShowFoldingLines.Checked;
                tb.HighlightingRangeType = HighlightingRangeType.VisibleRange;
                AutocompleteMenu popupMenu = new AutocompleteMenu(tb);
                popupMenu.Items.ImageList = ilAutocomplete;
                popupMenu.Opening += new EventHandler<CancelEventArgs>(popupMenu_Opening);
                BuildAutocompleteMenu(popupMenu);
                (tb.Tag as PopupMenu).popupMenu = popupMenu;
                tb.ToolTip.OwnerDraw = true;
                tb.ToolTip.Draw += ToolTip_Draw;
                tb.ToolTip.Popup += ToolTip_Popup;
                MSATabPage newPagem = new MSATabPage(tb, fileName != null ? Path.GetFileName(fileName) : "[new]");
                newPagem.Tag = fileName;
                newPagem.MSATabPageClosing += NewPagem_MSATabPageClosing;
                msaTabControl1.MSATabPageClosed += msaTabControl1_MSATabPageClosed;
                msaTabControl1.SelectedPageChanged += MsaTabControl1_SelectedPageChanged;
                msaTabControl1.AddPage(newPagem);
                documentMap1.BackgroundImage = tb.BackgroundImage;
                documentMap1.Target = tb;
            }
            catch (Exception ex)
            {
                if (MessageBox.Show(ex.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Retry)
                    CreateTab(fileName);

                return;
            }
            msaTabControl1.SelectedPage.Tag = fileName;
        }