Exemple #1
0
        private static void GotoSectionOrPerform()
        {
            if (SNDialogStruct.Form == null)
            {
                SourceNavigationDialog();
            }
            var editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());

            CheckAndSwitchOnCobolWords();
            editor.SetSelection(editor.WordEndPosition(editor.GetCurrentPos(), true), editor.WordStartPosition(editor.GetCurrentPos(), true));

            if (editor.GetSelectionLength() == 0)
            {
                return;
            }
            // If new search
            if (sectionName != editor.GetSelText().ToUpper())
            {
                sectionName = editor.GetSelText().ToUpper();
                int sectionImplementationLine = GetSectionImplementationLine(sectionName);
                if (sectionImplementationLine >= 0)
                {
                    if (editor.GetCurrentLineNumber() == sectionImplementationLine)
                    {
                        if (!SearchNextSectionOrPerform(sectionName, editor.GetCurrentPos().Value))
                        {
                            SearchNextSectionOrPerform(sectionName, 0);
                        }
                    }
                    else
                    {
                        ScrollToLine(sectionImplementationLine);
                        CurrentSearchOffset = sectionImplementationLine;
                    }
                }
                else
                {
                    sectionName = "";
                }
            }
            //If continuing search
            else
            {
                if (!SearchNextSectionOrPerform(sectionName, CurrentSearchOffset))
                {
                    SearchNextSectionOrPerform(sectionName, 0);
                }
            }
        }
        /// <summary>Gibt eine CADdy-Formatierte Liste zurück</summary>
        /// <param name="settings"></param>
        public void formatCurrentToCADdy(Settings settings)
        {
            IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());

            if (standpunkte.Count > 0)
            {
                Position selStart = editor.GetSelectionStart();
                Position selEnd   = editor.GetSelectionEnd();
                editor.BeginUndoAction();
                Position oldPos = editor.GetCurrentPos();
                editor.ClearAll();
                foreach (ClassCADdyStandpunkt item in standpunkte)
                {
                    String temp = item.getCADdyFormatString(settings);
                    editor.AppendText(temp.Length + 1, temp + Environment.NewLine);
                    foreach (ClassCADdyZielung ziel in item.Zielungen)
                    {
                        temp = ziel.getCADdyFormatString(settings);
                        editor.AppendText(temp.Length + 1, temp + Environment.NewLine);
                    }
                }
                editor.ConvertEOLs(0);
                editor.SetSelection(selStart.Value, selEnd.Value);
                editor.SetCurrentPos(oldPos);
                editor.EndUndoAction();
            }
        }
        public static void ClearSelection(this ScintillaGateway document)
        {
            int currentPos = document.GetCurrentPos();

            document.SetSelectionStart(currentPos);
            document.SetSelectionEnd(currentPos);
        }
        private static void EnsureFirstWordIsSelected(ScNotification notification)
        {
            if (isPluginActive)
            {
                nppResource.ClearIndicator();

                if (notification.Header.Code == (ulong)SciMsg.SCN_UPDATEUI)
                {
                    var scintillaGateway = new ScintillaGateway(PluginBase.GetCurrentScintilla());
                    var currentPosition  = scintillaGateway.GetCurrentPos();
                    if (currentPosition != lastPositionWhenUiUpdate)
                    {
                        if (scintillaGateway.GetSelectionEmpty())
                        {
                            lastPositionWhenUiUpdate = firstWordSelector.SelectFirstWordOfLine(scintillaGateway);
                        }
                    }
                    return;
                }

                if (notification.Header.Code == (ulong)SciMsg.SCN_MODIFIED)
                {
                    var isTextInsertedOrDeleted = (notification.ModificationType &
                                                   ((int)SciMsg.SC_MOD_INSERTTEXT | (int)SciMsg.SC_MOD_DELETETEXT)) > 0;
                    if (isTextInsertedOrDeleted)
                    {
                        lastPositionWhenUiUpdate = null;
                    }
                }
            }
        }
Exemple #5
0
        public Position SelectFirstWordOfLine(ScintillaGateway scintilla)
        {
            int lineNumber = scintilla.GetCurrentLineNumber();

            var lineContent = scintilla.GetLine(lineNumber);

            if (lineContent.StartsWith("#"))
            {
                return(null);
            }

            int endOfFirstWordOnLine = lineContent.IndexOf(' ');

            if (endOfFirstWordOnLine == -1)
            {
                return(null);
            }

            var positionOfLine          = scintilla.PositionFromLine(lineNumber);
            var cursorpos               = scintilla.GetCurrentPos() - positionOfLine;
            var cursorIsWithinFirstWord = cursorpos.Value <= endOfFirstWordOnLine;

            if (!cursorIsWithinFirstWord)
            {
                return(null);
            }

            var newPosition = new Position(positionOfLine.Value + endOfFirstWordOnLine);

            scintilla.SetAnchor(newPosition);
            scintilla.SetCurrentPos(positionOfLine);

            return(newPosition);
        }
        static public string GetStatementAtPosition(this ScintillaGateway document, int position = -1)
        {
            if (position == -1)
            {
                position = document.GetCurrentPos();
            }

            return(document.GetWordAtPosition(position, out Point point, statementDelimiters));
        }
Exemple #7
0
        /// <summary>
        /// Returns a string containing the last word typed.
        /// </summary>
        /// <returns>string</returns>
        internal static string getLastWord()
        {
            IntPtr           currentScint     = PluginBase.GetCurrentScintilla();
            ScintillaGateway scintillaGateway = new ScintillaGateway(currentScint);

            var selectionStart = scintillaGateway.GetCurrentPos();
            var selectionEnd   = scintillaGateway.GetCurrentPos();
            var endOfVariable  = scintillaGateway.GetCurrentPos();

            scintillaGateway.WordLeft();
            selectionStart = scintillaGateway.GetCurrentPos();
            scintillaGateway.WordRight();
            selectionEnd  = scintillaGateway.GetCurrentPos();
            endOfVariable = selectionEnd;

            scintillaGateway.SetSel(selectionStart, selectionEnd);

            return(scintillaGateway.GetSelText());
        }
        static public Point GetCaretScreenLocation(this ScintillaGateway document)
        {
            int pos = document.GetCurrentPos();
            int x   = document.PointXFromPosition(pos);
            int y   = document.PointYFromPosition(pos);

            var point = new Point(x, y);

            ClientToScreen(document.Handle, ref point);
            return(point);
        }
Exemple #9
0
        public void InsertSnippet()
        {
            var editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());

            editor.AddText(SnippetBody.Length, SnippetBody);

            using (TextToFind textToFind = new TextToFind(editor.GetCurrentPos().Value - SnippetBody.Length, editor.GetCurrentPos().Value, Placeholder))
            {
                Position placeholderPosition = editor.FindText(0, textToFind);
                editor.SetSelection(placeholderPosition.Value + Placeholder.Length, placeholderPosition.Value);
            }
        }
        /// <summary>
        /// Open the file and navigate to the 0-based line and column position.
        /// </summary>
        /// <param name="file"></param>
        /// <param name="line"></param>
        /// <param name="column"></param>
        static public void NavigateToFileContent(this ScintillaGateway document, string file, int line, int column)
        {
            try
            {
                Npp.Editor.Open(file);
                document.GrabFocus();
                document.GotoLine(line); //SCI lines are 0-based

                //at this point the caret is at the most left position (col=0)
                var currentPos = document.GetCurrentPos();
                document.GotoPos(currentPos + column - 1);
            }
            catch { }
        }
Exemple #11
0
        /// <summary>Gibt eine Excel-Formatierte Liste zurück</summary>
        public void formatCurrentToExcel()
        {
            IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());

            if (Punkte.Count > 0)
            {
                Position oldPos = editor.GetCurrentPos();
                editor.BeginUndoAction();
                editor.ClearAll();
                foreach (ClassCADdyPunkt item in Punkte)
                {
                    String temp = item.getExcelFormatString();
                    editor.AppendText(temp.Length + 1, temp + Environment.NewLine);
                }
                editor.ConvertEOLs(0);
                editor.EndUndoAction();
                editor.SetCurrentPos(oldPos);
                editor.ClearSelectionToCursor();
            }
        }
        /// <summary>Gibt eine CADdy-Formatierte Liste zurück</summary>
        /// <param name="settings"></param>
        public void formatCurrentToCAPLAN(Settings settings)
        {
            IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());

            if (standpunkte.Count > 0)
            {
                editor.BeginUndoAction();
                Position oldPos = editor.GetCurrentPos();
                editor.ClearAll();
                Dictionary <String, List <Int32> > stpkIndex = new Dictionary <String, List <Int32> >();
                for (Int32 counter = 0; counter < standpunkte.Count; counter++)
                {
                    if (!stpkIndex.Keys.Contains(standpunkte[counter].Punktnummer))
                    {
                        stpkIndex.Add(standpunkte[counter].Punktnummer, new List <Int32>());
                    }
                    stpkIndex[standpunkte[counter].Punktnummer].Add(counter);
                }
                foreach (KeyValuePair <String, List <Int32> > stId in stpkIndex)
                {
                    String temp = standpunkte[stId.Value[0]].getCADdyFormatString(settings);
                    editor.AppendText(temp.Length + 1, temp + Environment.NewLine);
                    foreach (Int32 stpkId in stId.Value)
                    {
                        foreach (ClassCADdyZielung ziel in standpunkte[stpkId].Zielungen)
                        {
                            temp = ziel.getCADdyFormatString(settings);
                            editor.AppendText(temp.Length + 1, temp + Environment.NewLine);
                        }
                    }
                }
                editor.ConvertEOLs(0);
                editor.SetCurrentPos(oldPos);
                editor.EndUndoAction();
            }
        }
        /// <summary>Gibt eine Excel-Formatierte Liste zurück</summary>
        public void formatCurrentToExcel()
        {
            IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());

            if (standpunkte.Count > 0)
            {
                editor.BeginUndoAction();
                Position oldPos = editor.GetCurrentPos();
                editor.ClearAll();
                foreach (ClassCADdyStandpunkt item in standpunkte)
                {
                    String temp = item.getExcelFormatString();
                    editor.AppendText(temp.Length + 1, temp + Environment.NewLine);
                    foreach (ClassCADdyZielung ziel in item.Zielungen)
                    {
                        temp = ziel.getExcelFormatString();
                        editor.AppendText(temp.Length + 1, temp + Environment.NewLine);
                    }
                }
                editor.ConvertEOLs(0);
                editor.SetCurrentPos(oldPos);
                editor.EndUndoAction();
            }
        }
 public static string GetCurrentLine(this ScintillaGateway document)
 {
     return(document.GetLine(document.LineFromPosition(document.GetCurrentPos())));
 }
Exemple #15
0
        internal static void C7GSPFunction()
        {
            //Preparing some variables
            var scintilla = new ScintillaGateway(PluginBase.GetCurrentScintilla());

            //Starting Undo "recording". Next steps can be undo with one undo command
            scintilla.BeginUndoAction();

            //Is there any text selected
            if (scintilla.GetSelText() != "")
            {
                //Calculating selections first line begin
                Position selStartPos  = scintilla.GetSelectionStart();
                int      startLineNum = scintilla.LineFromPosition(selStartPos);
                Position startLinePos = scintilla.PositionFromLine(startLineNum);

                //Calculating selections last line end
                Position selEndPos  = scintilla.GetSelectionEnd();
                int      endLineNum = scintilla.LineFromPosition(selEndPos);
                Position endLinePos = scintilla.GetLineEndPosition(endLineNum);

                //Setting the selection as needed
                scintilla.SetSel(startLinePos, endLinePos);

                //Preparing needed variables
                int ignoreMe = 0;

                //Gathered information
                string line = "";
                int    lineFeedLen = 0;
                int    tt = 0, np = 0, na = 0, gtrc = 0;
                string ns        = "";
                string modifiers = "";

                //Loopping through the selected lines
                int i = startLineNum;
                while (i <= endLineNum)
                {
                    //Line to the memory
                    line = scintilla.GetLine(i);

                    if (line.Length > 2)
                    {
                        //Checking did we get a fresh GT line (three first chars are int (TT))
                        if (int.TryParse(line.Substring(0, 3), out ignoreMe))
                        {
                            //Gathering the basic GT information
                            tt   = int.Parse(line.Substring(0, 3));
                            np   = int.Parse(line.Substring(5, 2));
                            na   = int.Parse(line.Substring(9, 3));
                            ns   = line.Substring(14, 16).Replace(" ", string.Empty);
                            gtrc = na = int.Parse(line.Substring(56, 3));

                            //Move carret to the begin of the line
                            scintilla.SetCurrentPos(scintilla.PositionFromLine(i));
                            //Delete all from the line
                            scintilla.DelLineRight();
                            //Add text
                            scintilla.InsertText(scintilla.PositionFromLine(i), "C7GSI:TT=" + tt + ",NP=" + np + ",NA=" + ",NS=" + ns + ",GTRC=" + gtrc + ";");

                            //Checking next line if it it's not empty
                            if (scintilla.GetLine(i + 1).Length >= 9)
                            {
                                //And the line will contain header which begins with MTT
                                if (scintilla.GetLine(i + 1).Substring(9, 3) == "MTT")
                                {
                                    //If yes then take the line under it to the variable
                                    modifiers = scintilla.GetLine(i + 2);

                                    //If linefeed is CRLF, then two extra characters in the end of line
                                    if (scintilla.GetEOLMode() == 0)
                                    {
                                        lineFeedLen = 2;
                                    }
                                    else
                                    {
                                        lineFeedLen = 1;
                                    }

                                    //Removing lines which not needed anymore
                                    scintilla.SetCurrentPos(scintilla.PositionFromLine(i + 1));
                                    scintilla.LineDelete();
                                    scintilla.LineDelete();

                                    endLineNum = endLineNum - 2;

                                    //Determining which variables the modifiers line will contain
                                    if (modifiers.Length == (12 + lineFeedLen))
                                    {
                                        //Insert command to the line
                                        scintilla.InsertText(scintilla.PositionFromLine(i + 1), "C7GSC:TT=" + tt + ",NP=" + np + ",NA=" + ",NS=" + ns + ",MTT=" + modifiers.Substring(9, 3).Replace(" ", string.Empty) + ";");
                                    }
                                    else if (modifiers.Length == (17 + lineFeedLen))
                                    {
                                        if (!string.IsNullOrWhiteSpace(modifiers.Substring(9, 3)))
                                        {
                                            //Insert command to the line
                                            scintilla.InsertText(scintilla.GetCurrentPos(), "C7GSC:TT=" + tt + ",NP=" + np + ",NA=" + ",NS=" + ns + ",MTT=" + modifiers.Substring(9, 3).Replace(" ", string.Empty) + ";");
                                            //Go to end of the current line
                                            scintilla.GotoPos(scintilla.GetLineEndPosition(scintilla.LineFromPosition(scintilla.GetCurrentPos())));
                                            //Adding new line
                                            scintilla.NewLine();
                                            endLineNum++;
                                        }
                                        scintilla.InsertText(scintilla.GetCurrentPos(), "C7GSC:TT=" + tt + ",NP=" + np + ",NA=" + ",NS=" + ns + ",MNP=" + modifiers.Substring(14, 3).Replace(" ", string.Empty) + ";");
                                    }
                                    else if (modifiers.Length == (22 + lineFeedLen))
                                    {
                                        if (!string.IsNullOrWhiteSpace(modifiers.Substring(9, 3)))
                                        {
                                            scintilla.InsertText(scintilla.GetCurrentPos(), "C7GSC:TT=" + tt + ",NP=" + np + ",NA=" + ",NS=" + ns + ",MTT=" + modifiers.Substring(9, 3).Replace(" ", string.Empty) + ";");
                                            scintilla.GotoPos(scintilla.GetLineEndPosition(scintilla.LineFromPosition(scintilla.GetCurrentPos())));
                                            scintilla.NewLine();
                                            endLineNum++;
                                        }
                                        if (!string.IsNullOrWhiteSpace(modifiers.Substring(14, 3)))
                                        {
                                            scintilla.InsertText(scintilla.GetCurrentPos(), "C7GSC:TT=" + tt + ",NP=" + np + ",NA=" + ",NS=" + ns + ",MNP=" + modifiers.Substring(14, 3).Replace(" ", string.Empty) + ";");
                                            scintilla.GotoPos(scintilla.GetLineEndPosition(scintilla.LineFromPosition(scintilla.GetCurrentPos())));
                                            scintilla.NewLine();
                                            endLineNum++;
                                        }
                                        scintilla.InsertText(scintilla.GetCurrentPos(), "C7GSC:TT=" + tt + ",NP=" + np + ",NA=" + ",NS=" + ns + ",MNA=" + modifiers.Substring(19, 3).Replace(" ", string.Empty) + ";");
                                    }
                                    else
                                    {
                                        if (!string.IsNullOrWhiteSpace(modifiers.Substring(9, 3)))
                                        {
                                            scintilla.InsertText(scintilla.GetCurrentPos(), "C7GSC:TT=" + tt + ",NP=" + np + ",NA=" + ",NS=" + ns + ",MTT=" + modifiers.Substring(9, 3).Replace(" ", string.Empty) + ";");
                                            scintilla.GotoPos(scintilla.GetLineEndPosition(scintilla.LineFromPosition(scintilla.GetCurrentPos())));
                                            scintilla.NewLine();
                                            endLineNum++;
                                        }
                                        if (!string.IsNullOrWhiteSpace(modifiers.Substring(14, 3)))
                                        {
                                            scintilla.InsertText(scintilla.GetCurrentPos(), "C7GSC:TT=" + tt + ",NP=" + np + ",NA=" + ",NS=" + ns + ",MNP=" + modifiers.Substring(14, 3).Replace(" ", string.Empty) + ";");
                                            scintilla.GotoPos(scintilla.GetLineEndPosition(scintilla.LineFromPosition(scintilla.GetCurrentPos())));
                                            scintilla.NewLine();
                                            endLineNum++;
                                        }
                                        if (!string.IsNullOrWhiteSpace(modifiers.Substring(19, 3)))
                                        {
                                            scintilla.InsertText(scintilla.GetCurrentPos(), "C7GSC:TT=" + tt + ",NP=" + np + ",NA=" + ",NS=" + ns + ",MNA=" + modifiers.Substring(19, 3).Replace(" ", string.Empty) + ";");
                                            scintilla.GotoPos(scintilla.GetLineEndPosition(scintilla.LineFromPosition(scintilla.GetCurrentPos())));
                                            scintilla.NewLine();
                                            endLineNum++;
                                        }
                                        scintilla.InsertText(scintilla.GetCurrentPos(), "C7GSC:TT=" + tt + ",NP=" + np + ",NA=" + ",NS=" + ns + ",MNS=" + modifiers.Substring(24, (modifiers.Length - 24 - lineFeedLen)).Replace(" ", string.Empty) + ";");
                                    }
                                }
                            }
                        }
                    }

                    i++;
                }
            }
            scintilla.EndUndoAction();
        }
        static public string TextAfterCursor(this ScintillaGateway document, int maxLength)
        {
            int currentPos = document.GetCurrentPos();

            return(TextAfterPosition(document, currentPos, maxLength));
        }
        static public string GetWordAtCursor(this ScintillaGateway document, out Point point, char[] wordDelimiters = null)
        {
            int currentPos = document.GetCurrentPos();

            return(Npp.GetCurrentDocument().GetWordAtPosition(currentPos, out point, wordDelimiters));
        }