callmeyan 2b3e330841 feat: ️新增全局回调方法,优化修订模式处理
在 `Bridge.cs` 文件中:
- 修改 `ProcessStartInfo` 的 `Verb` 属性赋值方式,保持不变。
- 新增 `Callback` 方法,用于全局回调。
- 新增 `CheckInTrackRevisions` 方法,用于检查文档是否处于修订模式,并根据用户选择关闭修订模式或返回相应结果。
- 修改提示信息内容,并在用户选择不关闭修订模式时,返回相应错误信息。
- 调整 `JSONObject.Create()` 的链式调用格式。
- 调整 `InitProofreadCacheList` 方法的参数格式。

在 `FormMessage.cs` 文件中:
- 新增 `ShowMessage` 方法的重载版本,支持自定义确认和取消按钮的文本。

在 `DocumentInfo.cs` 文件中:
- 新增 `GlobalCallback` 方法,用于调用 Web 全局回调函数。

在 `ThisAddIn.cs` 文件中:
- 修改日志记录信息,增加文档修订模式的状态。
- 新增 `GlobalCallback` 方法,用于全局回调。
2025-03-29 21:25:19 +08:00

161 lines
4.9 KiB
C#

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace AIProofread.Controls
{
public partial class FormMessage : BaseWinForm
{
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
/// <summary>
/// 初始化宽度
/// </summary>
private const int INIT_WIDTH = 380;
public FormMessage()
{
InitializeComponent();
}
private void SetMessage(string message)
{
LblMeesage.Text = message;
}
private string currentConfirmText;
private string currentConfirmAction;
private void SetConfirmText(string confirmText)
{
currentConfirmText = confirmText;
if (confirmText == "proofread")
{
confirmText = "重新校对";
}
BtnConfirm.Text = confirmText;
BtnConfirm.Visible = true;
BtnConfirm.Enabled = true;
}
private void HideConfirm()
{
BtnConfirm.Visible = false;
BtnConfirm.Enabled = false;
BtnClose.Location = new System.Drawing.Point((
(this.Width - BtnClose.Width) / 2
), BtnClose.Location.Y);
}
/// <summary>
/// 计算缩放
/// </summary>
/// <param name="size"></param>
/// <returns></returns>
private int ScaleSize(int size)
{
return (int)(size * this.Width * 1.0 / INIT_WIDTH);
}
private void ResetButtons()
{
BtnClose.Location = new System.Drawing.Point(ScaleSize(200), BtnClose.Location.Y);
BtnConfirm.Location = new System.Drawing.Point(ScaleSize(60), BtnConfirm.Location.Y);
BtnConfirm.Visible = true;
BtnConfirm.Enabled = true;
}
public void HideCloseBtn()
{
BtnClose.Visible = false;
LblMeesage.Location = new System.Drawing.Point(LblMeesage.Location.X, LblMeesage.Location.Y + ScaleSize(30));
}
public static FormMessage ShowMessage(string message, int closeDelay = 3000)
{
FormMessage formMessage = new FormMessage();
formMessage.SetMessage(message);
formMessage.HideConfirm();
// 先置顶
formMessage.TopMost = true;
formMessage.Show();
return formMessage;
}
public static DialogResult ShowMessage(string message, string confirmText = "确认",string cancelText="取消", string confirmAction = null)
{
FormMessage formMessage = new FormMessage();
formMessage.SetMessage(message);
formMessage.currentConfirmAction = confirmAction;
formMessage.BtnClose.Text = cancelText;
if (string.IsNullOrEmpty(confirmText))
{
formMessage.HideConfirm();
}
else
{
formMessage.BtnConfirm.Text = confirmText;
formMessage.ResetButtons();
}
return formMessage.ShowDialog();
}
public static DialogResult ShowMessage(string message, string confirmText = "确认", string confirmAction = null)
{
FormMessage formMessage = new FormMessage();
formMessage.SetMessage(message);
formMessage.currentConfirmAction = confirmAction;
if (string.IsNullOrEmpty(confirmText))
{
formMessage.HideConfirm();
}
else
{
formMessage.BtnConfirm.Text = confirmText;
formMessage.ResetButtons();
}
return formMessage.ShowDialog();
}
private void BtnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void BtnConfirm_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(currentConfirmAction))
{
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Globals.ThisAddIn.SendMessageToWeb(currentConfirmAction, time);
}
this.Close();
}
private void IconClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void HanleMouseDown()
{
ReleaseCapture();
SendMessage(this.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
private void label1_MouseDown(object sender, MouseEventArgs e)
{
HanleMouseDown();
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
HanleMouseDown();
}
}
}