summaryrefslogtreecommitdiff
path: root/Userland/Applications/TextEditor
diff options
context:
space:
mode:
authorMax Wipfli <mail@maxwipfli.ch>2021-06-29 20:12:53 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-30 11:13:54 +0200
commitd8be530397bb10dd7f700babcaffcfce5a14b12c (patch)
tree7d368afed723ff54ebaecc02a23628395af99840 /Userland/Applications/TextEditor
parent4c018909f72719b8916cd1480216e9ecb7a16d7a (diff)
downloadserenity-d8be530397bb10dd7f700babcaffcfce5a14b12c.zip
AK+Everywhere: Remove "null state" of LexicalPath
This removes the default constructor of LexicalPath, and subsequently modifies all its users to accommodate the change.
Diffstat (limited to 'Userland/Applications/TextEditor')
-rw-r--r--Userland/Applications/TextEditor/MainWidget.cpp21
-rw-r--r--Userland/Applications/TextEditor/MainWidget.h2
2 files changed, 15 insertions, 8 deletions
diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp
index 807d3ed9c9..cee46407ca 100644
--- a/Userland/Applications/TextEditor/MainWidget.cpp
+++ b/Userland/Applications/TextEditor/MainWidget.cpp
@@ -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);
diff --git a/Userland/Applications/TextEditor/MainWidget.h b/Userland/Applications/TextEditor/MainWidget.h
index bc26b57fe7..4cccac8181 100644
--- a/Userland/Applications/TextEditor/MainWidget.h
+++ b/Userland/Applications/TextEditor/MainWidget.h
@@ -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();