Skip to content

Commit 3fa9562

Browse files
authored
Release/2.2.27 (#40)
* CONTMS-128 Work with Intento glossaries in the memoQ (Trados) plugin
1 parent cd4af50 commit 3fa9562

15 files changed

+412
-56
lines changed

Intento.MT.Plugin.PropertiesForm.Test/Intento.MT.Plugin.PropertiesForm.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="IntentoSDK" Version="1.5.4" />
10+
<PackageReference Include="IntentoSDK" Version="1.5.5" />
1111
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
1212
<PackageReference Include="NUnit" Version="3.12.0" />
1313
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />

Intento.MT.Plugin.PropertiesForm/AuthState.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class AuthState : BaseState
2020
// Controlled components
2121
private ModelState modelState;
2222
private GlossaryState glossaryState;
23+
private ProvideAgnosticGlossaryState providerAgnosticGlossary;
2324

2425
private List<string> сonnectedAccounts;
2526
string error_message;
@@ -107,6 +108,7 @@ public static string Draw(IntentoTranslationProviderOptionsForm form, AuthState
107108

108109
ModelState.Draw(form, null);
109110
GlossaryState.Draw(form, null);
111+
ProvideAgnosticGlossaryState.Draw(form, null);
110112

111113
return null;
112114
}
@@ -153,15 +155,24 @@ public string Draw()
153155
{
154156
ModelState.Draw(form, null);
155157
GlossaryState.Draw(form, null);
158+
ProvideAgnosticGlossaryState.Draw(form, null);
156159
return error_message;
157160
}
158161

159162
var modelSt = GetModelState();
160163
error_message = ModelState.Draw(form, modelSt);
161164
var glossarySt = GetGlossaryState();
162165
string error_message2 = GlossaryState.Draw(form, glossarySt);
163-
if (string.IsNullOrEmpty(error_message))
164-
error_message = error_message2;
166+
var providerGlossary = GetProviderGlossaryState();
167+
var errorGlossary = ProvideAgnosticGlossaryState.Draw(form, providerGlossary);
168+
if (string.IsNullOrEmpty(error_message))
169+
{
170+
error_message = error_message2;
171+
}
172+
if (!string.IsNullOrEmpty(errorGlossary))
173+
{
174+
error_message = error_message2 + errorGlossary;
175+
}
165176

166177
if (modelSt != null && modelSt.UseModel)
167178
{
@@ -243,7 +254,9 @@ private void ResetChildrensState()
243254
glossaryState = new GlossaryState(this, options);
244255
glossaryState.ClearOptions(options);
245256
glossaryState = null;
246-
257+
providerAgnosticGlossary = new ProvideAgnosticGlossaryState(this, options);
258+
providerAgnosticGlossary.ClearOptions(options);
259+
providerAgnosticGlossary = null;
247260
}
248261

249262
public bool UseCustomAuth
@@ -264,6 +277,7 @@ public static void FillOptions(AuthState state, IntentoMTFormOptions options)
264277
options.CustomAuth = null;
265278
ModelState.FillOptions(null, options);
266279
GlossaryState.FillOptions(null, options);
280+
ProvideAgnosticGlossaryState.FillOptions(null, options);
267281
}
268282
else
269283
{
@@ -284,6 +298,7 @@ public static void FillOptions(AuthState state, IntentoMTFormOptions options)
284298

285299
ModelState.FillOptions(state.GetModelState(), options);
286300
GlossaryState.FillOptions(state.GetGlossaryState(), options);
301+
ProvideAgnosticGlossaryState.FillOptions(state.GetProviderGlossaryState(), options);
287302
}
288303
}
289304

@@ -306,6 +321,7 @@ public void comboBoxCredentialId_SelectedIndexChanged()
306321
{
307322
GetModelState()?.ClearOptions(options);
308323
GetGlossaryState()?.ClearOptions(options);
324+
GetProviderGlossaryState()?.ClearOptions(options);
309325
}
310326
EnableDisable();
311327
}
@@ -373,6 +389,22 @@ public GlossaryState GetGlossaryState()
373389
return glossaryState;
374390
}
375391

392+
public ProvideAgnosticGlossaryState GetProviderGlossaryState()
393+
{
394+
if (IsOK)
395+
{
396+
if (providerAgnosticGlossary == null)
397+
{
398+
providerAgnosticGlossary = new ProvideAgnosticGlossaryState(this, options);
399+
}
400+
}
401+
else
402+
{
403+
providerAgnosticGlossary = null;
404+
}
405+
return providerAgnosticGlossary;
406+
}
407+
376408
#endregion Properties
377409

378410
#region methods for managing a group of controls

Intento.MT.Plugin.PropertiesForm/GlossaryState.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,10 @@ private void ReadGlossaries()
281281
public void glossaryControls_ValueChanged()
282282
{
283283
formMT.groupBoxOptional.Enabled = options.UseCustomModel || currentGlossary != null;
284-
if (!internalControlChange)
285-
GlossaryState.FillOptions(this, options);
284+
if (!internalControlChange)
285+
{
286+
FillOptions(this, options);
287+
}
286288
EnableDisable();
287289
}
288290

Intento.MT.Plugin.PropertiesForm/Intento.MT.Plugin.PropertiesForm.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
<AssemblyOriginatorKeyFile>intento_sn.snk</AssemblyOriginatorKeyFile>
4040
</PropertyGroup>
4141
<ItemGroup>
42-
<Reference Include="IntentoSDK, Version=1.5.4.0, Culture=neutral, PublicKeyToken=7fbf26cf2c5f5508, processorArchitecture=MSIL">
43-
<HintPath>..\..\packages\IntentoSDK.1.5.4\lib\net45\IntentoSDK.dll</HintPath>
42+
<Reference Include="IntentoSDK, Version=1.5.5.0, Culture=neutral, PublicKeyToken=7fbf26cf2c5f5508, processorArchitecture=MSIL">
43+
<HintPath>..\..\packages\IntentoSDK.1.5.5\lib\net45\IntentoSDK.dll</HintPath>
4444
</Reference>
4545
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
4646
<HintPath>..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
@@ -58,6 +58,7 @@
5858
</ItemGroup>
5959
<ItemGroup>
6060
<Compile Include="Logs.cs" />
61+
<Compile Include="ProvideAgnosticGlossaryState.cs" />
6162
<Compile Include="WinForms\IntentoFormIgnoreError.cs">
6263
<SubType>Form</SubType>
6364
</Compile>

Intento.MT.Plugin.PropertiesForm/IntentoMTFormOptions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ public enum StateModeEnum
137137
// string of custom glossary
138138
public string Glossary { get; set; }
139139

140+
/// <summary>
141+
/// Array of selected intento glossaries
142+
/// </summary>
143+
public int[] IntentoGlossaries { get; set; }
144+
140145
// string of custom glossary name
141146
public string GlossaryName { get; set; }
142147

@@ -284,6 +289,7 @@ public void Fill(IntentoMTFormOptions res)
284289
res.CustomAuth = this.CustomAuth;
285290
res.UseCustomModel = this.UseCustomModel;
286291
res.Glossary = this.Glossary;
292+
res.IntentoGlossaries = this.IntentoGlossaries;
287293
res.CustomModel = this.CustomModel;
288294
res.Format = this.Format;
289295
res.UserAgent = this.UserAgent;

Intento.MT.Plugin.PropertiesForm/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.2.26.0")]
36-
[assembly: AssemblyFileVersion("2.2.26.0")]
35+
[assembly: AssemblyVersion("2.2.27.0")]
36+
[assembly: AssemblyFileVersion("2.2.27.0")]
3737
[assembly: IntentoSDK.AssemblyGitHash(Intento.MT.Plugin.PropertiesForm.GitHash.hash)]

Intento.MT.Plugin.PropertiesForm/Properties/Intento.MT.Plugin.PropertiesForm.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<package>
33
<metadata>
44
<id>Intento.MT.Plugin.PropertiesForm</id>
5-
<version>2.2.26.0</version>
5+
<version>2.2.27.0</version>
66
<authors>Intento</authors>
77
<owners>Intento</owners>
88
<requireLicenseAcceptance>false</requireLicenseAcceptance>
99
<description>A library with a settings form used in Intento momoQ plugin and Intento Trados plugin.</description>
1010
<copyright>Copyright © Intento 2018-2021</copyright>
1111
<dependencies>
12-
<dependency id="IntentoSDK" version="1.5.4.0" />
12+
<dependency id="IntentoSDK" version="1.5.5.0" />
1313
</dependencies>
1414
</metadata>
1515
<files>
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using static Intento.MT.Plugin.PropertiesForm.IntentoMTFormOptions;
7+
8+
namespace Intento.MT.Plugin.PropertiesForm
9+
{
10+
public class ProvideAgnosticGlossaryState: BaseState
11+
{
12+
AuthState authState;
13+
public StateModeEnum mode = StateModeEnum.unknown;
14+
public static bool internalControlChange = false;
15+
16+
private IList<dynamic> glossaries;
17+
private IList<dynamic> types;
18+
19+
/// <summary>
20+
///
21+
/// </summary>
22+
/// <param name="_form"></param>
23+
/// <param name="_options"></param>
24+
/// <param name="fromForm">Call from event, change of form check box may result recourcing</param>
25+
public ProvideAgnosticGlossaryState(AuthState authState, IntentoMTFormOptions _options, bool fromForm = false) : base(authState, _options)
26+
{
27+
this.authState = authState;
28+
}
29+
30+
public static string Draw(IntentoTranslationProviderOptionsForm form, ProvideAgnosticGlossaryState state)
31+
{
32+
if (state == null)
33+
{
34+
HideVisibility(form.formMT);
35+
return null;
36+
}
37+
return state.Draw();
38+
}
39+
40+
public string Draw()
41+
{
42+
FillGlossaryControls();
43+
44+
string errorMessage = null;
45+
if (!authState.providerState.intento_glossary)
46+
{
47+
formMT.providerAgnosticGlossariesGroup.Visible = false;
48+
formMT.listOfIntentoGlossaries.Visible = false;
49+
}
50+
else
51+
{
52+
formMT.listOfIntentoGlossaries.Visible = true;
53+
formMT.providerAgnosticGlossariesGroup.Visible = true;
54+
}
55+
return errorMessage;
56+
}
57+
58+
public void glossaryControls_ValueChanged()
59+
{
60+
if (!internalControlChange)
61+
{
62+
FillOptions(this, options);
63+
}
64+
EnableDisable();
65+
}
66+
67+
public int[] GetGlossaries()
68+
{
69+
ReadGlossaries();
70+
if (glossaries == null)
71+
{
72+
return new int[0];
73+
}
74+
var checkedElements = formMT.listOfIntentoGlossaries.CheckedIndices.Cast<int>().ToList();
75+
76+
var result = new List<int>();
77+
foreach (var index in checkedElements)
78+
{
79+
result.Add(Convert.ToInt32(glossaries[index].id.Value));
80+
}
81+
return result.ToArray();
82+
}
83+
84+
public static void FillOptions(ProvideAgnosticGlossaryState state, IntentoMTFormOptions options)
85+
{
86+
if (state == null)
87+
{
88+
options.IntentoGlossaries = null;
89+
}
90+
else
91+
{
92+
options.IntentoGlossaries = state.GetGlossaries();
93+
}
94+
}
95+
96+
public void ClearOptions(IntentoMTFormOptions options)
97+
{
98+
options.IntentoGlossaries = null;
99+
HideVisibility(formMT);
100+
}
101+
102+
private void Clear(bool clearTextBox = true, bool clearComboBox = true)
103+
{
104+
internalControlChange = true;
105+
if (clearComboBox)
106+
{
107+
formMT.listOfIntentoGlossaries.Items.Clear();
108+
}
109+
internalControlChange = false;
110+
}
111+
112+
private void FillGlossaryControls()
113+
{
114+
if (!authState.IsOK)
115+
return;
116+
117+
if (!authState.providerState.intento_glossary)
118+
{ // glossaries are not supported by provider
119+
formMT.providerAgnosticGlossariesGroup.Visible = false;
120+
Clear();
121+
return;
122+
}
123+
formMT.providerAgnosticGlossariesGroup.Visible = true;
124+
125+
ReadGlossaries();
126+
ReadTypes();
127+
128+
Clear();
129+
130+
if (glossaries != null)
131+
{
132+
// Fill Glossary and choose SelectedIndex
133+
foreach (var x in glossaries)
134+
{
135+
var type = types?.FirstOrDefault(t => t.id == x.cs_type);
136+
var name = x.name.Value + (type != null ? $" ({type.name})" : "");
137+
int n = (int)formMT.listOfIntentoGlossaries.Items.Add(name);
138+
var currentValue = (int)Convert.ToInt32(glossaries[n].id.Value);
139+
if (options.IntentoGlossaries != null && options.IntentoGlossaries.Contains(currentValue))
140+
{
141+
formMT.listOfIntentoGlossaries.SetItemChecked(n, true);
142+
}
143+
}
144+
formMT.comboBoxGlossaries.Visible = true;
145+
}
146+
}
147+
148+
private bool readDone = false;
149+
private void ReadGlossaries()
150+
{
151+
if (readDone)
152+
{
153+
return;
154+
}
155+
try
156+
{
157+
glossaries = form._translate.AgnosticGlossaries();
158+
readDone = true;
159+
}
160+
catch
161+
{
162+
readDone = false;
163+
}
164+
}
165+
166+
private bool readTypesDone = false;
167+
168+
private void ReadTypes()
169+
{
170+
if (readTypesDone)
171+
{
172+
return;
173+
}
174+
try
175+
{
176+
types = form._translate.AgnosticGlossariesTypes();
177+
readTypesDone = true;
178+
}
179+
catch
180+
{
181+
readTypesDone = false;
182+
}
183+
}
184+
185+
#region methods for managing a group of controls
186+
187+
private static void HideVisibility(IntentoFormOptionsMT formMT)
188+
{
189+
formMT.providerAgnosticGlossariesGroup.Visible = false;
190+
formMT.listOfIntentoGlossaries.Visible = false;
191+
formMT.listOfIntentoGlossaries.Items.Clear();
192+
}
193+
194+
#endregion methods for managing a group of controls
195+
}
196+
}

0 commit comments

Comments
 (0)