Ejemplo n.º 1
0
 /// <summary>
 /// Make the whole text the default font color.
 /// </summary>
 /// <param name="rtb">The richedit control that hold the note content.</param>
 /// <param name="rtf">The RTF text</param>
 /// <param name="skinnr">The skin number of the current note.</param>
 /// <param name="notes">Reference to notes class.</param>
 /// <returns>The new rtf stream</returns>
 private static string ResetHighlighting(RichTextBox rtb, string rtf, int skinnr, Notes notes)
 {
     comment            = false;
     commentline        = false;
     outerhtml          = true;
     htmlstringpart     = false;
     phpstringpart      = false;
     currentstringquote = '"';
     //Log.Write(LogType.info, "rtb.TextLength=" + rtb.TextLength); // debug
     return(rtfdirectedit.SetColorAllRTF(rtf, notes.GetTextClr(skinnr), rtb.TextLength));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Do a quick syntax check of the last added part of text.
        /// </summary>
        /// <param name="rtb">RichEditTextbox</param>
        /// <param name="skinnr">The skinnr</param>
        /// <param name="notes">Reference to notes</param>
        public static void CheckSyntaxQuick(RichTextBox rtb, int skinnr, Notes notes)
        {
            if (!keywordsinit)
            {
                Log.Write(LogType.error, "Keywords not initialized as they should already have. Hotfixing this.");
                InitHighlighter();
            }

            // check if highlighting is enabled at all.
            if (langs.Count > 0)
            {
                for (int i = 0; i < langs.Count; ++i)
                {
                    langs[i].PosDocumentStart = int.MaxValue;
                    langs[i].PosDocumentEnd   = int.MaxValue;

                    // find out start position of language
                    int langstartpos = rtb.Text.IndexOf(langs[i].DocumentStartStr);
                    if (langstartpos >= 0)
                    {
                        langs[i].PosDocumentStart = langstartpos;
                    }

                    // find out end position of language
                    int langendpos = rtb.Text.LastIndexOf(langs[i].DocumentEndStr);
                    if (langendpos >= 0)
                    {
                        langs[i].PosDocumentEnd = langendpos;
                    }
                }

                int    cursorpos = rtb.SelectionStart;
                string rtf       = rtb.Rtf;
                int    maxpos    = Settings.HighlightMaxchars;
                if (rtb.TextLength < Settings.HighlightMaxchars)
                {
                    maxpos = rtb.TextLength;
                }

                int lastpos = 0;
                // -2 for line ending length
                for (int i = cursorpos - 2; i > 0; i--)
                {
                    if (rtb.Text[i] == ' ' || rtb.Text[i] == '\n' || rtb.Text[i] == '\r')
                    {
                        lastpos = i + 1; // after ' ', '\n' or '\r'
                        break;
                    }
                }

                int partlen = cursorpos - lastpos;
                if (partlen > 0 && lastpos + partlen <= rtb.TextLength)
                {
                    string part = rtb.Text.Substring(lastpos, cursorpos - lastpos);
                    int    s    = part.LastIndexOf('<');
                    if (s > 0)
                    {
                        lastpos += s;
                        part     = rtb.Text.Substring(lastpos, cursorpos - lastpos);
                    }

                    rtf = CheckSyntaxPart(rtb, rtf, part, cursorpos, lastpos);
                }

                if (!string.IsNullOrEmpty(rtf))
                {
                    int    prevtextlen = rtb.TextLength;
                    string prevrtf     = rtb.Rtf;
                    rtb.Rtf = rtf;
                    if (rtb.TextLength != prevtextlen)
                    {
                        Log.Write(LogType.exception, "rtf editing failed. rtb.TextLength=" + rtb.TextLength + " prevtextlen=" + prevtextlen);
                        rtb.Rtf = prevrtf;
                    }
                }

                rtb.SelectionStart = cursorpos;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImportNotes" /> class.
 /// </summary>
 /// <param name="notes">Reference to notes class</param>
 public ImportNotes(Notes notes)
 {
     this.notes = notes;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Check the syntax of alle set languages on the RichTextbox RTF content.
        /// </summary>
        /// <param name="rtb">The richttextbox with RTF note content.</param>
        /// <param name="skinnr">The skin number</param>
        /// <param name="notes">Pointer to notes class.</param>
        public static void CheckSyntaxFull(RichTextBox rtb, int skinnr, Notes notes)
        {
            System.Diagnostics.Stopwatch stopwatch = null;
            if (Settings.ProgramLogInfo)
            {
                stopwatch = new System.Diagnostics.Stopwatch();
                stopwatch.Start();
            }

            string rtf = rtb.Rtf;

            if (string.IsNullOrEmpty(rtf))
            {
                Log.Write(LogType.exception, "Empty note rtf");
                return;
            }

            if (!keywordsinit)
            {
                Log.Write(LogType.error, "Keywords not initialized as they should already have. Hotfixing this, watchout memory use.");
                InitHighlighter();
            }

            rtf = ResetHighlighting(rtb, rtf, skinnr, notes);

            // check if highlighting is enabled at all.
            if (langs.Count > 0)
            {
                int lastpos = 0;
                int maxpos  = Settings.HighlightMaxchars;
                if (rtb.TextLength < Settings.HighlightMaxchars)
                {
                    maxpos = rtb.TextLength;
                }

                foreach (HighlightLanguage lang in langs)
                {
                    lang.PosDocumentStart = int.MaxValue;
                    lang.PosDocumentEnd   = int.MaxValue;
                }

                for (int curpos = 0; curpos < maxpos; ++curpos)
                {
                    // curpos == rtb.TextLength - 1 for checking last part
                    if (rtb.Text[curpos] == ' ' || rtb.Text[curpos] == '\n' || rtb.Text[curpos] == '\r' || rtb.Text[curpos] == '\t' || curpos == rtb.TextLength - 1)
                    {
                        string part = rtb.Text.Substring(lastpos, curpos - lastpos);
                        if (part.Length > 0)
                        {
                            rtf = CheckSyntaxPart(rtb, rtf, part, curpos, lastpos);
                        }

                        lastpos = curpos + 1; // without space or linefeed
                    }

#if !macos
                    if (rtb.Text[curpos] == '\n')
#elif macos
                    if (rtb.Text[curpos] == '\r')
#endif
                    {
                        commentline = false;
                    }
                }
            }

            if (!string.IsNullOrEmpty(rtf))
            {
                int    prevtextlen = rtb.TextLength;
                string prevrtf     = rtb.Rtf;
                rtb.Rtf = rtf;
                if (rtb.TextLength != prevtextlen)
                {
                    Log.Write(LogType.exception, "rtf editing failed. rtb.TextLength=" + rtb.TextLength + " prevtextlen=" + prevtextlen);
                    //rtb.Rtf = prevrtf;
                }
            }

            if (Settings.ProgramLogInfo)
            {
                stopwatch.Stop();
                Log.Write(LogType.info, "Note highlight time: " + stopwatch.ElapsedMilliseconds.ToString() + " ms");
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the Note class.
 /// Completly new note.
 /// </summary>
 /// <param name="notes">Reference to notes.</param>
 /// <param name="filename">The note filename.</param>
 public Note(Notes notes, string filename)
 {
     this.notes    = notes;
     this.filename = filename;
 }