Improved Performance

- Removed redundant calls by disabling event handling when an operation is created or moved, as well as before the end of construction
- Also removed unused and ordered namespaces
This commit is contained in:
adroslice 2019-11-23 18:40:55 +01:00
parent 4b50f44985
commit b7f6158300
5 changed files with 12 additions and 8 deletions

View File

@ -17,6 +17,7 @@ namespace BFR
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
public readonly AvaloniaProperty[] HandledProperties = new AvaloniaProperty[] { TextBox.TextProperty, ComboBox.SelectedItemProperty, NumericUpDown.ValueProperty, CheckBox.IsCheckedProperty }; public readonly AvaloniaProperty[] HandledProperties = new AvaloniaProperty[] { TextBox.TextProperty, ComboBox.SelectedItemProperty, NumericUpDown.ValueProperty, CheckBox.IsCheckedProperty };
private bool HandleEvents = false;
public async Task OpenDirectoryButtonClick() => OpenDirectory(await new OpenFolderDialog() { Directory = WorkingDirectory }.ShowAsync(this)); public async Task OpenDirectoryButtonClick() => OpenDirectory(await new OpenFolderDialog() { Directory = WorkingDirectory }.ShowAsync(this));
public void OpenDirectory(string directory) public void OpenDirectory(string directory)
@ -28,7 +29,7 @@ namespace BFR
public void FilterChanged(object sender, AvaloniaPropertyChangedEventArgs e) public void FilterChanged(object sender, AvaloniaPropertyChangedEventArgs e)
{ {
if(HandledProperties.Contains(e.Property)) if(HandledProperties.Contains(e.Property) && HandleEvents)
Filter(); // Bind to PropertyChanged Filter(); // Bind to PropertyChanged
} }
public void Filter() public void Filter()
@ -43,7 +44,7 @@ namespace BFR
public void PreviewChanged(object sender, AvaloniaPropertyChangedEventArgs e) public void PreviewChanged(object sender, AvaloniaPropertyChangedEventArgs e)
{ {
if (HandledProperties.Contains(e.Property)) if (HandledProperties.Contains(e.Property) && HandleEvents)
Preview(); // Bind to PropertyChanged Preview(); // Bind to PropertyChanged
} }
public void Preview() public void Preview()
@ -69,11 +70,13 @@ namespace BFR
public void AddOperation() public void AddOperation()
{ {
HandleEvents = false;
if (Operations.Count >= 1) if (Operations.Count >= 1)
Operations.Insert( Operations.Insert(
SelectedOperation >= 0 ? SelectedOperation + 1 : Operations.Count, SelectedOperation >= 0 ? SelectedOperation + 1 : Operations.Count,
OperationTypes[SelectedOperationType].Create()); OperationTypes[SelectedOperationType].Create());
else Operations.Add(OperationTypes[SelectedOperationType].Create()); else Operations.Add(OperationTypes[SelectedOperationType].Create());
HandleEvents = true;
Preview(); Preview();
} }
@ -87,11 +90,13 @@ namespace BFR
public void MoveOperation(object sender, SpinEventArgs e) public void MoveOperation(object sender, SpinEventArgs e)
{ {
HandleEvents = false;
if (Operations.Count > 1) if (Operations.Count > 1)
if (e.Direction == SpinDirection.Increase && SelectedOperation > 0) if (e.Direction == SpinDirection.Increase && SelectedOperation > 0)
Operations.Move(SelectedOperation, SelectedOperation - 1); Operations.Move(SelectedOperation, SelectedOperation - 1);
else if (e.Direction == SpinDirection.Decrease && SelectedOperation < Operations.Count - 1) else if (e.Direction == SpinDirection.Decrease && SelectedOperation < Operations.Count - 1)
Operations.Move(SelectedOperation, SelectedOperation + 1); Operations.Move(SelectedOperation, SelectedOperation + 1);
HandleEvents = true;
Preview(); Preview();
} }
@ -122,6 +127,7 @@ namespace BFR
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
DataContext = this; DataContext = this;
OpenDirectory(Environment.OSVersion.Platform == PlatformID.Win32NT ? @"C:\Users" : @"\home"); OpenDirectory(Environment.OSVersion.Platform == PlatformID.Win32NT ? @"C:\Users" : @"\home");
HandleEvents = true;
} }
} }
} }

View File

@ -1,5 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Xml.Serialization; using System.Xml.Serialization;
using System.Linq; using System.Linq;

View File

@ -1,4 +1,5 @@
using System.Linq; using System;
using System.Linq;
using System.Xml.Serialization; using System.Xml.Serialization;
using System.Collections.Generic; using System.Collections.Generic;
@ -6,7 +7,6 @@ using Avalonia;
using BFR.Helpers; using BFR.Helpers;
using BFR.DataModels; using BFR.DataModels;
using System;
namespace BFR.Operations namespace BFR.Operations
{ {

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Collections.Generic;
using System.Xml.Serialization; using System.Xml.Serialization;
using System.Collections.Generic;
using Avalonia; using Avalonia;

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Text;
using System.Globalization; using System.Globalization;
using System.Collections.Generic; using System.Collections.Generic;