Add 'src/be/nikiroo/utils/' from commit '46add0670fdee4bd936a13fe2448c5e20a7ffd0a'
[fanfix.git] / src / be / nikiroo / utils / resources / MetaInfo.java
index 4722be6f65c1a7328f4c30198eddccf5c5a2b2f8..f7598f190c2f9a5d491fd2b56b9644e06c104d1f 100644 (file)
@@ -141,7 +141,7 @@ public class MetaInfo<E extends Enum<E>> implements Iterable<MetaInfo<E>> {
        /**
         * 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}.
         * <p>
         * Will always allow an empty string in addition to the rest.
         * 
@@ -159,6 +159,22 @@ public class MetaInfo<E extends Enum<E>> implements Iterable<MetaInfo<E>> {
                return withEmpty;
        }
 
+       /**
+        * Return all the languages known by the program for this bundle.
+        * <p>
+        * 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<String> getKnownLanguages() {
+               if (bundle instanceof TransBundle) {
+                       return ((TransBundle<E>) bundle).getKnownLanguages();
+               }
+
+               return new ArrayList<String>();
+       }
+
        /**
         * This item is a comma-separated list of values instead of a single value.
         * <p>
@@ -461,12 +477,7 @@ public class MetaInfo<E extends Enum<E>> implements Iterable<MetaInfo<E>> {
         */
        public void setString(String value, int item) {
                if (isArray() && item >= 0) {
-                       List<String> 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 +570,8 @@ public class MetaInfo<E extends Enum<E>> implements Iterable<MetaInfo<E>> {
                        value = null;
                }
 
-               for (Runnable listener : reloadedListeners) {
+               // Copy the list so we can create new listener in a listener
+               for (Runnable listener : new ArrayList<Runnable>(reloadedListeners)) {
                        try {
                                listener.run();
                        } catch (Exception e) {
@@ -591,7 +603,8 @@ public class MetaInfo<E extends Enum<E>> implements Iterable<MetaInfo<E>> {
         *            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<Runnable>(saveListeners)) {
                        try {
                                listener.run();
                        } catch (Exception e) {