diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index 014d085f1a..61e7712934 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,8 @@ RefPtr Image::try_create_with_size(Gfx::IntSize const& size) } Image::Image(Gfx::IntSize const& size) - : m_size(size) + : m_title("Untitled") + , m_size(size) { } @@ -131,6 +133,7 @@ Result, String> Image::try_create_from_pixel_paint_file(Str image->add_layer(*layer); } + image->set_path(file_path); return image.release_nonnull(); } @@ -152,6 +155,7 @@ Result, String> Image::try_create_from_file(String const& f auto image = Image::try_create_from_bitmap(bitmap.release_nonnull()); if (!image) return String { "Unable to allocate Image"sv }; + image->set_path(file_path); return image.release_nonnull(); } @@ -418,4 +422,17 @@ void ImageUndoCommand::redo() undo(); } +void Image::set_title(String title) +{ + m_title = move(title); + for (auto* client : m_clients) + client->image_did_change_title(m_title); +} + +void Image::set_path(String path) +{ + m_path = move(path); + set_title(LexicalPath(m_path).basename()); +} + } diff --git a/Userland/Applications/PixelPaint/Image.h b/Userland/Applications/PixelPaint/Image.h index 2bcf87be7f..a5474a6958 100644 --- a/Userland/Applications/PixelPaint/Image.h +++ b/Userland/Applications/PixelPaint/Image.h @@ -30,6 +30,7 @@ public: virtual void image_did_modify_layer_stack() { } virtual void image_did_change() { } virtual void image_select_layer(Layer*) { } + virtual void image_did_change_title(String const&) { } protected: virtual ~ImageClient() = default; @@ -76,6 +77,12 @@ public: size_t index_of(Layer const&) const; + String const& path() const { return m_path; } + void set_path(String); + + String const& title() const { return m_title; } + void set_title(String); + private: explicit Image(Gfx::IntSize const&); @@ -84,6 +91,9 @@ private: void did_change(); void did_modify_layer_stack(); + String m_path; + String m_title; + Gfx::IntSize m_size; NonnullRefPtrVector m_layers; diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index 2aeaa1bfb5..33e8705c07 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -395,6 +395,12 @@ void ImageEditor::image_did_change() update(); } +void ImageEditor::image_did_change_title(String const& path) +{ + if (on_image_title_change) + on_image_title_change(path); +} + void ImageEditor::image_select_layer(Layer* layer) { set_active_layer(layer); diff --git a/Userland/Applications/PixelPaint/ImageEditor.h b/Userland/Applications/PixelPaint/ImageEditor.h index 69cd1b6d64..8b25b71758 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.h +++ b/Userland/Applications/PixelPaint/ImageEditor.h @@ -63,6 +63,8 @@ public: Function on_active_layer_change; + Function on_image_title_change; + Gfx::FloatRect layer_rect_to_editor_rect(Layer const&, Gfx::IntRect const&) const; Gfx::FloatRect image_rect_to_editor_rect(Gfx::IntRect const&) const; Gfx::FloatRect editor_rect_to_image_rect(Gfx::IntRect const&) const; @@ -86,6 +88,7 @@ private: virtual void image_did_change() override; virtual void image_select_layer(Layer*) override; + virtual void image_did_change_title(String const&) override; GUI::MouseEvent event_adjusted_for_layer(GUI::MouseEvent const&, Layer const&) const; GUI::MouseEvent event_with_pan_and_scale_applied(GUI::MouseEvent const&) const; diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp index a19fd34247..dbaf550ff5 100644 --- a/Userland/Applications/PixelPaint/main.cpp +++ b/Userland/Applications/PixelPaint/main.cpp @@ -135,6 +135,7 @@ int main(int argc, char** argv) GUI::MessageBox::show_error(window, String::formatted("Could not save {}: {}", save_path.value(), result.error())); return; } + editor->image().set_path(save_path.value()); }); auto menubar = GUI::Menubar::construct(); @@ -506,6 +507,13 @@ int main(int argc, char** argv) layer_properties_widget.set_layer(layer); }; + image_editor.on_image_title_change = [&](auto const& title) { + tab_widget.set_tab_title(image_editor, title); + }; + + // NOTE: We invoke the above hook directly here to make sure the tab title is set up. + image_editor.on_image_title_change(image->title()); + if (image->layer_count()) image_editor.set_active_layer(&image->layer(0));