-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathXmlBrowseViewBaseVc.cs
More file actions
1916 lines (1783 loc) · 71.2 KB
/
XmlBrowseViewBaseVc.cs
File metadata and controls
1916 lines (1783 loc) · 71.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2005-2025 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)
using System;
using System.Text.RegularExpressions;
using System.Xml;
using System.Collections.Generic;
using System.Drawing;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
using System.Reflection; // for check-box icons.
using SIL.FieldWorks.Common.FwUtils;
using SIL.LCModel;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Infrastructure;
using SIL.FieldWorks.Filters;
using SIL.FieldWorks.Common.ViewsInterfaces;
using SIL.FieldWorks.Resources; // for check-box icons.
using SIL.FieldWorks.Common.RootSites;
using SIL.LCModel.Core.Cellar;
using SIL.LCModel.Core.WritingSystems;
using SIL.LCModel.Core.KernelInterfaces;
using SIL.Utils;
using XCore;
namespace SIL.FieldWorks.Common.Controls
{
/// ----------------------------------------------------------------------------------------
/// <summary>
/// Summary description for XmlBrowseViewBaseVc.
/// </summary>
/// ----------------------------------------------------------------------------------------
public class XmlBrowseViewBaseVc : XmlVc
{
#region Constants
internal const int kfragRoot = 100000;
/// <summary></summary>
protected const int kfragListItem = 100001;
/// <summary></summary>
protected const int kfragCheck = 100002;
/// <summary></summary>
protected const int kfragEditRow = 100003;
/// <summary></summary>
protected internal const int kfragListItemInner = 100004;
/// <summary>(int)RGB(200, 255, 255)</summary>
public const int kclrTentative = 200 + 255 * 256 + 255 * 256*256;
#endregion Constants
#region Data Members
/// <summary>// Top-level fake property for list of objects.</summary>
protected int m_fakeFlid = 0;
/// <summary>// Controls appearance of column for check boxes.</summary>
protected bool m_fShowSelected;
/// <summary></summary>
protected IPicture m_UncheckedCheckPic;
/// <summary></summary>
protected IPicture m_CheckedCheckPic;
/// <summary></summary>
protected IPicture m_DisabledCheckPic;
/// <summary>Width in millipoints of the check box.</summary>
protected int m_dxmpCheckWidth;
/// <summary>Roughly 1-pixel border.</summary>
protected int m_dxmpCheckBorderWidth = 72000 / 96;
/// <summary></summary>
protected XmlBrowseViewBase m_xbv;
IPicture m_PreviewArrowPic;
IPicture m_PreviewRTLArrowPic;
int m_icolOverrideAllowEdit = -1; // index of column to force allow editing in.
bool m_fShowEnabled;
bool m_fInOnPaint;
// A writing system we wish to force to be used when a <string> element displays a multilingual property.
// Todo JohnT: Get rid of this!! It is set in a <column> element and used within the display of nested
// objects. This can produce unexpected results when the object property changes, because the inner
// Dispay() call is not within the outer one that normally sets m_wsForce.
// m_wsForce was introduced in place of m_columnNode as part of the process of getting rid of it.
private int m_wsForce;
// The writing system calculated by looking at the hvo and flid, as well as the ws attribute.
private int m_wsBest;
private int m_tagMe = XMLViewsDataCache.ktagTagMe;
/// <summary>
/// Set this variable true for displaying columns in reverse order. This may also affect
/// how the TAB key works.
/// </summary>
protected bool m_fShowColumnsRTL;
private static bool s_haveShownDefaultColumnMessage;
#pragma warning disable CS0414 // Field is assigned but never used - retained for potential future use
private bool m_fMultiColumnPreview = false;
#pragma warning restore CS0414
#endregion Data Members
#region Construction and initialization
internal string ColListId
{
get
{
string Id1 = m_xbv.m_bv.PropTable.GetStringProperty("currentContentControl", "");
string Id2 = m_xbv.GetCorrespondingPropertyName("ColumnList");
return String.Format("{0}_{1}", Id1, Id2);
}
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets or sets a value indicating whether [show enabled].
/// </summary>
/// <value><c>true</c> if [show enabled]; otherwise, <c>false</c>.</value>
/// ------------------------------------------------------------------------------------
public bool ShowEnabled
{
get
{
return m_fShowEnabled;
}
set
{
m_fShowEnabled = value;
}
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets a value indicating whether [show columns RTL].
/// </summary>
/// <value><c>true</c> if [show columns RTL]; otherwise, <c>false</c>.</value>
/// ------------------------------------------------------------------------------------
public bool ShowColumnsRTL
{
get
{
return m_fShowColumnsRTL;
}
}
/// <summary>
/// This contructor is used by SortMethodFinder to make a braindead VC.
/// </summary>
public XmlBrowseViewBaseVc() : base() // We don't have a string table.
{
m_fakeFlid = 0;
}
/// <summary>
/// This contructor is used by SortMethodFinder to make a partly braindead VC.
/// </summary>
public XmlBrowseViewBaseVc(XmlBrowseViewBase xbv)
{
MApp = xbv.m_bv.PropTable.GetValue<IApp>("FeedbackInfoProvider");
XmlBrowseViewBaseVcInit(xbv.Cache, xbv.DataAccess);
}
/// <summary>
/// This contructor is used by FilterBar and LayoutCache to make a badly braindead VC for special, temporary use.
/// It will fail if asked to interpret decorator properties, since it doesn't have the decorator SDA.
/// Avoid using this constructor if possible.
/// </summary>
public XmlBrowseViewBaseVc(LcmCache cache)
: base()
{
XmlBrowseViewBaseVcInit(cache, null);
}
/// <summary>
/// This contructor is used by FilterBar and LayoutCache to make a partly braindead VC.
/// </summary>
public XmlBrowseViewBaseVc(LcmCache cache, ISilDataAccess sda)
: base()
{
XmlBrowseViewBaseVcInit(cache, sda);
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="T:XmlBrowseViewBaseVc"/> class.
/// </summary>
/// <param name="xnSpec">The xn spec.</param>
/// <param name="fakeFlid">The fake flid.</param>
/// <param name="xbv">The XBV.</param>
/// ------------------------------------------------------------------------------------
public XmlBrowseViewBaseVc(XmlNode xnSpec, int fakeFlid, XmlBrowseViewBase xbv)
: this(xbv)
{
Debug.Assert(xnSpec != null);
Debug.Assert(xbv != null);
DataAccess = xbv.SpecialCache;
m_xbv = xbv;
m_xnSpec = xnSpec;
// This column list is saved in BrowseViewer.UpdateColumnList
string savedCols = m_xbv.m_bv.PropTable.GetStringProperty(ColListId, null, XCore.PropertyTable.SettingsGroup.LocalSettings);
SortItemProvider = xbv.SortItemProvider;
ComputePossibleColumns();
XmlDocument doc = null;
if (!string.IsNullOrEmpty(savedCols))
{
doc = GetSavedColumns(savedCols, m_xbv.Mediator, m_xbv.m_bv.PropTable, ColListId);
}
if (doc == null) // nothing saved, or saved info won't parse
{
// default: the columns that have 'width' specified.
foreach(XmlNode node in PossibleColumnSpecs)
{
if (XmlUtils.GetOptionalAttributeValue(node, "visibility", "always") == "always")
ColumnSpecs.Add(node);
}
}
else
{
var newPossibleColumns = new List<XmlNode>(PossibleColumnSpecs);
foreach (XmlNode node in doc.DocumentElement.SelectNodes("//column"))
{
// if there is a corresponding possible column, remove it from the newPossibleColumns list.
var possible = newPossibleColumns.Find(n =>
XmlUtils.GetOptionalAttributeValue(n, "label", "") ==
XmlUtils.GetOptionalAttributeValue(node, "label", "NONE"));
if (possible != null)
newPossibleColumns.Remove(possible);
if (IsValidColumnSpec(node))
ColumnSpecs.Add(node);
}
// Collect labels of columns the user deliberately removed (hidden).
var hiddenNodes = doc.DocumentElement.SelectNodes("//hidden");
var hiddenLabels = new HashSet<string>();
bool hasHiddenTracking = hiddenNodes.Count > 0;
if (hasHiddenTracking)
{
foreach (XmlNode hidden in hiddenNodes)
{
var label = XmlUtils.GetOptionalAttributeValue(hidden, "label", "");
if (!string.IsNullOrEmpty(label))
hiddenLabels.Add(label);
}
}
foreach (var node in newPossibleColumns)
{
if (!hasHiddenTracking)
{
// Bootstrap: no hidden tracking yet (pre-upgrade save).
// Don't auto-add anything — all missing columns are presumed
// deliberately removed. They'll be properly tracked on next save.
continue;
}
// Add common non-custom columns that were not in the saved list and not deliberately hidden.
var label = XmlUtils.GetOptionalAttributeValue(node, "label", "");
if (!hiddenLabels.Contains(label)
&& !IsCustomField(node, out _)
&& XmlUtils.GetOptionalAttributeValue(node, "common", "false") == "true")
{
ColumnSpecs.Add(node);
}
}
}
m_fakeFlid = fakeFlid;
SetupSelectColumn();
}
internal static XmlDocument GetSavedColumns(string savedCols, Mediator mediator, PropertyTable propertyTable, string colListId)
{
XmlDocument doc;
string target;
try
{
doc = new XmlDocument();
doc.LoadXml(savedCols);
int version = XmlUtils.GetOptionalIntegerValue(doc.DocumentElement, "version", 0);
if (version != BrowseViewer.kBrowseViewVersion)
{
// If we can fix problems introduced by a new version, fix them here.
// Otherwise throw up a dialog telling the user they are losing their settings.
switch (version)
{
// Process changes made in P4 Changelist 29278
case 12:
target = "<column label=\"Headword\" sortmethod=\"FullSortKey\" ws=\"$ws=vernacular\" editable=\"false\" width=\"96000\"><span><properties><editable value=\"false\" /></properties><string field=\"MLHeadWord\" ws=\"vernacular\" /></span></column>";
if (savedCols.IndexOf(target) > -1)
savedCols = savedCols.Replace(target, "<column label=\"Headword\" sortmethod=\"FullSortKey\" ws=\"$ws=vernacular\" editable=\"false\" width=\"96000\" layout=\"EntryHeadwordForFindEntry\" />");
target = "<column label=\"Lexeme Form\" visibility=\"menu\" common=\"true\" sortmethod=\"MorphSortKey\" ws=\"$ws=vernacular\" editable=\"false\"><span><properties><editable value=\"false\"/></properties><obj field=\"LexemeForm\" layout=\"empty\"><string field=\"Form\" ws=\"$ws=vernacular\"/></obj></span></column>";
if (savedCols.IndexOf(target) > -1)
savedCols = savedCols.Replace(target, "<column label=\"Lexeme Form\" visibility=\"menu\" common=\"true\" sortmethod=\"MorphSortKey\" ws=\"$ws=vernacular\" editable=\"false\" layout=\"LexemeFormForFindEntry\"/>");
target = "<column label=\"Citation Form\" visibility=\"menu\" sortmethod=\"CitationFormSortKey\" ws=\"$ws=vernacular\" editable=\"false\"><span><properties><editable value=\"false\"/></properties><string field=\"CitationForm\" ws=\"$ws=vernacular\"/></span></column>";
if (savedCols.IndexOf(target) > -1)
savedCols = savedCols.Replace(target, "<column label=\"Citation Form\" visibility=\"menu\" sortmethod=\"CitationFormSortKey\" ws=\"$ws=vernacular\" editable=\"false\" layout=\"CitationFormForFindEntry\"/>");
target = "<column label=\"Allomorphs\" editable=\"false\" width=\"96000\"><span><properties><editable value=\"false\"/></properties><seq field=\"AlternateForms\" layout=\"empty\" sep=\", \"><string field=\"Form\" ws=\"$ws=vernacular\"/></seq></span></column>";
if (savedCols.IndexOf(target) > -1)
savedCols = savedCols.Replace(target, "<column label=\"Allomorphs\" editable=\"false\" width=\"96000\" ws=\"$ws=vernacular\" layout=\"AllomorphsForFindEntry\"/>");
target = "<column label=\"Glosses\" multipara=\"true\" editable=\"false\" width=\"96000\"><seq field=\"Senses\" layout=\"empty\"><para><properties><editable value=\"false\"/></properties><string field=\"Gloss\" ws=\"$ws=analysis\"/></para></seq></column>";
if (savedCols.IndexOf(target) > -1)
savedCols = savedCols.Replace(target, "<column label=\"Glosses\" editable=\"false\" width=\"96000\" ws=\"$ws=analysis\" layout=\"GlossesForFindEntry\"/>");
savedCols = savedCols.Replace("root version=\"12\"", "root version=\"13\"");
goto case 13;
case 13:
savedCols = RemoveWeatherColumn(savedCols);
savedCols = savedCols.Replace("root version=\"13\"", "root version=\"14\"");
goto case 14;
case 14:
savedCols = FixVersion15Columns(savedCols);
savedCols = savedCols.Replace("root version=\"14\"", "root version=\"15\"");
goto case 15;
case 15:
savedCols = FixVersion16Columns(savedCols);
savedCols = savedCols.Replace("root version=\"15\"", "root version=\"16\"");
goto case 16;
case 16:
savedCols = FixVersion17Columns(savedCols);
savedCols = savedCols.Replace("root version=\"16\"", "root version=\"17\"");
goto case 17;
case 17:
savedCols = FixVersion18Columns(savedCols);
savedCols = savedCols.Replace("root version=\"17\"", "root version=\"18\"");
goto case 18;
case 18:
savedCols = FixVersion19Columns(savedCols);
savedCols = savedCols.Replace("root version=\"18\"", "root version=\"19\"");
goto case 19;
case 19:
savedCols = savedCols.Replace("root version=\"19\"", "root version=\"20\"");
propertyTable.SetProperty(colListId, savedCols, true);
doc.LoadXml(savedCols);
break;
default:
if (!s_haveShownDefaultColumnMessage)
{
s_haveShownDefaultColumnMessage = true; // FWR-1781 only show this once
MessageBox.Show(null, XMLViewsStrings.ksInvalidSavedLayout, XMLViewsStrings.ksNote);
}
doc = null;
// Forget the old settings, so we don't keep complaining every time the program runs.
// There doesn't seem to be any way to remove the property altogether, so at least, make it empty.
propertyTable.SetProperty(colListId, "", PropertyTable.SettingsGroup.LocalSettings, true);
break;
}
}
}
catch(Exception)
{
// If anything is wrong with the saved data (e.g., an old version that doesn't
// parse as XML), ignore it.
doc = null;
}
return doc;
}
/// <summary>
/// Handles the changes we made to add PictureLicense and PictureCreator to browse columns in 9.3
/// 9.3 (version 19, Dec 11, 2025).
/// </summary>
/// <param name="savedColsInput"></param>
/// <returns></returns>
internal static string FixVersion19Columns(string savedColsInput)
{
var savedCols = savedColsInput;
savedCols = AppendAttrValue(savedCols, "PictureLicenseForSense", "label", "Picture-License");
savedCols = AppendAttrValue(savedCols, "PictureLicenseForSense", "multipara", "true");
savedCols = AppendAttrValue(savedCols, "PictureLicenseForSense", "ws", "$ws=analysis vernacular");
savedCols = AppendAttrValue(savedCols, "PictureLicenseForSense", "editable", "false");
savedCols = AppendAttrValue(savedCols, "PictureLicenseForSense", "visibility", "dialog");
savedCols = AppendAttrValue(savedCols, "PictureCreatorForSense", "label", "Picture-Creator");
savedCols = AppendAttrValue(savedCols, "PictureCreatorForSense", "multipara", "true");
savedCols = AppendAttrValue(savedCols, "PictureCreatorForSense", "ws", "$ws=analysis vernacular");
savedCols = AppendAttrValue(savedCols, "PictureCreatorForSense", "editable", "false");
savedCols = AppendAttrValue(savedCols, "PictureCreatorForSense", "visibility", "dialog");
return savedCols;
}
/// <summary>
/// Handles the changes we made to browse columns between 8.3 Alpha and 8.3 Beta 2
/// 8.3 (version 18, Nov 11, 2016).
/// </summary>
/// <param name="savedColsInput"></param>
/// <returns></returns>
internal static string FixVersion18Columns(string savedColsInput)
{
var savedCols = savedColsInput;
savedCols = ChangeAttrValue(savedCols, "ExtNoteType", "ghostListField", "LexDb.AllPossibleExtendedNotes", "LexDb.AllExtendedNoteTargets");
savedCols = ChangeAttrValue(savedCols, "ExtNoteType", "label", "Ext. Note Type", "Ext. Note - Type");
savedCols = RemoveAttr(savedCols, "ExtNoteType", "editable");
savedCols = RemoveAttr(savedCols, "ExtNoteType", "ws");
savedCols = RemoveAttr(savedCols, "ExtNoteType", "transduce");
savedCols = AppendAttrValue(savedCols, "ExtNoteType", "list", "LexDb.ExtendedNoteTypes");
savedCols = AppendAttrValue(savedCols, "ExtNoteType", "field", "LexExtendedNote.ExtendedNoteType");
savedCols = AppendAttrValue(savedCols, "ExtNoteType", "bulkEdit", "atomicFlatListItem");
savedCols = AppendAttrValue(savedCols, "ExtNoteType", "displayWs", "best vernoranal");
savedCols = AppendAttrValue(savedCols, "ExtNoteType", "displayNameProperty", "ShortNameTSS");
savedCols = ChangeAttrValue(savedCols, "ExtNoteDiscussion", "ghostListField", "LexDb.AllPossibleExtendedNotes", "LexDb.AllExtendedNoteTargets");
savedCols = ChangeAttrValue(savedCols, "ExtNoteDiscussion", "label", "Ext. Note Discussion", "Ext. Note - Discussion");
savedCols = ChangeAttrValue(savedCols, "ExtNoteDiscussion", "editable", "false", "true");
return savedCols;
}
/// <summary>
/// Handles the changes we made to browse columns (other than additions) between roughly 7.3 (March 12, 2013) and
/// 8.3 (version 17, June 15, 2016).
/// </summary>
/// <param name="savedColsInput"></param>
/// <returns></returns>
internal static string FixVersion17Columns(string savedColsInput)
{
var savedCols = savedColsInput;
savedCols = ChangeAttrValue(savedCols, "EtymologyGloss", "transduce", "LexEntry.Etymology.Gloss", "LexEtymology.Gloss");
savedCols = ChangeAttrValue(savedCols, "EtymologySource", "transduce", "LexEntry.Etymology.Source", "LexEtymology.Source");
savedCols = ChangeAttrValue(savedCols, "EtymologyForm", "transduce", "LexEntry.Etymology.Form", "LexEtymology.Form");
savedCols = ChangeAttrValue(savedCols, "EtymologyComment", "transduce", "LexEntry.Etymology.Comment", "LexEtymology.Comment");
return savedCols;
}
/// <summary>
/// Handles the changes we made to browse columns (other than additions) between roughly 7.2 (April 20, 2011) and
/// 7.3 (version 16, March 12, 2013).
/// </summary>
/// <param name="savedColsInput"></param>
/// <returns></returns>
internal static string FixVersion16Columns(string savedColsInput)
{
var savedCols = savedColsInput;
savedCols = ChangeAttrValue(savedCols, "CVPattern", "ws", "pronunciation", "$ws=pronunciation");
savedCols = ChangeAttrValue(savedCols, "Tone", "ws", "pronunciation", "$ws=pronunciation");
savedCols = ChangeAttrValue(savedCols, "ScientificNameForSense", "ws", "analysis", "$ws=analysis");
savedCols = ChangeAttrValue(savedCols, "SourceForSense", "ws", "analysis", "$ws=analysis");
savedCols = AppendAttrValue(savedCols, "CustomPossAtomForEntry", true, "displayNameProperty", "ShortNameTSS");
savedCols = AppendAttrValue(savedCols, "CustomPossAtomForSense", true, "displayNameProperty", "ShortNameTSS");
savedCols = AppendAttrValue(savedCols, "CustomPossAtomForAllomorph", true, "displayNameProperty", "ShortNameTSS");
savedCols = AppendAttrValue(savedCols, "CustomPossAtomForExample", true, "displayNameProperty", "ShortNameTSS");
savedCols = ChangeAttrValue(savedCols, "ComplexEntryTypesBrowse", "ws", "\\$ws=analysis", "$ws=best analysis");
savedCols = ChangeAttrValue(savedCols, "VariantEntryTypesBrowse", "ws", "\\$ws=analysis", "$ws=best analysis");
savedCols = ChangeAttrValue(savedCols, "ComplexEntryTypesBrowse", "originalWs", "\\$ws=analysis", "$ws=best analysis");
savedCols = ChangeAttrValue(savedCols, "VariantEntryTypesBrowse", "originalWs", "\\$ws=analysis", "$ws=best analysis");
savedCols = AppendAttrValue(savedCols, "EtymologyGloss", "transduce", "LexEntry.Etymology.Gloss");
savedCols = AppendAttrValue(savedCols, "EtymologySource", "transduce", "LexEntry.Etymology.Source");
savedCols = AppendAttrValue(savedCols, "EtymologyForm", "transduce", "LexEntry.Etymology.Form");
savedCols = AppendAttrValue(savedCols, "EtymologyComment", "transduce", "LexEntry.Etymology.Comment");
return savedCols;
}
private static string FixVersion15Columns(string savedColsInput)
{
var savedCols = savedColsInput;
savedCols = new Regex("<column layout=\"IsAHeadwordForEntry\"[^>]*>").Replace(savedCols,
"<column layout=\"PublishAsHeadword\" multipara=\"true\" label=\"Show As Headword In\" width=\"72000\" " +
"bulkEdit=\"complexListMultiple\" field=\"LexEntry.ShowMainEntryIn\" list=\"LexDb.PublicationTypes\" displayNameProperty=\"ShortNameTSS\" " +
"displayWs=\"best analysis\" visibility=\"dialog\"/>");
savedCols = ChangeAttrValue(savedCols, "IsAbstractFormForEntry", "bulkEdit", "integerOnSubfield", "booleanOnSubfield");
savedCols = ChangeAttrValue(savedCols, "ExceptionFeatures", "label", "'Exception' Features", "Exception 'Features'");
savedCols = AppendAttrValue(savedCols, "PictureCaptionForSense", "ws", "$ws=vernacular analysis");
savedCols = ChangeAttrValue(savedCols, "AcademicDomainsForSense", "displayWs", "analysis", "best analysis");
savedCols = ChangeAttrValue(savedCols, "StatusForSense", "list", "LexDb.Status", "LangProject.Status");
savedCols = AppendAttrValue(savedCols, "ComplexEntryTypesBrowse", "ghostListField", "LexDb.AllComplexEntryRefPropertyTargets");
savedCols = AppendAttrValue(savedCols, "VariantEntryTypesBrowse", "ghostListField", "LexDb.AllVariantEntryRefPropertyTargets");
savedCols = FixCustomFields(savedCols, "Entry_", "LexEntry");
savedCols = FixCustomFields(savedCols, "Sense_", "LexSense");
savedCols = FixCustomFields(savedCols, "Allomorph_", "MoForm");
savedCols = FixCustomFields(savedCols, "Example_", "LexExampleSentence");
return savedCols;
}
private static string FixCustomFields(string savedCols, string layoutNameFragment, string className)
{
savedCols = AppendAttrValue(savedCols, "CustomIntegerFor" + layoutNameFragment, true, "sortType", "integer");
savedCols = AppendAttrValue(savedCols, "CustomGenDateFor" + layoutNameFragment, true, "sortType", "genDate");
savedCols = AppendAttrValue(savedCols, "CustomPossVectorFor" + layoutNameFragment, true, "bulkEdit", "complexListMultiple");
savedCols = AppendAttrValue(savedCols, "CustomPossVectorFor" + layoutNameFragment, true, "field", className + ".$fieldName");
savedCols = AppendAttrValue(savedCols, "CustomPossVectorFor" + layoutNameFragment, true, "list", "$targetList");
savedCols = AppendAttrValue(savedCols, "CustomPossVectorFor" + layoutNameFragment, true, "displayNameProperty", "ShortNameTSS");
savedCols = AppendAttrValue(savedCols, "CustomPossAtomFor" + layoutNameFragment, true, "bulkEdit", "atomicFlatListItem");
savedCols = AppendAttrValue(savedCols, "CustomPossAtomFor" + layoutNameFragment, true, "field", className + ".$fieldName");
savedCols = AppendAttrValue(savedCols, "CustomPossAtomFor" + layoutNameFragment, true, "list", "$targetList");
return savedCols;
}
private static string ChangeAttrValue(string savedCols, string layoutName, string attrName, string attrValue, string replaceWith)
{
var pattern = new Regex("<column [^>]*layout *= *\"" + layoutName + "\"[^>]*" + attrName + " *= *\"(" + attrValue + ")\"");
var match = pattern.Match(savedCols);
if (match.Success)
{
int index = match.Groups[1].Index;
// It is better to use Groups(1).Length here rather than attrValue.Length, because there may be some RE pattern
// in attrValue (e.g., \\$) which would make a discrepancy.
savedCols = savedCols.Substring(0, index) + replaceWith + savedCols.Substring(index +match.Groups[1].Length);
}
return savedCols;
}
private static string RemoveAttr(string savedCols, string layoutName, string attrName)
{
var pattern = new Regex("<column [^>]*layout *= *\"" + layoutName + "\"[^>]*(" + attrName + "=\"[^\r\n\t\f ]*\" )");
var match = pattern.Match(savedCols);
if (match.Success)
{
int index = match.Groups[1].Index;
// It is better to use Groups(1).Length here rather than attrValue.Length, because there may be some RE pattern
// in attrValue (e.g., \\$) which would make a discrepancy.
savedCols = savedCols.Substring(0, index) + savedCols.Substring(index + match.Groups[1].Length);
}
return savedCols;
}
private static string AppendAttrValue(string savedCols, string layoutName, string attrName, string attrValue)
{
return AppendAttrValue(savedCols, layoutName, false, attrName, attrValue);
}
private static string AppendAttrValue(string savedCols, string layoutName, bool customField, string attrName, string attrValue)
{
// If it's not a custom field we expect to know the layout name exactly, so should match a closing quote.
// If it is a custom field, any layout name that starts with the expected string...typically generated from something like
// "CustomIntegerForEntry_$fieldName"...is a match.
var close = customField ? "" : "\"";
var pattern = new Regex("<column [^>]*layout *= *\"" + layoutName + close + "[^>]*/>");
var match = pattern.Match(savedCols);
if (match.Success)
{
int index = match.Index + match.Length - 2; // just before closing />
var leadIn = savedCols.Substring(0, index);
var gap = " "; // for neatness don't put an extra space if we already have one.
if (leadIn.EndsWith(" "))
gap = "";
savedCols = leadIn + gap + attrName + "=\"" + attrValue + "\"" + savedCols.Substring(index);
}
return savedCols;
}
/// <summary>
/// This contructor is used by SortMethodFinder to make a braindead VC.
/// </summary>
private void XmlBrowseViewBaseVcInit(LcmCache cache, ISilDataAccess sda)
{
Debug.Assert(cache != null);
m_fakeFlid = 0;
Cache = cache; // sets m_mdc and m_layouts as well as m_cache.
if (sda != null)
DataAccess = sda;
}
private static string RemoveWeatherColumn(string savedCols)
{
var pattern = new Regex("<column layout=\"Weather\"[^>]*>");
return pattern.Replace(savedCols, "");
}
/// <summary>
/// Setup the check-mark column, if desired.
/// </summary>
protected virtual void SetupSelectColumn()
{
XmlAttribute xa = m_xnSpec.Attributes["selectColumn"];
m_fShowSelected = xa != null && xa.Value == "true";
if (m_fShowSelected)
{
// Only need these if showing the selected column.
m_UncheckedCheckPic = m_app.PictureHolder.GetPicture("UncheckedCheckBox", ResourceHelper.UncheckedCheckBox);
m_CheckedCheckPic = m_app.PictureHolder.GetPicture("CheckedCheckBox", ResourceHelper.CheckedCheckBox);
m_DisabledCheckPic = m_app.PictureHolder.GetPicture("DisabledCheckBox", ResourceHelper.DisabledCheckBox);
// We want a width in millipoints (72000/inch). Value we have is in 100/mm.
// There are 25.4 mm/inch.
m_dxmpCheckWidth = m_UncheckedCheckPic.Width * 72000 / 2540;
}
}
/// <summary>
/// Provide access to the special tag used to implement highlighting the selected row.
/// </summary>
internal int TagMe
{
get
{
return m_tagMe;
}
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// compute and return possible columns. This always recomputes them, so may pick
/// up generated columns for new custom fields.
/// </summary>
/// <returns></returns>
/// ------------------------------------------------------------------------------------
public List<XmlNode> ComputePossibleColumns()
{
XmlVc vc = null;
if (ListItemsClass != 0)
vc = this;
return PossibleColumnSpecs = PartGenerator.GetGeneratedChildren(m_xnSpec.SelectSingleNode("columns"), m_xbv.Cache, vc, (int)ListItemsClass);
}
int m_listItemsClass = 0;
/// <summary>
/// the class (or base class) of the items in SortItemProvider
/// </summary>
internal int ListItemsClass
{
get
{
if (m_listItemsClass == 0)
{
// try to get the listItemsClass information
// so we can build our columns (and custom fields) properly.
if (SortItemProvider != null)
{
// Remember, if we have a sortItemProvider, we can use this class info to generate parts for specific custom fields
m_listItemsClass = SortItemProvider.ListItemsClass;
}
else
{
// we still need to know what listItemsClass to expect this list to be based on.
string listItemsClass = XmlUtils.GetMandatoryAttributeValue(m_xnSpec, "listItemsClass");
m_listItemsClass = m_cache.MetaDataCacheAccessor.GetClassId(listItemsClass);
}
}
return m_listItemsClass;
}
set
{
m_listItemsClass = value;
}
}
/// <summary>
/// Check to see if column spec is still valid. If it is a custom field, update the label if necessary.
/// </summary>
internal bool IsValidColumnSpec(XmlNode colSpec)
{
// If it is a Custom Field, check that it is valid and has the correct label.
if (IsCustomField(colSpec, out var isValid))
{
return isValid;
}
// If the column matches a known PossibleColumnSpec by label, it is valid.
// Check this before GetPartFromParentNode because some views (e.g. Phonological Features
// with FsFeatDefn) have valid columns whose class hierarchy has no matching parts in
// the part inventory; GetPartFromParentNode would incorrectly reject those columns.
var label = XmlUtils.GetLocalizedAttributeValue(colSpec, "label", null) ??
XmlUtils.GetMandatoryAttributeValue(colSpec, "label");
var originalLabel = XmlUtils.GetLocalizedAttributeValue(colSpec, "originalLabel", null) ??
XmlUtils.GetAttributeValue(colSpec, "originalLabel");
if (XmlViewsUtils.FindNodeWithAttrVal(PossibleColumnSpecs, "label", label) != null ||
XmlViewsUtils.FindNodeWithAttrVal(PossibleColumnSpecs, "label", originalLabel) != null)
{
return true;
}
// For columns not in PossibleColumnSpecs (e.g. generated columns with a layout
// attribute), fall back to checking whether the part/layout inventory can resolve
// the column. Columns without a layout attribute that aren't in PossibleColumnSpecs
// are invalid (GetPartFromParentNode would trivially return the node itself).
if (XmlUtils.GetOptionalAttributeValue(colSpec, "layout") == null)
return false;
return GetPartFromParentNode(colSpec, ListItemsClass) != null;
}
/// <summary>
/// Check whether the column spec is a custom field, and if so, if it is still valid (Custom Fields can be deleted).
/// If the node refers to a valid custom field, the label attribute is adjusted to what we want the user to see.
/// </summary>
private bool IsCustomField(XmlNode colSpec, out bool isValidCustomField)
{
if (!TryColumnForCustomField(colSpec, ListItemsClass, out var columnForCustomField, out var propWs))
{
isValidCustomField = false;
return false;
}
if (columnForCustomField != null)
{
var fieldName = XmlUtils.GetAttributeValue(columnForCustomField, "field");
var className = XmlUtils.GetAttributeValue(columnForCustomField, "class");
if (!string.IsNullOrEmpty(fieldName) && !string.IsNullOrEmpty(className) &&
((IFwMetaDataCacheManaged)m_mdc).FieldExists(className, fieldName, false))
{
ColumnConfigureDialog.GenerateColumnLabel(colSpec, m_cache);
isValidCustomField = true;
}
else
{
isValidCustomField = false;
}
}
else if (propWs == null)
{
isValidCustomField = false;
}
else
{
XmlUtils.AppendAttribute(colSpec, "originalLabel", GetNewLabelFromMatchingCustomField(propWs.flid));
ColumnConfigureDialog.GenerateColumnLabel(colSpec, m_cache);
isValidCustomField = true;
}
return true;
}
private string GetNewLabelFromMatchingCustomField(int flid)
{
foreach (var possibleColumn in PossibleColumnSpecs)
{
// Desired node may be a child of a child... (See LT-6447.)
if (TryColumnForCustomField(possibleColumn, ListItemsClass, out _, out var propWs))
{
// the flid of the updated custom field node matches the given flid of the old node.
if (propWs != null && propWs.flid == flid)
{
return XmlUtils.GetLocalizedAttributeValue(possibleColumn, "label", null);
}
}
}
return "";
}
#endregion Construction and initialization
#region Properties
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets or sets the override allow edit column.
/// </summary>
/// <value>The override allow edit column.</value>
/// ------------------------------------------------------------------------------------
public int OverrideAllowEditColumn
{
get
{
return m_icolOverrideAllowEdit;
}
set
{
m_icolOverrideAllowEdit = value;
}
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets a value indicating whether this instance has select column.
/// </summary>
/// <value>
/// <c>true</c> if this instance has select column; otherwise, <c>false</c>.
/// </value>
/// ------------------------------------------------------------------------------------
public bool HasSelectColumn
{
get
{
return m_fShowSelected;
}
}
/// <summary>
/// Specifies the default state of check boxes
/// </summary>
public bool DefaultChecked
{
get
{
if (m_sda is XMLViewsDataCache)
return (m_sda as XMLViewsDataCache).DefaultSelected;
// pretty arbitrary, probably something else will crash if using this without
// the proper kind of cache, but it makes more sense than the other, since it
// is our general default.
return true;
}
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets the width of the select column.
/// </summary>
/// <value>The width of the select column.</value>
/// ------------------------------------------------------------------------------------
public int SelectColumnWidth
{
get
{
return m_dxmpCheckWidth + 4 * m_dxmpCheckBorderWidth;
}
}
/// <returns>
/// A list of the labels for the visible columns in their configured order
/// </returns>
public static List<string> GetHeaderLabels(XmlBrowseViewBaseVc vc)
{
var headerLabelList = new List<string>();
foreach (var col in vc.ColumnSpecs)
{
headerLabelList.Add(XmlUtils.GetLocalizedAttributeValue(col, "label", null) ??
XmlUtils.GetMandatoryAttributeValue(col, "label"));
}
return headerLabelList;
}
/// <summary>
/// Specifications of columns to display
/// </summary>
protected internal virtual List<XmlNode> ColumnSpecs { get; set; } = new List<XmlNode>();
/// <summary>
/// Specs of columns that COULD be displayed, regardless of whether they have been selected.
/// </summary>
protected internal List<XmlNode> PossibleColumnSpecs { get; set; }
/// <summary></summary>
protected internal ISortItemProvider SortItemProvider { get; set; }
/// <summary>
/// Use this to store a suitable preview arrow if we will be displaying previews.
/// (See BulkEditBar.)
/// </summary>
internal Image PreviewArrow
{
set
{
m_PreviewArrowPic = m_app.PictureHolder.GetPicture("PreviewArrow", value);
Image x = value;
x.RotateFlip(RotateFlipType.Rotate180FlipNone);
m_PreviewRTLArrowPic = m_app.PictureHolder.GetPicture("PreviewRTLArrow", x);
}
}
internal bool HasPreviewArrow
{
get { return m_PreviewArrowPic != null; }
}
#endregion Properties
#region Other methods
/// <summary>
/// Convert a .NET color to the type understood by Views code and other Win32 stuff.
/// </summary>
/// <param name="c"></param>
/// <returns></returns>
static public uint RGB(System.Drawing.Color c)
{
return RGB(c.R, c.G, c.B);
}
/// <summary>
/// Make a standard Win32 color from three components.
/// </summary>
/// <param name="r"></param>
/// <param name="g"></param>
/// <param name="b"></param>
/// <returns></returns>
static public uint RGB(int r, int g, int b)
{
return ((uint)(((byte)(r)|((short)((byte)(g))<<8))|(((short)(byte)(b))<<16)));
}
/// <summary>Border color to use</summary>
private System.Drawing.Color m_BorderColor = SystemColors.Control; // System.Drawing.Color.LightGray;
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets or sets the color of the border.
/// </summary>
/// <value>The color of the border.</value>
/// ------------------------------------------------------------------------------------
public System.Drawing.Color BorderColor
{
get
{
return m_BorderColor;
}
set
{
m_BorderColor = value;
}
}
const int kclrBackgroundSelRow = (int)0xFFE6D7;
internal virtual int SelectedRowBackgroundColor(int hvo)
{
return kclrBackgroundSelRow;
}
/// <summary>
/// Add a new table/row to the view for one existing object.
/// </summary>
/// <param name="vwenv"></param>
/// <param name="hvo"></param>
/// <param name="frag"></param>
protected virtual void AddTableRow(IVwEnv vwenv, int hvo, int frag)
{
// set the border color
vwenv.set_IntProperty((int )FwTextPropType.ktptBorderColor,
(int)FwTextPropVar.ktpvDefault,
(int)RGB(m_BorderColor));
// If we're using this special mode where just one column is editable, we need to make
// sure as far as possible that everything else is not.
if (OverrideAllowEditColumn >= 0)
vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int) FwTextPropVar.ktpvEnum,
(int)TptEditable.ktptNotEditable);
int index, hvoDummy, tagDummy;
int clev = vwenv.EmbeddingLevel;
vwenv.GetOuterObject(clev - 2, out hvoDummy, out tagDummy, out index);
if (index >= m_sda.get_VecSize(hvoDummy, tagDummy))
return; // something to fix.
if (index == m_xbv.SelectedIndex && m_xbv.SelectedRowHighlighting != XmlBrowseViewBase.SelectionHighlighting.none)
{
vwenv.set_IntProperty((int)FwTextPropType.ktptBackColor,
(int)FwTextPropVar.ktpvDefault,
// (int)RGB(Color.FromKnownColor(KnownColor.Highlight)));
SelectedRowBackgroundColor(hvo));
if (m_xbv.SelectedRowHighlighting == XmlBrowseViewBase.SelectionHighlighting.border)
{
vwenv.set_IntProperty((int)FwTextPropType.ktptBorderTop,
(int)FwTextPropVar.ktpvMilliPoint,
3000);
vwenv.set_IntProperty((int)FwTextPropType.ktptBorderColor,
(int)FwTextPropVar.ktpvDefault,
(int)RGB(Color.FromKnownColor(KnownColor.Highlight)));
}
}
// Make a table.
VwLength[] rglength = m_xbv.GetColWidthInfo();
int colCount = ColumnSpecs.Count;
if (m_fShowSelected)
colCount++;
// LT-7014, 7058: add the additional columns that are needed
if (rglength.Length < colCount)
{
VwLength[] rglengthNEW = new VwLength[colCount];
for (int ii = 0; ii < colCount; ii++)
{
if (ii < rglength.Length)
rglengthNEW[ii] = rglength[ii];
else
rglengthNEW[ii] = rglength[0];
}
rglength = rglengthNEW;
}
// If the only columns specified are custom fields which have been deleted,
// we can't show anything! (and we don't want to crash -- see LT-6449)
if (rglength.Length == 0)
return;
VwLength vl100; // Length representing 100% of the table width.
vl100.unit = rglength[0].unit;
vl100.nVal = 1;
for (int i = 0; i < colCount; ++i)
{
Debug.Assert(vl100.unit == rglength[i].unit);
vl100.nVal += rglength[i].nVal;
}
vwenv.OpenTable(colCount, // this many columns
vl100, // using 100% of available space
72000 / 96, //0, // no border
VwAlignment.kvaLeft, // cells by default left aligned
// VwFramePosition.kvfpBelow, //.kvfpBox, //.kvfpVoid, // no frame
VwFramePosition.kvfpBelow | VwFramePosition.kvfpRhs,
VwRule.kvrlCols, // vertical lines between columns
0, // no space between cells
0, // no padding within cell.
false);
// Set column widths.
for (int i = 0; i < colCount; ++i)
vwenv.MakeColumns(1, rglength[i]);
// the table only has a body (no header or footer), and only one row.
vwenv.OpenTableBody();
vwenv.OpenTableRow();
if (m_fShowSelected)
AddSelectionCell(vwenv, hvo);
// Make the cells.
int hvoRoot, tagDummy2, ihvoDummy;
vwenv.GetOuterObject(0, out hvoRoot, out tagDummy2, out ihvoDummy);
int icolActive = GetActiveColumn(vwenv, hvoRoot);
// if m_fShowSelected is true, we get an extra column of checkmarks that gives us
// a different index into the columns. This allows the one-based indexing to work
// in the call to ColumnSortedFromEnd. Without this, the one-based indexing has to
// be adjusted to zero-based indexing.
int cAdjCol = m_fShowSelected ? 0 : 1;
if (m_fShowColumnsRTL)
{
for (int icol = ColumnSpecs.Count; icol > 0; --icol)