|
@@ -49,6 +49,19 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
public ObservableCollection<string> PageRangeItems { get; set; }
|
|
|
|
|
|
#region 属性
|
|
|
+ private Visibility showTip;
|
|
|
+ /// <summary>
|
|
|
+ /// 是否显示渐隐提示
|
|
|
+ /// </summary>
|
|
|
+ public Visibility ShowTip
|
|
|
+ {
|
|
|
+ get { return showTip; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref showTip, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private int listSelecedIndex;
|
|
|
/// <summary>
|
|
|
/// 缩略图选中项的索引
|
|
@@ -94,6 +107,10 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
set
|
|
|
{
|
|
|
SetProperty(ref tbPageRangeVisibility, value);
|
|
|
+ if(value==Visibility.Visible)
|
|
|
+ {
|
|
|
+ comboxSelectIndex = -1;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -138,25 +155,188 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
/// 响应键盘回车事件
|
|
|
/// </summary>
|
|
|
public DelegateCommand<object> KeyDown { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 替换文件
|
|
|
+ /// </summary>
|
|
|
+ public DelegateCommand ReplaceCommand { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 插入文件命令
|
|
|
+ /// </summary>
|
|
|
+ public DelegateCommand InsertCommand { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 拆分文件
|
|
|
+ /// </summary>
|
|
|
+ public DelegateCommand SplitCommand { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 提取文件
|
|
|
+ /// </summary>
|
|
|
+ public DelegateCommand ExtractCommand { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 逆时针旋转
|
|
|
+ /// </summary>
|
|
|
+ public DelegateCommand LeftRotateCommand { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 顺时针旋转
|
|
|
+ /// </summary>
|
|
|
+ public DelegateCommand RightRotateCommand { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 删除
|
|
|
+ /// </summary>
|
|
|
+ public DelegateCommand DeleteCommand { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 倒序
|
|
|
+ /// </summary>
|
|
|
+ public DelegateCommand ReverseCommand { get; set; }
|
|
|
#endregion
|
|
|
|
|
|
public PageEditContentViewModel(IDialogService dialogService, IEventAggregator eventAggregator)
|
|
|
{
|
|
|
+ //变量初始化
|
|
|
dialogs = dialogService;
|
|
|
eventor = eventAggregator;
|
|
|
unicode = App.mainWindowViewModel.SelectedItem.Unicode;
|
|
|
PageEditItems = new ObservableCollection<PageEditItem>();
|
|
|
PageRangeItems = new ObservableCollection<string>();
|
|
|
|
|
|
- eventAggregator.GetEvent<PageEditRefreshEvent>().Subscribe(OnPageEditRefreshEvent, e => e.Unicode == unicode);
|
|
|
-
|
|
|
+ //绑定命令
|
|
|
SelectionChangedCommand = new DelegateCommand<object>(SelectionChangedEvent);
|
|
|
+ PreviewKeyDown = new DelegateCommand<object>(PreviewKeyDownEvent);
|
|
|
+ KeyDown = new DelegateCommand<object>(KeyDownEvent);
|
|
|
+
|
|
|
+ SplitCommand = new DelegateCommand(SplitCommandEvent);
|
|
|
+ InsertCommand = new DelegateCommand(InsertCommandEvent);
|
|
|
+ ReplaceCommand = new DelegateCommand(ReplaceCommandEvent,CanFileCommandExcute).ObservesProperty(() => ListSelectedIndex);
|
|
|
+ ExtractCommand = new DelegateCommand(ExtractCommandEvent,CanFileCommandExcute).ObservesProperty(() => ListSelectedIndex);
|
|
|
+ DeleteCommand = new DelegateCommand(DeleteCommandEvent, CanFileCommandExcute).ObservesProperty(() => ListSelectedIndex);
|
|
|
+ LeftRotateCommand = new DelegateCommand(LeftRotateCommandEvent, CanFileCommandExcute).ObservesProperty(() => ListSelectedIndex);
|
|
|
+ RightRotateCommand = new DelegateCommand(RightRotateCommandEvent, CanFileCommandExcute).ObservesProperty(() => ListSelectedIndex);
|
|
|
+ ReverseCommand = new DelegateCommand(ReverseCommandEvent,CanFileCommandExcute).ObservesProperty(() => ListSelectedIndex);
|
|
|
+
|
|
|
+ //订阅页面刷新事件
|
|
|
+ eventAggregator.GetEvent<PageEditRefreshEvent>().Subscribe(OnPageEditRefreshEvent, e => e.Unicode == unicode);
|
|
|
|
|
|
RefreshPageRangeItem();
|
|
|
}
|
|
|
|
|
|
|
|
|
#region 事件
|
|
|
+ /// <summary>
|
|
|
+ /// 替换功能的逻辑
|
|
|
+ /// </summary>
|
|
|
+ private void ReplaceCommandEvent()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 拆分功能的逻辑
|
|
|
+ /// </summary>
|
|
|
+ private void SplitCommandEvent()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 提取功能的逻辑
|
|
|
+ /// </summary>
|
|
|
+ private void ExtractCommandEvent()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 插入功能的逻辑
|
|
|
+ /// </summary>
|
|
|
+ private void InsertCommandEvent()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 删除选中页面
|
|
|
+ /// </summary>
|
|
|
+ private void DeleteCommandEvent()
|
|
|
+ {
|
|
|
+ List<int> indexList = new List<int>();
|
|
|
+ for(int i=0;i<PageEditItems.Count;i++)
|
|
|
+ {
|
|
|
+ if(PageEditItems[i].Selected)
|
|
|
+ {
|
|
|
+ indexList.Add(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var result = PDFViewer.Document.RemovePages(indexList.ToArray());
|
|
|
+ if(!result)
|
|
|
+ {
|
|
|
+ ShowTip = Visibility.Visible;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //文档层操作成功后再删除UI层
|
|
|
+ for(int i= indexList.Count-1; i>=0;i--)
|
|
|
+ {
|
|
|
+ PageEditItems.RemoveAt(indexList[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ RefreshPageNum();
|
|
|
+
|
|
|
+ PDFViewer.ReloadDocument();
|
|
|
+
|
|
|
+ //清空undo栈,标记为可保存状态
|
|
|
+ PDFViewer.UndoManager.ClearHistory();
|
|
|
+ PDFViewer.UndoManager.CanSave = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 左旋转页面的逻辑
|
|
|
+ /// </summary>
|
|
|
+ private void LeftRotateCommandEvent()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 右旋转页面的逻辑
|
|
|
+ /// </summary>
|
|
|
+ private void RightRotateCommandEvent()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 页面倒序的逻辑
|
|
|
+ /// </summary>
|
|
|
+ private void ReverseCommandEvent()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 是否可以执行文件操作命令 除插入、拆分外
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ private bool CanFileCommandExcute()
|
|
|
+ {
|
|
|
+ if(ListSelectedIndex<0)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 响应UI发送刷新图片的事件
|
|
|
/// </summary>
|
|
@@ -165,19 +345,20 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
{
|
|
|
//UI发送事件过来通知刷新图片时
|
|
|
//调整逻辑,前后预加载5页
|
|
|
- RefreshItemImage(e.PageRange.Item1 - 5, e.PageRange.Item2 + 5);
|
|
|
+ RefreshItemImage(e.PageRange.Item1 - 2, e.PageRange.Item2 + 2);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 选项改变事件
|
|
|
+ /// 选项改变事件
|
|
|
+ /// 虚拟化的时候不会触发选中事件
|
|
|
/// </summary>
|
|
|
/// <param name="e"></param>
|
|
|
private void SelectionChangedEvent(object e)
|
|
|
{
|
|
|
var args = e as SelectionChangedEventArgs;
|
|
|
+ var listbox = args.OriginalSource as ListBox;
|
|
|
if (TbPageRangeVisibility == Visibility.Visible&&args!=null)
|
|
|
{
|
|
|
- var listbox = args.OriginalSource as ListBox;
|
|
|
List<int> pagelist = new List<int>();
|
|
|
for(int i=0;i< listbox.SelectedItems.Count;i++)
|
|
|
{
|
|
@@ -202,6 +383,12 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
|
|
|
string pageparm = CommonHelper.GetPageParmFromList(pagelist);
|
|
|
TbPageRange = pageparm;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ if (listbox.SelectedItem != null)
|
|
|
+ {
|
|
|
+ listbox.ScrollIntoView(listbox.SelectedItem);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -217,7 +404,7 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (args.Key !=Key.OemComma && args.Key !=Key.Subtract && !((args.Key>Key.D0&&args.Key<Key.D9)||(args.Key>Key.NumPad0&&args.Key<Key.NumPad9)))
|
|
|
+ if (args.Key!=Key.Enter&&args.Key!=Key.Back&&args.Key !=Key.OemComma && args.Key !=Key.Subtract && !((args.Key>=Key.D0&&args.Key<=Key.D9)||(args.Key>=Key.NumPad0&&args.Key<=Key.NumPad9)))
|
|
|
{
|
|
|
args.Handled = true;
|
|
|
}
|
|
@@ -229,29 +416,31 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
/// <param name="e"></param>
|
|
|
private void KeyDownEvent(object e)
|
|
|
{
|
|
|
-
|
|
|
var args = e as KeyEventArgs;
|
|
|
if(args==null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
- List<int> TargetPages = new List<int>();
|
|
|
- var result = CommonHelper.GetPagesInRange(ref TargetPages, (args.OriginalSource as TextBox).Text, PDFViewer.Document.PageCount, new char[] { ',', ',' }, new char[] { '-' });
|
|
|
- if(!result)
|
|
|
- {
|
|
|
- MessageBox.Show("请输入有效范围");
|
|
|
- }
|
|
|
-
|
|
|
- //选中输入的页面范围
|
|
|
- for(int i=0;i<PageEditItems.Count;i++)
|
|
|
+ if (args.Key == Key.Enter)
|
|
|
{
|
|
|
- if(TargetPages.Contains(PageEditItems[i].PageNumber))
|
|
|
+ List<int> TargetPageIndexs = new List<int>();
|
|
|
+ var result = CommonHelper.GetPagesInRange(ref TargetPageIndexs, (args.OriginalSource as TextBox).Text, PDFViewer.Document.PageCount, new char[] { ',', ',' }, new char[] { '-' });
|
|
|
+ if (!result)
|
|
|
{
|
|
|
- PageEditItems[i].Selected = true;
|
|
|
+ MessageBox.Show("请输入有效范围");
|
|
|
}
|
|
|
- else
|
|
|
+
|
|
|
+ //选中输入的页面范围
|
|
|
+ for (int i = 0; i < PageEditItems.Count; i++)
|
|
|
{
|
|
|
- PageEditItems[i].Selected = false;
|
|
|
+ if (TargetPageIndexs.Contains(PageEditItems[i].PageNumber-1))
|
|
|
+ {
|
|
|
+ PageEditItems[i].Selected = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PageEditItems[i].Selected = false;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -260,6 +449,17 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
|
|
|
#region 方法
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 刷新页码
|
|
|
+ /// </summary>
|
|
|
+ private void RefreshPageNum()
|
|
|
+ {
|
|
|
+ for(int i=0;i<PageEditItems.Count;i++)
|
|
|
+ {
|
|
|
+ PageEditItems[i].PageNumber = i + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 刷新页面范围下拉框
|
|
|
/// </summary>
|
|
@@ -489,7 +689,5 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|