123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- using PDF_Master.CustomControl;
- using PDF_Master.Helper;
- using PDF_Master.Model.Dialog.ToolsDialogs;
- using PDF_Master.ViewModels.Dialog.ToolsDialogs;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace PDF_Master.Views.Dialog.ToolsDialogs
- {
- /// <summary>
- /// MergeDialog.xaml 的交互逻辑
- /// </summary>
- public partial class MergeDialog : UserControl
- {
- /// <summary>
- /// 当前显示了线段的Item
- /// </summary>
- private ListViewItem listViewItem = null;
- private bool IsFile = false;
- public MergeDialog()
- {
- InitializeComponent();
- }
- private void Delete_Click(object sender, RoutedEventArgs e)
- {
- (DataContext as MergeDialogViewModel).DeleteItem((sender as Button).DataContext as MergeObject);
- }
- private void MergeView_PreviewMouseMove(object sender, MouseEventArgs e)
- {
- if (e.LeftButton == MouseButtonState.Pressed)
- {
- var pos = e.GetPosition(MergeView);
- HitTestResult result = VisualTreeHelper.HitTest(MergeView, pos);
- if (result == null)
- {
- return;
- }
- //点击删除按钮
- Button Button = CommonHelper.FindVisualParent<Button>(result.VisualHit);
- if (Button != null)
- {
- return;
- }
- //点击下拉框
- WritableComboBox writableComboBox = CommonHelper.FindVisualParent<WritableComboBox>(result.VisualHit);
- if (writableComboBox != null)
- {
- return;
- }
- var treeViewItem = CommonHelper.FindVisualParent<ListViewItem>(result.VisualHit);
- if (treeViewItem == null)
- {
- return;
- }
- DataObject dataObj = new DataObject(treeViewItem);
- DragDrop.DoDragDrop(MergeView, dataObj, DragDropEffects.Move);
- return;
- }
- }
- private void MergeView_Drop(object sender, DragEventArgs e)
- {
- if (IsFile)
- {
- DragDropHelper.Drop(this, e);
- string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
- (DataContext as MergeDialogViewModel).AddFiles(file);
- }
- ListViewItem souredata = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;
- if (souredata == null)
- {
- return;
- }
- MergeObject soureNode = souredata.DataContext as MergeObject;
- Point pos = e.GetPosition(MergeView);
- HitTestResult result = VisualTreeHelper.HitTest(MergeView, pos);
- if (result == null)
- {
- HiddenaAllLine();
- return;
- }
- ListViewItem targetitem = CommonHelper.FindVisualParent<ListViewItem>(result.VisualHit);
- if (targetitem == null)
- {
- HiddenaAllLine();
- return;
- }
- MergeObject targetNode = targetitem.DataContext as MergeObject;
- if (soureNode.Equals(targetNode))
- {
- HiddenaAllLine();
- return;
- }
- (DataContext as MergeDialogViewModel).MoveMerge(targetNode, soureNode);
- HiddenaAllLine();
- }
- private void MergeView_DragOver(object sender, DragEventArgs e)
- {
- if (IsFile)
- {
- DragDropHelper.DragOver(this, e);
- }
- ListViewItem sourceitem = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;
- if (sourceitem == null)
- {
- return;
- }
- Point pos = e.GetPosition(MergeView);
- HitTestResult result = VisualTreeHelper.HitTest(MergeView, pos);
- if (result != null)
- {
- ListViewItem treeviewitem = CommonHelper.FindVisualParent<ListViewItem>(result.VisualHit);
- if (treeviewitem != null)
- {
- if (listViewItem == null)
- {
- listViewItem = treeviewitem;
- }
- else if (!listViewItem.Equals(treeviewitem))
- {
- (listViewItem.DataContext as MergeObject).IsBackwards = false;
- (listViewItem.DataContext as MergeObject).IsForward = false;
- listViewItem = treeviewitem;
- }
- else
- {
- (listViewItem.DataContext as MergeObject).IsBackwards = false;
- (listViewItem.DataContext as MergeObject).IsForward = false;
- }
- if (listViewItem.Equals(sourceitem))
- {
- return;
- }
- //鼠标位于上半部分显示实线,下半部分显示虚线
- Point p = treeviewitem.TranslatePoint(new Point(0, 0), MergeView);
- if (pos.Y < p.Y + 16)
- {
- (treeviewitem.DataContext as MergeObject).IsBackwards = true;
- }
- else
- {
- (treeviewitem.DataContext as MergeObject).IsForward = true;
- }
- }
- }
- }
- private void MergeView_DragLeave(object sender, DragEventArgs e)
- {
- if (IsFile)
- {
- DragDropHelper.DragLeave();
- }
- HiddenaAllLine();
- }
- /// <summary>
- /// 清理线条显示,以及相关缓存对象
- /// </summary>
- private void HiddenaAllLine()
- {
- if (listViewItem != null)
- {
- (listViewItem.DataContext as MergeObject).IsBackwards = false;
- (listViewItem.DataContext as MergeObject).IsForward = false;
- listViewItem = null;
- }
- }
- private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
- {
- Regex regex = new Regex("[^0-9.]+");
- e.Handled = regex.IsMatch(e.Text);
- }
- private void TextBoxEx_LostFocus(object sender, RoutedEventArgs e)
- {
- try
- {
- double Tag = Double.Parse((sender as TextBox).Text);
- if (Tag <= 0)
- {
- (sender as TextBox).Text = "";
- }
- }
- catch (Exception)
- {
- (sender as TextBox).Text = "";
- }
- }
- private void TextBoxEx_PreviewKeyDown(object sender, KeyEventArgs e)
- {
- if (e.Key == Key.Enter)
- {
- BtnMerge.Focus();
- e.Handled = true;
- }
- }
- private void MergeView_DragEnter(object sender, DragEventArgs e)
- {
- IsFile = false;
- var file = (System.Array)e.Data.GetData(DataFormats.FileDrop);
- if (file == null)//为null 表示内部拖动 触发的
- {
- return;
- }
- foreach (string f in file)
- {
- System.IO.FileInfo info = new System.IO.FileInfo(f);
- //只要拖拽进来的文件里包含有pdf格式文件,就允许拖入
- if (System.IO.Path.GetExtension(f).ToLower() == ".pdf" && info.Length > 0)
- {
- DragDropHelper.DragEnter(this, e);
- IsFile = true;
- }
- //图片格式
- else if (Properties.Resources.imageex.Contains(System.IO.Path.GetExtension(f).ToLower()) && info.Length > 0)
- {
- DragDropHelper.DragEnter(this, e);
- IsFile = true;
- }
- }
- }
- private void Grid_Drop(object sender, DragEventArgs e)
- {
- if (IsFile)
- {
- DragDropHelper.Drop(this, e);
- string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
- (DataContext as MergeDialogViewModel).AddFiles(file);
- }
- }
- private void Grid_DragEnter(object sender, DragEventArgs e)
- {
- IsFile = false;
- var file = (System.Array)e.Data.GetData(DataFormats.FileDrop);
- if (file == null)//为null 表示内部拖动 触发的
- {
- return;
- }
- foreach (string f in file)
- {
- System.IO.FileInfo info = new System.IO.FileInfo(f);
- //只要拖拽进来的文件里包含有pdf格式文件,就允许拖入
- if (System.IO.Path.GetExtension(f).ToLower() == ".pdf" && info.Length > 0)
- {
- DragDropHelper.DragEnter(this, e);
- IsFile = true;
- }
- //图片格式
- else if (Properties.Resources.imageex.Contains(System.IO.Path.GetExtension(f).ToLower()) && info.Length > 0)
- {
- DragDropHelper.DragEnter(this, e);
- IsFile = true;
- }
- }
- }
- private void Grid_DragOver(object sender, DragEventArgs e)
- {
- if (IsFile)
- {
- DragDropHelper.DragOver(this, e);
- }
- }
- private void Grid_DragLeave(object sender, DragEventArgs e)
- {
- if (IsFile)
- {
- DragDropHelper.DragLeave();
- }
- }
- private void UserControl_Loaded(object sender, RoutedEventArgs e)
- {
- NoFileText.Text = App.MainPageLoader.GetString("Merge_Hint");
- TitleFileName.Text = App.MainPageLoader.GetString("Merge_TitleFileName");
- TitlePageRange.Text = App.MainPageLoader.GetString("Merge_TitlePageRange");
- TitleSize.Text = App.MainPageLoader.GetString("Merge_TitleSize");
- AddComboBoxItemText.Text = App.MainPageLoader.GetString("Merge_AddFiles");
- AddFolderComboBoxItemText.Text = App.MainPageLoader.GetString("Merge_AddFolder");
- AddOpenFileComboBoxItem.Text = App.MainPageLoader.GetString("Merge_AddOpenFile");
- BtnMerge.Content = App.MainPageLoader.GetString("Merge_Yes");
- BtnCancel.Content = App.MainPageLoader.GetString("Merge_No");
- }
- }
- }
|