public CommandHistoryEventListener( CommandHistory history )
        {
            m_executedCallCount = 0;
            m_undoneCallCount = 0;
            m_redoneCallCount = 0;
            m_changedCallCount = 0;
            m_clearedCallCount = 0;

            history.ActionExecuted += new EventHandler<CommandEventArgs>( history_ActionExecuted );
            history.ActionUndone += new EventHandler<CommandEventArgs>( history_ActionUndone );
            history.ActionRedone += new EventHandler<CommandEventArgs>( history_ActionRedone );
            history.Changed += new EventHandler( history_Changed );
            history.Cleared += new EventHandler( history_Cleared );
        }
Esempio n. 2
0
        /// <summary>
        /// Make sure CommandHistory added as a service to given site.
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <remarks>You have to make sure added IServiceContainer to this
        /// serviceProvider.</remarks>
        public static CommandHistory EnsureHasService(IServiceProvider serviceProvider = null)
        {
            CommandHistory result = null;
            IServiceProvider sp = serviceProvider;
            if (sp != null)
            {
                // Add this CommandHistory service if given service
                // doesn't contains it.
                result = sp.GetService(typeof(CommandHistory)) as CommandHistory;
                if (result == null)
                {
                    // If there are no service, added new instance.
                    IServiceContainer s = sp.GetService(typeof(IServiceContainer))
                        as IServiceContainer;

                    if (s == null)
                    {
                        throw new InvalidOperationException("empty service container");
                    }

                    result = new CommandHistory();
                    s.AddService(typeof(CommandHistory), result);
                }
            }
            else
            {
                // If they don't have ISite, returns static instance.
                if (staticCommandHistory == null)
                    staticCommandHistory = new CommandHistory();

                result = staticCommandHistory;
            }

            return result;
        }