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