|
@@ -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;
|
|
|
}
|
|
|
|