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);
                }
            }
        }
Exemple #2
0
        private static void copyAsImage()
        {
            try
            {
                IntPtr           currentScint     = PluginBase.GetCurrentScintilla();
                ScintillaGateway scintillaGateway = new ScintillaGateway(currentScint);
                // Get selected text.
                string        selectedText = scintillaGateway.GetSelText();
                var           lines        = selectedText.Split('\n');
                DrawIOBuilder builder      = new DrawIOBuilder();
                for (var i = 0; i < lines.Length; i++)
                {
                    var line = lines[i];
                    lines[i] = line.Trim(new char[] { ' ', '\r' });
                }


                DrawIOComponent[] drawIOComponent = builder.FlowchartBuilder(lines);
                builder.DrawToClipBoard(drawIOComponent);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #3
0
        /// <summary>
        /// Replace the tag at the caret with an expansion defined in the [Tags]
        /// ini-file section.
        /// </summary>
        internal static void ReplaceTag()
        {
            IntPtr           currentScint     = PluginBase.GetCurrentScintilla();
            ScintillaGateway scintillaGateway = new ScintillaGateway(currentScint);
            int position = scintillaGateway.GetSelectionEnd();

            string selectedText = scintillaGateway.GetSelText();

            if (string.IsNullOrEmpty(selectedText))
            {
                // TODO: remove this hardcoded 10 crap. Remove selection manipulation:
                // user will not be happy to see any such side-effects.
                scintillaGateway.SetSelection(position > 10 ? (position - 10) : (position - position), position);
                selectedText = scintillaGateway.GetSelText();
                var reges = Regex.Matches(scintillaGateway.GetSelText(), @"(\w+)");
                if (reges.Count > 0)
                {
                    selectedText = reges.Cast <Match>().Select(m => m.Value).LastOrDefault();
                    scintillaGateway.SetSelection(position - selectedText.Length, position);
                    selectedText = scintillaGateway.GetSelText();
                }
            }
            try {
                if (string.IsNullOrEmpty(selectedText))
                {
                    throw new Exception("No tag here.");
                }
                byte[] buffer = new byte[1048];
                var    ini    = new IniFile(iniFilePath);
                string value  = ini.Get("Tags", selectedText, 1048);
                if (string.IsNullOrEmpty(value.Trim('\0')))
                {
                    throw new Exception("No tag here.");
                }
                value = TransformTags(value);
                scintillaGateway.ReplaceSel(value.Replace("|", null));
                scintillaGateway.SetSelectionEnd(position + value.Substring(0, value.IndexOf('|')).Length - selectedText.Length);
            } catch (Exception ex) {
                scintillaGateway.CallTipShow(position, ex.Message);
            }
        }
Exemple #4
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);
        }
Exemple #5
0
        internal static void myMenuFunction()
        {
            IntPtr           currentScint     = PluginBase.GetCurrentScintilla();
            ScintillaGateway scintillaGateway = new ScintillaGateway(currentScint);
            // Get selected text.
            string selectedText = scintillaGateway.GetSelText();


            var lines = selectedText.Split('\n');
            //var html = "<table style='box-sizing: inherit; font-family: arial, sans-serif; border-collapse: collapse; color: rgb(0, 0, 0); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;'>";

            var myHtml = generator.GenerateMarkdown(lines);

            ClipboardHelper.CopyToClipboard(selectedText, myHtml);
        }
Exemple #6
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());
        }
Exemple #7
0
        internal static void goToDefinition()
        {
            IntPtr           hCurrScintilla = PluginBase.GetCurrentScintilla();
            NotepadPPGateway npp            = new NotepadPPGateway();
            ScintillaGateway sci            = new ScintillaGateway(hCurrScintilla);
            var selectedText = sci.GetSelText();

            if (string.IsNullOrEmpty(selectedText))
            {
                return;
            }
            Dictionary <string, string> filePaths = new Dictionary <string, string>();
            var stream = new FileStream(@"plugins/Config/GoToDefinition/sql_repos.txt", FileMode.Open, FileAccess.Read);

            using (var streamReader = new StreamReader(stream, Encoding.UTF8))
            {
                var text         = streamReader.ReadToEnd();
                var allFilePaths = text.Split(';');
                foreach (var filePath in allFilePaths)
                {
                    var kvp = filePath.Split('=');
                    if (kvp.Length > 1)
                    {
                        filePaths.Add(kvp[0], kvp[1]);
                    }
                }
            }
            StringBuilder sb = new StringBuilder();

            var matchingFileNames = new List <string>();

            foreach (var kvp in filePaths)
            {
                var matchingFiles = Directory.GetFiles(kvp.Value, $"{selectedText}*", SearchOption.TopDirectoryOnly);
                matchingFileNames.AddRange(matchingFiles);
            }

            FilesDialog fd = new FilesDialog(matchingFileNames.ToArray());

            fd.Show();
        }
Exemple #8
0
        internal static void saveAsDrawIO()
        {
            try
            {
                frmMyDlg frmMyDlg = new frmMyDlg();
                var      filename = frmMyDlg.filename;

                IntPtr           currentScint     = PluginBase.GetCurrentScintilla();
                ScintillaGateway scintillaGateway = new ScintillaGateway(currentScint);
                // Get selected text.
                string selectedText = scintillaGateway.GetSelText();
                var    lines        = selectedText.Split('\n'); for (var i = 0; i < lines.Length; i++)
                {
                    var line = lines[i];
                    lines[i] = line.Trim(new char[] { ' ', '\r' });
                }
                DrawIOBuilder     builder         = new DrawIOBuilder();
                DrawIOComponent[] drawIOComponent = builder.FlowchartBuilder(lines);
                builder.SaveToFile(filename, drawIOComponent);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #9
0
        /// <summary>
        /// Capitalize user selected text based on Chicago Manual of Style.
        /// </summary>
        internal static void CapitalizeTitle()
        {
            // Only call this once per notepad-plus-plus session.
            if (forbidden.Count == 0)
            {
                // Get the list of forbidden words.
                forbidden = GetForbiddenWords(@"plugins\doc\FirstUpper\FirstUpperForbiddenWords.txt");
            }

            IntPtr           currentScint     = PluginBase.GetCurrentScintilla();
            ScintillaGateway scintillaGateway = new ScintillaGateway(currentScint);

            try
            {
                // Get selected text.
                string selectedText = scintillaGateway.GetSelText();
                // Convert to lower case in case some words are already
                // capitalized that should not be capitalized.
                selectedText = selectedText.ToLowerInvariant();
                // Change to char array for easy editing of single chars.
                char[] charArraySelText = selectedText.ToCharArray();

                StringBuilder word             = new StringBuilder();
                char          firstLetter      = new char();
                int           firstLetterIndex = -1;
                bool          firstWord        = true;

                // For the length of the selected text...
                for (int i = 0; i < selectedText.Length; i++)
                {
                    // If the current character is not a whitespace character...
                    if (!ignoreChars.Contains(selectedText[i]))
                    {
                        // If first letter index is negative that means this
                        // is the first letter of the word. Set the index accordingly.
                        if (i >= 0 && firstLetterIndex < 0)
                        {
                            // Set the first letter index to the index of the first letter of this word.
                            firstLetterIndex = i;
                        }

                        // Build the string one char at a time.
                        word.Append(selectedText[i]);
                    }

                    // Out of bounds check.
                    if ((i + 1) < selectedText.Length - 1)
                    {
                        // If the next char is whitespace char that means the current
                        // char is the last char of the current word.
                        if (ignoreChars.Contains(selectedText[i + 1]))
                        {
                            // Make sure it is not a forbidden word.
                            if ((firstWord || !forbidden.Contains(word.ToString())) && word.Length != 0)
                            {
                                // Convert the first letter of the word to uppercase.
                                firstLetter = Convert.ToChar(word[0].ToString().ToUpperInvariant());
                                // Replace the correct char in the selected text with its uppercase letter.
                                charArraySelText.SetValue(firstLetter, firstLetterIndex);
                                // Clear the word to make ready for the next one.
                                Clear(word);
                                // Reset first letter and first word indicators.
                                firstLetterIndex = -1;
                                firstWord        = false;
                            }
                            // Otherwise we do not want the word to be capitalized...
                            else
                            {
                                // Clear the word to make ready for the next one.
                                Clear(word);
                                // Reset first letter indicator.
                                firstLetterIndex = -1;
                            }
                        }
                    }
                    // Otherwise this is the last word of the selected text.
                    else if (i == selectedText.Length - 1)
                    {
                        // Convert the first letter of the word to uppercase.
                        firstLetter = Convert.ToChar(word[0].ToString().ToUpperInvariant());
                        // Replace the correct char in the selected text with its uppercase letter.
                        charArraySelText.SetValue(firstLetter, firstLetterIndex);
                        // Reset first letter indicator.
                        firstLetterIndex = -1;
                        break;
                    }
                }
                // Convert the char array back to string.
                selectedText = new string(charArraySelText);
                // Replace the selected text with the new string
                scintillaGateway.ReplaceSel(selectedText);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Exemple #10
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();
        }