Explain platform clipboard external dependencies in OptionsView
This commit is contained in:
parent
d05b0093b9
commit
608f037e68
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include "common/String.h"
|
#include "common/String.h"
|
||||||
|
|
||||||
class GameSave;
|
class GameSave;
|
||||||
@ -13,4 +14,5 @@ namespace Clipboard
|
|||||||
bool GetEnabled();
|
bool GetEnabled();
|
||||||
void SetEnabled(bool newEnabled);
|
void SetEnabled(bool newEnabled);
|
||||||
void RecreateWindow();
|
void RecreateWindow();
|
||||||
|
std::optional<String> Explanation();
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,11 @@ namespace Clipboard
|
|||||||
}
|
}
|
||||||
return gdc;
|
return gdc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<String> Explanation() final override
|
||||||
|
{
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<ClipboardImpl> CocoaClipboardFactory()
|
std::unique_ptr<ClipboardImpl> CocoaClipboardFactory()
|
||||||
|
@ -24,7 +24,7 @@ namespace Clipboard
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<GameSave> clipboardData;
|
std::unique_ptr<GameSave> clipboardData;
|
||||||
std::unique_ptr<ClipboardImpl> clipboard;
|
static std::unique_ptr<ClipboardImpl> clipboard;
|
||||||
|
|
||||||
void InvokeClipboardSetClipboardData()
|
void InvokeClipboardSetClipboardData()
|
||||||
{
|
{
|
||||||
@ -94,7 +94,7 @@ namespace Clipboard
|
|||||||
static bool enabled = false;
|
static bool enabled = false;
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
enabled = GlobalPrefs::Ref().Get<bool>("NativeClipboard.Enabled", true);
|
enabled = GlobalPrefs::Ref().Get("NativeClipboard.Enabled", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetEnabled()
|
bool GetEnabled()
|
||||||
@ -131,4 +131,9 @@ namespace Clipboard
|
|||||||
}
|
}
|
||||||
InvokeClipboardSetClipboardData();
|
InvokeClipboardSetClipboardData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<String> Explanation()
|
||||||
|
{
|
||||||
|
return clipboard ? clipboard->Explanation() : std::nullopt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
class GameSave;
|
class GameSave;
|
||||||
|
|
||||||
@ -35,6 +36,8 @@ namespace Clipboard
|
|||||||
GetClipboardDataUnknown
|
GetClipboardDataUnknown
|
||||||
>;
|
>;
|
||||||
virtual GetClipboardDataResult GetClipboardData() = 0;
|
virtual GetClipboardDataResult GetClipboardData() = 0;
|
||||||
|
|
||||||
|
virtual std::optional<String> Explanation() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::unique_ptr<GameSave> clipboardData;
|
extern std::unique_ptr<GameSave> clipboardData;
|
||||||
|
@ -18,6 +18,7 @@ namespace Clipboard
|
|||||||
ByteString inCommand;
|
ByteString inCommand;
|
||||||
ByteString formatsCommand;
|
ByteString formatsCommand;
|
||||||
ByteString outCommand;
|
ByteString outCommand;
|
||||||
|
std::optional<String> explanation;
|
||||||
std::optional<int> defaultForSubsystem;
|
std::optional<int> defaultForSubsystem;
|
||||||
};
|
};
|
||||||
std::map<ByteString, Preset> builtInPresets = {
|
std::map<ByteString, Preset> builtInPresets = {
|
||||||
@ -25,12 +26,14 @@ namespace Clipboard
|
|||||||
"xclip -selection clipboard -target %s",
|
"xclip -selection clipboard -target %s",
|
||||||
"xclip -out -selection clipboard -target TARGETS",
|
"xclip -out -selection clipboard -target TARGETS",
|
||||||
"xclip -out -selection clipboard -target %s",
|
"xclip -out -selection clipboard -target %s",
|
||||||
|
"Requires the xclip utility to be installed",
|
||||||
SDL_SYSWM_X11,
|
SDL_SYSWM_X11,
|
||||||
} },
|
} },
|
||||||
{ "wl-clipboard", {
|
{ "wl-clipboard", {
|
||||||
"wl-copy --type %s",
|
"wl-copy --type %s",
|
||||||
"wl-paste --list-types",
|
"wl-paste --list-types",
|
||||||
"wl-paste --type %s",
|
"wl-paste --type %s",
|
||||||
|
"Requires the wl-clipboard utility to be installed",
|
||||||
SDL_SYSWM_WAYLAND,
|
SDL_SYSWM_WAYLAND,
|
||||||
} },
|
} },
|
||||||
};
|
};
|
||||||
@ -98,6 +101,7 @@ namespace Clipboard
|
|||||||
SubstFormat(it->second.inCommand),
|
SubstFormat(it->second.inCommand),
|
||||||
SubstFormat(it->second.formatsCommand),
|
SubstFormat(it->second.formatsCommand),
|
||||||
SubstFormat(it->second.outCommand),
|
SubstFormat(it->second.outCommand),
|
||||||
|
it->second.explanation,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,6 +244,12 @@ namespace Clipboard
|
|||||||
}
|
}
|
||||||
return GetClipboardDataChanged{ std::move(*saveDataOpt) };
|
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()
|
std::unique_ptr<ClipboardImpl> ExternalClipboardFactory()
|
||||||
|
@ -28,4 +28,9 @@ namespace Clipboard
|
|||||||
void RecreateWindow()
|
void RecreateWindow()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<String> Explanation()
|
||||||
|
{
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,6 +217,11 @@ namespace Clipboard
|
|||||||
auto base = reinterpret_cast<const char *>(data.get());
|
auto base = reinterpret_cast<const char *>(data.get());
|
||||||
return GetClipboardDataChanged{ std::vector<char>(base, base + size) };
|
return GetClipboardDataChanged{ std::vector<char>(base, base + size) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<String> Explanation() final override
|
||||||
|
{
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<ClipboardImpl> WindowsClipboardFactory()
|
std::unique_ptr<ClipboardImpl> WindowsClipboardFactory()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "Format.h"
|
#include "Format.h"
|
||||||
#include "OptionsController.h"
|
#include "OptionsController.h"
|
||||||
#include "OptionsModel.h"
|
#include "OptionsModel.h"
|
||||||
|
#include "common/clipboard/Clipboard.h"
|
||||||
#include "common/platform/Platform.h"
|
#include "common/platform/Platform.h"
|
||||||
#include "graphics/Graphics.h"
|
#include "graphics/Graphics.h"
|
||||||
#include "graphics/Renderer.h"
|
#include "graphics/Renderer.h"
|
||||||
@ -59,7 +60,18 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340))
|
|||||||
AddComponent(scrollPanel);
|
AddComponent(scrollPanel);
|
||||||
|
|
||||||
int currentY = 8;
|
int currentY = 8;
|
||||||
auto addCheckbox = [this, ¤tY, &autoWidth](int indent, String text, String info, std::function<void ()> action) {
|
auto addLabel = [this, ¤tY, &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, ¤tY, &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, "");
|
auto *checkbox = new ui::Checkbox(ui::Point(8 + indent * 15, currentY), ui::Point(1, 16), text, "");
|
||||||
autoWidth(checkbox, 0);
|
autoWidth(checkbox, 0);
|
||||||
checkbox->SetActionCallback({ action });
|
checkbox->SetActionCallback({ action });
|
||||||
@ -67,12 +79,7 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340))
|
|||||||
currentY += 14;
|
currentY += 14;
|
||||||
if (info.size())
|
if (info.size())
|
||||||
{
|
{
|
||||||
auto *label = new ui::Label(ui::Point(22 + indent * 15, currentY), ui::Point(1, 16), "\bg" + info);
|
addLabel(indent, info);
|
||||||
autoWidth(label, 0);
|
|
||||||
label->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
|
||||||
label->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
|
||||||
scrollPanel->AddChild(label);
|
|
||||||
currentY += 14;
|
|
||||||
}
|
}
|
||||||
currentY += 4;
|
currentY += 4;
|
||||||
return checkbox;
|
return checkbox;
|
||||||
@ -298,9 +305,16 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340))
|
|||||||
});
|
});
|
||||||
if constexpr (PLATFORM_CLIPBOARD)
|
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());
|
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", {
|
decoSpace = addDropDown("Colour space used by decoration tools", {
|
||||||
{ "sRGB", 0 },
|
{ "sRGB", 0 },
|
||||||
|
Reference in New Issue
Block a user