TextEditor: Show "Untitled" when there's no current document path

This commit is contained in:
Andreas Kling 2020-12-30 03:44:38 +01:00
parent 7c0e43eb3d
commit 2dc09d1cd7
3 changed files with 8 additions and 3 deletions

View file

@ -540,7 +540,10 @@ void TextEditorWidget::set_path(const LexicalPath& lexical_path)
void TextEditorWidget::update_title() void TextEditorWidget::update_title()
{ {
StringBuilder builder; StringBuilder builder;
builder.append(m_path); if (m_path.is_empty())
builder.append("Untitled");
else
builder.append(m_path);
if (m_document_dirty) if (m_document_dirty)
builder.append(" (*)"); builder.append(" (*)");
builder.append(" - Text Editor"); builder.append(" - Text Editor");

View file

@ -54,10 +54,11 @@ public:
void set_preview_mode(PreviewMode); void set_preview_mode(PreviewMode);
void set_auto_detect_preview_mode(bool value) { m_auto_detect_preview_mode = value; } void set_auto_detect_preview_mode(bool value) { m_auto_detect_preview_mode = value; }
void update_title();
private: private:
TextEditorWidget(); TextEditorWidget();
void set_path(const LexicalPath& file); void set_path(const LexicalPath& file);
void update_title();
void update_preview(); void update_preview();
void update_markdown_preview(); void update_markdown_preview();
void update_html_preview(); void update_html_preview();

View file

@ -56,7 +56,6 @@ int main(int argc, char** argv)
auto app_icon = GUI::Icon::default_icon("app-text-editor"); auto app_icon = GUI::Icon::default_icon("app-text-editor");
auto window = GUI::Window::construct(); auto window = GUI::Window::construct();
window->set_title("Text Editor");
window->resize(640, 400); window->resize(640, 400);
auto& text_widget = window->set_main_widget<TextEditorWidget>(); auto& text_widget = window->set_main_widget<TextEditorWidget>();
@ -84,6 +83,8 @@ int main(int argc, char** argv)
if (file_to_edit) if (file_to_edit)
text_widget.open_sesame(file_to_edit); text_widget.open_sesame(file_to_edit);
else
text_widget.update_title();
window->show(); window->show();
window->set_icon(app_icon.bitmap_for_size(16)); window->set_icon(app_icon.bitmap_for_size(16));