improve:图片插入
This commit is contained in:
@@ -34,6 +34,8 @@ namespace Ink_Canvas
|
||||
private bool isClipboardMonitoringEnabled;
|
||||
private BitmapSource lastClipboardImage;
|
||||
private HwndSource _clipboardHwndSource;
|
||||
private DateTime _lastPasteNotificationTime = DateTime.MinValue;
|
||||
private const int PasteNotificationDebounceSeconds = 4;
|
||||
|
||||
// 初始化剪贴板监控
|
||||
private void InitializeClipboardMonitoring()
|
||||
@@ -50,6 +52,7 @@ namespace Ink_Canvas
|
||||
OnSourceInitializedForClipboard(this, EventArgs.Empty);
|
||||
else
|
||||
SourceInitialized += OnSourceInitializedForClipboard;
|
||||
Dispatcher.BeginInvoke(new Action(EnsureClipboardHookInstalled), DispatcherPriority.Loaded);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -57,6 +60,14 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureClipboardHookInstalled()
|
||||
{
|
||||
if (_clipboardHwndSource != null) return;
|
||||
var handle = new WindowInteropHelper(this).Handle;
|
||||
if (handle == IntPtr.Zero) return;
|
||||
OnSourceInitializedForClipboard(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void OnSourceInitializedForClipboard(object sender, EventArgs e)
|
||||
{
|
||||
SourceInitialized -= OnSourceInitializedForClipboard;
|
||||
@@ -92,19 +103,12 @@ namespace Ink_Canvas
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Clipboard.ContainsImage())
|
||||
{
|
||||
if (!Clipboard.ContainsImage())
|
||||
return;
|
||||
|
||||
var clipboardImage = Clipboard.GetImage();
|
||||
if (clipboardImage != null && clipboardImage != lastClipboardImage)
|
||||
{
|
||||
if (clipboardImage != null)
|
||||
lastClipboardImage = clipboardImage;
|
||||
// 在白板模式下显示粘贴提示
|
||||
if (currentMode == 1) // 白板模式
|
||||
{
|
||||
ShowPasteNotification();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -112,20 +116,40 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
|
||||
// 显示粘贴提示
|
||||
private void ShowPasteNotification()
|
||||
public void CheckClipboardImageAndShowPasteNotificationWhenEnteringBoard()
|
||||
{
|
||||
try
|
||||
{
|
||||
Dispatcher.Invoke(() =>
|
||||
if (!Clipboard.ContainsImage())
|
||||
return;
|
||||
|
||||
bool debounceElapsed = (DateTime.Now - _lastPasteNotificationTime).TotalSeconds >= PasteNotificationDebounceSeconds;
|
||||
if (!debounceElapsed)
|
||||
return;
|
||||
|
||||
_lastPasteNotificationTime = DateTime.Now;
|
||||
ShowPasteNotification();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"进入白板时检测剪贴板失败: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// 显示粘贴提示
|
||||
private void ShowPasteNotification()
|
||||
{
|
||||
Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
ShowNotification("检测到剪贴板中有图片,右键点击白板可粘贴");
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"显示粘贴提示失败: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}), DispatcherPriority.Normal);
|
||||
}
|
||||
|
||||
// 处理右键菜单显示
|
||||
@@ -360,9 +384,9 @@ namespace Ink_Canvas
|
||||
ClipboardUpdate?.Invoke();
|
||||
}
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 忽略剪贴板访问错误
|
||||
LogHelper.WriteLogToFile($"剪贴板 NotifyFromMessage 异常: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3027,6 +3027,8 @@ namespace Ink_Canvas
|
||||
}
|
||||
|
||||
StackPanelPPTButtons.Visibility = Visibility.Visible;
|
||||
|
||||
CheckClipboardImageAndShowPasteNotificationWhenEnteringBoard();
|
||||
}
|
||||
|
||||
Topmost = true;
|
||||
@@ -3186,6 +3188,8 @@ namespace Ink_Canvas
|
||||
{
|
||||
Topmost = false;
|
||||
}
|
||||
|
||||
CheckClipboardImageAndShowPasteNotificationWhenEnteringBoard();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Ink_Canvas.Helpers;
|
||||
using Ink_Canvas.Helpers;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -21,6 +21,10 @@ namespace Ink_Canvas
|
||||
{
|
||||
try
|
||||
{
|
||||
if (TextBlockNotice == null || GridNotifications == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
lastNotificationShowTime = Environment.TickCount;
|
||||
|
||||
TextBlockNotice.Text = notice;
|
||||
@@ -36,7 +40,10 @@ namespace Ink_Canvas
|
||||
});
|
||||
}).Start();
|
||||
}
|
||||
catch { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"ShowNotification 异常: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user