Beispiel #1
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);
            }
        }
Beispiel #2
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = Index;
         hashCode = (hashCode * 397) ^ PageSize;
         hashCode = (hashCode * 397) ^ ShowEmpty.GetHashCode();
         hashCode = (hashCode * 397) ^ OnlySelected.GetHashCode();
         hashCode = (hashCode * 397) ^ Lang;
         hashCode = (hashCode * 397) ^ MatchWholeWord.GetHashCode();
         hashCode = (hashCode * 397) ^ (TextToFind != null ? TextToFind.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Category != null ? Category.GetHashCode() : 0);
         return(hashCode);
     }
 }
        public Findwindow(MainWindow mainwin)
        {
            _main     = mainwin;
            _editText = _main.EditText1;

            InitializeComponent();

            // for window odality operation
            ownerHandle = (new System.Windows.Interop.WindowInteropHelper(mainwin)).Handle;
            handle      = (new System.Windows.Interop.WindowInteropHelper(this)).Handle;
            EnableWindow(handle, true);
            SetForegroundWindow(handle);

            // initial setting
            TextToFind.Focus();
            DirectionDown.IsChecked = true;
        }
Beispiel #4
0
        private unsafe SearchResult InternalSearch(SearchFlags flags, string text, int startPosition, int endPosition)
        {
            fixed(byte *pt = Encoding.UTF8.GetBytes(text))
            {
                var pf = new TextToFind();

                pf.lpstrText = (IntPtr)pt;
                pf.chrg.Min  = startPosition;
                pf.chrg.Max  = endPosition <= 0 ? startPosition + scintilla.Ref.Send(Sci.SCI_GETTEXTLENGTH) : endPosition;

                var res = RunSearch(flags, ref pf);

                if (res == -1)
                {
                    return(SearchResult.NotFound);
                }
                else
                {
                    return(new SearchResult(pf.chrgText.Min, pf.chrgText.Max));
                }
            }
        }
Beispiel #5
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();
        }
Beispiel #6
0
        private static bool SearchNextSectionOrPerform(string sectionName, int offset)
        {
            var editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());

            using (TextToFind textToFind = new TextToFind(offset, editor.GetTextLength() - 1, sectionName))
            {
                Position sectionPosition = editor.FindText(0, textToFind);
                if (sectionPosition.Value >= 0)
                {
                    if (editor.GetLine(editor.LineFromPosition(sectionPosition)).StartsWith("*"))
                    {
                        CurrentSearchOffset = sectionPosition.Value + sectionName.Length;
                        return(SearchNextSectionOrPerform(sectionName, CurrentSearchOffset));
                    }
                    ScrollToLine(editor.LineFromPosition(sectionPosition));
                    CurrentSearchOffset = sectionPosition.Value + sectionName.Length;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
 private void Window_Activated(object sender, EventArgs e)
 {
     TextToFind.Focus();
 }
Beispiel #8
0
        public int Execute()
        {
            try
            {
                string textToParse;
                string textToFind;

                List <int> indexes = new List <int>();


                if (IgnoreCase)
                {
                    textToParse = TextToParse.ToLower();
                    textToFind  = TextToFind.ToLower();
                }
                else
                {
                    textToParse = TextToParse;
                    textToFind  = TextToFind;
                }

                if (UseRegulerExpression)
                {
                    string pattern = textToFind;
                    textToParse = textToParse.Remove(0, StartingPoint + 1);
                    Regex rgx = new Regex(textToFind);

                    foreach (Match match in rgx.Matches(textToParse))
                    {
                        indexes.Add(match.Index);
                    }
                }
                else
                {
                    indexes = FindIndexes(TextToParse + " ", TextToFind, StartingPoint).ToList();
                }


                if (FirstOccurenceOnly && indexes.Count > 1)
                {
                    indexes.RemoveRange(1, indexes.Count - 1);
                }



                if (VariableStorage.FindTextVar.ContainsKey(ResultStoreVar))
                {
                    VariableStorage.FindTextVar.Remove(ResultStoreVar);
                }

                VariableStorage.FindTextVar.Add(ResultStoreVar, Tuple.Create(this.ID, indexes));
                VarCounter++;



                return(1);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
Beispiel #9
0
 private unsafe int RunSearch(SearchFlags flags, ref TextToFind ttf)
 {
     fixed(TextToFind *pff = &ttf)
     return(scintilla.Ref.Send(Sci.SCI_FINDTEXT, (Int32)flags, (IntPtr)pff));
 }
Beispiel #10
0
        internal void GuessIndentation(IntPtr id, bool force = false)
        {
            if (Main.FileCache.TryGetValue(id, out BufferInfo buff))
            {
                SetUseTabs(buff.UseTabs);
                return;
            }

            if (!nps.EnableAutoDetect && !force)
            {
                return;
            }

            int numLines = (int)Win32.SendMessage(nps.CurScintilla, SciMsg.SCI_GETLINECOUNT, 0, 0);

            if (numLines >= nps.AutodetectMinLinesToRead)
            {
                int wsLines  = 0;
                int tabLines = 0;
                var ttf      = new TextToFind(0, 0, @"^\s+");
                for (var i = 0; i < Math.Min(nps.AutodetectMaxLinesToRead, numLines); i++)
                {
                    int startPos = (int)Win32.SendMessage(nps.CurScintilla, SciMsg.SCI_POSITIONFROMLINE, i, 0);
                    int endPos   = (int)Win32.SendMessage(nps.CurScintilla, SciMsg.SCI_GETLINEENDPOSITION, i, 0); // excl EOL chars
                    int lineLen  = endPos - startPos;
                    if (lineLen > 0)
                    {
                        ttf.chrg = new CharacterRange(startPos, startPos + Math.Min(lineLen, nps.AutodetectMaxCharsToReadPerLine));
                        int find = (int)Win32.SendMessage(nps.CurScintilla, SciMsg.SCI_FINDTEXT, (int)(SciMsg.SCFIND_REGEXP | SciMsg.SCFIND_CXX11REGEX), ttf.NativePointer);
                        if (find != -1)
                        {
                            wsLines++;
                            var rgFind = ttf.chrgText;
                            var tr     = new TextRange(rgFind, rgFind.cpMax - rgFind.cpMin + 1);
                            Win32.SendMessage(nps.CurScintilla, SciMsg.SCI_GETTEXTRANGE, 0, tr.NativePointer);
                            if (tr.lpstrText.Contains("\t"))
                            {
                                tabLines++;
                            }

                            //MessageBox.Show(string.Format("Line: {3}\nFind start: {0}\nFind end: {1}\nFind len: {2}",
                            //    rgFind.cpMin, rgFind.cpMax, rgFind.cpMax - rgFind.cpMin, i + 1));
                        }
                    }
                }

                if (wsLines >= nps.AutodetectMinWhitespaceLines)
                {
                    buff = GetBufferInfo(id);
                    if (tabLines >= (wsLines - tabLines))
                    {
                        buff.UseTabs = 1;
                    }
                    else
                    {
                        buff.UseTabs = 0;
                    }

                    Main.FileCache[id] = buff;
                    SetUseTabs(buff.UseTabs);
                }

                //MessageBox.Show(string.Format("Lines: {0}, count: {1}, tabs: {2}\nFile: {3}", numLines, wsLines, tabLines, buff.path));
            }
        }