void CheckCurrentState(string expression, FindFlags flags, SearchFilter filter)
 {
     if (this.expression != expression || this.flags != flags || this.filter != filter)
     {
         this.expression = expression;
         this.flags      = flags;
         this.filter     = filter;
         this.list       = null;
         this.match      = null;
     }
 }
        public FindResult FindNext(string expression, FindFlags flags, SearchFilter filter)
        {
            CheckCurrentState(expression, flags, filter);

            if (ev != null && ev.IsEditing)
            {
                start = ev.SelectionStart; // remember where we were in the editor.
                ev.EndEdit(false);
            }
            this.ev    = null;
            this.match = null;

            if (string.IsNullOrEmpty(expression))
            {
                return(FindResult.None);
            }

            if (this.list == null)
            {
                FindNodes();
            }

            // In case user changed the selection since the last find.
            int  pos          = FindSelectedNode();
            int  wrap         = -1;
            bool first        = true;
            bool hasSomething = this.list.Count > 0;

            while (this.list != null && hasSomething &&
                   (first || pos != wrap))
            {
                first = false;
                if (wrap == -1)
                {
                    wrap = pos;
                }
                if (this.Backwards)
                {
                    pos--;
                    if (pos < 0)
                    {
                        pos = list.Count - 1;
                    }
                }
                else
                {
                    pos++;
                    if (pos >= list.Count)
                    {
                        pos = 0;
                    }
                }

                XmlNodeMatch m    = list[pos] as XmlNodeMatch;
                XmlNode      node = m.Node;
                this.match = m;

                if (node != null)
                {
                    this.current = this.view.FindNode(node);
                    if (this.current == this.view.SelectedNode)
                    {
                        continue;
                    }
                    if (this.current != null)
                    {
                        this.view.SelectedNode = this.current;
                        if (m.IsName)
                        {
                            ev = this.view.TreeView;
                        }
                        else
                        {
                            ev = this.view.NodeTextView;
                        }
                        if (ev.BeginEdit(null))
                        {
                            ev.SelectText(m.Index, m.Length);
                        }
                    }
                }
                return(FindResult.Found);
            }
            return(hasSomething ? FindResult.NoMore : FindResult.None);
        }
Exemplo n.º 3
0
 void CheckCurrentState(string expression, FindFlags flags, SearchFilter filter)
 {
     if (this.expression != expression || this.flags != flags || this.filter != filter) {
         this.expression = expression;
         this.flags = flags;
         this.filter = filter;
         this.list = null;
         this.match = null;
     }
 }
Exemplo n.º 4
0
        public FindResult FindNext(string expression, FindFlags flags, SearchFilter filter)
        {
            CheckCurrentState(expression, flags, filter);

            this._match = null;

            if (string.IsNullOrEmpty(expression))
            {
                return(FindResult.None);
            }

            if (this._list == null)
            {
                FindNodes();
                this._position = -1;
                this._start    = -1; // we have not yet moved to one of the found nodes.
            }
            else if (this._resetPosition)
            {
                this._resetPosition = false;
                FindNodes();
                if (this._start >= _list.Count)
                {
                    this._start = _list.Count - 1;
                }

                if (this._position >= _list.Count)
                {
                    this._position = _list.Count - 1;
                }
            }

            int  s     = this._start;
            bool first = (this._start == -1);

            var  rc    = FindSelectedNode();
            int  pos   = rc.Item1;
            bool exact = rc.Item2;

            if (pos != this._position)
            {
                // user has moved the selection somewhere else, so start the find ring over again.
                first = true;
            }

            bool hasSomething = this._list != null && this._list.Count > 0;

            while (hasSomething)
            {
                if (this.Backwards)
                {
                    pos--;
                    if (pos < 0)
                    {
                        pos = _list.Count - 1;
                    }
                }
                else
                {
                    pos++;
                    if (pos >= _list.Count)
                    {
                        pos = 0;
                    }
                }

                if (first)
                {
                    this._start = s = pos;
                    first       = false;
                }
                else if (pos == this._start)
                {
                    // we have wrapped around!
                    break;
                }

                this._position = pos;

                XmlNodeMatch m = _list[pos] as XmlNodeMatch;
                if (m.Replaced)
                {
                    continue;
                }
                XmlNode node = m.Node;
                this._match = m;

                if (node != null)
                {
                    this._current = this._view.FindNode(node);
                    if (this._current != null)
                    {
                        this._view.SelectedNode = this._current;
                        if (m.IsName)
                        {
                            _ev = this._view.TreeView;
                        }
                        else
                        {
                            _ev = this._view.NodeTextView;
                        }
                        if (_ev.BeginEdit(null))
                        {
                            _ev.SelectText(m.Index, m.Length);
                        }
                    }
                }
                return(FindResult.Found);
            }

            this._start = -1; // get ready for another cycle around.
            return(hasSomething ? FindResult.NoMore : FindResult.None);
        }
Exemplo n.º 5
0
        public FindResult FindNext(string expression, FindFlags flags, SearchFilter filter)
        {
            CheckCurrentState(expression, flags, filter);

            if (ev != null && ev.IsEditing) {
                start = ev.SelectionStart; // remember where we were in the editor.
                ev.EndEdit(false);
            }
            this.ev = null;
            this.match = null;

            if (string.IsNullOrEmpty(expression))
                return FindResult.None;

            if (this.list == null) {
                FindNodes();
            }

            // In case user changed the selection since the last find.
            int pos = FindSelectedNode();
            int wrap = -1;
            bool first = true;
            bool hasSomething = this.list.Count > 0;
            while (this.list != null && hasSomething &&
                (first || pos != wrap)) {
                first = false;
                if (wrap == -1) wrap = pos;
                if (this.Backwards) {
                    pos--;
                    if (pos < 0) pos = list.Count - 1;
                } else {
                    pos++;
                    if (pos >= list.Count) pos = 0;
                }

                XmlNodeMatch m = list[pos] as XmlNodeMatch;
                XmlNode node = m.Node;
                this.match = m;

                if (node != null) {
                    this.current = this.view.FindNode(node);
                    if (this.current == this.view.SelectedNode) {
                        continue;
                    }
                    if (this.current != null) {
                        this.view.SelectedNode = this.current;
                        if (m.IsName) {
                            ev = this.view.TreeView;
                        } else {
                            ev = this.view.NodeTextView;
                        }
                        if (ev.BeginEdit(null)) {
                            ev.SelectText(m.Index, m.Length);
                        }
                    }
                }
                return FindResult.Found;
            }
            return hasSomething ? FindResult.NoMore : FindResult.None;
        }