Skip to content

Commit

Permalink
Remove dead code from History (microsoft#1228)
Browse files Browse the repository at this point in the history
* Clean history

* clean unit tests

* cleaning

* Remove friend class in HistoryViewModel
  • Loading branch information
rudyhuyn authored May 25, 2020
1 parent c37f540 commit 143907f
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 440 deletions.
24 changes: 0 additions & 24 deletions src/CalcManager/CalculatorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,30 +554,6 @@ namespace CalculationManager
return m_currentDegreeMode;
}

void CalculatorManager::SetHistory(_In_ CalculatorMode eMode, _In_ vector<shared_ptr<HISTORYITEM>> const& history)
{
CalculatorHistory* pHistory = nullptr;

switch (eMode)
{
case CalculatorMode::Standard:
pHistory = m_pStdHistory.get();
break;
case CalculatorMode::Scientific:
pHistory = m_pSciHistory.get();
break;
}

if (pHistory)
{
pHistory->ClearHistory();
for (auto const& historyItem : history)
{
pHistory->AddItem(historyItem);
}
}
}

wstring CalculatorManager::GetResultForRadix(uint32_t radix, int32_t precision, bool groupDigitsPerRadix)
{
return m_currentCalculatorEngine ? m_currentCalculatorEngine->GetCurrentResultForRadix(radix, precision, groupDigitsPerRadix) : L"";
Expand Down
1 change: 0 additions & 1 deletion src/CalcManager/CalculatorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ namespace CalculationManager
return m_pHistory->MaxHistorySize();
}
CalculationManager::Command GetCurrentDegreeMode();
void SetHistory(_In_ CalculatorMode eMode, _In_ std::vector<std::shared_ptr<HISTORYITEM>> const& history);
void SetInHistoryItemLoadMode(_In_ bool isHistoryItemLoadMode);
};
}
2 changes: 0 additions & 2 deletions src/CalcViewModel/ApplicationViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ task<void> ApplicationViewModel::HandleToggleAlwaysOnTop(float width, float heig
localSettings->Values->Insert(HeightLocalSettings, height);

bool success = co_await ApplicationView::GetForCurrentView()->TryEnterViewModeAsync(ApplicationViewMode::Default);
CalculatorViewModel->AreHistoryShortcutsEnabled = success;
CalculatorViewModel->HistoryVM->AreHistoryShortcutsEnabled = success;
CalculatorViewModel->IsAlwaysOnTop = !success;
IsAlwaysOnTop = !success;
Expand Down Expand Up @@ -261,7 +260,6 @@ task<void> ApplicationViewModel::HandleToggleAlwaysOnTop(float width, float heig
}

bool success = co_await ApplicationView::GetForCurrentView()->TryEnterViewModeAsync(ApplicationViewMode::CompactOverlay, compactOptions);
CalculatorViewModel->AreHistoryShortcutsEnabled = !success;
CalculatorViewModel->HistoryVM->AreHistoryShortcutsEnabled = !success;
CalculatorViewModel->IsAlwaysOnTop = success;
IsAlwaysOnTop = success;
Expand Down
61 changes: 0 additions & 61 deletions src/CalcViewModel/Common/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,67 +72,6 @@ bool Utils::IsLastCharacterTarget(_In_ wstring const& input, _In_ wchar_t target
return !input.empty() && input.back() == target;
}

void Utils::SerializeCommandsAndTokens(
_In_ shared_ptr<vector<pair<wstring, int>>> const& tokens,
_In_ shared_ptr<vector<shared_ptr<IExpressionCommand>>> const& commands,
DataWriter ^ writer)
{
// Save the size of the commands vector
writer->WriteUInt32(static_cast<unsigned int>(commands->size()));

SerializeCommandVisitor cmdVisitor(writer);
for (const auto& exprCmd : *commands)
{
CalculationManager::CommandType commandType = exprCmd->GetCommandType();
writer->WriteInt32(static_cast<int>(commandType));
exprCmd->Accept(cmdVisitor);
}

writer->WriteUInt32(static_cast<unsigned int>(tokens->size()));

for (const auto& eachToken : *tokens)
{
auto stringData = ref new Platform::String(eachToken.first.c_str());
auto intData = eachToken.second;
writer->WriteUInt32(writer->MeasureString(stringData));
writer->WriteString(stringData);
writer->WriteInt32(intData);
}
}

const shared_ptr<vector<shared_ptr<IExpressionCommand>>> Utils::DeserializeCommands(DataReader ^ reader)
{
auto commandVector = make_shared<vector<shared_ptr<IExpressionCommand>>>();
auto commandVectorSize = reader->ReadUInt32();

CommandDeserializer cmdDeserializer(reader);
for (unsigned int i = 0; i < commandVectorSize; ++i)
{
auto commandTypeInt = reader->ReadInt32();
CalculationManager::CommandType commandType = static_cast<CalculationManager::CommandType>(commandTypeInt);
shared_ptr<IExpressionCommand> exprCmd = cmdDeserializer.Deserialize(commandType);
commandVector->push_back(exprCmd);
}

return commandVector;
}

const shared_ptr<vector<pair<wstring, int>>> Utils::DeserializeTokens(DataReader ^ reader)
{
auto tokenVector = make_shared<vector<pair<wstring, int>>>();
auto tokensSize = reader->ReadUInt32();

for (unsigned int i = 0; i < tokensSize; ++i)
{
auto stringDataLen = reader->ReadUInt32();
auto stringData = reader->ReadString(stringDataLen);
auto intData = reader->ReadInt32();
tokenVector->emplace_back(stringData->Data(), intData);
}

return tokenVector;
}

DateTime Utils::GetUniversalSystemTime()
{
SYSTEMTIME sysTime = {};
Expand Down
7 changes: 0 additions & 7 deletions src/CalcViewModel/Common/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,6 @@ namespace Utils
double GetDoubleFromWstring(std::wstring input);
int GetWindowId();
void RunOnUIThreadNonblocking(std::function<void()>&& function, _In_ Windows::UI::Core::CoreDispatcher ^ currentDispatcher);
void SerializeCommandsAndTokens(
_In_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens,
_In_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& commands,
Windows::Storage::Streams::DataWriter ^ writer);

const std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> DeserializeCommands(Windows::Storage::Streams::DataReader ^ reader);
const std::shared_ptr<std::vector<std::pair<std::wstring, int>>> DeserializeTokens(Windows::Storage::Streams::DataReader ^ reader);

Windows::Foundation::DateTime GetUniversalSystemTime();
bool IsDateTimeOlderThan(Windows::Foundation::DateTime dateTime, const long long duration);
Expand Down
Loading

0 comments on commit 143907f

Please sign in to comment.