From eb5320023ad6d4746dd6abfa191ea2e016719077 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Mon, 6 Sep 2021 21:07:41 +0200 Subject: HackStudio: Preserve the untitled filename text on file modification Previously, the title of an unnamed file would just disappear from the editor label if you started typing. --- Userland/DevTools/HackStudio/EditorWrapper.cpp | 7 +++++-- Userland/DevTools/HackStudio/EditorWrapper.h | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Userland/DevTools') diff --git a/Userland/DevTools/HackStudio/EditorWrapper.cpp b/Userland/DevTools/HackStudio/EditorWrapper.cpp index 2fb43b84a3..9a1b2414d3 100644 --- a/Userland/DevTools/HackStudio/EditorWrapper.cpp +++ b/Userland/DevTools/HackStudio/EditorWrapper.cpp @@ -26,7 +26,7 @@ EditorWrapper::EditorWrapper() label_wrapper.set_layout(); label_wrapper.layout()->set_margins({ 0, 2 }); - m_filename_label = label_wrapper.add("(Untitled)"); + m_filename_label = label_wrapper.add(untitled_label); m_filename_label->set_text_alignment(Gfx::TextAlignment::CenterLeft); m_filename_label->set_fixed_height(14); @@ -123,7 +123,10 @@ void EditorWrapper::set_project_root(LexicalPath const& project_root) void EditorWrapper::update_title() { StringBuilder title; - title.append(m_filename); + if (m_filename.is_null()) + title.append(untitled_label); + else + title.append(m_filename); if (m_document_dirty) title.append(" (*)"); diff --git a/Userland/DevTools/HackStudio/EditorWrapper.h b/Userland/DevTools/HackStudio/EditorWrapper.h index d4c422ac51..755fcd5cd3 100644 --- a/Userland/DevTools/HackStudio/EditorWrapper.h +++ b/Userland/DevTools/HackStudio/EditorWrapper.h @@ -55,6 +55,8 @@ public: Function on_change; private: + static constexpr auto untitled_label = "(Untitled)"; + EditorWrapper(); void update_title(); -- cgit v1.2.3