[longomatch] Make sure the field we add has a unique name.



commit 89c01ee11bb0d056b9cbf5c27aee6ef9f3ab2ca2
Author: Julien Moutte <julien fluendo com>
Date:   Wed Mar 18 18:36:37 2015 +0100

    Make sure the field we add has a unique name.

 .../Gui/Component/MediaFileSetSelection.cs         |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/LongoMatch.GUI/Gui/Component/MediaFileSetSelection.cs 
b/LongoMatch.GUI/Gui/Component/MediaFileSetSelection.cs
index e771e59..4e4345b 100644
--- a/LongoMatch.GUI/Gui/Component/MediaFileSetSelection.cs
+++ b/LongoMatch.GUI/Gui/Component/MediaFileSetSelection.cs
@@ -16,6 +16,7 @@
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
 using System;
+using System.Linq;
 using System.Collections.Generic;
 using Mono.Unix;
 using LongoMatch.Core.Store;
@@ -59,8 +60,25 @@ namespace LongoMatch.Gui.Component
                        }
                }
 
+               /// <summary>
+               /// Add a media file chooser with given name. If name is null pick a name automatically 
avoiding duplicates.
+               /// </summary>
+               /// <param name="name">Name.</param>
                void AddMediaFileChooser (String name)
                {
+                       if (name == null) {
+                               int i = fileChoosers.Count;
+
+                               if (i == 0) {
+                                       name = Catalog.GetString ("Main camera angle");
+                               } else {
+                                       name = String.Format ("{0} {1}", Catalog.GetString ("Angle"), i);
+                                       while (fileChoosers.Any (c => c.MediaFile.Name == name)) {
+                                               name = String.Format ("{0} {1}", Catalog.GetString ("Angle"), 
++i);
+                                       }
+                               }
+                       }
+
                        MediaFileChooser chooser = new MediaFileChooser (name);
 
                        chooser.ChangedEvent += HandleFileChangedEvent;
@@ -114,7 +132,7 @@ namespace LongoMatch.Gui.Component
                        to_remove.Clear ();
 
                        if (!have_empty_chooser) {
-                               AddMediaFileChooser (String.Format ("{0} {1}", Catalog.GetString ("Angle"), 
fileChoosers.Count));
+                               AddMediaFileChooser (null);
                        }
                }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]