Pārlūkot izejas kodu

书签,优化

OYXH\oyxh 2 gadi atpakaļ
vecāks
revīzija
c0ceab09a9

+ 51 - 47
PDF Office/ViewModels/BOTA/BookmarkContentViewModel.cs

@@ -11,6 +11,7 @@ using Prism.Mvvm;
 using Prism.Regions;
 using Prism.Services.Dialogs;
 using System;
+using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Linq;
 using System.Reflection;
@@ -35,17 +36,13 @@ namespace PDF_Office.ViewModels.BOTA
     {
         #region 属性
 
-        private static string hoverColor = "#D9D9D9";
-        private static string defaultColor = "#F2F2F2";
-        private static string selectColcr = "#97D7FB";
-        private static string borderBackground = "#FFFFFF";
-        private static string borderBrush = "#000000";
-
-        private bool isSelete = false;
         private IRegionManager region;
         private IDialogService dialogs;
         public CPDFViewer PDFViewer;
 
+        /// <summary>
+        /// 书签ItemSouce
+        /// </summary>
         private ObservableCollection<CPDFBookmark> bookmarklist;
 
         public ObservableCollection<CPDFBookmark> Bookmarklist
@@ -60,6 +57,9 @@ namespace PDF_Office.ViewModels.BOTA
             }
         }
 
+        /// <summary>
+        /// 书签列表为空时,显示状态
+        /// </summary>
         private Visibility isEmpty;
 
         public Visibility IsEmptyPanelVisibility
@@ -109,8 +109,25 @@ namespace PDF_Office.ViewModels.BOTA
             KeyDownCommand = new DelegateCommand<object>(KeyDownEvent);
         }
 
+        /// <summary>
+        /// 检测ObservableCollection的数据变更
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void Bookmarklist_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
         {
+            ObservableCollection<CPDFBookmark> obsSender = sender as ObservableCollection<CPDFBookmark>;
+            if (obsSender != null)
+            {
+                if (obsSender.Count < 1)
+                {
+                    IsEmptyPanelVisibility = Visibility.Visible;
+                }
+                else
+                {
+                    IsEmptyPanelVisibility = Visibility.Collapsed;
+                }
+            }
         }
 
         /// <summary>
@@ -163,7 +180,6 @@ namespace PDF_Office.ViewModels.BOTA
                         {
                             PDFViewer.UndoManager.CanSave = true;
                             Bookmarklist.Add(bookmark);
-                            //Bookmarklist = new ObservableCollection<CPDFBookmark>(PDFViewer.Document.GetBookmarkList().OrderBy(d => d.Title));
                         }
                     }
                 }
@@ -182,33 +198,29 @@ namespace PDF_Office.ViewModels.BOTA
                 if (RemoveBookMark(bookmark))
                 {
                     Bookmarklist.Remove(bookmark);
-                    Bookmarklist.CollectionChanged += Bookmarklist_CollectionChanged;
                 }
             }
         }
 
-        private void RenameEvent(object obj)
-        {
-            CPDFBookmark bookmark = obj as CPDFBookmark;
-            if (bookmark != null)
-            {
-                //var result = PDFViewer.Document.EditBookmark(bookmark.PageIndex, textBox.Text.Trim());
-                //if (result)
-                //{
-                //    bookmark.Title = textBox.Text.Trim();
-                //    PDFViewer.UndoManager.CanSave = true;
-                //}
-            }
-        }
-
+        /// <summary>
+        /// 删除书签
+        /// </summary>
+        /// <param name="item"></param>
+        /// <returns></returns>
         private bool RemoveBookMark(CPDFBookmark item)
         {
             var data = item;
             if (data == null)
+            {
                 return false;
+            }
             return PDFViewer.Document.RemoveBookmark(data.PageIndex);
         }
 
+        /// <summary>
+        /// ListViewItem失去焦点
+        /// </summary>
+        /// <param name="obj"></param>
         private void LostFocusEvent(object obj)
         {
             TextBox textBox = null;
@@ -219,8 +231,6 @@ namespace PDF_Office.ViewModels.BOTA
                 if (parameter.Parameter is TextBox)
                 {
                     textBox = (TextBox)parameter.Parameter;
-                    //textBox.PreviewMouseDown += new MouseButtonEventHandler(TxtTitleInput_PreviewMouseLeftButtonDown);
-
                     listViewItem = CommonHelper.FindVisualParent<ListViewItem>(textBox);
                 }
             }
@@ -232,13 +242,20 @@ namespace PDF_Office.ViewModels.BOTA
             UpdateTitle(listViewItem, textBox);
         }
 
+        /// <summary>
+        /// 修改书签标题
+        /// </summary>
+        /// <param name="listViewItem"></param>
+        /// <param name="textBox"></param>
         private void UpdateTitle(ListViewItem listViewItem, TextBox textBox)
         {
             if (listViewItem != null)
             {
                 var data = listViewItem.DataContext as CPDFBookmark;
                 if (data == null)
+                {
                     return;
+                }
                 var result = PDFViewer.Document.EditBookmark(data.PageIndex, textBox.Text.Trim());
                 if (result)
                 {
@@ -248,32 +265,29 @@ namespace PDF_Office.ViewModels.BOTA
             }
         }
 
-        private void TxtTitleInput_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
-        {
-            TextBox textBox = sender as TextBox;
-            textBox.Focus();
-            e.Handled = true;
-        }
-
+        /// <summary>
+        /// ListBoxItem左键单击,页面跳转
+        /// </summary>
+        /// <param name="obj"></param>
         private void ListViewItemMouseLeftButtonDownEvent(object obj)
         {
             ListBoxItem listBoxItem = (obj as ListBoxItem);
 
             if (listBoxItem != null)
             {
-                //box.Background = listBoxItem.Background;
-                //box.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(selectColcr));
                 if (!(listBoxItem.DataContext is CPDFBookmark))
                 {
                     return;
                 }
                 int index = (listBoxItem.DataContext as CPDFBookmark).PageIndex;
                 PDFViewer.GoToPage(index);
-                isSelete = false;
             }
-            //MessageBox.Show("dsafa");
         }
 
+        /// <summary>
+        /// 添加书签
+        /// </summary>
+        /// <param name="obj"></param>
         private void AddBookmarkEvent(object obj)
         {
             int index = PDFViewer.CurrentIndex;
@@ -286,23 +300,13 @@ namespace PDF_Office.ViewModels.BOTA
                 System.Windows.Controls.ListView listView = obj as System.Windows.Controls.ListView;
                 if (listView != null)
                 {
-                    //listView.Items.CurrentItem = list[0];
                     ListBoxItem myListBoxItem = (ListBoxItem)(listView.ItemContainerGenerator.ContainerFromItem(list[0]));
 
-                    //ContentPresenter myContentPresenter = CommonHelper.FindVisualChild<ContentPresenter>(myListBoxItem);
-                    //DataTemplate myDataTemplate = myContentPresenter.ContentTemplate;
-                    //Grid item = (Grid)myDataTemplate.FindName("Grid", myContentPresenter);
-
-                    //Grid grid = CommonHelper.FindVisualChild<Grid>(myListBoxItem);
                     if (myListBoxItem.IsSelected == false)
                     {
                         myListBoxItem.IsSelected = true;
                         myListBoxItem.Focus();
                     }
-
-                    //listView.SelectedItem = myListBoxItem;
-
-                    //myListBoxItem.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(selectColcr));
                     return;
                 }
             }
@@ -326,7 +330,6 @@ namespace PDF_Office.ViewModels.BOTA
                             PDFViewer.UndoManager.CanSave = true;
 
                             Bookmarklist.Add(bookmark);
-                            // Bookmarklist = new ObservableCollection<CPDFBookmark>(PDFViewer.Document.GetBookmarkList().OrderBy(d => d.Title));
                         }
                     }
                 }
@@ -338,6 +341,7 @@ namespace PDF_Office.ViewModels.BOTA
             navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
             if (PDFViewer == null)
             {
+                IsEmptyPanelVisibility = Visibility.Visible;
                 return;
             }
 

+ 0 - 16
PDF Office/Views/BOTA/BookmarkContent.xaml

@@ -139,22 +139,6 @@
                         <Setter Property="ContextMenu" Value="{StaticResource ContextMenu}" />
                     </Style>
                 </ListView.ItemContainerStyle>
-                <!--<ListView.ContextMenu>
-                <ContextMenu Width="200" Name="ContextMenu">
-                <MenuItem
-                Click="MenuItemRename_Click"
-                CommandParameter="{Binding PlacementTarget.SelectedItem, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
-                Header="重命名" />
-                <MenuItem
-                Command="{Binding EditPageIndexCommand}"
-                CommandParameter="{Binding PlacementTarget.SelectedItem, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
-                Header="更改目标位置" />
-                <MenuItem
-                Command="{Binding DeleteCommand}"
-                CommandParameter="{Binding PlacementTarget.SelectedItem, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
-                Header="删除" />
-                </ContextMenu>
-                </ListView.ContextMenu>-->
             </ListView>
         </Grid>
         <StackPanel

+ 35 - 4
PDF Office/Views/BOTA/BookmarkContent.xaml.cs

@@ -24,6 +24,10 @@ namespace PDF_Office.Views.BOTA
     public partial class BookmarkContent : UserControl
     {
         private BookmarkContentViewModel viewModel = null;
+
+        /// <summary>
+        /// 上一个ListBoxItem,为选中状态做准备
+        /// </summary>
         private ListBoxItem histotyListBoxItem = null;
 
         public BookmarkContent()
@@ -32,6 +36,11 @@ namespace PDF_Office.Views.BOTA
             viewModel = this.DataContext as BookmarkContentViewModel;
         }
 
+        /// <summary>
+        ///ListViewItem,鼠标左键点击
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void ListViewItem_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
         {
             object[] objects = new object[] { sender, e };
@@ -72,6 +81,12 @@ namespace PDF_Office.Views.BOTA
             }
         }
 
+        /// <summary>
+        /// ListViewItem双击时选中状态
+        /// </summary>
+        /// <param name="listBoxItem"></param>
+        /// <param name="textBox"></param>
+        /// <param name="textBlock"></param>
         private void SetSelectedStatus(ListBoxItem listBoxItem, TextBox textBox, TextBlock textBlock)
         {
             listBoxItem.IsSelected = true;
@@ -85,6 +100,11 @@ namespace PDF_Office.Views.BOTA
             }));
         }
 
+        /// <summary>
+        /// ListViewItem失去焦点
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void ListViewItem_LostFocus(object sender, RoutedEventArgs e)
         {
             ListBoxItem listItem = sender as ListBoxItem;
@@ -103,6 +123,11 @@ namespace PDF_Office.Views.BOTA
             }
         }
 
+        /// <summary>
+        /// 右键菜单-重命名
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void MenuItemRename_Click(object sender, RoutedEventArgs e)
         {
             if (sender is MenuItem)
@@ -121,10 +146,11 @@ namespace PDF_Office.Views.BOTA
             }
         }
 
-        private void ListViewItem_KeyDown(object sender, KeyEventArgs e)
-        {
-        }
-
+        /// <summary>
+        /// BookMarkListView,鼠标点击
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void BookMarkListView_PreviewMouseDown(object sender, MouseButtonEventArgs e)
         {
             if (e.LeftButton == MouseButtonState.Pressed)
@@ -168,6 +194,11 @@ namespace PDF_Office.Views.BOTA
             }
         }
 
+        /// <summary>
+        /// 右键菜单-删除
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void MenuItemDeleteCommand_Click(object sender, RoutedEventArgs e)
         {
             List<int> pagelist = new List<int>();