/// <summary> /// Checks for and reports any disallowed discourse template moves. /// </summary> /// <param name="cache"></param> /// <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(FdoCache cache, CmPossibility movingColumn, int hvoTemplate, int hvoTemplateList, int hvoDest) { // 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 (movingColumn.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 (cache.GetOwnerOfObject(hvoDest) == hvoTemplate && moveColumnIsLeaf) { CmPossibility dest = (CmPossibility.CreateFromDBObject(cache, hvoDest)) as CmPossibility; // If it isn't already a group, we can only turn it into one if it's empty if (dest.SubPossibilitiesOS.Count == 0) { return(dest.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); }
/// <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; FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache"); CmPossibility column = CmObject.CreateFromDBObject(cache, hvoMove) as CmPossibility; if (column.CheckAndReportProtectedChartColumn()) { return; } int hvoOwner = cache.GetOwnerOfObject(hvoMove); if (hvoOwner == 0) // probably not possible { return; } ICmObject owner = CmObject.CreateFromDBObject(cache, hvoOwner); int flid = column.OwningFlid; int oldIndex = column.IndexInOwner; int newIndex = oldIndex + distance; if (newIndex < 0) { return; } int cobj = cache.GetVectorSize(owner.Hvo, flid); 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++; } cache.MoveOwningSequence(owner.Hvo, flid, oldIndex, oldIndex, owner.Hvo, flid, newIndex); }