ViewModel-First (#9621)

* Interaction

* Remove view action

* ViewModel-first

* MainGirdOrientation Hot Reload

* Fix avalonia preview

* Remove CloseWindowInteraction

* Fix

* Avoid threading issues

* Fix

* ProfilesSelect

* Try fix previewer

* Remove AppEvents.ProfilesRefreshRequested

* Remove AppEvents.SubscriptionsRefreshRequested

* Remove AppEvents.ProxiesReloadRequested

* Remove AppEvents.AdjustMainLvColWidthRequested

* Remove AppEvents.SetDefaultServerRequested

* Remove AppEvents.RoutingsMenuRefreshRequested

* Remove AppEvents.TestServerRequested

* Remove AppEvents.InboundDisplayRequested

* Remove AppEvents.SubscriptionsUpdateRequested

* Remove AppEvents.ShowHideWindowRequested

* Remove AppEvents.ReloadRequested

* Remove AppEvents.AddServerRequested

* Fix
This commit is contained in:
DHR60
2026-07-14 01:05:05 +00:00
committed by GitHub
parent 6f50206606
commit 9664ee380e
115 changed files with 2075 additions and 2190 deletions
@@ -1,7 +1,10 @@
namespace ServiceLib.ViewModels;
public class ProfilesSelectViewModel : MyReactiveObject
public class ProfilesSelectViewModel : MyReactiveObject, ICloseable
{
public event EventHandler? RequestClose;
public Interaction<Unit, Unit> ProfilesFocusInteraction { get; } = new();
#region private prop
private string _serverFilter = string.Empty;
@@ -12,6 +15,8 @@ public class ProfilesSelectViewModel : MyReactiveObject
#endregion private prop
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
#region ObservableCollection
public IObservableCollection<ProfileItemModel> ProfileItems { get; } = new ObservableCollectionExtended<ProfileItemModel>();
@@ -36,18 +41,25 @@ public class ProfilesSelectViewModel : MyReactiveObject
[Reactive]
public bool FilterExclude { get; set; }
[Reactive]
public bool MultiSelect { get; set; }
#endregion ObservableCollection
#region Init
public ProfilesSelectViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
public ProfilesSelectViewModel()
{
_config = AppManager.Instance.Config;
_updateView = updateView;
_subIndexId = _config.SubIndexId ?? string.Empty;
#region WhenAnyValue && ReactiveCommand
SaveCmd = ReactiveCommand.Create(() =>
{
SelectFinish();
});
this.WhenAnyValue(
x => x.SelectedSub,
y => y != null && !y.Remarks.IsNullOrEmpty() && _subIndexId != y.Id)
@@ -107,7 +119,7 @@ public class ProfilesSelectViewModel : MyReactiveObject
{
return false;
}
_updateView?.Invoke(EViewAction.CloseWindow, null);
RequestClose?.Invoke(this, EventArgs.Empty);
return true;
}
@@ -125,7 +137,13 @@ public class ProfilesSelectViewModel : MyReactiveObject
await RefreshServers();
await _updateView?.Invoke(EViewAction.ProfilesFocus, null);
try
{
await ProfilesFocusInteraction.Handle(Unit.Default);
}
catch (UnhandledInteractionException<Unit, Unit>)
{
}
}
private async Task ServerFilterChanged(bool c)
@@ -157,8 +175,6 @@ public class ProfilesSelectViewModel : MyReactiveObject
var selected = lstModel.FirstOrDefault(t => t.IndexId == _config.IndexId);
SelectedProfile = selected ?? lstModel.First();
}
await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null);
}
private async Task RefreshSubscriptions()