Exemplo n.º 1
0
        /// <summary>Convert to a rich text form with the builder.</summary>
        /// <param name="builder"></param>
        public void ToRichText(RichTextBuilder builder)
        {
            if (IsTarget)
            {
                builder.ForegroundColor = Color.Blue;
                builder.AppendFormat("<{0}> ", AddressString);
            }

            if (IsFunction)
            {
                builder.ForegroundColor = Color.DarkGreen;
            }
            else if (IsPointer)
            {
                builder.ForegroundColor = Color.Purple;
            }
            builder.Append(ToStringValue());

            if (IsInvalid)
            {
                builder.ForegroundColor = Color.Red;
                builder.Append(" <<" + Errors.Replace("\n", "; ") + ">>");
            }

            builder.ForegroundColor = Color.Black;
        }
Exemplo n.º 2
0
        public virtual void ToRichText(RichTextBuilder builder)
        {
            string format;

            if (OpcodeFormats.TryGetValue(Opcode, out format))
            {
                for (int index = 0; index < format.Length; index++)
                {
                    if (format[index] == '{')
                    {
                        if (format[index + 1] == '{')
                        {
                            index++;
                            builder.Append('{');
                        }
                        else
                        {
                            int end;

                            for (end = ++index; format[end] != '}'; end++)
                            {
                                ;
                            }
                            int           operandIndex = int.Parse(format.Substring(index, end - index));
                            ScriptOperand operand      = GetOperand(operandIndex);
                            operand.ToRichText(builder);
                            index = end;
                        }
                    }
                    else
                    {
                        builder.Append(format[index]);
                    }
                }
            }
            else
            {
                if (IsOpcodeDefined)
                {
                    builder.Append(Opcode.ToString());
                }
                else
                {
                    builder.ForegroundColor = Color.Red;
                    builder.AppendFormat("{0:X2}", (int)Opcode);
                    builder.ForegroundColor = Color.Black;
                }

                foreach (ScriptOperand operand in Operands)
                {
                    builder.Append(" ");
                    operand.ToRichText(builder);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Convert to rich text.
        /// </summary>
        /// <param name="builder"></param>
        public void ToRichText(RichTextBuilder builder)
        {
            builder.AppendFormat("{0}: ", AddressString);
            Opcode.ToRichText(builder);

            for (int index = 0; index < Operands.Count; index++)
            {
                builder.Append(index == 0 ? " " : ", ");
                Operands[index].ToRichText(builder);
            }
        }
Exemplo n.º 4
0
        /// <summary>Convert to a rich text form with the builder.</summary>
        /// <param name="builder"></param>
        public void ToRichText(RichTextBuilder builder)
        {
            if (IsTarget) {
                builder.ForegroundColor = Color.Blue;
                builder.AppendFormat("<{0}> ", AddressString);
            }

            if (IsFunction)
                builder.ForegroundColor = Color.DarkGreen;
            else if (IsPointer)
                builder.ForegroundColor = Color.Purple;
            builder.Append(ToStringValue());

            if (IsInvalid) {
                builder.ForegroundColor = Color.Red;
                builder.Append(" <<" + Errors.Replace("\n", "; ") + ">>");
            }

            builder.ForegroundColor = Color.Black;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Convert to rich text.
        /// </summary>
        /// <param name="builder"></param>
        public void ToRichText(RichTextBuilder builder)
        {
            builder.AppendFormat("{0}: ", AddressString);
            Opcode.ToRichText(builder);

            for (int index = 0; index < Operands.Count; index++) {
                builder.Append(index == 0 ? " " : ", ");
                Operands[index].ToRichText(builder);
            }
        }
Exemplo n.º 6
0
        public virtual void ToRichText(RichTextBuilder builder)
        {
            string format;

            if (OpcodeFormats.TryGetValue(Opcode, out format)) {
                for (int index = 0; index < format.Length; index++) {
                    if (format[index] == '{') {
                        if (format[index + 1] == '{') {
                            index++;
                            builder.Append('{');
                        } else {
                            int end;

                            for (end = ++index; format[end] != '}'; end++) ;
                            int operandIndex = int.Parse(format.Substring(index, end - index));
                            ScriptOperand operand = GetOperand(operandIndex);
                            operand.ToRichText(builder);
                            index = end;
                        }
                    } else
                        builder.Append(format[index]);
                }
            } else {
                if (IsOpcodeDefined)
                    builder.Append(Opcode.ToString());
                else {
                    builder.ForegroundColor = Color.Red;
                    builder.AppendFormat("{0:X2}", (int)Opcode);
                    builder.ForegroundColor = Color.Black;
                }

                foreach (ScriptOperand operand in Operands) {
                    builder.Append(" ");
                    operand.ToRichText(builder);
                }
            }
        }
Exemplo n.º 7
0
        public override System.Windows.Forms.Control Browse(Action<double> progressUpdateCallback = null)
        {
            RichTextBuilder builder = new RichTextBuilder();
            bool indentNext = false;

            //builder.Append(@"{\rtf\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\par ");
            builder.UnderlineStyle = RichTextUnderlineStyle.Double;

            foreach (ScriptInstruction instruction in Instructions) {
                string codeName = CodeAddressName(instruction.Address);

                if (codeName != null)
                    builder.AppendFormat("\n==============================\n{0}\n==============================\n", codeName);

                if (instruction.IsTarget)
                    builder.IsUnderlined = true;
                builder.AppendFormat("{0:X}h", instruction.Address);
                if (instruction.IsTarget)
                    builder.IsUnderlined = false;
                builder.Append(":\t");

                if (indentNext)
                    builder.Append("\t");
                instruction.ToRichText(builder);
                //builder.Append(instruction.ToString());
                builder.Append("\n");
                if (instruction.IsBranch && !indentNext)
                    builder.Append("\n");
                indentNext = instruction.IsTest;
            }

            builder.Append(ExceptionEnd);
            var output = builder.ToString();

            BetterRichTextBox box = new BetterRichTextBox() {
                ReadOnly = false,
                Multiline = true,
                //ScrollBars = ScrollBars.Vertical,
                Rtf = output,
                WordWrap = false,
            };

            Font normal = box.Font;
            var underlined = new Font(normal, FontStyle.Underline);
            bool recurse = false;

            box.SelectionChanged += (object sender, EventArgs args) => {
                if (recurse)
                    return;

                try {
                    Point scrollPosition = box.ScrollPosition;
                    int resetStart = box.SelectionStart, resetLength = box.SelectionLength;
                    box.BeginUpdate();

                    recurse = true;
                    var start = box.SelectionStart;
                    string text = box.Text;

                    if (!IsIdentifier(text, start) && !IsIdentifier(text, start - 1))
                        return;
                    while (IsIdentifier(text, start - 1))
                        start--;

                    int end = box.SelectionStart;
                    while (IsIdentifier(text, end))
                        end++;

                    string searchText = text.Substring(start, end - start);

                    box.SelectAll();
                    //box.SelectionFont = normal;
                    box.SelectionBackColor = Color.Transparent;

                    start = 0;
                    while (true) {
                        start = text.IndexOf(searchText, start);
                        if (start < 0)
                            break;

                        if (!IsIdentifier(text, start - 1) && !IsIdentifier(text, start + searchText.Length)) {
                            box.Select(start, searchText.Length);
                            //box.SelectionFont = underlined;
                            box.SelectionBackColor = Color.Yellow;
                        }

                        start += searchText.Length;
                    }

                    box.Select(resetStart, resetLength);
                    box.ScrollPosition = scrollPosition;
                } finally {
                    box.EndUpdate();
                    box.Invalidate();
                    recurse = false;
                }
            };

            box.LinkClicked += (sender, args) => {
                throw new Exception();
            };

            return box;
        }
Exemplo n.º 8
0
        public override System.Windows.Forms.Control Browse(Action <double> progressUpdateCallback = null)
        {
            RichTextBuilder builder    = new RichTextBuilder();
            bool            indentNext = false;

            //builder.Append(@"{\rtf\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\par ");
            builder.UnderlineStyle = RichTextUnderlineStyle.Double;

            foreach (ScriptInstruction instruction in Instructions)
            {
                string codeName = CodeAddressName(instruction.Address);

                if (codeName != null)
                {
                    builder.AppendFormat("\n==============================\n{0}\n==============================\n", codeName);
                }

                if (instruction.IsTarget)
                {
                    builder.IsUnderlined = true;
                }
                builder.AppendFormat("{0:X}h", instruction.Address);
                if (instruction.IsTarget)
                {
                    builder.IsUnderlined = false;
                }
                builder.Append(":\t");

                if (indentNext)
                {
                    builder.Append("\t");
                }
                instruction.ToRichText(builder);
                //builder.Append(instruction.ToString());
                builder.Append("\n");
                if (instruction.IsBranch && !indentNext)
                {
                    builder.Append("\n");
                }
                indentNext = instruction.IsTest;
            }

            builder.Append(ExceptionEnd);
            var output = builder.ToString();

            BetterRichTextBox box = new BetterRichTextBox()
            {
                ReadOnly  = false,
                Multiline = true,
                //ScrollBars = ScrollBars.Vertical,
                Rtf      = output,
                WordWrap = false,
            };

            Font normal     = box.Font;
            var  underlined = new Font(normal, FontStyle.Underline);
            bool recurse    = false;

            box.SelectionChanged += (object sender, EventArgs args) => {
                if (recurse)
                {
                    return;
                }

                try {
                    Point scrollPosition = box.ScrollPosition;
                    int   resetStart = box.SelectionStart, resetLength = box.SelectionLength;
                    box.BeginUpdate();

                    recurse = true;
                    var    start = box.SelectionStart;
                    string text  = box.Text;

                    if (!IsIdentifier(text, start) && !IsIdentifier(text, start - 1))
                    {
                        return;
                    }
                    while (IsIdentifier(text, start - 1))
                    {
                        start--;
                    }

                    int end = box.SelectionStart;
                    while (IsIdentifier(text, end))
                    {
                        end++;
                    }

                    string searchText = text.Substring(start, end - start);

                    box.SelectAll();
                    //box.SelectionFont = normal;
                    box.SelectionBackColor = Color.Transparent;

                    start = 0;
                    while (true)
                    {
                        start = text.IndexOf(searchText, start);
                        if (start < 0)
                        {
                            break;
                        }

                        if (!IsIdentifier(text, start - 1) && !IsIdentifier(text, start + searchText.Length))
                        {
                            box.Select(start, searchText.Length);
                            //box.SelectionFont = underlined;
                            box.SelectionBackColor = Color.Yellow;
                        }

                        start += searchText.Length;
                    }

                    box.Select(resetStart, resetLength);
                    box.ScrollPosition = scrollPosition;
                } finally {
                    box.EndUpdate();
                    box.Invalidate();
                    recurse = false;
                }
            };

            box.LinkClicked += (sender, args) => {
                throw new Exception();
            };


            return(box);
        }