From d68e505b04598e9001248d797f013b3965577ba3 Mon Sep 17 00:00:00 2001 From: Zach Herman Date: Thu, 19 Sep 2019 16:41:50 -0700 Subject: [PATCH] Add copy button to history menu item context menu (#628) Adds a Copy button to the context menu for history menu items located above the delete button in the menu. Copy only copies the result and not the entire content of the history item (equation and result). Fixes #429 --- src/Calculator/Resources/en-US/Resources.resw | 4 ++++ src/Calculator/Views/HistoryList.xaml | 3 +++ src/Calculator/Views/HistoryList.xaml.cpp | 11 +++++++++++ src/Calculator/Views/HistoryList.xaml.h | 1 + 4 files changed, 19 insertions(+) diff --git a/src/Calculator/Resources/en-US/Resources.resw b/src/Calculator/Resources/en-US/Resources.resw index 4b243135..5d38a1a9 100644 --- a/src/Calculator/Resources/en-US/Resources.resw +++ b/src/Calculator/Resources/en-US/Resources.resw @@ -1109,6 +1109,10 @@ Delete Text string for the Calculator Delete swipe button in the History list + + Copy + Text string for the Calculator Copy option in the History list context menu + Delete Text string for the Calculator Delete option in the History list context menu diff --git a/src/Calculator/Views/HistoryList.xaml b/src/Calculator/Views/HistoryList.xaml index 58f27a03..eff64adf 100644 --- a/src/Calculator/Views/HistoryList.xaml +++ b/src/Calculator/Views/HistoryList.xaml @@ -50,6 +50,9 @@ + diff --git a/src/Calculator/Views/HistoryList.xaml.cpp b/src/Calculator/Views/HistoryList.xaml.cpp index e9e74e4c..3130c48d 100644 --- a/src/Calculator/Views/HistoryList.xaml.cpp +++ b/src/Calculator/Views/HistoryList.xaml.cpp @@ -8,6 +8,7 @@ #include "pch.h" #include "HistoryList.xaml.h" +#include "CalcViewModel/Common/CopyPasteManager.h" #include "CalcViewModel/Common/LocalizationService.h" using namespace CalculatorApp; @@ -52,6 +53,16 @@ void HistoryList::ListView_ItemClick(_In_ Object ^ sender, _In_ ItemClickEventAr } } +void HistoryList::OnCopyMenuItemClicked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e) +{ + auto listViewItem = HistoryContextMenu->Target; + auto itemViewModel = dynamic_cast(HistoryListView->ItemFromContainer(listViewItem)); + if (itemViewModel != nullptr) + { + CopyPasteManager::CopyToClipboard(itemViewModel->Result); + } +} + void HistoryList::OnDeleteMenuItemClicked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e) { auto listViewItem = HistoryContextMenu->Target; diff --git a/src/Calculator/Views/HistoryList.xaml.h b/src/Calculator/Views/HistoryList.xaml.h index f8399a83..839e47f4 100644 --- a/src/Calculator/Views/HistoryList.xaml.h +++ b/src/Calculator/Views/HistoryList.xaml.h @@ -34,6 +34,7 @@ namespace CalculatorApp Windows::Foundation::Rect m_visibleBounds; Windows::Foundation::Rect m_coreBounds; void ListView_ItemClick(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Controls::ItemClickEventArgs ^ e); + void OnCopyMenuItemClicked(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs ^ e); void OnDeleteMenuItemClicked(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs ^ e); void OnDeleteSwipeInvoked(_In_ Microsoft::UI::Xaml::Controls::SwipeItem ^ sender, _In_ Microsoft::UI::Xaml::Controls::SwipeItemInvokedEventArgs ^ e); };