mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 14:13:30 -07:00
Move History and Memory context menus to ListViewItemContainer so users can open them with keyboards
This commit is contained in:
parent
f6a6aae6e6
commit
a0d4565515
5 changed files with 29 additions and 54 deletions
|
@ -51,7 +51,7 @@
|
||||||
Invoked="OnDeleteSwipeInvoked"/>
|
Invoked="OnDeleteSwipeInvoked"/>
|
||||||
</muxc:SwipeItems>
|
</muxc:SwipeItems>
|
||||||
|
|
||||||
<MenuFlyout x:Key="HistoryContextMenu">
|
<MenuFlyout x:Name="HistoryContextMenu">
|
||||||
<MenuFlyoutItem x:Uid="DeleteHistoryMenuItem"
|
<MenuFlyoutItem x:Uid="DeleteHistoryMenuItem"
|
||||||
Click="OnDeleteMenuItemClicked"
|
Click="OnDeleteMenuItemClicked"
|
||||||
Icon="Delete"/>
|
Icon="Delete"/>
|
||||||
|
@ -59,9 +59,7 @@
|
||||||
|
|
||||||
<DataTemplate x:Key="HistoryItemTemplate" x:DataType="model:HistoryItemViewModel">
|
<DataTemplate x:Key="HistoryItemTemplate" x:DataType="model:HistoryItemViewModel">
|
||||||
<muxc:SwipeControl RightItems="{StaticResource HistorySwipeItems}">
|
<muxc:SwipeControl RightItems="{StaticResource HistorySwipeItems}">
|
||||||
<StackPanel Margin="0,6,4,6"
|
<StackPanel Margin="0,6,4,6"Background="Transparent">
|
||||||
Background="Transparent"
|
|
||||||
ContextFlyout="{StaticResource HistoryContextMenu}">
|
|
||||||
<TextBlock x:Name="exprTextBlock"
|
<TextBlock x:Name="exprTextBlock"
|
||||||
Margin="0,0,0,4"
|
Margin="0,0,0,4"
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
|
@ -87,6 +85,7 @@
|
||||||
BasedOn="{StaticResource HistoryMemoryItemContainerStyle}"
|
BasedOn="{StaticResource HistoryMemoryItemContainerStyle}"
|
||||||
TargetType="ListViewItem">
|
TargetType="ListViewItem">
|
||||||
<Setter Property="Margin" Value="0,0,0,20"/>
|
<Setter Property="Margin" Value="0,0,0,20"/>
|
||||||
|
<Setter Property="ContextFlyout" Value="{StaticResource HistoryContextMenu}"/>
|
||||||
</Style>
|
</Style>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</UserControl.Resources>
|
</UserControl.Resources>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -67,9 +67,13 @@ void HistoryList::ListView_ItemClick(_In_ Object^ sender, _In_ ItemClickEventArg
|
||||||
|
|
||||||
void HistoryList::OnDeleteMenuItemClicked(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
|
void HistoryList::OnDeleteMenuItemClicked(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
|
||||||
{
|
{
|
||||||
auto clickedItem = safe_cast<HistoryItemViewModel^>(safe_cast<FrameworkElement^>(sender)->DataContext);
|
auto listViewItem = HistoryContextMenu->Target;
|
||||||
|
auto itemViewModel = safe_cast<HistoryItemViewModel^>(HistoryListView->ItemFromContainer(listViewItem));
|
||||||
|
|
||||||
Model->DeleteItem(clickedItem);
|
if (itemViewModel != nullptr)
|
||||||
|
{
|
||||||
|
Model->DeleteItem(itemViewModel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryList::OnDeleteSwipeInvoked(_In_ MUXC::SwipeItem^ sender, _In_ MUXC::SwipeItemInvokedEventArgs^ e)
|
void HistoryList::OnDeleteSwipeInvoked(_In_ MUXC::SwipeItem^ sender, _In_ MUXC::SwipeItemInvokedEventArgs^ e)
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<converters:BooleanToVisibilityNegationConverter x:Key="BooleanToVisibilityNegationConverter"/>
|
<converters:BooleanToVisibilityNegationConverter x:Key="BooleanToVisibilityNegationConverter"/>
|
||||||
<converters:BooleanNegationConverter x:Key="BooleanNegationConverter"/>
|
<converters:BooleanNegationConverter x:Key="BooleanNegationConverter"/>
|
||||||
|
|
||||||
<MenuFlyout x:Key="MemoryContextMenu">
|
<MenuFlyout x:Name="MemoryContextMenu">
|
||||||
<MenuFlyoutItem x:Uid="ClearMemoryMenuItem" Click="OnClearMenuItemClicked">
|
<MenuFlyoutItem x:Uid="ClearMemoryMenuItem" Click="OnClearMenuItemClicked">
|
||||||
<MenuFlyoutItem.Icon>
|
<MenuFlyoutItem.Icon>
|
||||||
<FontIcon FontFamily="{StaticResource CalculatorFontFamily}" Glyph=""/>
|
<FontIcon FontFamily="{StaticResource CalculatorFontFamily}" Glyph=""/>
|
||||||
|
@ -44,6 +44,7 @@
|
||||||
BasedOn="{StaticResource HistoryMemoryItemContainerStyle}"
|
BasedOn="{StaticResource HistoryMemoryItemContainerStyle}"
|
||||||
TargetType="ListViewItem">
|
TargetType="ListViewItem">
|
||||||
<Setter Property="Margin" Value="0,0,0,8"/>
|
<Setter Property="Margin" Value="0,0,0,8"/>
|
||||||
|
<Setter Property="ContextFlyout" Value="{StaticResource MemoryContextMenu}"/>
|
||||||
</Style>
|
</Style>
|
||||||
</UserControl.Resources>
|
</UserControl.Resources>
|
||||||
|
|
||||||
|
@ -107,8 +108,6 @@
|
||||||
<ListView x:Name="MemoryListView"
|
<ListView x:Name="MemoryListView"
|
||||||
Padding="0,12,0,0"
|
Padding="0,12,0,0"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
ContextCanceled="OnContextCanceled"
|
|
||||||
ContextRequested="OnContextRequested"
|
|
||||||
IsItemClickEnabled="true"
|
IsItemClickEnabled="true"
|
||||||
ItemClick="MemoryListItemClick"
|
ItemClick="MemoryListItemClick"
|
||||||
ItemContainerStyle="{ThemeResource MemoryItemContainerStyle}"
|
ItemContainerStyle="{ThemeResource MemoryItemContainerStyle}"
|
||||||
|
|
|
@ -39,7 +39,6 @@ Memory::Memory() :
|
||||||
m_isErrorVisualState(false)
|
m_isErrorVisualState(false)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
m_memoryItemFlyout = safe_cast<MenuFlyout^>(Resources->Lookup("MemoryContextMenu"));
|
|
||||||
|
|
||||||
MemoryPaneEmpty->FlowDirection = LocalizationService::GetInstance()->GetFlowDirection();
|
MemoryPaneEmpty->FlowDirection = LocalizationService::GetInstance()->GetFlowDirection();
|
||||||
}
|
}
|
||||||
|
@ -56,53 +55,31 @@ void Memory::MemoryListItemClick(_In_ Object^ sender, _In_ ItemClickEventArgs^ e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Memory::OnContextRequested(Windows::UI::Xaml::UIElement^ sender, Windows::UI::Xaml::Input::ContextRequestedEventArgs^ e)
|
|
||||||
{
|
|
||||||
// Walk up the tree to find the ListViewItem.
|
|
||||||
// There may not be one if the click wasn't on an item.
|
|
||||||
auto requestedElement = safe_cast<FrameworkElement^>(e->OriginalSource);
|
|
||||||
while ((requestedElement != sender) && !dynamic_cast<ListViewItem^>(requestedElement))
|
|
||||||
{
|
|
||||||
requestedElement = safe_cast<FrameworkElement^>(VisualTreeHelper::GetParent(requestedElement));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (requestedElement != sender)
|
|
||||||
{
|
|
||||||
// The context menu request was for a ListViewItem.
|
|
||||||
auto memorySlot = safe_cast<MemoryItemViewModel^>(MemoryListView->ItemFromContainer(requestedElement));
|
|
||||||
Point point;
|
|
||||||
if (e->TryGetPosition(requestedElement, &point))
|
|
||||||
{
|
|
||||||
m_memoryItemFlyout->ShowAt(requestedElement, point);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Not invoked via pointer, so let XAML choose a default location.
|
|
||||||
m_memoryItemFlyout->ShowAt(requestedElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
e->Handled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Memory::OnContextCanceled(Windows::UI::Xaml::UIElement^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
|
||||||
{
|
|
||||||
m_memoryItemFlyout->Hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Memory::OnClearMenuItemClicked(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
|
void Memory::OnClearMenuItemClicked(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
|
||||||
{
|
{
|
||||||
GetMemoryItemForCurrentFlyout()->Clear();
|
auto memoryItem = GetMemoryItemForCurrentFlyout();
|
||||||
|
if (memoryItem != nullptr)
|
||||||
|
{
|
||||||
|
memoryItem->Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Memory::OnMemoryAddMenuItemClicked(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
|
void Memory::OnMemoryAddMenuItemClicked(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
|
||||||
{
|
{
|
||||||
GetMemoryItemForCurrentFlyout()->MemoryAdd();
|
auto memoryItem = GetMemoryItemForCurrentFlyout();
|
||||||
|
if (memoryItem != nullptr)
|
||||||
|
{
|
||||||
|
memoryItem->MemoryAdd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Memory::OnMemorySubtractMenuItemClicked(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
|
void Memory::OnMemorySubtractMenuItemClicked(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
|
||||||
{
|
{
|
||||||
GetMemoryItemForCurrentFlyout()->MemorySubtract();
|
auto memoryItem = GetMemoryItemForCurrentFlyout();
|
||||||
|
if (memoryItem != nullptr)
|
||||||
|
{
|
||||||
|
memoryItem->MemorySubtract();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Memory::IsErrorVisualState::get()
|
bool Memory::IsErrorVisualState::get()
|
||||||
|
@ -135,7 +112,6 @@ void Memory::MemoryList_Unloaded(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
|
||||||
|
|
||||||
MemoryItemViewModel^ Memory::GetMemoryItemForCurrentFlyout()
|
MemoryItemViewModel^ Memory::GetMemoryItemForCurrentFlyout()
|
||||||
{
|
{
|
||||||
auto listViewItem = m_memoryItemFlyout->Target;
|
auto listViewItem = MemoryContextMenu->Target;
|
||||||
|
|
||||||
return safe_cast<MemoryItemViewModel^>(MemoryListView->ItemFromContainer(listViewItem));
|
return safe_cast<MemoryItemViewModel^>(MemoryListView->ItemFromContainer(listViewItem));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -37,14 +37,11 @@ namespace CalculatorApp
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Windows::UI::Xaml::Controls::MenuFlyout^ m_memoryItemFlyout;
|
|
||||||
Windows::Foundation::Rect m_visibleBounds;
|
Windows::Foundation::Rect m_visibleBounds;
|
||||||
Windows::Foundation::Rect m_coreBounds;
|
Windows::Foundation::Rect m_coreBounds;
|
||||||
bool m_isErrorVisualState;
|
bool m_isErrorVisualState;
|
||||||
|
|
||||||
void MemoryListItemClick(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::Controls::ItemClickEventArgs^ e);
|
void MemoryListItemClick(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::Controls::ItemClickEventArgs^ e);
|
||||||
void OnContextRequested(Windows::UI::Xaml::UIElement^ sender, Windows::UI::Xaml::Input::ContextRequestedEventArgs^ e);
|
|
||||||
void OnContextCanceled(Windows::UI::Xaml::UIElement^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
|
||||||
void OnClearMenuItemClicked(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
|
void OnClearMenuItemClicked(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||||
void OnMemoryAddMenuItemClicked(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
|
void OnMemoryAddMenuItemClicked(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||||
void OnMemorySubtractMenuItemClicked(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
|
void OnMemorySubtractMenuItemClicked(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue