Skip to content

Commit

Permalink
[API 7] Setting Tooltip (#65)
Browse files Browse the repository at this point in the history
* Feat: Setting Tooltip

* fix: use java 8

* Remove empty lines

* Check if empty

* use UpperCamelCase instead of Full uppercase

* Check if empty
  • Loading branch information
Pjiesco authored Oct 26, 2023
1 parent ca95a1f commit b034dd9
Show file tree
Hide file tree
Showing 5 changed files with 63 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,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

0 comments on commit b034dd9

Please sign in to comment.