OYXH\oyxh 2 роки тому
батько
коміт
80cde84ff6

+ 13 - 5
PDF Office/Styles/ListViewStyle.xaml

@@ -367,14 +367,22 @@
                             <Setter TargetName="Bd" Property="Panel.Background" Value="#d9d9d9" />
                             <Setter TargetName="Bd" Property="Border.BorderBrush" Value="#d9d9d9" />
                         </MultiTrigger>
+                        <MultiTrigger>
+                            <MultiTrigger.Conditions>
+                                <Condition Property="UIElement.IsMouseOver" Value="False" />
+                            </MultiTrigger.Conditions>
+                            <Setter TargetName="Bd" Property="Panel.Background" Value="#F2F2F2" />
+                            <Setter TargetName="Bd" Property="Border.BorderBrush" Value="#F2F2F2" />
+                        </MultiTrigger>
                         <MultiTrigger>
                             <MultiTrigger.Conditions>
                                 <Condition Property="Selector.IsSelectionActive" Value="False" />
                                 <Condition Property="Selector.IsSelected" Value="True" />
                             </MultiTrigger.Conditions>
-                            <Setter TargetName="Bd" Property="Panel.Background" Value="#97D7FB" />
-                            <Setter TargetName="Bd" Property="Border.BorderBrush" Value="#97D7FB" />
+                            <Setter TargetName="Bd" Property="Panel.Background" Value="#d9d9d9" />
+                            <Setter TargetName="Bd" Property="Border.BorderBrush" Value="#d9d9d9" />
                         </MultiTrigger>
+
                         <MultiTrigger>
                             <MultiTrigger.Conditions>
                                 <Condition Property="Selector.IsSelectionActive" Value="True" />
@@ -383,9 +391,9 @@
                             <Setter TargetName="Bd" Property="Panel.Background" Value="#97D7FB" />
                             <Setter TargetName="Bd" Property="Border.BorderBrush" Value="#97D7FB" />
                         </MultiTrigger>
-                        <Trigger Property="UIElement.IsEnabled" Value="False">
-                            <Setter TargetName="Bd" Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
-                        </Trigger>
+                        <!--<Trigger Property="UIElement.IsEnabled" Value="False">
+                        <Setter TargetName="Bd" Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
+                        </Trigger>-->
                     </ControlTemplate.Triggers>
                 </ControlTemplate>
             </Setter.Value>

+ 85 - 125
PDF Office/ViewModels/BOTA/BookmarkContentViewModel.cs

@@ -2,6 +2,7 @@
 using ComPDFKitViewer.PdfViewer;
 using ImTools;
 using Microsoft.Office.Interop.Word;
+using PDF_Office.CustomControl;
 using PDF_Office.Helper;
 using PDF_Office.Model;
 using PDF_Office.Model.PageEdit;
@@ -15,6 +16,7 @@ using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls.Primitives;
+using System.Windows.Forms;
 using System.Windows.Input;
 using System.Windows.Media;
 using static Dropbox.Api.TeamLog.AdminAlertSeverityEnum;
@@ -33,6 +35,8 @@ namespace PDF_Office.ViewModels.BOTA
         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;
@@ -80,7 +84,11 @@ namespace PDF_Office.ViewModels.BOTA
         public DelegateCommand<object> AddBookmarkCommand { get; set; }
 
         public DelegateCommand<object> ListViewItemMouseDownCommand { get; set; }
-        public DelegateCommand TextBoxMouseDownCommand { get; set; }
+        public DelegateCommand<object> RenameCommand { get; set; }
+
+        public DelegateCommand<object> EditPageIndexCommand { get; set; }
+
+        public DelegateCommand<object> DeleteCommand { get; set; }
 
         #endregion 命令
 
@@ -96,6 +104,27 @@ namespace PDF_Office.ViewModels.BOTA
             GotFocusCommand = new DelegateCommand<object>(GotFocusEvent);
             AddBookmarkCommand = new DelegateCommand<object>(AddBookmarkEvent);
             ListViewItemMouseDownCommand = new DelegateCommand<object>(ListViewItemMouseLeftButtonDownEvent);
+            RenameCommand = new DelegateCommand<object>(RenameEvent);
+            DeleteCommand = new DelegateCommand<object>(DelegateEvent);
+            EditPageIndexCommand = new DelegateCommand<object>(EditPageIndexEvent);
+        }
+
+        private void EditPageIndexEvent(object obj)
+        {
+            throw new NotImplementedException();
+        }
+
+        private void DelegateEvent(object obj)
+        {
+        }
+
+        private void RenameEvent(object obj)
+        {
+            CPDFBookmark bookmark = obj as CPDFBookmark;
+            if (bookmark != null)
+            {
+                //ListBoxItem myListBoxItem = (ListBoxItem)(myListBox.ItemContainerGenerator.ContainerFromItem(myListBox.Items.CurrentItem));
+            }
         }
 
         private void GotFocusEvent(object obj)
@@ -167,23 +196,25 @@ namespace PDF_Office.ViewModels.BOTA
                                 box = (TextBlock)mouse.OriginalSource;
                                 grid = (box.Parent as StackPanel).Parent as Grid;
 
-                                grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(selectColcr));
+                                //grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(selectColcr));
                                 if (box != null)
                                 {
                                     box.Visibility = Visibility.Collapsed;
                                     TextBox textBox = CommonHelper.FindVisualChild<TextBox>(grid);
                                     textBox.PreviewMouseDown += new MouseButtonEventHandler(TxtTitleInput_PreviewMouseLeftButtonDown);
                                     TxtTitleInput_PreviewMouseLeftButtonDown(textBox, mouse);
+                                    isSelete = true;
                                 }
                             }
                         }
-                        else
+                        if (mouse.ClickCount == 1)
                         {
                             ListBoxItem listBoxItem = (objs[0] as ListBoxItem);
                             if (listBoxItem != null)
                             {
                                 int index = (listBoxItem.DataContext as CPDFBookmark).PageIndex;
                                 PDFViewer.GoToPage(index);
+                                isSelete = false;
                             }
                         }
                         //MessageBox.Show("dsafa");
@@ -192,57 +223,6 @@ namespace PDF_Office.ViewModels.BOTA
             }
         }
 
-        private void AddBookmarkEvent(object obj)
-        {
-            int index = PDFViewer.CurrentIndex;
-            string mark = string.Format($"第{index + 1}页");
-
-            var list = PDFViewer.Document.GetBookmarkList().FindAll(q => q.PageIndex == index);
-
-            if (list.Count > 0)
-            {
-                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);
-                    grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(selectColcr));
-                    return;
-                }
-            }
-            DialogParameters value = new DialogParameters();
-            value.Add(ParameterNames.Bookmark, mark);
-            value.Add(ParameterNames.Title, "创建一个新的书签");
-            dialogs.ShowDialog(DialogNames.AddBookmarkDialog, value, e =>
-            {
-                if (e.Result == ButtonResult.OK && e.Parameters != null)
-                {
-                    if
-                    (e.Parameters.ContainsKey(ParameterNames.Bookmark))
-                    {
-                        mark = e.Parameters.GetValue<string>(ParameterNames.Bookmark).ToString();
-                        CPDFBookmark bookmark = new CPDFBookmark();
-                        bookmark.Title = mark;
-                        bookmark.Date = DateTime.Now.ToString(@"yyyyMMddHHmmsszzz\'").Replace(':', '\'') + "\n";
-                        bookmark.PageIndex = PDFViewer.CurrentIndex;
-
-                        if (PDFViewer.Document.AddBookmark(bookmark))
-                        {
-                            PDFViewer.UndoManager.CanSave = true;
-
-                            Bookmarklist = new ObservableCollection<CPDFBookmark>(PDFViewer.Document.GetBookmarkList().OrderBy(d => d.Title));
-                        }
-                    }
-                }
-            });
-        }
-
         private void MouseLeaveEvent(object obj)
         {
             if (obj is CompositeCommandParameter)
@@ -254,57 +234,17 @@ namespace PDF_Office.ViewModels.BOTA
                     if (grid != null)
                     {
                         TextBlock box = CommonHelper.FindVisualChild<TextBlock>(grid);
-                        if (box != null)
-                        {
-                            box.Visibility = Visibility.Visible;
-                        }
-                        grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(defaultColor));
-                    }
-                }
-            }
-
-            #region history
 
-            if (obj is MouseEventArgs)
-            {
-                var mouse = (MouseEventArgs)obj;
-                Grid grid = null;
-                if (mouse.Source is Grid)
-                {
-                    grid = mouse.Source as Grid;
-                    if (grid != null)
-                    {
-                        TextBlock box = CommonHelper.FindVisualChild<TextBlock>(grid);
                         if (box != null)
                         {
                             box.Visibility = Visibility.Visible;
                         }
-                        grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(defaultColor));
-                    }
-                }
-                if (mouse.Source is TextBlock)
-                {
-                    TextBlock text = (TextBlock)mouse.Source;
-                    if (text != null)
-                    {
-                        text.Visibility = Visibility.Visible;
-                        grid = (text.Parent as StackPanel).Parent as Grid;
-                        grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(defaultColor));
-                    }
-                }
-                if (mouse.Source is TextBox)
-                {
-                    TextBox text = (TextBox)mouse.Source;
-                    if (text != null)
-                    {
-                        text.Visibility = Visibility.Collapsed;
-                        grid = (text.Parent as StackPanel).Parent as Grid;
-                        grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(defaultColor));
+                        ListBoxItem myListBoxItem = CommonHelper.FindVisualParent<ListBoxItem>(grid);
+                        //myListBoxItem.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(defaultColor));
+                        //grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(defaultColor));
                     }
                 }
             }
-
-            #endregion history
         }
 
         public void MouseEnterEvent(object obj)
@@ -322,46 +262,66 @@ namespace PDF_Office.ViewModels.BOTA
                         {
                             box.Visibility = Visibility.Visible;
                         }
-                        grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(hoverColor));
+                        ListBoxItem myListBoxItem = CommonHelper.FindVisualParent<ListBoxItem>(grid);
+                        //myListBoxItem.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(hoverColor));
+                        //grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(hoverColor));
                     }
                 }
             }
+        }
 
-            #region history
+        private void AddBookmarkEvent(object obj)
+        {
+            int index = PDFViewer.CurrentIndex;
+            string mark = string.Format($"第{index + 1}页");
 
-            if (obj is MouseEventArgs)
+            var list = PDFViewer.Document.GetBookmarkList().FindAll(q => q.PageIndex == index);
+
+            if (list.Count > 0)
             {
-                var mouse = (MouseEventArgs)obj;
-                Grid grid = null;
-                if (mouse.Source is Grid)
+                System.Windows.Controls.ListView listView = obj as System.Windows.Controls.ListView;
+                if (listView != null)
                 {
-                    grid = mouse.Source as Grid;
-                    if (grid != null)
-                    {
-                        TextBlock box = CommonHelper.FindVisualChild<TextBlock>(grid);
-                        if (box != null)
-                        {
-                            box.Visibility = Visibility.Visible;
-                        }
-                        grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(hoverColor));
-                    }
+                    //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);
+                    myListBoxItem.IsSelected = true;
+                    myListBoxItem.Focus();
+                    listView.SelectedItem = myListBoxItem;
+
+                    //myListBoxItem.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(selectColcr));
+                    return;
                 }
-                if (mouse.Source is TextBlock)
+            }
+            DialogParameters value = new DialogParameters();
+            value.Add(ParameterNames.Bookmark, mark);
+            value.Add(ParameterNames.Title, "创建一个新的书签");
+            dialogs.ShowDialog(DialogNames.AddBookmarkDialog, value, e =>
+            {
+                if (e.Result == ButtonResult.OK && e.Parameters != null)
                 {
-                    TextBlock text = (TextBlock)mouse.Source;
-                    if (text != null)
+                    if (e.Parameters.ContainsKey(ParameterNames.Bookmark))
                     {
-                        text.Visibility = Visibility.Visible;
-                        grid = (text.Parent as StackPanel).Parent as Grid;
-                        grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(hoverColor));
+                        mark = e.Parameters.GetValue<string>(ParameterNames.Bookmark).ToString();
+                        CPDFBookmark bookmark = new CPDFBookmark();
+                        bookmark.Title = mark;
+                        bookmark.Date = DateTime.Now.ToString(@"yyyyMMddHHmmsszzz\'").Replace(':', '\'') + "\n";
+                        bookmark.PageIndex = PDFViewer.CurrentIndex;
+
+                        if (PDFViewer.Document.AddBookmark(bookmark))
+                        {
+                            PDFViewer.UndoManager.CanSave = true;
+
+                            Bookmarklist = new ObservableCollection<CPDFBookmark>(PDFViewer.Document.GetBookmarkList().OrderBy(d => d.Title));
+                        }
                     }
                 }
-            }
-            else
-            {
-            }
-
-            #endregion history
+            });
         }
 
         public void MouseClickEvent(object obj)

+ 17 - 2
PDF Office/Views/BOTA/BookmarkContent.xaml

@@ -30,8 +30,7 @@
                 <Grid
                     Name="Grid"
                     HorizontalAlignment="Stretch"
-                    VerticalAlignment="Stretch"
-                    Background="#F2F2F2">
+                    VerticalAlignment="Stretch">
                     <Grid.RowDefinitions>
                         <RowDefinition Height="40" />
                     </Grid.RowDefinitions>
@@ -179,6 +178,22 @@
                         <!--<EventSetter Event="Unselected" Handler="ListViewItem_Unselected" />-->
                     </Style>
                 </ListView.ItemContainerStyle>
+                <ListView.ContextMenu>
+                    <ContextMenu Width="200">
+                        <MenuItem
+                            Command="{Binding RenameCommand}"
+                            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