Skip to content

Commit cbc9499

Browse files
authored
LT-21495: Move AddTexts to Pub/Sub
Cherry-pick from the PubSub branch to the main branch using the following commands: git cherry-pick --no-commit 11d9885 git cherry-pick --no-commit d431877 After the cherry-pick additional edits were made to: 1. resolve conflicts 2. Remove the Subscribe() and Unsubscribe() from StatisticsView.cs. In this view the command is only executed from the menu and toolbar. The GUI that would call Publish() is not displayed. 3. standardize on the use of: using static SIL.FieldWorks.Common.FwUtils.FwUtils;
1 parent fe415b8 commit cbc9499

4 files changed

Lines changed: 53 additions & 19 deletions

File tree

Src/LexText/Interlinear/InterlinearTextsRecordClerk.cs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ public List<int> GetScriptureIds()
3737
return (from st in GetInterestingTextList().ScriptureTexts select st.Hvo).ToList();
3838
}
3939

40+
public override bool IsControllingTheRecordTreeBar
41+
{
42+
set
43+
{
44+
CheckDisposed();
45+
46+
// Nothing to do if we were already the active clerk or if we are not controlling the recordtreebar,
47+
var oldActiveClerk = m_propertyTable.GetValue<RecordClerk>("ActiveClerk");
48+
if (oldActiveClerk == this || !value)
49+
return;
50+
51+
base.IsControllingTheRecordTreeBar = value;
52+
Subscriber.Subscribe(EventConstants.AddTexts, AddTexts);
53+
}
54+
}
55+
56+
protected override void RemoveNotification()
57+
{
58+
Subscriber.Unsubscribe(EventConstants.AddTexts, AddTexts);
59+
base.RemoveNotification();
60+
}
61+
4062
protected override string FilterStatusContents(bool listIsFiltered)
4163
{
4264
var baseStatus = base.FilterStatusContents(listIsFiltered);
@@ -141,10 +163,25 @@ public void ParseInterstingTextsIfNeeded()
141163
}
142164
}
143165

166+
/// <summary>
167+
/// Handler for the "Choose Texts..." menu item.
168+
/// Triggered from: DistFiles/Language Explorer/Configuration/Words/areaConfiguration.xml
169+
/// </summary>
144170
protected internal bool OnAddTexts(object args)
145171
{
146172
CheckDisposed();
147-
// get saved scripture choices
173+
AddTexts(args);
174+
175+
return true;
176+
}
177+
178+
/// <summary>
179+
/// Method to handle published messages for AddTexts.
180+
/// </summary>
181+
protected internal void AddTexts(object args)
182+
{
183+
CheckDisposed();
184+
// get saved texts choices
148185
var interestingTextsList = GetInterestingTextList();
149186
var interestingTexts = interestingTextsList.InterestingTexts.ToArray();
150187

@@ -154,10 +191,11 @@ protected internal bool OnAddTexts(object args)
154191
{
155192
interestingTextsList.SetInterestingTexts(dlg.GetListOfIncludedTexts());
156193
UpdateFilterStatusBarPanel();
194+
ReloadIfNeeded();
157195
}
158196
}
159197

160-
return true;
198+
return;
161199
}
162200

163201
private InterestingTextList GetInterestingTextList()

Src/LexText/Interlinear/StatisticsView.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configu
7979
m_clerk = (clerk == null || clerk is TemporaryRecordClerk) ?
8080
(InterlinearTextsRecordClerk)RecordClerkFactory.CreateClerk(mediator, _propertyTable, configurationParameters, true, true) :
8181
(InterlinearTextsRecordClerk)clerk;
82-
// There's no record bar for it to control, but it should control the staus bar (e.g., it should update if we change
82+
// There's no record bar for it to control, but it should control the status bar (e.g., it should update if we change
8383
// the set of selected texts).
8484
m_clerk.ActivateUI(true);
8585
_areaName = XmlUtils.GetOptionalAttributeValue(configurationParameters, "area", "unknown");
@@ -237,14 +237,16 @@ public bool OnDisplayAddTexts(object commandObject, ref UIItemDisplayProperties
237237
return true;
238238
}
239239

240+
/// <summary>
241+
/// Handler for the "Choose Texts..." menu item.
242+
/// Triggered from: DistFiles/Language Explorer/Configuration/Words/areaConfiguration.xml
243+
/// </summary>
240244
public bool OnAddTexts(object args)
241245
{
242-
bool result = m_clerk.OnAddTexts(args);
243-
if(result)
244-
{
245-
RebuildStatisticsTable();
246-
}
247-
return result;
246+
CheckDisposed();
247+
m_clerk.AddTexts(args);
248+
RebuildStatisticsTable();
249+
return true;
248250
}
249251

250252
#endregion
@@ -254,7 +256,6 @@ public bool OnAddTexts(object args)
254256
public bool PrepareToGoAway()
255257
{
256258
CheckDisposed();
257-
258259
return true;
259260
}
260261

Src/LexText/Interlinear/TextsFilterItem.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// (http://www.gnu.org/licenses/lgpl-2.1.html)
44

55
using SIL.FieldWorks.Common.Controls;
6+
using SIL.FieldWorks.Common.FwUtils;
7+
using static SIL.FieldWorks.Common.FwUtils.FwUtils;
68
using SIL.LCModel.Core.KernelInterfaces;
79
using SIL.LCModel;
810
using XCore;
@@ -25,14 +27,7 @@ public TextsFilterItem(ITsString tssName, LcmCache cache, Mediator mediator) : b
2527

2628
public override bool Invoke()
2729
{
28-
#pragma warning disable 618 // suppress obsolete warning
29-
m_mediator.SendMessage("AddTexts", this);
30-
#pragma warning restore 618
31-
32-
//var clerk = RecordClerk.FindClerk(m_mediator, "interlinearTexts") as InterlinearTextsRecordClerk;
33-
//if (clerk == null)
34-
// return false;
35-
//clerk.OnAddTexts(null);
30+
Publisher.Publish(new PublisherParameterObject(EventConstants.AddTexts, this));
3631

3732
return false; // Whatever the user did, we don't currently count it as changing the filter.
3833
}

Src/xWorks/RecordClerk.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ public static RecordClerk FindClerk(PropertyTable propertyTable, string id)
20142014
/// <summary>
20152015
/// Stop notifications of prop changes
20162016
/// </summary>
2017-
void RemoveNotification()
2017+
protected virtual void RemoveNotification()
20182018
{
20192019
Subscriber.Unsubscribe(EventConstants.FilterListChanged, FilterListChanged);
20202020

0 commit comments

Comments
 (0)