Example #1
0
        bool printDocument(scintilla.ScintillaControl editor, String sTitle)
        {
            bool bStatus = false;
            m_title = sTitle;

            if (null != editor)
            {
                m_editor = editor;
                if (0 == m_editor.Length)
                {
                    MessageBox.Show("Printing an empty document is fairly useless...");
                    return false;
                }

                PrintDocument docToPrint = new PrintDocument();
                docToPrint.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);

                PrintDialog pdlg = new PrintDialog();
                pdlg.Document = docToPrint;

                DialogResult dr = pdlg.ShowDialog(editor);
                if (DialogResult.OK == dr)
                {
                    docToPrint.Print();
                    bStatus = true;
                }

            }
            return bStatus;
        }
 private int m_textEditor_UpdateUI(scintilla.ScintillaControl pSender)
 {
     updateMenus();
     return default(int);
 }
 private int m_textEditor_Modified(scintilla.ScintillaControl pSender)
 {
     toolStripMenuItem_EditUndo.Enabled = m_textEditor.CanUndo;
     toolStripMenuItem_EditRedo.Enabled = m_textEditor.CanRedo;
     updateMenus();
     markItem(getCurrentItem(), true);
     bookMarkRemoveAll();
     return default(int);
 }
 private int m_textEditor_MarginClick(scintilla.ScintillaControl pSender, int modifiers, int position, int margin)
 {
     //int position = m_textEditor.CurrentPos;
     //int modifiers = 0; // HACK
     int lineClick = m_textEditor.LineFromPosition(position);
     if (Convert.ToBoolean(modifiers & 1 /* SCMOD_SHIFT */) && Convert.ToBoolean(modifiers & 2 /* SCMOD_CTRL*/))
     {
         // Fold All
         Editor_FoldAll();
     }
     else
     {
         int levelClick = m_textEditor.GetFoldLevel(lineClick);
         if (Convert.ToBoolean(levelClick & 0x2000 /* SC_FOLDLEVELHEADERFLAG */ ))
         {
             if (Convert.ToBoolean(modifiers & 1 /* SCMOD_SHIFT */))
             {
                 Editor_EnsureAllChidrenVisible(lineClick, levelClick);
             }
             else if (Convert.ToBoolean(modifiers & 2 /* SCMOD_CTRL */))
             {
                 Editor_ToggleFoldRecursive(lineClick, levelClick);
             }
             else
             {
                 m_textEditor.ToggleFold(lineClick);
             }
         }
     }
     return default(int);
 }
        private int m_textEditor_HotSpotClick(scintilla.ScintillaControl pSender, int modifiers, int position)
        {
            String sToken = getCurrentWord(position).Replace(':', '_');

            if (sToken.Length > 0)
            {
                int style = m_textEditor.get_StyleAt(position);
                String sUrl = null;
                switch (style)
                {
                    case 12: /* iRule LTM tokens */
                        //sUrl = "http://devcentral.f5.com/Wiki/print.aspx/iRules." + sToken;
                        //sUrl = "http://devcentral.f5.com/Wiki/default.aspx/iRules." + sToken;
                        sUrl = "https://devcentral.f5.com/wiki/iRules." + sToken + ".ashx";
                        break;
                    case 13: /* iRule GTM tokens */
                        //sUrl = "http://devcentral.f5.com/Wiki/print.aspx/iRules." + sToken;
                        //sUrl = "http://devcentral.f5.com/Wiki/default.aspx/iRules." + sToken;
                        sUrl = "https://devcentral.f5.com/wiki/iRules." + sToken + ".ashx";
                        break;
                    case 14: /* tcl commands */
                        //sUrl = "http://tmml.sourceforge.net/doc/tcl/" + sToken + ".html";
                        sUrl = "http://www.tcl.tk/man/tcl8.4/TclCmd/" + sToken + ".htm";
                        break;
                }
                Configuration.LaunchProcess(sUrl);
            }
            return default(int);
        }
 private int m_textEditor_DwellStart(scintilla.ScintillaControl pSender, int position, int x, int y)
 {
     m_textEditor.CallTipShow(position, "Click this link to go to the online documentation");
     return default(int);
 }
        private void m_textEditor_CharAdded(scintilla.ScintillaControl pSender, char CharacterAdded)
        {
            String[] log_facilities = new String[] {
                "alert", "crit", "debug", "emerg", "err", "error", "info", "none", "notice", "panic", "warn", "warning"
            };

            markItem(m_lastTreeViewNode, true);

            if (m_doAutoIndent)
            {
                autoIndentLine(pSender, CharacterAdded);
            }

            // check for autocomplete
            if (m_showAutoComplete && (m_eventList.Length > 0))
            {
                int position = m_textEditor.CurrentPos;
                if (' ' == CharacterAdded)
                {
                    position--;
                }
                if (position > 0)
                {
                    position--;
                }

                String sWord = getCurrentWord(position);
                System.Diagnostics.Debug.WriteLine("Current Word: '" + sWord + "'");
                if (0 == sWord.Length)
                {
                    // Nada...
                }
                if (sWord.Equals("when") && (' ' == CharacterAdded))
                {
                    if ((null != m_lastTreeViewNode) && (null != m_lastTreeViewNode.Tag))
                    {
                        iRuleInfo iri = (iRuleInfo)m_lastTreeViewNode.Tag;
                        if (iRuleInfo.RuleType.LOCALLB == iri.rule_type)
                        {
                            m_textEditor.AutoCShow(0, m_eventList);
                        }
                        else if (iRuleInfo.RuleType.GLOBALLB == iri.rule_type)
                        {
                            m_textEditor.AutoCShow(0, m_eventListGTM);
                        }
                    }
                    else
                    {
                        m_textEditor.AutoCShow(0, m_eventList);
                    }
                }
                else if (showCommandAC(sWord))
                {
                    // nada, work done in method
                }
                else if (sWord.Equals("log") && (' ' == CharacterAdded))
                {
                    String tokens = "";
                    for (int i = 0; i < 8; i++)
                    {
                        if (tokens.Length > 0) { tokens = tokens + ";"; }
                        for (int j = 0; j < log_facilities.Length; j++)
                        {
                            tokens = tokens + "local" + i.ToString() + "." + log_facilities[j];
                            if (j < log_facilities.Length-1)
                            {
                                tokens = tokens + ";";
                            }
                        }
                    }
                    m_textEditor.AutoCShow(0, tokens);
                }
                else if ((sWord.Length == 7) && sWord.StartsWith("local") && sWord.EndsWith("."))
                {
                    String tokens = "";
                    for (int j = 0; j < log_facilities.Length; j++)
                    {
                        tokens = tokens + log_facilities[j] + " ";
                        if (j < log_facilities.Length - 1)
                        {
                            tokens = tokens + ";";
                        }
                    }
                    m_textEditor.AutoCShow(0, tokens);
                }
                else if (sWord.Equals("string") && (' ' == CharacterAdded))
                {
                    m_textEditor.AutoCShow(0, "bytelength ;compare ;equal ;first ;index ;is alnum ;is alpha ;is ascii ;is boolean ;is control ;is digit ;is double ;is false ;is graph ;is integer ;is lower ;is print ;is punct ;is space ;is true ;is upper ;is wideinteger ;is wordchar ;is xdigit ;last ;length ;map ;match ;range ;repeat ;replace ;tolower ;totitle ;toupper ;trim ;trimleft ;trimright ;wordend ;wordstart ");
                }
                else if (sWord.Length > 2)
                {
                    // Look for a match...
                    String matchList = getListOfMatches(sWord);
                    if ((null != matchList) && (matchList.Length > 0))
                    {
                        m_textEditor.AutoCShow(sWord.Length, matchList);
                    }
                }
            }
        }
        /// <summary>
        /// Gets the previous non-whitespace character in the current line.
        /// </summary>
        /// <param name="sci">The scintilla. control</param>
        /// <param name="pos">The position to search from</param>
        /// <returns>The previous non-whitespace character in the current line or '\0' if there isn't one.</returns>
        private char getPreviousNonWhitespaceChar(scintilla.ScintillaControl sci, int pos)
        {
            char[] contents = sci.Text.ToCharArray();
            --pos;
            if (pos > contents.Length) { return '\0'; }
            while (pos >= 0)
            {
                char c = contents[pos];
                switch (c)
                {
                    case '\n':
                        return '\0';
                    case ' ':
                    case '\t':
                    case '\r':
                        break;
                    default:
                        return c;
                }
                --pos;
            }

            return '\0';
        }
        /// <summary>
        /// Gets the last non-whitespace character of the previous line.
        /// </summary>
        /// <param name="sci">The scintilla. control</param>
        /// <param name="pos">The position to search from.</param>
        /// <returns>The last non-whitespace character in the previous line.</returns>
        private char getEndOfLastLine(scintilla.ScintillaControl sci, int pos)
        {
            int newlinesSeen = 0;
            char[] contents = sci.Text.ToCharArray();
            --pos;
            if (pos > contents.Length) { return '\0'; }
            while (pos >= 0 && newlinesSeen < 2)
            {
                char c = contents[pos];
                switch (c)
                {
                    case '\n':
                        ++newlinesSeen;
                        break;
                    case ' ':
                    case '\t':
                    case '\r':
                        break;
                    default:
                        if (newlinesSeen == 1)
                        {
                            return c;
                        }
                        break;
                }
                --pos;
            }

            return '\0';
        }
 /// <summary>
 /// Calculates the length (number of characters) of a particular indent.
 /// The length of an indent depends on whether or not tabs are enabled
 /// and the width of a tab.
 /// </summary>
 /// <param name="sci">The scintilla. control</param>
 /// <param name="indent">The indent to measure</param>
 /// <returns>The length of th eindent.</returns>
 private int calcLengthOfIndent(scintilla.ScintillaControl sci, int indent)
 {
     if (indent <= 0) { return 0; }
     if (sci.UseTabs)
     {
         return indent / sci.TabWidth;
     }
     else
     {
         return indent;
     }
 }
        /// <summary>
        /// Checks to see if a line needs to be auto indented and indents it if
        /// it does.  Auto indenting follows these rules:
        /// <list>
        ///     <item>
        ///         If a new line has been created it is given the same indent
        ///         as the previous line.
        ///     </item>
        ///     <item>
        ///         If a new line is created and the previous line ends with an
        ///         opening brace then the new line is indented one level more
        ///         than the previous line
        ///     </item>
        ///     <item>
        ///         If a closing brace is added and it is the first
        ///         non-whitespace character on the line and the current line
        ///         has the same indent as the previous line then the line is
        ///         unindented one level.
        ///     </item>
        /// </list>
        /// </summary>
        /// <param name="sci">The scintilla. control</param>
        /// <param name="ch">The character that was just added</param>
        private void autoIndentLine(scintilla.ScintillaControl sci, char ch)
        {
            if ( m_autoIndent )
            {
                if (ch == '}')
                {
                    int currPos = sci.CurrentPos;
                    int currLine = sci.LineFromPosition(currPos);

                    if (currLine > 0)
                    {
                        char lastChar = getPreviousNonWhitespaceChar(sci, currPos - 1);
                        if (lastChar == '\0')
                        {
                            int currIndent = sci.GetLineIndentation(currLine);

                            int prevIndent = sci.GetLineIndentation(currLine - 1);

                            if ((currIndent >= sci.TabWidth) /* && (currIndent == prevIndent) */)
                            {
                                int newIndent = currIndent - sci.TabWidth;
                                sci.SetLineIndentation(currLine, newIndent);
                                int newPos = currPos - (calcLengthOfIndent(sci, currIndent) - calcLengthOfIndent(sci, newIndent));
                                sci.SetSel(newPos, newPos);
                            }
                        }
                    }
                }
                else if (ch == '\n')
                {
                    int currLine = sci.LineFromPosition(sci.CurrentPos);
                    if (currLine > 0)
                    {
                        int prevIndent = sci.GetLineIndentation(currLine - 1);
                        int newIndent = prevIndent;

                        /* Check to see if the previous line ends in an opening
                         * brace.  If it does we'll add an extra indent.
                         * We can't just use pSender.GetLine(currLine - 1) because
                         * the string returned seems to have junk characters at the
                         * end of it, making it difficult to see what the actual
                         * last character is. */
                        char lastChar = getEndOfLastLine(sci, sci.CurrentPos);
                        bool openBrace = (lastChar == '{');

                        if (openBrace)
                        {
                            newIndent += sci.TabWidth;
                        }

                        sci.SetLineIndentation(currLine, newIndent);
                        int newPos = sci.CurrentPos + calcLengthOfIndent(sci, newIndent);
                        sci.SetSel(newPos, newPos);
                    }
                }
            }
        }