Skip to content

Commit

Permalink
Switched to using field where possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Nov 29, 2024
1 parent 4bf73c7 commit de195ae
Show file tree
Hide file tree
Showing 25 changed files with 193 additions and 312 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ public MainViewModelForDesigner() {
}

public class MainViewModel : ViewModelBase {
private ProgressPanelViewModel fileTreeAsyncPanelViewModel_;
private string fileName_;
private ModelPanelViewModel modelPanel_;

public AudioPlayerPanelViewModel AudioPlayerPanel { get; } = new();

public MainViewModel() {
Expand Down Expand Up @@ -136,22 +132,22 @@ var animationPlaybackManager
}

public ProgressPanelViewModel FileBundleTreeAsyncPanelViewModel {
get => this.fileTreeAsyncPanelViewModel_;
get;
private set
=> this.RaiseAndSetIfChanged(ref this.fileTreeAsyncPanelViewModel_,
=> this.RaiseAndSetIfChanged(ref field,
value);
}

public string FileName {
get => this.fileName_;
get;

set => this.RaiseAndSetIfChanged(ref this.fileName_, value);
set => this.RaiseAndSetIfChanged(ref field, value);
}

public ModelPanelViewModel ModelPanel {
get => this.modelPanel_;
get;
private set => this.RaiseAndSetIfChanged(
ref this.modelPanel_,
ref field,
value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ public KeyValueGridViewModelForDesigner() {
}

public class KeyValueGridViewModel : ViewModelBase {
private ObservableCollection<KeyValuePairViewModel> keyValuePairs_ = [];

public ObservableCollection<KeyValuePairViewModel> KeyValuePairs {
get => this.keyValuePairs_;
set => this.RaiseAndSetIfChanged(ref this.keyValuePairs_, value);
}
get;
set => this.RaiseAndSetIfChanged(ref field, value);
} = [];
}

public class KeyValuePairViewModel(string key, string? value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
namespace uni.ui.avalonia.common.buttons;

public class ReportIssueButtonViewModel : ViewModelBase {
private Exception? exception_;

public Exception? Exception {
get => this.exception_;
set => this.RaiseAndSetIfChanged(ref this.exception_, value);
get;
set => this.RaiseAndSetIfChanged(ref field, value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,18 @@ public AsyncPanelViewModelForDesigner() {
}

public class AsyncPanelViewModel : ViewModelBase {
private AsyncProgress progress_;
private IDataTemplate dataTemplate_;

public AsyncProgress Progress {
get => this.progress_;
set => this.RaiseAndSetIfChanged(ref this.progress_, value);
get;
set => this.RaiseAndSetIfChanged(ref field, value);
}

public IDataTemplate DataTemplate {
get => this.dataTemplate_;
set => this.RaiseAndSetIfChanged(ref this.dataTemplate_, value);
get;
set => this.RaiseAndSetIfChanged(ref field, value);
}
}

public partial class AsyncPanel : UserControl {
private IDataTemplate dataTemplate_;

public AsyncPanel() {
this.InitializeComponent();
this.DataContextChanged += (_, _) => {
Expand All @@ -75,10 +70,10 @@ public static readonly DirectProperty<ProgressPanel, IDataTemplate>
(owner, value) => owner.DataTemplate = value);

public IDataTemplate DataTemplate {
get => this.dataTemplate_;
get;
set {
this.SetAndRaise(DataTemplateProperty, ref this.dataTemplate_, value);
this.dataTemplate_ = value;
this.SetAndRaise(DataTemplateProperty, ref field, value);
field = value;

if (this.ViewModel_ != null) {
this.ViewModel_.DataTemplate = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,29 @@ public ProgressPanelViewModelForDesigner() {
}

public class ProgressPanelViewModel : ViewModelBase {
private ValueFractionProgress progress_;
private ProgressSpinnerViewModel progressSpinner_;
private IDataTemplate dataTemplate_;

public ValueFractionProgress Progress {
get => this.progress_;
get;
set {
this.RaiseAndSetIfChanged(ref this.progress_, value);
this.RaiseAndSetIfChanged(ref field, value);
this.ProgressSpinner = new ProgressSpinnerViewModel {
Progress = value
};
}
}

public ProgressSpinnerViewModel ProgressSpinner {
get => this.progressSpinner_;
get;
private set
=> this.RaiseAndSetIfChanged(ref this.progressSpinner_, value);
=> this.RaiseAndSetIfChanged(ref field, value);
}

public IDataTemplate DataTemplate {
get => this.dataTemplate_;
set => this.RaiseAndSetIfChanged(ref this.dataTemplate_, value);
get;
set => this.RaiseAndSetIfChanged(ref field, value);
}
}

public partial class ProgressPanel : UserControl {
private IDataTemplate dataTemplate_;

public ProgressPanel() {
this.InitializeComponent();
this.DataContextChanged += (_, _) => {
Expand All @@ -91,10 +85,10 @@ public static readonly DirectProperty<ProgressPanel, IDataTemplate>
(owner, value) => owner.DataTemplate = value);

public IDataTemplate DataTemplate {
get => this.dataTemplate_;
get;
set {
this.SetAndRaise(DataTemplateProperty, ref this.dataTemplate_, value);
this.dataTemplate_ = value;
this.SetAndRaise(DataTemplateProperty, ref field, value);
field = value;

if (this.ViewModel_ != null) {
this.ViewModel_.DataTemplate = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ public ProgressSpinnerViewModelForDesigner() {
}

public class ProgressSpinnerViewModel : ViewModelBase {
private ValueFractionProgress progress_;

public ValueFractionProgress Progress {
get => this.progress_;
set => this.RaiseAndSetIfChanged(ref this.progress_, value);
get;
set => this.RaiseAndSetIfChanged(ref field, value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ public AnimationListViewModelForDesigner() {
}

public class AnimationListViewModel : ViewModelBase {
private IReadOnlyList<IReadOnlyAnimation>? animations_;
private ObservableCollection<AnimationViewModel> animationViewModels_;
private AnimationViewModel? selectedAnimationViewModel_;

public required IReadOnlyList<IReadOnlyAnimation>? Animations {
get => this.animations_;
get;
set {
this.RaiseAndSetIfChanged(ref this.animations_, value);
this.RaiseAndSetIfChanged(ref field, value);
this.AnimationViewModels = new ObservableCollection<AnimationViewModel>(
value?.Select(a => new AnimationViewModel
{ Animation = a })
Expand All @@ -49,30 +45,27 @@ public required IReadOnlyList<IReadOnlyAnimation>? Animations {
}

public ObservableCollection<AnimationViewModel> AnimationViewModels {
get => this.animationViewModels_;
get;
private set {
this.RaiseAndSetIfChanged(ref this.animationViewModels_, value);
this.RaiseAndSetIfChanged(ref field, value);
this.SelectedAnimationViewModel
= this.AnimationViewModels.FirstOrDefault();
}
}

public AnimationViewModel? SelectedAnimationViewModel {
get => this.selectedAnimationViewModel_;
get;
set => this.RaiseAndSetIfChanged(
ref this.selectedAnimationViewModel_,
ref field,
value);
}
}

public class AnimationViewModel : ViewModelBase {
private IReadOnlyAnimation animation_;
private MaterialIconKind icon_;

public required IReadOnlyAnimation Animation {
get => this.animation_;
get;
set {
this.RaiseAndSetIfChanged(ref this.animation_, value);
this.RaiseAndSetIfChanged(ref field, value);

var frameCount = value.FrameCount;
this.Icon = frameCount switch {
Expand All @@ -84,8 +77,8 @@ public required IReadOnlyAnimation Animation {
}

public MaterialIconKind Icon {
get => this.icon_;
private set => this.RaiseAndSetIfChanged(ref this.icon_, value);
get;
private set => this.RaiseAndSetIfChanged(ref field, value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ public AnimationPlaybackPanelViewModelForDesigner() {
public class AnimationPlaybackPanelViewModel : ViewModelBase {
private IAnimationPlaybackManager? animationPlaybackManager_;

private bool isPlaying_;
private string playButtonTooltip_;

private bool loopPlayback_;
private string loopButtonTooltip_;

private int frameRate_;
private float frame_;
private int frameCount_;
private float lastFrame_;
private int frameTextWidth_;

public IAnimationPlaybackManager? AnimationPlaybackManager {
get => this.animationPlaybackManager_;
set {
Expand All @@ -59,9 +47,9 @@ public IAnimationPlaybackManager? AnimationPlaybackManager {
}

public bool IsPlaying {
get => this.isPlaying_;
get;
set {
this.RaiseAndSetIfChanged(ref this.isPlaying_, value);
this.RaiseAndSetIfChanged(ref field, value);
if (this.animationPlaybackManager_ != null) {
this.animationPlaybackManager_.IsPlaying = value;
}
Expand All @@ -71,14 +59,14 @@ public bool IsPlaying {
}

public string PlayButtonTooltip {
get => this.playButtonTooltip_;
set => this.RaiseAndSetIfChanged(ref this.playButtonTooltip_, value);
get;
set => this.RaiseAndSetIfChanged(ref field, value);
}

public bool LoopPlayback {
get => this.loopPlayback_;
get;
set {
this.RaiseAndSetIfChanged(ref this.loopPlayback_, value);
this.RaiseAndSetIfChanged(ref field, value);
if (this.animationPlaybackManager_ != null) {
this.animationPlaybackManager_.LoopPlayback = value;
}
Expand All @@ -88,49 +76,49 @@ public bool LoopPlayback {
}

public string LoopButtonTooltip {
get => this.loopButtonTooltip_;
set => this.RaiseAndSetIfChanged(ref this.loopButtonTooltip_, value);
get;
set => this.RaiseAndSetIfChanged(ref field, value);
}

public int FrameRate {
get => this.frameRate_;
get;
set {
this.RaiseAndSetIfChanged(ref this.frameRate_, value);
this.RaiseAndSetIfChanged(ref field, value);
if (this.animationPlaybackManager_ != null) {
this.animationPlaybackManager_.FrameRate = value;
}
}
}

public float Frame {
get => this.frame_;
get;
set {
this.RaiseAndSetIfChanged(ref this.frame_, value);
this.RaiseAndSetIfChanged(ref field, value);
if (this.animationPlaybackManager_ != null) {
this.animationPlaybackManager_.Frame = value;
}
}
}

public int FrameCount {
get => this.frameCount_;
get;
private set {
this.RaiseAndSetIfChanged(ref this.frameCount_, value);
this.RaiseAndSetIfChanged(ref field, value);
this.LastFrame = Math.Max(0, value - .0001f);

var digitsInFrameCount = this.frameCount_.Base10DigitCount();
var digitsInFrameCount = field.Base10DigitCount();
this.FrameTextWidth = 45 + 10 * digitsInFrameCount;
}
}

public float LastFrame {
get => this.lastFrame_;
private set => this.RaiseAndSetIfChanged(ref this.lastFrame_, value);
get;
private set => this.RaiseAndSetIfChanged(ref field, value);
}

public int FrameTextWidth {
get => this.frameTextWidth_;
private set => this.RaiseAndSetIfChanged(ref this.frameTextWidth_, value);
get;
private set => this.RaiseAndSetIfChanged(ref field, value);
}

private void Update_() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,24 @@ public static implicit operator KeyValuePairViewModel(
}

public class AnimationsPanelViewModel : ViewModelBase {
private IReadOnlyList<IReadOnlyAnimation>? animations_;
private AnimationListViewModel animationListViewModel_;
private AnimationViewModel? selectedAnimationViewModel_;

public IReadOnlyList<IReadOnlyAnimation>? Animations {
get => this.animations_;
get;
set {
this.RaiseAndSetIfChanged(ref this.animations_, value);
this.RaiseAndSetIfChanged(ref field, value);
this.AnimationList = new AnimationListViewModel { Animations = value };
}
}

public AnimationListViewModel AnimationList {
get => this.animationListViewModel_;
get;
private set
=> this.RaiseAndSetIfChanged(ref this.animationListViewModel_, value);
=> this.RaiseAndSetIfChanged(ref field, value);
}

public AnimationViewModel? SelectedAnimation {
get => this.selectedAnimationViewModel_;
get;
set {
this.RaiseAndSetIfChanged(ref this.selectedAnimationViewModel_,
this.RaiseAndSetIfChanged(ref field,
value);

var animationPlaybackManager = this.AnimationPlaybackManager;
Expand Down
Loading

0 comments on commit de195ae

Please sign in to comment.