Skip to content
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

Check null reference before invoking event handlers #12

Merged
merged 1 commit into from
Apr 13, 2021
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
8 changes: 4 additions & 4 deletions src/Calculator/Common/AlwaysSelectedCollectionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public bool MoveCurrentTo(object item)
if (newCurrentPosition != -1)
{
m_currentPosition = newCurrentPosition;
CurrentChanged(this, null);
CurrentChanged?.Invoke(this, null);
return true;
}
}
Expand All @@ -46,7 +46,7 @@ public bool MoveCurrentTo(object item)
{
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() =>
{
CurrentChanged(this, null);
CurrentChanged?.Invoke(this, null);
})).AsTask().Wait();
}
return false;
Expand All @@ -60,7 +60,7 @@ public bool MoveCurrentToPosition(int index)
}

m_currentPosition = index;
CurrentChanged(this, null);
CurrentChanged?.Invoke(this, null);
return true;
}

Expand Down Expand Up @@ -219,7 +219,7 @@ IEnumerator IEnumerable.GetEnumerator()
void OnSourceBindableVectorChanged(Windows.UI.Xaml.Interop.IBindableObservableVector source, object e)
{
Windows.Foundation.Collections.IVectorChangedEventArgs args = (Windows.Foundation.Collections.IVectorChangedEventArgs)e;
VectorChanged(this, args);
VectorChanged?.Invoke(this, args);
}

public event EventHandler<object> CurrentChanged;
Expand Down
12 changes: 6 additions & 6 deletions src/Calculator/Controls/EquationTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private void OnDeleteButtonClicked(object sender, RoutedEventArgs e)

private void OnEquationButtonClicked(object sender, RoutedEventArgs e)
{
EquationButtonClicked(this, new RoutedEventArgs());
EquationButtonClicked?.Invoke(this, new RoutedEventArgs());

SetEquationButtonTooltipAndAutomationName();
}
Expand All @@ -424,7 +424,7 @@ private void OnRemoveButtonClicked(object sender, RoutedEventArgs e)
m_richEditBox.MathText = "";
}

RemoveButtonClicked(this, new RoutedEventArgs());
RemoveButtonClicked?.Invoke(this, new RoutedEventArgs());

if (m_functionButton != null)
{
Expand Down Expand Up @@ -452,7 +452,7 @@ private void OnColorChooserButtonClicked(object sender, RoutedEventArgs e)

private void OnFunctionButtonClicked(object sender, RoutedEventArgs e)
{
KeyGraphFeaturesButtonClicked(this, new RoutedEventArgs());
KeyGraphFeaturesButtonClicked?.Invoke(this, new RoutedEventArgs());
}

private void OnFunctionMenuButtonClicked(object sender, RoutedEventArgs e)
Expand All @@ -463,7 +463,7 @@ private void OnFunctionMenuButtonClicked(object sender, RoutedEventArgs e)
m_richEditBox.SubmitEquation(EquationSubmissionSource.FOCUS_LOST);
}

KeyGraphFeaturesButtonClicked(this, new RoutedEventArgs());
KeyGraphFeaturesButtonClicked?.Invoke(this, new RoutedEventArgs());
}

private void OnRichEditMenuOpened(object sender, object args)
Expand Down Expand Up @@ -614,12 +614,12 @@ private void OnEquationSubmitted(object sender, MathRichEditBoxSubmission args)
}
}

EquationSubmitted(this, args);
EquationSubmitted?.Invoke(this, args);
}

private void OnEquationFormatRequested(object sender, MathRichEditBoxFormatRequest args)
{
EquationFormatRequested(this, args);
EquationFormatRequested?.Invoke(this, args);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Calculator/Controls/MathRichEditBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,19 @@ public void SubmitEquation(EquationSubmissionSource source)
{
// Request the final formatting of the text
var formatRequest = new MathRichEditBoxFormatRequest(newVal);
FormatRequest(this, formatRequest);
FormatRequest?.Invoke(this, formatRequest);

if (!string.IsNullOrEmpty(formatRequest.FormattedText))
{
newVal = formatRequest.FormattedText;
}

SetValue(MathTextProperty, newVal);
EquationSubmitted(this, new MathRichEditBoxSubmission(true, source));
EquationSubmitted?.Invoke(this, new MathRichEditBoxSubmission(true, source));
}
else
{
EquationSubmitted(this, new MathRichEditBoxSubmission(false, source));
EquationSubmitted?.Invoke(this, new MathRichEditBoxSubmission(false, source));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Calculator/Utils/DispatcherTimerDelayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Stop()
private void Timer_Tick(object sender, object e)
{
m_timer.Stop();
Action(this, null);
Action?.Invoke(this, null);
}

private DispatcherTimer m_timer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ private void EquationTextBox_RemoveButtonClicked(object sender, RoutedEventArgs

private void EquationTextBox_KeyGraphFeaturesButtonClicked(object sender, RoutedEventArgs e)
{
KeyGraphFeaturesRequested(this, GetViewModelFromEquationTextBox(sender));
KeyGraphFeaturesRequested?.Invoke(this, GetViewModelFromEquationTextBox(sender));
}

private void EquationTextBox_EquationButtonClicked(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -565,7 +565,7 @@ private void VariableAreaTapped(object sender, TappedRoutedEventArgs e)

private void EquationTextBox_EquationFormatRequested(object sender, MathRichEditBoxFormatRequest e)
{
EquationFormatRequested(sender, e);
EquationFormatRequested?.Invoke(sender, e);
}

private void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion src/Calculator/Views/TitleBar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private void OnIsAlwaysOnTopModePropertyChanged(bool oldValue, bool newValue)

private void AlwaysOnTopButton_Click(object sender, RoutedEventArgs e)
{
AlwaysOnTopClick(this, e);
AlwaysOnTopClick?.Invoke(this, e);
}

private Windows.ApplicationModel.Core.CoreApplicationViewTitleBar m_coreTitleBar;
Expand Down