コード例 #1
0
        internal static int GetSimpleWordCountByMetadata(HArticle ao)
        {
            var dict = StatisticsWindow.core.mainWndRef.RTBPageCacheDict;

            if (dict.ContainsKey(ao.Id))
            {
                return(StatisticsWindow.GetSimpleWordCount(dict[ao.Id].GetText()));
            }
            else
            {
                RTBPage np = new RTBPage()
                {
                    ArticalRef = ao
                };
                TextRange t = new TextRange(np.RichTextBox_TextArea.Document.ContentStart, np.RichTextBox_TextArea.Document.ContentEnd);
                t.Load(ao.DocumentMetadata, DataFormats.XamlPackage);
                np.UpdateRTBStyle();
                dict[ao.Id] = np;
                return(StatisticsWindow.GetSimpleWordCount(np.GetText()));
            }
        }
コード例 #2
0
 /// <summary>
 /// 工程树:选择项改变
 /// </summary>
 private void TreeView_ProjectTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
 {
     try
     {
         // 保存更改
         if (this.CurrentActivePage != null)
         {
             this.CurrentBookId = this.CurrentActivePage.ArticalRef.BookId;
             this.core.PageCommit();
         }
         // 分析Tag
         var selectedTag = (this.TreeView_ProjectTree.SelectedItem as TreeViewItem)?.Tag;
         if (selectedTag == null)
         {
             return;
         }
         if (selectedTag.ToString() == "HemeIndexPage")
         {
             this.CurrentActivePage        = null;
             this.Grid_MainArea.Background = this.IndexBackgroundBrush;
             this.Frame_RTB.NavigationService.Navigate(this.IndexPageRef);
             this.StackPanel_Commands.Visibility  = this.TextBlock_CurrentChapterName.Visibility =
                 this.TextBlock_MsgBar.Visibility = this.TextBlock_StateBar.Visibility = Visibility.Hidden;
             return;
         }
         else
         {
             this.StackPanel_Commands.Visibility    = this.TextBlock_CurrentChapterName.Visibility =
                 this.TextBlock_MsgBar.Visibility   = this.TextBlock_StateBar.Visibility = Visibility.Visible;
             this.Grid_MainArea.Background          = this.MainAreaBrush;
             this.TextBlock_CurrentChapterName.Text = (this.TreeView_ProjectTree.SelectedItem as TreeViewItem).Header.ToString();
         }
         var sType = selectedTag.ToString().Split('#');
         // 书籍
         if (sType[0] == "HBook")
         {
             var hb = this.core.BookVector.Find(b => b.BookRef.Id == $"HBook#{sType[1]}");
             if (hb != null)
             {
                 var hp = hb.BookRef.HomePage;
                 if (this.RTBPageCacheDict.ContainsKey(hp.Id))
                 {
                     this.CurrentActivePage = this.RTBPageCacheDict[hp.Id];
                 }
                 else
                 {
                     RTBPage np = new RTBPage()
                     {
                         ArticalRef = hp
                     };
                     this.CurrentActivePage = np;
                     this.RTBPageCacheDict.Add(hp.Id, np);
                 }
                 TextRange t = new TextRange(this.CurrentActivePage.RichTextBox_TextArea.Document.ContentStart,
                                             this.CurrentActivePage.RichTextBox_TextArea.Document.ContentEnd);
                 t.Load(hp.DocumentMetadata, DataFormats.XamlPackage);
                 this.CurrentActivePage.UpdateRTBStyle();
                 this.Frame_RTB.NavigationService.Navigate(this.CurrentActivePage);
             }
             this.CurrentBookId = selectedTag.ToString();
         }
         // 文章
         else
         {
             var pid = $"HArticle#{sType[1]}";
             var p   = this.core.ArticleDict[pid];
             this.CurrentBookId = p.BookId;
             if (this.RTBPageCacheDict.ContainsKey(pid))
             {
                 this.CurrentActivePage = this.RTBPageCacheDict[pid];
             }
             else
             {
                 RTBPage np = new RTBPage()
                 {
                     ArticalRef = p
                 };
                 this.CurrentActivePage = np;
                 this.RTBPageCacheDict.Add(pid, np);
             }
             TextRange t = new TextRange(this.CurrentActivePage.RichTextBox_TextArea.Document.ContentStart,
                                         this.CurrentActivePage.RichTextBox_TextArea.Document.ContentEnd);
             t.Load(p.DocumentMetadata, DataFormats.XamlPackage);
             this.CurrentActivePage.UpdateRTBStyle();
             this.Frame_RTB.NavigationService.Navigate(this.CurrentActivePage);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("An error was occured when toggle page." + Environment.NewLine + ex);
     }
 }