Exemple #1
0
        /// <summary>
        /// Checks for and reports any disallowed discourse template moves.
        /// </summary>
        /// <param name="movingColumn">The proposed possibility item (template column) to move.</param>
        /// <param name="hvoTemplate">The hvo of the affected Chart Template (only 'default' exists so far).</param>
        /// <param name="hvoTemplateList">The hvo of the Template List.</param>
        /// <param name="hvoDest">The hvo of the destination item.</param>
        /// <returns>true means we found and reported a bad move.</returns>
        private bool CheckAndReportBadDiscourseTemplateMove(ICmPossibility movingColumn, int hvoTemplate,
                                                            int hvoTemplateList, int hvoDest)
        {
            using (var movingColumnUI = new CmPossibilityUi(movingColumn))
            {
                // First, check whether we're allowed to manipulate this column at all. This is the same check as
                // whether we're allowed to delete it.
                if (movingColumnUI.CheckAndReportProtectedChartColumn())
                {
                    return(true);
                }
            }
            // Other things being equal, we now need to make sure we aren't messing up the chart levels
            // Unless something is badly wrong, the destination is either the root template,
            // a column group one level down from the root template, a column two levels down,
            // or the base list.
            if (hvoDest == hvoTemplateList)
            {
                MessageBox.Show(m_tree, xWorksStrings.ksCantPromoteGroupToTemplate,
                                xWorksStrings.ksProhibitedMovement, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(true);
            }
            // if the destination IS the root, that's fine...anything can move there.
            if (hvoDest == hvoTemplate)
            {
                return(false);
            }
            // It's OK to move a leaf to a group (one level down from the root, as long as
            // the destination 'group' isn't a column that's in use.
            bool moveColumnIsLeaf = movingColumn.SubPossibilitiesOS.Count == 0;

            if (m_objRepo.GetObject(hvoDest).Owner.Hvo == hvoTemplate && moveColumnIsLeaf)
            {
                ICmPossibility dest = m_possRepo.GetObject(hvoDest);
                using (var destUI = new CmPossibilityUi(dest))
                {
                    // If it isn't already a group, we can only turn it into one if it's empty
                    if (dest.SubPossibilitiesOS.Count == 0)
                    {
                        return(destUI.CheckAndReportProtectedChartColumn());
                    }
                }
                // If it's already a group it should be fine as a destination.
                return(false);
            }
            // Anything else represents an attempt to make the tree too deep, e.g., moving a
            // column into child column, or a group into another group.
            MessageBox.Show(m_tree, xWorksStrings.ksTemplateTooDeep,
                            xWorksStrings.ksProhibitedMovement, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Move the clicked item the specified distance (currently +/- 1) in its owning list.
        /// </summary>
        /// <param name="distance"></param>
        void MoveItem(int distance)
        {
            int hvoMove = ClickObject;

            if (hvoMove == 0)
            {
                return;
            }

            ICmPossibility column = m_possRepo.GetObject(hvoMove);

            using (var columnUI = new CmPossibilityUi(column))
            {
                if (columnUI.CheckAndReportProtectedChartColumn())
                {
                    return;
                }
            }
            var owner = column.Owner;

            if (owner == null)             // probably not possible
            {
                return;
            }
            int hvoOwner = owner.Hvo;
            int ownFlid  = column.OwningFlid;
            int oldIndex = m_cache.DomainDataByFlid.GetObjIndex(hvoOwner, ownFlid, column.Hvo);
            int newIndex = oldIndex + distance;

            if (newIndex < 0)
            {
                return;
            }
            int cobj = m_cache.DomainDataByFlid.get_VecSize(hvoOwner, ownFlid);

            if (newIndex >= cobj)
            {
                return;
            }
            // Without this, we insert it before the next object, which is the one it's already before,
            // so it doesn't move.
            if (distance > 0)
            {
                newIndex++;
            }
            UndoableUnitOfWorkHelper.Do(xWorksStrings.UndoMoveItem, xWorksStrings.RedoMoveItem,
                                        m_cache.ActionHandlerAccessor,
                                        () => m_cache.DomainDataByFlid.MoveOwnSeq(
                                            hvoOwner, ownFlid, oldIndex, oldIndex, hvoOwner, ownFlid, newIndex));
        }