优化面板按钮逻辑

- 调整 `TaskPane_VisibleChanged` 方法逻辑,增加异步延迟处理和详细日志记录,修复 `CurrentDocument` 引用问题。
- 优化 `CheckBtnStatus` 方法,提升代码可读性并修正按钮状态逻辑。
- 改进 `TaskPane` 释放逻辑,增加对控件的重置操作。
This commit is contained in:
LittleBoy 2025-05-08 16:48:10 +08:00
parent 32e85c62c0
commit a54765e911
2 changed files with 18 additions and 11 deletions

Binary file not shown.

View File

@ -188,7 +188,7 @@ namespace AIProofread.Model
{
try
{
Logger.Debug("激活 for " + CurrentDocument.FullName + " 没有 visible is " + PaneVisible);
Logger.Debug("激活 for " + CurrentDocument.Name + " 没有 visible is " + PaneVisible);
ShowDocumentStatus("Active");
IsActive = true;
if (Config.IS_WPS && null != TaskPane)
@ -212,9 +212,10 @@ namespace AIProofread.Model
{
PaneVisible = TaskPane.Visible;
TaskPane.Visible = false;
Logger.Debug("取消 for " + CurrentDocument.FullName + " current visible " + PaneVisible);
Logger.Debug("取消 for " + CurrentDocument.Name + " current visible " + PaneVisible);
}
}catch (Exception e)
}
catch (Exception e)
{
Logger.Error("Deactive Error", e);
}
@ -227,7 +228,7 @@ namespace AIProofread.Model
// 判断TaskPane是否已经释放
if (null == TaskPane) return;
if (TaskPane.Control.IsDisposed) return;
ProofreadMainControl control = (ProofreadMainControl)TaskPane.Control;
control.ResetWeb();
@ -304,22 +305,28 @@ namespace AIProofread.Model
//
if (Globals.ThisAddIn.ribbon != null)
{
Globals.ThisAddIn.ribbon.BtnShowPanel.Enabled = !PaneVisible && Proofread;
var visible = TaskPane.Visible;
Globals.ThisAddIn.ribbon.BtnShowPanel.Enabled = !visible && Proofread;
Globals.ThisAddIn.ribbon.SetCommonBtnStatus(!Proofreading);
}
}
private void TaskPane_VisibleChanged(object sender, EventArgs e)
{
if (Config.IS_WPS)
// 异步等待500ms
System.Threading.Tasks.Task.Delay(1000).ContinueWith(t =>
{
if(CurrentDocument == Globals.ThisAddIn.ActiveDocument)
Logger.Debug($"2==> VisibleChanged {CurrentDocument.Name} is {TaskPane.Visible}");
if (Config.IS_WPS)
{
Logger.Debug($"VisibleChanged ${CurrentDocument.Name} is {TaskPane.Visible}");
// 如果已经隐藏 则记录隐藏用于(WPS)多面板的切换的处理
PaneVisible = TaskPane.Visible;
if (CurrentDocument == Globals.ThisAddIn.ActiveDocument.CurrentDocument)
{
// 如果已经隐藏 则记录隐藏用于(WPS)多面板的切换的处理
PaneVisible = TaskPane.Visible;
}
}
}
Globals.ThisAddIn.ActiveDocument?.CheckBtnStatus();
});
CheckBtnStatus();
//Globals.ThisAddIn.ribbon.BtnShowPanel.Enabled = !TaskPane.Visible && Proofread;
}