Пример #1
0
        public void SelectIntellisenseListBoxItem()
        {
            if (ActiveTextBox == null)
            {
                return;
            }

            if (WordMatched)
            {
                // insert selected item
                if (ActiveTextBox is TextBox)
                {
                    TextBox activeTextBox = (TextBox)ActiveTextBox;

                    activeTextBox.SelectionStart  = _carotLocation;
                    activeTextBox.SelectionLength = 0;
                    int    selectedIndex         = IntellisenseListBox.SelectedIndex;
                    string intellisenseSelection = _completionList[selectedIndex];

                    string precursorText     = activeTextBox.Text.Substring(0, activeTextBox.SelectionStart);
                    string postcursorText    = activeTextBox.Text.Substring(activeTextBox.SelectionStart);
                    string initialText       = precursorText.Substring(0, precursorText.Length - _charsToRemoveList[selectedIndex]);
                    string postInsertionText = initialText.Insert(precursorText.Length - _charsToRemoveList[selectedIndex], intellisenseSelection);

                    activeTextBox.Text = postInsertionText + postcursorText;
                    if (ActiveGridView != null && ActiveGridView.CurrentCell != null)
                    {
                        ActiveGridView.CurrentCell.Value = activeTextBox.Text;
                    }

                    activeTextBox.SelectionStart = initialText.Length + intellisenseSelection.Length;
                }
                else if (ActiveTextBox is UIScintilla)
                {
                    UIScintilla activeScintilla = (UIScintilla)ActiveTextBox;

                    activeScintilla.SelectionStart = _carotLocation + 1;
                    //activeScintilla.SelectionLength = 0;
                    int    selectedIndex         = IntellisenseListBox.SelectedIndex;
                    string intellisenseSelection = _completionList[selectedIndex];

                    string precursorText     = activeScintilla.Text.Substring(0, activeScintilla.SelectionStart);
                    string postcursorText    = activeScintilla.Text.Substring(activeScintilla.SelectionStart);
                    string initialText       = precursorText.Substring(0, precursorText.Length - _charsToRemoveList[selectedIndex]);
                    string postInsertionText = initialText.Insert(precursorText.Length - _charsToRemoveList[selectedIndex], intellisenseSelection);

                    activeScintilla.Text = postInsertionText + postcursorText;
                    if (ActiveGridView != null && ActiveGridView.CurrentCell != null)
                    {
                        ActiveGridView.CurrentCell.Value = activeScintilla.Text;
                    }

                    activeScintilla.SelectionStart = initialText.Length + intellisenseSelection.Length;
                }
            }
        }
        private UIScintilla NewTextEditorActions(ProjectType projecttype, string title = "newTextEditorActions")
        {
            UIScintilla scintilla = new UIScintilla();

            scintilla.Dock         = DockStyle.Fill;
            scintilla.KeyDown     += newTextEditorActions_KeyDown;
            scintilla.TextChanged += newTextEditorActions_TextChanged;
            scintilla.Leave       += newTextEditorActions_Leave;

            // Reset the styles
            scintilla.StyleResetDefault();
            scintilla.Styles[Style.Default].Font = "Consolas";
            scintilla.Styles[Style.Default].Size = 11;
            scintilla.StyleClearAll();

            scintilla.SetProperty("tab.timmy.whinge.level", "1");
            scintilla.SetProperty("fold", "1");

            // Use margin 2 for fold markers
            scintilla.Margins[2].Type      = MarginType.Symbol;
            scintilla.Margins[2].Mask      = Marker.MaskFolders;
            scintilla.Margins[2].Sensitive = true;
            scintilla.Margins[2].Width     = 20;

            // Reset folder markers
            for (int i = Marker.FolderEnd; i <= Marker.FolderOpen; i++)
            {
                scintilla.Markers[i].SetForeColor(SystemColors.ControlLightLight);
                scintilla.Markers[i].SetBackColor(SystemColors.ControlDark);
            }

            // Style the folder markers
            scintilla.Markers[Marker.Folder].Symbol = MarkerSymbol.BoxPlus;
            scintilla.Markers[Marker.Folder].SetBackColor(SystemColors.ControlText);
            scintilla.Markers[Marker.FolderOpen].Symbol = MarkerSymbol.BoxMinus;
            scintilla.Markers[Marker.FolderEnd].Symbol  = MarkerSymbol.BoxPlusConnected;
            scintilla.Markers[Marker.FolderEnd].SetBackColor(SystemColors.ControlText);
            scintilla.Markers[Marker.FolderMidTail].Symbol = MarkerSymbol.TCorner;
            scintilla.Markers[Marker.FolderOpenMid].Symbol = MarkerSymbol.BoxMinusConnected;
            scintilla.Markers[Marker.FolderSub].Symbol     = MarkerSymbol.VLine;
            scintilla.Markers[Marker.FolderTail].Symbol    = MarkerSymbol.LCorner;

            // Enable automatic folding
            scintilla.AutomaticFold = (AutomaticFold.Show | AutomaticFold.Click | AutomaticFold.Change);

            switch (projecttype)
            {
            case ProjectType.Python:
                scintilla.Lexer = Lexer.Python;
                scintilla.Styles[Style.Python.Default].ForeColor      = Color.FromArgb(0x80, 0x80, 0x80);
                scintilla.Styles[Style.Python.CommentLine].ForeColor  = Color.FromArgb(0x00, 0x7F, 0x00);
                scintilla.Styles[Style.Python.CommentLine].Italic     = true;
                scintilla.Styles[Style.Python.Number].ForeColor       = Color.FromArgb(0x00, 0x7F, 0x7F);
                scintilla.Styles[Style.Python.String].ForeColor       = Color.FromArgb(0x7F, 0x00, 0x7F);
                scintilla.Styles[Style.Python.Character].ForeColor    = Color.FromArgb(0x7F, 0x00, 0x7F);
                scintilla.Styles[Style.Python.Word].ForeColor         = Color.FromArgb(0x00, 0x00, 0x7F);
                scintilla.Styles[Style.Python.Word].Bold              = true;
                scintilla.Styles[Style.Python.Triple].ForeColor       = Color.FromArgb(0x7F, 0x00, 0x00);
                scintilla.Styles[Style.Python.TripleDouble].ForeColor = Color.FromArgb(0x7F, 0x00, 0x00);
                scintilla.Styles[Style.Python.ClassName].ForeColor    = Color.FromArgb(0x00, 0x00, 0xFF);
                scintilla.Styles[Style.Python.ClassName].Bold         = true;
                scintilla.Styles[Style.Python.DefName].ForeColor      = Color.FromArgb(0x00, 0x7F, 0x7F);
                scintilla.Styles[Style.Python.DefName].Bold           = true;
                scintilla.Styles[Style.Python.Operator].Bold          = true;
                scintilla.Styles[Style.Python.CommentBlock].ForeColor = Color.FromArgb(0x7F, 0x7F, 0x7F);
                scintilla.Styles[Style.Python.CommentBlock].Italic    = true;
                scintilla.Styles[Style.Python.StringEol].ForeColor    = Color.FromArgb(0x00, 0x00, 0x00);
                scintilla.Styles[Style.Python.StringEol].BackColor    = Color.FromArgb(0xE0, 0xC0, 0xE0);
                scintilla.Styles[Style.Python.StringEol].FillLine     = true;
                scintilla.Styles[Style.Python.Word2].ForeColor        = Color.FromArgb(0x40, 0x70, 0x90);
                scintilla.Styles[Style.Python.Decorator].ForeColor    = Color.FromArgb(0x80, 0x50, 0x00);
                // Important for Python
                scintilla.ViewWhitespace = WhitespaceMode.VisibleAlways;
                break;

            case ProjectType.CSScript:
            case ProjectType.TagUI:
                scintilla.Lexer = Lexer.Cpp;
                scintilla.Styles[Style.Cpp.Default].ForeColor        = Color.Silver;
                scintilla.Styles[Style.Cpp.Comment].ForeColor        = Color.FromArgb(0, 128, 0);     // Green
                scintilla.Styles[Style.Cpp.CommentLine].ForeColor    = Color.FromArgb(0, 128, 0);     // Green
                scintilla.Styles[Style.Cpp.CommentLineDoc].ForeColor = Color.FromArgb(128, 128, 128); // Gray
                scintilla.Styles[Style.Cpp.Number].ForeColor         = Color.Olive;
                scintilla.Styles[Style.Cpp.Word].ForeColor           = Color.Blue;
                scintilla.Styles[Style.Cpp.Word2].ForeColor          = Color.Blue;
                scintilla.Styles[Style.Cpp.String].ForeColor         = Color.FromArgb(163, 21, 21); // Red
                scintilla.Styles[Style.Cpp.Character].ForeColor      = Color.FromArgb(163, 21, 21); // Red
                scintilla.Styles[Style.Cpp.Verbatim].ForeColor       = Color.FromArgb(163, 21, 21); // Red
                scintilla.Styles[Style.Cpp.StringEol].BackColor      = Color.Pink;
                scintilla.Styles[Style.Cpp.Operator].ForeColor       = Color.Purple;
                scintilla.Styles[Style.Cpp.Preprocessor].ForeColor   = Color.Maroon;
                break;

            case ProjectType.PowerShell:
                scintilla.Lexer = Lexer.PowerShell;
                scintilla.Styles[Style.PowerShell.Default].ForeColor           = Color.Black;
                scintilla.Styles[Style.PowerShell.Comment].ForeColor           = Color.Green;
                scintilla.Styles[Style.PowerShell.CommentDocKeyword].ForeColor = Color.Green;
                scintilla.Styles[Style.PowerShell.CommentStream].ForeColor     = Color.Green;
                scintilla.Styles[Style.PowerShell.Number].ForeColor            = Color.Gray;
                scintilla.Styles[Style.PowerShell.Cmdlet].ForeColor            = Color.LimeGreen;
                scintilla.Styles[Style.PowerShell.Variable].ForeColor          = Color.Gray;
                scintilla.Styles[Style.PowerShell.Operator].ForeColor          = Color.Teal;
                scintilla.Styles[Style.PowerShell.String].ForeColor            = Color.LimeGreen;
                scintilla.Styles[Style.PowerShell.Keyword].ForeColor           = Color.ForestGreen;
                scintilla.Styles[Style.PowerShell.User1].ForeColor             = Color.Magenta;
                scintilla.Styles[Style.PowerShell.Character].ForeColor         = Color.LimeGreen;
                scintilla.Styles[Style.PowerShell.Alias].ForeColor             = Color.MediumBlue;
                scintilla.Styles[Style.PowerShell.Function].ForeColor          = Color.MediumBlue;
                scintilla.Styles[Style.PowerShell.HereCharacter].ForeColor     = Color.LimeGreen;
                scintilla.Styles[Style.PowerShell.HereString].ForeColor        = Color.LimeGreen;
                scintilla.Styles[Style.PowerShell.Identifier].ForeColor        = Color.Black;
                break;

                //Could be useful later if we decide to allow users to open/edit the config file
                //case Json:
                //    // Configure the JSON lexer styles
                //    scintilla.Lexer = Lexer.Json;
                //    scintilla.Styles[Style.Json.Default].ForeColor = Color.Silver;
                //    scintilla.Styles[Style.Json.BlockComment].ForeColor = Color.FromArgb(0, 128, 0); // Green
                //    scintilla.Styles[Style.Json.LineComment].ForeColor = Color.FromArgb(0, 128, 0); // Green
                //    scintilla.Styles[Style.Json.Number].ForeColor = Color.Olive;
                //    scintilla.Styles[Style.Json.PropertyName].ForeColor = Color.Blue;
                //    scintilla.Styles[Style.Json.String].ForeColor = Color.FromArgb(163, 21, 21); // Red
                //    scintilla.Styles[Style.Json.StringEol].BackColor = Color.Pink;
                //    scintilla.Styles[Style.Json.Operator].ForeColor = Color.Purple;
                //    break;
            }

            return(scintilla);
        }
Пример #3
0
        public bool PopulateIntellisenseListBox()
        {
            IntellisenseListBox.Items.Clear();
            _workspace.ClearSolution();
            _completionList    = new List <string>();
            _charsToRemoveList = new List <int>();

            string script = "";

            if (ActiveTextBox is TextBox)
            {
                Variables.ForEach(v => script += $"{v.VariableType.GetRealTypeFullName()}? {v.VariableName} = " +
                                                 $"{(v.VariableValue == null || (v.VariableValue is string && string.IsNullOrEmpty(v.VariableValue.ToString())) ? "null" : v.VariableValue.ToString().Trim())};");
                Arguments.ForEach(a => script += $"{a.ArgumentType.GetRealTypeFullName()}? {a.ArgumentName} = " +
                                                 $"{(a.ArgumentValue == null || (a.ArgumentValue is string && string.IsNullOrEmpty(a.ArgumentValue.ToString())) ? "null" : a.ArgumentValue.ToString().Trim())};");

                TextBox activeTextBox = (TextBox)ActiveTextBox;

                var scriptCode = script + activeTextBox.Text;

                var results = LoadIntellisenseScript(script, scriptCode);

                if (results == null)
                {
                    return(false);
                }

                foreach (var i in results.Items)
                {
                    string recString = activeTextBox.Text.Substring(i.Span.Start - script.Length, i.Span.Length);
                    if (scriptCode[script.Length + activeTextBox.SelectionStart - 1] != '.')
                    {
                        if (recString != "" && i.DisplayText.Length >= recString.Length && i.DisplayText.Substring(0, recString.Length).ToLower().Equals(recString.ToLower()))
                        {
                            if (recString != "")
                            {
                                _completionList.Add(i.DisplayText);
                                _charsToRemoveList.Add(recString.Length);
                            }
                            else
                            {
                                _completionList.Add(i.DisplayText);
                                _charsToRemoveList.Add(0);
                            }
                            IntellisenseListBox.Items.Add(new UIIntellisenseListBoxItem(i.DisplayText, GetIntellisenseIcon(i)));
                        }
                    }
                    else
                    {
                        _completionList.Add(i.DisplayText);
                        _charsToRemoveList.Add(0);
                        IntellisenseListBox.Items.Add(new UIIntellisenseListBoxItem(i.DisplayText, GetIntellisenseIcon(i)));
                    }
                }
            }
            else if (ActiveTextBox is UIScintilla)
            {
                UIScintilla activeScintilla = (UIScintilla)ActiveTextBox;

                var scriptCode = script + activeScintilla.Text;

                if (activeScintilla.SelectionStart >= scriptCode.Length)
                {
                    activeScintilla.SelectionStart = scriptCode.Length - 1;
                }
                var results = LoadIntellisenseScript(script, scriptCode);

                if (results == null)
                {
                    return(false);
                }
                try
                {
                    foreach (var i in results.Items)
                    {
                        int trueLength = i.Span.Length;
                        if (i.Span.Length == 0)
                        {
                            trueLength = 1;
                        }
                        string recString = activeScintilla.Text.Substring(i.Span.Start - script.Length, trueLength);
                        if (scriptCode[script.Length + activeScintilla.SelectionStart] != '.')
                        {
                            if (recString != "" && i.DisplayText.Length >= recString.Length && i.DisplayText.Substring(0, recString.Length).ToLower().Equals(recString.ToLower()))
                            {
                                if (recString != "")
                                {
                                    _completionList.Add(i.DisplayText);
                                    _charsToRemoveList.Add(recString.Length);
                                }
                                else
                                {
                                    _completionList.Add(i.DisplayText);
                                    _charsToRemoveList.Add(0);
                                }
                                IntellisenseListBox.Items.Add(new UIIntellisenseListBoxItem(i.DisplayText, GetIntellisenseIcon(i)));
                            }
                        }
                        else
                        {
                            _completionList.Add(i.DisplayText);
                            _charsToRemoveList.Add(0);
                            IntellisenseListBox.Items.Add(new UIIntellisenseListBoxItem(i.DisplayText, GetIntellisenseIcon(i)));
                        }
                    }
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine(ex);
                }
            }

            if (IntellisenseListBox.Items.Count <= 0)
            {
                return(false);
            }

            return(true);
        }