Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Src/Common/FwUtils/EndOfActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal void AddEvent(PublisherParameterObject publisherParameterObject)
}

// Add the dictionary entry if the key is not present. Overwrite the value if the key is present.
m_events[publisherParameterObject.Message] = publisherParameterObject.NewValue;
m_events[publisherParameterObject.Message] = publisherParameterObject.Data;
}

/// Should be private, but is public to support testing.
Expand Down
1 change: 1 addition & 0 deletions Src/Common/FwUtils/EventConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class EventConstants
public const string CreateFirstRecord = "CreateFirstRecord";
public const string DataTreeDelete = "DataTreeDelete";
public const string DeleteRecord = "DeleteRecord";
public const string DialogInsertItemInVector = "DialogInsertItemInVector";
public const string DictionaryConfigured = "DictionaryConfigured";
public const string FilterListChanged = "FilterListChanged";
public const string FollowLink = "FollowLink";
Expand Down
4 changes: 2 additions & 2 deletions Src/Common/FwUtils/Publisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void Publish(PublisherParameterObject publisherParameterObject)
{
Guard.AgainstNull(publisherParameterObject, nameof(publisherParameterObject));

PublishMessage(publisherParameterObject.Message, publisherParameterObject.NewValue);
PublishMessage(publisherParameterObject.Message, publisherParameterObject.Data);
}

/// <inheritdoc />
Expand All @@ -89,7 +89,7 @@ public void Publish(IList<PublisherParameterObject> publisherParameterObjects)

foreach (var publisherParameterObject in publisherParameterObjects)
{
PublishMessage(publisherParameterObject.Message, publisherParameterObject.NewValue);
PublishMessage(publisherParameterObject.Message, publisherParameterObject.Data);
}
}
#endregion
Expand Down
21 changes: 18 additions & 3 deletions Src/Common/FwUtils/PublisherParameterObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,33 @@ namespace SIL.FieldWorks.Common.FwUtils
{
public sealed class PublisherParameterObject
{
public PublisherParameterObject(string message, object newValue = null)
public PublisherParameterObject(string message, object data = null)
{
if (string.IsNullOrWhiteSpace(message))
{
throw new ArgumentNullException(message, nameof(message));
}

Message = message;
NewValue = newValue;
Data = data;
}

public string Message { get; }
public object NewValue { get; }
public object Data { get; }
}

/// <summary>
/// Convenience class for use when we want to pass a return value back through the PublisherParameterObject.
/// </summary>
public class ReturnObject
{
public ReturnObject(object data)
{
Data = data;
ReturnValue = false;
}

public object Data { get; set; }
public bool ReturnValue { get; set; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would Handled be a better name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I agree, Handled is a better name, but my intent is for this to be generic so the next time it is used it also makes sense, which might be something other than Handled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure Handled is the only case, but ReturnValue is acceptable.

}
}
47 changes: 36 additions & 11 deletions Src/LexText/LexTextControls/EntryDlgListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System;
using System.Diagnostics;
using System.Windows.Forms;
using SIL.FieldWorks.Common.FwUtils;
using static SIL.FieldWorks.Common.FwUtils.FwUtils;
using SIL.LCModel;
using SIL.LCModel.Infrastructure;
using XCore;
Expand All @@ -32,28 +34,51 @@ protected override string PersistentLabel

public InsertEntryDlgListener()
{
Subscriber.Subscribe(EventConstants.DialogInsertItemInVector, DialogInsertItemInVector);
}

#endregion Construction and Initialization

#region IDisposable
protected override void Dispose(bool disposing)
{
if (disposing)
{
Subscriber.Unsubscribe(EventConstants.DialogInsertItemInVector, DialogInsertItemInVector);
}
base.Dispose(disposing);
}
#endregion IDisposable

#region XCORE Message Handlers

/// <summary>
/// Handles the xWorks message to insert a new lexical entry.
/// Handles the message to insert a new lexical entry.
/// Invoked by the RecordClerk
/// </summary>
/// <param name="argument">The xCore Command object.</param>
/// <returns>true, if we handled the message, otherwise false, if there was an unsupported 'classname' parameter</returns>
public bool OnDialogInsertItemInVector(object argument)
/// <param name="obj">Object that contains the xCore Command object and has a ReturnValue. The
/// ReturnValue is true if we handled the message.</param>
private void DialogInsertItemInVector(object obj)
{
CheckDisposed();

Debug.Assert(argument != null && argument is XCore.Command);
string className = XmlUtils.GetOptionalAttributeValue(
(argument as Command).Parameters[0],
"className");
if (className == null || className != "LexEntry")
return false;
if (!(obj is ReturnObject retObj) ||
!(retObj.Data is Command command))
{
Debug.Assert(false, "Received unexpected object type.");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could use Debug.Fail or even a yellow-box crash

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code had an Assert to check Command, I think leaving it as an Assert but also checking ReturnObject is sufficient. It doesn't seem like it needs to change.

return;
}
// Return if already handled by another Subscriber.
if (retObj.ReturnValue)
{
return;
}
// Only handle "LexEntry" class.
string className = XmlUtils.GetOptionalAttributeValue(command.Parameters[0], "className");
if (className != "LexEntry")
{
return;
}

using (InsertEntryDlg dlg = new InsertEntryDlg())
{
Expand All @@ -72,7 +97,7 @@ public bool OnDialogInsertItemInVector(object argument)
#pragma warning restore 618
}
}
return true; // We "handled" the message, regardless of what happened.
retObj.ReturnValue = true; // We "handled" the message, regardless of what happened.
}

#endregion XCORE Message Handlers
Expand Down
50 changes: 42 additions & 8 deletions Src/LexText/LexTextControls/RecordDlgListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using System.Diagnostics;
using System.Windows.Forms;
using SIL.FieldWorks.Common.FwUtils;
using static SIL.FieldWorks.Common.FwUtils.FwUtils;
using SIL.LCModel;
using SIL.Utils;
using XCore;
Expand All @@ -24,23 +26,55 @@ protected override string PersistentLabel

#endregion Properties

#region Construction and Initialization

public InsertRecordDlgListener()
{
Subscriber.Subscribe(EventConstants.DialogInsertItemInVector, DialogInsertItemInVector);
}

#endregion Construction and Initialization

#region IDisposable
protected override void Dispose(bool disposing)
{
if (disposing)
{
Subscriber.Unsubscribe(EventConstants.DialogInsertItemInVector, DialogInsertItemInVector);
}
base.Dispose(disposing);
}
#endregion IDisposable

#region XCORE Message Handlers

/// <summary>
/// Handles the xWorks message to insert a new Data Notebook record.
/// Handles the message to insert a new Data Notebook record.
/// Invoked by the RecordClerk
/// </summary>
/// <param name="argument">The xCore Command object.</param>
/// <returns>true, if we handled the message, otherwise false, if there was an unsupported 'classname' parameter</returns>
public bool OnDialogInsertItemInVector(object argument)
/// <param name="arg">Object that contains the xCore Command object and has a ReturnValue. The
/// ReturnValue is true if we handled the message.</param>
private void DialogInsertItemInVector(object arg)
{
CheckDisposed();

var command = (Command) argument;
if (!(arg is ReturnObject retObj) ||
!(retObj.Data is Command command))
{
Debug.Assert(false, "Received unexpected object type.");
return;
}
// Return if already handled by another Subscriber.
if (retObj.ReturnValue)
{
return;
}
// Only handle "RnGenericRec" class.
string className = XmlUtils.GetOptionalAttributeValue(command.Parameters[0], "className");
if (className == null || className != "RnGenericRec")
return false;
if (className != "RnGenericRec")
{
return;
}

bool subrecord = XmlUtils.GetOptionalBooleanAttributeValue(command.Parameters[0], "subrecord", false);
bool subsubrecord = XmlUtils.GetOptionalBooleanAttributeValue(command.Parameters[0], "subsubrecord", false);
Expand Down Expand Up @@ -74,7 +108,7 @@ public bool OnDialogInsertItemInVector(object argument)
#pragma warning restore 618
}
}
return true; // We "handled" the message, regardless of what happened.
retObj.ReturnValue = true; // We "handled" the message, regardless of what happened.
}

#endregion XCORE Message Handlers
Expand Down
44 changes: 34 additions & 10 deletions Src/LexText/Morphology/MasterCatDlgListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

using System.Diagnostics;
using System.Windows.Forms;
using SIL.FieldWorks.Common.FwUtils;
using static SIL.FieldWorks.Common.FwUtils.FwUtils;
using SIL.LCModel;
using SIL.FieldWorks.LexText.Controls;
using SIL.Utils;
using XCore;

namespace SIL.FieldWorks.XWorks.MorphologyEditor
{
Expand All @@ -32,6 +35,7 @@ protected override string PersistentLabel
/// </summary>
public MasterCatDlgListener()
{
Subscriber.Subscribe(EventConstants.DialogInsertItemInVector, DialogInsertItemInVector);
}

#endregion Construction and Initialization
Expand All @@ -52,26 +56,46 @@ public MasterCatDlgListener()
// The base class finalizer is called automatically.
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
Subscriber.Unsubscribe(EventConstants.DialogInsertItemInVector, DialogInsertItemInVector);
}
base.Dispose(disposing);
}

#endregion IDisposable & Co. implementation

#region XCORE Message Handlers

/// <summary>
/// Handles the xWorks message to insert a new PartOfSpeech.
/// Handles the message to insert a new PartOfSpeech.
/// Invoked by the RecordClerk via a main menu.
/// </summary>
/// <param name="argument">The xCore Command object.</param>
/// <returns>true, if we handled the message, otherwise false, if there was an unsupported 'classname' parameter</returns>
public override bool OnDialogInsertItemInVector(object argument)
/// <param name="obj">Object that contains the xCore Command object and has a ReturnValue. The
/// ReturnValue is true if we handled the message.</param>
private void DialogInsertItemInVector(object obj)
{
CheckDisposed();

Debug.Assert(argument != null && argument is XCore.Command);
string className = XmlUtils.GetOptionalAttributeValue(
(argument as XCore.Command).Parameters[0], "className");
if (className == null || className != "PartOfSpeech")
return false;
if (!(obj is ReturnObject retObj) ||
!(retObj.Data is Command command))
{
Debug.Assert(false, "Received unexpected object type.");
return;
}
// Return if already handled by another Subscriber.
if (retObj.ReturnValue)
{
return;
}
// Only handle "PartOfSpeech" class.
string className = XmlUtils.GetOptionalAttributeValue(command.Parameters[0], "className");
if (className != "PartOfSpeech")
{
return;
}

using (var dlg = new MasterCategoryListDlg())
{
Expand All @@ -91,7 +115,7 @@ public override bool OnDialogInsertItemInVector(object argument)
break;
}
}
return true; // We "handled" the message, regardless of what happened.
retObj.ReturnValue = true; // We "handled" the message, regardless of what happened.
}

#endregion XCORE Message Handlers
Expand Down
15 changes: 0 additions & 15 deletions Src/LexText/Morphology/MasterDlgListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,5 @@ public int Priority
}

#endregion IxCoreColleague implementation

#region XCORE Message Handlers

/// <summary>
/// Handles the xWorks message to insert a new class.
/// Invoked by the RecordClerk via a main menu.
/// </summary>
/// <param name="argument">The xCore Command object.</param>
/// <returns>true, if we handled the message, otherwise false, if there was an unsupported 'classname' parameter</returns>
public virtual bool OnDialogInsertItemInVector(object argument)
{
return false; // Needs to be handled by the override method
}

#endregion XCORE Message Handlers
}
}
Loading
Loading