feat: 调整方法参数和文件保存逻辑
This commit is contained in:
parent
200f415ac6
commit
e52fd188b6
Binary file not shown.
@ -329,7 +329,7 @@ namespace AIProofread
|
||||
/// </summary>
|
||||
/// <param name="documentId"></param>
|
||||
/// <param name="callback"></param>
|
||||
public void CheckInTrackRevisions(string message,int documentId, string callbackId)
|
||||
public void CheckInTrackRevisions(string message, int documentId, string callbackId)
|
||||
{
|
||||
var doc = documentId > 0 ? Globals.ThisAddIn.GetDocumentById(documentId) : Globals.ThisAddIn.ActiveDocument;
|
||||
|
||||
@ -789,17 +789,45 @@ namespace AIProofread
|
||||
}
|
||||
|
||||
// 保存文件
|
||||
public string WriteText(string content, string path)
|
||||
public void WriteText(string content, string filename, string callbackId)
|
||||
{
|
||||
try
|
||||
Globals.ThisAddIn.ActiveDocument.RunInMainThread(() =>
|
||||
{
|
||||
File.WriteAllText(path, content);
|
||||
return BridgeResult.Success("ok");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BridgeResult.Error(-1, ex.Message);
|
||||
}
|
||||
var json = JSONObject.Create();
|
||||
try
|
||||
{
|
||||
string currentName = Globals.ThisAddIn.Application.ActiveDocument.Name;
|
||||
// 去掉文件名后缀
|
||||
currentName = currentName.Substring(0, currentName.LastIndexOf("."));
|
||||
SaveFileDialog sfd = new SaveFileDialog
|
||||
{
|
||||
// 设置默认文件名
|
||||
FileName = filename,
|
||||
Filter = "文本文件|*.txt"
|
||||
};
|
||||
|
||||
var result = sfd.ShowDialog();
|
||||
// 如果用户取消选择,则返回
|
||||
if (result != DialogResult.Cancel)
|
||||
{
|
||||
if (File.Exists(sfd.FileName))
|
||||
{
|
||||
File.Delete(sfd.FileName);
|
||||
}
|
||||
File.WriteAllText(sfd.FileName, content);
|
||||
json.Put("status", "success");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
json.Put("status", "error").Put("message", ex.Message);
|
||||
}
|
||||
Globals.ThisAddIn.GlobalCallback(
|
||||
callbackId,
|
||||
json.ToString()
|
||||
);
|
||||
});
|
||||
//
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user