1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 14:37:45 +00:00

AK+Everywhere: Remove "null state" of LexicalPath

This removes the default constructor of LexicalPath, and subsequently
modifies all its users to accommodate the change.
This commit is contained in:
Max Wipfli 2021-06-29 20:12:53 +02:00 committed by Andreas Kling
parent 4c018909f7
commit d8be530397
10 changed files with 52 additions and 52 deletions

View file

@ -78,7 +78,7 @@ HexEditorWidget::HexEditorWidget()
if (file_size.has_value() && file_size.value() > 0) {
m_document_dirty = false;
m_editor->set_buffer(ByteBuffer::create_zeroed(file_size.value()));
set_path(LexicalPath());
set_path({});
update_title();
} else {
GUI::MessageBox::show(window(), "Invalid file size entered.", "Error", GUI::MessageBox::Type::Error);
@ -130,7 +130,7 @@ HexEditorWidget::HexEditorWidget()
}
m_document_dirty = false;
set_path(LexicalPath(save_path.value()));
set_path(save_path.value());
dbgln("Wrote document to {}", save_path.value());
});
@ -311,11 +311,18 @@ void HexEditorWidget::initialize_menubar(GUI::Menubar& menubar)
help_menu.add_action(GUI::CommonActions::make_about_action("Hex Editor", GUI::Icon::default_icon("app-hex-editor"), window()));
}
void HexEditorWidget::set_path(const LexicalPath& lexical_path)
void HexEditorWidget::set_path(StringView const& path)
{
m_path = lexical_path.string();
m_name = lexical_path.title();
m_extension = lexical_path.extension();
if (path.is_empty()) {
m_path = {};
m_name = {};
m_extension = {};
} else {
auto lexical_path = LexicalPath(path);
m_path = lexical_path.string();
m_name = lexical_path.title();
m_extension = lexical_path.extension();
}
update_title();
}
@ -342,7 +349,7 @@ void HexEditorWidget::open_file(const String& path)
m_document_dirty = false;
m_editor->set_buffer(file->read_all()); // FIXME: On really huge files, this is never going to work. Should really create a framework to fetch data from the file on-demand.
set_path(LexicalPath(path));
set_path(path);
}
bool HexEditorWidget::request_close()

View file

@ -27,7 +27,7 @@ public:
private:
HexEditorWidget();
void set_path(const LexicalPath& file);
void set_path(StringView const&);
void update_title();
void set_search_results_visible(bool visible);

View file

@ -254,7 +254,7 @@ MainWidget::MainWidget()
}
m_editor->set_text(StringView());
set_path(LexicalPath());
set_path({});
update_title();
});
@ -287,7 +287,7 @@ MainWidget::MainWidget()
// FIXME: It would be cool if this would propagate from GUI::TextDocument somehow.
window()->set_modified(false);
set_path(LexicalPath(save_path.value()));
set_path(save_path.value());
dbgln("Wrote document to {}", save_path.value());
});
@ -595,11 +595,18 @@ void MainWidget::initialize_menubar(GUI::Menubar& menubar)
help_menu.add_action(GUI::CommonActions::make_about_action("Text Editor", GUI::Icon::default_icon("app-text-editor"), window()));
}
void MainWidget::set_path(const LexicalPath& lexical_path)
void MainWidget::set_path(StringView const& path)
{
m_path = lexical_path.string();
m_name = lexical_path.title();
m_extension = lexical_path.extension();
if (path.is_empty()) {
m_path = {};
m_name = {};
m_extension = {};
} else {
auto lexical_path = LexicalPath(path);
m_path = lexical_path.string();
m_name = lexical_path.title();
m_extension = lexical_path.extension();
}
if (m_extension == "c" || m_extension == "cc" || m_extension == "cxx" || m_extension == "cpp" || m_extension == "h") {
m_cpp_highlight->activate();
@ -660,7 +667,7 @@ bool MainWidget::open_file(const String& path)
m_editor->set_text(file->read_all());
set_path(LexicalPath(path));
set_path(path);
m_editor->set_focus(true);

View file

@ -42,7 +42,7 @@ public:
private:
MainWidget();
void set_path(const LexicalPath& file);
void set_path(StringView const&);
void update_preview();
void update_markdown_preview();
void update_html_preview();