summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2023-02-06 18:51:02 +0100
committerAndreas Kling <kling@serenityos.org>2023-02-28 14:39:32 +0100
commitd0ba5f2ed7d2fa397328638457083876338b34e3 (patch)
treefa2152da8a199b7168f5f9adbe8ccc9535aa248a
parent5f2351579623572913c7bfc5243890f718519f14 (diff)
downloadserenity-d0ba5f2ed7d2fa397328638457083876338b34e3.zip
ImageViewer: Add list of recently open files to the File menu :^)
-rw-r--r--Userland/Applications/ImageViewer/CMakeLists.txt2
-rw-r--r--Userland/Applications/ImageViewer/ViewWidget.cpp2
-rw-r--r--Userland/Applications/ImageViewer/main.cpp12
3 files changed, 15 insertions, 1 deletions
diff --git a/Userland/Applications/ImageViewer/CMakeLists.txt b/Userland/Applications/ImageViewer/CMakeLists.txt
index 6add0cf6fc..0826d53a56 100644
--- a/Userland/Applications/ImageViewer/CMakeLists.txt
+++ b/Userland/Applications/ImageViewer/CMakeLists.txt
@@ -12,4 +12,4 @@ set(SOURCES
)
serenity_app(ImageViewer ICON filetype-image)
-target_link_libraries(ImageViewer PRIVATE LibCore LibDesktop LibGUI LibGfx LibImageDecoderClient LibMain)
+target_link_libraries(ImageViewer PRIVATE LibCore LibDesktop LibGUI LibGfx LibConfig LibImageDecoderClient LibMain)
diff --git a/Userland/Applications/ImageViewer/ViewWidget.cpp b/Userland/Applications/ImageViewer/ViewWidget.cpp
index 6bdfd5d05b..0941251da4 100644
--- a/Userland/Applications/ImageViewer/ViewWidget.cpp
+++ b/Userland/Applications/ImageViewer/ViewWidget.cpp
@@ -16,6 +16,7 @@
#include <LibCore/MappedFile.h>
#include <LibCore/MimeData.h>
#include <LibCore/Timer.h>
+#include <LibGUI/Application.h>
#include <LibGUI/MessageBox.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Orientation.h>
@@ -196,6 +197,7 @@ void ViewWidget::load_from_file(DeprecatedString const& path)
}
m_path = Core::DeprecatedFile::real_path_for(path);
+ GUI::Application::the()->set_most_recently_open_file(String::from_utf8(path).release_value_but_fixme_should_propagate_errors());
reset_view();
}
diff --git a/Userland/Applications/ImageViewer/main.cpp b/Userland/Applications/ImageViewer/main.cpp
index 8970b09737..165a76a7c8 100644
--- a/Userland/Applications/ImageViewer/main.cpp
+++ b/Userland/Applications/ImageViewer/main.cpp
@@ -8,6 +8,7 @@
#include "MainWidget.h"
#include "ViewWidget.h"
#include <AK/URL.h>
+#include <LibConfig/Client.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/System.h>
#include <LibDesktop/Launcher.h>
@@ -40,6 +41,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::try_create(arguments));
+ Config::pledge_domain("ImageViewer");
+
+ app->set_config_domain(TRY(String::from_utf8("ImageViewer"sv)));
+
TRY(Desktop::Launcher::add_allowed_handler_with_any_url("/bin/ImageViewer"));
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_scheme("/usr/share/man/man1/ImageViewer.md") }));
TRY(Desktop::Launcher::seal_allowlist());
@@ -286,6 +291,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(file_menu->try_add_action(open_action));
TRY(file_menu->try_add_action(delete_action));
TRY(file_menu->try_add_separator());
+
+ TRY(file_menu->add_recent_files_list([&](auto& action) {
+ auto path = action.text();
+ widget->set_path(path);
+ widget->load_from_file(path);
+ }));
+
TRY(file_menu->try_add_action(quit_action));
auto image_menu = TRY(window->try_add_menu("&Image"));