From 2dc09d1cd7ee24a52902dd44359c593e1b61c133 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 30 Dec 2020 03:44:38 +0100 Subject: [PATCH] TextEditor: Show "Untitled" when there's no current document path --- Applications/TextEditor/TextEditorWidget.cpp | 5 ++++- Applications/TextEditor/TextEditorWidget.h | 3 ++- Applications/TextEditor/main.cpp | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp index 65f40b325f2..53d1ae80bbf 100644 --- a/Applications/TextEditor/TextEditorWidget.cpp +++ b/Applications/TextEditor/TextEditorWidget.cpp @@ -540,7 +540,10 @@ void TextEditorWidget::set_path(const LexicalPath& lexical_path) void TextEditorWidget::update_title() { StringBuilder builder; - builder.append(m_path); + if (m_path.is_empty()) + builder.append("Untitled"); + else + builder.append(m_path); if (m_document_dirty) builder.append(" (*)"); builder.append(" - Text Editor"); diff --git a/Applications/TextEditor/TextEditorWidget.h b/Applications/TextEditor/TextEditorWidget.h index 5b78e84c3c6..3320096f509 100644 --- a/Applications/TextEditor/TextEditorWidget.h +++ b/Applications/TextEditor/TextEditorWidget.h @@ -54,10 +54,11 @@ public: void set_preview_mode(PreviewMode); void set_auto_detect_preview_mode(bool value) { m_auto_detect_preview_mode = value; } + void update_title(); + private: TextEditorWidget(); void set_path(const LexicalPath& file); - void update_title(); void update_preview(); void update_markdown_preview(); void update_html_preview(); diff --git a/Applications/TextEditor/main.cpp b/Applications/TextEditor/main.cpp index 53dd964abdb..8e9c8fdfb8e 100644 --- a/Applications/TextEditor/main.cpp +++ b/Applications/TextEditor/main.cpp @@ -56,7 +56,6 @@ int main(int argc, char** argv) auto app_icon = GUI::Icon::default_icon("app-text-editor"); auto window = GUI::Window::construct(); - window->set_title("Text Editor"); window->resize(640, 400); auto& text_widget = window->set_main_widget(); @@ -84,6 +83,8 @@ int main(int argc, char** argv) if (file_to_edit) text_widget.open_sesame(file_to_edit); + else + text_widget.update_title(); window->show(); window->set_icon(app_icon.bitmap_for_size(16));