Ejemplo n.º 1
0
        public bool PreviousSnippetRange()
        {
            //	Same as NextSnippetRange but going in the opposite direction
            if (!_snippetLinks.IsActive || Scintilla.AutoComplete.IsActive)
            {
                return(false);
            }

            SnippetLink sl = _snippetLinks.PreviousActiveSnippetLink;

            if (sl != null)
            {
                while (sl.Ranges.Count == 0)
                {
                    _snippetLinks.Remove(sl);
                    sl = _snippetLinks.PreviousActiveSnippetLink;
                    if (sl == null)
                    {
                        Scintilla.Commands.StopProcessingCommands = true;
                        return(true);
                    }
                }

                sl.Ranges[0].Select();
                Scintilla.Commands.StopProcessingCommands = true;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        private void cascadeSnippetLinkRangeChange(SnippetLink oldActiveSnippetLink, SnippetLinkRange oldActiveRange)
        {
            Scintilla.ManagedRanges.Sort();

            int offset = 0;

            string newText = oldActiveRange.Text;


            Scintilla.NativeInterface.SetModEventMask(0);
            foreach (ManagedRange mr in Scintilla.ManagedRanges)
            {
                if (offset != 0)
                {
                    mr.Change(mr.Start + offset, mr.End + offset);
                }

                SnippetLinkRange slr = mr as SnippetLinkRange;
                if (slr == null || !oldActiveSnippetLink.Ranges.Contains(slr) || slr.Text == newText)
                {
                    continue;
                }

                int oldLength = slr.Length;
                slr.Text = newText;
                slr.End += newText.Length - oldLength;
                offset  += newText.Length - oldLength;
            }

            Scintilla.NativeInterface.SetModEventMask(Constants.SC_MODEVENTMASKALL);
        }
Ejemplo n.º 3
0
        private void Scintilla_SelectionChanged(object sender, EventArgs e)
        {
            Range sr = Scintilla.Selection.Range;

            if (_snippetLinks.IsActive)
            {
                SnippetLink      oldActiveSnippetLink = _snippetLinks.ActiveSnippetLink;
                SnippetLinkRange oldActiveRange       = _snippetLinks.ActiveRange;

                _snippetLinks.ActiveSnippetLink = null;
                _snippetLinks.ActiveRange       = null;

                for (int i = 0; i < _snippetLinks.Count; i++)
                {
                    SnippetLink sl = _snippetLinks[i];

                    foreach (SnippetLinkRange r in sl.Ranges)
                    {
                        if (r.IntersectsWith(sr))
                        {
                            _snippetLinks.ActiveSnippetLink = sl;
                            _snippetLinks.ActiveRange       = r;
                            break;
                        }
                    }
                    if (_snippetLinks.ActiveRange != null)
                    {
                        break;
                    }
                }

                foreach (SnippetLink sl in _snippetLinks.Values)
                {
                    foreach (Range r in sl.Ranges)
                    {
                        if (sl == _snippetLinks.ActiveSnippetLink)
                        {
                            r.ClearIndicator(Scintilla.Snippets.InactiveSnippetIndicator);
                            r.SetIndicator(Scintilla.Snippets.ActiveSnippetIndicator);
                        }
                        else
                        {
                            r.SetIndicator(Scintilla.Snippets.InactiveSnippetIndicator);
                            r.ClearIndicator(Scintilla.Snippets.ActiveSnippetIndicator);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public bool NextSnippetRange()
        {
            //	This would be a whole lot easier if I had the Command Contexts set
            //	up. The way it's working now is that this command will always execute
            //	irregardlessly of if the SnippetLinks are active. Since we may not have
            //	a valid context to execute we don't necessarily want to eat the
            //	keystroke in all circumstances, hence the bool return
            if (!_snippetLinks.IsActive || Scintilla.AutoComplete.IsActive)
            {
                return(false);
            }

            //	OK So we want to find the next SnippetLink in
            //	whatever order they are in and then select it
            //	so that they can fill it out.
            SnippetLink sl = _snippetLinks.NextActiveSnippetLink;

            if (sl != null)
            {
                //	However it is possible that all of this Snippet Links'
                //	ranges have been deleted by the user. If this is the case
                //	we need to remove this snippet link from the list and go
                //	to the next link.

                while (sl.Ranges.Count == 0)
                {
                    _snippetLinks.Remove(sl);
                    sl = _snippetLinks.NextActiveSnippetLink;

                    //	No more snippet links? Nothing to do but quit
                    if (sl == null)
                    {
                        Scintilla.Commands.StopProcessingCommands = true;
                        return(true);
                    }
                }

                //	Yay we have it. Select the first Range in the Snippet Link's Series
                sl.Ranges[0].Select();
                Scintilla.Commands.StopProcessingCommands = true;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        private void snippetLinkTimer_Tick(object sender, EventArgs e)
        {
            _snippetLinkTimer.Enabled = false;
            Range sr = Scintilla.Selection.Range;

            if (_snippetLinks.IsActive)
            {
                SnippetLink      oldActiveSnippetLink = _snippetLinks.ActiveSnippetLink;
                SnippetLinkRange oldActiveRange       = _snippetLinks.ActiveRange;

                if (oldActiveRange != null && (oldActiveRange.IntersectsWith(sr) || oldActiveRange.Equals(sr)))
                {
                    Scintilla.BeginInvoke(new MethodInvoker(delegate()
                    {
                        cascadeSnippetLinkRangeChange(oldActiveSnippetLink, oldActiveRange);

                        foreach (SnippetLink sl in _snippetLinks.Values)
                        {
                            foreach (Range r in sl.Ranges)
                            {
                                if (sl == _snippetLinks.ActiveSnippetLink)
                                {
                                    r.ClearIndicator(Scintilla.Snippets.InactiveSnippetIndicator);
                                    r.SetIndicator(Scintilla.Snippets.ActiveSnippetIndicator);
                                }
                                else
                                {
                                    r.SetIndicator(Scintilla.Snippets.InactiveSnippetIndicator);
                                    r.ClearIndicator(Scintilla.Snippets.ActiveSnippetIndicator);
                                }
                            }
                        }

                        if (_pendingUndo)
                        {
                            _pendingUndo = false;
                            Scintilla.UndoRedo.EndUndoAction();
                        }

                        Scintilla.NativeInterface.Colourise(0, -1);
                    }));
                }
            }
        }
Ejemplo n.º 6
0
        private SnippetLinkRange addSnippetLink(SnippetLinkRange range)
        {
            string      key = range.Key;
            SnippetLink sl  = null;

            for (int i = 0; i < _snippetLinks.Count; i++)
            {
                if (_snippetLinks[i].Key.Equals(key, StringComparison.CurrentCultureIgnoreCase))
                {
                    sl = _snippetLinks[i];
                    break;
                }
            }
            if (sl == null)
            {
                sl = new SnippetLink(key);
                _snippetLinks.Add(sl);
            }

            sl.Ranges.Add(range);
            range.Parent = sl.Ranges;

            return(range);
        }
Ejemplo n.º 7
0
        private SnippetLinkRange addSnippetLink(SnippetLinkRange range)
        {
            string key = range.Key;
            SnippetLink sl = null;
            for (int i = 0; i < _snippetLinks.Count; i++)
            {
                if (_snippetLinks[i].Key.Equals(key, StringComparison.CurrentCultureIgnoreCase))
                {
                    sl = _snippetLinks[i];
                    break;
                }
            }
            if (sl == null)
            {
                sl = new SnippetLink(key);
                _snippetLinks.Add(sl);
            }

            sl.Ranges.Add(range);
            range.Parent = sl.Ranges;

            return range;
        }
Ejemplo n.º 8
0
        private void cascadeSnippetLinkRangeChange(SnippetLink oldActiveSnippetLink, SnippetLinkRange oldActiveRange)
        {
            Scintilla.ManagedRanges.Sort();

            int offset = 0;

            string newText = oldActiveRange.Text;


            Scintilla.NativeInterface.SetModEventMask(0);
            foreach (ManagedRange mr in Scintilla.ManagedRanges)
            {
                if (offset != 0)
                    mr.Change(mr.Start + offset, mr.End + offset);

                SnippetLinkRange slr = mr as SnippetLinkRange;
                if (slr == null || !oldActiveSnippetLink.Ranges.Contains(slr) || slr.Text == newText)
                    continue;

                int oldLength = slr.Length;
                slr.Text = newText;
                slr.End += newText.Length - oldLength;
                offset += newText.Length - oldLength;
            }

            Scintilla.NativeInterface.SetModEventMask(Constants.SC_MODEVENTMASKALL);
        }