//private void ActiveAwareIsActiveChanged(object sender, EventArgs e)
        //{
        //    IActiveAware activeAware = (sender as IActiveAware);
        //    if (activeAware == null) { return; }
        //    CommandFindNextDescription.IsActive = activeAware.IsActive;
        //    CommandFindPrevDescription.IsActive = activeAware.IsActive;
        //}

        #region Events



        private bool checkTreeNodeFragmentRemoval(bool done, TreeNode node)
        {
            if (node.HasXmlProperty &&
                node.GetXmlElementLocalName().Equals("img", StringComparison.OrdinalIgnoreCase))
            {
                if (done)
                {
                    DescriptionsNavigator.RemoveDescribableTreeNode(node);
                }
                else
                {
                    DescriptionsNavigator.AddDescribableTreeNode(node);
                }
                RaisePropertyChanged(() => HasNotDescribableTreeNodes);

                return(true); // break
            }
            foreach (var child in node.Children.ContentsAs_Enumerable)
            {
                if (checkTreeNodeFragmentRemoval(done, child))
                {
                    return(true);
                }
            }
            return(false);
        }
        private void onDescribableTreeNodeFoundByFlowDocumentParser(TreeNode data)
        {
            if (!TheDispatcher.CheckAccess())
            {
#if DEBUG
                Debugger.Break();
#endif
                TheDispatcher.Invoke(DispatcherPriority.Normal, (Action <TreeNode>)onDescribableTreeNodeFoundByFlowDocumentParser, data);
                return;
            }
            DescriptionsNavigator.AddDescribableTreeNode(data);

            RaisePropertyChanged(() => HasNotDescribableTreeNodes);
        }
        private void onProjectLoaded(Project project)
        {
            if (m_UrakawaSession.IsXukSpine)
            {
                return;
            }

            m_UndoRedoManagerHooker = project.Presentations.Get(0).UndoRedoManager.Hook(this);

            DescriptionsNavigator = new DescriptionsNavigator(View);
            View.LoadProject();

            RaisePropertyChanged(() => SelectedTreeNode);
        }
        public DescriptionsNavigationViewModel(
            IEventAggregator eventAggregator,
            ILoggerFacade logger,
            [Import(typeof(IShellView), RequiredCreationPolicy = CreationPolicy.Shared, AllowDefault = false)]
            IShellView view,
            [Import(typeof(IUrakawaSession), RequiredCreationPolicy = CreationPolicy.Shared, AllowDefault = false)]
            IUrakawaSession urakawaSession)
        {
            m_EventAggregator = eventAggregator;
            m_Logger          = logger;
            m_UrakawaSession  = urakawaSession;
            m_ShellView       = view;


            m_Logger.Log("DescriptionsNavigationViewModel.initializeCommands", Category.Debug, Priority.Medium);

            CommandFindFocusDescriptions = new RichDelegateCommand(
                @"DESCRIPTIONS CommandFindFocus DUMMY TXT",
                @"DESCRIPTIONS CommandFindFocus DUMMY TXT",
                null, // KeyGesture set only for the top-level CompositeCommand
                null,
                () =>
            {
                m_ShellView.RaiseEscapeEvent();

                if (View != null)
                {
                    IsSearchVisible = true;
                    FocusHelper.Focus(View.SearchBox);
                    View.SearchBox.SelectAll();
                }
            },
                () => View != null
                //&& View.SearchBox.Visibility == Visibility.Visible
                && View.SearchBox.IsEnabled,
                null, //Settings_KeyGestures.Default,
                null  //PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Nav_TOCFindNext)
                );

            CommandFindNextDescription = new RichDelegateCommand(
                @"DESCRIPTIONS CommandFindNext DUMMY TXT",
                @"DESCRIPTIONS CommandFindNext DUMMY TXT",
                null, // KeyGesture set only for the top-level CompositeCommand
                null, () =>
            {
                m_ShellView.RaiseEscapeEvent();

                DescriptionsNavigator.FindNext(true);
            },
                () => DescriptionsNavigator != null && !string.IsNullOrEmpty(DescriptionsNavigator.SearchTerm),
                null, //Settings_KeyGestures.Default,
                null  //PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Nav_DescriptionsFindNext)
                );

            CommandFindPrevDescription = new RichDelegateCommand(
                @"DESCRIPTIONS CommandFindPrevious DUMMY TXT",
                @"DESCRIPTIONS CommandFindPrevious DUMMY TXT",
                null, // KeyGesture set only for the top-level CompositeCommand
                null, () =>
            {
                m_ShellView.RaiseEscapeEvent();

                DescriptionsNavigator.FindPrevious(true);
            },
                () => DescriptionsNavigator != null && !string.IsNullOrEmpty(DescriptionsNavigator.SearchTerm),
                null, //Settings_KeyGestures.Default,
                null  //PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Nav_DescFindPrev)
                );

            m_EventAggregator.GetEvent <ProjectLoadedEvent>().Subscribe(onProjectLoaded, ProjectLoadedEvent.THREAD_OPTION);
            m_EventAggregator.GetEvent <ProjectUnLoadedEvent>().Subscribe(onProjectUnLoaded, ProjectUnLoadedEvent.THREAD_OPTION);

            m_EventAggregator.GetEvent <DescribableTreeNodeFoundByFlowDocumentParserEvent>().Subscribe(onDescribableTreeNodeFoundByFlowDocumentParser, DescribableTreeNodeFoundByFlowDocumentParserEvent.THREAD_OPTION);

            m_EventAggregator.GetEvent <TreeNodeSelectionChangedEvent>().Subscribe(OnTreeNodeSelectionChanged, TreeNodeSelectionChangedEvent.THREAD_OPTION);
        }