Skip to content

Commit

Permalink
Feat: Setting Tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
Pjiesco committed Oct 6, 2023
1 parent 1964ce0 commit 06065cc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
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,17 @@ 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().isBlank()) {
JsonObject tooltip = new JsonObject();

tooltip.addProperty(SettingHelper.Tooltip.TITLE, setting.tooltip().title());
tooltip.addProperty(SettingHelper.Tooltip.BODY, setting.tooltip().body());
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 Expand Up @@ -66,6 +77,8 @@ public static Pair<JsonObject, TypeSpec.Builder> process(TouchPortalPluginAnnota
throw new GenericHelper.TPTypeException.Builder(className).typeUnsupported(desiredTPType).forAnnotation(GenericHelper.TPTypeException.ForAnnotation.SETTING).build();
}



return Pair.create(jsonSetting, settingTypeSpecBuilder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,28 @@ public static TypeSpec.Builder createSettingTypeSpecBuilder(Element settingEleme
stateTypeSpecBuilder.addField(SpecUtils.getStaticFinalDoubleFieldSpec("max_value", setting.maxValue()));
}

if (!setting.tooltip().body().isBlank()) {
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("title", tooltip.title()));
tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("body", tooltip.body()));
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

0 comments on commit 06065cc

Please sign in to comment.