Esempio n. 1
0
		private void RemoveItemsRequested(object sender, RemoveItemsRequestedEventArgs e)
		{
			SelectionHelper sel = SelectionHelper.Create(m_view);
			int cellId = -1;
			int cellIndex = -1;
			UndoableUnitOfWorkHelper.Do(MEStrings.ksRuleUndoRemove, MEStrings.ksRuleRedoRemove, m_cache.ActionHandlerAccessor, () =>
			{
				cellId = RemoveItems(sel, e.Forward, out cellIndex);
			});

			// if the no cell is returned, then do not reconstruct
			if (cellId != -1 && cellId != -2)
				// if the cell index is -1 that means that we removed the first item in this cell,
				// so we move the cursor to the beginning of the first item after the removed items,
				// instead of the end of the item before the removed items.
				ReconstructView(cellId, cellIndex, cellIndex == -1);
		}
Esempio n. 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);
                }
            }
        }