X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fresources%2FMetaInfo.java;h=70c6c43181bbff8f8885c1eca15a792eef03eac1;hb=601003e69e1dc81774243c6eadf7982b6b563b33;hp=4722be6f65c1a7328f4c30198eddccf5c5a2b2f8;hpb=74d2a495c7b5c5d66a03dd7f94b58f93849008fb;p=fanfix.git diff --git a/src/be/nikiroo/utils/resources/MetaInfo.java b/src/be/nikiroo/utils/resources/MetaInfo.java index 4722be6..70c6c43 100644 --- a/src/be/nikiroo/utils/resources/MetaInfo.java +++ b/src/be/nikiroo/utils/resources/MetaInfo.java @@ -27,6 +27,7 @@ public class MetaInfo> implements Iterable> { private List saveListeners = new ArrayList(); private String name; + private boolean hidden; private String description; private boolean dirty; @@ -90,6 +91,7 @@ public class MetaInfo> implements Iterable> { } this.name = name; + this.hidden = meta.hidden(); this.description = description; reload(); @@ -110,6 +112,16 @@ public class MetaInfo> implements Iterable> { public String getName() { return name; } + + /** + * This item should be hidden from the user (she will still be able to + * modify it if she opens the file manually). + * + * @return TRUE if it should stay hidden + */ + public boolean isHidden() { + return hidden; + } /** * A description for this item: what it is or does, how to explain that item @@ -141,7 +153,7 @@ public class MetaInfo> implements Iterable> { /** * The allowed list of values that a {@link Format#FIXED_LIST} item is * allowed to be, or a list of suggestions for {@link Format#COMBO_LIST} - * items. + * items. Also works for {@link Format#LOCALE}. *

* Will always allow an empty string in addition to the rest. * @@ -159,6 +171,22 @@ public class MetaInfo> implements Iterable> { return withEmpty; } + /** + * Return all the languages known by the program for this bundle. + *

+ * This only works for {@link TransBundle}, and will return an empty list if + * this is not a {@link TransBundle}. + * + * @return the known language codes + */ + public List getKnownLanguages() { + if (bundle instanceof TransBundle) { + return ((TransBundle) bundle).getKnownLanguages(); + } + + return new ArrayList(); + } + /** * This item is a comma-separated list of values instead of a single value. *

@@ -461,12 +489,7 @@ public class MetaInfo> implements Iterable> { */ public void setString(String value, int item) { if (isArray() && item >= 0) { - List values = BundleHelper.parseList(this.value, -1); - for (int i = values.size(); i <= item; i++) { - values.add(null); - } - values.set(item, value); - this.value = BundleHelper.fromList(values); + this.value = BundleHelper.fromList(this.value, value, item); } else { this.value = value; } @@ -559,7 +582,8 @@ public class MetaInfo> implements Iterable> { value = null; } - for (Runnable listener : reloadedListeners) { + // Copy the list so we can create new listener in a listener + for (Runnable listener : new ArrayList(reloadedListeners)) { try { listener.run(); } catch (Exception e) { @@ -591,7 +615,8 @@ public class MetaInfo> implements Iterable> { * dirty flag) */ public void save(boolean onlyIfDirty) { - for (Runnable listener : saveListeners) { + // Copy the list so we can create new listener in a listener + for (Runnable listener : new ArrayList(saveListeners)) { try { listener.run(); } catch (Exception e) { @@ -636,6 +661,15 @@ public class MetaInfo> implements Iterable> { return children; } + /** + * The number of sub-items, if any. + * + * @return the number or 0 + */ + public int size() { + return children.size(); + } + @Override public Iterator> iterator() { return children.iterator(); @@ -660,8 +694,10 @@ public class MetaInfo> implements Iterable> { List> shadow = new ArrayList>(); for (E id : type.getEnumConstants()) { MetaInfo info = new MetaInfo(type, bundle, id); - list.add(info); - shadow.add(info); + if (!info.hidden) { + list.add(info); + shadow.add(info); + } } for (int i = 0; i < list.size(); i++) {