-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Antidote 4.0.3.2: Fix tracking changes issue
- Loading branch information
Showing
4 changed files
with
156 additions
and
169 deletions.
There are no files selected for viewing
260 changes: 128 additions & 132 deletions
260
...e Verifier/Sdl.Community.AntidoteVerifier/Sdl.Community.AntidoteVerifier/EditorService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,143 +1,139 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Sdl.Community.AntidoteVerifier.Extensions; | ||
using Sdl.Community.AntidoteVerifier.Extensions; | ||
using Sdl.Community.AntidoteVerifier.Utils; | ||
using Sdl.FileTypeSupport.Framework.BilingualApi; | ||
using Sdl.TranslationStudioAutomation.IntegrationApi; | ||
using Sdl.TranslationStudioAutomation.IntegrationApi.Extensions; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Sdl.Community.AntidoteVerifier | ||
{ | ||
public struct RangeOfCharacterInfos | ||
{ | ||
public int length; | ||
public int start; | ||
} | ||
|
||
public class EditorService : IEditorService | ||
{ | ||
private readonly IStudioDocument _document; | ||
private readonly Dictionary<int, KeyValuePair<string, string>> _segmentMetadata; | ||
|
||
public EditorService(IStudioDocument document) | ||
{ | ||
_document = document; | ||
_segmentMetadata = new Dictionary<int, KeyValuePair<string, string>>(); | ||
Initialize(); | ||
} | ||
|
||
public void ActivateDocument() | ||
{ | ||
//Commented because Activate is not thread-safe and it will crash. | ||
//EditorController editorController = SdlTradosStudio.Application.GetController<EditorController>(); | ||
//editorController.Activate(_document); | ||
} | ||
|
||
public bool CanReplace(int segmentId, int startPosition, int endPosition, string origString, string displayLanguage, ref string message, ref string explication) | ||
{ | ||
var ret = false; | ||
var segmentPair = GetSegmentPair(segmentId); | ||
if (segmentPair != null) | ||
{ | ||
ret = segmentPair.Target.CanReplace(startPosition, endPosition, origString, displayLanguage, ref message, ref explication); | ||
} | ||
return ret; | ||
} | ||
|
||
public int GetActiveSegmentId() | ||
{ | ||
var segmentId = int.Parse(_document.ActiveSegmentPair.Properties.Id.Id); | ||
var paragraphUnitId = _document.ActiveSegmentPair.GetParagraphUnitProperties().ParagraphUnitId.Id; | ||
foreach (var kvp in _segmentMetadata) | ||
{ | ||
if (kvp.Value.Key.Equals(segmentId) && kvp.Value.Value.Equals(paragraphUnitId)) | ||
{ | ||
return kvp.Key; | ||
} | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
public int GetCurrentSegmentId(int segmentNumber) | ||
{ | ||
return segmentNumber; | ||
} | ||
|
||
public int GetDocumentId() | ||
{ | ||
return DocumentIdGenerator.Instance.GetDocumentId(_document.ActiveFile.Id); | ||
} | ||
|
||
public string GetDocumentName() | ||
{ | ||
return _document.ActiveFile.Name; | ||
} | ||
|
||
public int GetDocumentNoOfSegments() | ||
{ | ||
return _segmentMetadata.Count(); | ||
} | ||
|
||
public string GetSegmentText(int index) | ||
{ | ||
var segmentPair = GetSegmentPair(index); | ||
return segmentPair.Target.GetString(); | ||
} | ||
|
||
public string GetSelection() | ||
public struct RangeOfCharacterInfos | ||
{ | ||
public int length; | ||
public int start; | ||
} | ||
|
||
public class EditorService : IEditorService | ||
{ | ||
private readonly IStudioDocument _document; | ||
private readonly Dictionary<int, KeyValuePair<string, string>> _segmentMetadata; | ||
|
||
public EditorService(IStudioDocument document) | ||
{ | ||
_document = document; | ||
_segmentMetadata = new Dictionary<int, KeyValuePair<string, string>>(); | ||
Initialize(); | ||
} | ||
|
||
public void ActivateDocument() | ||
{ | ||
EditorController editorController = SdlTradosStudio.Application.GetController<EditorController>(); | ||
editorController.Activate(_document); | ||
} | ||
|
||
public bool CanReplace(int segmentId, int startPosition, int endPosition, string origString, string displayLanguage, ref string message, ref string explication) | ||
{ | ||
var ret = false; | ||
var segmentPair = GetSegmentPair(segmentId); | ||
if (segmentPair != null) | ||
{ | ||
ret = segmentPair.Target.CanReplace(startPosition, endPosition, origString, displayLanguage, ref message, ref explication); | ||
} | ||
return ret; | ||
} | ||
|
||
public int GetActiveSegmentId() | ||
{ | ||
var segmentId = int.Parse(_document.ActiveSegmentPair.Properties.Id.Id); | ||
var paragraphUnitId = _document.ActiveSegmentPair.GetParagraphUnitProperties().ParagraphUnitId.Id; | ||
foreach (var kvp in _segmentMetadata) | ||
{ | ||
if (kvp.Value.Key.Equals(segmentId) && kvp.Value.Value.Equals(paragraphUnitId)) | ||
{ | ||
return kvp.Key; | ||
} | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
public int GetCurrentSegmentId(int segmentNumber) | ||
{ | ||
return segmentNumber; | ||
} | ||
|
||
public int GetDocumentId() | ||
{ | ||
return DocumentIdGenerator.Instance.GetDocumentId(_document.ActiveFile.Id); | ||
} | ||
|
||
public string GetDocumentName() | ||
{ | ||
return _document.ActiveFile.Name; | ||
} | ||
|
||
public int GetDocumentNoOfSegments() | ||
{ | ||
return _segmentMetadata.Count(); | ||
} | ||
|
||
public string GetSegmentText(int index) | ||
{ | ||
var segmentPair = GetSegmentPair(index); | ||
return segmentPair.Target.GetString(); | ||
} | ||
|
||
public string GetSelection() | ||
{ | ||
return _document.Selection.Target.ToString(); | ||
} | ||
|
||
public void ReplaceTextInSegment(int segmentId, int startPosition, int endPosition, string replacementText) | ||
{ | ||
var segmentPair = GetSegmentPair(segmentId); | ||
|
||
segmentPair?.Target.Replace(startPosition, endPosition, replacementText); | ||
|
||
_document.UpdateSegmentPair(segmentPair); | ||
} | ||
|
||
public void SelectText(int index, int startPosition, int endPosition) | ||
{ | ||
var segmentPair = GetSegmentPair(index); | ||
|
||
var paragraphUnitId = segmentPair.GetParagraphUnitProperties().ParagraphUnitId.Id; | ||
|
||
_document.SetActiveSegmentPair(paragraphUnitId, segmentPair.Properties.Id.Id); | ||
} | ||
|
||
private ISegmentPair GetSegmentPair(int index) | ||
{ | ||
var segmentUniqueIdentifier = _segmentMetadata[index]; | ||
|
||
return _document.SegmentPairs | ||
.FirstOrDefault( | ||
segmentPair => | ||
{ | ||
var segmentIdFound = segmentPair.Properties.Id.Id.Equals(segmentUniqueIdentifier.Key.ToString()); | ||
var paragraphUnitId = segmentPair.GetParagraphUnitProperties().ParagraphUnitId.Id; | ||
return segmentIdFound && paragraphUnitId.Equals(segmentUniqueIdentifier.Value); | ||
}); | ||
} | ||
|
||
private void Initialize() | ||
{ | ||
_segmentMetadata.Clear(); | ||
|
||
var index = 1; | ||
for (var i = 0; i < _document?.FilteredSegmentPairsCount; i++) | ||
{ | ||
var segmentPair = _document.FilteredSegmentPairs.ToList()[i]; | ||
var paragraphUnitId = segmentPair.GetParagraphUnitProperties().ParagraphUnitId.Id; | ||
var currentId = segmentPair.Properties.Id.Id; | ||
|
||
if (string.IsNullOrEmpty(segmentPair.Target.GetString())) | ||
continue; | ||
_segmentMetadata.Add(index, new KeyValuePair<string, string>(currentId, paragraphUnitId)); | ||
index++; | ||
} | ||
} | ||
} | ||
public void ReplaceTextInSegment(int segmentId, int startPosition, int endPosition, string replacementText) | ||
{ | ||
var segmentPair = GetSegmentPair(segmentId); | ||
segmentPair?.Target.Replace(startPosition, endPosition, replacementText); | ||
_document.UpdateSegmentPair(segmentPair); | ||
} | ||
|
||
public void SelectText(int index, int startPosition, int endPosition) | ||
{ | ||
var segmentPair = GetSegmentPair(index); | ||
|
||
var paragraphUnitId = segmentPair.GetParagraphUnitProperties().ParagraphUnitId.Id; | ||
|
||
_document.SetActiveSegmentPair(paragraphUnitId, segmentPair.Properties.Id.Id); | ||
} | ||
|
||
private ISegmentPair GetSegmentPair(int index) | ||
{ | ||
var segmentUniqueIdentifier = _segmentMetadata[index]; | ||
|
||
return _document.SegmentPairs | ||
.FirstOrDefault( | ||
segmentPair => | ||
{ | ||
var segmentIdFound = segmentPair.Properties.Id.Id.Equals(segmentUniqueIdentifier.Key.ToString()); | ||
var paragraphUnitId = segmentPair.GetParagraphUnitProperties().ParagraphUnitId.Id; | ||
return segmentIdFound && paragraphUnitId.Equals(segmentUniqueIdentifier.Value); | ||
}); | ||
} | ||
|
||
private void Initialize() | ||
{ | ||
_segmentMetadata.Clear(); | ||
|
||
var index = 1; | ||
for (var i = 0; i < _document?.FilteredSegmentPairsCount; i++) | ||
{ | ||
var segmentPair = _document.FilteredSegmentPairs.ToList()[i]; | ||
var paragraphUnitId = segmentPair.GetParagraphUnitProperties().ParagraphUnitId.Id; | ||
var currentId = segmentPair.Properties.Id.Id; | ||
|
||
if (string.IsNullOrEmpty(segmentPair.Target.GetString())) | ||
continue; | ||
_segmentMetadata.Add(index, new KeyValuePair<string, string>(currentId, paragraphUnitId)); | ||
index++; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../Sdl.Community.AntidoteVerifier/Sdl.Community.AntidoteVerifier/pluginpackage.manifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters