Remove old shells, some UI improvements for settings.
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
using Wino.Calendar.ViewModels;
|
||||
using Wino.Mail.WinUI;
|
||||
|
||||
namespace Wino.Mail.Views.Abstract;
|
||||
|
||||
public abstract class CalendarAppShellAbstract : BasePage<CalendarAppShellViewModel>
|
||||
{
|
||||
protected CalendarAppShellAbstract()
|
||||
{
|
||||
NavigationCacheMode = Microsoft.UI.Xaml.Navigation.NavigationCacheMode.Disabled;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using Wino.Mail.ViewModels;
|
||||
using Wino.Mail.WinUI;
|
||||
|
||||
namespace Wino.Views.Abstract;
|
||||
|
||||
public abstract class MailAppShellAbstract : BasePage<MailAppShellViewModel>
|
||||
{
|
||||
protected MailAppShellAbstract()
|
||||
{
|
||||
NavigationCacheMode = Microsoft.UI.Xaml.Navigation.NavigationCacheMode.Disabled;
|
||||
}
|
||||
}
|
||||
@@ -1,308 +0,0 @@
|
||||
<abstract:CalendarAppShellAbstract
|
||||
x:Class="Wino.Mail.WinUI.Views.Calendar.CalendarAppShell"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:abstract="using:Wino.Mail.Views.Abstract"
|
||||
xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
|
||||
xmlns:animations="using:CommunityToolkit.WinUI.Animations"
|
||||
xmlns:calendarControls="using:Wino.Calendar.Controls"
|
||||
xmlns:communityControls="using:CommunityToolkit.WinUI.Controls"
|
||||
xmlns:coreControls="using:Wino.Mail.WinUI.Controls"
|
||||
xmlns:coreSelectors="using:Wino.Mail.WinUI.Selectors"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:data="using:Wino.Calendar.ViewModels.Data"
|
||||
xmlns:domain="using:Wino.Core.Domain"
|
||||
xmlns:helpers="using:Wino.Helpers"
|
||||
xmlns:local="using:Wino.Calendar.Views"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:menu="using:Wino.Core.Domain.MenuItems"
|
||||
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
|
||||
Loaded="OnLoaded"
|
||||
PreviewKeyDown="OnPreviewKeyDown"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Page.Resources>
|
||||
<DataTemplate x:Key="CalendarSettingsItemTemplate" x:DataType="menu:SettingsItem">
|
||||
<coreControls:WinoNavigationViewItem DataContext="{x:Bind}" SelectsOnInvoked="False">
|
||||
<coreControls:WinoNavigationViewItem.Icon>
|
||||
<muxc:AnimatedIcon>
|
||||
<muxc:AnimatedIcon.Source>
|
||||
<animatedvisuals:AnimatedSettingsVisualSource />
|
||||
</muxc:AnimatedIcon.Source>
|
||||
<muxc:AnimatedIcon.FallbackIconSource>
|
||||
<muxc:SymbolIconSource Symbol="Setting" />
|
||||
</muxc:AnimatedIcon.FallbackIconSource>
|
||||
</muxc:AnimatedIcon>
|
||||
</coreControls:WinoNavigationViewItem.Icon>
|
||||
<TextBlock VerticalAlignment="Center" Text="{x:Bind domain:Translator.MenuSettings}" />
|
||||
</coreControls:WinoNavigationViewItem>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="CalendarStoreUpdateItemTemplate" x:DataType="menu:StoreUpdateMenuItem">
|
||||
<coreControls:WinoNavigationViewItem DataContext="{x:Bind}" SelectsOnInvoked="False">
|
||||
<muxc:NavigationViewItem.Icon>
|
||||
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="" />
|
||||
</muxc:NavigationViewItem.Icon>
|
||||
<TextBlock VerticalAlignment="Center" Text="{x:Bind domain:Translator.MenuUpdateAvailable}" />
|
||||
</coreControls:WinoNavigationViewItem>
|
||||
</DataTemplate>
|
||||
|
||||
<coreSelectors:NavigationMenuTemplateSelector
|
||||
x:Key="NavigationMenuTemplateSelector"
|
||||
RatingItemTemplate="{StaticResource RatingItemTemplate}"
|
||||
SeperatorTemplate="{StaticResource SeperatorTemplate}" />
|
||||
|
||||
<Style
|
||||
x:Key="CalendarNavigationButtonStyle"
|
||||
BasedOn="{StaticResource DefaultButtonStyle}"
|
||||
TargetType="Button">
|
||||
<Setter Property="Margin" Value="0,4,0,0" />
|
||||
<Setter Property="Padding" Value="8,4,8,6" />
|
||||
<Setter Property="CornerRadius" Value="6" />
|
||||
<Setter Property="Width" Value="40" />
|
||||
</Style>
|
||||
</Page.Resources>
|
||||
|
||||
<Grid
|
||||
x:Name="RootGrid"
|
||||
Padding="0"
|
||||
ColumnSpacing="0"
|
||||
RowSpacing="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="48" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
|
||||
<Grid
|
||||
Grid.ColumnSpan="2"
|
||||
Background="{ThemeResource WinoApplicationBackgroundColor}"
|
||||
IsHitTestVisible="False">
|
||||
<Grid.BackgroundTransition>
|
||||
<BrushTransition />
|
||||
</Grid.BackgroundTransition>
|
||||
</Grid>
|
||||
|
||||
<muxc:NavigationView
|
||||
x:Name="navigationView"
|
||||
Grid.Row="1"
|
||||
Grid.ColumnSpan="3"
|
||||
Background="Transparent"
|
||||
DisplayModeChanged="NavigationViewDisplayModeChanged"
|
||||
IsBackButtonVisible="Collapsed"
|
||||
IsPaneOpen="{x:Bind ViewModel.PreferencesService.IsNavigationPaneOpened, Mode=TwoWay}"
|
||||
IsPaneToggleButtonVisible="False"
|
||||
IsSettingsVisible="False"
|
||||
IsTitleBarAutoPaddingEnabled="False"
|
||||
ItemInvoked="NavigationViewItemInvoked"
|
||||
MenuItemTemplateSelector="{StaticResource NavigationMenuTemplateSelector}"
|
||||
MenuItemsSource="{x:Bind ViewModel.MenuItems, Mode=OneWay}"
|
||||
OpenPaneLength="{x:Bind ViewModel.StatePersistenceService.OpenPaneLength, Mode=TwoWay}"
|
||||
PaneClosed="NavigationPaneClosed"
|
||||
PaneDisplayMode="Auto"
|
||||
PaneOpened="NavigationPaneOpened"
|
||||
Style="{StaticResource CalendarShellNavigationViewStyle}">
|
||||
<muxc:NavigationView.PaneCustomContent>
|
||||
<Grid x:Name="PaneCustomContent" Padding="0,0,0,6">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<coreControls:WinoNavigationViewItem
|
||||
x:Name="NewCalendarEventNavigationItem"
|
||||
Grid.Row="0"
|
||||
Height="50"
|
||||
Margin="0,0,0,12"
|
||||
AutomationProperties.Name="{x:Bind domain:Translator.CalendarEventCompose_NewEventButton, Mode=OneTime}"
|
||||
IsTabStop="True"
|
||||
KeyDown="NewCalendarEventNavigationItemKeyDown"
|
||||
SelectsOnInvoked="False"
|
||||
Tapped="NewCalendarEventNavigationItemTapped">
|
||||
<muxc:NavigationViewItem.Icon>
|
||||
<coreControls:WinoFontIcon Icon="NewMail" />
|
||||
</muxc:NavigationViewItem.Icon>
|
||||
<TextBlock
|
||||
Margin="0,-2,0,0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="16"
|
||||
Style="{StaticResource FlyoutPickerTitleTextBlockStyle}"
|
||||
Text="{x:Bind domain:Translator.CalendarEventCompose_NewEventButton, Mode=OneTime}" />
|
||||
</coreControls:WinoNavigationViewItem>
|
||||
|
||||
<Border
|
||||
x:Name="RangeSummaryCard"
|
||||
Grid.Row="1"
|
||||
Margin="16,0,16,12"
|
||||
Padding="12"
|
||||
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
|
||||
CornerRadius="8">
|
||||
<StackPanel Spacing="12">
|
||||
<TextBlock
|
||||
FontWeight="SemiBold"
|
||||
Text="{x:Bind ViewModel.VisibleDateRangeText, Mode=OneWay}"
|
||||
TextWrapping="WrapWholeWords" />
|
||||
|
||||
<muxc:CalendarView
|
||||
x:Name="VisibleDateRangeCalendarView"
|
||||
HorizontalAlignment="Stretch"
|
||||
SelectionMode="Multiple"
|
||||
SelectedDatesChanged="VisibleDateRangeCalendarViewSelectedDatesChanged" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- Account Calendars Host -->
|
||||
<ListView
|
||||
x:Name="CalendarHostListView"
|
||||
Grid.Row="2"
|
||||
ItemsSource="{x:Bind ViewModel.AccountCalendarStateService.GroupedAccountCalendars}"
|
||||
SelectionMode="None">
|
||||
<ListView.Header>
|
||||
<TextBlock
|
||||
Margin="20,12,12,12"
|
||||
FontSize="16"
|
||||
Text="Calendars" />
|
||||
</ListView.Header>
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:DataType="data:GroupedAccountCalendarViewModel">
|
||||
<muxc:Expander
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
IsExpanded="{x:Bind IsExpanded, Mode=TwoWay}">
|
||||
<muxc:Expander.Header>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<CheckBox
|
||||
Width="26"
|
||||
MinWidth="0"
|
||||
IsChecked="{x:Bind IsCheckedState, Mode=TwoWay}"
|
||||
IsThreeState="True" />
|
||||
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
TextWrapping="Wrap">
|
||||
<Run FontWeight="SemiBold" Text="{x:Bind Account.Name}" />
|
||||
<Run FontSize="12" Text="(" /><Run FontSize="12" Text="{x:Bind Account.Address}" /><Run FontSize="12" Text=")" />
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
</muxc:Expander.Header>
|
||||
<muxc:Expander.Content>
|
||||
<ItemsControl ItemsSource="{x:Bind AccountCalendars}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="data:AccountCalendarViewModel">
|
||||
<CheckBox
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
VerticalContentAlignment="Stretch"
|
||||
IsChecked="{x:Bind IsChecked, Mode=TwoWay}">
|
||||
<Grid Margin="0,0,0,5" ColumnSpacing="6">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Ellipse
|
||||
Width="20"
|
||||
Height="20"
|
||||
Fill="{x:Bind helpers:XamlHelpers.GetSolidColorBrushFromHex(BackgroundColorHex), Mode=OneWay}" />
|
||||
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="14"
|
||||
Text="{x:Bind Name, Mode=OneWay}"
|
||||
TextWrapping="Wrap" />
|
||||
</Grid>
|
||||
</CheckBox>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</muxc:Expander.Content>
|
||||
</muxc:Expander>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</Grid>
|
||||
</muxc:NavigationView.PaneCustomContent>
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Main Content -->
|
||||
<Frame
|
||||
x:Name="InnerShellFrame"
|
||||
Padding="0,0,7,7"
|
||||
CacheSize="0"
|
||||
IsNavigationStackEnabled="True">
|
||||
<Frame.ContentTransitions>
|
||||
<TransitionCollection>
|
||||
<PopupThemeTransition />
|
||||
</TransitionCollection>
|
||||
</Frame.ContentTransitions>
|
||||
</Frame>
|
||||
|
||||
<!-- InfoBar -->
|
||||
<coreControls:WinoInfoBar
|
||||
x:Name="ShellInfoBar"
|
||||
MaxWidth="700"
|
||||
Margin="0,60,25,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
IsClosable="False"
|
||||
IsOpen="False" />
|
||||
</Grid>
|
||||
</muxc:NavigationView>
|
||||
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="LowResolutionStates">
|
||||
<VisualState x:Name="BigScreen">
|
||||
<VisualState.StateTriggers>
|
||||
<AdaptiveTrigger MinWindowWidth="1200" />
|
||||
</VisualState.StateTriggers>
|
||||
<VisualState.Setters>
|
||||
<Setter Target="navigationView.IsPaneOpen" Value="True" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="SmallScreen">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="navigationView.IsPaneOpen" Value="False" />
|
||||
</VisualState.Setters>
|
||||
<VisualState.StateTriggers>
|
||||
<AdaptiveTrigger MinWindowWidth="0" />
|
||||
</VisualState.StateTriggers>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
|
||||
<VisualStateGroup x:Name="CalendarOrientationStates">
|
||||
<VisualState x:Name="HorizontalCalendar" />
|
||||
<VisualState x:Name="VerticalCalendar" />
|
||||
</VisualStateGroup>
|
||||
|
||||
<VisualStateGroup x:Name="ShellStateContentGroup">
|
||||
<VisualState x:Name="DefaultShellContentState" />
|
||||
<VisualState x:Name="EventDetailsContentState">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="RangeSummaryCard.IsEnabled" Value="False" />
|
||||
<Setter Target="CalendarHostListView.IsEnabled" Value="False" />
|
||||
</VisualState.Setters>
|
||||
<VisualState.StateTriggers>
|
||||
<StateTrigger IsActive="{x:Bind ViewModel.StatePersistenceService.IsEventDetailsVisible, Mode=OneWay}" />
|
||||
</VisualState.StateTriggers>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Grid>
|
||||
</abstract:CalendarAppShellAbstract>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,307 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.MenuItems;
|
||||
using Wino.Core.Domain.Models;
|
||||
using Wino.Core.Domain.Models.Calendar;
|
||||
using Wino.Mail.Views.Abstract;
|
||||
using Wino.Messaging.Client.Calendar;
|
||||
using Windows.System;
|
||||
|
||||
namespace Wino.Mail.WinUI.Views.Calendar;
|
||||
|
||||
public sealed partial class CalendarAppShell : CalendarAppShellAbstract,
|
||||
IRecipient<CalendarDisplayTypeChangedMessage>
|
||||
{
|
||||
private const string STATE_HorizontalCalendar = "HorizontalCalendar";
|
||||
private const string STATE_VerticalCalendar = "VerticalCalendar";
|
||||
private bool _isSynchronizingVisibleDateRangeCalendar;
|
||||
|
||||
public Frame GetShellFrame() => InnerShellFrame;
|
||||
|
||||
public CalendarAppShell()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
ViewModel.PropertyChanged += ViewModelPropertyChanged;
|
||||
ManageCalendarDisplayType(ViewModel.StatePersistenceService.CalendarDisplayType);
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
UpdateNavigationPaneLayout(navigationView.DisplayMode);
|
||||
SynchronizeVisibleDateRangeCalendar();
|
||||
}
|
||||
|
||||
private void ManageCalendarDisplayType(Core.Domain.Enums.CalendarDisplayType displayType)
|
||||
{
|
||||
if (displayType == Core.Domain.Enums.CalendarDisplayType.Month)
|
||||
{
|
||||
VisualStateManager.GoToState(this, STATE_VerticalCalendar, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
VisualStateManager.GoToState(this, STATE_HorizontalCalendar, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void PreviousDateClicked(object sender, RoutedEventArgs e)
|
||||
=> ViewModel.PreviousDateRangeCommand.Execute(null);
|
||||
|
||||
private void NextDateClicked(object sender, RoutedEventArgs e)
|
||||
=> ViewModel.NextDateRangeCommand.Execute(null);
|
||||
|
||||
private async void NewCalendarEventNavigationItemTapped(object sender, TappedRoutedEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
await InvokeNewCalendarEventAsync();
|
||||
}
|
||||
|
||||
private void VisibleDateRangeCalendarViewSelectedDatesChanged(CalendarView sender, CalendarViewSelectedDatesChangedEventArgs args)
|
||||
{
|
||||
if (_isSynchronizingVisibleDateRangeCalendar)
|
||||
return;
|
||||
|
||||
DateTimeOffset? interactedDate = null;
|
||||
|
||||
if (args.AddedDates.Count > 0)
|
||||
{
|
||||
interactedDate = args.AddedDates[0];
|
||||
}
|
||||
else if (args.RemovedDates.Count > 0)
|
||||
{
|
||||
interactedDate = args.RemovedDates[0];
|
||||
}
|
||||
|
||||
if (interactedDate is null)
|
||||
return;
|
||||
|
||||
var clickedArgs = new CalendarViewDayClickedEventArgs(interactedDate.Value.DateTime);
|
||||
|
||||
if (ViewModel.DateClickedCommand.CanExecute(clickedArgs))
|
||||
{
|
||||
ViewModel.DateClickedCommand.Execute(clickedArgs);
|
||||
}
|
||||
}
|
||||
|
||||
private async void NewCalendarEventNavigationItemKeyDown(object sender, KeyRoutedEventArgs e)
|
||||
{
|
||||
if (e.Key is not (VirtualKey.Enter or VirtualKey.Space))
|
||||
return;
|
||||
|
||||
e.Handled = true;
|
||||
await InvokeNewCalendarEventAsync();
|
||||
}
|
||||
|
||||
private async void NavigationViewItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
|
||||
{
|
||||
if (args.InvokedItemContainer is FrameworkElement { DataContext: IMenuItem menuItem })
|
||||
{
|
||||
await ViewModel.HandleNavigationItemInvokedAsync(menuItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void NavigationViewDisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args)
|
||||
=> UpdateNavigationPaneLayout(args.DisplayMode);
|
||||
|
||||
private void NavigationPaneOpened(NavigationView sender, object args)
|
||||
=> UpdateNavigationPaneLayout(sender.DisplayMode);
|
||||
|
||||
private void NavigationPaneClosed(NavigationView sender, object args)
|
||||
=> UpdateNavigationPaneLayout(sender.DisplayMode);
|
||||
|
||||
private Task InvokeNewCalendarEventAsync()
|
||||
=> ViewModel.HandleNavigationItemInvokedAsync(new NewCalendarEventMenuItem());
|
||||
|
||||
private void UpdateNavigationPaneLayout(NavigationViewDisplayMode displayMode)
|
||||
{
|
||||
var paneContentVisibility = displayMode == NavigationViewDisplayMode.Expanded && navigationView.IsPaneOpen
|
||||
? Visibility.Visible
|
||||
: Visibility.Collapsed;
|
||||
|
||||
PaneCustomContent.Visibility = paneContentVisibility;
|
||||
|
||||
Debug.WriteLine($"NavigationView display mode changed to {displayMode}. Pane custom content visibility set to {paneContentVisibility}.");
|
||||
}
|
||||
|
||||
public void Receive(CalendarDisplayTypeChangedMessage message)
|
||||
{
|
||||
ManageCalendarDisplayType(message.NewDisplayType);
|
||||
SynchronizeVisibleDateRangeCalendar();
|
||||
}
|
||||
|
||||
private void ViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName is nameof(ViewModel.CurrentVisibleRange) or nameof(ViewModel.VisibleDateRangeText))
|
||||
{
|
||||
SynchronizeVisibleDateRangeCalendar();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnNavigatedFrom(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedFrom(e);
|
||||
|
||||
InnerShellFrame.BackStack.Clear();
|
||||
InnerShellFrame.ForwardStack.Clear();
|
||||
|
||||
if (InnerShellFrame.Content is IDisposable disposableContent)
|
||||
{
|
||||
disposableContent.Dispose();
|
||||
}
|
||||
|
||||
Bindings.StopTracking();
|
||||
}
|
||||
|
||||
protected override void RegisterRecipients()
|
||||
{
|
||||
base.RegisterRecipients();
|
||||
|
||||
WeakReferenceMessenger.Default.Register<CalendarDisplayTypeChangedMessage>(this);
|
||||
}
|
||||
|
||||
protected override void UnregisterRecipients()
|
||||
{
|
||||
base.UnregisterRecipients();
|
||||
|
||||
WeakReferenceMessenger.Default.Unregister<CalendarDisplayTypeChangedMessage>(this);
|
||||
}
|
||||
|
||||
private async void OnPreviewKeyDown(object sender, KeyRoutedEventArgs e)
|
||||
{
|
||||
if (e.KeyStatus.RepeatCount > 1 || ShouldIgnoreShortcut())
|
||||
return;
|
||||
|
||||
var key = NormalizeKey(e.Key);
|
||||
if (string.IsNullOrEmpty(key))
|
||||
return;
|
||||
|
||||
var shortcutService = WinoApplication.Current.Services.GetRequiredService<IKeyboardShortcutService>();
|
||||
var shortcut = await shortcutService.GetShortcutForKeyAsync(WinoApplicationMode.Calendar, key, GetCurrentModifierKeys());
|
||||
|
||||
if (shortcut == null)
|
||||
return;
|
||||
|
||||
var details = new KeyboardShortcutTriggerDetails
|
||||
{
|
||||
ShortcutId = shortcut.Id,
|
||||
Mode = shortcut.Mode,
|
||||
Action = shortcut.Action,
|
||||
Key = shortcut.Key,
|
||||
ModifierKeys = shortcut.ModifierKeys,
|
||||
Sender = sender,
|
||||
Origin = FocusManager.GetFocusedElement(XamlRoot)
|
||||
};
|
||||
|
||||
await ViewModel.KeyboardShortcutHook(details);
|
||||
|
||||
if (InnerShellFrame.Content is BasePage activePage && activePage.AssociatedViewModel != null)
|
||||
{
|
||||
await activePage.AssociatedViewModel.KeyboardShortcutHook(details);
|
||||
}
|
||||
|
||||
if (details.Handled)
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShouldIgnoreShortcut()
|
||||
{
|
||||
var focusedElement = FocusManager.GetFocusedElement(XamlRoot);
|
||||
|
||||
if (focusedElement is TextBox or AutoSuggestBox or PasswordBox or RichEditBox or ComboBox)
|
||||
return true;
|
||||
|
||||
if (focusedElement is FrameworkElement frameworkElement)
|
||||
{
|
||||
var typeName = frameworkElement.GetType().Name;
|
||||
if (typeName.Contains("WebView", StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static ModifierKeys GetCurrentModifierKeys()
|
||||
{
|
||||
var modifiers = ModifierKeys.None;
|
||||
|
||||
if (Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Control).HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down))
|
||||
modifiers |= ModifierKeys.Control;
|
||||
if (Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Menu).HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down))
|
||||
modifiers |= ModifierKeys.Alt;
|
||||
if (Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Shift).HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down))
|
||||
modifiers |= ModifierKeys.Shift;
|
||||
if (Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.LeftWindows).HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down) ||
|
||||
Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.RightWindows).HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down))
|
||||
{
|
||||
modifiers |= ModifierKeys.Windows;
|
||||
}
|
||||
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
private static string NormalizeKey(Windows.System.VirtualKey key)
|
||||
{
|
||||
return key switch
|
||||
{
|
||||
Windows.System.VirtualKey.Control or
|
||||
Windows.System.VirtualKey.LeftControl or
|
||||
Windows.System.VirtualKey.RightControl or
|
||||
Windows.System.VirtualKey.Menu or
|
||||
Windows.System.VirtualKey.LeftMenu or
|
||||
Windows.System.VirtualKey.RightMenu or
|
||||
Windows.System.VirtualKey.Shift or
|
||||
Windows.System.VirtualKey.LeftShift or
|
||||
Windows.System.VirtualKey.RightShift or
|
||||
Windows.System.VirtualKey.LeftWindows or
|
||||
Windows.System.VirtualKey.RightWindows => string.Empty,
|
||||
_ => key.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
private void SynchronizeVisibleDateRangeCalendar()
|
||||
{
|
||||
if (!DispatcherQueue.HasThreadAccess)
|
||||
{
|
||||
var enqueued = DispatcherQueue.TryEnqueue(SynchronizeVisibleDateRangeCalendar);
|
||||
|
||||
if (!enqueued)
|
||||
throw new InvalidOperationException("Could not marshal visible date range calendar synchronization onto the UI thread.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_isSynchronizingVisibleDateRangeCalendar = true;
|
||||
|
||||
try
|
||||
{
|
||||
VisibleDateRangeCalendarView.SelectedDates.Clear();
|
||||
|
||||
var currentRange = ViewModel.CurrentVisibleRange;
|
||||
if (currentRange == null)
|
||||
return;
|
||||
|
||||
foreach (var date in currentRange.Dates)
|
||||
{
|
||||
VisibleDateRangeCalendarView.SelectedDates.Add(new DateTimeOffset(date.ToDateTime(TimeOnly.MinValue)));
|
||||
}
|
||||
|
||||
VisibleDateRangeCalendarView.SetDisplayDate(new DateTimeOffset(currentRange.AnchorDate.ToDateTime(TimeOnly.MinValue)));
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isSynchronizingVisibleDateRangeCalendar = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -568,27 +568,14 @@
|
||||
Text="{x:Bind domain:Translator.CalendarEventCompose_NewEventButton, Mode=OneTime}" />
|
||||
</coreControls:WinoNavigationViewItem>
|
||||
|
||||
<Border
|
||||
x:Name="RangeSummaryCard"
|
||||
<muxc:CalendarView
|
||||
x:Name="VisibleDateRangeCalendarView"
|
||||
Grid.Row="1"
|
||||
Margin="16,0,16,12"
|
||||
Padding="12"
|
||||
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
|
||||
CornerRadius="8">
|
||||
<StackPanel Spacing="12">
|
||||
<TextBlock
|
||||
FontWeight="SemiBold"
|
||||
Text="{x:Bind ViewModel.CalendarClient.VisibleDateRangeText, Mode=OneWay}"
|
||||
TextWrapping="WrapWholeWords" />
|
||||
|
||||
<muxc:CalendarView
|
||||
x:Name="VisibleDateRangeCalendarView"
|
||||
HorizontalAlignment="Stretch"
|
||||
SelectedDatesChanged="VisibleDateRangeCalendarViewSelectedDatesChanged"
|
||||
SelectionMode="Multiple"
|
||||
Style="{StaticResource WinoCalendarViewStyle}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
Margin="12,0"
|
||||
HorizontalAlignment="Stretch"
|
||||
SelectedDatesChanged="VisibleDateRangeCalendarViewSelectedDatesChanged"
|
||||
SelectionMode="Multiple"
|
||||
Style="{StaticResource WinoCalendarViewStyle}" />
|
||||
|
||||
<ListView
|
||||
x:Name="CalendarHostListView"
|
||||
|
||||
@@ -66,6 +66,7 @@ public sealed partial class WinoAppShell : Views.Abstract.WinoAppShellAbstract,
|
||||
ViewModel.MailClient.PropertyChanged += MailClientPropertyChanged;
|
||||
ViewModel.CalendarClient.PropertyChanged += CalendarClientPropertyChanged;
|
||||
ViewModel.PropertyChanged += ViewModelPropertyChanged;
|
||||
ViewModel.PreferencesService.PreferenceChanged += PreferencesServiceChanged;
|
||||
ViewModel.StatePersistenceService.StatePropertyChanged += StatePersistenceServiceChanged;
|
||||
CalendarTypeSelector.RegisterPropertyChangedCallback(WinoCalendarTypeSelectorControl.SelectedTypeProperty, CalendarTypeSelectorSelectedTypeChanged);
|
||||
|
||||
@@ -561,6 +562,7 @@ public sealed partial class WinoAppShell : Views.Abstract.WinoAppShellAbstract,
|
||||
|
||||
try
|
||||
{
|
||||
VisibleDateRangeCalendarView.FirstDayOfWeek = MapFirstDayOfWeek(ViewModel.PreferencesService.FirstDayOfWeek);
|
||||
VisibleDateRangeCalendarView.SelectedDates.Clear();
|
||||
|
||||
var currentRange = ViewModel.CalendarClient.CurrentVisibleRange;
|
||||
@@ -580,6 +582,27 @@ public sealed partial class WinoAppShell : Views.Abstract.WinoAppShellAbstract,
|
||||
}
|
||||
}
|
||||
|
||||
private void PreferencesServiceChanged(object? sender, string propertyName)
|
||||
{
|
||||
if (propertyName == nameof(IPreferencesService.FirstDayOfWeek))
|
||||
{
|
||||
SynchronizeVisibleDateRangeCalendar();
|
||||
}
|
||||
}
|
||||
|
||||
private static Windows.Globalization.DayOfWeek MapFirstDayOfWeek(DayOfWeek dayOfWeek)
|
||||
=> dayOfWeek switch
|
||||
{
|
||||
DayOfWeek.Sunday => Windows.Globalization.DayOfWeek.Sunday,
|
||||
DayOfWeek.Monday => Windows.Globalization.DayOfWeek.Monday,
|
||||
DayOfWeek.Tuesday => Windows.Globalization.DayOfWeek.Tuesday,
|
||||
DayOfWeek.Wednesday => Windows.Globalization.DayOfWeek.Wednesday,
|
||||
DayOfWeek.Thursday => Windows.Globalization.DayOfWeek.Thursday,
|
||||
DayOfWeek.Friday => Windows.Globalization.DayOfWeek.Friday,
|
||||
DayOfWeek.Saturday => Windows.Globalization.DayOfWeek.Saturday,
|
||||
_ => Windows.Globalization.DayOfWeek.Monday
|
||||
};
|
||||
|
||||
private void ViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName != nameof(ViewModel.SelectedMenuItem) || !ViewModel.CurrentClient.HandlesNavigationSelection)
|
||||
|
||||
Reference in New Issue
Block a user