-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathDataTree.cs
More file actions
4747 lines (4379 loc) · 164 KB
/
DataTree.cs
File metadata and controls
4747 lines (4379 loc) · 164 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-2017 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)
using SIL.FieldWorks.Common.Controls;
using SIL.FieldWorks.Common.Framework.DetailControls.Resources;
using SIL.FieldWorks.Common.FwUtils;
using static SIL.FieldWorks.Common.FwUtils.FwUtils;
using SIL.FieldWorks.Common.RootSites;
using SIL.LCModel;
using SIL.LCModel.Core.Cellar;
using SIL.LCModel.Core.KernelInterfaces;
using SIL.LCModel.Core.WritingSystems;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Infrastructure;
using SIL.LCModel.Utils;
using SIL.PlatformUtilities;
using SIL.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using XCore;
namespace SIL.FieldWorks.Common.Framework.DetailControls
{
/// <summary>
/// A DataTree displays a tree diagram alongside a collection of controls. Each control is
/// represented as a Slice, and typically contains an actual .NET control of some
/// sort (most often, in FieldWorks, a subclass of SIL.FieldWorks.Common.Framework.RootSite).
/// The controls are arranged vertically, one under the other, and the tree diagram is
/// aligned with the controls.
///
/// The creator of a DataTree is responsible to add items to it, though DataTree
/// provide helpful methods for adding
/// certain commonly useful controls. Additional items may be added as a result of user
/// actions, typically expanding and contracting nodes.
///
/// Much of the standard behavior of the DataTree is achieved by delegating it to virtual
/// methods of Slice, which can be subclassed to specialize this behavior.
///
/// Review JohnT: do I have the right superclass? This choice allows the window to have
/// a scroll bar and to contain other controls, and seems to be the intended superclass
/// for stuff developed by application programmers.
/// </summary>
/// Possible superclasses for DataTree:
/// System.Windows.Forms.Panel
/// System.Windows.Forms.ContainerControl
/// System.Windows.Forms.UserControl
public class DataTree : UserControl, IVwNotifyChange, IxCoreColleague, IRefreshableRoot
{
/// <summary>
/// Part refs that don't represent actual data slices
/// </summary>
public static string[] SpecialPartRefs = { "ChangeHandler", "_CustomFieldPlaceholder" };
/// <summary>
/// Occurs when the current slice changes
/// </summary>
public event EventHandler CurrentSliceChanged;
#region Data members
/// <summary>
/// Use this to do the Add/RemoveNotifications, since it can be used in the unmanged section of Dispose.
/// (If m_sda is COM, that is.)
/// Doing it there will be safer, since there was a risk of it not being removed
/// in the mananged section, as when disposing was done by the Finalizer.
/// </summary>
private ISilDataAccess m_sda;
/// <summary></summary>
protected LcmCache m_cache;
/// <summary>use SetContextMenuHandler() to subscribe to this event (if you want to provide a Context menu for this DataTree)</summary>
protected event SliceShowMenuRequestHandler ShowContextMenuEvent;
/// <summary>the descendent object that is being displayed</summary>
protected ICmObject m_descendant;
/// <summary></summary>
protected IFwMetaDataCache m_mdc; // allows us to interpret class and field names and trace superclasses.
/// <summary></summary>
protected ICmObject m_root;
/// <summary></summary>
protected Slice m_currentSlice = null;
/// <summary>used to restore current slice during RefreshList()</summary>
private string m_currentSlicePartName = null;
/// <summary>used to restore current slice during RefreshList()</summary>
private Guid m_currentSliceObjGuid = Guid.Empty;
/// <summary>used to restore current slice during RefreshList()</summary>
private bool m_fSetCurrentSliceNew = false;
/// <summary>used to restore current slice during RefreshList()</summary>
private Slice m_currentSliceNew = null;
/// <summary>used to restore current slice during RefreshList()</summary>
private string m_sPartNameProperty = null;
/// <summary>used to restore current slice during RefreshList()</summary>
private string m_sObjGuidProperty = null;
/// <summary></summary>
protected ImageCollection m_smallImages = null;
/// <summary></summary>
protected string m_rootLayoutName = "default";
/// <summary></summary>
protected string m_layoutChoiceField;
/// <summary>This is the position a splitter would be if we had a single one, the actual
/// position of the splitter in a zero-indent slice. This is persisted, and can also be
/// controlled by the XML file; the value here is a last-resort default.
/// </summary>
protected int m_sliceSplitPositionBase = 150;
/// <summary>
/// This XML document object holds the nodes that we create on-the-fly to represent custom fields.
/// </summary>
protected XmlDocument m_autoCustomFieldNodesDocument;
/// <summary></summary>
protected XmlNode m_autoCustomFieldNodesDocRoot;
/// <summary></summary>
protected Inventory m_layoutInventory; // inventory of layouts for different object classes.
/// <summary></summary>
protected Inventory m_partInventory; // inventory of parts used in layouts.
/// <summary></summary>
protected internal bool m_fHasSplitter;
/// <summary></summary>
protected SliceFilter m_sliceFilter;
/// <summary>Set of KeyValuePair objects (hvo, flid), properties for which we must refresh if altered.</summary>
protected HashSet<Tuple<int, int>> m_monitoredProps = new HashSet<Tuple<int, int>>();
// Number of times DeepSuspendLayout has been called without matching DeepResumeLayout.
protected int m_cDeepSuspendLayoutCount;
protected IPersistenceProvider m_persistenceProvider = null;
protected LcmStyleSheet m_styleSheet;
protected bool m_fShowAllFields = false;
protected ToolTip m_tooltip; // used for slice tree nodes. All tooltips are cleared when we switch records!
protected LayoutStates m_layoutState = LayoutStates.klsNormal;
protected int m_dxpLastRightPaneWidth = -1; // width of right pane (if any) the last time we did a layout.
// to allow slices to handle events (e.g. InflAffixTemplateSlice)
protected Mediator m_mediator;
protected PropertyTable m_propertyTable;
protected IRecordChangeHandler m_rch = null;
protected IRecordListUpdater m_rlu = null;
protected string m_listName;
bool m_fDisposing = false;
bool m_fRefreshListNeeded = false;
/// <summary>
/// this helps DataTree delay from setting focus in a slice, until we're all setup to do so.
/// </summary>
bool m_fSuspendSettingCurrentSlice = false;
bool m_fCurrentContentControlObjectTriggered = false;
/// <summary>
/// These variables are used to prevent refreshes from occurring when they're not wanted,
/// but then to do a refresh when it's safe.
/// </summary>
bool m_fDoNotRefresh = false;
bool m_fPostponedClearAllSlices = false;
// Set during ConstructSlices, to suppress certain behaviors not safe at this point.
bool m_postponePropChanged = true;
internal bool ConstructingSlices { get; private set; }
public List<Slice> Slices { get; private set; }
#endregion Data members
#region constants
/// <summary></summary>
public const int HeavyweightRuleThickness = 2;
/// <summary></summary>
public const int HeavyweightRuleAboveMargin = 10;
#endregion constants
#region enums
public enum TreeItemState: byte
{
ktisCollapsed,
ktisExpanded,
ktisFixed, // not able to expand or contract
// Normally capable of expansion, this node has no current children, typically because it
// expands to show a sequence and the sequence is empty. We treat it like 'collapsed'
// in that, if an object is added to the sequence, we show it. But, it is drawn as an empty
// box, and clicking has no effect.
ktisCollapsedEmpty
}
/// <summary>
/// This is used in m_layoutStates to keep track of various special situations that
/// affect what is done during OnLayout and HandleLayout1.
/// </summary>
public enum LayoutStates : byte
{
klsNormal, // OnLayout executes normally, nothing special is happening
klsChecking, // OnPaint is checking that all slices that intersect the client area are ready to function.
klsLayoutSuspended, // Had to suspend layout during paint, need to resume at end and repaint.
klsClearingAll, // In the process of clearing all slices, ignore any intermediate layout messages.
klsDoingLayout, // We are executing HandleLayout1 (other than from OnPaint), or laying out a single slice in FieldAt().
}
#endregion enums
#region TraceSwitch methods
/// <summary>
/// Control how much output we send to the application's listeners (e.g. visual studio output window)
/// </summary>
protected TraceSwitch m_traceSwitch = new TraceSwitch("DataTree", "");
protected void TraceVerbose(string s)
{
if(m_traceSwitch.TraceVerbose)
Trace.Write(s);
}
protected void TraceVerboseLine(string s)
{
if(m_traceSwitch.TraceVerbose)
Trace.WriteLine("DataTreeThreadID="+System.Threading.Thread.CurrentThread.GetHashCode()+": "+s);
}
protected void TraceInfoLine(string s)
{
if(m_traceSwitch.TraceInfo || m_traceSwitch.TraceVerbose)
Trace.WriteLine("DataTreeThreadID="+System.Threading.Thread.CurrentThread.GetHashCode()+": "+s);
}
#endregion
#region Slice collection manipulation methods
private ToolTip ToolTip
{
get
{
CheckDisposed();
if (m_tooltip == null)
{
m_tooltip = new ToolTip {ShowAlways = true};
}
return m_tooltip;
}
}
private void InsertSlice(int index, Slice slice)
{
InstallSlice(slice, index);
ResetTabIndices(index);
if (m_fSetCurrentSliceNew && !slice.IsHeaderNode)
{
m_fSetCurrentSliceNew = false;
if (m_currentSliceNew == null || m_currentSliceNew.IsDisposed)
m_currentSliceNew = slice;
}
}
private void InstallSlice(Slice slice, int index)
{
Debug.Assert(index >= 0 && index <= Slices.Count);
slice.SuspendLayout();
slice.Install(this);
ForceSliceIndex(slice, index);
Debug.Assert(slice.IndexInContainer == index,
String.Format("InstallSlice: slice '{0}' at index({1}) should have been inserted in index({2}).",
(slice.ConfigurationNode != null && slice.ConfigurationNode.OuterXml != null ? slice.ConfigurationNode.OuterXml : "(DummySlice?)"),
slice.IndexInContainer, index));
// Note that it is absolutely vital to do this AFTER adding the slice to the data tree.
// Otherwise, the tooltip appears behind the form and is usually never seen.
SetToolTip(slice);
slice.ResumeLayout();
// Make sure it isn't added twice.
SplitContainer sc = slice.SplitCont;
AdjustSliceSplitPosition(slice);
}
/// <summary>
/// For some strange reason, the first Controls.SetChildIndex doesn't always put it in the specified index.
/// The second time seems to work okay though.
/// </summary>
private void ForceSliceIndex(Slice slice, int index)
{
if (index < Slices.Count && Slices[index] != slice)
{
Slices.Remove(slice);
Slices.Insert(index, slice);
}
}
private void SetToolTip(Slice slice)
{
if (slice.ToolTip != null)
ToolTip.SetToolTip(slice.TreeNode, slice.ToolTip);
}
void slice_SplitterMoved(object sender, SplitterEventArgs e)
{
if (m_currentSlice == null)
return; // Too early to do much;
var movedSlice = sender is Slice slice ? slice
// sender is also a SplitContainer.
: (Slice) ((SplitContainer) sender).Parent; // Review: This branch is probably obsolete.
if (m_currentSlice != movedSlice)
return; // Too early to do much;
Debug.Assert(movedSlice == m_currentSlice);
m_sliceSplitPositionBase = movedSlice.SplitCont.SplitterDistance - movedSlice.LabelIndent();
PersistPreferences();
SuspendLayout();
foreach (Slice otherSlice in Slices)
{
if (movedSlice != otherSlice)
{
AdjustSliceSplitPosition(otherSlice);
}
}
ResumeLayout(false);
// This can affect the lines between the slices. We need to redraw them but not the
// slices themselves.
Invalidate(false);
movedSlice.TakeFocus();
}
private void AdjustSliceSplitPosition(Slice otherSlice)
{
SplitContainer otherSliceSC = otherSlice.SplitCont;
// Remove and readd event handler when setting the value for the other fellow.
otherSliceSC.SplitterMoved -= slice_SplitterMoved;
otherSlice.SetSplitPosition();
otherSliceSC.SplitterMoved += slice_SplitterMoved;
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
foreach (Slice slice in Slices)
{
AdjustSliceSplitPosition(slice);
}
}
protected void InsertSliceRange(int insertPosition, ISet<Slice> slices)
{
var indexableSlices = new List<Slice>(slices.ToArray());
for (int i = indexableSlices.Count - 1; i >= 0; --i)
{
InstallSlice(indexableSlices[i], insertPosition);
}
ResetTabIndices(insertPosition);
}
/// <summary>
/// Use with care...if it's a real slice, or a real one being replaced, there are
/// other things to do like adding to or removing from container. This is mainly for messing
/// with dummy slices.
/// </summary>
internal void RawSetSlice(int index, Slice slice)
{
CheckDisposed();
Debug.Assert(slice != Slices[index], "Can't replace the slice with itself.");
RemoveSliceAt(index);
InstallSlice(slice, index);
SetTabIndex(index);
}
internal void RemoveSliceAt(int index)
{
RemoveSlice(Slices[index], index);
}
/// <summary>
/// Removes a slice but does NOT clean up tooltips; caller should do that.
/// </summary>
private void RemoveSlice(Slice gonner)
{
RemoveSlice(gonner, Slices.IndexOf(gonner), false);
}
private void RemoveSlice(Slice gonner, int index)
{
RemoveSlice(gonner, index, true);
}
/// <summary>
/// this should ONLY be called from slice.Dispose(). It makes sure that when a slice
/// is removed by disposing it directly it gets removed from the Slices collection.
/// </summary>
/// <param name="gonner"></param>
internal void RemoveDisposedSlice(Slice gonner)
{
Slices.Remove(gonner);
}
private void RemoveSlice(Slice gonner, int index, bool fixToolTips)
{
gonner.AboutToDiscard();
gonner.SplitCont.SplitterMoved -= slice_SplitterMoved;
Controls.Remove(gonner);
Debug.Assert(Slices[index] == gonner);
Slices.RemoveAt(index);
// Reset CurrentSlice, if appropriate.
if (gonner == m_currentSlice)
{
Slice newCurrent = null;
if (Slices.Count > index)
{
// Get the one at the same index (next one after the one being removed).
newCurrent = Slices[index] as Slice;
}
else if (Slices.Count > 0 && Slices.Count > index - 1)
{
// Get the one before index.
newCurrent = Slices[index - 1] as Slice;
}
if (newCurrent != null)
{
CurrentSlice = newCurrent;
}
else
{
m_currentSlice = null;
gonner.SetCurrentState(false);
}
}
// Since "gonner's" SliceTreeNode still is referenced by m_tooltip,
// (if it has one at all, that is),
// we have to also remove with ToolTip for gonner,
// Since the dumb MS ToolTip class can't just remove one,
// we have to remove them all and re-add the remaining ones
// in order to have it really turn loose of the SliceTreeNode.
// But, only do all of that, if it actually has a ToolTip.
bool gonnerHasToolTip = fixToolTips && (gonner.ToolTip != null);
if (gonnerHasToolTip)
m_tooltip.RemoveAll();
gonner.Dispose();
// Now, we need to re-add all of the surviving tooltips.
if (gonnerHasToolTip)
{
foreach (Slice keeper in Slices)
SetToolTip(keeper);
}
ResetTabIndices(index);
}
private void SetTabIndex(int index)
{
var slice = Slices[index];
if (slice.IsRealSlice)
{
slice.TabIndex = index;
slice.TabStop = !(slice.Control == null) && slice.Control.TabStop;
}
}
/// <summary>
/// Resets the TabIndex for all slices that are located at, or above, the <c>startingIndex</c>.
/// </summary>
/// <param name="startingIndex">The index to start renumbering the TabIndex.</param>
private void ResetTabIndices(int startingIndex)
{
for (int i = startingIndex; i < Slices.Count; ++i)
SetTabIndex(i);
}
#endregion Slice collection manipulation methods
public DataTree()
{
// string objName = ToString() + GetHashCode().ToString();
// Debug.WriteLine("Creating object:" + objName);
Slices = new List<Slice>();
m_autoCustomFieldNodesDocument = new XmlDocument();
m_autoCustomFieldNodesDocRoot = m_autoCustomFieldNodesDocument.CreateElement("root");
m_autoCustomFieldNodesDocument.AppendChild(m_autoCustomFieldNodesDocRoot);
}
/// <summary>
/// Get the root layout name.
/// </summary>
public string RootLayoutName
{
// NB: The DataTree has not been written to handle swapping layouts,
// so no 'Setter' is provided.
get
{
CheckDisposed();
return m_rootLayoutName;
}
}
/// <summary>
/// Get/Set a stylesheet suitable for use in views.
/// Ideally, there should be just one for the whole application, so if the app has
/// more than one datatree, do something to ensure this.
/// Also, something external should set it if the default stylesheet (the styles
/// stored in LangProject.Styles) is not to be used.
/// Otherwise, the datatree will automatically load it when first requested
/// (provided it has a cache by that time).
/// </summary>
public LcmStyleSheet StyleSheet
{
get
{
CheckDisposed();
if (m_styleSheet == null && m_cache != null)
{
m_styleSheet = new LcmStyleSheet();
m_styleSheet.Init(m_cache, m_cache.LanguageProject.Hvo,
LangProjectTags.kflidStyles);
}
return m_styleSheet;
}
set
{
CheckDisposed();
m_styleSheet = value;
}
}
private void PostponePropChanged(object commandObject)
{
if ((bool)commandObject == true)
m_postponePropChanged = true;
else
m_postponePropChanged = false;
}
public void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel)
{
CheckDisposed();
#if false
// This will be for real time updates, which is kind of expensive these days.
if (tag == (int)FDO.Ling.LexEntry.LexEntryTags.kflidCitationForm
|| tag == (int)FDO.Ling.MoForm.MoFormTags.kflidForm)
{
if (m_rch != null)
{
// We need to refresh the record list if homograph numbers change.
m_rch.Fixup(true);
}
}
#endif
// No, since it can only be null, if 'this' has been disposed.
// That probably means the corresponding RemoveNotication was not done.
// The current Dispose method has done this Remove call for quite a while now,
// so if we still get here with it being null, something else is really broken.
// We'll go with throwing a disposed exception for now, to see whomight still be
// mis-behaving.
//if (m_monitoredProps == null)
// return;
if (m_monitoredProps.Contains(Tuple.Create(hvo, tag)))
{
// If we call RefreshList now, it causes a crash in the invoker
// because some slice data structures that are being used by the invoker
// get disposed by RefreshList (LT-21980, LT-22011). So we postpone calling
// RefreshList until the work is done.
if (m_postponePropChanged)
{
this.BeginInvoke(new Action(RefreshListAndFocus));
} else
{
RefreshListAndFocus();
}
}
// Note, in LinguaLinks import we don't have an action handler when we hit this.
else if (m_cache.DomainDataByFlid.GetActionHandler() != null && m_cache.DomainDataByFlid.GetActionHandler().IsUndoOrRedoInProgress)
{
// Redoing an Add or Undoing a Delete may not have an existing slice to work with, so just force
// a list refresh. See LT-6033.
if (m_root != null && hvo == m_root.Hvo)
{
CellarPropertyType type = (CellarPropertyType)m_mdc.GetFieldType(tag);
if (type == CellarPropertyType.OwningCollection ||
type == CellarPropertyType.OwningSequence ||
type == CellarPropertyType.ReferenceCollection ||
type == CellarPropertyType.ReferenceSequence)
{
RefreshList(true);
// Try to make sure some slice ends up current.
OnFocusFirstPossibleSlice(null);
return;
}
}
// some FieldSlices (e.g. combo slices)may want to Update their display
// if its field changes during an Undo/Redo (cf. LT-4861).
RefreshList(hvo, tag);
}
}
private void RefreshListAndFocus()
{
if (!IsDisposed)
{
RefreshList(false);
OnFocusFirstPossibleSlice(null);
}
}
/// <summary></summary>
public Mediator Mediator
{
get
{
CheckDisposed();
return m_mediator;
}
}
/// <summary />
public PropertyTable PropTable
{
get
{
CheckDisposed();
return m_propertyTable;
}
}
/// <summary>
/// Tells whether we are showing all fields, or just the ones requested.
/// </summary>
public bool ShowingAllFields
{
get
{
CheckDisposed();
return m_fShowAllFields;
}
}
/// <summary>
/// Return the slice which should receive commands.
/// NB: This may be null.
/// </summary>
/// <remarks>
/// Originally, I had called this FocusSlice, but that was misleading because
/// some slices do not have any control, or have one but it cannot be focused upon.
/// currently, you get to be the current slice if
/// 1) your control receives focus
/// 2) the user clicks on your tree control
/// </remarks>
/// <exception cref="ArgumentException">Thrown if trying to set the current slice to null.</exception>
[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Slice CurrentSlice
{
get
{
// Trap this before the throw to give the debugger a chance to analyze.
Debug.Assert(m_currentSlice == null || !m_currentSlice.IsDisposed, "CurrentSlice is already disposed??");
CheckDisposed();
return m_currentSlice;
}
set
{
CheckDisposed();
if (value == null)
throw new ArgumentException("CurrentSlice on DataTree cannot be set to null. Set the underlying data member to null, if you really want it to be null.");
Debug.Assert(!value.IsDisposed, "Setting CurrentSlice to a disposed slice -- not a good idea!");
// don't set the current slice until we're all setup to do so (LT-7307)
if (m_currentSlice == value || m_fSuspendSettingCurrentSlice)
{
// LT-17633 But if we are trying to set a different slice from the one planned,
// we need to remember that. This can happen, for instance, when we insert several
// slices to replace a ghost field, but we want the current slice to be other than
// the first one.
m_currentSliceNew = value;
return;
}
// Tell the old geezer it isn't current anymore.
if (m_currentSlice != null)
{
m_currentSlice.Validate();
if (m_currentSlice.Control is ContainerControl)
((ContainerControl)m_currentSlice.Control).Validate();
m_currentSlice.SetCurrentState(false);
}
m_currentSlice = value;
// Tell new guy it is current.
m_currentSlice.SetCurrentState(true);
int index = m_currentSlice.IndexInContainer;
ScrollControlIntoView(m_currentSlice);
// Ensure that we can tab and shift-tab. This requires that at least one
// following and one prior slice be a tab stop, if possible.
for (int i = index + 1; i < Slices.Count; i++)
{
MakeSliceRealAt(i);
if (Slices[i].TabStop)
break;
}
for (int i = index - 1; i >= 0; i--)
{
MakeSliceRealAt(i);
if (Slices[i].TabStop)
break;
}
Invalidate(); // .Refresh();
// update the current descendant
m_descendant = DescendantForSlice(m_currentSlice);
if (CurrentSliceChanged != null)
CurrentSliceChanged(this, new EventArgs());
}
}
/// <summary>
/// Get the object that is considered the descendant for the given slice, that is,
/// the object of a header node which is one of the slice's parents (or the slice itself),
/// if possible, otherwise, the root object. May return null if the nearest Parent is disposed.
/// </summary>
/// <returns></returns>
private ICmObject DescendantForSlice(Slice slice)
{
var loopSlice = slice;
while (loopSlice != null && !loopSlice.IsDisposed)
{
// if there is not parent slice, we must be on a root slice
if (loopSlice.ParentSlice == null)
return m_root;
// if we are on a header slice, the slice's object is the descendant
if (loopSlice.IsHeaderNode)
return loopSlice.Object.IsValidObject ? loopSlice.Object : null;
loopSlice = loopSlice.ParentSlice;
}
// The following (along with the Disposed check above) prevents
// LT-11455 Crash if we delete the last compound rule.
// And LT-11463 Crash if Lexeme Form is filtered to Blanks.
return m_root.IsValidObject ? m_root : null;
}
/// <summary>
/// Determines whether the containing tree has a SubPossibilities slice.
/// </summary>
public bool HasSubPossibilitiesSlice
{
get
{
CheckDisposed();
// Start at the end of the list, since we usually put SubPossibilities there.
int i = Slices.Count - 1;
for (; i >= 0; --i)
{
var current = (Slice) Slices[i];
// Not sure these two cases are general enough to find a SubPossibilities slice.
// Ideally we want to find the <seq field='SubPossibilities'> node, but in the case of
// a header node, it's not that easy, and I (EricP) am not sure how to actually get from the
// <part ref='SubPossibilities'> down to the seq in that case. Works for now!
if (current.IsSequenceNode)
{
// see if slices is a SubPossibilities
XmlNode node = current.ConfigurationNode.SelectSingleNode("seq");
string field = XmlUtils.GetOptionalAttributeValue(node, "field");
if (field == "SubPossibilities")
break;
}
else if (current.IsHeaderNode)
{
XmlNode node = current.CallerNode.SelectSingleNode("*/part[starts-with(@ref,'SubPossibilities')]");
if (node != null)
break;
}
}
// if we found a SubPossibilities slice, the index will be in range.
return i >= 0 && i < Slices.Count;
}
}
public ICmObject Root
{
get
{
CheckDisposed();
return m_root;
}
}
public ICmObject Descendant
{
get
{
CheckDisposed();
return m_descendant;
}
}
public void Reset()
{
CheckDisposed();
var savedLayoutState = m_layoutState;
m_layoutState = LayoutStates.klsClearingAll;
try
{
// Get rid of all the slices...makes sure none of them can keep focus (e.g., see LT-11348)
var slices = Slices.ToArray();
foreach (var slice in slices) //inform all the slices they are about to be discarded, remove the trees handler from them
{
slice.AboutToDiscard();
slice.SplitCont.SplitterMoved -= slice_SplitterMoved;
}
Controls.Clear(); //clear the controls
Slices.Clear(); //empty the slices collection
foreach (var slice in slices) //make sure the slices don't think they are active, dispose them
{
slice.SetCurrentState(false);
slice.Dispose();
}
m_currentSlice = null; //no more current slice
// A tooltip doesn't always exist: see LT-11441, LT-11442, and LT-11444.
if (m_tooltip != null)
m_tooltip.RemoveAll();
m_root = null;
}
finally
{
m_layoutState = savedLayoutState;
}
}
private void ResetRecordListUpdater()
{
if (m_listName != null && m_rlu == null)
{
// Find the first parent IRecordListOwner object (if any) that
// owns an IRecordListUpdater.
var rlo = m_propertyTable.GetValue<IRecordListOwner>("window");
if (rlo != null)
m_rlu = rlo.FindRecordListUpdater(m_listName);
}
}
/// <summary>
/// Set the base split position of the DataTree and all slices.
/// </summary>
/// <remarks>
/// Note: This value is a base value and should never include the LabelIndent offset.
/// Each Slice will add its own Label length, when its SplitterDistance is set.
/// </remarks>
public int SliceSplitPositionBase
{
get
{
CheckDisposed();
return m_sliceSplitPositionBase;
}
set
{
CheckDisposed();
if (value == m_sliceSplitPositionBase)
return;
m_sliceSplitPositionBase = value;
PersistPreferences();
SuspendLayout();
foreach (Slice slice in Slices)
{
SplitContainer sc = slice.SplitCont;
sc.SplitterMoved -= slice_SplitterMoved;
slice.SetSplitPosition();
sc.SplitterMoved += slice_SplitterMoved;
}
ResumeLayout(false);
// This can affect the lines between the slices. We need to redraw them but not the
// slices themselves.
Invalidate(false);
}
}
public ImageCollection SmallImages
{
get
{
CheckDisposed();
return m_smallImages;
}
set
{
CheckDisposed();
m_smallImages = value;
}
}
/// <summary>
/// a look up table for getting the correct version of strings that the user will see.
/// </summary>
public SliceFilter SliceFilter
{
get
{
CheckDisposed();
return m_sliceFilter;
}
set
{
CheckDisposed();
m_sliceFilter = value;
}
}
public IPersistenceProvider PersistenceProvder
{
set
{
CheckDisposed();
m_persistenceProvider= value;
}
get
{
CheckDisposed();
return m_persistenceProvider;
}
}
private void MonoIgnoreUpdates()
{
#if USEIGNOREUPDATES
// static method call to get reasonable performance from mono
// IgnoreUpdates is custom functionality added to mono's winforms
// (commit 3233f63ece7e922d03a115ce8d8524e8554be19d)
// Stops all winforms Size events
Control.IgnoreUpdates();
#endif
}
private void MonoResumeUpdates()
{
#if USEIGNOREUPDATES
// static method call to get reasonable performance from mono
// Resumes all winforms Size events
Control.UnignoreUpdates();
#endif
}
/// <summary>
/// Shows the specified object and makes the slices for the descendant object visible.
/// </summary>
/// <param name="root">The root.</param>
/// <param name="layoutName">Name of the layout.</param>
/// <param name="layoutChoiceField">The layout choice field.</param>
/// <param name="descendant">The descendant.</param>
/// <param name="suppressFocusChange">if set to <c>true</c> focus changes will be suppressed.</param>
public virtual void ShowObject(ICmObject root, string layoutName, string layoutChoiceField, ICmObject descendant, bool suppressFocusChange)
{
CheckDisposed();
if (m_root == root && layoutName == m_rootLayoutName && layoutChoiceField == m_layoutChoiceField && m_descendant == descendant)
return;
string toolName = m_propertyTable.GetStringProperty("currentContentControl", null);
if (root is ILexEntry)
{
// We are in the Lexicon Edit Popup window
toolName = "lexiconEdit";
}
// Initialize our internal state with the state of the PropertyTable
m_fShowAllFields = m_propertyTable.GetBoolProperty("ShowHiddenFields-" + toolName, false, PropertyTable.SettingsGroup.LocalSettings);
m_propertyTable.SetPropertyPersistence("ShowHiddenFields-" + toolName, true, PropertyTable.SettingsGroup.LocalSettings);
m_propertyTable.SetDefault("ShowHiddenFields", m_fShowAllFields, PropertyTable.SettingsGroup.LocalSettings, false);
SetCurrentSlicePropertyNames();
m_currentSlicePartName = m_propertyTable.GetStringProperty(m_sPartNameProperty, null, PropertyTable.SettingsGroup.LocalSettings);
m_currentSliceObjGuid = m_propertyTable.GetValue(m_sObjGuidProperty, PropertyTable.SettingsGroup.LocalSettings, Guid.Empty);
m_propertyTable.SetProperty(m_sPartNameProperty, null, PropertyTable.SettingsGroup.LocalSettings, false);
m_propertyTable.SetProperty(m_sObjGuidProperty, Guid.Empty, PropertyTable.SettingsGroup.LocalSettings, false);
m_propertyTable.SetPropertyPersistence(m_sPartNameProperty, true, PropertyTable.SettingsGroup.LocalSettings);
m_propertyTable.SetPropertyPersistence(m_sObjGuidProperty, true, PropertyTable.SettingsGroup.LocalSettings);
m_currentSliceNew = null;
m_fSetCurrentSliceNew = false;
MonoIgnoreUpdates();
DeepSuspendLayout();
try
{
m_rootLayoutName = layoutName;
m_layoutChoiceField = layoutChoiceField;
Debug.Assert(m_cache != null, "You need to call Initialize() first.");
if (m_root != root)
{