소스 검색

LibCards: Add a helper to create an action to open Cards Settings

This is a useful shortcut to open the settings from within the game
rather than having to go through the system menu.
Timothy Flynn 2 년 전
부모
커밋
33fd2c1af9
2개의 변경된 파일18개의 추가작업 그리고 0개의 파일을 삭제
  1. 14 0
      Userland/Libraries/LibCards/CardGame.cpp
  2. 4 0
      Userland/Libraries/LibCards/CardGame.h

+ 14 - 0
Userland/Libraries/LibCards/CardGame.cpp

@@ -9,10 +9,24 @@
 #include "CardGame.h"
 #include <LibCards/CardPainter.h>
 #include <LibConfig/Client.h>
+#include <LibGUI/Action.h>
+#include <LibGUI/Process.h>
+#include <LibGUI/Window.h>
 #include <LibGfx/Palette.h>
 
 namespace Cards {
 
+ErrorOr<NonnullRefPtr<GUI::Action>> make_cards_settings_action(GUI::Window* parent)
+{
+    auto action = GUI::Action::create(
+        "&Cards Settings", {}, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/games.png"sv)), [parent](auto&) {
+            GUI::Process::spawn_or_show_error(parent, "/bin/GamesSettings"sv, Array { "--open-tab", "cards" });
+        },
+        parent);
+    action->set_status_tip("Open the Game Settings for Cards");
+    return action;
+}
+
 CardGame::CardGame()
 {
     auto background_color = Gfx::Color::from_string(Config::read_string("Games"sv, "Cards"sv, "BackgroundColor"sv));

+ 4 - 0
Userland/Libraries/LibCards/CardGame.h

@@ -6,12 +6,16 @@
 
 #pragma once
 
+#include <AK/Error.h>
 #include <LibCards/CardStack.h>
 #include <LibConfig/Listener.h>
+#include <LibGUI/Forward.h>
 #include <LibGUI/Frame.h>
 
 namespace Cards {
 
+ErrorOr<NonnullRefPtr<GUI::Action>> make_cards_settings_action(GUI::Window* parent = nullptr);
+
 class CardGame
     : public GUI::Frame
     , public Config::Listener {