mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:27:34 +00:00
PixelPaint: Move save
and save_as
logic inside ImageEditor
Previously the save logic was hardcoded to only work for the active editor, so closing editors in the background would not properly handle the unsaved changes. This patch brings us closer to be able to fix that problem.
This commit is contained in:
parent
b3e47f0bd5
commit
c2b3bab984
3 changed files with 41 additions and 30 deletions
|
@ -14,7 +14,9 @@
|
|||
#include "Tools/Tool.h"
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibFileSystemAccessClient/Client.h>
|
||||
#include <LibGUI/Command.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGfx/DisjointRectSet.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
|
@ -698,6 +700,37 @@ void ImageEditor::image_select_layer(Layer* layer)
|
|||
set_active_layer(layer);
|
||||
}
|
||||
|
||||
void ImageEditor::save_project()
|
||||
{
|
||||
if (path().is_empty()) {
|
||||
save_project_as();
|
||||
return;
|
||||
}
|
||||
auto response = FileSystemAccessClient::Client::the().request_file(window()->window_id(), path(), Core::OpenMode::Truncate | Core::OpenMode::WriteOnly);
|
||||
if (response.error != 0)
|
||||
return;
|
||||
auto result = save_project_to_fd_and_close(*response.fd);
|
||||
if (result.is_error()) {
|
||||
GUI::MessageBox::show_error(window(), String::formatted("Could not save {}: {}", *response.chosen_file, result.error()));
|
||||
return;
|
||||
}
|
||||
undo_stack().set_current_unmodified();
|
||||
}
|
||||
|
||||
void ImageEditor::save_project_as()
|
||||
{
|
||||
auto save_result = FileSystemAccessClient::Client::the().save_file(window()->window_id(), "untitled", "pp");
|
||||
if (save_result.error != 0)
|
||||
return;
|
||||
auto result = save_project_to_fd_and_close(*save_result.fd);
|
||||
if (result.is_error()) {
|
||||
GUI::MessageBox::show_error(window(), String::formatted("Could not save {}: {}", *save_result.chosen_file, result.error()));
|
||||
return;
|
||||
}
|
||||
set_path(*save_result.chosen_file);
|
||||
undo_stack().set_current_unmodified();
|
||||
}
|
||||
|
||||
Result<void, String> ImageEditor::save_project_to_fd_and_close(int fd) const
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue