- 引入 log4net 库,统一日志记录方式,提升可维护性。 - 优化异常处理,增加详细日志记录,增强代码健壮性。 - 调整资源文件引用,新增图标资源,删除无用资源。 - 优化文档事件处理逻辑,改进面板显示与隐藏逻辑。 - 增加对 WPS 环境的支持,动态调整功能行为。 - 禁用部分功能(如常识性检测、客服、升级和帮助)。 - 删除冗余代码,清理注释,统一代码风格。 - 更新程序集版本至 2.2.5,改进调试与生产环境配置。
161 lines
4.8 KiB
C#
161 lines
4.8 KiB
C#
using log4net;
|
|
using log4net.Repository.Hierarchy;
|
|
using Microsoft.Office.Interop.Word;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace AIProofread.Model
|
|
{
|
|
/// <summary>
|
|
/// 文档列表
|
|
/// </summary>
|
|
public class DocumentList
|
|
{
|
|
public ILog Logger = LogHelper.GetLogger(typeof(DocumentList));
|
|
public List<DocumentInfo> documentList = new List<DocumentInfo>();
|
|
public DocumentInfo ActiveDocument { get; set; }
|
|
public int Count => documentList.Count;
|
|
|
|
public void Add(DocumentInfo documentInfo)
|
|
{
|
|
documentList.Add(documentInfo);
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
documentList.ForEach(doc => { doc.Dispose(); });
|
|
|
|
documentList.Clear();
|
|
}
|
|
|
|
public DocumentInfo Get(int index)
|
|
{
|
|
return documentList[index];
|
|
}
|
|
public DocumentInfo GetById(int id)
|
|
{
|
|
return Count > 0 ? documentList.FirstOrDefault(x => x.Id == id) : null;
|
|
}
|
|
public DocumentInfo Get(string uniqueId)
|
|
{
|
|
return Count > 0 ? documentList.FirstOrDefault(x => x.UniqueId == uniqueId) : null;
|
|
}
|
|
public DocumentInfo Get(Document doc)
|
|
{
|
|
return Count > 0 && doc != null ? documentList.FirstOrDefault(x => x.CurrentDocument == doc) : null;
|
|
}
|
|
|
|
public DocumentInfo GetActive()
|
|
{
|
|
// documentList.FirstOrDefault(x => x.IsActive)
|
|
return Count > 0 ? ActiveDocument : null;
|
|
}
|
|
|
|
public bool Contains(DocumentInfo documentInfo)
|
|
{
|
|
return Count > 0 && documentList.Contains(documentInfo);
|
|
}
|
|
|
|
public bool Contains(string uniqueId)
|
|
{
|
|
return Count > 0 && documentList.Any(x => x.UniqueId == uniqueId);
|
|
}
|
|
|
|
// 通过文档判断是否包含
|
|
public bool Contains(Document originDocument)
|
|
{
|
|
return Count > 0 && originDocument != null && documentList.Any(x => x.CurrentDocument == originDocument);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 移除文档
|
|
/// </summary>
|
|
/// <param name="documentInfo"></param>
|
|
/// <returns></returns>
|
|
public bool Remove(DocumentInfo documentInfo)
|
|
{
|
|
return documentList.Remove(documentInfo);
|
|
}
|
|
public bool Remove(Document originDocument)
|
|
{
|
|
if (Count > 0 && originDocument != null)
|
|
{
|
|
documentList.RemoveAll(x =>
|
|
{
|
|
if (x.CurrentDocument == originDocument)
|
|
{
|
|
x.Close();
|
|
return true;
|
|
}
|
|
return false;
|
|
});
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取文档的索引
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <returns></returns>
|
|
public int IndexOf(DocumentInfo item)
|
|
{
|
|
return documentList.IndexOf(item);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置当前激活的文档
|
|
/// </summary>
|
|
/// <param name="originDocument"></param>
|
|
public DocumentInfo SetActiveDocument(Document originDocument)
|
|
{
|
|
Logger.Debug("SetActiveDocument(113): " + originDocument.Name);
|
|
if (originDocument == null) return null;
|
|
var document = InitDocument(originDocument);
|
|
if (document == null)
|
|
{
|
|
Logger.Error("Document not exists SetActiveDocument");
|
|
return null;
|
|
}
|
|
|
|
if (ActiveDocument != null && ActiveDocument.CurrentDocument != originDocument)
|
|
{
|
|
// WPS 只有一个窗口 所以需要先关闭之前文档的面板
|
|
ActiveDocument?.Deactive();
|
|
}
|
|
// 如果存在,则设置激活
|
|
ActiveDocument = document;
|
|
//document.IsActive = true;
|
|
document.Active();
|
|
document.CheckBtnStatus();
|
|
return document;
|
|
}
|
|
|
|
internal void HideAllPane()
|
|
{
|
|
documentList.ForEach(d => d.HidePane());
|
|
}
|
|
|
|
public DocumentInfo InitDocument(Document originDocument)
|
|
{
|
|
var document = Get(originDocument);
|
|
|
|
try
|
|
{
|
|
// 如果不存在,则添加
|
|
if (document == null)
|
|
{
|
|
Logger.Debug("Document not exists,InitDocument: " + originDocument.Name);
|
|
document = new DocumentInfo(originDocument);
|
|
Add(document);
|
|
}
|
|
}catch(Exception ex)
|
|
{
|
|
Logger.Error("InitDocument error: " + ex.Message,ex);
|
|
}
|
|
return document;
|
|
}
|
|
}
|
|
}
|