diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/ImagePanel.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/ImagePanel.xaml.cs index b1f051a..6706cb7 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/ImagePanel.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/ImagePanel.xaml.cs @@ -56,6 +56,7 @@ namespace QuickLook.Plugin.ImageViewer viewPanel.MouseLeftButtonDown += ViewPanel_MouseLeftButtonDown; viewPanel.MouseMove += ViewPanel_MouseMove; + viewPanel.ManipulationInertiaStarting += ViewPanel_ManipulationInertiaStarting; viewPanel.ManipulationStarting += ViewPanel_ManipulationStarting; viewPanel.ManipulationDelta += ViewPanel_ManipulationDelta; } @@ -128,7 +129,16 @@ namespace QuickLook.Plugin.ImageViewer private void ImagePanel_SizeChanged(object sender, SizeChangedEventArgs e) { if (ZoomToFit) - DoZoomToFit(false); + DoZoomToFit(); + } + + private void ViewPanel_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e) + { + e.TranslationBehavior = new InertiaTranslationBehavior + { + InitialVelocity = e.InitialVelocities.LinearVelocity, + DesiredDeceleration = 10.0 * 96.0 / (1000.0 * 1000.0) + }; } private void ViewPanel_ManipulationStarting(object sender, ManipulationStartingEventArgs e) @@ -220,7 +230,7 @@ namespace QuickLook.Plugin.ImageViewer viewPanel.ScrollToVerticalOffset(point.Y); } - public void DoZoomToFit(bool suppressEvent) + public void DoZoomToFit() { if (viewPanelImage.Source == null) return; @@ -228,7 +238,7 @@ namespace QuickLook.Plugin.ImageViewer var factor = Math.Min(viewPanel.ActualWidth / viewPanelImage.Source.Width, viewPanel.ActualHeight / viewPanelImage.Source.Height); - Zoom(factor, true, suppressEvent); + Zoom(factor, true); } public void ResetZoom() diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs index dc70034..66cc674 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs @@ -34,6 +34,8 @@ namespace QuickLook.Plugin.PDFViewer { private const double MinZoomFactor = 0.1d; private const double MaxZoomFactor = 3d; + private int _changePageDeltaSum; + private bool _pdfLoaded; private double _viewRenderFactor = 1d; @@ -103,9 +105,23 @@ namespace QuickLook.Plugin.PDFViewer const double tolerance = 0.0001d; if (Math.Abs(pos.Y) < tolerance && delta > 0) + { + _changePageDeltaSum += delta; + if (Math.Abs(_changePageDeltaSum) < 20) + return; + PrevPage(); - else if (Math.Abs(pos.Y - size.Height) < tolerance && delta < 0) + _changePageDeltaSum = 0; + } + else if (Math.Abs(pos.Y - size.Height) < tolerance && delta < -0) + { + _changePageDeltaSum += delta; + if (Math.Abs(_changePageDeltaSum) < 20) + return; + NextPage(); + _changePageDeltaSum = 0; + } } private void NextPage() @@ -193,7 +209,7 @@ namespace QuickLook.Plugin.PDFViewer OnPropertyChanged("PageIds"); CurrentPage = 0; - pagePanel.DoZoomToFit(true); + pagePanel.DoZoomToFit(); } protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.xaml b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.xaml index b25ce2b..40e52d5 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.xaml +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.xaml @@ -11,6 +11,6 @@ UseLayoutRounding="True"> + WordWrap="True" IsReadOnly="True" IsManipulationEnabled="True" /> \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.xaml.cs index 8bdb826..2145f0e 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.xaml.cs @@ -18,6 +18,7 @@ using System.IO; using System.Text; using System.Windows.Controls; +using System.Windows.Input; using System.Windows.Media; using ICSharpCode.AvalonEdit.Highlighting; @@ -32,12 +33,48 @@ namespace QuickLook.Plugin.TextViewer { InitializeComponent(); + viewer.ManipulationInertiaStarting += Viewer_ManipulationInertiaStarting; + viewer.ManipulationStarting += Viewer_ManipulationStarting; + viewer.ManipulationDelta += Viewer_ManipulationDelta; + + viewer.PreviewMouseWheel += Viewer_MouseWheel; + viewer.FontFamily = new FontFamily(context.GetString("Editor_FontFamily", failsafe: "Consolas")); LoadFile(path); } + private void Viewer_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e) + { + e.TranslationBehavior = new InertiaTranslationBehavior + { + InitialVelocity = e.InitialVelocities.LinearVelocity, + DesiredDeceleration = 10.0 * 96.0 / (1000.0 * 1000.0) + }; + } + + private void Viewer_MouseWheel(object sender, MouseWheelEventArgs e) + { + e.Handled = true; + + viewer.ScrollToVerticalOffset(viewer.VerticalOffset - e.Delta); + } + + private void Viewer_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) + { + e.Handled = true; + + var delta = e.DeltaManipulation; + viewer.ScrollToVerticalOffset(viewer.VerticalOffset - delta.Translation.Y); + } + + private void Viewer_ManipulationStarting(object sender, ManipulationStartingEventArgs e) + { + e.ManipulationContainer = this; + e.Mode = ManipulationModes.Translate; + } + private void LoadFile(string path) { using (var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))