stuff-from-scratch/apps/notes_tk/text_editor/TextEditorController.cpp

59 lines
1.2 KiB
C++
Raw Permalink Normal View History

2020-06-27 09:47:30 +00:00
#include "TextEditorController.h"
#include "File.h"
TextEditorController::TextEditorController()
: mModel(TextEditorModel::Create()),
mSavePath(),
mLoadPath()
{
}
2023-12-21 09:18:44 +00:00
Ptr<TextEditorController> TextEditorController::Create()
2020-06-27 09:47:30 +00:00
{
return std::make_unique<TextEditorController>();
}
2023-12-21 09:18:44 +00:00
void TextEditorController::SetContent(const String& content)
2020-06-27 09:47:30 +00:00
{
mModel->GetDocument()->SetContent(content);
}
2023-12-21 09:18:44 +00:00
String TextEditorController::GetContent() const
2020-06-27 09:47:30 +00:00
{
return mModel->GetDocument()->GetContent();
}
void TextEditorController::OnSave()
{
if(mSavePath.empty()) return;
File outfile(mSavePath);
2022-12-01 10:52:48 +00:00
outfile.open(File::AccessMode::Write);
outfile.writeText(mModel->GetDocument()->GetContent());
2020-06-27 09:47:30 +00:00
}
void TextEditorController::OnLoad()
{
if(mLoadPath.empty()) return;
File infile(mLoadPath);
2022-12-01 10:52:48 +00:00
infile.open(File::AccessMode::Read);
mModel->GetDocument()->SetContent(infile.readText());
2020-06-27 09:47:30 +00:00
}
void TextEditorController::SetSavePath(const std::filesystem::path& path)
{
mSavePath = path;
}
void TextEditorController::SetLoadPath(const std::filesystem::path& path)
{
mLoadPath = path;
}
void TextEditorController::OnClear()
{
mModel->GetDocument()->Clear();
}