mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-20 21:33:10 -07:00
Use lambdas instead of making new Handler objects (#1915)
This commit is contained in:
parent
0de7449460
commit
edf08514a6
11 changed files with 52 additions and 70 deletions
|
@ -44,10 +44,10 @@ namespace CalculatorApp
|
|||
// restore the selection to the way we wanted it to begin with
|
||||
if (CurrentPosition >= 0 && CurrentPosition < m_source.Count)
|
||||
{
|
||||
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() =>
|
||||
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
CurrentChanged?.Invoke(this, null);
|
||||
})).AsTask().Wait();
|
||||
}).AsTask().Wait();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -33,11 +33,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for MinFontSize. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty MinFontSizeProperty =
|
||||
DependencyProperty.Register(nameof(MinFontSize), typeof(double), typeof(CalculationResult), new PropertyMetadata(0.0, new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(MinFontSize), typeof(double), typeof(CalculationResult), new PropertyMetadata(0.0, (sender, args) =>
|
||||
{
|
||||
var self = (CalculationResult)sender;
|
||||
self.OnMinFontSizePropertyChanged((double)args.OldValue, (double)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public double MaxFontSize
|
||||
{
|
||||
|
@ -47,11 +47,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for MaxFontSize. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty MaxFontSizeProperty =
|
||||
DependencyProperty.Register(nameof(MaxFontSize), typeof(double), typeof(CalculationResult), new PropertyMetadata(30.0, new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(MaxFontSize), typeof(double), typeof(CalculationResult), new PropertyMetadata(30.0, (sender, args) =>
|
||||
{
|
||||
var self = (CalculationResult)sender;
|
||||
self.OnMaxFontSizePropertyChanged((double)args.OldValue, (double)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public Thickness DisplayMargin
|
||||
{
|
||||
|
@ -71,11 +71,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for IsActive. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty IsActiveProperty =
|
||||
DependencyProperty.Register(nameof(IsActive), typeof(bool), typeof(CalculationResult), new PropertyMetadata(default(bool), new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(IsActive), typeof(bool), typeof(CalculationResult), new PropertyMetadata(default(bool), (sender, args) =>
|
||||
{
|
||||
var self = (CalculationResult)sender;
|
||||
self.OnIsActivePropertyChanged((bool)args.OldValue, (bool)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public string DisplayValue
|
||||
{
|
||||
|
@ -85,11 +85,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for DisplayValue. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty DisplayValueProperty =
|
||||
DependencyProperty.Register(nameof(DisplayValue), typeof(string), typeof(CalculationResult), new PropertyMetadata(string.Empty, new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(DisplayValue), typeof(string), typeof(CalculationResult), new PropertyMetadata(string.Empty, (sender, args) =>
|
||||
{
|
||||
var self = (CalculationResult)sender;
|
||||
self.OnDisplayValuePropertyChanged((string)args.OldValue, (string)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public bool IsInError
|
||||
{
|
||||
|
@ -99,11 +99,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for IsInError. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty IsInErrorProperty =
|
||||
DependencyProperty.Register(nameof(IsInError), typeof(bool), typeof(CalculationResult), new PropertyMetadata(default(bool), new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(IsInError), typeof(bool), typeof(CalculationResult), new PropertyMetadata(default(bool), (sender, args) =>
|
||||
{
|
||||
var self = (CalculationResult)sender;
|
||||
self.OnIsInErrorPropertyChanged((bool)args.OldValue, (bool)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public bool IsOperatorCommand
|
||||
{
|
||||
|
@ -151,7 +151,7 @@ namespace CalculatorApp
|
|||
|
||||
if (widthDiff > WIDTHCUTOFF)
|
||||
{
|
||||
fontSizeChange = Math.Min((double)Math.Max((double)Math.Floor(WIDTHTOFONTSCALAR * widthDiff) - WIDTHTOFONTOFFSET, INCREMENTOFFSET), MAXFONTINCREMENT);
|
||||
fontSizeChange = Math.Min(Math.Max(Math.Floor(WIDTHTOFONTSCALAR * widthDiff) - WIDTHTOFONTOFFSET, INCREMENTOFFSET), MAXFONTINCREMENT);
|
||||
}
|
||||
if (m_textBlock.ActualWidth < containerSize && Math.Abs(m_textBlock.FontSize - MaxFontSize) > FONTTOLERANCE && !m_haveCalculatedMax)
|
||||
{
|
||||
|
|
|
@ -33,11 +33,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for ButtonId. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty ButtonIdProperty =
|
||||
DependencyProperty.Register(nameof(ButtonId), typeof(NumbersAndOperatorsEnum), typeof(CalculatorButton), new PropertyMetadata(default(NumbersAndOperatorsEnum), new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(ButtonId), typeof(NumbersAndOperatorsEnum), typeof(CalculatorButton), new PropertyMetadata(default(NumbersAndOperatorsEnum), (sender, args) =>
|
||||
{
|
||||
var self = (CalculatorButton)sender;
|
||||
self.OnButtonIdPropertyChanged((NumbersAndOperatorsEnum)args.OldValue, (NumbersAndOperatorsEnum)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public string AuditoryFeedback
|
||||
{
|
||||
|
@ -47,11 +47,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for AuditoryFeedback. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty AuditoryFeedbackProperty =
|
||||
DependencyProperty.Register(nameof(AuditoryFeedback), typeof(string), typeof(CalculatorButton), new PropertyMetadata(string.Empty, new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(AuditoryFeedback), typeof(string), typeof(CalculatorButton), new PropertyMetadata(string.Empty, (sender, args) =>
|
||||
{
|
||||
var self = (CalculatorButton)sender;
|
||||
self.OnAuditoryFeedbackPropertyChanged((string)args.OldValue, (string)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public Windows.UI.Xaml.Media.Brush HoverBackground
|
||||
{
|
||||
|
|
|
@ -37,11 +37,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for TokensUpdated. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty TokensUpdatedProperty =
|
||||
DependencyProperty.Register(nameof(TokensUpdated), typeof(bool), typeof(OverflowTextBlock), new PropertyMetadata(default(bool), new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(TokensUpdated), typeof(bool), typeof(OverflowTextBlock), new PropertyMetadata(default(bool), (sender, args) =>
|
||||
{
|
||||
var self = (OverflowTextBlock)sender;
|
||||
self.OnTokensUpdatedPropertyChanged((bool)args.OldValue, (bool)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public OverflowButtonPlacement ScrollButtonsPlacement
|
||||
{
|
||||
|
@ -51,11 +51,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for ScrollButtonsPlacement. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty ScrollButtonsPlacementProperty =
|
||||
DependencyProperty.Register(nameof(ScrollButtonsPlacement), typeof(OverflowButtonPlacement), typeof(OverflowTextBlock), new PropertyMetadata(default(OverflowButtonPlacement), new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(ScrollButtonsPlacement), typeof(OverflowButtonPlacement), typeof(OverflowTextBlock), new PropertyMetadata(default(OverflowButtonPlacement), (sender, args) =>
|
||||
{
|
||||
var self = (OverflowTextBlock)sender;
|
||||
self.OnScrollButtonsPlacementPropertyChanged((OverflowButtonPlacement)args.OldValue, (OverflowButtonPlacement)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public bool IsActive
|
||||
{
|
||||
|
|
|
@ -234,7 +234,7 @@ namespace CalculatorApp
|
|||
// Delay load things later when we get a chance.
|
||||
WeakReference weakThis = new WeakReference(this);
|
||||
_ = this.Dispatcher.RunAsync(
|
||||
CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
|
||||
CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
if (TraceLogger.GetInstance().IsWindowIdInLog(ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread())))
|
||||
{
|
||||
|
@ -243,7 +243,7 @@ namespace CalculatorApp
|
|||
refThis.GetMemory();
|
||||
}
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private void LoadResourceStrings()
|
||||
|
@ -533,7 +533,7 @@ namespace CalculatorApp
|
|||
|
||||
// Since we need different font sizes for different numeric system,
|
||||
// we use a table of optimal font sizes for each numeric system.
|
||||
private static readonly FontTable[] fontTables = new FontTable[] {
|
||||
private static readonly FontTable[] fontTables = {
|
||||
new FontTable { numericSystem = "Arab", fullFont = 104, fullFontMin = 29.333, portraitMin = 23, snapFont = 40,
|
||||
fullNumPadFont = 56, snapScientificNumPadFont = 40, portraitScientificNumPadFont = 56 },
|
||||
new FontTable { numericSystem = "ArabExt", fullFont = 104, fullFontMin = 29.333, portraitMin = 23, snapFont = 40,
|
||||
|
|
|
@ -258,8 +258,7 @@ namespace CalculatorApp
|
|||
}
|
||||
|
||||
if (submission.Source == EquationSubmissionSource.ENTER_KEY
|
||||
|| (submission.Source == EquationSubmissionSource.FOCUS_LOST && submission.HasTextChanged && eq.Expression != null
|
||||
&& eq.Expression.Length > 0))
|
||||
|| (submission.Source == EquationSubmissionSource.FOCUS_LOST && submission.HasTextChanged && !string.IsNullOrEmpty(eq.Expression)))
|
||||
{
|
||||
if (submission.Source == EquationSubmissionSource.ENTER_KEY)
|
||||
{
|
||||
|
@ -355,13 +354,13 @@ namespace CalculatorApp
|
|||
{
|
||||
|
||||
WeakReference weakThis = new WeakReference(this);
|
||||
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
|
||||
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
if (weakThis.Target is EquationInputArea refThis && refThis.m_isHighContrast == refThis.m_accessibilitySettings.HighContrast)
|
||||
{
|
||||
refThis.ReloadAvailableColors(false, false);
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private void EquationTextBox_RemoveButtonClicked(object sender, RoutedEventArgs e)
|
||||
|
@ -436,10 +435,7 @@ namespace CalculatorApp
|
|||
if (index >= 0)
|
||||
{
|
||||
var container = (UIElement)EquationInputList.ContainerFromIndex(index);
|
||||
if (container != null)
|
||||
{
|
||||
container.StartBringIntoView();
|
||||
}
|
||||
container?.StartBringIntoView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -466,10 +462,7 @@ namespace CalculatorApp
|
|||
if (index >= 0)
|
||||
{
|
||||
var container = (UIElement)EquationInputList.ContainerFromIndex(index);
|
||||
if (container != null)
|
||||
{
|
||||
container.StartBringIntoView();
|
||||
}
|
||||
container?.StartBringIntoView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -594,11 +587,11 @@ namespace CalculatorApp
|
|||
{
|
||||
TimeSpan timeSpan = new TimeSpan(10000000); // 1 tick = 100 nanoseconds, and 10000000 ticks = 1 second.
|
||||
DispatcherTimerDelayer delayer = new DispatcherTimerDelayer(timeSpan);
|
||||
delayer.Action += new EventHandler<object>((object s, object arg) =>
|
||||
delayer.Action += (s, arg) =>
|
||||
{
|
||||
CalculatorApp.ViewModel.Common.TraceLogger.GetInstance().LogVariableChanged("Slider", name);
|
||||
variableSliders.Remove(name);
|
||||
});
|
||||
};
|
||||
delayer.Start();
|
||||
variableSliders.Add(name, delayer);
|
||||
}
|
||||
|
@ -612,12 +605,8 @@ namespace CalculatorApp
|
|||
private EquationViewModel GetViewModelFromEquationTextBox(object sender)
|
||||
{
|
||||
var tb = (EquationTextBox)sender;
|
||||
if (tb == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var eq = (EquationViewModel)tb.DataContext;
|
||||
var eq = (EquationViewModel)tb?.DataContext;
|
||||
|
||||
return eq;
|
||||
}
|
||||
|
|
|
@ -752,13 +752,13 @@ namespace CalculatorApp
|
|||
private void OnColorValuesChanged(UISettings sender, object args)
|
||||
{
|
||||
WeakReference weakThis = new WeakReference(this);
|
||||
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
|
||||
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
if (weakThis.Target is GraphingCalculator refThis && IsMatchAppTheme)
|
||||
{
|
||||
refThis.UpdateGraphTheme();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdateGraphTheme()
|
||||
|
@ -788,13 +788,13 @@ namespace CalculatorApp
|
|||
|
||||
IsMatchAppTheme = isMatchAppTheme;
|
||||
WeakReference weakThis = new WeakReference(this);
|
||||
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
|
||||
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
if (weakThis.Target is GraphingCalculator refThis)
|
||||
{
|
||||
refThis.UpdateGraphTheme();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private const double zoomInScale = 1 / 1.0625;
|
||||
|
|
|
@ -187,7 +187,7 @@ namespace CalculatorApp
|
|||
}
|
||||
}
|
||||
|
||||
private static readonly Dictionary<NumbersAndOperatorsEnum, Tuple<string, int, int>> buttonOutput = new Dictionary<NumbersAndOperatorsEnum, Tuple<string, int, int>>()
|
||||
private static readonly Dictionary<NumbersAndOperatorsEnum, Tuple<string, int, int>> buttonOutput = new Dictionary<NumbersAndOperatorsEnum, Tuple<string, int, int>>
|
||||
{
|
||||
{ NumbersAndOperatorsEnum.Sin, Tuple.Create("sin()", 4, 0) },
|
||||
{ NumbersAndOperatorsEnum.Cos, Tuple.Create("cos()", 4, 0) },
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace CalculatorApp
|
|||
{
|
||||
if (Frame.RequestedThemeProperty == dp)
|
||||
{
|
||||
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => { SetTitleBarControlColors(); }));
|
||||
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, SetTitleBarControlColors);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,8 +120,8 @@ namespace CalculatorApp
|
|||
return;
|
||||
}
|
||||
|
||||
double leftAddition = 0;
|
||||
double rightAddition = 0;
|
||||
double leftAddition;
|
||||
double rightAddition;
|
||||
|
||||
if (FlowDirection == FlowDirection.LeftToRight)
|
||||
{
|
||||
|
@ -140,18 +140,14 @@ namespace CalculatorApp
|
|||
|
||||
private void ColorValuesChanged(Windows.UI.ViewManagement.UISettings sender, object e)
|
||||
{
|
||||
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => { SetTitleBarControlColors(); }));
|
||||
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, SetTitleBarControlColors);
|
||||
}
|
||||
|
||||
private void SetTitleBarControlColors()
|
||||
{
|
||||
var applicationView = ApplicationView.GetForCurrentView();
|
||||
if (applicationView == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var applicationTitleBar = applicationView.TitleBar;
|
||||
var applicationTitleBar = applicationView?.TitleBar;
|
||||
if (applicationTitleBar == null)
|
||||
{
|
||||
return;
|
||||
|
@ -184,11 +180,11 @@ namespace CalculatorApp
|
|||
|
||||
private void OnHighContrastChanged(Windows.UI.ViewManagement.AccessibilitySettings sender, object args)
|
||||
{
|
||||
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
|
||||
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
SetTitleBarControlColors();
|
||||
SetTitleBarVisibility(false);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private void OnWindowActivated(object sender, WindowActivatedEventArgs e)
|
||||
|
@ -281,12 +277,12 @@ namespace CalculatorApp
|
|||
public static readonly DependencyProperty BackButtonSpaceReservedProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(BackButtonSpaceReserved), typeof(bool), typeof(TitleBar),
|
||||
new PropertyMetadata(false, new PropertyChangedCallback((sender, args) =>
|
||||
new PropertyMetadata(false, (sender, args) =>
|
||||
{
|
||||
var self = sender as TitleBar;
|
||||
VisualStateManager.GoToState(
|
||||
self, (bool)args.NewValue ? self.BackButtonVisible.Name : self.BackButtonCollapsed.Name, true);
|
||||
})));
|
||||
}));
|
||||
|
||||
private readonly Windows.ApplicationModel.Core.CoreApplicationViewTitleBar m_coreTitleBar;
|
||||
private readonly Windows.UI.ViewManagement.UISettings m_uiSettings;
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace CalculatorApp
|
|||
|
||||
public void SetDefaultFocus()
|
||||
{
|
||||
Control[] focusPrecedence = new Control[] { Value1, CurrencyRefreshBlockControl, OfflineBlock, ClearEntryButtonPos0 };
|
||||
Control[] focusPrecedence = { Value1, CurrencyRefreshBlockControl, OfflineBlock, ClearEntryButtonPos0 };
|
||||
|
||||
foreach (Control control in focusPrecedence)
|
||||
{
|
||||
|
@ -368,10 +368,7 @@ namespace CalculatorApp
|
|||
|
||||
private void HideProgressRing()
|
||||
{
|
||||
if (m_delayTimer != null)
|
||||
{
|
||||
m_delayTimer.Stop();
|
||||
}
|
||||
m_delayTimer?.Stop();
|
||||
|
||||
CurrencyLoadingProgressRing.IsActive = false;
|
||||
}
|
||||
|
@ -391,8 +388,8 @@ namespace CalculatorApp
|
|||
private static readonly Lazy<UISettings> uiSettings = new Lazy<UISettings>(true);
|
||||
private readonly Windows.UI.Xaml.Controls.MenuFlyout m_resultsFlyout = default;
|
||||
|
||||
private readonly string m_chargesMayApplyText = string.Empty;
|
||||
private readonly string m_failedToRefreshText = string.Empty;
|
||||
private readonly string m_chargesMayApplyText;
|
||||
private readonly string m_failedToRefreshText;
|
||||
|
||||
private bool m_meteredConnectionOverride;
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace CalculatorApp
|
|||
public Task HandleViewRelease()
|
||||
{
|
||||
TaskCompletionSource<object> tsource = new TaskCompletionSource<object>();
|
||||
_ = m_coreDispatcher.RunAsync(CoreDispatcherPriority.Low, new DispatchedHandler(() =>
|
||||
_ = m_coreDispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
|
||||
{
|
||||
KeyboardShortcutManager.OnWindowClosed(this.m_viewId);
|
||||
Window.Current.Content = null;
|
||||
|
@ -70,7 +70,7 @@ namespace CalculatorApp
|
|||
tsource.SetResult(new object());
|
||||
this.m_coreDispatcher.StopProcessEvents();
|
||||
Window.Current.Close();
|
||||
}));
|
||||
});
|
||||
|
||||
return tsource.Task;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue