Browse Source

综合-【主页】文件列表,需要点击其他空白区域取消文件选中;【会员】合并,免费用户不支持2个以上文档的合并;【打印】Ui显示问题

OYXH\oyxh 1 year ago
parent
commit
2ecaffabe9

+ 28 - 17
PDF Office/CustomControl/NumericUpDown.xaml

@@ -6,20 +6,21 @@
     xmlns:local="clr-namespace:PDF_Master.CustomControl"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     d:DesignWidth="120"
-    FontSize="20"
+    FontSize="14"
     Loaded="UserControl_Loaded"
     mc:Ignorable="d">
-    <Border Background="{StaticResource color.field.bg.def}"
-                BorderBrush="{StaticResource color.field.border.norm}" BorderThickness="1,1,1,1"
-                CornerRadius="4,4,4,4">
+    <Border
+        Background="{StaticResource color.field.bg.def}"
+        BorderBrush="{StaticResource color.field.border.norm}"
+        BorderThickness="1,1,1,1"
+        CornerRadius="4,4,4,4">
         <Grid>
             <Grid.ColumnDefinitions>
                 <ColumnDefinition Width="*" />
                 <ColumnDefinition Width="1" />
                 <ColumnDefinition Width="20" />
             </Grid.ColumnDefinitions>
-            <Border
-                />
+            <Border />
             <TextBox
                 Name="TextBox_Num"
                 MinWidth="68"
@@ -28,29 +29,33 @@
                 VerticalContentAlignment="Center"
                 Background="Transparent"
                 BorderThickness="0"
-                LostFocus="TextBox_Num_LostFocus"
-                PreviewKeyDown="TextBox_Num_PreviewKeyDown"
                 FontFamily="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=FontFamily}"
                 FontSize="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=FontSize}"
                 Foreground="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=Foreground}"
                 InputMethod.IsInputMethodEnabled="False"
+                LostFocus="TextBox_Num_LostFocus"
+                PreviewKeyDown="TextBox_Num_PreviewKeyDown"
                 PreviewTextInput="CountTextBox_PreviewTextInput"
                 Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=Text}"
                 TextAlignment="Left" />
-            <Rectangle Grid.Column="1" Fill="{StaticResource color.field.border.norm}" Margin="0,0.5,0,0.5"></Rectangle>
-            <Grid Grid.Column="2" Width="20"  >
+            <Rectangle
+                Grid.Column="1"
+                Margin="0,0.5,0,0.5"
+                Fill="{StaticResource color.field.border.norm}" />
+            <Grid Grid.Column="2" Width="20">
                 <Grid.RowDefinitions>
                     <RowDefinition Height="12*" />
-                    <RowDefinition Height="3*"/>
                     <RowDefinition Height="3*" />
-                    <RowDefinition Height="12*"/>
+                    <RowDefinition Height="3*" />
+                    <RowDefinition Height="12*" />
                 </Grid.RowDefinitions>
                 <Border
                     Grid.Row="0"
+                    Grid.RowSpan="2"
                     Background="{StaticResource color.field.bg.def}"
                     BorderBrush="{StaticResource color.field.border.norm}"
                     BorderThickness="0,0,0,0.5"
-                    CornerRadius="0,4,0,0" Grid.RowSpan="2">
+                    CornerRadius="0,4,0,0">
                     <Button
                         Name="Button_Add"
                         Background="Transparent"
@@ -58,27 +63,33 @@
                         BorderThickness="0"
                         Click="Button_Add_Click">
                         <Path
-                           
+                            Width="10.06"
+                            Height="5.78"
                             Data="M10 5.93571L13.9696 9.90532L15.0303 8.84466L10.5303 4.34472C10.2374 4.05183 9.76257 4.05183 9.46967 4.34472L4.96974 8.84466L6.0304 9.90532L10 5.93571Z"
                             Fill="{StaticResource color.icon.arrow.gray.def}"
-                            Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=ShowBtn}" Height="5.78" Stretch="Fill" Width="10.06" />
+                            Stretch="Fill"
+                            Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=ShowBtn}" />
                     </Button>
                 </Border>
                 <Border
                     Grid.Row="2"
+                    Grid.RowSpan="2"
                     Background="{StaticResource color.field.bg.def}"
                     BorderBrush="{StaticResource color.field.border.norm}"
                     BorderThickness="0,0.5,0,0"
-                    CornerRadius="0,0,4,0" Grid.RowSpan="2" >
+                    CornerRadius="0,0,4,0">
                     <Button
                         Name="Button_Sub"
                         Background="Transparent"
                         BorderThickness="00"
                         Click="Button_Sub_Click">
                         <Path
+                            Width="10.06"
+                            Height="5.78"
                             Data="M10 9.06427L6.03039 5.09467L4.96973 6.15533L9.46967 10.6553C9.76256 10.9482 10.2374 10.9482 10.5303 10.6553L15.0303 6.15533L13.9696 5.09467L10 9.06427Z"
                             Fill="{StaticResource color.icon.arrow.gray.def}"
-                            Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=ShowBtn}" Height="5.78" Stretch="Fill" Width="10.06"/>
+                            Stretch="Fill"
+                            Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=ShowBtn}" />
                     </Button>
                 </Border>
             </Grid>

+ 88 - 43
PDF Office/ViewModels/Dialog/ToolsDialogs/MergeDialogViewModel.cs

@@ -33,15 +33,17 @@ using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySetti
 
 namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
 {
-    class MergeDialogViewModel : BindableBase, IDialogAware
+    internal class MergeDialogViewModel : BindableBase, IDialogAware
     {
         // Fix:存储当前程序加载的文档的路径和tag,
         //如果路径相同则用tag里的密码解锁,
         //解锁失败再另行提权
         private string CurrentFilePath = string.Empty;
+
         private string currentLoadedPassword = string.Empty;
-        private IEventAggregator eventAggregator;
-        enum PageSizeType
+        private IEventAggregator eventAggregator;
+
+        private enum PageSizeType
         {
             kDefault = 0,
             A4 = 1,
@@ -63,8 +65,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
         }
 
         public void OnDialogClosed()
-        {
-
+        {
         }
 
         public void OnDialogOpened(IDialogParameters parameters)
@@ -112,7 +113,8 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
             }
         }
 
-        #endregion
+        #endregion 框架内容
+
         #region 定义与初始化
 
         public ObservableCollection<MergeObject> MergeObjectlist { get; set; }
@@ -143,6 +145,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
         }
 
         private Visibility processVisible = Visibility.Collapsed;
+
         /// <summary>
         /// 是否显示进度条
         /// </summary>
@@ -156,6 +159,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
         }
 
         private bool _AddOpenFileIsEn = false;
+
         /// <summary>
         /// 添加已打开文件是否置灰
         /// </summary>
@@ -167,6 +171,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                 SetProperty(ref _AddOpenFileIsEn, value);
             }
         }
+
         private string inputHeight;
 
         public string InputHeight
@@ -179,6 +184,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
         }
 
         private double maxValue;
+
         /// <summary>
         /// 最大文件数 用于显示进度条
         /// </summary>
@@ -204,15 +210,18 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                 SetProperty(ref currentvalue, value);
             }
         }
-       /// <summary>
-       /// 订阅按钮
-       /// </summary>
+
+        /// <summary>
+        /// 订阅按钮
+        /// </summary>
         private string _TextUpgrade;
+
         public string TextUpgrade
         {
             get { return _TextUpgrade; }
             set { _TextUpgrade = value; }
         }
+
         /// <summary>
         /// 是否显示限制字段
         /// </summary>
@@ -231,9 +240,8 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
         /// 是否取消添加文件
         /// </summary>
 
-        private bool CancelAddFiles = false;
-
-
+        private bool CancelAddFiles = false;
+
         public MergeDialogViewModel(IDialogService dialogService, IEventAggregator eventAggregator)
         {
             IntString();
@@ -249,6 +257,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
             CancelAddFileCommand = new DelegateCommand(CancelAddFileOpention);
             UnlockMouseDownCommand = new DelegateCommand(UnlockMouseDown);
         }
+
         /// <summary>
         /// 多语
         /// </summary>
@@ -257,14 +266,15 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
             TextUpgrade = App.ServiceLoader.GetString("TextUpgrade");
         }
 
-        #endregion
+        #endregion 定义与初始化
 
         #region 私有方法
 
         private void UnlockMouseDown()
         {
             ConverterHelper.convertUnlock();
-        }
+        }
+
         private void CancelAddFileOpention()
         {
             CancelAddFiles = true;
@@ -284,6 +294,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
             Clear();
             RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
         }
+
         /// <summary>
         /// 点击取消页面范围控件使失去焦点不生效
         /// </summary>
@@ -307,6 +318,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                 }
             }
         }
+
         public void ButtonAddFiles(object data)
         {
             int index = Convert.ToInt32(data);
@@ -316,11 +328,13 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                 case 0:
                     //打开文件
                     AddFiles(OpenFile());
-                    break;
+                    break;
+
                 case 1:
                     //打开文件夹
                     AddFiles(OpenFileFolder());
-                    break;
+                    break;
+
                 case 2:
                     //打开当前文件
                     List<string> list = new List<string>();
@@ -330,7 +344,8 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                         list.Add(App.OpenedFileList[i]);
                     }
                     AddFiles(list.ToArray());
-                    break;
+                    break;
+
                 default:
                     break;
             }
@@ -342,7 +357,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
         private void AddOpenFileIsEnChange()
         {
             AddOpenFileIsEn = false;
-            if (MergeObjectlist.Count> App.OpenedFileList.Count)
+            if (MergeObjectlist.Count > App.OpenedFileList.Count)
             {
                 AddOpenFileIsEn = true;
                 return;
@@ -365,9 +380,8 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                     break;
                 }
             }
-        }
-
-
+        }
+
         private string[] OpenFileFolder()
         {
             System.Windows.Forms.FolderBrowserDialog openFile = new System.Windows.Forms.FolderBrowserDialog();
@@ -395,7 +409,8 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
             }
 
             return list.ToArray();
-        }
+        }
+
         private string[] OpenFile()
         {
             OpenFileDialog openFile = new OpenFileDialog();
@@ -410,7 +425,6 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
 
         private void Merge()
         {
-
             bool result = true;
             CPDFDocument SaveDoc = CPDFDocument.CreateDocument();
             int sum = MergeObjectlist.Count;
@@ -423,7 +437,8 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                 List<int> listnum = new List<int>();
                 if (MergeObjectlist[i].SetPageRange == null || MergeObjectlist[i].SetPageRange.Count == 0)
                 {
-                    if (MergeObjectlist[i].SDKPageCount == 0) {
+                    if (MergeObjectlist[i].SDKPageCount == 0)
+                    {
                         AlertsMessage alertsMessage = new AlertsMessage();
                         alertsMessage.ShowDialog("", App.MainPageLoader.GetString("PageRangeWarning"), App.ServiceLoader.GetString("Text_ok"));
                         return;
@@ -434,7 +449,6 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                         pageRangeList.Add(page1);
                     }
                     MergeObjectlist[i].SetPageRange = pageRangeList;
-                   
                 }
             }
 
@@ -474,8 +488,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                         catch
                         {
                             continue;
-                        }
-
+                        }
                     }
                     else
                     {
@@ -554,24 +567,29 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
             switch (pageSizeType)
             {
                 case PageSizeType.kDefault:
-                    break;
+                    break;
+
                 case PageSizeType.A4:
 
                     rect.Width = CommonHelper.GetPageSizeFomrUnit(210);
                     rect.Height = CommonHelper.GetPageSizeFomrUnit(297);
-                    break;
+                    break;
+
                 case PageSizeType.A3:
                     rect.Width = CommonHelper.GetPageSizeFomrUnit(297);
                     rect.Height = CommonHelper.GetPageSizeFomrUnit(420);
-                    break;
+                    break;
+
                 case PageSizeType.Letter:
                     rect.Width = CommonHelper.GetPageSizeFomrUnit(216);
                     rect.Height = CommonHelper.GetPageSizeFomrUnit(279);
-                    break;
+                    break;
+
                 case PageSizeType.Legal:
                     rect.Width = CommonHelper.GetPageSizeFomrUnit(216);
                     rect.Height = CommonHelper.GetPageSizeFomrUnit(356);
-                    break;
+                    break;
+
                 case PageSizeType.Customized:
                     if (!string.IsNullOrEmpty(InputWidth) && !string.IsNullOrEmpty(InputHeight))
                     {
@@ -583,7 +601,8 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                         rect.Width = CommonHelper.GetPageSizeFomrUnit(595);
                         rect.Height = CommonHelper.GetPageSizeFomrUnit(841);
                     }
-                    break;
+                    break;
+
                 default:
                     break;
             }
@@ -619,7 +638,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
             }
         }
 
-        #endregion
+        #endregion 私有方法
 
         #region 公开方法
 
@@ -660,10 +679,17 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
             {
                 return;
             }
+            if (Settings.Default.UserDate.subscribestatus != 1 && MergeObjectlist.Count >= 2)
+            {
+                return;
+            }
             bool showDialog = false;
             ProcessVisible = Visibility.Visible;
             MaxValue = FilePath.Length;
-            for (int i = 0; i < FilePath.Length; i++)
+
+            int sum = SetFilesLength(FilePath);
+
+            for (int i = 0; i < sum; i++)
             {
                 //加入异步语句,防止UI卡死,显示加载进度条
                 await System.Threading.Tasks.Task.Delay(1);
@@ -763,7 +789,6 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                     }
                     else
                     {
-
                         VerifyPasswordResult condition = new VerifyPasswordResult();
                         App.Current.Dispatcher.Invoke(() =>
                         {
@@ -777,7 +802,6 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                                 mergeObject.Password = condition.Password;
                                 if (doc.UnlockWithPassword(condition.Password) && doc.CheckOwnerPassword(condition.Password))
                                 {
-
                                 }
                             }
                         }
@@ -786,8 +810,6 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                             doc.Release();
                             continue;
                         }
-
-
                     }
 
                     mergeObject.DocName = doc.FileName;
@@ -803,7 +825,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                         mergeObject.IsEvenPageIsEnabled = false;
                     }
                     mergeObject.SDKPageCount = doc.PageCount;
-                    
+
                     mergeObject.DocSize = CommonHelper.GetFileSize(mergeObject.FilePath);
 
                     //获取第一页缩略图
@@ -836,7 +858,30 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                 {
                 }
             }
-        }
-        #endregion
+        }
+
+        /// <summary>
+        ///  未购买的用户 设置文件数量
+        /// </summary>
+        /// <param name="filePath"></param>
+        /// <returns></returns>
+        private int SetFilesLength(string[] filePath)
+        {
+            int sum = filePath.Length;
+            if (Settings.Default.UserDate.subscribestatus != 1 && sum >= 2)
+            {
+                if (MergeObjectlist.Count >= 1)
+                {
+                    sum = 1;
+                }
+                else
+                {
+                    sum = 2;
+                }
+            }
+            return sum;
+        }
+
+        #endregion 公开方法
     }
-}
+}

+ 2 - 2
PDF Office/Views/HomePanel/HomeGuidContent.xaml

@@ -12,6 +12,7 @@
     d:DesignWidth="800"
     prism:ViewModelLocator.AutoWireViewModel="True"
     Background="{StaticResource color.sys.layout.anti}"
+    PreviewMouseDown="UserControl_MouseDown"
     mc:Ignorable="d">
     <Grid>
         <ScrollViewer
@@ -31,8 +32,7 @@
                 <recentFiles:RecentFilesContent
                     x:Name="Recentlist"
                     Grid.Row="1"
-                    Margin="24,0"
-                    MouseDown="Recentlist_MouseDown" />
+                    Margin="24,0" />
             </Grid>
         </ScrollViewer>
     </Grid>

+ 34 - 22
PDF Office/Views/HomePanel/HomeGuidContent.xaml.cs

@@ -1,4 +1,5 @@
-using PDF_Master.Views.HomePanel.RecentFiles;
+using PDF_Master.Helper;
+using PDF_Master.Views.HomePanel.RecentFiles;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
@@ -51,33 +52,44 @@ namespace PDF_Master.Views.HomePanel
         private void Recentlist_MouseDown(object sender, MouseButtonEventArgs e)
         {
             //Windows:最近文件列表补充点击空白处取消选中;移除Esc取消选中逻辑
-            if (sender is RecentFilesContent recentFilesContent)
+            // 文件列表,需要点击其他空白区域取消文件选中
+            if (e.ClickCount == 1 && e.LeftButton == MouseButtonState.Pressed && Recentlist.GridRecentFilesList.Visibility == Visibility.Visible && Recentlist.GridRecentFilesList.SelectedItems.Count > 0)
             {
-                if (recentFilesContent.GridRecentFilesList.Visibility == Visibility.Visible)
+                HitTestResult hitTestResult = VisualTreeHelper.HitTest(Recentlist.GridRecentFilesList, e.GetPosition(Recentlist.GridRecentFilesList));
+                if (hitTestResult == null)
                 {
-                    var point = e.GetPosition(recentFilesContent.GridRecentFilesList);
-                    var result = VisualTreeHelper.HitTest(recentFilesContent.GridRecentFilesList, point);
-                    if (result != null)
-                    {
-                        if (recentFilesContent.GridRecentFilesList.SelectedIndex != -1)
-                        {
-                            recentFilesContent.GridRecentFilesList.SelectedIndex = -1;
-                        }
-                    }
+                    Recentlist.GridRecentFilesList.SelectedItems.Clear();
                 }
-                else if (recentFilesContent.RecentFilesList.Visibility == Visibility.Visible)
+                else if (hitTestResult.VisualHit == Recentlist.GridRecentFilesList)
                 {
-                    var point = e.GetPosition(recentFilesContent.RecentFilesList);
-                    var result = VisualTreeHelper.HitTest(recentFilesContent.RecentFilesList, point);
-                    if (result != null)
-                    {
-                        if (recentFilesContent.RecentFilesList.SelectedIndex != -1)
-                        {
-                            recentFilesContent.RecentFilesList.SelectedIndex = -1;
-                        }
-                    }
+                    Recentlist.GridRecentFilesList.SelectedItems.Clear();
+                }
+                else if (hitTestResult.VisualHit is ScrollViewer scrollViewer)
+                {
+                    Recentlist.GridRecentFilesList.SelectedItems.Clear();
                 }
             }
+            else if (e.ClickCount == 1 && e.LeftButton == MouseButtonState.Pressed && Recentlist.RecentFilesList.Visibility == Visibility.Visible && Recentlist.RecentFilesList.SelectedItems.Count > 0)
+            {
+                HitTestResult hitTestResult = VisualTreeHelper.HitTest(Recentlist.RecentFilesList, e.GetPosition(Recentlist.RecentFilesList));
+                if (hitTestResult == null)
+                {
+                    Recentlist.RecentFilesList.SelectedItems.Clear();
+                }
+                else if (hitTestResult.VisualHit == Recentlist.RecentFilesList)
+                {
+                    Recentlist.RecentFilesList.SelectedItems.Clear();
+                }
+                else if (hitTestResult.VisualHit is ScrollViewer scrollViewer)
+                {
+                    Recentlist.RecentFilesList.SelectedItems.Clear();
+                }
+            }
+        }
+
+        private void UserControl_MouseDown(object sender, MouseButtonEventArgs e)
+        {
+            Recentlist_MouseDown(sender, e);
         }
     }
 }