private void onProjectUnLoaded(Project project)
        {
            if (m_UndoRedoManagerHooker != null)
            {
                m_UndoRedoManagerHooker.UnHook();
            }
            m_UndoRedoManagerHooker = null;

            PagesNavigator = null;
            View.UnloadProject();
        }
        private void onProjectLoaded(Project project)
        {
            if (m_session.IsXukSpine)
            {
                return;
            }

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

            PagesNavigator = new PagesNavigator(View);

            View.LoadProject();
        }
        private void onPageFoundByFlowDocumentParser(TreeNode treeNode)
        {
            if (!TheDispatcher.CheckAccess())
            {
#if DEBUG
                Debugger.Break();
#endif
                TheDispatcher.Invoke(DispatcherPriority.Normal, (Action <TreeNode>)onPageFoundByFlowDocumentParser, treeNode);
                return;
            }
            PagesNavigator.AddPage(treeNode);

            RaisePropertyChanged(() => HasNotPages);
        }
        public PagesPaneViewModel(
            IEventAggregator eventAggregator,
            ILoggerFacade logger,
            [Import(typeof(IShellView), RequiredCreationPolicy = CreationPolicy.Shared, AllowDefault = false)]
            IShellView view,
            [Import(typeof(IUrakawaSession), RequiredCreationPolicy = CreationPolicy.Shared, AllowDefault = false)]
            IUrakawaSession session)
        {
            m_EventAggregator = eventAggregator;
            m_Logger          = logger;

            m_ShellView = view;
            m_session   = session;

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

            CommandRenumberPages = new RichDelegateCommand(
                Tobi_Plugin_NavigationPane_Lang.CmdNavigationRenumberPages_ShortDesc,
                Tobi_Plugin_NavigationPane_Lang.CmdNavigationRenumberPages_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                null, //m_ShellView.LoadTangoIcon("bookmark-new"),
                () =>
            {
                if (PagesNavigator_Pages.Count <= 0)
                {
                    return;
                }

                var textBox_pageNumberStringPrefix = new TextBox()
                {
                    Text = ""
                };

                var label_pageNumberStringPrefix = new TextBlock()
                {
                    Text   = Tobi_Plugin_NavigationPane_Lang.PageNumberPrefix + ": ",
                    Margin = new Thickness(8, 0, 8, 0),
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Focusable           = true,
                    TextWrapping        = TextWrapping.Wrap
                };

                var panel_pageNumberStringPrefix = new DockPanel()
                {
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Margin = new Thickness(0, 0, 0, 18)
                };
                label_pageNumberStringPrefix.SetValue(DockPanel.DockProperty, Dock.Left);
                panel_pageNumberStringPrefix.Children.Add(label_pageNumberStringPrefix);
                panel_pageNumberStringPrefix.Children.Add(textBox_pageNumberStringPrefix);

                var textBox_pageNumberIntegerStart = new TextBox()
                {
                    Text = "1"
                };

                var label_pageNumberIntegerStart = new TextBlock()
                {
                    Text   = Tobi_Plugin_NavigationPane_Lang.PageNumberStart + ": ",
                    Margin = new Thickness(8, 0, 8, 0),
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Focusable           = true,
                    TextWrapping        = TextWrapping.Wrap
                };

                var panel_pageNumberIntegerStart = new DockPanel()
                {
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Margin = new Thickness(0, 0, 0, 0)
                };
                label_pageNumberIntegerStart.SetValue(DockPanel.DockProperty, Dock.Left);
                panel_pageNumberIntegerStart.Children.Add(label_pageNumberIntegerStart);
                panel_pageNumberIntegerStart.Children.Add(textBox_pageNumberIntegerStart);



                var panel = new StackPanel
                {
                    Orientation         = Orientation.Vertical,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment   = VerticalAlignment.Center,
                };

                panel.Children.Add(panel_pageNumberStringPrefix);
                panel.Children.Add(panel_pageNumberIntegerStart);

                var windowPopup = new PopupModalWindow(m_ShellView,
                                                       UserInterfaceStrings.EscapeMnemonic(Tobi_Plugin_NavigationPane_Lang.CmdNavigationRenumberPages_ShortDesc),
                                                       panel,
                                                       PopupModalWindow.DialogButtonsSet.OkCancel,
                                                       PopupModalWindow.DialogButton.Ok,
                                                       false, 250, 160, null, 40, null);
                windowPopup.ShowModal();

                if (windowPopup.ClickedDialogButton != PopupModalWindow.DialogButton.Ok)
                {
                    return;
                }


                string prefix = "";
                if (!String.IsNullOrEmpty(textBox_pageNumberStringPrefix.Text))
                {
                    prefix = textBox_pageNumberStringPrefix.Text;
                }

                int pageNumber = 1;
                if (!String.IsNullOrEmpty(textBox_pageNumberIntegerStart.Text))
                {
                    try
                    {
                        pageNumber = Int32.Parse(textBox_pageNumberIntegerStart.Text);
                    }
                    catch (Exception ex)
                    {
                        return;
                    }
                }



                var treeNodes = new List <TreeNode>(PagesNavigator_Pages.Count);
                foreach (Page marked in PagesNavigator_Pages)
                {
                    treeNodes.Add(marked.TreeNode);
                }

                string pageNumberStr = "";

                m_session.DocumentProject.Presentations.Get(0).UndoRedoManager.StartTransaction(Tobi_Plugin_NavigationPane_Lang.CmdNavigationRenumberPages_ShortDesc, Tobi_Plugin_NavigationPane_Lang.CmdNavigationRenumberPages_LongDesc, "PAGE_BREAKS_RENUMBER");
                foreach (TreeNode treeNode in treeNodes)
                {
                    pageNumberStr = prefix + (pageNumber++);
                    var cmd       = treeNode.Presentation.CommandFactory.CreateTreeNodeChangeTextCommand(treeNode, pageNumberStr);
                    treeNode.Presentation.UndoRedoManager.Execute(cmd);
                }
                m_session.DocumentProject.Presentations.Get(0).UndoRedoManager.EndTransaction();
            },
                () => m_session.DocumentProject != null && !m_session.isAudioRecording &&
                !m_session.IsXukSpine, //SelectedTreeNode != null, //!m_UrakawaSession.IsSplitMaster &&
                Settings_KeyGestures.Default,
                null)                  //PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_RemoveAllDocMarks)
            ;

            m_ShellView.RegisterRichCommand(CommandRenumberPages);

            CommandFindFocusPage = new RichDelegateCommand(
                @"PAGES CommandFindFocus DUMMY TXT",
                @"PAGES 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)
                );

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

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

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

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

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

            m_EventAggregator.GetEvent <PageFoundByFlowDocumentParserEvent>().Subscribe(onPageFoundByFlowDocumentParser, PageFoundByFlowDocumentParserEvent.THREAD_OPTION);

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