Exemplo n.º 1
0
        private static void HighlightPriv(RichTextBox rtb, SprContext ctx)
        {
            if (rtb == null)
            {
                Debug.Assert(false); return;
            }

            int iSelStart = rtb.SelectionStart;
            int iSelLen   = rtb.SelectionLength;

            string strText = rtb.Text;

            rtb.SelectAll();
            // rtb.SelectionBackColor = SystemColors.Window;
            rtb.SelectionColor = SystemColors.ControlText;

            List <SprStyle> l = GetHighlight(strText, ctx);

            l.Add(null);             // Sentinel

            SprStyle sFrom = null;
            int      pFrom = 0;

            for (int i = 0; i < l.Count; ++i)
            {
                SprStyle s = l[i];

                if (sFrom != null)
                {
                    if ((s == null) || !sFrom.Equals(s))
                    {
                        if (sFrom.Color.HasValue)
                        {
                            rtb.Select(pFrom, i - pFrom);
                            rtb.SelectionColor = sFrom.Color.Value;
                            // rtb.SelectionBackColor = sFrom.Color.Value;
                        }

                        sFrom = s;
                        pFrom = i;
                    }
                }
                else
                {
                    sFrom = s;
                    pFrom = i;
                }
            }

            rtb.Select(iSelStart, iSelLen);
        }
Exemplo n.º 2
0
        private static void SetStyle(List <SprStyle> l, SprPart p,
                                     int iPartOffset, int nLength, SprStyle s)
        {
            int px = p.Start + iPartOffset;

            if (px < 0)
            {
                Debug.Assert(false); return;
            }
            if (nLength < 0)
            {
                Debug.Assert(false); return;
            }
            if ((px + nLength) > l.Count)
            {
                Debug.Assert(false); return;
            }

            for (int i = 0; i < nLength; ++i)
            {
                Debug.Assert(l[px + i] == null);
                l[px + i] = s;
            }
        }
Exemplo n.º 3
0
        private static bool HighlightRegularPlh(SprPart pPart, List <SprStyle> lStyles,
                                                Stack <SprPart> sToDo, SprContext ctx)
        {
            string str = pPart.Text;

            int iStart = str.IndexOf('{');

            if (iStart < 0)
            {
                return(false);
            }

            if ((iStart + 2) >= str.Length)
            {
                SetStyle(lStyles, pPart, iStart, str.Length - iStart, SprStyleError);
            }
            else
            {
                int iOpen  = str.IndexOf('{', iStart + 2);
                int iClose = str.IndexOf('}', iStart + 2);

                bool bAT = ((ctx != null) && ctx.EncodeAsAutoTypeSequence);

                if (iClose < 0)
                {
                    SetStyle(lStyles, pPart, iStart, str.Length - iStart, SprStyleError);
                }
                else if ((iOpen >= 0) && (iOpen < iClose))
                {
                    sToDo.Push(pPart.GetPart(iOpen));

                    SetStyle(lStyles, pPart, iStart, iOpen - iStart, SprStyleError);
                }
                else if (bAT && ((str[iStart + 1] == '{') || (str[iStart + 1] == '}')) &&
                         (iClose != (iStart + 2)))
                {
                    sToDo.Push(pPart.GetPart(iClose + 1));

                    SetStyle(lStyles, pPart, iStart, iClose - iStart + 1, SprStyleError);
                }
                else
                {
                    sToDo.Push(pPart.GetPart(iClose + 1));

                    int iErrLvl = 0;

                    string strPlh = str.Substring(iStart + 1, iClose - iStart - 1);
                    if (strPlh.Length == 0)
                    {
                        Debug.Assert(false); iErrLvl = 2;
                    }
                    else if (char.IsWhiteSpace(strPlh[0]))
                    {
                        iErrLvl = 2;
                    }
                    else if (strPlh.StartsWith("S:", StrUtil.CaseIgnoreCmp) &&
                             (ctx != null) && (ctx.Entry != null))
                    {
                        string strField = strPlh.Substring(2);

                        List <string> lFields = PwDefs.GetStandardFields();
                        lFields.AddRange(ctx.Entry.Strings.GetKeys());

                        bool bFound = false;
                        foreach (string strAvail in lFields)
                        {
                            if (strField.Equals(strAvail, StrUtil.CaseIgnoreCmp))
                            {
                                bFound = true;
                                break;
                            }
                        }

                        if (!bFound)
                        {
                            iErrLvl = 1;
                        }
                    }

                    SprStyle s = SprStyleOK;
                    if (iErrLvl == 1)
                    {
                        s = SprStyleWarning;
                    }
                    else if (iErrLvl > 1)
                    {
                        s = SprStyleError;
                    }

                    SetStyle(lStyles, pPart, iStart, iClose - iStart + 1, s);
                }
            }

            if (iStart > 0)
            {
                sToDo.Push(pPart.GetPart(0, iStart));
            }
            return(true);
        }