Improve the Recall support (#2245)

* stash changes

* stash changes

* pass build

* set snapshot

* stash changes

* update launch utils

* stash changes

* stash changes

* renaming

* DeflateUtils

* stash changes

* deserialization

* restore session

* connect ui

* handle errors

* rename CalcManagerHistoryToken

* handle optional props

* fix optional props

* ensure error state

* resolve a comment

* resolve a comment
This commit is contained in:
Tian L. 2024-11-07 17:04:01 +08:00 committed by GitHub
parent 9d7d3a6b79
commit 80015d227f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 998 additions and 676 deletions

View file

@ -227,7 +227,7 @@ String ^ StandardCalculatorViewModel::CalculateNarratorDisplayValue(_In_ wstring
String ^ StandardCalculatorViewModel::GetNarratorStringReadRawNumbers(_In_ String ^ localizedDisplayValue)
{
wstring ws;
LocalizationSettings^ locSettings = LocalizationSettings::GetInstance();
LocalizationSettings ^ locSettings = LocalizationSettings::GetInstance();
// Insert a space after each digit in the string, to force Narrator to read them as separate numbers.
for (const wchar_t& c : localizedDisplayValue)
@ -386,7 +386,7 @@ void StandardCalculatorViewModel::SetTokens(_Inout_ shared_ptr<vector<pair<wstri
return;
}
LocalizationSettings^ localizer = LocalizationSettings::GetInstance();
LocalizationSettings ^ localizer = LocalizationSettings::GetInstance();
const wstring separator = L" ";
for (unsigned int i = 0; i < nTokens; ++i)
@ -449,7 +449,7 @@ String ^ StandardCalculatorViewModel::GetCalculatorExpressionAutomationName()
void StandardCalculatorViewModel::SetMemorizedNumbers(const vector<wstring>& newMemorizedNumbers)
{
LocalizationSettings^ localizer = LocalizationSettings::GetInstance();
LocalizationSettings ^ localizer = LocalizationSettings::GetInstance();
if (newMemorizedNumbers.size() == 0) // Memory has been cleared
{
MemorizedNumbers->Clear();
@ -1060,8 +1060,8 @@ ButtonInfo StandardCalculatorViewModel::MapCharacterToButtonId(char16 ch)
{
if (LocalizationSettings::GetInstance()->IsLocalizedDigit(ch))
{
result.buttonId =
NumbersAndOperatorsEnum::Zero + static_cast<NumbersAndOperatorsEnum>(ch - LocalizationSettings::GetInstance()->GetDigitSymbolFromEnUsDigit('0'));
result.buttonId = NumbersAndOperatorsEnum::Zero
+ static_cast<NumbersAndOperatorsEnum>(ch - LocalizationSettings::GetInstance()->GetDigitSymbolFromEnUsDigit('0'));
result.canSendNegate = true;
}
}
@ -1588,7 +1588,7 @@ void StandardCalculatorViewModel::UpdateProgrammerPanelDisplay()
binaryDisplayString = m_standardCalculatorManager.GetResultForRadix(2, precision, true);
}
}
LocalizationSettings^ localizer = LocalizationSettings::GetInstance();
LocalizationSettings ^ localizer = LocalizationSettings::GetInstance();
binaryDisplayString = AddPadding(binaryDisplayString);
localizer->LocalizeDisplayValue(&hexDisplayString);
@ -1787,49 +1787,56 @@ void StandardCalculatorViewModel::SetBitshiftRadioButtonCheckedAnnouncement(Plat
Announcement = CalculatorAnnouncement::GetBitShiftRadioButtonCheckedAnnouncement(announcement);
}
StandardCalculatorSnapshot StandardCalculatorViewModel::GetStandardCalculatorSnapshot() const
CalculatorApp::ViewModel::Snapshot::StandardCalculatorSnapshot ^ StandardCalculatorViewModel::Snapshot::get()
{
StandardCalculatorSnapshot snapshot;
auto& historyItems = m_standardCalculatorManager.GetHistoryItems();
if (!historyItems.empty())
{
snapshot.CalcManager.HistoryItems = std::move(historyItems);
}
snapshot.PrimaryDisplay = PrimaryDisplaySnapshot{ m_DisplayValue, m_IsInError };
auto result = ref new CalculatorApp::ViewModel::Snapshot::StandardCalculatorSnapshot();
result->CalcManager = ref new CalculatorApp::ViewModel::Snapshot::CalcManagerSnapshot(m_standardCalculatorManager);
result->PrimaryDisplay = ref new CalculatorApp::ViewModel::Snapshot::PrimaryDisplaySnapshot(m_DisplayValue, m_IsInError);
if (!m_tokens->empty() && !m_commands->empty())
{
snapshot.ExpressionDisplay = { *m_tokens, *m_commands };
result->ExpressionDisplay = ref new CalculatorApp::ViewModel::Snapshot::ExpressionDisplaySnapshot(*m_tokens, *m_commands);
}
snapshot.DisplayCommands = m_standardCalculatorManager.GetDisplayCommandsSnapshot();
return snapshot;
result->DisplayCommands = ref new Platform::Collections::Vector<CalculatorApp::ViewModel::Snapshot::ICalcManagerIExprCommand ^>();
for (auto cmd : m_standardCalculatorManager.GetDisplayCommandsSnapshot())
{
result->DisplayCommands->Append(CalculatorApp::ViewModel::Snapshot::CreateExprCommand(cmd.get()));
}
return result;
}
void StandardCalculatorViewModel::SetStandardCalculatorSnapshot(const StandardCalculatorSnapshot& snapshot)
void CalculatorApp::ViewModel::StandardCalculatorViewModel::Snapshot::set(CalculatorApp::ViewModel::Snapshot::StandardCalculatorSnapshot ^ snapshot)
{
if (snapshot.CalcManager.HistoryItems.has_value())
assert(snapshot != nullptr);
m_standardCalculatorManager.Reset();
if (snapshot->CalcManager->HistoryItems != nullptr)
{
m_standardCalculatorManager.SetHistoryItems(snapshot.CalcManager.HistoryItems.value());
m_standardCalculatorManager.SetHistoryItems(ToUnderlying(snapshot->CalcManager->HistoryItems));
}
std::vector<int> commands;
if (snapshot.ExpressionDisplay.has_value() && snapshot.ExpressionDisplay->Tokens.back().first == L"=")
if (snapshot->ExpressionDisplay != nullptr && snapshot->ExpressionDisplay->Tokens->GetAt(snapshot->ExpressionDisplay->Tokens->Size - 1)->OpCodeName == L"=")
{
commands = GetCommandsFromExpressionCommands(snapshot.ExpressionDisplay->Commands);
commands = GetCommandsFromExpressionCommands(ToUnderlying(snapshot->ExpressionDisplay->Commands));
}
if (commands.empty() && !snapshot.DisplayCommands.empty())
if (commands.empty() && snapshot->DisplayCommands->Size > 0)
{
commands = GetCommandsFromExpressionCommands(snapshot.DisplayCommands);
commands = GetCommandsFromExpressionCommands(ToUnderlying(snapshot->DisplayCommands));
}
for (const auto& command : commands)
for (auto cmd : commands)
{
m_standardCalculatorManager.SendCommand(static_cast<Command>(command));
m_standardCalculatorManager.SendCommand(static_cast<Command>(cmd));
}
if (snapshot.ExpressionDisplay.has_value())
if (snapshot->ExpressionDisplay != nullptr)
{
using RawTokenCollection = std::vector<std::pair<std::wstring, int>>;
RawTokenCollection rawTokens;
for (CalculatorApp::ViewModel::Snapshot::CalcManagerToken ^ token : snapshot->ExpressionDisplay->Tokens)
{
rawTokens.push_back(std::pair{ token->OpCodeName->Data(), token->CommandIndex });
}
SetExpressionDisplay(
std::make_shared<std::vector<std::pair<std::wstring, int>>>(snapshot.ExpressionDisplay->Tokens),
std::make_shared<std::vector<std::shared_ptr<IExpressionCommand>>>(snapshot.ExpressionDisplay->Commands));
std::make_shared<RawTokenCollection>(rawTokens),
std::make_shared<std::vector<std::shared_ptr<IExpressionCommand>>>(ToUnderlying(snapshot->ExpressionDisplay->Commands)));
}
SetPrimaryDisplay(snapshot.PrimaryDisplay.DisplayValue, snapshot.PrimaryDisplay.IsError);
SetPrimaryDisplay(snapshot->PrimaryDisplay->DisplayValue, snapshot->PrimaryDisplay->IsError);
}