-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathSandboxBase.cs
More file actions
4994 lines (4657 loc) · 168 KB
/
Copy pathSandboxBase.cs
File metadata and controls
4994 lines (4657 loc) · 168 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) 2015-2018 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)
//#define TraceMouseCalls // uncomment this line to trace mouse messages
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.Text;
using SIL.LCModel;
using SIL.FieldWorks.Common.RootSites;
using SIL.LCModel.Utils;
using SIL.FieldWorks.Common.FwUtils;
using SIL.FieldWorks.Common.ViewsInterfaces;
using SIL.FieldWorks.FdoUi;
using SIL.FieldWorks.Common.Widgets;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Infrastructure;
using SIL.LCModel.Core.Cellar;
using SIL.LCModel.Core.Text;
using SIL.LCModel.Core.KernelInterfaces;
using SIL.PlatformUtilities;
using XCore;
using SIL.WritingSystems;
using Icu.Collation;
namespace SIL.FieldWorks.IText
{
#region SandboxBase class
public partial class SandboxBase : RootSite
{
#region Model
// In some ways it would be nice for these to be enumerations, but it is too infuriating
// to have to keep casting them to ints. They are quite arbitrary constants; I have
// used largish numbers so they can easily be recognized when found somewhere in the
// debugger.
// An SbWord corresponds to a WfiWordform in the real model, though some of its
// properties store information from WfiAnalysis and WfiGloss as well.
internal const int kclsidSbWord = 6901;
// An SbMorph corresponds to a bundle of properties that are aligned with the morphs
// of a WfiAnalysis in the real model. The information comes from the WfiMorphBundles
// of the WfiAnalysis.
internal const int kclsidSbMorph = 6902;
// An SbNamedObject may be a LexEntry, LexSense, various kinds of CmPossibility...
// it is used anywhere that we need a reference to an object, and all we will display
// of it is its name.
// It was a tough call to know whether to make these properties refer to a
// CmNamedObject, or whether to just give the owning object a string property to hold
// the name. The advantage of this approach is that we know unambiguously when
// something is missing (object prop is 0), and also, we can more readily record
// correspondence between the dummy object and the real one which the name stands for.
internal const int kclsidSbNamedObj = 6903;
// String, the surface form of the word, the current vernacular ws alternative of
// the WfiWordform.Form; line 1.
internal const int ktagSbWordForm = 6901001;
// owning obj seq, the morpheme bundles, lines 2-5
public const int ktagSbWordMorphs = 6902002;
// Dummy tag used if there are no morphs.
internal const int ktagMissingMorphs = 6902003;
// The Form property of the Morph object (SbNamedObj), line 2. (Real obj is an MoForm.)
internal const int ktagSbMorphForm = 6902003;
// The 'Text' property of the SbMorph, taken from the real MoForm if any, otherwise
// from the real WfiMorphBundle
//internal const int ktagSbMorphText = 6902021;
// The LexEntry property of the Morph object, an SbNamedObj, line 3.
internal const int ktagSbMorphEntry = 6902004;
// The Name property of the NamedObj object, a string, used on several lines.
internal const int ktagSbNamedObjName = 6903005;
// Dummy tag used if the morph has no LexEntry
internal const int ktagMissingEntry = 6902006;
// The Gloss property of the Morph object, an SbNamedObj, line 4. (Real obj is a
// LexSense.)
internal const int ktagSbMorphGloss = 6902007;
// Dummy tag used if the morph has no Gloss.
internal const int ktagMissingMorphGloss = 6902008;
// The Pos property of the Morph object, an SbNamedObj, line 5. (Real obj is an MSA.)
internal const int ktagSbMorphPos = 6902009;
// Dummy tag used if the morph has no Pos.
internal const int ktagMissingMorphPos = 6902010;
// The POS of the word, an SbNameObj, line 7. (Real object is a PartOfSpeech.)
protected internal const int ktagSbWordPos = 6901012;
// Dummy tag used if the word has no Pos.
internal const int ktagMissingWordPos = 6901013;
// Dummy tag used to own SbNamedObjects we only want to refer to.
internal const int ktagSbWordDummy = 6901014;
// And this one if the word gloss is a guess.
internal const int ktagSbWordGlossGuess = 6901020;
// The word gloss.
internal protected const int ktagSbWordGloss = 6902021;
// Preceding punctuation for a morpheme.
internal const int ktagSbMorphPrefix = 6902015;
// Trailing punctuation for a morpheme.
internal const int ktagSbMorphPostfix = 6902016;
//// This is the hvo in the REAL cache of the MoMorphType that we should link
//// to if we have to create a new MoMorph. It isn't currently used.
//internal const int ktagSbMorphRealType = 6902017;
//// This is the clsid we should use to make a real MoMorph subclass if we
//// need to.
//internal const int ktagSbMorphClsid = 6902018;
// This is true if the named object is a guess.
internal const int ktagSbNamedObjGuess = 6903019;
// This is used to store an object corresponding to WfiMorphBundle.InflType.
internal const int ktagSbNamedObjInflType = 6903020;
// This group identify the pull-down icons. They must be the only tags in the range
// 6905000-6905999.
internal const int ktagMinIcon = 6905000;
internal const int ktagMorphFormIcon = 6905021;
internal const int ktagMorphEntryIcon = 6905022;
// The gloss of the word, a multi string (line 6):
internal protected const int ktagWordGlossIcon = 6905023;
internal protected const int ktagWordPosIcon = 6905024;
internal const int ktagAnalysisIcon = 6905025; // not yet used.
internal const int ktagWordLinkIcon = 6905026;
internal const int ktagLimIcon = 6906000;
#endregion Model
#region events
public event FwSelectionChangedEventHandler SelectionChangedEvent;
internal event SandboxChangedEventHandler SandboxChangedEvent;
#endregion events
#region Constants
// In an in-memory cache, we can 'create' a totally fake object by just inventing
// a number.
protected const int kSbWord = 10000007;
#endregion Constants
#region Data members
private int m_hvoLastSelEntry; // HVO in real cache of last selected lex entry.
protected CachePair m_caches = new CachePair();
protected InterlinLineChoices m_choices; // Keeps track of which lines to show.
// This object monitors property changes in the sandbox, primarily for edits to the morpheme breakdown.
// It can also be used to implement some problem deletions.
private SandboxEditMonitor m_editMonitor;
// This is used to store the initial state of our sandbox, so we can revert to it in case of an undo action.
protected int m_hvoInitialWag = 0;
private IVwStylesheet m_stylesheet;
// The original value of m_hvoWordform, to which we return if the user chooses
// 'Use default analysis' in the line-one chooser.
private IWfiWordform m_wordformOriginal;
// The text that appears in the word line, the original casing from the paragraph.
protected ITsString m_rawWordform;
// The annotation context for the sandbox.
protected AnalysisOccurrence m_occurrenceSelected;
// This flag controls behavior that depends on whether the word being analyzed should be treated
// as at the start of a sentence. Currently this affects the behavior for words with initial
// capitalization only.
private bool m_fTreatAsSentenceInitial = true;
// Indicates the case status of the wordform.
private StringCaseStatus m_case;
// If m_hvoWordform is set to zero, this should be set to the actual text that should be
// assigned to the new Wordform that will be created if GetRealAnalysis is called.
private ITsString m_tssWordform;
// The original Gloss we started with. ReviewP: Can we get rid of this?
private int m_hvoWordGloss;
private bool m_fSuppressShowCombo = true; // set to prevent SelectionChanged displaying combo.
private bool m_fShowAnalysisCombo = true; // false to hide Wordform-line combo (if no analyses).
internal IComboHandler m_ComboHandler; // handles most kinds of combo box.
private ChooseAnalysisHandler m_caHandler; // handles the one on the base line.
protected SandboxVc m_vc;
private Point m_LastMouseMovePos;
// Rectangle containing last selection passed to ShowComboForSelection.
private Rect m_locLastShowCombo;
// True during calls to MakeCombo to suppress selected index changed effects.
private bool m_fMakingCombo = false;
// True when the user has started editing text in the combo. Blocks moving and
// reinitializing the combo on mouse move, and ensures that we do something with what
// the user has typed on OK and mousedown elsewhere.
private bool m_fLockCombo = false;
// True to lay out with infinite width, expecting to be fully visible.
private bool m_fSizeToContent;
// We'd like to just use the VC's copy, but it may not get made in time.
private bool m_fShowMorphBundles = true;
// Flag used to prevent mouse move events from entering CallMouseMoveDrag multiple
// times before prior ones have exited. Otherwise we get lines displayed multiple
// times while scrolling during a selection.
private bool m_fMouseInProcess = false;
// This is set true by CallMouseMoveDrag if m_fNewSelection is true, and set false by
// either CallMouseDown or CallMouseUp. It controls whether CallMouseUp creates a
// range selection, and also controls whether ShowComboForSelection actually creates
// and shows the dropdown list.
private bool m_fInMouseDrag = false;
// This is set true by CallMouseDown after a new selection is created, and reset to
// false by CallMouseUp.
private bool m_fNewSelection = false;
// This flag handles keeping the combo dropdown list open after you click on the arrow
// but then proceed to drag before letting up on the mouse button.
private bool m_fMouseDownActivatedCombo = false;
// Normally we return a 'real' analysis in GetRealAnalysis() only if something in the
// cache changed (the user made some edit). In certain cases (guessing, choosing a
// different base form) we must return it even if nothing in the cache changed.
//private bool m_fForceReturnNewAnalysis;
private bool m_fHaveUndone; // tells whether an Undo has occurred since Sandbox started on this word.
private int m_rgbGuess = NoGuessColor;
// During processing of a right-click menu item, this is the morpheme the user clicked on
// (from the sandbox cache).
int m_hvoRightClickMorph;
// The analysis we guessed (may actually be a WfiGloss). If we didn't guess, it's the actual
// analysis we started with.
int m_hvoAnalysisGuess;
private SpellCheckHelper m_spellCheckHelper;
#endregion Data members
#region Properties
/// <summary>
/// Pass through to the VC.
/// </summary>
protected virtual bool IsMorphemeFormEditable
{
get { return true; }
}
public void UpdateLineChoices(InterlinLineChoices choices)
{
m_choices = choices;
if (m_vc != null)
m_vc.UpdateLineChoices(choices);
m_rootb.Reconstruct();
}
/// <summary>
/// When sandbox is visible, it should be the same as the InterlinDocForAnalysis m_hvoAnnotation.
/// However, when the Sandbox is not visible the parent is setting/sizing things up for a new annotation.
/// </summary>
public virtual int HvoAnnotation
{
get { return m_occurrenceSelected.Analysis.Hvo; }
}
/// <summary>
/// The writing system of the wordform in this analysis.
/// </summary>
int m_wsRawWordform = 0;
internal protected virtual int RawWordformWs
{
get
{
if (m_wsRawWordform == 0)
{
m_wsRawWordform = TsStringUtils.GetWsAtOffset(RawWordform, 0);
}
return m_wsRawWordform;
}
set
{
m_wsRawWordform = value;
// we want to establish a new RawWordform with the given ws.
m_rawWordform = null;
}
}
internal protected InterlinLineChoices InterlinLineChoices
{
get { return m_choices; }
}
/// <summary>
/// Returns the count of Sandbox.WordGlossHvo the used (across records) in the Text area.
/// (cf. LT-1428)
/// </summary>
protected virtual int WordGlossReferenceCount
{
get
{
return 0;
}
}
protected CaseFunctions VernCaseFuncs(ITsString tss)
{
var ws = m_caches.MainCache.ServiceLocator.WritingSystemManager.Get(TsStringUtils.GetWsAtOffset(tss, 0));
return new CaseFunctions(ws);
}
protected bool ComboOnMouseHover
{
get
{
return false;
}
}
protected bool IconsForAnalysisChoices
{
get
{
return true;
}
}
protected bool IsIconSelected
{
get
{
return new TextSelInfo(RootBox).IsPicture;
}
}
/// <summary>
/// the given word is a phrase if it has any word breaking space characters
/// </summary>
/// <param name="word"></param>
/// <returns></returns>
static internal bool IsPhrase(string word)
{
return !String.IsNullOrEmpty(word) && word.IndexOfAny(Common.FwUtils.Unicode.SpaceChars) != -1;
}
/// <summary>
/// Return true if there is no analysis worth saving.
/// </summary>
protected bool IsAnalysisEmpty
{
get
{
ISilDataAccess sda = m_caches.DataAccess;
// See if any alternate writing systems of word line are filled in.
List<int> wordformWss = m_choices.OtherEnabledWritingSystemsForFlid(InterlinLineChoices.kflidWord, 0);
foreach (int wsId in wordformWss)
{
if (sda.get_MultiStringAlt(kSbWord, ktagSbWordForm, wsId).Length > 0)
return false;
}
if (!IsMorphFormLineEmpty)
return false;
if (HasWordGloss())
return false;
// If we found nothing yet, it's non-empty if a word POS has been chosen.
return !HasWordCat();
}
}
/// <summary>
/// LT-7807. Controls whether or not confirming the analyses will try to update the Lexicon.
/// Only true for monomorphemic analyses.
/// </summary>
protected virtual bool ShouldAddWordGlossToLexicon
{
get
{
if (InterlinDoc == null)
return false;
return InterlinDoc.InModeForAddingGlossedWordsToLexicon && MorphCount == 1;
}
}
/// <summary>
/// True if user is in gloss tab.
/// </summary>
private bool IsInGlossMode()
{
if (InterlinDoc == null)
return false;
InterlinMaster master = InterlinDoc.GetMaster();
if (master == null)
return false;
return master.InterlinearTab == InterlinMaster.TabPageSelection.Gloss;
}
internal bool HasWordCat()
{
ISilDataAccess sda = m_caches.DataAccess;
return sda.get_ObjectProp(kSbWord, ktagSbWordPos) != 0;
}
internal bool HasWordGloss()
{
ISilDataAccess sda = m_caches.DataAccess;
foreach (int wsId in m_choices.EnabledWritingSystemsForFlid(InterlinLineChoices.kflidWordGloss))
{
// some analysis exists if any gloss multistring has content.
if (sda.get_MultiStringAlt(kSbWord, ktagSbWordGloss, wsId).Length > 0)
return true;
}
return false;
}
/// <summary>
/// This is useful for detecting whether or not the user has deleted the entire morpheme line
/// (cf. LT-1621).
/// </summary>
protected bool IsMorphFormLineEmpty
{
get
{
int cmorphs = MorphCount;
if (cmorphs == 0)
{
//Debug.Assert(!ShowMorphBundles); // if showing should always have one.
// JohnT: except when the user turned on morphology while the Sandbox was active...
return true;
}
if (MorphCount == 1)
{
int hvoMorph = m_caches.DataAccess.get_VecItem(kSbWord, ktagSbWordMorphs, 0);
ITsString tssFullForm = GetFullMorphForm(hvoMorph);
if (tssFullForm.Length == 0)
return true;
}
return false;
}
}
/// <summary>
/// Return the count of morphemes.
/// </summary>
/// <returns></returns>
public int MorphCount
{
get
{
CheckDisposed();
return Caches.DataAccess.get_VecSize(kSbWord, ktagSbWordMorphs);
}
}
/// <summary>
/// Return the list of msas as hvos
/// </summary>
public List<int> MsaHvoList
{
get
{
CheckDisposed();
int chvo = MorphCount;
using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative<int>(chvo))
{
Caches.DataAccess.VecProp(kSbWord, ktagSbWordMorphs, chvo, out chvo, arrayPtr);
int[] morphsHvoList = MarshalEx.NativeToArray<int>(arrayPtr, chvo);
List<int> msas = new List<int>(morphsHvoList.Length);
for (int i = 0; i < morphsHvoList.Length; i++)
{
int hvo = (int)morphsHvoList.GetValue(i);
if (hvo != 0)
{
int msaSecHvo = m_caches.DataAccess.get_ObjectProp(hvo, ktagSbMorphPos);
int msaHvo = m_caches.RealHvo(msaSecHvo);
msas.Add(msaHvo);
}
}
return msas;
}
}
}
internal CachePair Caches
{
get
{
CheckDisposed();
return m_caches;
}
}
public virtual ITsString RawWordform
{
get
{
CheckDisposed();
if (m_rawWordform == null || m_rawWordform.Length == 0)
{
IWfiWordform wf = CurrentAnalysisTree.Wordform;
if (m_wsRawWordform != 0)
m_rawWordform = wf.Form.get_String(m_wsRawWordform);
else
m_rawWordform = wf.Form.BestVernacularAlternative;
}
return m_rawWordform;
}
set
{
CheckDisposed();
m_rawWordform = value;
// we want RawWordformWs to be set to the ws of the new RawWordform.
m_wsRawWordform = 0;
}
}
/// <summary>
/// This controls behavior that depends on whether the word being analyzed should be treated
/// as at the start of a sentence. Currently this affects the behavior for words with initial
/// capitalization only.
/// </summary>
public bool TreatAsSentenceInitial
{
get
{
CheckDisposed();
return m_fTreatAsSentenceInitial;
}
set
{
CheckDisposed();
m_fTreatAsSentenceInitial = value;
}
}
/// <summary>
/// This property holds the color to use for any display that indicates multiple
/// analysis options are available. It should be set to the standard background color
/// if there is nothing to report.
/// </summary>
public int MultipleAnalysisColor
{
get { return m_multipleAnalysisColor; }
set
{
//avoid unnecessary side affects if no actual change is occurring.
if (m_multipleAnalysisColor != value)
{
m_multipleAnalysisColor = value;
//if we are having our information about multiple analysis state update,
//then update the vc if it already exists so that it will agree.
if (m_vc != null)
{
m_vc.MultipleOptionBGColor = m_multipleAnalysisColor;
}
}
}
}
static protected int NoGuessColor
{
get { return (int)CmObjectUi.RGB(DefaultBackColor); }
}
/// <summary>
/// indicates whether the current state of the sandbox is using a guessed analysis.
/// </summary>
public bool UsingGuess
{
get; set;
}
/// <summary>
/// Indicates the direction of flow of baseline that Sandbox is in.
/// (Only available after MakeRoot)
/// </summary>
public bool RightToLeftWritingSystem
{
get
{
return m_vc != null && m_vc.RightToLeft;
}
}
// Controls whether to display the morpheme bundles.
public bool ShowMorphBundles
{
get
{
CheckDisposed();
return m_fShowMorphBundles;
}
set
{
CheckDisposed();
m_fShowMorphBundles = value;
if (m_vc != null)
m_vc.ShowMorphBundles = value;
}
}
/// <summary>
/// Finds the interlinDoc that this Sandbox is embedded in.
/// </summary>
internal virtual InterlinDocForAnalysis InterlinDoc
{
get
{
return null;
}
}
internal int RootWordHvo
{
get
{
CheckDisposed();
return kSbWord;
}
}
/// <summary>
/// True if the combo on the Wordform line is wanted (there are known analyses).
/// </summary>
protected bool ShowAnalysisCombo
{
get { return m_fShowAnalysisCombo; }
}
/// <summary>
/// The index of the word we're editing among the context words we're showing.
/// Currently this is also it's index in the list of root objects.
/// </summary>
internal int IndexOfCurrentItem
{
get
{
CheckDisposed();
return 0;
}
}
internal SandboxEditMonitor SandboxEditMonitor
{
get
{
CheckDisposed();
return m_editMonitor;
}
}
public bool SizeToContent
{
get
{
CheckDisposed();
return m_fSizeToContent;
}
set
{
CheckDisposed();
m_fSizeToContent = value;
// If we are changing the window size to match the content, we don't want to autoscroll.
this.AutoScroll = !m_fSizeToContent;
}
}
internal ChooseAnalysisHandler FirstLineHandler
{
get
{
CheckDisposed();
return m_caHandler;
}
set
{
CheckDisposed();
m_caHandler = value;
}
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Disables/enables the Edit/Undo menu item
/// </summary>
/// <param name="commandObject"></param>
/// <param name="display"></param>
/// <returns><c>true</c></returns>
/// ------------------------------------------------------------------------------------
protected bool OnDisplayUndo(object commandObject, ref UIItemDisplayProperties display)
{
if (m_caches.DataAccess.IsDirty())
{
display.Enabled = true;
display.Text = ITextStrings.ksUndoAllChangesHere;
return true;
}
else
{
return false; // we don't want to handle the command.
}
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// This function will undo the last changes done to the project.
/// This function is executed when the user clicks the undo menu item.
/// </summary>
/// <param name="args">Unused</param>
/// <returns><c>true</c> if handled, otherwise <c>false</c></returns>
/// ------------------------------------------------------------------------------------
protected bool OnUndo(object args)
{
if (m_caches.DataAccess.IsDirty())
{
ResyncSandboxToDatabase();
m_fHaveUndone = true;
return true;
}
// We didn't handle it; some other colleague may be able to undo something we don't know about.
return false;
}
/// <summary>
/// Triggered to tell clients that the Sandbox has changed (e.g. been edited from
/// its initial state) to help determine whether we should allow trying to save or
/// undo the changes.
///
/// Currently triggered by SandboxEditMonitor.PropChanged whenever a property changes on the cache
/// </summary>
internal void OnUpdateEdited()
{
bool fIsEdited = m_caches.DataAccess.IsDirty();
//The user has now approved this candidate, remove any ambiguity indicating color.
if (fIsEdited)
MultipleAnalysisColor = NoGuessColor;
if (SandboxChangedEvent != null)
SandboxChangedEvent(this, new SandboxChangedEventArgs(fIsEdited));
}
/// <summary>
/// Resync the sandbox and reconstruct the rootbox to match the current state
/// of the database.
/// </summary>
internal void ResyncSandboxToDatabase()
{
CheckDisposed();
// hvoAnnotation should be a constant
ReconstructForWordBundleAnalysis(m_hvoInitialWag);
}
protected void ReconstructForWordBundleAnalysis(int hvoWag)
{
m_fHaveUndone = false;
HideCombos(); // Usually redundant, but MUST not have one around hooked to old data.
LoadForWordBundleAnalysis(hvoWag);
if (m_rootb == null)
MakeRoot();
else
m_rootb.Reconstruct();
}
internal void MarkAsInitialState()
{
// As well as noting that this IS the initial state, we want to record some things about the initial state,
// for possible use when resetting the focus box.
// Generally m_hvoInitialWag is more reliably set in LoadForWordBundleAnalysis, since by the time
// MarkInitialState is called, CurrentAnalysisTree.Analysis may have been cleared (e.g., if we are
// glossing a capitalized word at the start of a segment). It is important to set it here when saving
// an updated analysis, so that a subsequent undo will restore it to the saved value.
m_hvoAnalysisGuess = m_hvoInitialWag = CurrentAnalysisTree.Analysis != null ?
CurrentAnalysisTree.Analysis.Hvo : 0;
m_caches.DataAccess.ClearDirty(); // indicate we've loaded or saved.
OnUpdateEdited(); // tell client we've updated the state of the sandbox.
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Disables/enables the Edit/Undo menu item
/// </summary>
/// <param name="commandObject"></param>
/// <param name="display"></param>
/// <returns><c>true</c></returns>
/// ------------------------------------------------------------------------------------
protected bool OnDisplayRedo(object commandObject, ref UIItemDisplayProperties display)
{
// if the cache isn't dirty and we've done an Undo inside the annotation, we want
// a special message saying we can't redo. If the cache IS dirty, the user has been
// doing something since the Undo, so shouldn't expect Redo;
if (m_caches.DataAccess.IsDirty() || m_fHaveUndone)
{
display.Enabled = false;
if (m_fHaveUndone)
display.Text = ITextStrings.ksCannotRedoChangesHere;
// Otherwise just leave it a disabled 'Redo'; the user isn't expecting to be
// able to redo anything since he's 'done' something most recently.
return true;
}
else
return false; // we don't want to handle the command.
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Consistent with OnDisplayRedo.
/// </summary>
/// <param name="args">Unused</param>
/// <returns><c>true</c> if handled, otherwise <c>false</c></returns>
/// ------------------------------------------------------------------------------------
protected bool OnRedo(object args)
{
if (m_caches.DataAccess.IsDirty() || m_fHaveUndone)
{
return true; // We (didn't) do it.
}
// We didn't handle it; some other colleague may be able to undo something we don't know about.
return false;
}
/// <summary>
/// Indicates the case of the Wordform we're dealing with.
/// </summary>
public StringCaseStatus CaseStatus
{
get
{
CheckDisposed();
return m_case;
}
}
/// <summary>
/// The analysis object (in the real cache) that we started out looking at.
/// </summary>
public int Analysis
{
get
{
CheckDisposed();
if (CurrentAnalysisTree == null || CurrentAnalysisTree.Analysis == null)
return 0;
return CurrentAnalysisTree.Analysis.Hvo;
}
}
/// <summary>
/// Used to save the appropriate form to use for the new Wordform
/// that will be created if an alternate-case wordform that does not already exist is confirmed.
/// Also used as the first menu item in the morphemes menu when m_hvoWordform is zero.
/// </summary>
internal ITsString FormOfWordform
{
get
{
CheckDisposed();
return m_tssWordform;
}
}
/// <summary>
/// This is the WordGloss that the Sandbox was initialized with, either from the initial WAG or
/// from a guess.
/// </summary>
internal int WordGlossHvo
{
get
{
CheckDisposed();
return m_hvoWordGloss;
}
set
{
CheckDisposed();
m_hvoWordGloss = value;
}
}
/// <summary>
/// if the (anchor) selection is inside the display of a morpheme, return the index of that morpheme.
/// Otherwise, return -1.
/// </summary>
internal protected int MorphIndex
{
get
{
TextSelInfo tsi = new TextSelInfo(RootBox);
if (tsi.ContainingObjectTag(tsi.Levels(false) - 1) != ktagSbWordMorphs ||
tsi.TagAnchor == ktagMorphFormIcon) // don't count the morpheme dropdown icon.
return -1;
return tsi.ContainingObjectIndex(tsi.Levels(false) - 1);
}
}
/// <summary>
/// Return true if there is a selection that is at the start of the morpheme line for a particular morpheme
/// (that is, it's at the start of the prefix of the morpheme, or at the start of the name of the morpheme's form
/// AND it has no prefix)
/// </summary>
protected bool IsSelAtStartOfMorph
{
get
{
TextSelInfo tsi = new TextSelInfo(RootBox);
if (tsi.IsRange || tsi.IchEnd != 0 || tsi.Selection == null)
return false;
if (tsi.TagAnchor == ktagSbMorphPrefix)
return true;
if (tsi.TagAnchor != ktagSbNamedObjName)
return false;
// only the first Morpheme line is currently displaying prefix/postfix.
int currentLine = GetLineOfCurrentSelection();
if (currentLine != -1 && m_choices.IsFirstEnabledOccurrenceOfFlid(currentLine))
{
return (tsi.ContainingObjectTag(1) == ktagSbMorphForm
&& m_caches.DataAccess.get_StringProp(tsi.ContainingObject(1), ktagSbMorphPrefix).Length == 0);
}
else
{
return tsi.IchAnchor == 0;
}
}
}
/// <summary>
/// Return true if there is a selection that is at the end of the morpheme line for a particular morpheme
/// (that is, it's at the end of the postfix of the morpheme, or at the end of the name of the morpheme's form
/// AND it has no postfix)
/// </summary>
protected bool IsSelAtEndOfMorph
{
get
{
TextSelInfo tsi = new TextSelInfo(RootBox);
if (tsi.IsRange || tsi.IchEnd != tsi.AnchorLength || tsi.Selection == null)
return false;
if (tsi.TagAnchor == ktagSbMorphPostfix)
return true;
if (tsi.TagAnchor != ktagSbNamedObjName)
return false;
// only the first Morpheme line is currently displaying prefix/postfix.
int currentLine = GetLineOfCurrentSelection();
if (currentLine != -1 && m_choices.IsFirstEnabledOccurrenceOfFlid(currentLine))
{
return (tsi.ContainingObjectTag(1) == ktagSbMorphForm
&& m_caches.DataAccess.get_StringProp(tsi.ContainingObject(1), ktagSbMorphPostfix).Length == 0);
}
else
{
return tsi.AnchorLength == tsi.IchEnd;
}
}
}
/// <summary>
/// True if the selection is on the right edge of the morpheme.
/// </summary>
private bool IsSelAtRightOfMorph
{
get
{
if (m_vc.RightToLeft)
return IsSelAtStartOfMorph;
else
return IsSelAtEndOfMorph;
}
}
/// <summary>
/// True if the selection is on the left edge of the morpheme.
/// </summary>
private bool IsSelAtLeftOfMorph
{
get
{
if (m_vc.RightToLeft)
return IsSelAtEndOfMorph;
else
return IsSelAtStartOfMorph;
}
}
protected bool IsWordPosIconSelected
{
get
{
TextSelInfo tsi = new TextSelInfo(RootBox);
return tsi.IsPicture && tsi.TagAnchor == ktagWordPosIcon;
}
}
#endregion Properties
#region Construction, initialization & Disposal
public SandboxBase()
{
SubscribeToRootSiteEventHandlerEvents();
InitializeComponent();
CurrentAnalysisTree = new AnalysisTree();
// Tab should move between the piles inside the focus box! See LT-9228.
AcceptsTab = true;
}