mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:58:11 +00:00
PixelPaint: Make images keep track of their path & title
The title is either "Untitled" (default), or the basename of the image after we've opened or saved it.
This commit is contained in:
parent
35456f035c
commit
abc40af809
5 changed files with 45 additions and 1 deletions
|
@ -10,6 +10,7 @@
|
|||
#include <AK/JsonObject.h>
|
||||
#include <AK/JsonObjectSerializer.h>
|
||||
#include <AK/JsonValue.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/MappedFile.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibCore/File.h>
|
||||
|
@ -51,7 +52,8 @@ RefPtr<Image> 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<NonnullRefPtr<Image>, 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<NonnullRefPtr<Image>, 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue