示例#1
0
        /// <summary>
        /// Checks if the client can do the command</summary>
        /// <param name="commandTag">Command</param>
        /// <returns>True if client can do the command</returns>
        bool ICommandClient.CanDoCommand(object commandTag)
        {
            if (commandTag is StandardCommand)
            {
                ISelectionContext  selectionContext  = m_contextRegistry.GetActiveContext <ISelectionContext>();
                IEnumerableContext enumerableContext = m_contextRegistry.GetActiveContext <IEnumerableContext>();

                switch ((StandardCommand)commandTag)
                {
                case StandardCommand.ViewHide:
                    return(selectionContext != null && selectionContext.SelectionCount > 0);

                case StandardCommand.ViewShow:
                    return(selectionContext != null && selectionContext.SelectionCount > 0);

                case StandardCommand.ViewShowLast:
                    return(m_hideStack != null && m_hideStack.Count > 0);

                case StandardCommand.ViewShowAll:
                    return(enumerableContext != null);

                case StandardCommand.ViewIsolate:
                    return(selectionContext != null && selectionContext.SelectionCount > 0);
                }
            }

            return(false);
        }
        /// <summary>
        /// Checks if the client can do the command</summary>
        /// <param name="commandTag">Command</param>
        /// <returns>True if client can do the command</returns>
        bool ICommandClient.CanDoCommand(object commandTag)
        {
            bool canDo = false;

            if (commandTag is StandardCommand)
            {
                IViewingContext viewingContext = m_contextRegistry.GetActiveContext <IViewingContext>();

                switch ((StandardCommand)commandTag)
                {
                case StandardCommand.ViewFrameSelection:
                    ISelectionContext selectionContext = m_contextRegistry.GetActiveContext <ISelectionContext>();
                    if (viewingContext != null && selectionContext != null)
                    {
                        canDo = viewingContext.CanFrame(selectionContext.Selection);
                    }
                    break;

                case StandardCommand.ViewFrameAll:
                    IEnumerableContext enumerableContext = m_contextRegistry.GetActiveContext <IEnumerableContext>();
                    if (viewingContext != null && enumerableContext != null)
                    {
                        canDo = viewingContext.CanFrame(enumerableContext.Items);
                    }
                    break;
                }
            }

            return(canDo);
        }
示例#3
0
        /// <summary>
        /// Checks if the client can do the command</summary>
        /// <param name="commandTag">Command</param>
        /// <returns>True if client can do the command</returns>
        bool ICommandClient.CanDoCommand(object commandTag)
        {
            bool canDo = false;

            if (commandTag is StandardCommand)
            {
                ISelectionContext  selectionContext  = m_contextRegistry.GetActiveContext <ISelectionContext>();
                IEnumerableContext enumerableContext = m_contextRegistry.GetActiveContext <IEnumerableContext>();

                // This logic needs to be kept in sync with ActiveContextChanged() and SelectionChanged().
                switch ((StandardCommand)commandTag)
                {
                case StandardCommand.EditDeselectAll:
                    canDo =
                        selectionContext != null &&
                        selectionContext.LastSelected != null;
                    break;

                case StandardCommand.EditSelectAll:
                case StandardCommand.EditInvertSelection:
                    // Doing an exact test to see if these commands are useful is expensive.
                    // Let's enable them if there is a selection and enumerable context.
                    canDo =
                        selectionContext != null &&
                        enumerableContext != null;
                    break;
                }
            }

            return(canDo);
        }
        /// <summary>
        /// Frames all items, if the context registry's current context is
        /// adaptable to an IViewingContext and an IEnumerableContext</summary>
        public void FrameAll()
        {
            object               activeContext     = m_contextRegistry.ActiveContext;
            IEnumerableContext   enumerableContext = activeContext.As <IEnumerableContext>();
            IEnumerable <object> items             = (enumerableContext != null) ? enumerableContext.Items : null;

            FrameAll(
                activeContext.As <IViewingContext>(),
                items);
        }
示例#5
0
        /// <summary>
        /// Selects all enumerable objects in the given context</summary>
        /// <param name="selectionContext">Context holding selection</param>
        /// <param name="enumerableContext">Context holding enumeration of selectable objects</param>
        /// <returns>True iff all objects were selected</returns>
        public bool SelectAll(ISelectionContext selectionContext, IEnumerableContext enumerableContext)
        {
            if (selectionContext != null &&
                enumerableContext != null)
            {
                selectionContext.SetRange(enumerableContext.Items);
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Selects all enumerable objects in the given context</summary>
        /// <param name="selectionContext">Context holding selection</param>
        /// <param name="enumerableContext">Context holding enumeration of selectable objects</param>
        /// <returns>True iff all objects were selected</returns>
        public bool SelectAll(ISelectionContext selectionContext, IEnumerableContext enumerableContext)
        {
            if (selectionContext != null &&
                enumerableContext != null)
            {
                selectionContext.SetRange(enumerableContext.Items);
                return true;
            }

            return false;
        }
示例#7
0
        /// <summary>
        /// Shows all objects</summary>
        /// <param name="visibilityContext">Visibility context</param>
        /// <param name="enumerableContext">Enumerable context</param>
        public void ShowAll(IVisibilityContext visibilityContext, IEnumerableContext enumerableContext)
        {
            if (visibilityContext != null && enumerableContext != null)
            {
                foreach (object item in enumerableContext.Items)
                {
                    visibilityContext.SetVisible(item, true);
                }

                Refresh();
            }
        }
示例#8
0
        /// <summary>
        /// Checks if the client can do the command</summary>
        /// <param name="commandTag">Command</param>
        /// <returns>True if client can do the command</returns>
        bool ICommandClient.CanDoCommand(object commandTag)
        {
            bool canDo = false;

            if (commandTag is StandardCommand)
            {
                ISelectionContext  selectionContext  = m_contextRegistry.GetActiveContext <ISelectionContext>();
                IEnumerableContext enumerableContext = m_contextRegistry.GetActiveContext <IEnumerableContext>();;

                switch ((StandardCommand)commandTag)
                {
                case StandardCommand.EditSelectAll:
                    if (selectionContext != null && enumerableContext != null)
                    {
                        // test if there are any objects
                        foreach (object item in enumerableContext.Items)
                        {
                            canDo = true;
                            break;
                        }
                    }
                    break;

                case StandardCommand.EditDeselectAll:
                    canDo =
                        selectionContext != null &&
                        selectionContext.LastSelected != null;
                    break;

                case StandardCommand.EditInvertSelection:
                    canDo =
                        selectionContext != null &&     // if selection, and enumerable, we can invert
                        enumerableContext != null;
                    break;
                }
            }

            return(canDo);
        }
示例#9
0
        /// <summary>
        /// Does a command</summary>
        /// <param name="commandTag">Command</param>
        void ICommandClient.DoCommand(object commandTag)
        {
            if (commandTag is StandardCommand)
            {
                ISelectionContext  selectionContext  = m_contextRegistry.GetActiveContext <ISelectionContext>();
                IEnumerableContext enumerableContext = m_contextRegistry.GetActiveContext <IEnumerableContext>();
                IVisibilityContext visibilityContext = m_contextRegistry.GetActiveContext <IVisibilityContext>();

                IEnumerable <object> selection = null;
                if (selectionContext != null)
                {
                    selection = selectionContext.Selection;
                }

                switch ((StandardCommand)commandTag)
                {
                case StandardCommand.ViewHide:
                    HideSelection(selection, visibilityContext);
                    break;

                case StandardCommand.ViewShow:
                    ShowSelection(selection, visibilityContext);
                    break;

                case StandardCommand.ViewShowLast:
                    ShowLastHidden(visibilityContext);
                    break;

                case StandardCommand.ViewShowAll:
                    ShowAll(visibilityContext, enumerableContext);
                    break;

                case StandardCommand.ViewIsolate:
                    IsolateSelection(selection, visibilityContext, enumerableContext);
                    break;
                }
            }
        }
示例#10
0
        /// <summary>
        /// Inverts the selection in the given context (deselect all selected, and select all deselected objects)</summary>
        /// <param name="selectionContext">Context holding selection</param>
        /// <param name="enumerableContext">Context holding enumeration of selectable objects</param>
        /// <returns>True iff selection was inverted</returns>
        public bool InvertSelection(ISelectionContext selectionContext, IEnumerableContext enumerableContext)
        {
            if (selectionContext != null &&
                enumerableContext != null)
            {
                HashSet <object> selected = new HashSet <object>(selectionContext.Selection);
                List <object>    inverted = new List <object>(enumerableContext.Items);
                for (int i = 0; i < inverted.Count;)
                {
                    if (selected.Contains(inverted[i]))
                    {
                        inverted.RemoveAt(i);
                    }
                    else
                    {
                        i++;
                    }
                }

                selectionContext.SetRange(inverted);
            }

            return(false);
        }
示例#11
0
        private void IsolateSelection(IEnumerable<object> selection, IVisibilityContext visibilityContext, IEnumerableContext enumerableContext)
        {
            if (selection != null && visibilityContext != null && enumerableContext != null)
            {
                foreach (object item in enumerableContext.Items)
                    visibilityContext.SetVisible(item, false);

                foreach (object item in selection)
                    visibilityContext.SetVisible(item, true);

                Refresh();
            }
        }
示例#12
0
        /// <summary>
        /// Shows all objects</summary>
        /// <param name="visibilityContext">Visibility context</param>
        /// <param name="enumerableContext">Enumerable context</param>
        public void ShowAll(IVisibilityContext visibilityContext, IEnumerableContext enumerableContext)
        {
            if (visibilityContext != null && enumerableContext != null)
            {
                foreach (object item in enumerableContext.Items)
                    visibilityContext.SetVisible(item, true);

                Refresh();
            }
        }
示例#13
0
        private void IsolateSelection(IEnumerable <object> selection, IVisibilityContext visibilityContext, IEnumerableContext enumerableContext)
        {
            if (selection != null && visibilityContext != null && enumerableContext != null)
            {
                foreach (object item in enumerableContext.Items)
                {
                    visibilityContext.SetVisible(item, false);
                }

                foreach (Path <object> path in selection)
                {
                    foreach (object item in path)
                    {
                        visibilityContext.SetVisible(item, true);
                    }

                    DomNode lastNode = path.Last.As <DomNode>();
                    SetVisibility(lastNode, true, visibilityContext);
                }

                Refresh();
            }
        }
示例#14
0
        private void IsolateSelection(IEnumerable<object> selection, IVisibilityContext visibilityContext, IEnumerableContext enumerableContext)
        {
            if (selection != null && visibilityContext != null && enumerableContext != null)
            {
                foreach (object item in enumerableContext.Items)
                    visibilityContext.SetVisible(item, false);

                foreach (Path<object> path in selection)
                {
                    foreach (object item in path)
                    {
                        visibilityContext.SetVisible(item, true);                        
                    }

                    DomNode lastNode = path.Last.As<DomNode>();
                    SetVisibility(lastNode, true, visibilityContext);
                }
                    
                Refresh();
            }
        }
        /// <summary>
        /// Inverts the selection in the given context (deselect all selected, and select all deselected objects)</summary>
        /// <param name="selectionContext">Context holding selection</param>
        /// <param name="enumerableContext">Context holding enumeration of selectable objects</param>
        /// <returns>True iff selection was inverted</returns>
        public bool InvertSelection(ISelectionContext selectionContext, IEnumerableContext enumerableContext)
        {
            if (selectionContext != null &&
                enumerableContext != null)
            {
                HashSet<object> selected = new HashSet<object>(selectionContext.Selection);
                List<object> inverted = new List<object>(enumerableContext.Items);
                for (int i = 0; i < inverted.Count; )
                {
                    if (selected.Contains(inverted[i]))
                        inverted.RemoveAt(i);
                    else
                        i++;
                }

                selectionContext.SetRange(inverted);
            }

            return false;
        }
示例#16
0
 /// <summary>
 ///     Returns a Slinq that enumerates over the specified enumerable.
 ///     The returned Slinq will be backed by an IEnumerator
 ///     <T>
 ///         , and thus will allocate an object or box.
 ///         Slinqs created by this method do not support element removal.
 /// </summary>
 public static Slinq <T, IEnumerableContext <T> > Slinq <T>(this IEnumerable <T> enumerable)
 {
     return(IEnumerableContext <T> .Slinq(enumerable));
 }
示例#17
0
        private void IsolateSelection(IEnumerable <object> selection, IVisibilityContext visibilityContext, IEnumerableContext enumerableContext)
        {
            if (selection != null && visibilityContext != null && enumerableContext != null)
            {
                foreach (object item in enumerableContext.Items)
                {
                    visibilityContext.SetVisible(item, false);
                }

                foreach (object item in selection)
                {
                    visibilityContext.SetVisible(item, true);
                }

                Refresh();
            }
        }