2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-11-01 14:40:32 -03:00
|
|
|
#include "ProjectFile.h"
|
2020-02-06 11:04:03 -03:00
|
|
|
#include <LibCore/File.h>
|
2019-10-23 15:54:41 -03:00
|
|
|
|
2020-08-17 10:22:30 -03:00
|
|
|
namespace HackStudio {
|
|
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
ProjectFile::ProjectFile(String const& name)
|
2020-02-16 05:17:49 -03:00
|
|
|
: m_name(name)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 15:29:38 -03:00
|
|
|
GUI::TextDocument& ProjectFile::document() const
|
2019-10-27 15:39:15 -03:00
|
|
|
{
|
2021-03-05 12:21:01 -03:00
|
|
|
create_document_if_needed();
|
|
|
|
|
VERIFY(m_document);
|
2019-11-01 15:22:42 -03:00
|
|
|
return *m_document;
|
2019-10-23 15:54:41 -03:00
|
|
|
}
|
2020-08-17 10:22:30 -03:00
|
|
|
|
2020-11-03 09:27:05 -03:00
|
|
|
int ProjectFile::vertical_scroll_value() const
|
|
|
|
|
{
|
|
|
|
|
return m_vertical_scroll_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectFile::vertical_scroll_value(int vertical_scroll_value)
|
|
|
|
|
{
|
|
|
|
|
m_vertical_scroll_value = vertical_scroll_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ProjectFile::horizontal_scroll_value() const
|
|
|
|
|
{
|
|
|
|
|
return m_horizontal_scroll_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectFile::horizontal_scroll_value(int horizontal_scroll_value)
|
|
|
|
|
{
|
|
|
|
|
m_horizontal_scroll_value = horizontal_scroll_value;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-05 12:21:01 -03:00
|
|
|
CodeDocument& ProjectFile::code_document() const
|
|
|
|
|
{
|
|
|
|
|
create_document_if_needed();
|
|
|
|
|
VERIFY(m_document);
|
|
|
|
|
return *m_document;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectFile::create_document_if_needed() const
|
|
|
|
|
{
|
|
|
|
|
if (m_document)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_document = CodeDocument::create(m_name);
|
2021-05-12 06:26:43 -03:00
|
|
|
auto file_or_error = Core::File::open(m_name, Core::OpenMode::ReadOnly);
|
2021-03-05 12:21:01 -03:00
|
|
|
if (file_or_error.is_error()) {
|
|
|
|
|
warnln("Couldn't open '{}': {}", m_name, file_or_error.error());
|
|
|
|
|
// This is okay though, we'll just go with an empty document and create the file when saving.
|
2021-03-19 08:06:32 -03:00
|
|
|
return;
|
2021-03-05 12:21:01 -03:00
|
|
|
}
|
2021-03-19 08:06:32 -03:00
|
|
|
|
|
|
|
|
auto& file = *file_or_error.value();
|
|
|
|
|
m_could_render_text = m_document->set_text(file.read_all());
|
2021-03-05 12:21:01 -03:00
|
|
|
}
|
|
|
|
|
|
2020-08-17 10:22:30 -03:00
|
|
|
}
|