Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API 7] Setting Tooltip #65

Merged
merged 6 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,17 @@
* @return boolean isReadOnly
*/
boolean isReadOnly() default false;

/**
* Setting Tooltip
*
* @return {@link Tooltip} tooltip
*/
Tooltip tooltip() default @Tooltip(body = "");

@interface Tooltip {
String title() default "";
String body();
String docUrl() default "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ public static Pair<JsonObject, TypeSpec.Builder> process(TouchPortalPluginAnnota
jsonSetting.addProperty(SettingHelper.TYPE, desiredTPType);
jsonSetting.addProperty(SettingHelper.DEFAULT, setting.defaultValue());
jsonSetting.addProperty(SettingHelper.IS_READ_ONLY, setting.isReadOnly());

if (!setting.tooltip().body().isEmpty()) {
JsonObject tooltip = new JsonObject();

tooltip.addProperty(SettingHelper.Tooltip.BODY, setting.tooltip().body());

if (!setting.tooltip().title().isEmpty()) {
tooltip.addProperty(SettingHelper.Tooltip.TITLE, setting.tooltip().title());
}
if (!setting.tooltip().docUrl().isEmpty()) {
tooltip.addProperty(SettingHelper.Tooltip.DOC_URL, setting.tooltip().docUrl());
}

jsonSetting.add(SettingHelper.TOOLTIP, tooltip);
}

switch (desiredTPType) {
case SettingHelper.TYPE_TEXT:
if (setting.maxLength() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,31 @@ public static TypeSpec.Builder createSettingTypeSpecBuilder(Element settingEleme
stateTypeSpecBuilder.addField(SpecUtils.getStaticFinalDoubleFieldSpec("max_value", setting.maxValue()));
}

if (!setting.tooltip().body().isEmpty()) {
stateTypeSpecBuilder.addType(createSettingTooltipTypeSpecBuilder(setting.tooltip()).build());
}

return stateTypeSpecBuilder;
}

/**
* Generates a TypeSpec.Builder with Constants for the {@link Setting.Tooltip}
*
* @param tooltip {@link Setting.Tooltip}
* @return TypeSpec.Builder tooltipTypeSpecBuilder
*/
public static TypeSpec.Builder createSettingTooltipTypeSpecBuilder(Setting.Tooltip tooltip) {
TypeSpec.Builder tooltipTypeSpecBuilder = TypeSpec.classBuilder("Tooltip").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("body", tooltip.body()));
if (!tooltip.title().isEmpty()) {
tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("title", tooltip.title()));
}
if (!tooltip.title().isEmpty()) {
tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("docUrl", tooltip.docUrl()));
}
return tooltipTypeSpecBuilder;
}

/**
* Generates a TypeSpec.Builder with Constants for the {@link State}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public class SettingHelper {
public static final String MIN_VALUE = "minValue";
public static final String MAX_VALUE = "maxValue";
public static final String IS_READ_ONLY = "readOnly";
public static final String TOOLTIP = "tooltip";

public static class Tooltip {
public static final String TITLE = "title";
public static final String BODY = "body";
public static final String DOC_URL = "docUrl";
}

/**
* Get the generated Setting Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import java.io.File;
import java.util.HashMap;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -80,7 +79,11 @@ private enum Categories {
/**
* Setting of type text definition example
*/
@Setting(name = "IP", defaultValue = "localhost", maxLength = 15)
@Setting(name = "IP", defaultValue = "localhost", maxLength = 15, tooltip = @Setting.Tooltip(
title = "IP address",
body = "ip address to connect to",
docUrl = "https://example.com"
))
private String ipSetting;

/**
Expand Down