From 148f3dfc052bc6a4161073e59505bd547ab347c3 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Wed, 10 Jan 2024 23:39:19 +0100 Subject: [PATCH] prefs: Show custom layout names if provided Show the name of custom layouts in the list if it's provided using the `name` attribute. This should make managing several custom layouts easier. --- srcs/juloo.keyboard2/Config.java | 2 +- srcs/juloo.keyboard2/KeyboardData.java | 12 ++++++--- srcs/juloo.keyboard2/LayoutsPreference.java | 27 +++++++++++++++++---- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index 53360de..cb68e80 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -430,7 +430,7 @@ final class Config l.add(migrate_layout(snd_layout)); String custom_layout = prefs.getString("custom_layout", ""); if (custom_layout != null && !custom_layout.equals("")) - l.add(new LayoutsPreference.CustomLayout(custom_layout)); + l.add(LayoutsPreference.CustomLayout.parse(custom_layout)); LayoutsPreference.save_to_preferences(e, l); case 1: default: break; diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index ed5aa9a..557e42f 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -27,6 +27,8 @@ class KeyboardData public final String script; /** Might be different from [script]. Might be null. */ public final String numpad_script; + /** The [name] attribute. Might be null. */ + public final String name; /** Position of every keys on the layout, see [getKeys()]. */ private Map _key_pos = null; @@ -229,6 +231,7 @@ class KeyboardData String numpad_script = parser.getAttributeValue(null, "numpad_script"); if (numpad_script == null) numpad_script = script; + String name = parser.getAttributeValue(null, "name"); ArrayList rows = new ArrayList(); Modmap modmap = null; while (next_tag(parser)) @@ -248,7 +251,7 @@ class KeyboardData float kw = (specified_kw != 0f) ? specified_kw : compute_max_width(rows); if (add_bottom_row) rows.add(bottom_row.updateWidth(kw)); - return new KeyboardData(rows, kw, modmap, script, numpad_script); + return new KeyboardData(rows, kw, modmap, script, numpad_script, name); } private static float compute_max_width(List rows) @@ -266,7 +269,8 @@ class KeyboardData return Row.parse(parser); } - protected KeyboardData(List rows_, float kw, Modmap mm, String sc, String npsc) + protected KeyboardData(List rows_, float kw, Modmap mm, String sc, + String npsc, String name_) { float kh = 0.f; for (Row r : rows_) @@ -275,6 +279,7 @@ class KeyboardData modmap = mm; script = sc; numpad_script = npsc; + name = name_; keysWidth = kw; keysHeight = kh; } @@ -282,7 +287,8 @@ class KeyboardData /** Copies the fields of an other keyboard, with rows changed. */ protected KeyboardData(KeyboardData src, List rows) { - this(rows, compute_max_width(rows), src.modmap, src.script, src.numpad_script); + this(rows, compute_max_width(rows), src.modmap, src.script, + src.numpad_script, src.name); } public static class Row diff --git a/srcs/juloo.keyboard2/LayoutsPreference.java b/srcs/juloo.keyboard2/LayoutsPreference.java index e2bc243..d1cffcf 100644 --- a/srcs/juloo.keyboard2/LayoutsPreference.java +++ b/srcs/juloo.keyboard2/LayoutsPreference.java @@ -67,7 +67,7 @@ public class LayoutsPreference extends ListGroupPreference