stash changes

This commit is contained in:
Tian Liao 2024-10-24 11:32:26 +08:00
commit 1645cfddcd
10 changed files with 167 additions and 71 deletions

View file

@ -512,9 +512,9 @@ void ApplicationViewModel::Categories::set(IObservableVector<NavCategoryGroup ^>
}
}
ApplicationSnapshot ^ ApplicationViewModel::Snapshot::get()
CalculatorApp::ViewModel::Snapshot::ApplicationSnapshot ^ ApplicationViewModel::Snapshot::get()
{
auto snapshot = ref new ApplicationSnapshot();
auto snapshot = ref new CalculatorApp::ViewModel::Snapshot::ApplicationSnapshot();
snapshot->Mode = static_cast<int>(Mode);
if (m_CalculatorViewModel != nullptr && m_mode == ViewMode::Standard)
{
@ -556,7 +556,7 @@ void ApplicationViewModel::Initialize(ViewMode mode)
}
}
void ApplicationViewModel::Initialize(ApplicationSnapshot ^ snapshot)
void ApplicationViewModel::Initialize(CalculatorApp::ViewModel::Snapshot::ApplicationSnapshot ^ snapshot)
{
// TODO: restore
Initialize(static_cast<ViewMode>(snapshot->Mode));

View file

@ -20,7 +20,7 @@ namespace CalculatorApp
[Windows::Foundation::Metadata::DefaultOverload]
void Initialize(CalculatorApp::ViewModel::Common::ViewMode mode); // Use for first init, use deserialize for rehydration
void Initialize(ApplicationSnapshot^ snapshot);
void Initialize(CalculatorApp::ViewModel::Snapshot::ApplicationSnapshot^ snapshot);
OBSERVABLE_OBJECT();
OBSERVABLE_PROPERTY_RW(StandardCalculatorViewModel ^, CalculatorViewModel);
@ -73,9 +73,9 @@ namespace CalculatorApp
}
}
property ApplicationSnapshot ^ Snapshot
property CalculatorApp::ViewModel::Snapshot::ApplicationSnapshot ^ Snapshot
{
ApplicationSnapshot ^ get();
CalculatorApp::ViewModel::Snapshot::ApplicationSnapshot ^ get();
}
static property Platform::String ^ LaunchedLocalSettings

View file

@ -9,78 +9,64 @@
#include "CalcManager/ExpressionCommand.h"
#include "Snapshots.h"
namespace
namespace CalculatorApp::ViewModel::Snapshot
{
ref struct UnaryCommand sealed : public CalculatorApp::ViewModel::ICalcManagerIExprCommand
UnaryCommand::UnaryCommand(Windows::Foundation::Collections::IVectorView<int> ^ cmds)
{
internal :;
std::vector<int> Commands;
};
for (auto cmd : cmds)
{
m_cmds.push_back(cmd);
}
}
ref struct BinaryCommand sealed : public CalculatorApp::ViewModel::ICalcManagerIExprCommand
Windows::Foundation::Collections::IVectorView<int> ^ UnaryCommand::Commands::get()
{
internal :;
int Command;
};
return ref new Platform::Collections::VectorView<int>(m_cmds);
}
ref struct OperandCommand sealed : public CalculatorApp::ViewModel::ICalcManagerIExprCommand
OperandCommand::OperandCommand(bool isNegative, bool isDecimal, bool isSciFmt, Windows::Foundation::Collections::IVectorView<int> ^ cmds)
{
internal :;
bool IsNegative;
bool IsDecimalPresent;
bool IsSciFmt;
std::vector<int> Commands;
};
IsNegative = isNegative;
IsDecimalPresent = isDecimal;
IsSciFmt = isSciFmt;
for (auto cmd : cmds)
{
m_cmds.push_back(cmd);
}
}
ref struct Parentheses sealed : public CalculatorApp::ViewModel::ICalcManagerIExprCommand
{
internal :;
int Command;
};
} // namespace
namespace CalculatorApp::ViewModel
{
ICalcManagerIExprCommand ^ CreateExprCommand(const IExpressionCommand* exprCmd) {
switch (exprCmd->GetCommandType())
{
case CalculationManager::CommandType::UnaryCommand:
{
auto cmd = static_cast<const IUnaryCommand*>(exprCmd);
auto result = ref new UnaryCommand();
std::vector<int> cmdlist;
for (auto& subcmd : *cmd->GetCommands())
{
result->Commands.push_back(subcmd);
cmdlist.push_back(subcmd);
}
return result;
return ref new UnaryCommand(std::move(cmdlist));
}
case CalculationManager::CommandType::BinaryCommand:
{
auto cmd = static_cast<const IBinaryCommand*>(exprCmd);
auto result = ref new BinaryCommand();
result->Command = cmd->GetCommand();
return result;
return ref new BinaryCommand(cmd->GetCommand());
}
case CalculationManager::CommandType::OperandCommand:
{
auto cmd = static_cast<const IOpndCommand*>(exprCmd);
auto result = ref new OperandCommand();
result->IsNegative = cmd->IsNegative();
result->IsDecimalPresent = cmd->IsDecimalPresent();
result->IsSciFmt = cmd->IsSciFmt();
std::vector<int> cmdlist;
for (auto& subcmd : *cmd->GetCommands())
{
result->Commands.push_back(subcmd);
cmdlist.push_back(subcmd);
}
return result;
return ref new OperandCommand(cmd->IsNegative(), cmd->IsDecimalPresent(), cmd->IsSciFmt(), std::move(cmdlist));
}
case CalculationManager::CommandType::Parentheses:
{
auto cmd = static_cast<const IParenthesisCommand*>(exprCmd);
auto result = ref new Parentheses();
result->Command = cmd->GetCommand();
return result;
return ref new Parentheses(cmd->GetCommand());
}
default:
throw std::logic_error{ "unhandled command type." };
@ -161,13 +147,13 @@ namespace CalculatorApp::ViewModel
{
if (auto unary = dynamic_cast<UnaryCommand ^>(cmdEntry); unary != nullptr)
{
if (unary->Commands.size() == 1)
if (unary->m_cmds.size() == 1)
{
result.push_back(std::make_shared<CUnaryCommand>(unary->Commands[0]));
result.push_back(std::make_shared<CUnaryCommand>(unary->m_cmds[0]));
}
else if (unary->Commands.size() == 2)
else if (unary->m_cmds.size() == 2)
{
result.push_back(std::make_shared<CUnaryCommand>(unary->Commands[0], unary->Commands[1]));
result.push_back(std::make_shared<CUnaryCommand>(unary->m_cmds[0], unary->m_cmds[1]));
}
else
{
@ -184,7 +170,7 @@ namespace CalculatorApp::ViewModel
}
else if (auto operand = dynamic_cast<OperandCommand ^>(cmdEntry); operand != nullptr)
{
auto subcmds = std::make_shared<std::vector<int>>(operand->Commands);
auto subcmds = std::make_shared<std::vector<int>>(operand->m_cmds);
result.push_back(std::make_shared<COpndCommand>(std::move(subcmds), operand->IsNegative, operand->IsDecimalPresent, operand->IsSciFmt));
}
}

View file

@ -7,20 +7,70 @@
#include "CalcManager/CalculatorManager.h"
namespace CalculatorApp::ViewModel
namespace CalculatorApp::ViewModel::Snapshot
{
public
interface struct ICalcManagerIExprCommand
{
};
ref struct UnaryCommand sealed : public ICalcManagerIExprCommand
{
property Windows::Foundation::Collections::IVectorView<int> ^ Commands { Windows::Foundation::Collections::IVectorView<int> ^ get(); };
explicit UnaryCommand(Windows::Foundation::Collections::IVectorView<int> ^ cmds);
internal :;
explicit UnaryCommand(std::vector<int> cmds)
: m_cmds(std::move(cmds))
{
}
std::vector<int> m_cmds;
};
ref struct BinaryCommand sealed : public ICalcManagerIExprCommand
{
property int Command;
explicit BinaryCommand(int cmd)
{
Command = cmd;
}
};
ref struct OperandCommand sealed : public ICalcManagerIExprCommand
{
property bool IsNegative;
property bool IsDecimalPresent;
property bool IsSciFmt;
property Windows::Foundation::Collections::IVectorView<int> ^ Commands { Windows::Foundation::Collections::IVectorView<int> ^ get(); };
explicit OperandCommand(bool isNegative, bool isDecimal, bool isSciFmt, Windows::Foundation::Collections::IVectorView<int> ^ cmds);
internal :;
explicit OperandCommand(bool isNegative, bool isDecimal, bool isSciFmt, std::vector<int> cmds)
{
IsNegative = isNegative;
IsDecimalPresent = isDecimal;
IsSciFmt = isSciFmt;
m_cmds = std::move(cmds);
}
std::vector<int> m_cmds;
};
ref struct Parentheses sealed : public ICalcManagerIExprCommand
{
property int Command;
explicit Parentheses(int cmd)
{
Command = cmd;
}
};
public
ref struct CalcManagerHistoryToken sealed
{
property Platform::String ^ OpCodeName; // mandatory
property int CommandIndex;
internal :;
explicit CalcManagerHistoryToken(Platform::String ^ opCodeName, int cmdIndex);
};
@ -32,6 +82,12 @@ public
property Platform::String ^ Expression; // mandatory
property Platform::String ^ Result; // mandatory
// explicit CalcManagerHistoryItem(
// Windows::Foundation::Collections::IVector<CalcManagerHistoryToken ^> ^ tokens,
// Windows::Foundation::Collections::IVector<ICalcManagerIExprCommand ^> ^ commands,
// Platform::String ^ expression,
// Platform::String ^ result);
internal :;
explicit CalcManagerHistoryItem(const CalculationManager::HISTORYITEM& item);
};

View file

@ -115,7 +115,7 @@ namespace CalculatorResourceKeys
StringReference DisplayCopied(L"Display_Copied");
}
StandardCalculatorViewModel::StandardCalculatorViewModel(StandardCalculatorSnapshot ^ snapshot)
StandardCalculatorViewModel::StandardCalculatorViewModel(CalculatorApp::ViewModel::Snapshot::StandardCalculatorSnapshot ^ snapshot)
: m_DisplayValue(L"0")
, m_DecimalDisplayValue(L"0")
, m_HexDisplayValue(L"0")
@ -208,7 +208,7 @@ StandardCalculatorViewModel::StandardCalculatorViewModel(StandardCalculatorSnaps
{
using RawTokenCollection = std::vector<std::pair<std::wstring, int>>;
RawTokenCollection rawTokens;
for (CalcManagerHistoryToken ^ token : snapshot->ExpressionDisplay->Tokens)
for (CalculatorApp::ViewModel::Snapshot::CalcManagerHistoryToken ^ token : snapshot->ExpressionDisplay->Tokens)
{
rawTokens.push_back(std::pair{ token->OpCodeName->Data(), token->CommandIndex });
}
@ -1823,18 +1823,18 @@ void StandardCalculatorViewModel::SetBitshiftRadioButtonCheckedAnnouncement(Plat
Announcement = CalculatorAnnouncement::GetBitShiftRadioButtonCheckedAnnouncement(announcement);
}
StandardCalculatorSnapshot ^ StandardCalculatorViewModel::GetSnapshot() const
CalculatorApp::ViewModel::Snapshot::StandardCalculatorSnapshot ^ StandardCalculatorViewModel::GetSnapshot() const
{
auto result = ref new StandardCalculatorSnapshot();
result->CalcManager = ref new CalcManagerSnapshot(m_standardCalculatorManager);
result->PrimaryDisplay = ref new PrimaryDisplaySnapshot(m_DisplayValue, m_IsInError);
result->ExpressionDisplay = ref new ExpressionDisplaySnapshot(*m_tokens, *m_commands);
result->DisplayCommands = ref new Platform::Collections::Vector<ICalcManagerIExprCommand ^>();
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);
result->ExpressionDisplay = ref new CalculatorApp::ViewModel::Snapshot::ExpressionDisplaySnapshot(*m_tokens, *m_commands);
result->DisplayCommands = ref new Platform::Collections::Vector<CalculatorApp::ViewModel::Snapshot::ICalcManagerIExprCommand ^>();
for (auto cmd : m_standardCalculatorManager.GetDisplayCommandsSnapshot())
{
result->DisplayCommands->Append(CreateExprCommand(cmd.get()));
result->DisplayCommands->Append(CalculatorApp::ViewModel::Snapshot::CreateExprCommand(cmd.get()));
}
return nullptr;
return result;
}
// StandardCalculatorSnapshot StandardCalculatorViewModel::GetStandardCalculatorSnapshot() const

View file

@ -268,8 +268,8 @@ namespace CalculatorApp
}
}
property StandardCalculatorSnapshot
^ Snapshot { StandardCalculatorSnapshot ^ get() { return GetSnapshot(); } }
property CalculatorApp::ViewModel::Snapshot::StandardCalculatorSnapshot
^ Snapshot { CalculatorApp::ViewModel::Snapshot::StandardCalculatorSnapshot ^ get() { return GetSnapshot(); } }
// Used by unit tests
void
@ -327,10 +327,10 @@ namespace CalculatorApp
}
internal :;
explicit StandardCalculatorViewModel(StandardCalculatorSnapshot ^ snapshot = nullptr);
explicit StandardCalculatorViewModel(CalculatorApp::ViewModel::Snapshot::StandardCalculatorSnapshot ^ snapshot = nullptr);
private:
StandardCalculatorSnapshot ^ GetSnapshot() const;
CalculatorApp::ViewModel::Snapshot::StandardCalculatorSnapshot ^ GetSnapshot() const;
void SetMemorizedNumbers(const std::vector<std::wstring>& memorizedNumbers);
void UpdateProgrammerPanelDisplay();
void HandleUpdatedOperandData(CalculationManager::Command cmdenum);

View file

@ -167,6 +167,7 @@
<Compile Include="Selectors\NavViewMenuItemTemplateSelector.cs" />
<Compile Include="Utils\ResourceVirtualKey.cs" />
<Compile Include="Utils\ResourceString.cs" />
<Compile Include="Utils\SerdeUtils.cs" />
<Compile Include="Utils\ThemeHelper.cs" />
<Compile Include="Views\GraphingCalculator\EquationStylePanelControl.xaml.cs">
<DependentUpon>EquationStylePanelControl.xaml</DependentUpon>
@ -799,6 +800,9 @@
<Version>6.2.14</Version>
</PackageReference>
<PackageReference Include="Microsoft.UI.Xaml" Version="2.8.1" />
<PackageReference Include="System.Text.Json">
<Version>8.0.5</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CalcViewModel\CalcViewModel.vcxproj">

View file

@ -1,7 +1,5 @@
using System;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.UserActivities;
using CalculatorApp.ViewModel;
using CalculatorApp.ViewModel.Snapshot;
namespace CalculatorApp
{

View file

@ -0,0 +1,49 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using CalculatorApp.ViewModel.Snapshot;
namespace CalculatorApp
{
internal class CalcManagerHistoryTokenAlias
{
[JsonIgnore]
public CalcManagerHistoryToken Value;
[JsonPropertyName("t")]
public string OpCodeName
{
get => Value.OpCodeName;
set => Value.OpCodeName = value;
}
[JsonPropertyName("c")]
public int CommandIndex { get => Value.CommandIndex; }
}
internal class CalcManagerIExprCommandAlias
{
[JsonPropertyName("t")]
public string Type;
[JsonPropertyName("c")]
public string CmdString;
}
internal class CalcManagerHistoryItemAlias
{
[JsonIgnore]
public CalcManagerHistoryItem Value;
[JsonPropertyName("t")]
public IList<CalcManagerHistoryTokenAlias> Tokens
{
get => Value.Tokens.Select(x => new CalcManagerHistoryTokenAlias { Value = x }).ToList();
set => Value.Tokens = value.Select(x => new CalcManagerHistoryToken(x.OpCodeName, x.CommandIndex)).ToList();
}
//public IList<CalcManagerIExprCommandAlias> Commands
//{
// get => Value.Commands;
//}
}
}

View file

@ -23,6 +23,7 @@ using CalculatorApp.ViewModel.Common;
using CalculatorApp.ViewModel.Common.Automation;
using wuxc = Windows.UI.Xaml.Controls;
using System.Text.Json;
namespace CalculatorApp
{
@ -69,6 +70,8 @@ namespace CalculatorApp
}
var channel = UserActivityChannel.GetDefault();
var activity = await channel.GetOrCreateUserActivityAsync($"{Guid.NewGuid()}");
var s = Model.Snapshot;
var j = JsonSerializer.Serialize(s);
activity.ActivationUri = new Uri($"ms-calculator:snapshot/TODO");
activity.IsRoamable = false;
var resProvider = AppResourceProvider.GetInstance();