Esempio n. 1
0
        private void RefreshFile(string file)
        {
            bool    found = false;
            TabPage tp    = null;

            foreach (TabPage p in code_edit_panel.Controls)
            {
                if (p.Tag != null)
                {
                    if (p.Tag.ToString() == file)
                    {
                        found = true;
                        tp    = p;
                        break;
                    }
                }
            }

            if (tp != null)
            {
                if (found)
                {
                    SyntaxHighlighter.SyntaxRichTextBox m_syntaxRichTextBox = tp.Controls.OfType <SyntaxHighlighter.SyntaxRichTextBox>().FirstOrDefault();
                    // Load a file and update the syntax highlighting.
                    m_syntaxRichTextBox.LoadFile(file, RichTextBoxStreamType.PlainText);
                    m_syntaxRichTextBox.ProcessAllLines();
                }
            }

            if (tp != null)
            {
                code_edit_panel.SelectedTab = tp;
            }
        }
Esempio n. 2
0
        private void LoadFile(ListViewItem item)
        {
            bool    found = false;
            TabPage tp    = null;

            foreach (TabPage p in code_edit_panel.Controls)
            {
                if (p.Tag != null)
                {
                    if (p.Tag.ToString() == item.Tag.ToString())
                    {
                        found = true;
                        tp    = p;
                        break;
                    }
                }
            }

            if (!found)
            {
                if (item.Tag != null)
                {
                    string text = File.ReadAllText(item.Tag.ToString());
                    tp        = new TabPage($"{item.Text}        ");
                    tp.Tag    = item.Tag;
                    tp.Leave += tabPage_Leave;
                    code_edit_panel.TabPages.Add(tp);

                    SyntaxHighlighter.SyntaxRichTextBox m_syntaxRichTextBox = new SyntaxHighlighter.SyntaxRichTextBox();
                    m_syntaxRichTextBox.Dock        = DockStyle.Fill;
                    m_syntaxRichTextBox.BorderStyle = BorderStyle.None;
                    m_syntaxRichTextBox.Margin      = new Padding(0);
                    m_syntaxRichTextBox.AcceptsTab  = true;
                    m_syntaxRichTextBox.Font        = new Font(new FontFamily("Consolas"), 11);
                    m_syntaxRichTextBox.KeyDown    += M_syntaxRichTextBox_KeyDown;

                    // Add the keywords to the list.
                    List <string> keywords = new List <string>()
                    {
                        "public", "class", "void", "bool", "namespace", "using", "return", "base", "string", "int", "float", "double",
                        "char", "true", "false", "new", "private", "protected", "static", "override", "readonly", "System", "this"
                    };
                    m_syntaxRichTextBox.Settings.Keywords.AddRange(keywords);

                    // Set the comment identifier.
                    // For Lua this is two minus-signs after each other (--).
                    // For C++ code we would set this property to "//".
                    m_syntaxRichTextBox.Settings.Comment = "//";

                    // Set the colors that will be used.
                    m_syntaxRichTextBox.Settings.KeywordColor = Color.Blue;
                    m_syntaxRichTextBox.Settings.CommentColor = Color.Green;
                    m_syntaxRichTextBox.Settings.StringColor  = Color.Brown;
                    m_syntaxRichTextBox.Settings.IntegerColor = Color.BlueViolet;

                    // Let's not process strings and integers.
                    m_syntaxRichTextBox.Settings.EnableStrings  = true;
                    m_syntaxRichTextBox.Settings.EnableIntegers = true;

                    // Let's make the settings we just set valid by compiling
                    // the keywords to a regular expression.
                    m_syntaxRichTextBox.CompileKeywords();

                    // Load a file and update the syntax highlighting.
                    m_syntaxRichTextBox.LoadFile(item.Tag.ToString(), RichTextBoxStreamType.PlainText);
                    m_syntaxRichTextBox.ProcessAllLines();

                    //RichTextBox tb = new RichTextBox();
                    //tb.Dock = DockStyle.Fill;
                    //tb.BorderStyle = BorderStyle.None;
                    //tb.Margin = new Padding(0);
                    //tb.Text = text;
                    tp.Controls.Add(m_syntaxRichTextBox);
                }
            }

            if (tp != null)
            {
                code_edit_panel.SelectedTab = tp;
            }
        }