using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Media; using PicView.Avalonia.Functions; using PicView.Avalonia.UI; using PicView.Avalonia.WindowBehavior; using R3; namespace PicView.Avalonia.ViewModels; public class MainWindowViewModel : IDisposable { public BindableReactiveProperty ImageBackground { get; } = new(); public BindableReactiveProperty ConstrainedImageBackground { get; } = new(); public BindableReactiveProperty RightControlOffSetMargin { get; } = new(); public BindableReactiveProperty TopScreenMargin { get; } = new(); public BindableReactiveProperty BottomScreenMargin { get; } = new(); public BindableReactiveProperty BottomCornerRadius { get; } = new(); public BindableReactiveProperty BackgroundChoice { get; } = new(); public BindableReactiveProperty WindowMinSize { get; } = new(); public BindableReactiveProperty TitlebarHeight { get; } = new(); public BindableReactiveProperty BottombarHeight { get; } = new(); public BindableReactiveProperty SizeToContent { get; } = new(); public BindableReactiveProperty ToggleScrollBarVisibility { get; } = new(); public BindableReactiveProperty CanResize { get; } = new(); public BindableReactiveProperty CurrentView { get; } = new(); public BindableReactiveProperty IsFileMenuVisible { get; } = new(); public BindableReactiveProperty IsImageMenuVisible { get; } = new(); public BindableReactiveProperty IsSettingsMenuVisible { get; } = new(); public BindableReactiveProperty IsToolsMenuVisible { get; } = new(); public BindableReactiveProperty TitleMaxWidth { get; } = new(); public BindableReactiveProperty IsFullscreen { get; } = new(); public BindableReactiveProperty IsMaximized { get; } = new(); public BindableReactiveProperty ShouldRestore { get; } = new(); public BindableReactiveProperty ShouldMaximizeBeShown { get; } = new(true); public BindableReactiveProperty IsLoadingIndicatorShown { get; } = new(); public BindableReactiveProperty IsUIShown { get; } = new(); public BindableReactiveProperty IsTopToolbarShown { get; } = new(); public BindableReactiveProperty IsBottomToolbarShown { get; } = new(); public BindableReactiveProperty IsEditableTitlebarOpen { get; } = new(); public BindableReactiveProperty ChangeCtrlZoomImage { get; } = new(); public void LayoutButtonSubscription() { Observable.EveryValueChanged(this, x => x.IsMaximized.CurrentValue, UIHelper.GetFrameProvider) .Subscribe(_ => SetButtonValues()); Observable.EveryValueChanged(this, x => x.IsFullscreen.CurrentValue, UIHelper.GetFrameProvider) .Subscribe(_ => SetButtonValues()); } #region Menus public ReactiveCommand CloseMenuCommand { get; } = new(CloseMenus); public ReactiveCommand ToggleFileMenuCommand { get; } = new(ToggleFileMenu); public ReactiveCommand ToggleImageMenuCommand { get; } = new(ToggleImageMenu); public ReactiveCommand ToggleSettingsMenuCommand { get; } = new(ToggleSettingsMenu); public ReactiveCommand ToggleToolsMenuCommand { get; } = new(ToggleToolsMenu); private static void CloseMenus(Unit unit) => MenuManager.CloseMenus(UIHelper.GetMainView.DataContext as MainViewModel); private static void ToggleFileMenu(Unit unit) => MenuManager.ToggleFileMenu(UIHelper.GetMainView.DataContext as MainViewModel); private static void ToggleImageMenu(Unit unit) => MenuManager.ToggleImageMenu(UIHelper.GetMainView.DataContext as MainViewModel); private static void ToggleSettingsMenu(Unit unit) => MenuManager.ToggleSettingsMenu(UIHelper.GetMainView.DataContext as MainViewModel); private static void ToggleToolsMenu(Unit unit) => MenuManager.ToggleToolsMenu(UIHelper.GetMainView.DataContext as MainViewModel); #endregion Menus public ReactiveCommand ExitCommand { get; } = new(async (_, _) => { await FunctionsMapper.Close(); }); public ReactiveCommand MaximizeCommand { get; } = new(async (_, _) => { await FunctionsMapper.Maximize(); }); public ReactiveCommand MinimizeCommand { get; } = new(async (_, _) => { await WindowFunctions.Minimize(); }); public ReactiveCommand RestoreCommand { get; } = new(async (_, _) => { await FunctionsMapper.Restore(); }); public ReactiveCommand ToggleFullscreenCommand { get; } = new(async (_, _) => { await FunctionsMapper.ToggleFullscreen(); }); private void SetButtonValues() { ShouldRestore.Value = IsFullscreen.CurrentValue || IsMaximized.CurrentValue; ShouldMaximizeBeShown.Value = !IsFullscreen.CurrentValue && !IsMaximized.CurrentValue; } public void Dispose() { Disposable.Dispose(ImageBackground, ConstrainedImageBackground, RightControlOffSetMargin, TopScreenMargin, BottomScreenMargin, BottomCornerRadius, BackgroundChoice, WindowMinSize, TitlebarHeight, BottombarHeight, SizeToContent, CanResize, CurrentView, TitleMaxWidth, IsLoadingIndicatorShown, IsUIShown, IsTopToolbarShown, IsBottomToolbarShown, IsEditableTitlebarOpen); } }