Example #1
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();
            }
        }
Example #2
0
        public static string GetSelectedText(this ScintillaGateway document)
        {
            int start = document.GetSelectionStart();
            int end   = document.GetSelectionEnd();

            return(document.GetTextBetween(start, end));
        }
Example #3
0
        /// <summary>Koordinaten verschieben</summary>
        /// <param name="tRW"></param>
        /// <param name="tHW"></param>
        /// <param name="tHO"></param>
        /// <param name="settings"></param>
        public Boolean translateCoords(Double tRW, Double tHW, Double tHO)
        {
            Boolean           hasAnyChanged = false;
            IScintillaGateway editor        = new ScintillaGateway(PluginBase.GetCurrentScintilla());
            int sLnrStart = -1;
            int sLnrEnd   = -1;

            if (editor != null)
            {
                sLnrStart = editor.LineFromPosition(editor.GetSelectionStart());
                sLnrEnd   = editor.LineFromPosition(editor.GetSelectionEnd());
                if (editor.GetColumn(editor.GetSelectionEnd()) < 2)
                {
                    sLnrEnd--;
                }
                if ((sLnrEnd - sLnrStart) <= 0)
                {
                    sLnrStart = sLnrEnd = -1;
                }
            }
            if (Double.IsNaN(tRW))
            {
                tRW = 0.0;
            }
            if (Double.IsNaN(tHW))
            {
                tHW = 0.0;
            }
            if (Double.IsNaN(tHO))
            {
                tHO = 0.0;
            }
            foreach (ClassCADdyPunkt item in Punkte)
            {
                if ((sLnrStart >= 0) && (sLnrEnd >= 0))
                {
                    if ((item.LineNumber >= sLnrStart) && (item.LineNumber <= sLnrEnd))
                    {
                        item.Rechtswert += tRW;
                        item.Hochwert   += tHW;
                        item.Hoehe      += tHO;
                        hasAnyChanged    = true;
                    }
                }
                else
                {
                    item.Rechtswert += tRW;
                    item.Hochwert   += tHW;
                    item.Hoehe      += tHO;
                    hasAnyChanged    = true;
                }
            }
            return(hasAnyChanged);
        }
Example #4
0
        /// <summary>Setzt die Punktnummern auf den angegebenen Code</summary>
        /// <param name="pointnumber"></param>
        /// <param name="newCode"></param>
        /// <returns>true = es wurde mind. ein Code geändert</returns>
        public Boolean setPointNumberToCode(String pointnumber, String newCode)
        {
            Boolean allPoints     = false;
            Boolean hasAnyChanged = false;

            if (ClassStringTools.IsNullOrWhiteSpace(pointnumber))
            {
                pointnumber = "*";
            }
            if (!ClassStringTools.IsNullOrWhiteSpace(newCode))
            {
                IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());
                int sLnrStart            = -1;
                int sLnrEnd = -1;
                if (editor != null)
                {
                    sLnrStart = editor.LineFromPosition(editor.GetSelectionStart());
                    sLnrEnd   = editor.LineFromPosition(editor.GetSelectionEnd());
                    if (editor.GetColumn(editor.GetSelectionEnd()) < 2)
                    {
                        sLnrEnd--;
                    }
                }
                ClassRegexTools regexT = null;
                if (pointnumber == "*")
                {
                    allPoints = true;
                }
                else
                {
                    regexT = new ClassRegexTools(pointnumber);
                }
                foreach (ClassCADdyPunkt item in Punkte)
                {
                    if (allPoints || regexT.isMatch(item.Punktnummer))
                    {
                        if ((sLnrStart >= 0) && (sLnrEnd >= 0))
                        {
                            if ((item.LineNumber >= sLnrStart) && (item.LineNumber <= sLnrEnd))
                            {
                                item.Code     = newCode;
                                hasAnyChanged = true;
                            }
                        }
                        else
                        {
                            item.Code     = newCode;
                            hasAnyChanged = true;
                        }
                    }
                }
            }
            return(hasAnyChanged);
        }
Example #5
0
        private void ExecuteCommand(string command)
        {
            IntPtr           currentScint     = PluginBase.GetCurrentScintilla();
            ScintillaGateway scintillaGateway = new ScintillaGateway(currentScint);
            string           selectedText     = scintillaGateway.GetSelText();
            int    positionStar = scintillaGateway.GetSelectionStart();
            int    positionEnd  = scintillaGateway.GetSelectionEnd();
            string newText      = command.Replace("|", selectedText);

            scintillaGateway.ReplaceSel(newText);
            scintillaGateway.SetSelection(positionStar + command.Substring(0, command.IndexOf('|')).Length, positionEnd + command.Substring(0, command.IndexOf('|')).Length);
            //scintillaGateway.SetSelectionEnd(position + command.Substring(0, command.IndexOf('|')).Length);
        }
Example #6
0
        public void InsertSnippet()
        {
            ScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());

            editor.BeginUndoAction();

            Position end    = editor.GetLineEndPosition(editor.LineFromPosition(editor.GetSelectionEnd()));
            Position start  = editor.PositionFromLine(editor.LineFromPosition(editor.GetSelectionStart()));
            int      indent = KeepIndent ? editor.GetLineIndentation(editor.LineFromPosition(start)) : 0;

            string insertText = IndentSnippetBody(SnippetBodyBefore, indent)
                                + IndentSelectedStrings(editor, start, end)
                                + IndentSnippetBody(SnippetBodyAfter, indent);

            editor.DeleteRange(start, end.Value - start.Value + 1);
            editor.InsertText(start, insertText);
            using (TextToFind textToFind = new TextToFind(start.Value, start.Value + insertText.Length, Placeholder))
            {
                Position placeholderPosition = editor.FindText(0, textToFind);
                editor.SetSelection(placeholderPosition.Value + Placeholder.Length, placeholderPosition.Value);
            }
            editor.EndUndoAction();
        }
Example #7
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();
        }