Browse Source

快捷键-调整快捷键实现方式

ZhouJieSheng 1 year ago
parent
commit
f63fb44b81

+ 2 - 1
PDF Office/Helper/GlobalCommands.cs

@@ -8,10 +8,11 @@ using System.Threading.Tasks;
 namespace PDF_Master.Helper
 namespace PDF_Master.Helper
 {
 {
     /// <summary>
     /// <summary>
-    /// 全局可用的命令 注册后,在任何界面可以当作静态资源绑定
+    /// 全局可用的命令 注册后,在任何界面可以当作静态资源绑定(需要留意 该命令没有办法区分页签,需要谨慎使用)
     /// </summary>
     /// </summary>
     public static class GlobalCommands
     public static class GlobalCommands
     {
     {
+        //一下命令已调整成其他方式实现
         public static CompositeCommand PrePageCommand = new CompositeCommand();
         public static CompositeCommand PrePageCommand = new CompositeCommand();
 
 
         public static CompositeCommand NextPageCommand = new CompositeCommand();
         public static CompositeCommand NextPageCommand = new CompositeCommand();

+ 25 - 21
PDF Office/ViewModels/BottomToolContentViewModel.cs

@@ -245,6 +245,21 @@ namespace PDF_Master.ViewModels
         /// </summary>
         /// </summary>
         public DelegateCommand<object> PreviewKeyDown { get; set; }
         public DelegateCommand<object> PreviewKeyDown { get; set; }
 
 
+        /// <summary>
+        /// 进入单页
+        /// </summary>
+        public DelegateCommand SinglePageCommand { get; set; }
+
+        /// <summary>
+        /// 进入双页
+        /// </summary>
+        public DelegateCommand DoublePageCommand { get; set; }
+
+        /// <summary>
+        /// 回到实际大小
+        /// </summary>
+        public DelegateCommand RealSizeCommand { get; set; }
+
         private bool isShowViewModular = false;
         private bool isShowViewModular = false;
 
 
         /// <summary>
         /// <summary>
@@ -441,6 +456,9 @@ namespace PDF_Master.ViewModels
             ShowViewModularCommand = new DelegateCommand<object>(ShowViewModularEvent);
             ShowViewModularCommand = new DelegateCommand<object>(ShowViewModularEvent);
             PreviewKeyDown = new DelegateCommand<object>(previewkeydown);
             PreviewKeyDown = new DelegateCommand<object>(previewkeydown);
             PreViewCommand = new DelegateCommand(undo);
             PreViewCommand = new DelegateCommand(undo);
+            SinglePageCommand = new DelegateCommand(()=> { IsSingleView = true; });
+            DoublePageCommand = new DelegateCommand(()=> { IsDoubleView = true; });
+            RealSizeCommand = new DelegateCommand(ZoomToRealSize);
 
 
             NextViewCommnad = new DelegateCommand(redo);
             NextViewCommnad = new DelegateCommand(redo);
 
 
@@ -927,8 +945,12 @@ namespace PDF_Master.ViewModels
             }
             }
             if(e.PropertyName== "IsPropertyOpen")
             if(e.PropertyName== "IsPropertyOpen")
             {
             {
-                //监听的属性面板的变化
-                IsShowViewModular = ViewContentViewModel.IsPropertyOpen;
+                //右上角按钮收起属性面板后,底部工具栏按钮状态同步变化
+                if (ViewContentViewModel.IsPropertyOpen == false)
+                {
+                    //监听的属性面板的变化
+                    IsShowViewModular = ViewContentViewModel.IsPropertyOpen;
+                }
             }
             }
         }
         }
 
 
@@ -1067,6 +1089,7 @@ namespace PDF_Master.ViewModels
             if (viewContentViewModel != null)
             if (viewContentViewModel != null)
             {
             {
                 this.ViewContentViewModel = viewContentViewModel;
                 this.ViewContentViewModel = viewContentViewModel;
+                ViewContentViewModel.bottom = this;
                 IsShowViewModular = viewContentViewModel.IsPropertyOpen;
                 IsShowViewModular = viewContentViewModel.IsPropertyOpen;
                 viewContentViewModel.PropertyChanged -= ViewContentViewModel_PropertyChanged;
                 viewContentViewModel.PropertyChanged -= ViewContentViewModel_PropertyChanged;
                 viewContentViewModel.PropertyChanged += ViewContentViewModel_PropertyChanged;
                 viewContentViewModel.PropertyChanged += ViewContentViewModel_PropertyChanged;
@@ -1094,25 +1117,6 @@ namespace PDF_Master.ViewModels
                 }
                 }
                 CurrentZoom = PDFViewer.ZoomFactor * 100;
                 CurrentZoom = PDFViewer.ZoomFactor * 100;
                 PDFViewer.InfoChanged += PDFViewer_InfoChanged;
                 PDFViewer.InfoChanged += PDFViewer_InfoChanged;
-            }
-
-            //避免重复注册
-            if (GlobalCommands.FirstPageCommand.RegisteredCommands.Count < 1)
-            {
-                //注册成全局命令
-                GlobalCommands.FirstPageCommand.RegisterCommand(FirstPageCommand);
-                GlobalCommands.LastPageCommand.RegisterCommand(LastPageCommand);
-                GlobalCommands.NextPageCommand.RegisterCommand(NextPageCommand);
-                GlobalCommands.PrePageCommand.RegisterCommand(PrePageCommand);
-                GlobalCommands.PreViewCommand.RegisterCommand(PreViewCommand);
-                GlobalCommands.NextViewCommand.RegisterCommand(NextViewCommnad);
-                GlobalCommands.UpCommand.RegisterCommand(UpCommand);
-                GlobalCommands.DownCommand.RegisterCommand(DownCommand);
-                GlobalCommands.SinglePageCommand.RegisterCommand(new DelegateCommand(() => { IsSingleView = true; }));
-                GlobalCommands.DoublePageCommand.RegisterCommand(new DelegateCommand(() => { IsDoubleView = true; }));
-                GlobalCommands.ZoomInCommand.RegisterCommand(ZoomInCommand);
-                GlobalCommands.ZoomOutPageCommand.RegisterCommand(ZoomOutCommand);
-                GlobalCommands.RealSizeCommand.RegisterCommand(new DelegateCommand(() => { ZoomToRealSize(); }));
             }
             }
         }
         }
 
 

+ 131 - 9
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -210,6 +210,9 @@ namespace PDF_Master.ViewModels
         public CPDFViewer PDFViewer { get; set; }
         public CPDFViewer PDFViewer { get; set; }
         public bool ReadModeIsShowProperty { get; set; } = false;
         public bool ReadModeIsShowProperty { get; set; } = false;
         public MainContentViewModel mainViewModel { get; set; }
         public MainContentViewModel mainViewModel { get; set; }
+
+        public BottomToolContentViewModel bottom { get; set; }
+
         public bool IsSettingOut = false;
         public bool IsSettingOut = false;
         public IRegionManager region;
         public IRegionManager region;
 
 
@@ -774,6 +777,39 @@ namespace PDF_Master.ViewModels
 
 
         public DelegateCommand<object> OpenPropertyCommand { get; set; }
         public DelegateCommand<object> OpenPropertyCommand { get; set; }
 
 
+        /// <summary>
+        /// 用于底部工具栏的部分Bug
+        /// </summary>
+        public DelegateCommand RealSizeCommand { get; set; }
+
+        public DelegateCommand OpenFullCommand { get; set; }
+
+        public DelegateCommand SinglePageCommand { get; set; }
+
+        public DelegateCommand DoublePageCommand { get; set; }
+
+        public DelegateCommand FirstPageCommand { get; set; }
+
+        public DelegateCommand LastPageCommand { get; set; }
+
+        public DelegateCommand UpCommand { get; set; }
+
+        public DelegateCommand DownCommand { get; set; }
+
+
+        public DelegateCommand PrePageCommand { get; set; }
+
+        public DelegateCommand NextPageCommmand { get; set; }
+
+        public DelegateCommand PreViewCommand { get; set; }
+
+        public DelegateCommand NextViewCommand { get; set; }
+
+        public DelegateCommand ZoomInCommand { get; set; }
+
+        public DelegateCommand ZoomOutCommand { get; set; }
+
+
         #endregion 命令
         #endregion 命令
 
 
         public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
         public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
@@ -821,6 +857,22 @@ namespace PDF_Master.ViewModels
             SettingsCommand = new DelegateCommand(SettingsEvent);
             SettingsCommand = new DelegateCommand(SettingsEvent);
             CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
             CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
             ClosePropertyCommand = new DelegateCommand(CloseProperty);
             ClosePropertyCommand = new DelegateCommand(CloseProperty);
+            //底部工具栏相关的命令  绑在这一层响应更快
+            RealSizeCommand = new DelegateCommand(realsize);
+            OpenFullCommand = new DelegateCommand(OpenFullWindow);
+            FirstPageCommand = new DelegateCommand(firstpage);
+            LastPageCommand = new DelegateCommand(lastpage);
+            PreViewCommand = new DelegateCommand(preview);
+            NextViewCommand = new DelegateCommand(nextview);
+            PrePageCommand = new DelegateCommand(prepage);
+            NextPageCommmand = new DelegateCommand(nextpage);
+            ZoomInCommand = new DelegateCommand(zoomin);
+            ZoomOutCommand = new DelegateCommand(zoomout);
+            UpCommand = new DelegateCommand(up);
+            DownCommand = new DelegateCommand(down);
+            SinglePageCommand = new DelegateCommand(singlepage);
+            DoublePageCommand = new DelegateCommand(doublepage);
+
             //未显示时无法注册上Region名称
             //未显示时无法注册上Region名称
             ToolContentVisible = Visibility.Visible;
             ToolContentVisible = Visibility.Visible;
             ToolsBarContentVisible = Visibility.Visible;
             ToolsBarContentVisible = Visibility.Visible;
@@ -854,6 +906,76 @@ namespace PDF_Master.ViewModels
             StartAutoSave();
             StartAutoSave();
         }
         }
 
 
+        private void doublepage()
+        {
+            bottom?.DoublePageCommand.Execute();
+        }
+
+        private void singlepage()
+        {
+            bottom?.SinglePageCommand.Execute();
+        }
+
+        private void down()
+        {
+            bottom?.DownCommand.Execute();
+        }
+
+        private void up()
+        {
+            bottom?.UpCommand.Execute();
+        }
+
+        private void zoomin()
+        {
+            bottom?.ZoomInCommand.Execute();
+        }
+
+        private void zoomout()
+        {
+            bottom?.ZoomOutCommand.Execute();
+        }
+
+        private void nextpage()
+        {
+            bottom?.NextPageCommand.Execute();
+        }
+
+        private void prepage()
+        {
+            bottom?.PrePageCommand.Execute();
+        }
+
+        private void nextview()
+        {
+
+            bottom?.NextViewCommnad.Execute();
+        }
+
+        private void preview()
+        {
+            bottom?.PreViewCommand.Execute();
+        }
+
+        private void lastpage()
+        {
+            bottom?.LastPageCommand.Execute();
+        }
+
+        private void firstpage()
+        {
+            bottom?.FirstPageCommand.Execute();
+        }
+
+
+        /// <summary>
+        /// 底部工具栏的缩放至实际大小
+        /// </summary>
+        private void realsize()
+        {
+            bottom?.RealSizeCommand.Execute();
+        }
+
         /// <summary>
         /// <summary>
         /// 进入全屏模式
         /// 进入全屏模式
         /// </summary>
         /// </summary>
@@ -2245,6 +2367,8 @@ namespace PDF_Master.ViewModels
                 parameters.Add(ParameterNames.ViewContentViewModel, this);
                 parameters.Add(ParameterNames.ViewContentViewModel, this);
                 region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
                 region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
             }
             }
+            PDFViewer.SnapsToDevicePixels = true;
+            PDFViewer.UseLayoutRounding = true;
             region.AddToRegion(ViwerRegionName, PDFViewer);
             region.AddToRegion(ViwerRegionName, PDFViewer);
 
 
             if (App.mainWindowViewModel != null)
             if (App.mainWindowViewModel != null)
@@ -2369,11 +2493,11 @@ namespace PDF_Master.ViewModels
         /// <summary>
         /// <summary>
         /// 已有路径文档的保存逻辑
         /// 已有路径文档的保存逻辑
         /// </summary>
         /// </summary>
-        public bool saveFile(bool autosave=false)
+        public bool saveFile(bool autosave = false)
         {
         {
             try
             try
             {
             {
-                if ((string.IsNullOrEmpty(PDFViewer.Document.FilePath) || mainViewModel.NewFile)&&!autosave)
+                if ((string.IsNullOrEmpty(PDFViewer.Document.FilePath) || mainViewModel.NewFile) && !autosave)
                     return saveAsFile();
                     return saveAsFile();
 
 
                 //文档已被修复时 提示另存为
                 //文档已被修复时 提示另存为
@@ -2525,7 +2649,7 @@ namespace PDF_Master.ViewModels
                                       OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
                                       OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
                                       try
                                       try
                                       {
                                       {
-                                          if (info!=null&&!string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
+                                          if (info != null && !string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
                                           {
                                           {
                                               var size = PDFViewer.Document.GetPageSize(0);
                                               var size = PDFViewer.Document.GetPageSize(0);
                                               System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
                                               System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
@@ -2569,12 +2693,10 @@ namespace PDF_Master.ViewModels
                     //弹窗前 激活主窗体
                     //弹窗前 激活主窗体
                     //App.Current.MainWindow.Activate();
                     //App.Current.MainWindow.Activate();
                     AlertsMessage alertsMessage = new AlertsMessage();
                     AlertsMessage alertsMessage = new AlertsMessage();
-                    System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
-                    {
-
-                        //文件被占用 保存失败时
-                        alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
-                    }));
+                    //文件被占用 保存失败时
+                    alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
+                    //显示当前窗体,防止窗口置底
+                    App.Current.MainWindow.Activate();
                     if (alertsMessage.result == ContentResult.Ok)
                     if (alertsMessage.result == ContentResult.Ok)
                         return saveAsFile();
                         return saveAsFile();
                     else
                     else

+ 23 - 22
PDF Office/Views/ViewContent.xaml

@@ -20,6 +20,7 @@
     DragOver="UserControl_DragOver"
     DragOver="UserControl_DragOver"
     Drop="UserControl_Drop"
     Drop="UserControl_Drop"
     IsVisibleChanged="UserControl_IsVisibleChanged"
     IsVisibleChanged="UserControl_IsVisibleChanged"
+    Loaded="UserControl_Loaded"
     MouseDown="UserControl_MouseDown"
     MouseDown="UserControl_MouseDown"
     Unloaded="UserControl_Unloaded"
     Unloaded="UserControl_Unloaded"
     mc:Ignorable="d">
     mc:Ignorable="d">
@@ -87,71 +88,71 @@
         <KeyBinding Command="{Binding RedoCommand}" Gesture="Ctrl+Shift+Z" />
         <KeyBinding Command="{Binding RedoCommand}" Gesture="Ctrl+Shift+Z" />
         <KeyBinding
         <KeyBinding
             Key="Up"
             Key="Up"
-            Command="{x:Static helper:GlobalCommands.FirstPageCommand}"
+            Command="{Binding FirstPageCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
         <KeyBinding
         <KeyBinding
             Key="Down"
             Key="Down"
-            Command="{x:Static helper:GlobalCommands.LastPageCommand}"
+            Command="{Binding LastPageCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
-        <KeyBinding Key="Up" Command="{x:Static helper:GlobalCommands.UpCommand}" />
-        <KeyBinding Key="Down" Command="{x:Static helper:GlobalCommands.DownCommand}" />
-        <KeyBinding Key="Left" Command="{x:Static helper:GlobalCommands.PrePageCommand}" />
-        <KeyBinding Key="PageUp" Command="{x:Static helper:GlobalCommands.PrePageCommand}" />
-        <KeyBinding Key="PageDown" Command="{x:Static helper:GlobalCommands.NextPageCommand}" />
-        <KeyBinding Key="Right" Command="{x:Static helper:GlobalCommands.NextPageCommand}" />
+        <KeyBinding Key="Up" Command="{Binding UpCommand}" />
+        <KeyBinding Key="Left" Command="{Binding PrePageCommand}" />
+        <KeyBinding Key="Left" Command="{Binding PrePageCommand}" />
+        <KeyBinding Key="Down" Command="{Binding DownCommand}" />
+        <KeyBinding Key="PageDown" Command="{Binding NextPageCommmand}" />
+        <KeyBinding Key="PageDown" Command="{Binding NextPageCommmand}" />
         <KeyBinding
         <KeyBinding
             Key="B"
             Key="B"
             Command="{x:Static helper:GlobalCommands.BookMarkCommand}"
             Command="{x:Static helper:GlobalCommands.BookMarkCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
-        <KeyBinding Key="F11" Command="{x:Static helper:GlobalCommands.FullWindowCommand}" />
+        <KeyBinding Key="F11" Command="{Binding OpenFullCommand}" />
         <KeyBinding
         <KeyBinding
             Key="NumPad1"
             Key="NumPad1"
-            Command="{x:Static helper:GlobalCommands.SinglePageCommand}"
+            Command="{Binding SinglePageCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
         <KeyBinding
         <KeyBinding
             Key="D1"
             Key="D1"
-            Command="{x:Static helper:GlobalCommands.SinglePageCommand}"
+            Command="{Binding SinglePageCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
         <KeyBinding
         <KeyBinding
             Key="NumPad2"
             Key="NumPad2"
-            Command="{x:Static helper:GlobalCommands.DoublePageCommand}"
+            Command="{Binding DoublePageCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
         <KeyBinding
         <KeyBinding
             Key="D2"
             Key="D2"
-            Command="{x:Static helper:GlobalCommands.DoublePageCommand}"
+            Command="{Binding DoublePageCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
         <KeyBinding
         <KeyBinding
             Key="NumPad0"
             Key="NumPad0"
-            Command="{x:Static helper:GlobalCommands.RealSizeCommand}"
+            Command="{Binding RealSizeCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
         <KeyBinding
         <KeyBinding
             Key="D0"
             Key="D0"
-            Command="{x:Static helper:GlobalCommands.RealSizeCommand}"
+            Command="{Binding RealSizeCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
         <KeyBinding
         <KeyBinding
             Key="Add"
             Key="Add"
-            Command="{x:Static helper:GlobalCommands.ZoomInCommand}"
+            Command="{Binding ZoomInCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
         <KeyBinding
         <KeyBinding
             Key="OemPlus"
             Key="OemPlus"
-            Command="{x:Static helper:GlobalCommands.ZoomInCommand}"
+            Command="{Binding ZoomInCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
         <KeyBinding
         <KeyBinding
             Key="Subtract"
             Key="Subtract"
-            Command="{x:Static helper:GlobalCommands.ZoomOutPageCommand}"
+            Command="{Binding ZoomOutCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
         <KeyBinding
         <KeyBinding
             Key="OemMinus"
             Key="OemMinus"
-            Command="{x:Static helper:GlobalCommands.ZoomOutPageCommand}"
+            Command="{Binding ZoomOutCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
 
 
         <KeyBinding
         <KeyBinding
             Key="OemOpenBrackets"
             Key="OemOpenBrackets"
-            Command="{x:Static helper:GlobalCommands.PreViewCommand}"
+            Command="{Binding PreViewCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
         <KeyBinding
         <KeyBinding
             Key="OemCloseBrackets"
             Key="OemCloseBrackets"
-            Command="{x:Static helper:GlobalCommands.NextViewCommand}"
+            Command="{Binding NextViewCommand}"
             Modifiers="Ctrl" />
             Modifiers="Ctrl" />
     </UserControl.InputBindings>
     </UserControl.InputBindings>
 
 
@@ -717,10 +718,10 @@
             Width="{Binding ActualWidth, ElementName=ReadModeContent, Mode=OneWay}"
             Width="{Binding ActualWidth, ElementName=ReadModeContent, Mode=OneWay}"
             Height="44"
             Height="44"
             Margin="0,0,0,5"
             Margin="0,0,0,5"
-            IsHitTestVisible="False"
             HorizontalAlignment="Center"
             HorizontalAlignment="Center"
             VerticalAlignment="Bottom"
             VerticalAlignment="Bottom"
             Fill="Transparent"
             Fill="Transparent"
+            IsHitTestVisible="False"
             MouseEnter="RectangleReadMode_MouseEnter"
             MouseEnter="RectangleReadMode_MouseEnter"
             Visibility="Collapsed" />
             Visibility="Collapsed" />
     </Grid>
     </Grid>

+ 7 - 0
PDF Office/Views/ViewContent.xaml.cs

@@ -540,5 +540,12 @@ namespace PDF_Master.Views
            
            
 
 
         }
         }
+
+        private void UserControl_Loaded(object sender, RoutedEventArgs e)
+        {
+            //自动聚焦,修复快捷键无响应的问题
+            this.Focusable = true;
+            this.Focus();
+        }
     }
     }
 }
 }