public static void SubscribeToHistoryEvents(IExecutableItem toolBarItem,
                                                    Func <IUndoRedoManager, IObservableCollection <IUndoableAction> > stackCallback)
        {
            NotifyCollectionChangedEventHandler handler = (sender, e) => toolBarItem.RaiseCanExecuteChanged();

            var shell = IoC.Get <IShell>();

            shell.ActiveDocumentChanging += (sender, e) =>
            {
                if (shell.ActiveItem != null)
                {
                    stackCallback(shell.ActiveItem.UndoRedoManager).CollectionChanged -= handler;
                }
            };
            shell.ActiveDocumentChanged += (sender, e) =>
            {
                if (shell.ActiveItem != null)
                {
                    stackCallback(shell.ActiveItem.UndoRedoManager).CollectionChanged += handler;
                }
                toolBarItem.RaiseCanExecuteChanged();
            };

            if (shell.ActiveItem != null)
            {
                stackCallback(shell.ActiveItem.UndoRedoManager).CollectionChanged += handler;
            }
        }
예제 #2
0
        public static void SubscribeToHistoryEvents(IExecutableItem toolBarItem,
            Func<IUndoRedoManager, IObservableCollection<IUndoableAction>> stackCallback)
        {
            NotifyCollectionChangedEventHandler handler = (sender, e) => toolBarItem.RaiseCanExecuteChanged();

            var shell = IoC.Get<IShell>();
            shell.ActiveDocumentChanging += (sender, e) =>
            {
                if (shell.ActiveItem != null)
                    stackCallback(shell.ActiveItem.UndoRedoManager).CollectionChanged -= handler;
            };
            shell.ActiveDocumentChanged += (sender, e) =>
            {
                if (shell.ActiveItem != null)
                    stackCallback(shell.ActiveItem.UndoRedoManager).CollectionChanged += handler;
                toolBarItem.RaiseCanExecuteChanged();
            };

            if (shell.ActiveItem != null)
                stackCallback(shell.ActiveItem.UndoRedoManager).CollectionChanged += handler;
        }