Example #1
0
        /// <summary>
        /// Show variables of the currently selected line in the editor.
        /// </summary>
        /// <param name="editor"></param>
        private void UpdateDebugListView(CodeEditor editor)
        {
            // RESET DEBUG LIST VIEW
            debugListView.Clear();
            debugListView.AddColumn("X", 80);
            debugListView.AddColumn("Y", 80);
            debugListView.AddColumn("Z", 80);
            debugListView.AddColumn("W", 80);

            // if the code has been edited no debug information can
            // be shown, because debug variables might have been
            // added or removed, which leads to invalid debug output
            if ((editor.Parent as TabPage).Text.EndsWith("*"))
                return;

            // get debug variables of the line where the caret is placed
            var first = editor.LineFromPosition(editor.SelectionStart);
            var last = editor.LineFromPosition(editor.SelectionEnd);
            var dbgVars = FxDebugger.GetDebugVariablesFromLine(editor, first, last - first + 1);
            dbgVars.Select(Var => FxDebugger.GetDebugVariableValue(Var.ID, glControl.Frame - 1))
                   .ForEach(dbgVars, (Val, Var) => { if (Val != null) NewVariableItem(Var.Name, Val); });
            debugListView.Update();
        }
Example #2
0
        /// <summary>
        /// Get debug variable from the specified text position in the code editor.
        /// </summary>
        /// <param name="editor">Source code editor.</param>
        /// <param name="position">Position in the code.</param>
        /// <returns>Returns the debug variable at the specified position or
        /// the default value if no debug variable could be found.</returns>
        public static DbgVar GetDebugVariableFromPosition(CodeEditor editor, int position)
        {
            // find all debug variables
            var vars = RegexDbgVar.Matches(editor.Text);

            for (int i = 0; i < vars.Count; i++)
            {
                var varLine = editor.LineFromPosition(vars[i].Index);
                // is the debug variable in the same line
                if (vars[i].Index <= position && position <= vars[i].Index + vars[i].Length)
                    return new DbgVar(i, vars[i].Index, varLine, vars[i].Value);
            }
            return null;
        }
Example #3
0
        /// <summary>
        /// Get debug variable from the specified text line in the code editor.
        /// </summary>
        /// <param name="editor">Source code editor.</param>
        /// <param name="line">Zero-based line number in the code.</param>
        /// <returns>Returns all debug variables in the specified line or
        /// <code>null</code> if no debug variable could be found.</returns>
        public static IEnumerable<DbgVar> GetDebugVariablesFromLine(CodeEditor editor, int line, int length = 1)
        {
            // find all debug variables
            var vars = RegexDbgVar.Matches(editor.Text);
            var from = line;
            var to = line + length;

            for (int i = 0; i < vars.Count; i++)
            {
                var varLine = editor.LineFromPosition(vars[i].Index);
                // is the debug variable in the same line
                if (from <= varLine && varLine < to)
                    yield return new DbgVar(i, vars[i].Index, varLine, vars[i].Value);
            }
        }
Example #4
0
        public void Fold(CodeEditor editor, int pos, int endPos)
        {
            // setup state machine
            var line = editor.LineFromPosition(pos);
            var lastLine = -1;
            var lastCharPos = line;
            var foldLevel = editor.Lines[line].FoldLevel;
            var textLength = editor.TextLength;
            const int DEFAULT_FOLD_LEVEL = 1024;

            // for each character
            for (var state = FoldState.Unknown;
                state == FoldState.Unknown ? pos < endPos : pos < textLength;
                pos++)
            {
                var c = (char)editor.GetCharAt(pos);

                switch (c)
                {
                    // open folding
                    case '{':
                        state = FoldState.StartFolding;
                        break;
                    // close folding
                    case '}':
                        state = FoldState.EndFolding;
                        break;
                    // next line
                    case '\n':
                        line++;
                        break;
                    // remember last character to place
                    // fold icon in the last character line
                    default:
                        if (char.IsLetterOrDigit(c))
                            lastCharPos = pos;
                        break;
                }

                switch (state)
                {
                    // STATE: open folding
                    case FoldState.StartFolding:
                        var lastCharLine = editor.LineFromPosition(lastCharPos);
                        // start folding at last character containing line
                        editor.Lines[lastCharLine].FoldLevelFlags = FoldLevelFlags.Header;
                        editor.Lines[lastCharLine].FoldLevel = foldLevel++;
                        // for all other lines up to the current position also add folding
                        for (int i = lastCharLine + 1; i <= line; i++)
                        {
                            editor.Lines[i].FoldLevelFlags = FoldLevelFlags.White;
                            editor.Lines[i].FoldLevel = foldLevel;
                        }
                        lastLine = line;
                        // switch to folding state
                        state = FoldState.Foldable;
                        break;
                    // STATE: close folding
                    case FoldState.EndFolding:
                        // end folding
                        editor.Lines[line].FoldLevel = foldLevel;
                        // decrease fold level
                        foldLevel = Math.Max(--foldLevel, DEFAULT_FOLD_LEVEL);
                        lastLine = line;
                        // switch to folding state (which will
                        // switch to unknown state if the most
                        // outer fold level is reached)
                        state = FoldState.Foldable;
                        break;
                    // STATE: folding
                    case FoldState.Foldable:
                        // still in folding state
                        if (foldLevel > DEFAULT_FOLD_LEVEL)
                        {
                            if (line != lastLine)
                            {
                                // set fold level for line
                                editor.Lines[line].FoldLevel = foldLevel;
                                lastLine = line;
                            }
                        }
                        // end folding state
                        else
                            state = FoldState.Unknown;
                        break;
                }
            }
        }