示例#1
0
		protected int GetIndexToRemove(ICmObject[] objs, SelectionHelper sel, bool forward)
		{
			ICmObject obj = GetCmObject(sel, SelectionHelper.SelLimitType.Top);
			for (int i = 0; i < objs.Length; i++)
			{
				if (objs[i] == obj)
				{
					var tss = sel.GetTss(SelectionHelper.SelLimitType.Anchor);
					// if the current ich is at the end of the current string, then we can safely assume
					// we are at the end of the current item, so remove it or the next item based on what
					// key was pressed, otherwise we are in the middle in which
					// case the entire item is selected, or at the beginning, so we remove it or the previous
					// item based on what key was pressed
					if (sel.IchAnchor == tss.Length)
					{
						if (forward)
							return i == objs.Length ? -1 : i + 1;
						return i;
					}
					if (forward)
						return i == objs.Length ? -1 : i;
					return i - 1;
				}
			}

			return -1;
		}
示例#2
0
        private void RemoveItemsRequested(object sender, RemoveItemsRequestedEventArgs e)
        {
            if (m_patternModel.Root.IsLeaf)
            {
                return;
            }

            SelectionHelper        sel    = SelectionHelper.Create(m_view);
            ComplexConcPatternNode parent = null;
            int index = -1;

            if (sel.IsRange)
            {
                ComplexConcPatternNode[] nodes = CurrentNodes;
                if (nodes.Length > 0)
                {
                    parent = nodes[0].Parent;
                    index  = GetNodeIndex(nodes[0]);
                    foreach (ComplexConcPatternNode node in nodes)
                    {
                        node.Parent.Children.Remove(node);
                    }
                }
            }
            else
            {
                ComplexConcPatternNode n = GetNode(sel, SelectionHelper.SelLimitType.Top);
                parent = n.Parent;
                index  = GetNodeIndex(n);
                ITsString tss = sel.GetTss(SelectionHelper.SelLimitType.Anchor);
                // if the current ich is at the end of the current string, then we can safely assume
                // we are at the end of the current item, so remove it or the next item based on what
                // key was pressed, otherwise we are in the middle in which
                // case the entire item is selected, or at the beginning, so we remove it or the previous
                // item based on what key was pressed
                if (sel.IchAnchor == tss.Length)
                {
                    if (e.Forward)
                    {
                        if (index == n.Parent.Children.Count - 1)
                        {
                            index = -1;
                        }
                        else
                        {
                            index++;
                        }
                    }
                }
                else
                {
                    if (!e.Forward)
                    {
                        index--;
                    }
                }

                if (index != -1)
                {
                    parent.Children.RemoveAt(index);
                }
            }

            if (parent != null && index != -1)
            {
                if (!parent.IsLeaf)
                {
                    bool isFirstBdry = parent.Children[0] is ComplexConcWordBdryNode;
                    if ((parent.Children.Count == 1 && isFirstBdry) ||
                        (parent.Children.Count > 1 && isFirstBdry && !(parent.Children[1] is ComplexConcMorphNode)))
                    {
                        parent.Children.RemoveAt(0);
                        if (index > 0)
                        {
                            index--;
                        }
                    }
                }
                if (parent.Children.Count > 1 && parent.Children[parent.Children.Count - 1] is ComplexConcWordBdryNode &&
                    !(parent.Children[parent.Children.Count - 2] is ComplexConcMorphNode))
                {
                    parent.Children.RemoveAt(parent.Children.Count - 1);
                    if (index >= parent.Children.Count)
                    {
                        index--;
                    }
                }
                for (int i = parent.Children.Count - 1; i > 0; i--)
                {
                    if (parent.Children[i] is ComplexConcWordBdryNode)
                    {
                        if (parent.Children[i - 1] is ComplexConcWordBdryNode ||
                            (!(parent.Children[i - 1] is ComplexConcMorphNode) || (i + 1 < parent.Children.Count && !(parent.Children[i + 1] is ComplexConcMorphNode))))
                        {
                            parent.Children.RemoveAt(i);
                            if (index > i)
                            {
                                index--;
                            }
                        }
                    }
                }

                if (!parent.IsLeaf && parent.Children[0] is ComplexConcOrNode)
                {
                    parent.Children.RemoveAt(0);
                    if (index > 0)
                    {
                        index--;
                    }
                }
                if (!parent.IsLeaf && parent.Children[parent.Children.Count - 1] is ComplexConcOrNode)
                {
                    parent.Children.RemoveAt(parent.Children.Count - 1);
                    if (index >= parent.Children.Count)
                    {
                        index--;
                    }
                }
                for (int i = parent.Children.Count - 1; i > 0; i--)
                {
                    if (parent.Children[i] is ComplexConcOrNode && parent.Children[i - 1] is ComplexConcOrNode)
                    {
                        parent.Children.RemoveAt(i);
                        if (index > i)
                        {
                            index--;
                        }
                    }
                }

                if (parent.Parent != null && parent.Children.Count == 1)
                {
                    ComplexConcPatternNode p = parent.Parent;
                    int parentIndex          = GetNodeIndex(parent);
                    p.Children.RemoveAt(parentIndex);
                    p.Children.Insert(parentIndex, parent.Children[0]);
                    index = index == 1 ? parentIndex + 1 : parentIndex;
                }
                else
                {
                    while (parent.Parent != null && parent.IsLeaf)
                    {
                        ComplexConcPatternNode p = parent.Parent;
                        index = GetNodeIndex(parent);
                        p.Children.Remove(parent);
                        parent = p;
                    }
                }

                if (index >= parent.Children.Count)
                {
                    ReconstructView(parent, parent.Children.Count - 1, false);
                }
                else
                {
                    ReconstructView(parent, index, true);
                }
            }
        }