fixed wps 外部多文档打开时导致panel隐藏的问题
This commit is contained in:
parent
59776008d3
commit
0c1fd59146
Binary file not shown.
@ -13,20 +13,27 @@ Global
|
|||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
|
Test|Any CPU = Test|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{6CE536CB-6154-4FDF-9FFE-23A73B4E84AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{6CE536CB-6154-4FDF-9FFE-23A73B4E84AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{6CE536CB-6154-4FDF-9FFE-23A73B4E84AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{6CE536CB-6154-4FDF-9FFE-23A73B4E84AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{6CE536CB-6154-4FDF-9FFE-23A73B4E84AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{6CE536CB-6154-4FDF-9FFE-23A73B4E84AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{6CE536CB-6154-4FDF-9FFE-23A73B4E84AB}.Release|Any CPU.Build.0 = Release|Any CPU
|
{6CE536CB-6154-4FDF-9FFE-23A73B4E84AB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{6CE536CB-6154-4FDF-9FFE-23A73B4E84AB}.Test|Any CPU.ActiveCfg = Test|Any CPU
|
||||||
|
{6CE536CB-6154-4FDF-9FFE-23A73B4E84AB}.Test|Any CPU.Build.0 = Test|Any CPU
|
||||||
{455E23BE-F34F-4F6F-A9EA-381D66170B1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{455E23BE-F34F-4F6F-A9EA-381D66170B1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{455E23BE-F34F-4F6F-A9EA-381D66170B1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{455E23BE-F34F-4F6F-A9EA-381D66170B1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{455E23BE-F34F-4F6F-A9EA-381D66170B1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{455E23BE-F34F-4F6F-A9EA-381D66170B1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{455E23BE-F34F-4F6F-A9EA-381D66170B1B}.Release|Any CPU.Build.0 = Release|Any CPU
|
{455E23BE-F34F-4F6F-A9EA-381D66170B1B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{455E23BE-F34F-4F6F-A9EA-381D66170B1B}.Test|Any CPU.ActiveCfg = Test|Any CPU
|
||||||
|
{455E23BE-F34F-4F6F-A9EA-381D66170B1B}.Test|Any CPU.Build.0 = Test|Any CPU
|
||||||
{FF204E99-82F8-405E-847B-88FC6DF07715}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{FF204E99-82F8-405E-847B-88FC6DF07715}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{FF204E99-82F8-405E-847B-88FC6DF07715}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{FF204E99-82F8-405E-847B-88FC6DF07715}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{FF204E99-82F8-405E-847B-88FC6DF07715}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{FF204E99-82F8-405E-847B-88FC6DF07715}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{FF204E99-82F8-405E-847B-88FC6DF07715}.Release|Any CPU.Build.0 = Release|Any CPU
|
{FF204E99-82F8-405E-847B-88FC6DF07715}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{FF204E99-82F8-405E-847B-88FC6DF07715}.Test|Any CPU.ActiveCfg = Test|Any CPU
|
||||||
|
{FF204E99-82F8-405E-847B-88FC6DF07715}.Test|Any CPU.Build.0 = Test|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -316,6 +316,20 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ManifestCertificateThumbprint>62DF6B414BD2608A130540A801F32D12E0199A99</ManifestCertificateThumbprint>
|
<ManifestCertificateThumbprint>62DF6B414BD2608A130540A801F32D12E0199A99</ManifestCertificateThumbprint>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Test|AnyCPU'">
|
||||||
|
<OutputPath>bin\Test\</OutputPath>
|
||||||
|
<DefineConstants>VSTO40;TRACE</DefineConstants>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<LangVersion>7.3</LangVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Test|Win32'">
|
||||||
|
<OutputPath>bin\Win32\Test\</OutputPath>
|
||||||
|
<DefineConstants>VSTO40</DefineConstants>
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<LangVersion>7.3</LangVersion>
|
||||||
|
</PropertyGroup>
|
||||||
<!-- Include the build rules for a C# project. -->
|
<!-- Include the build rules for a C# project. -->
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- Include additional build rules for an Office application add-in. -->
|
<!-- Include additional build rules for an Office application add-in. -->
|
||||||
|
@ -8,6 +8,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||||
<StartAction>Project</StartAction>
|
<StartAction>Project</StartAction>
|
||||||
<StartProgram>C:\Soft\Kingsoft\WPS Office\12.1.0.16910\office6\wps.exe</StartProgram>
|
<StartProgram>C:\Soft\Kingsoft\WPS Office\12.1.0.16929\office6\wps.exe</StartProgram>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
@ -104,11 +104,13 @@ namespace AIProofread
|
|||||||
|
|
||||||
public void ShowCurrentPane()
|
public void ShowCurrentPane()
|
||||||
{
|
{
|
||||||
Globals.ThisAddIn.currentDocumentTaskPane.Visible = true;
|
Globals.ThisAddIn.ShowPanel();
|
||||||
|
//Globals.ThisAddIn.currentDocumentTaskPane.Visible = true;
|
||||||
}
|
}
|
||||||
public void HideCurrentPane()
|
public void HideCurrentPane()
|
||||||
{
|
{
|
||||||
Globals.ThisAddIn.currentDocumentTaskPane.Visible = false;
|
Globals.ThisAddIn.HidePanel();
|
||||||
|
//Globals.ThisAddIn.currentDocumentTaskPane.Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Logout(string action)
|
public void Logout(string action)
|
||||||
@ -224,7 +226,8 @@ namespace AIProofread
|
|||||||
{
|
{
|
||||||
if (item.mark != null)
|
if (item.mark != null)
|
||||||
{
|
{
|
||||||
if(item.content.tag == "i" && item.content.isAccept == AcceptStatus.Default) {
|
if (item.content.tag == "i" && item.content.isAccept == AcceptStatus.Default)
|
||||||
|
{
|
||||||
item.mark.Text = "";
|
item.mark.Text = "";
|
||||||
}
|
}
|
||||||
item.ResetMarkStyle();
|
item.ResetMarkStyle();
|
||||||
@ -232,9 +235,10 @@ namespace AIProofread
|
|||||||
}
|
}
|
||||||
marks.Clear();
|
marks.Clear();
|
||||||
DocumentUtil.ClearProofreadMarks();
|
DocumentUtil.ClearProofreadMarks();
|
||||||
}catch (Exception ex)
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.Log("ClearAllProofreadMark",ex);
|
Logger.Log("ClearAllProofreadMark", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,6 +438,7 @@ namespace AIProofread
|
|||||||
//var app = Globals.ThisAddIn.Application;
|
//var app = Globals.ThisAddIn.Application;
|
||||||
//var cur = app.Selection;
|
//var cur = app.Selection;
|
||||||
//
|
//
|
||||||
|
int aIndex = 0;
|
||||||
foreach (var correct in list)
|
foreach (var correct in list)
|
||||||
{
|
{
|
||||||
//cur.TypeText(correct.Insert);
|
//cur.TypeText(correct.Insert);
|
||||||
@ -446,11 +451,20 @@ namespace AIProofread
|
|||||||
// return it.start + correct.Insert_len;
|
// return it.start + correct.Insert_len;
|
||||||
//}).ToList();
|
//}).ToList();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
if (aIndex++ > 20)
|
||||||
|
{
|
||||||
|
Console.WriteLine(aIndex);
|
||||||
|
}
|
||||||
foreach (var item in correct.Diffs)
|
foreach (var item in correct.Diffs)
|
||||||
{
|
{
|
||||||
|
if(item.id == 109288)
|
||||||
|
{
|
||||||
|
Console.WriteLine("xxx");
|
||||||
|
}
|
||||||
var mark = AddBookmark(item, index, correct.Sentence_offset, correct.Insert_len, correct.Paragraph_offset);
|
var mark = AddBookmark(item, index, correct.Sentence_offset, correct.Insert_len, correct.Paragraph_offset);
|
||||||
if (item.tag != "i") index++;
|
if (item.tag != "i") index++;
|
||||||
if (mark != null) {
|
if (mark != null)
|
||||||
|
{
|
||||||
marks.Add(item.id, new ProofreadItem(item, mark));
|
marks.Add(item.id, new ProofreadItem(item, mark));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -458,7 +472,7 @@ namespace AIProofread
|
|||||||
}
|
}
|
||||||
foreach (var item in marks)
|
foreach (var item in marks)
|
||||||
{
|
{
|
||||||
if(item.Value.mark != null)
|
if (item.Value.mark != null)
|
||||||
{
|
{
|
||||||
if (item.Value.content.tag == "i")
|
if (item.Value.content.tag == "i")
|
||||||
{
|
{
|
||||||
@ -472,7 +486,7 @@ namespace AIProofread
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public string GetParagraph(int index)
|
public string GetParagraph(int index)
|
||||||
{
|
{
|
||||||
@ -496,32 +510,13 @@ namespace AIProofread
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Microsoft.Office.Tools.Word.Bookmark AddBookmark(CorrectedContent item, int findIndex, int offset, int length,int paragraphIndex)
|
public Microsoft.Office.Tools.Word.Bookmark AddBookmark(CorrectedContent item, int findIndex, int offset, int length, int paragraphIndex)
|
||||||
{
|
{
|
||||||
Microsoft.Office.Tools.Word.Bookmark bookmark = null;
|
Microsoft.Office.Tools.Word.Bookmark bookmark = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var document = Globals.ThisAddIn.Application.ActiveDocument;
|
var document = Globals.ThisAddIn.Application.ActiveDocument;
|
||||||
ControlCollection controls = Globals.Factory.GetVstoObject(document).Controls;
|
ControlCollection controls = Globals.Factory.GetVstoObject(document).Controls;
|
||||||
// 判断并获取当前段落
|
|
||||||
if (paragraphIndex > document.Paragraphs.Count) return null;
|
|
||||||
var paragraph = document.Paragraphs[paragraphIndex];
|
|
||||||
var paragraphStart = paragraph.Range.Start;
|
|
||||||
var Start = paragraphStart + offset;
|
|
||||||
var End = Start + length - 1;
|
|
||||||
if(End > paragraph.Range.End)
|
|
||||||
{
|
|
||||||
End = paragraph.Range.End;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 当前句子的选区
|
|
||||||
var fullRange = document.Range(Start, End);
|
|
||||||
string fullText = fullRange.Text;
|
|
||||||
Start = paragraphStart + offset + item.start;
|
|
||||||
End = paragraphStart + offset + item.end;
|
|
||||||
|
|
||||||
// 定位要操作的文字
|
|
||||||
var r = document.Range(Start, End);
|
|
||||||
var markName = Config.BuildBookmarkName(item.id);
|
var markName = Config.BuildBookmarkName(item.id);
|
||||||
|
|
||||||
// 判断是否已经存在
|
// 判断是否已经存在
|
||||||
@ -529,28 +524,77 @@ namespace AIProofread
|
|||||||
{
|
{
|
||||||
controls.Remove(markName);
|
controls.Remove(markName);
|
||||||
}
|
}
|
||||||
// 判断选区是否正确
|
Range findRange = null;
|
||||||
if (item.tag == "i" || r.Text == item.origin)
|
if (paragraphIndex > document.Paragraphs.Count) return null;
|
||||||
|
var paragraph = document.Paragraphs[paragraphIndex];
|
||||||
|
var paragraphStart = paragraph.Range.Start;
|
||||||
|
offset += paragraphStart;
|
||||||
|
|
||||||
|
var Start = offset;
|
||||||
|
var End = Start + length - 1;
|
||||||
|
if (End > paragraph.Range.End)
|
||||||
{
|
{
|
||||||
bookmark = controls.AddBookmark(r, markName);
|
End = paragraph.Range.End;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 当前句子的选区
|
||||||
|
var fullRange = document.Range(Start, End);
|
||||||
|
string fullText = fullRange.Text ?? paragraph.Range.Text;
|
||||||
|
Start = offset + item.start;
|
||||||
|
End = offset + item.end;
|
||||||
|
|
||||||
|
// 如果是新增 只能使用接口数据
|
||||||
|
findRange = document.Range(Start, End);
|
||||||
|
if (item.tag != "i" && findRange.Text != item.origin)
|
||||||
|
{
|
||||||
|
findRange = DocumentUtil.FindRange(paragraphIndex, item.origin, item.start, item.end);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (findRange != null)
|
||||||
|
{
|
||||||
|
bookmark = controls.AddBookmark(findRange, markName);
|
||||||
bookmark.Tag = "ai_proofread";
|
bookmark.Tag = "ai_proofread";
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
#region start
|
||||||
int startPos = 0, index, findCount = 0;
|
|
||||||
while ((index = fullText.IndexOf(item.origin, startPos)) != -1)
|
//// 判断并获取当前段落
|
||||||
{
|
|
||||||
if (findCount == findIndex)
|
|
||||||
{
|
//// 定位要操作的文字
|
||||||
r = document.Range(offset + index, offset + index + item.origin.Length);
|
//var r = document.Range(Start, End);
|
||||||
bookmark = controls.AddBookmark(r, markName);
|
|
||||||
bookmark.Tag = "ai_proofread";
|
//// 判断选区是否正确
|
||||||
break;
|
//if (item.tag == "i" || r.Text == item.origin)
|
||||||
}
|
//{
|
||||||
startPos = index;
|
// bookmark = controls.AddBookmark(r, markName);
|
||||||
findCount++;
|
// bookmark.Tag = "ai_proofread";
|
||||||
}
|
//}
|
||||||
}
|
//else
|
||||||
|
//{
|
||||||
|
// object str = item.origin;
|
||||||
|
// FindRange(ref fullRange, ref str);
|
||||||
|
|
||||||
|
// if(fullRange != null){
|
||||||
|
// bookmark = controls.AddBookmark(fullRange, markName);
|
||||||
|
// bookmark.Tag = "ai_proofread";
|
||||||
|
// }
|
||||||
|
// //int startPos = 0, index, findCount = 0;
|
||||||
|
// //while ((index = fullText.IndexOf(item.origin, startPos)) != -1)
|
||||||
|
// //{
|
||||||
|
// // if (findCount == findIndex)
|
||||||
|
// // {
|
||||||
|
// // r = document.Range(offset + index, offset + index + item.origin.Length);
|
||||||
|
// // if(r.Text == item.origin) { }
|
||||||
|
// // bookmark = controls.AddBookmark(r, markName);
|
||||||
|
// // bookmark.Tagetg = "ai_proofread";
|
||||||
|
// // break;
|
||||||
|
// // }
|
||||||
|
// // startPos = index;
|
||||||
|
// // findCount++;
|
||||||
|
// //}
|
||||||
|
//}
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -560,5 +604,15 @@ namespace AIProofread
|
|||||||
return bookmark;
|
return bookmark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void FindRange(ref Range range,ref object whatToFind)
|
||||||
|
{
|
||||||
|
object matchCase = false; // 是否区分大小写
|
||||||
|
object matchWholeWord = false; // 是否匹配整个单词
|
||||||
|
object matchWildcards = false; // 是否使用通配符
|
||||||
|
object forward = true; // 搜索方向,true表示向前搜索,false表示向后搜索
|
||||||
|
object wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue; // 搜索范围,这里表示继续搜索
|
||||||
|
|
||||||
|
range.Find.Execute(ref whatToFind, ref matchCase, ref matchWholeWord, ref matchWildcards, ref forward, ref wrap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ namespace AIProofread
|
|||||||
public class Config
|
public class Config
|
||||||
{
|
{
|
||||||
public static readonly string APP_NAME = "AI校对王";
|
public static readonly string APP_NAME = "AI校对王";
|
||||||
public static readonly string APP_VERSION = "1.0.0";
|
public static readonly string APP_VERSION = "1.0.4";
|
||||||
public static bool IS_WPS = false;
|
public static bool IS_WPS = false;
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -22,9 +22,9 @@ namespace AIProofread
|
|||||||
Directory.CreateDirectory(Config.APP_LOG_PATH);
|
Directory.CreateDirectory(Config.APP_LOG_PATH);
|
||||||
}
|
}
|
||||||
StreamWriter streamWriter = File.AppendText(path);
|
StreamWriter streamWriter = File.AppendText(path);
|
||||||
|
streamWriter.WriteLine("***************************[" + (Config.IS_WPS ? "WPS" : "WORD") + "]***************************");
|
||||||
streamWriter.WriteLine("消息:" + msg);
|
streamWriter.WriteLine("消息:" + msg);
|
||||||
streamWriter.WriteLine("时间:" + DateTime.Now.ToString("yyyy - MM - dd HH: mm:ss"));
|
streamWriter.WriteLine("时间:" + DateTime.Now.ToString("yyyy - MM - dd HH: mm:ss"));
|
||||||
streamWriter.WriteLine("***************************[" + (Config.IS_WPS?"WPS":"WORD")+ "]***************************");
|
|
||||||
streamWriter.WriteLine();
|
streamWriter.WriteLine();
|
||||||
streamWriter.Flush();
|
streamWriter.Flush();
|
||||||
streamWriter.Close();
|
streamWriter.Close();
|
||||||
|
9
AIProofread/Ribbon1.Designer.cs
generated
9
AIProofread/Ribbon1.Designer.cs
generated
@ -51,6 +51,7 @@ namespace AIProofread
|
|||||||
this.grpDebug = this.Factory.CreateRibbonGroup();
|
this.grpDebug = this.Factory.CreateRibbonGroup();
|
||||||
this.btnShowPane = this.Factory.CreateRibbonButton();
|
this.btnShowPane = this.Factory.CreateRibbonButton();
|
||||||
this.btnHidePane = this.Factory.CreateRibbonButton();
|
this.btnHidePane = this.Factory.CreateRibbonButton();
|
||||||
|
this.btnTestLocation = this.Factory.CreateRibbonButton();
|
||||||
this.tabAIProofread.SuspendLayout();
|
this.tabAIProofread.SuspendLayout();
|
||||||
this.group1.SuspendLayout();
|
this.group1.SuspendLayout();
|
||||||
this.grpDebug.SuspendLayout();
|
this.grpDebug.SuspendLayout();
|
||||||
@ -167,6 +168,7 @@ namespace AIProofread
|
|||||||
//
|
//
|
||||||
this.grpDebug.Items.Add(this.btnShowPane);
|
this.grpDebug.Items.Add(this.btnShowPane);
|
||||||
this.grpDebug.Items.Add(this.btnHidePane);
|
this.grpDebug.Items.Add(this.btnHidePane);
|
||||||
|
this.grpDebug.Items.Add(this.btnTestLocation);
|
||||||
this.grpDebug.Label = "开发调试";
|
this.grpDebug.Label = "开发调试";
|
||||||
this.grpDebug.Name = "grpDebug";
|
this.grpDebug.Name = "grpDebug";
|
||||||
this.grpDebug.Visible = false;
|
this.grpDebug.Visible = false;
|
||||||
@ -183,6 +185,12 @@ namespace AIProofread
|
|||||||
this.btnHidePane.Name = "btnHidePane";
|
this.btnHidePane.Name = "btnHidePane";
|
||||||
this.btnHidePane.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnHidePane_Click);
|
this.btnHidePane.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnHidePane_Click);
|
||||||
//
|
//
|
||||||
|
// btnTestLocation
|
||||||
|
//
|
||||||
|
this.btnTestLocation.Label = "文本位置";
|
||||||
|
this.btnTestLocation.Name = "btnTestLocation";
|
||||||
|
this.btnTestLocation.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnTestLocation_Click);
|
||||||
|
//
|
||||||
// Ribbon1
|
// Ribbon1
|
||||||
//
|
//
|
||||||
this.Name = "Ribbon1";
|
this.Name = "Ribbon1";
|
||||||
@ -216,6 +224,7 @@ namespace AIProofread
|
|||||||
internal Microsoft.Office.Tools.Ribbon.RibbonGroup grpDebug;
|
internal Microsoft.Office.Tools.Ribbon.RibbonGroup grpDebug;
|
||||||
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnShowPane;
|
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnShowPane;
|
||||||
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnHidePane;
|
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnHidePane;
|
||||||
|
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnTestLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
partial class ThisRibbonCollection
|
partial class ThisRibbonCollection
|
||||||
|
@ -4,6 +4,8 @@ using System.Diagnostics;
|
|||||||
using AIProofread.Controls;
|
using AIProofread.Controls;
|
||||||
using UtilLib;
|
using UtilLib;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using Microsoft.Office.Interop.Word;
|
||||||
|
|
||||||
namespace AIProofread
|
namespace AIProofread
|
||||||
{
|
{
|
||||||
@ -17,7 +19,7 @@ namespace AIProofread
|
|||||||
//btnLogout.Label = "退出\n登录";
|
//btnLogout.Label = "退出\n登录";
|
||||||
|
|
||||||
Globals.ThisAddIn.ribbon = this;
|
Globals.ThisAddIn.ribbon = this;
|
||||||
if(Config.RUN_IN_DEBUG)
|
if (Config.RUN_IN_DEBUG)
|
||||||
{
|
{
|
||||||
grpDebug.Visible = true;
|
grpDebug.Visible = true;
|
||||||
}
|
}
|
||||||
@ -129,5 +131,26 @@ namespace AIProofread
|
|||||||
{
|
{
|
||||||
Globals.ThisAddIn.HidePanel();
|
Globals.ThisAddIn.HidePanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TestStr(int p, string str)
|
||||||
|
{
|
||||||
|
|
||||||
|
var doc = Globals.ThisAddIn.Application.ActiveDocument;
|
||||||
|
var p1 = doc.Paragraphs[p];
|
||||||
|
var text = p1.Range.Text;
|
||||||
|
var index = text.IndexOf(str);
|
||||||
|
var r = DocumentUtil.FindRange(p, str, index, index + str.Length);
|
||||||
|
|
||||||
|
System.Windows.Forms.MessageBox.Show("段落:" + p + str + ":" + index + (r == null ? "" : r.Text));
|
||||||
|
//var findRange = FindRange(p, findIndex, str, index, index + str.Length);
|
||||||
|
|
||||||
|
}
|
||||||
|
private void btnTestLocation_Click(object sender, RibbonControlEventArgs e)
|
||||||
|
{
|
||||||
|
TestStr(2, "销");
|
||||||
|
TestStr(3, "针");
|
||||||
|
TestStr(22, "疏");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,29 +43,15 @@ namespace AIProofread
|
|||||||
public List<FormLogin> LoginFormList = new List<FormLogin>();
|
public List<FormLogin> LoginFormList = new List<FormLogin>();
|
||||||
|
|
||||||
public Dictionary<Word.Document, CustomTaskPane> taskPanels = new Dictionary<Word.Document, CustomTaskPane>();
|
public Dictionary<Word.Document, CustomTaskPane> taskPanels = new Dictionary<Word.Document, CustomTaskPane>();
|
||||||
public Dictionary<Word.Document, bool> panelsVisible = new Dictionary<Word.Document, bool>();
|
public Dictionary<Word.Document, bool> panelsVisibleStatus = new Dictionary<Word.Document, bool>();
|
||||||
public CustomTaskPane currentDocumentTaskPane;
|
public CustomTaskPane currentDocumentTaskPane;
|
||||||
|
|
||||||
private static readonly Dictionary<Word.Document, Dictionary<int, ProofreadItem>> allMarks = new Dictionary<Word.Document, Dictionary<int, ProofreadItem>>();
|
private static readonly Dictionary<Word.Document, Dictionary<int, ProofreadItem>> allMarks = new Dictionary<Word.Document, Dictionary<int, ProofreadItem>>();
|
||||||
|
|
||||||
private void Application_WindowDeactivate(Word.Document doc, Window Wn)
|
private void Application_WindowDeactivate(Word.Document doc, Window Wn)
|
||||||
{
|
{
|
||||||
Logger.Log("Application_WindowDeactivate -- " + doc.FullName);
|
Logger.Log("Application_WindowDeactivate -- " + doc.FullName + " visible:" + currentDocumentTaskPane.Visible);
|
||||||
//HidePanel(Doc);
|
//HidePanel(Doc);
|
||||||
if (taskPanels.ContainsKey(doc))
|
|
||||||
{
|
|
||||||
var visible = taskPanels[doc].Visible;
|
|
||||||
// 记录当前文档的显示状态
|
|
||||||
if (!panelsVisible.ContainsKey(doc))
|
|
||||||
{
|
|
||||||
panelsVisible.Add(doc, visible);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
panelsVisible[doc] = visible;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Application_WindowActivate(Word.Document activeDoc, Window Wn)
|
private void Application_WindowActivate(Word.Document activeDoc, Window Wn)
|
||||||
@ -77,17 +63,19 @@ namespace AIProofread
|
|||||||
}
|
}
|
||||||
Logger.Log("Application_WindowActivate -- " + activeDoc.FullName);
|
Logger.Log("Application_WindowActivate -- " + activeDoc.FullName);
|
||||||
//ShowPanel(Doc);
|
//ShowPanel(Doc);
|
||||||
|
// 创建面板
|
||||||
if (!taskPanels.ContainsKey(activeDoc))
|
if (!taskPanels.ContainsKey(activeDoc))
|
||||||
{
|
{
|
||||||
ShowPanel(activeDoc, false);
|
ShowPanel(activeDoc, false);
|
||||||
|
panelsVisibleStatus.Add(activeDoc, false);
|
||||||
}
|
}
|
||||||
|
// 设置当前面板为新创建的面板
|
||||||
this.currentDocumentTaskPane = taskPanels[activeDoc];
|
this.currentDocumentTaskPane = taskPanels[activeDoc];
|
||||||
if (IsWPS)
|
if (IsWPS)
|
||||||
{
|
{
|
||||||
HideOtherPanel(activeDoc);
|
HideOtherPanel(activeDoc);
|
||||||
}
|
}
|
||||||
if (panelsVisible.ContainsKey(activeDoc) && panelsVisible[activeDoc])
|
if (panelsVisibleStatus.ContainsKey(activeDoc) && panelsVisibleStatus[activeDoc])
|
||||||
{
|
{
|
||||||
taskPanels[activeDoc].Visible = true;
|
taskPanels[activeDoc].Visible = true;
|
||||||
}
|
}
|
||||||
@ -128,6 +116,10 @@ namespace AIProofread
|
|||||||
}
|
}
|
||||||
void DisposePanel(Word.Document doc)
|
void DisposePanel(Word.Document doc)
|
||||||
{
|
{
|
||||||
|
if (panelsVisibleStatus.ContainsKey(doc))
|
||||||
|
{
|
||||||
|
panelsVisibleStatus.Remove(doc);
|
||||||
|
}
|
||||||
if (taskPanels.ContainsKey(doc))
|
if (taskPanels.ContainsKey(doc))
|
||||||
{
|
{
|
||||||
taskPanels[doc].Visible = false;
|
taskPanels[doc].Visible = false;
|
||||||
@ -142,9 +134,14 @@ namespace AIProofread
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 隐藏其他的文档
|
||||||
foreach (var key in taskPanels.Keys)
|
foreach (var key in taskPanels.Keys)
|
||||||
{
|
{
|
||||||
taskPanels[key].Visible = false;
|
// 记录面板原始状态
|
||||||
|
if (key != doc)
|
||||||
|
{
|
||||||
|
taskPanels[key].Visible = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,12 +333,20 @@ namespace AIProofread
|
|||||||
public void ShowPanel()
|
public void ShowPanel()
|
||||||
{
|
{
|
||||||
this.currentDocumentTaskPane.Visible = true;
|
this.currentDocumentTaskPane.Visible = true;
|
||||||
|
if (panelsVisibleStatus.ContainsKey(Application.ActiveDocument))
|
||||||
|
{
|
||||||
|
panelsVisibleStatus[Application.ActiveDocument] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 隐藏面板
|
// 隐藏面板
|
||||||
public void HidePanel()
|
public void HidePanel()
|
||||||
{
|
{
|
||||||
this.currentDocumentTaskPane.Visible = false;
|
this.currentDocumentTaskPane.Visible = false;
|
||||||
|
if (panelsVisibleStatus.ContainsKey(Application.ActiveDocument))
|
||||||
|
{
|
||||||
|
panelsVisibleStatus[Application.ActiveDocument] = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -8,6 +8,7 @@ using Bookmark = Microsoft.Office.Tools.Word.Bookmark;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.Office.Tools.Word;
|
using Microsoft.Office.Tools.Word;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace AIProofread
|
namespace AIProofread
|
||||||
{
|
{
|
||||||
@ -85,8 +86,9 @@ namespace AIProofread
|
|||||||
|
|
||||||
public static void ClearProofreadMarks()
|
public static void ClearProofreadMarks()
|
||||||
{
|
{
|
||||||
var bookmarks = Globals.ThisAddIn.Application.ActiveDocument.Bookmarks;
|
var document = Globals.ThisAddIn.Application.ActiveDocument;
|
||||||
ControlCollection controls = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveDocument).Controls;
|
var bookmarks = document.Bookmarks;
|
||||||
|
ControlCollection controls = Globals.Factory.GetVstoObject(document).Controls;
|
||||||
foreach (Microsoft.Office.Interop.Word.Bookmark mark in bookmarks)
|
foreach (Microsoft.Office.Interop.Word.Bookmark mark in bookmarks)
|
||||||
{
|
{
|
||||||
if (Config.IsProofreadMark(mark.Name))
|
if (Config.IsProofreadMark(mark.Name))
|
||||||
@ -94,18 +96,15 @@ namespace AIProofread
|
|||||||
// 去除高亮
|
// 去除高亮
|
||||||
mark.Range.Shading.BackgroundPatternColor = WdColor.wdColorAutomatic;
|
mark.Range.Shading.BackgroundPatternColor = WdColor.wdColorAutomatic;
|
||||||
// 去除下划线
|
// 去除下划线
|
||||||
mark.Range.Underline = WdUnderline.wdUnderlineNone;
|
//mark.Range.Underline = WdUnderline.wdUnderlineNone;
|
||||||
//mark.Delete();
|
try
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (controls.Contains(mark))
|
|
||||||
{
|
{
|
||||||
controls.Remove(mark);
|
mark.Delete();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Log("remove mark", e);
|
||||||
}
|
}
|
||||||
}catch(Exception e)
|
|
||||||
{
|
|
||||||
Logger.Log("remove mark",e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,5 +158,126 @@ namespace AIProofread
|
|||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找对应段落的range
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="paragraphsIndex">段落index,从第1开始计数</param>
|
||||||
|
/// <param name="findText">要查找字符串</param>
|
||||||
|
/// <param name="wordStart">字符串原始起始位置</param>
|
||||||
|
/// <param name="wordEnd">字符串原始结束位置</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Range FindRange(int paragraphsIndex, string findText, int wordStart, int wordEnd)
|
||||||
|
{
|
||||||
|
// <param name="findIndex"></param> 暂时接口无法支持
|
||||||
|
var document = Globals.ThisAddIn.Application.ActiveDocument;
|
||||||
|
if (paragraphsIndex > document.Paragraphs.Count) return null;
|
||||||
|
var paragraph = document.Paragraphs[paragraphsIndex];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//int num = 0;
|
||||||
|
int num3 = 0;
|
||||||
|
|
||||||
|
// 段落开始和结束
|
||||||
|
object Start = paragraph.Range.Start;
|
||||||
|
object End = paragraph.Range.End;
|
||||||
|
|
||||||
|
// 段落选区
|
||||||
|
Range range = document.Range(ref Start, ref End);
|
||||||
|
|
||||||
|
var activeDocument = document;
|
||||||
|
// 查找对象位置
|
||||||
|
End = range.Start + wordStart;
|
||||||
|
Start = range.Start + wordEnd;
|
||||||
|
// 直接找到
|
||||||
|
var findRange = activeDocument.Range(ref End, ref Start);
|
||||||
|
// 判断对应选区是否是要找的文本
|
||||||
|
if (findRange.Text == findText)
|
||||||
|
{
|
||||||
|
return findRange;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 查找
|
||||||
|
range.Find.MatchByte = true;
|
||||||
|
// 使用选区查找功能
|
||||||
|
Find find = range.Find;
|
||||||
|
// 节约变量
|
||||||
|
End = findText;
|
||||||
|
Start = true;
|
||||||
|
|
||||||
|
object MatchWholeWord = Type.Missing;
|
||||||
|
object MatchWildcards = Type.Missing;
|
||||||
|
object MatchSoundsLike = Type.Missing;
|
||||||
|
object MatchAllWordForms = Type.Missing;
|
||||||
|
object Forward = Type.Missing;
|
||||||
|
object Wrap = Type.Missing;
|
||||||
|
object Format = Type.Missing;
|
||||||
|
object ReplaceWith = Type.Missing;
|
||||||
|
object Replace = Type.Missing;
|
||||||
|
object MatchKashida = Type.Missing;
|
||||||
|
object MatchDiacritics = Type.Missing;
|
||||||
|
object MatchAlefHamza = Type.Missing;
|
||||||
|
object MatchControl = Type.Missing;
|
||||||
|
|
||||||
|
// 没有找到则执行查询
|
||||||
|
find.Execute(
|
||||||
|
ref End, ref Start, ref MatchWholeWord,
|
||||||
|
ref MatchWildcards, ref MatchSoundsLike,
|
||||||
|
ref MatchAllWordForms, ref Forward, ref Wrap,
|
||||||
|
ref Format, ref ReplaceWith, ref Replace,
|
||||||
|
ref MatchKashida, ref MatchDiacritics,
|
||||||
|
ref MatchAlefHamza, ref MatchControl
|
||||||
|
);
|
||||||
|
|
||||||
|
while (range.Find.Found)
|
||||||
|
{
|
||||||
|
var obj4 = range.Document;
|
||||||
|
MatchControl = range.Start;
|
||||||
|
MatchAlefHamza = range.End;
|
||||||
|
var range2 = obj4.Range(ref MatchControl, ref MatchAlefHamza);
|
||||||
|
num3 = range2.End;
|
||||||
|
if (range2.Text == findText)
|
||||||
|
{
|
||||||
|
return range2;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//if (findIndex == num)
|
||||||
|
//{
|
||||||
|
|
||||||
|
//}
|
||||||
|
//num++;
|
||||||
|
//range.Find.MatchByte = true;
|
||||||
|
//Find find2 = range.Find;
|
||||||
|
//MatchAlefHamza = missword;
|
||||||
|
//MatchControl = true;
|
||||||
|
//MatchDiacritics = Type.Missing;
|
||||||
|
//MatchKashida = Type.Missing;
|
||||||
|
//Replace = Type.Missing;
|
||||||
|
//ReplaceWith = Type.Missing;
|
||||||
|
//Format = Type.Missing;
|
||||||
|
//Wrap = Type.Missing;
|
||||||
|
//Forward = Type.Missing;
|
||||||
|
//MatchAllWordForms = Type.Missing;
|
||||||
|
//MatchSoundsLike = Type.Missing;
|
||||||
|
//MatchWildcards = Type.Missing;
|
||||||
|
//MatchWholeWord = Type.Missing;
|
||||||
|
//Start = Type.Missing;
|
||||||
|
//End = Type.Missing;
|
||||||
|
//// 再次重复查找
|
||||||
|
//find2.Execute(ref MatchAlefHamza, ref MatchControl, ref MatchDiacritics, ref MatchKashida, ref Replace, ref ReplaceWith, ref Format, ref Wrap, ref Forward, ref MatchAllWordForms, ref MatchSoundsLike, ref MatchWildcards, ref MatchWholeWord, ref Start, ref End);
|
||||||
|
}
|
||||||
|
if (num3 == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,4 @@
|
|||||||
|
// <autogenerated />
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
|
BIN
AIProofread/obj/Test/AIProofread.csproj.AssemblyReference.cache
Normal file
BIN
AIProofread/obj/Test/AIProofread.csproj.AssemblyReference.cache
Normal file
Binary file not shown.
BIN
AIProofread/obj/Test/DesignTimeResolveAssemblyReferences.cache
Normal file
BIN
AIProofread/obj/Test/DesignTimeResolveAssemblyReferences.cache
Normal file
Binary file not shown.
Binary file not shown.
BIN
AIProofread/obj/Test/TempPE/Properties.Resources.Designer.cs.dll
Normal file
BIN
AIProofread/obj/Test/TempPE/Properties.Resources.Designer.cs.dll
Normal file
Binary file not shown.
0
AIProofread/obj/Test/build.force
Normal file
0
AIProofread/obj/Test/build.force
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// <autogenerated />
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
|
BIN
util-lib/obj/Test/DesignTimeResolveAssemblyReferencesInput.cache
Normal file
BIN
util-lib/obj/Test/DesignTimeResolveAssemblyReferencesInput.cache
Normal file
Binary file not shown.
BIN
util-lib/obj/Test/util-lib.csproj.AssemblyReference.cache
Normal file
BIN
util-lib/obj/Test/util-lib.csproj.AssemblyReference.cache
Normal file
Binary file not shown.
@ -30,6 +30,15 @@
|
|||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Test|AnyCPU'">
|
||||||
|
<OutputPath>bin\Test\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<LangVersion>7.3</LangVersion>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user