-
-
Notifications
You must be signed in to change notification settings - Fork 42
LT-21517: Implement DialogInsertItemInVector in Pub/Sub system #836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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."); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: could use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) | ||
| { | ||
|
|
@@ -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 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would
Handledbe a better name?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure
Handledis the only case, butReturnValueis acceptable.