add:长按翻页

This commit is contained in:
2025-08-23 19:43:09 +08:00
parent d01a24f879
commit 70735943c3
6 changed files with 123 additions and 0 deletions
+1
View File
@@ -22,6 +22,7 @@ namespace Ink_Canvas.Helpers
public int PPTLBButtonPosition { get; set; } = 0;
public int PPTRBButtonPosition { get; set; } = 0;
public bool EnablePPTButtonPageClickable { get; set; } = true;
public bool EnablePPTButtonLongPressPageTurn { get; set; } = true;
#endregion
#region Private Fields
+13
View File
@@ -1843,6 +1843,19 @@
<TextBlock
Text="# 开启该选项后,点击页码按钮可以唤起PowerPoint自带的网格缩略图视图。WPS不支持该功能,开启也没用。"
TextWrapping="Wrap" Foreground="#a1a1aa" />
<ui:SimpleStackPanel Orientation="Horizontal"
HorizontalAlignment="Left">
<TextBlock Foreground="#fafafa" Text="PPT 翻页按钮长按翻页"
VerticalAlignment="Center" FontSize="14" Margin="0,0,16,0" />
<ui:ToggleSwitch OnContent="" OffContent=""
Name="ToggleSwitchEnablePPTButtonLongPressPageTurn"
IsOn="True"
FontFamily="Microsoft YaHei UI" FontWeight="Bold"
Toggled="ToggleSwitchEnablePPTButtonLongPressPageTurn_OnToggled" />
</ui:SimpleStackPanel>
<TextBlock
Text="# 开启该选项后,长按PPT翻页按钮可以连续翻页,提高翻页效率。"
TextWrapping="Wrap" Foreground="#a1a1aa" />
</ui:SimpleStackPanel>
<Line HorizontalAlignment="Center" X1="0" Y1="0" X2="400" Y2="0" Stroke="#3f3f46"
StrokeThickness="1" Margin="0,4,0,4" />
+94
View File
@@ -11,6 +11,7 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using Application = System.Windows.Application;
using File = System.IO.File;
using MessageBox = System.Windows.MessageBox;
@@ -80,6 +81,13 @@ namespace Ink_Canvas
private bool isPresentationHaveBlackSpace;
private string pptName;
private bool _isPptClickingBtnTurned;
// 长按翻页相关字段
private DispatcherTimer _longPressTimer;
private bool _isLongPressActive = false;
private bool _isLongPressNext = true; // true为下一页,false为上一页
private const int LongPressDelay = 500; // 长按延迟时间(毫秒)
private const int LongPressInterval = 200; // 长按翻页间隔(毫秒)
#endregion
#region PPT Managers
@@ -98,6 +106,9 @@ namespace Ink_Canvas
{
try
{
// 初始化长按定时器
InitializeLongPressTimer();
// 初始化PPT管理器
_pptManager = new PPTManager();
_pptManager.IsSupportWPS = Settings.PowerPointSettings.IsSupportWPS;
@@ -127,6 +138,7 @@ namespace Ink_Canvas
_pptUIManager.PPTLBButtonPosition = Settings.PowerPointSettings.PPTLBButtonPosition;
_pptUIManager.PPTRBButtonPosition = Settings.PowerPointSettings.PPTRBButtonPosition;
_pptUIManager.EnablePPTButtonPageClickable = Settings.PowerPointSettings.EnablePPTButtonPageClickable;
_pptUIManager.EnablePPTButtonLongPressPageTurn = Settings.PowerPointSettings.EnablePPTButtonLongPressPageTurn;
LogHelper.WriteLogToFile("PPT管理器初始化完成", LogHelper.LogType.Event);
}
@@ -157,6 +169,8 @@ namespace Ink_Canvas
{
_pptManager?.Dispose();
_pptInkManager?.Dispose();
_longPressTimer?.Stop();
_longPressTimer = null;
_pptManager = null;
_pptInkManager = null;
_pptUIManager = null;
@@ -167,6 +181,60 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile($"释放PPT管理器失败: {ex}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 初始化长按定时器
/// </summary>
private void InitializeLongPressTimer()
{
_longPressTimer = new DispatcherTimer();
_longPressTimer.Interval = TimeSpan.FromMilliseconds(LongPressDelay);
_longPressTimer.Tick += OnLongPressTimerTick;
}
/// <summary>
/// 启动长按检测
/// </summary>
/// <param name="sender">触发事件的控件</param>
/// <param name="isNext">是否为下一页按钮</param>
private void StartLongPressDetection(object sender, bool isNext)
{
if (!Settings.PowerPointSettings.EnablePPTButtonLongPressPageTurn) return;
_isLongPressNext = isNext;
_isLongPressActive = false;
_longPressTimer?.Start();
}
/// <summary>
/// 停止长按检测
/// </summary>
private void StopLongPressDetection()
{
_longPressTimer?.Stop();
_isLongPressActive = false;
}
/// <summary>
/// 长按定时器事件处理
/// </summary>
private void OnLongPressTimerTick(object sender, EventArgs e)
{
if (!Settings.PowerPointSettings.EnablePPTButtonLongPressPageTurn) return;
_isLongPressActive = true;
_longPressTimer.Interval = TimeSpan.FromMilliseconds(LongPressInterval);
// 执行翻页
if (_isLongPressNext)
{
BtnPPTSlidesDown_Click(BtnPPTSlidesDown, null);
}
else
{
BtnPPTSlidesUp_Click(BtnPPTSlidesUp, null);
}
}
#endregion
#region New PPT Event Handlers
@@ -1047,6 +1115,12 @@ namespace Ink_Canvas
{
PPTRBPreviousButtonFeedbackBorder.Opacity = 0.15;
}
// 启动长按检测
if (Settings.PowerPointSettings.EnablePPTButtonLongPressPageTurn)
{
StartLongPressDetection(sender, false);
}
}
private void GridPPTControlPrevious_MouseLeave(object sender, MouseEventArgs e)
{
@@ -1067,6 +1141,9 @@ namespace Ink_Canvas
{
PPTRBPreviousButtonFeedbackBorder.Opacity = 0;
}
// 停止长按检测
StopLongPressDetection();
}
private void GridPPTControlPrevious_MouseUp(object sender, MouseButtonEventArgs e)
{
@@ -1087,6 +1164,10 @@ namespace Ink_Canvas
{
PPTRBPreviousButtonFeedbackBorder.Opacity = 0;
}
// 停止长按检测
StopLongPressDetection();
BtnPPTSlidesUp_Click(BtnPPTSlidesUp, null);
}
@@ -1110,6 +1191,12 @@ namespace Ink_Canvas
{
PPTRBNextButtonFeedbackBorder.Opacity = 0.15;
}
// 启动长按检测
if (Settings.PowerPointSettings.EnablePPTButtonLongPressPageTurn)
{
StartLongPressDetection(sender, true);
}
}
private void GridPPTControlNext_MouseLeave(object sender, MouseEventArgs e)
{
@@ -1130,6 +1217,9 @@ namespace Ink_Canvas
{
PPTRBNextButtonFeedbackBorder.Opacity = 0;
}
// 停止长按检测
StopLongPressDetection();
}
private void GridPPTControlNext_MouseUp(object sender, MouseButtonEventArgs e)
{
@@ -1150,6 +1240,10 @@ namespace Ink_Canvas
{
PPTRBNextButtonFeedbackBorder.Opacity = 0;
}
// 停止长按检测
StopLongPressDetection();
BtnPPTSlidesDown_Click(BtnPPTSlidesDown, null);
}
+9
View File
@@ -511,6 +511,13 @@ namespace Ink_Canvas
SaveSettingsToFile();
}
private void ToggleSwitchEnablePPTButtonLongPressPageTurn_OnToggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.PowerPointSettings.EnablePPTButtonLongPressPageTurn = ToggleSwitchEnablePPTButtonLongPressPageTurn.IsOn;
SaveSettingsToFile();
}
private void CheckboxEnableLBPPTButton_IsCheckChanged(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
@@ -883,6 +890,8 @@ namespace Ink_Canvas
_pptUIManager.PPTRSButtonPosition = Settings.PowerPointSettings.PPTRSButtonPosition;
_pptUIManager.PPTLBButtonPosition = Settings.PowerPointSettings.PPTLBButtonPosition;
_pptUIManager.PPTRBButtonPosition = Settings.PowerPointSettings.PPTRBButtonPosition;
_pptUIManager.EnablePPTButtonPageClickable = Settings.PowerPointSettings.EnablePPTButtonPageClickable;
_pptUIManager.EnablePPTButtonLongPressPageTurn = Settings.PowerPointSettings.EnablePPTButtonLongPressPageTurn;
_pptUIManager.UpdateNavigationPanelsVisibility();
_pptUIManager.UpdateNavigationButtonStyles();
}
@@ -367,6 +367,9 @@ namespace Ink_Canvas
ToggleSwitchEnablePPTButtonPageClickable.IsOn =
Settings.PowerPointSettings.EnablePPTButtonPageClickable;
ToggleSwitchEnablePPTButtonLongPressPageTurn.IsOn =
Settings.PowerPointSettings.EnablePPTButtonLongPressPageTurn;
var dops = Settings.PowerPointSettings.PPTButtonsDisplayOption.ToString();
var dopsc = dops.ToCharArray();
if ((dopsc[0] == '1' || dopsc[0] == '2') && (dopsc[1] == '1' || dopsc[1] == '2') &&
+3
View File
@@ -262,6 +262,9 @@ namespace Ink_Canvas
[JsonProperty("enablePPTButtonPageClickable")]
public bool EnablePPTButtonPageClickable { get; set; } = true;
[JsonProperty("enablePPTButtonLongPressPageTurn")]
public bool EnablePPTButtonLongPressPageTurn { get; set; } = true;
// -- new --
[JsonProperty("powerPointSupport")]