Explain platform clipboard external dependencies in OptionsView

This commit is contained in:
Tamás Bálint Misius 2024-01-05 11:14:14 +01:00
parent d05b0093b9
commit 608f037e68
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
8 changed files with 59 additions and 10 deletions

View File

@ -1,5 +1,6 @@
#pragma once
#include <memory>
#include <optional>
#include "common/String.h"
class GameSave;
@ -13,4 +14,5 @@ namespace Clipboard
bool GetEnabled();
void SetEnabled(bool newEnabled);
void RecreateWindow();
std::optional<String> Explanation();
}

View File

@ -62,6 +62,11 @@ namespace Clipboard
}
return gdc;
}
std::optional<String> Explanation() final override
{
return std::nullopt;
}
};
std::unique_ptr<ClipboardImpl> CocoaClipboardFactory()

View File

@ -24,7 +24,7 @@ namespace Clipboard
};
std::unique_ptr<GameSave> clipboardData;
std::unique_ptr<ClipboardImpl> clipboard;
static std::unique_ptr<ClipboardImpl> clipboard;
void InvokeClipboardSetClipboardData()
{
@ -94,7 +94,7 @@ namespace Clipboard
static bool enabled = false;
void Init()
{
enabled = GlobalPrefs::Ref().Get<bool>("NativeClipboard.Enabled", true);
enabled = GlobalPrefs::Ref().Get("NativeClipboard.Enabled", false);
}
bool GetEnabled()
@ -131,4 +131,9 @@ namespace Clipboard
}
InvokeClipboardSetClipboardData();
}
std::optional<String> Explanation()
{
return clipboard ? clipboard->Explanation() : std::nullopt;
}
}

View File

@ -3,6 +3,7 @@
#include <vector>
#include <variant>
#include <memory>
#include <optional>
class GameSave;
@ -35,6 +36,8 @@ namespace Clipboard
GetClipboardDataUnknown
>;
virtual GetClipboardDataResult GetClipboardData() = 0;
virtual std::optional<String> Explanation() = 0;
};
extern std::unique_ptr<GameSave> clipboardData;

View File

@ -18,6 +18,7 @@ namespace Clipboard
ByteString inCommand;
ByteString formatsCommand;
ByteString outCommand;
std::optional<String> explanation;
std::optional<int> defaultForSubsystem;
};
std::map<ByteString, Preset> builtInPresets = {
@ -25,12 +26,14 @@ namespace Clipboard
"xclip -selection clipboard -target %s",
"xclip -out -selection clipboard -target TARGETS",
"xclip -out -selection clipboard -target %s",
"Requires the xclip utility to be installed",
SDL_SYSWM_X11,
} },
{ "wl-clipboard", {
"wl-copy --type %s",
"wl-paste --list-types",
"wl-paste --type %s",
"Requires the wl-clipboard utility to be installed",
SDL_SYSWM_WAYLAND,
} },
};
@ -98,6 +101,7 @@ namespace Clipboard
SubstFormat(it->second.inCommand),
SubstFormat(it->second.formatsCommand),
SubstFormat(it->second.outCommand),
it->second.explanation,
};
}
@ -240,6 +244,12 @@ namespace Clipboard
}
return GetClipboardDataChanged{ std::move(*saveDataOpt) };
}
std::optional<String> Explanation() final override
{
auto preset = GetPreset();
return preset ? preset->explanation : std::nullopt;
}
};
std::unique_ptr<ClipboardImpl> ExternalClipboardFactory()

View File

@ -28,4 +28,9 @@ namespace Clipboard
void RecreateWindow()
{
}
std::optional<String> Explanation()
{
return std::nullopt;
}
}

View File

@ -217,6 +217,11 @@ namespace Clipboard
auto base = reinterpret_cast<const char *>(data.get());
return GetClipboardDataChanged{ std::vector<char>(base, base + size) };
}
std::optional<String> Explanation() final override
{
return std::nullopt;
}
};
std::unique_ptr<ClipboardImpl> WindowsClipboardFactory()

View File

@ -2,6 +2,7 @@
#include "Format.h"
#include "OptionsController.h"
#include "OptionsModel.h"
#include "common/clipboard/Clipboard.h"
#include "common/platform/Platform.h"
#include "graphics/Graphics.h"
#include "graphics/Renderer.h"
@ -59,7 +60,18 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340))
AddComponent(scrollPanel);
int currentY = 8;
auto addCheckbox = [this, &currentY, &autoWidth](int indent, String text, String info, std::function<void ()> action) {
auto addLabel = [this, &currentY, &autoWidth](int indent, String text) {
auto *label = new ui::Label(ui::Point(22 + indent * 15, currentY), ui::Point(1, 16), "");
autoWidth(label, 0);
label->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
label->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
label->SetMultiline(true);
label->SetText("\bg" + text); // stupid hack because autoWidth just changes Size.X and that doesn't update the text wrapper
label->AutoHeight();
scrollPanel->AddChild(label);
currentY += label->Size.Y - 1;
};
auto addCheckbox = [this, &currentY, &autoWidth, &addLabel](int indent, String text, String info, std::function<void ()> action) {
auto *checkbox = new ui::Checkbox(ui::Point(8 + indent * 15, currentY), ui::Point(1, 16), text, "");
autoWidth(checkbox, 0);
checkbox->SetActionCallback({ action });
@ -67,12 +79,7 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340))
currentY += 14;
if (info.size())
{
auto *label = new ui::Label(ui::Point(22 + indent * 15, currentY), ui::Point(1, 16), "\bg" + info);
autoWidth(label, 0);
label->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
label->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
scrollPanel->AddChild(label);
currentY += 14;
addLabel(indent, info);
}
currentY += 4;
return checkbox;
@ -298,9 +305,16 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340))
});
if constexpr (PLATFORM_CLIPBOARD)
{
nativeClipoard = addCheckbox(0, "Use platform clipboard", "Allows copying and pasting across TPT instances", [this] {
auto indent = 0;
nativeClipoard = addCheckbox(indent, "Use platform clipboard", "Allows copying and pasting across TPT instances", [this] {
c->SetNativeClipoard(nativeClipoard->GetChecked());
});
currentY -= 4; // temporarily undo the currentY += 4 at the end of addCheckbox
if (auto extra = Clipboard::Explanation())
{
addLabel(indent, "\bg" + *extra);
}
currentY += 4; // and then undo the undo
}
decoSpace = addDropDown("Colour space used by decoration tools", {
{ "sRGB", 0 },