#include "TextEditorController.h" #include "File.h" TextEditorController::TextEditorController() : mModel(TextEditorModel::Create()), mSavePath(), mLoadPath() { } Ptr TextEditorController::Create() { return std::make_unique(); } void TextEditorController::SetContent(const String& content) { mModel->GetDocument()->SetContent(content); } String TextEditorController::GetContent() const { return mModel->GetDocument()->GetContent(); } void TextEditorController::OnSave() { if(mSavePath.empty()) return; File outfile(mSavePath); outfile.open(File::AccessMode::Write); outfile.writeText(mModel->GetDocument()->GetContent()); } void TextEditorController::OnLoad() { if(mLoadPath.empty()) return; File infile(mLoadPath); infile.open(File::AccessMode::Read); mModel->GetDocument()->SetContent(infile.readText()); } 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(); }