-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathInterlinMaster.cs
More file actions
1483 lines (1337 loc) · 49.3 KB
/
InterlinMaster.cs
File metadata and controls
1483 lines (1337 loc) · 49.3 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 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.Collections.Generic;
using System.Drawing;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
using SIL.LCModel.Core.Text;
using SIL.LCModel.Core.KernelInterfaces;
using SIL.LCModel;
using SIL.LCModel.DomainServices;
using SIL.FieldWorks.Common.ViewsInterfaces;
using SIL.FieldWorks.XWorks;
using SIL.FieldWorks.Common.RootSites;
using SIL.FieldWorks.Common.Widgets;
using XCore;
using SIL.LCModel.Infrastructure;
using SIL.FieldWorks.Common.FwUtils;
using static SIL.FieldWorks.Common.FwUtils.FwUtils;
using SIL.Utils;
namespace SIL.FieldWorks.IText
{
/// <summary>
/// InterlinMaster is a master control for the main pane of an interlinear view.
/// It holds and information bar ("Information"), a TitleContents pane,
/// another information bar ("Text"/"Interlinear Text") with a label button
/// ("Show Interlinear"/"Show Raw Text") and then either a RawTextPane or an
/// InterlinDocChild. Eventually it may also show a SandBox, and perhaps a
/// segment of a lexicon! This comment is way out-of-date!
/// </summary>
public partial class InterlinMaster : InterlinMasterBase, IFocusablePanePortion
{
// Controls
protected IVwStylesheet m_styleSheet;
protected InfoPane m_infoPane; // Parent is m_tpInfo.
static public Dictionary<Tuple<string, Guid>, InterAreaBookmark> m_bookmarks;
private bool m_fParsedTextDuringSave;
// This flag is normally set during a Refresh. When it is set, we suppress switching the focus box
// to the current occurrence in a concordance view, which would otherwise happen as a side effect
// of the Refresh. Instead, as usual the focus box stays wherever it is now. The flag is cleared
// on the next call to ShowRecord.
// If we don't have a current record, Refresh won't result in ShowRecord being called, so we don't
// need to set the flag (and must not, lest it interfere with the next time we move to a different
// occurrence).
private bool m_fRefreshOccurred;
// true (typically used as concordance 3rd pane) to suppress autocreating a text if the
// clerk has no current object.
protected bool m_fSuppressAutoCreate;
private string m_currentTool = "";
public string CurrentTool
{
get { return m_currentTool; }
}
/// <summary>
/// Numbers identifying the main tabs in the interlinear text.
/// </summary>
public enum TabPageSelection
{
Info = 0,
RawText = 1,
Gloss = 2,
Interlinearizer = 3,
TaggingView = 4,
PrintView = 5,
ConstituentChart = 6
}
// These constants allow us to use a switch statement in SaveBookMark()
const int ktpsInfo = (int)TabPageSelection.Info;
const int ktpsRawText = (int)TabPageSelection.RawText;
const int ktpsGloss = (int)TabPageSelection.Gloss;
const int ktpsAnalyze = (int)TabPageSelection.Interlinearizer;
const int ktpsTagging = (int)TabPageSelection.TaggingView;
const int ktpsPrint = (int)TabPageSelection.PrintView;
const int ktpsCChart = (int)TabPageSelection.ConstituentChart;
public InterlinMaster()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
}
internal string BookmarkId
{
get { return m_vectorName ?? ""; }
}
/// <summary>
/// Something sometimes insists on giving the tab control focus when switching tabs.
/// This defeats ctrl-tab to move between tabs.
/// </summary>
void m_tabCtrl_GotFocus(object sender, EventArgs e)
{
if (m_tabCtrl.SelectedTab == null)
return;
var child = (from Control c in m_tabCtrl.SelectedTab.Controls select c).FirstOrDefault();
if (child != null)
child.Focus();
}
/// <summary>
/// Called by reflection when the browse view steals the focus.
/// </summary>
/// <param name="sender"></param>
public void OnBrowseViewStoleFocus(object sender)
{
m_tabCtrl_GotFocus(sender, new EventArgs());
}
internal bool ParsedDuringSave
{
get
{
CheckDisposed();
return m_fParsedTextDuringSave;
}
set
{
CheckDisposed();
m_fParsedTextDuringSave = value;
}
}
internal TitleContentsPane TitleContentsPane
{
get { return m_tcPane; }
set { m_tcPane = value; }
}
protected int GetWidth(string text, Font fnt)
{
int width;
using (Graphics g = Graphics.FromHwnd(Handle))
{
width = (int)g.MeasureString(text, fnt).Width + 1;
}
return width;
}
void SetStyleSheetFor(IStyleSheet site)
{
if (m_styleSheet == null)
SetupStyleSheet();
if (site != null)
site.StyleSheet = m_styleSheet;
}
IInterlinearTabControl CurrentInterlinearTabControl { get; set; }
void SetCurrentInterlinearTabControl(IInterlinearTabControl pane)
{
CurrentInterlinearTabControl = pane;
SetupInterlinearTabControlForStText(pane);
}
private void SetupInterlinearTabControlForStText(IInterlinearTabControl site)
{
InitializeInterlinearTabControl(site);
//if (site is ISetupLineChoices && m_tabCtrl.SelectedIndex != ktpsCChart)
if (site is ISetupLineChoices interlinearView)
{
interlinearView.SetupLineChoices($"InterlinConfig_v3_{(interlinearView.ForEditing ? "Edit" : "Doc")}_{InterlinearTab}",
$"InterlinConfig_v2_{(interlinearView.ForEditing ? "Edit" : "Doc")}_{InterlinearTab}",
GetLineMode());
}
// Review: possibly need to do SetPaneSizeAndRoot
if (site is IChangeRootObject rootObject)
{
if (rootObject is Control)
{
(rootObject as Control).SuspendLayout();
}
rootObject.SetRoot(RootStTextHvo);
if (rootObject is Control)
{
(rootObject as Control).ResumeLayout();
}
}
}
internal InterlinLineChoices.InterlinMode GetLineMode()
{
switch (m_tabCtrl.SelectedIndex)
{
case (int)TabPageSelection.Gloss:
return m_propertyTable.GetBoolProperty(InterlinDocForAnalysis.ksPropertyAddWordsToLexicon, false) ?
InterlinLineChoices.InterlinMode.GlossAddWordsToLexicon : InterlinLineChoices.InterlinMode.Gloss;
case (int)TabPageSelection.ConstituentChart:
return InterlinLineChoices.InterlinMode.Chart;
case (int)TabPageSelection.TaggingView:
return InterlinLineChoices.InterlinMode.Gloss;
default:
return InterlinLineChoices.InterlinMode.Analyze;
}
}
protected override void OnHandleCreated(EventArgs e)
{
if (m_styleSheet == null)
{
SetupStyleSheet();
if (m_styleSheet != null)
{
SetStyleSheetFor(m_tcPane);
SetStyleSheetFor(CurrentInterlinearTabControl as IStyleSheet);
}
}
base.OnHandleCreated(e);
// re-select our annotation if we're in the raw text pane, since
// initialization subsequent to ShowRecord() loses our selection.
if (m_tabCtrl.SelectedIndex == ktpsRawText)
this.SelectAnnotation();
}
/// <summary>
/// Override method to add other content to main control.
/// </summary>
protected override void AddPaneBar()
{
try
{
SetupStyleSheet();
base.AddPaneBar();
}
catch (ApplicationException)
{
//m_informationBar = new ImageHolder(); //something to show at design time
}
}
protected override void SetInfoBarText()
{
if (m_informationBar != null && m_configurationParameters != null)
{
string sAltTitle = XmlUtils.GetAttributeValue(m_configurationParameters, "altTitleId");
if (!String.IsNullOrEmpty(sAltTitle))
{
string sTitle = StringTable.Table.GetString(sAltTitle, "AlternativeTitles");
if (!String.IsNullOrEmpty(sTitle))
{
((IPaneBar)m_informationBar).Text = sTitle;
return;
}
}
}
base.SetInfoBarText();
}
/// <summary>
/// do any further tabpage related setup based upon the interlinMaster configurationParameters.
/// </summary>
/// <param name="configurationParameters">configuration for InterlinMaster</param>
private void FinishInitTabPages(XmlNode configurationParameters)
{
//
// Finish defining m_tpRawText.
//
bool fEditable = XmlUtils.GetOptionalBooleanAttributeValue(configurationParameters, "editable", true);
if (!fEditable)
m_tpRawText.ToolTipText = String.Format(ITextStrings.ksBaseLineNotEditable);
}
private void SetupStyleSheet()
{
m_styleSheet = FontHeightAdjuster.StyleSheetFromPropertyTable(m_propertyTable);
}
/// <summary>
/// Sets m_bookmarks to what is currently selected and persists it.
/// </summary>
internal void SaveBookMark()
{
CheckDisposed();
if (m_tabCtrl.SelectedIndex == ktpsInfo || CurrentInterlinearTabControl == null)
return; // nothing to save...for now, don't overwrite existing one.
if (RootStText == null)
return;
AnalysisOccurrence curAnalysis = null;
var fSaved = false;
switch (m_tabCtrl.SelectedIndex)
{
case ktpsAnalyze:
fSaved = SandboxPaneBookmarkSave(m_idcAnalyze, ref curAnalysis);
break;
case ktpsGloss:
fSaved = SandboxPaneBookmarkSave(m_idcGloss, ref curAnalysis);
break;
case ktpsCChart:
if (m_constChartPane == null) // Have added this to designer
return; // e.g., right after creating a new database, when previous one was open in chart pane.
// Call CChart.GetUnchartedWordForBookmark() by reflection to see where the chart
// thinks the bookmark should be.
var type = m_constChartPane.GetType();
var info = type.GetMethod("GetUnchartedWordForBookmark");
Debug.Assert(info != null);
curAnalysis = (AnalysisOccurrence)info.Invoke(m_constChartPane, null);
break;
case ktpsTagging:
if (m_taggingPane != null)
curAnalysis = m_taggingPane.OccurrenceContainingSelection();
break;
case ktpsPrint:
if (m_printViewPane != null)
curAnalysis = m_printViewPane.OccurrenceContainingSelection();
break;
case ktpsRawText:
// Find the analysis we were working on.
if (m_rtPane != null)
{
if (SaveBookmarkFromRootBox(m_rtPane.RootBox))
return;
}
break;
default:
Debug.Fail("Unhandled tab index.");
break;
}
if (curAnalysis == null || !curAnalysis.IsValid)
// This result means the Chart doesn't want to save a bookmark,
// or that something else went wrong (e.g., we couldn't make a bookmark because we just deleted the text).
return;
if (!fSaved)
{
InterAreaBookmark mark;
if(m_bookmarks.TryGetValue(new Tuple<string, Guid>(CurrentTool, RootStText.Guid), out mark))
{
//We only want to persist the save if we are in the interlinear edit, not the concordance view
mark.Save(curAnalysis, CurrentTool.Equals("interlinearTexts"), IndexOfTextRecord);
}
else
{
mark = new InterAreaBookmark(this, Cache, m_propertyTable);
mark.Restore(IndexOfTextRecord);
m_bookmarks.Add(new Tuple<string, Guid>(CurrentTool, RootStText.Guid), mark);
}
}
}
/// <summary>
/// Returns true if it already saved a bookmark (from RootBox), false otherwise.
/// </summary>
/// <param name="pane"></param>
/// <param name="curAnalysis">ref var comes out with the location to be saved.</param>
/// <returns></returns>
private bool SandboxPaneBookmarkSave(InterlinDocForAnalysis pane, ref AnalysisOccurrence curAnalysis)
{
if (pane == null) // Can this really happen? Perhaps if !m_fullyinitialized?
{
if (m_rtPane != null) // Not the one, but the other? Odd.
{
if (SaveBookmarkFromRootBox(m_rtPane.RootBox))
return true;
}
}
else
curAnalysis = pane.OccurrenceContainingSelection();
return false;
}
private bool SaveBookmarkFromRootBox(IVwRootBox rb)
{
if (rb == null || rb.Selection == null)
return false;
// There may be pictures in the text, and the selection may be on a picture or its
// caption. Therefore, getting the TextSelInfo is not enough. See LT-7906.
// Unfortunately, the bookmark for a picture or its caption can only put the user
// back in the same paragraph, it can't fully reestablish the exact same position.
var iPara = -1;
var helper = SelectionHelper.GetSelectionInfo(rb.Selection, rb.Site);
var ichAnchor = helper.IchAnchor;
var ichEnd = helper.IchEnd;
var hvoParaAnchor = 0;
var hvoParaEnd = 0;
var sliAnchor = helper.GetLevelInfo(SelectionHelper.SelLimitType.Anchor);
var sliEnd = helper.GetLevelInfo(SelectionHelper.SelLimitType.End);
if (sliAnchor.Length != sliEnd.Length)
ichEnd = ichAnchor;
for (var i = 0; i < sliAnchor.Length; ++i)
{
if (sliAnchor[i].tag == StTextTags.kflidParagraphs)
{
hvoParaAnchor = sliAnchor[i].hvo;
break;
}
}
for (var i = 0; i < sliEnd.Length; ++i)
{
if (sliEnd[i].tag != StTextTags.kflidParagraphs)
continue;
hvoParaEnd = sliEnd[i].hvo;
break;
}
if (hvoParaAnchor != 0)
{
IStTxtPara para = null;
if (Cache.ServiceLocator.GetInstance<IStTxtParaRepository>().TryGetObject(hvoParaAnchor, out para))
{
iPara = para.IndexInOwner;
if (hvoParaAnchor != hvoParaEnd)
ichEnd = ichAnchor;
if (ichAnchor == -1)
ichAnchor = 0;
if (ichEnd == -1)
ichEnd = 0;
}
}
if (iPara >= 0)
{
//if there is a bookmark for this text with this tool, then save it, if not some logic error brought us here,
//but simply not saving a bookmark which doesn't exist seems better than crashing. naylor 3/2012
var key = new Tuple<string, Guid>(CurrentTool, RootStText.Guid);
if (m_bookmarks.ContainsKey(key))
{
m_bookmarks[key].Save(IndexOfTextRecord, iPara, Math.Min(ichAnchor, ichEnd), Math.Max(ichAnchor, ichEnd), true);
}
return true;
}
return false;
}
protected override void OnLayout(LayoutEventArgs levent)
{
if (m_styleSheet == null)
return; // cannot display properly without style sheet, so don't try.
// LT-10995: the TitleContentsPane m_tcPane and the TabControl m_tabCtrl used to be
// docked (definition in InterlinMaster.resx). However, this led to problems if the
// font size of displayed data got changed. So we are doing the layout ourselves now:
m_tabCtrl.Width = this.Width; // tab control width = container width
if (m_tcPane == null)
{
// If there is no TitleContentsPane then the TabControl needs to occupy the
// entire container:
m_tabCtrl.Location = new Point(0, 0);
m_tabCtrl.Height = this.Height;
}
else
{
// If there is a TitleContentsPane then it needs to be at the top of the
// container, match the container's width, and have its height calculated
// automatically:
m_tcPane.Location = new Point(0,0);
m_tcPane.Width = this.Width;
m_tcPane.AdjustHeight();
// And then the TabControl needs to fill the rest of the container below
// the TitleContentsPane:
m_tabCtrl.Location = new Point(0, m_tcPane.Height);
m_tabCtrl.Height = this.Height - m_tcPane.Height;
}
base.OnLayout(levent);
}
public void OnPropertyChanged(string name)
{
CheckDisposed();
switch (name)
{
case "InterlinearTab":
if (m_tabCtrl.SelectedIndex != (int)InterlinearTab)
ShowTabView();
break;
}
}
/// <summary>
/// Enable if there's anything to select. This is needed so that the toolbar button is
/// disabled when there's nothing to look up. Otherwise, crashes can result when it's
/// clicked but there's nothing there to process! It's misleading to the user if
/// nothing else. We leave the button visible so that the user doesn't get nauseated
/// from the buttons appearing and disappearing rapidly.
/// </summary>
/// <param name="commandObject"></param>
/// <param name="display"></param>
/// <returns>true</returns>
public bool OnDisplayLexiconLookup(object commandObject,
ref UIItemDisplayProperties display)
{
CheckDisposed();
display.Visible = true;
//LT-6904 : exposed the case where the m_rtPane was null
// (another case of toolbar processing being done at an unexpected time)
display.Enabled = m_tabCtrl.SelectedIndex == ktpsRawText ?
m_rtPane?.LexiconLookupEnabled() ?? false : false;
return true;
}
private int RootStTextHvo
{
get
{
CheckDisposed();
return RootStText != null ? (((ICmObject)RootStText).IsValidObject ? RootStText.Hvo : 0) : 0;
}
}
/// <remarks>virtual for tests</remarks>
internal protected virtual IStText RootStText { get; private set; }
internal int TextListFlid
{
get
{
CheckDisposed();
return Clerk.VirtualFlid;
}
}
internal int TextListIndex
{
get
{
CheckDisposed();
return Clerk.CurrentIndex;
}
}
bool m_fInShowTabView = false;
protected void ShowTabView()
{
SaveWorkInProgress();
m_fInShowTabView = true;
try
{
m_tabCtrl.SelectedIndex = (int)InterlinearTab; // set the persisted tab setting.
if (m_tabCtrl.SelectedIndex == ktpsCChart && m_constChartPane == null)
{
// This is the first time on this tab, do lazy creation
CreateCChart();
}
RefreshPaneBar();
// search through the current tab page controls until we find one implementing IInterlinearTabControl
var currentTabControl = FindControls<IInterlinearTabControl>(m_tabCtrl.SelectedTab.Controls).FirstOrDefault();
SetCurrentInterlinearTabControl(currentTabControl as IInterlinearTabControl);
if (CurrentInterlinearTabControl == null)
return; // nothing to show.
switch (m_tabCtrl.SelectedIndex)
{
case ktpsRawText:
if (ParentForm == Form.ActiveForm)
m_rtPane.Focus();
if (m_rtPane.RootBox != null && m_rtPane.RootBox.Selection == null && RootStText != null)
m_rtPane.RootBox.MakeSimpleSel(true, false, false, true);
break;
case ktpsCChart:
if (RootStText == null)
m_constChartPane.Enabled = false;
else
{
// LT-7733 Warning dialog for Text Chart
XMessageBoxExManager.Trigger("TextChartNewFeature");
m_constChartPane.Enabled = true;
}
//SetConstChartRoot(); should be done above in SetCurrentInterlinearTabControl()
if (ParentForm == Form.ActiveForm)
m_constChartPane.Focus();
break;
case ktpsInfo:
//We may already be initialized, but this is not very expensive and sometimes
//the infoPane was initialized with no data and should be re-initialized here
m_infoPane.Initialize(Cache, m_mediator, m_propertyTable, Clerk);
m_infoPane.Dock = DockStyle.Fill;
m_infoPane.Enabled = m_infoPane.CurrentRootHvo != 0;
m_infoPane.BackColor = m_infoPane.Enabled ? SystemColors.Control : Color.White;
if (m_infoPane.Enabled && ParentForm == Form.ActiveForm)
m_infoPane.Focus();
break;
default:
break;
}
SelectAnnotation();
UpdateContextHistory();
}
finally
{
m_fInShowTabView = false;
}
}
private void CreateCChart()
{
m_constChartPane = (InterlinDocChart)DynamicLoader.CreateObject("Discourse.dll",
"SIL.FieldWorks.Discourse.ConstituentChart",
new object[] { Cache, m_propertyTable });
SetupChartPane();
m_tpCChart.Controls.Add(m_constChartPane);
if (m_styleSheet != null)
m_styleSheet = ((IStyleSheet)m_constChartPane).StyleSheet;
}
private void SetupChartPane()
{
(m_constChartPane as IxCoreColleague).Init(m_mediator, m_propertyTable, m_configurationParameters);
m_constChartPane.BackColor = SystemColors.Window;
m_constChartPane.Name = "m_constChartPane";
m_constChartPane.Dock = DockStyle.Fill;
}
/// <summary>
/// Finds the controls implementing TInterfaceMatch
/// </summary>
/// <typeparam name="TInterfaceMatch"></typeparam>
/// <param name="controls"></param>
/// <returns></returns>
private static IEnumerable<Control> FindControls<TInterfaceMatch>(ControlCollection controls)
{
foreach (Control c in controls)
{
if (c is TInterfaceMatch)
yield return c;
foreach (var c2 in FindControls<TInterfaceMatch>(c.Controls))
yield return c2;
}
}
private void RefreshPaneBar()
{
// if we're in the context of a PaneBar, refresh the bar so the menu items will
// reflect the current tab.
if (MainPaneBar != null && MainPaneBar is UserControl && (MainPaneBar as UserControl).Parent is PaneBarContainer)
((MainPaneBar as UserControl).Parent as PaneBarContainer).RefreshPaneBar();
}
/// <summary>
/// Determine whether we need to parse any of the texts paragraphs.
/// </summary>
/// <param name="stText"></param>
/// <returns></returns>
public static bool HasParagraphNeedingParse(IStText stText)
{
return stText.ParagraphsOS.Cast<IStTxtPara>().Any(para => !para.ParseIsCurrent);
}
/// <summary>
/// todo: add progress bar.
/// typically a delegate for NonUndoableUnitOfWorkHelper
/// </summary>
/// <param name="stText">
/// <param name="forceParse">
/// </param>
public static void LoadParagraphAnnotationsAndGenerateEntryGuessesIfNeeded(IStText stText, bool forceParse)
{
if (stText == null)
return;
using (var pp = new ParagraphParser(stText.Cache))
{
if (forceParse)
{
foreach (var para in stText.ParagraphsOS.Cast<IStTxtPara>())
{
pp.ForceParse(para);
}
}
else
{
foreach (var para in stText.ParagraphsOS.Cast<IStTxtPara>().Where(
para => !para.ParseIsCurrent))
{
pp.Parse(para);
}
}
}
var services = new AnalysisGuessServices(stText.Cache);
services.GenerateEntryGuesses(stText);
}
/// <summary>
/// Required override for RecordView subclass.
/// </summary>
/// <param name="mediator"></param>
/// <param name="propertyTable"></param>
/// <param name="configurationParameters"></param>
public override void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configurationParameters)
{
CheckDisposed();
// Do this BEFORE calling InitBase, which calls ShowRecord, whose correct behavior
// depends on the suppressAutoCreate flag.
bool fHideTitlePane = XmlUtils.GetBooleanAttributeValue(configurationParameters, "hideTitleContents");
// When used as the third pane of a concordance, we don't want the
// title/contents stuff.
if (fHideTitlePane)
m_tcPane.Visible = false;
m_fSuppressAutoCreate = XmlUtils.GetBooleanAttributeValue(configurationParameters,
"suppressAutoCreate");
// InitBase will do this, but we need it in place for testing IsPersistedForAnInterlinearTabPage.
m_mediator = mediator;
// InitBase will do this, but we need it in place before calling SetInitialTabPage().
m_propertyTable = propertyTable;
SetParsingDevMode(IsParsingDevMode());
// Making the tab control currently requires this first...
if (!fHideTitlePane)
{
m_tcPane.StyleSheet = m_styleSheet;
m_tcPane.Visible = true;
}
if (m_bookmarks != null && m_bookmarks.Count > 0)
{
foreach (InterAreaBookmark bookmark in m_bookmarks.Values)
{
bookmark.Init(this, Cache, propertyTable);
}
}
FinishInitTabPages(configurationParameters);
SetInitialTabPage();
m_currentTool = configurationParameters.Attributes["clerk"].Value;
// Do NOT do this, it raises an exception.
//base.Init (mediator, configurationParameters);
// Instead do this.
InitBase(mediator, propertyTable, configurationParameters);
m_fullyInitialized = true;
RefreshPaneBar();
Subscriber.Subscribe(EventConstants.RefreshInterlin, RefreshInterlin);
}
/// <summary>
/// Set the appropriate tab index BEFORE calling InitBase, since that calls
/// RecordView.InitBase, which calls ShowRecord, which calls ShowTabView,
/// which will unnecessarily create the wrong pane, if the tab index is wrong.
/// </summary>
private void SetInitialTabPage()
{
// If the Record Clerk has remembered we're IsPersistedForAnInterlinearTabPage,
// and we haven't already switched to that tab page, do so now.
m_tabCtrl.SelectedIndex = Visible && m_tabCtrl.SelectedIndex != (int)InterlinearTab ?
// Switch to the persisted tab page index.
(int)InterlinearTab :
ktpsRawText;
}
/// <summary>
/// From IxCoreContentControl
/// </summary>
/// <returns>true if ok to go away</returns>
public override bool PrepareToGoAway()
{
CheckDisposed();
SaveBookMark();
if (!SaveWorkInProgress()) return false;
return base.PrepareToGoAway();
}
private bool SaveWorkInProgress()
{
if (m_idcAnalyze != null && m_idcAnalyze.Visible && !m_idcAnalyze.PrepareToGoAway())
return false;
if (m_idcGloss != null && m_idcGloss.Visible && !m_idcGloss.PrepareToGoAway())
return false;
return true;
}
public bool OnPrepareToRefresh(object args)
{
CheckDisposed();
// flag that a refresh was triggered (unless we don't have a current record..see var comment).
if (RootStTextHvo != 0)
m_fRefreshOccurred = true;
return false; // other things may wish to prepare too.
}
protected override void SetupDataContext()
{
base.SetupDataContext();
InitializeInterlinearTabControl(m_tcPane);
InitializeInterlinearTabControl(CurrentInterlinearTabControl);
}
private void InitializeInterlinearTabControl(IInterlinearTabControl site)
{
if (site != null)
{
SetStyleSheetFor(site as IStyleSheet);
site.Cache = Cache;
if (site is IxCoreColleague)
(site as IxCoreColleague).Init(m_mediator, m_propertyTable, m_configurationParameters);
}
}
/// <summary>
/// The record index of the currently selected text.
/// </summary>
internal int IndexOfTextRecord
{
get
{
CheckDisposed();
if (Clerk.CurrentObjectHvo != 0 && Cache.ServiceLocator.IsValidObjectId(Clerk.CurrentObjectHvo))
{
if (Clerk.CurrentObject.ClassID == StTextTags.kClassId)
return Clerk.CurrentIndex;
}
return -1;
}
}
internal string TitleOfTextRecord
{
get
{
CheckDisposed();
if (Clerk.CurrentObject != null)
{
var rootObj = Clerk.CurrentObject;
if (rootObj.ClassID == TextTags.kClassId)
{
var text = rootObj as LCModel.IText;
return text.Name.AnalysisDefaultWritingSystem.Text;
}
}
return string.Empty;
}
}
protected override void ShowRecord(RecordNavigationInfo rni)
{
base.ShowRecord(rni);
// independent of whether base.ShowRecord(rni) skips ShowRecord()
// we still want to try to put the focus in our control.
// (but only if we're in the active window -- see FWR-1795)
if (ParentForm == Form.ActiveForm)
this.Focus();
}
/// <summary>
/// This is an attempt to improve scrolling by mouse wheel, by passing on focus when the interlin master gets it.
/// </summary>
/// <param name="e"></param>
protected override void OnGotFocus(EventArgs e)
{
if (m_tabCtrl.SelectedTab != null && m_tabCtrl.SelectedTab.Controls[0].CanFocus)
m_tabCtrl.SelectedTab.Controls[0].Focus();
}
/// <summary>
/// Save any intermediate analysis information on validation requests
/// note: this is triggered before a Send/Receive operation
/// </summary>
/// <param name="e"></param>
protected override void OnValidating(System.ComponentModel.CancelEventArgs e)
{
base.OnValidating(e);
SaveWorkInProgress();
}
private void RefreshInterlin(object argument)
{
// Reset data.
RootStText = null;
m_idcAnalyze.ResetAnalysisCache();
// Refresh the display.
Clerk.JumpToIndex(Clerk.CurrentIndex);
}
protected override void ShowRecord()
{
SaveWorkInProgress();
base.ShowRecord();
if (Clerk.SuspendLoadingRecordUntilOnJumpToRecord)
return;
//This is our very first time trying to show a text, if possible we would like to show the stored text.
if (m_bookmarks == null)
m_bookmarks = new Dictionary<Tuple<string, Guid>, InterAreaBookmark>();
// It's important not to do this if there is a filter, as there's a good chance the new
// record doesn't pass the filter and we get into an infinite loop. Also, if the user
// is filtering, he probably just wants to see that there are no matching texts, not
// make a new one.
if (Clerk is InterlinearTextsRecordClerk &&
Clerk.CurrentObjectHvo == 0 && !m_fSuppressAutoCreate && !Clerk.ShouldNotModifyList
&& Clerk.Filter == null)
{
// This is needed in SwitchText(0) to avoid LT-12411 when in Info tab.
// We'll get a chance to do it later.
Clerk.SuppressSaveOnChangeRecord = true;
// first clear the views of their knowledge of the previous text.
// otherwise they could crash trying to access information that is no longer valid. (LT-10024)
SwitchText(0);
// Presumably because there are none..make one.
// This is invisible to the user so it should not be undoable; that is particularly
// important if the most recent action was to delete the last text, which will
// not be undoable if we are now showing 'Undo insert text'.
NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
{
// We don't want to force a Save here if we just deleted the last text;
// we want to be able to Undo deleting it!
var options = new RecordClerk.ListUpdateHelper.ListUpdateHelperOptions();
options.SuppressSaveOnChangeRecord = true;
using (new RecordClerk.ListUpdateHelper(Clerk, options))
((InterlinearTextsRecordClerk)Clerk).AddNewTextNonUndoable();
});
}
if (Clerk.CurrentObjectHvo == 0)
{
SwitchText(0); // We no longer have a text.
return; // We get another call when there is one.
}
var hvoRoot = Clerk.CurrentObjectHvo;
if (Clerk.CurrentObjectHvo != 0 && !Cache.ServiceLocator.IsValidObjectId(Clerk.CurrentObjectHvo)) // RecordClerk is tracking an analysis
{
// This pane, as well as knowing how to work with a record list of Texts, knows
// how to work with one of fake objects in a concordance, that is, a list of occurrences of
// a word.
hvoRoot = SetConcordanceBookmarkAndReturnRoot(hvoRoot);
}
else
{
var stText = Cache.ServiceLocator.GetInstance<IStTextRepository>().GetObject(hvoRoot);
if (stText.ParagraphsOS.Count == 0)
NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
((InterlinearTextsRecordClerk)Clerk).CreateFirstParagraph(stText, Cache.DefaultVernWs));
if (stText.ParagraphsOS.Count == 1 && ((IStTxtPara)stText.ParagraphsOS[0]).Contents.Length == 0)
{
// If we have restarted FLEx since this text was created, the WS has been lost and replaced with the userWs.
// If this is the case, default to the Default Vernacular WS (LT-15688 & LT-20837)
var userWs = Cache.ServiceLocator.WritingSystemManager.UserWs;
if(stText.MainWritingSystem == userWs)
NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
((IStTxtPara)stText.ParagraphsOS[0]).Contents = TsStringUtils.MakeString(string.Empty, Cache.DefaultVernWs));
// since we have no text, we should not sit on any of the analyses tabs,
// the info tab is still useful though.
if (InterlinearTab != TabPageSelection.Info && InterlinearTab != TabPageSelection.RawText)
InterlinearTab = TabPageSelection.RawText;
// Don't steal the focus from another window. See FWR-1795.
if (ParentForm == Form.ActiveForm)
m_rtPane.Focus();
}
if (RootStText == null || RootStText.Hvo != hvoRoot)
{
// we've just now entered the area, so try to restore a bookmark.
CreateOrRestoreBookmark(stText);
}
}
if ((RootStText == null || RootStText.Hvo != hvoRoot) &&
Cache.ServiceLocator.IsValidObjectId(hvoRoot))
{
SwitchText(hvoRoot); // sets RootStText
}
else
{
SelectAnnotation(); // select an annotation in the current text.
}
// This takes a lot of time, and the view is never visible by now, and it gets done
// again when made visible! So don't do it!
//m_idcPane.SetRoot(hvoRoot);
// If we're showing the raw text pane make sure it has a selection.
if (Controls.IndexOf(m_rtPane) >= 0 && m_rtPane.RootBox.Selection == null)
m_rtPane.RootBox.MakeSimpleSel(true, false, false, true);
UpdateContextHistory();
m_fRefreshOccurred = false; // reset our flag that a refresh occurred.
}
private int SetConcordanceBookmarkAndReturnRoot(int hvoRoot)
{
if (!CurrentTool.Equals("interlinearTexts"))