[longomatch] Add dialog to choose an importer when several are available



commit 02e36285685d3cb59df51a1ffa6701961bdea416
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed Nov 26 16:34:35 2014 +0100

    Add dialog to choose an importer when several are available

 LongoMatch.Addins/AddinsManager.cs                 |    4 +-
 .../ExtensionPoints/IImportProject.cs              |    2 +
 LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs      |    4 +
 LongoMatch.Core/Interfaces/IProjectsImporter.cs    |    5 +-
 LongoMatch.GUI/Gui/Dialog/ChooseOptionDialog.cs    |   55 +++++++
 LongoMatch.GUI/Gui/Dialog/ChooseProjectDialog.cs   |   48 ++++++
 LongoMatch.GUI/Gui/GUIToolkit.cs                   |   32 ++++-
 LongoMatch.GUI/LongoMatch.GUI.csproj               |    4 +
 LongoMatch.GUI/Makefile.am                         |    4 +
 .../LongoMatch.Gui.Dialog.ChooseOptionDialog.cs    |   80 ++++++++++
 .../LongoMatch.Gui.Dialog.ChooseProjectDialog.cs   |   72 +++++++++
 LongoMatch.GUI/gtk-gui/gui.stetic                  |  159 +++++++++++++++++++-
 LongoMatch.Services/Services/ToolsManager.cs       |   47 +++++--
 13 files changed, 500 insertions(+), 16 deletions(-)
---
diff --git a/LongoMatch.Addins/AddinsManager.cs b/LongoMatch.Addins/AddinsManager.cs
index 1970d05..9568dcb 100644
--- a/LongoMatch.Addins/AddinsManager.cs
+++ b/LongoMatch.Addins/AddinsManager.cs
@@ -107,9 +107,11 @@ namespace LongoMatch.Addins
                        foreach (IImportProject importProject in 
AddinManager.GetExtensionObjects<IImportProject> ()) {
                                Log.Information ("Adding import entry from plugin: " + importProject.Name);
                                importer.RegisterImporter (new Func<string, Project> 
(importProject.ImportProject),
+                                                          importProject.Description,
                                                           importProject.FilterName,
                                                           importProject.FilterExtensions,
-                                                          importProject.NeedsEdition);
+                                                          importProject.NeedsEdition,
+                                                          importProject.CanOverwrite);
                        }
                }
 
diff --git a/LongoMatch.Addins/ExtensionPoints/IImportProject.cs 
b/LongoMatch.Addins/ExtensionPoints/IImportProject.cs
index 9e9a6a3..83eb6ff 100644
--- a/LongoMatch.Addins/ExtensionPoints/IImportProject.cs
+++ b/LongoMatch.Addins/ExtensionPoints/IImportProject.cs
@@ -29,6 +29,8 @@ namespace LongoMatch.Addins.ExtensionPoints
 
                bool NeedsEdition { get; }
 
+               bool CanOverwrite { get; }
+
                Project ImportProject (string filename);
        }
 }
diff --git a/LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs b/LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs
index 9c4b76d..71a39e6 100644
--- a/LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs
+++ b/LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs
@@ -55,6 +55,8 @@ namespace LongoMatch.Core.Interfaces.GUI
                string SelectFolder(string title, string defaultName, string defaultFolder,
                        string filterName, string[] extensionFilter);
                        
+               object ChooseOption (Dictionary<string, object> options, object parent=null);
+
                IBusyDialog BusyDialog(string message, object parent=null);
                        
                List<EditionJob> ConfigureRenderingJob (Playlist playlist);
@@ -66,6 +68,8 @@ namespace LongoMatch.Core.Interfaces.GUI
                void CloseProject ();
                                             
                void SelectProject(List<ProjectDescription> projects);
+
+               ProjectDescription ChooseProject(List<ProjectDescription> projects);
                
                void CreateNewProject (Project project=null);
                
diff --git a/LongoMatch.Core/Interfaces/IProjectsImporter.cs b/LongoMatch.Core/Interfaces/IProjectsImporter.cs
index 0f9d7bc..a07e13f 100644
--- a/LongoMatch.Core/Interfaces/IProjectsImporter.cs
+++ b/LongoMatch.Core/Interfaces/IProjectsImporter.cs
@@ -23,8 +23,9 @@ namespace LongoMatch.Core.Interfaces
        public interface IProjectsImporter
        {
                void RegisterImporter (Func<string, Project> ImportFunction,
-                                      string filterName, string[] extensions,
-                                      bool needsEdition);
+                                      string description, string filterName,
+                                      string[] extensions, bool needsEdition,
+                                      bool canOverwrite);
        }
 }
 
diff --git a/LongoMatch.GUI/Gui/Dialog/ChooseOptionDialog.cs b/LongoMatch.GUI/Gui/Dialog/ChooseOptionDialog.cs
new file mode 100644
index 0000000..9310a1b
--- /dev/null
+++ b/LongoMatch.GUI/Gui/Dialog/ChooseOptionDialog.cs
@@ -0,0 +1,55 @@
+//
+//  Copyright (C) 2014 Andoni Morales Alastruey
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Gtk;
+
+namespace LongoMatch.Gui.Dialog
+{
+       public partial class ChooseOptionDialog : Gtk.Dialog
+       {
+               public ChooseOptionDialog ()
+               {
+                       this.Build ();
+               }
+
+               public Dictionary<string, object> Options {
+                       set {
+                               RadioButton first = null;
+                               SelectedOption = value.Values.FirstOrDefault ();
+                               foreach (string desc in value.Keys) {
+                                       first = new RadioButton (first, desc);
+                                       first.Toggled += (sender, e) => {
+                                               if ((sender as RadioButton).Active) {
+                                                       SelectedOption = value[desc];
+                                               }
+                                       };
+                                       first.ShowAll ();
+                                       optionsbox.PackStart (first, false, true, 0);
+                               }
+                       }
+               }
+               
+               public object SelectedOption {
+                       get;
+                       protected set;
+               }
+       }
+}
+
diff --git a/LongoMatch.GUI/Gui/Dialog/ChooseProjectDialog.cs 
b/LongoMatch.GUI/Gui/Dialog/ChooseProjectDialog.cs
new file mode 100644
index 0000000..2dca673
--- /dev/null
+++ b/LongoMatch.GUI/Gui/Dialog/ChooseProjectDialog.cs
@@ -0,0 +1,48 @@
+//
+//  Copyright (C) 2014 Andoni Morales Alastruey
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.Collections.Generic;
+using LongoMatch.Core.Store;
+
+namespace LongoMatch.Gui.Dialog
+{
+       public partial class ChooseProjectDialog : Gtk.Dialog
+       {
+               public ChooseProjectDialog ()
+               {
+                       this.Build ();
+                       projectlistwidget1.ShowList = false;
+                       projectlistwidget1.SelectionMode = Gtk.SelectionMode.Single;
+                       projectlistwidget1.ProjectsSelected += (projects) => {
+                               if (projects != null && projects.Count == 1) {
+                                       Project = projects[0];
+                               }
+                       };
+               }
+
+               public void Fill (List<ProjectDescription> projects) {
+                       projectlistwidget1.Fill (Config.DatabaseManager.ActiveDB.GetAllProjects ());
+               }
+               
+               public ProjectDescription Project {
+                       get;
+                       set;
+               }
+       }
+}
+
diff --git a/LongoMatch.GUI/Gui/GUIToolkit.cs b/LongoMatch.GUI/Gui/GUIToolkit.cs
index 939d260..10ca6db 100644
--- a/LongoMatch.GUI/Gui/GUIToolkit.cs
+++ b/LongoMatch.GUI/Gui/GUIToolkit.cs
@@ -140,7 +140,24 @@ namespace LongoMatch.Gui
                        return FileChooserHelper.OpenFiles (mainWindow as Widget, title, defaultName,
                                                            defaultFolder, filterName, extensionFilter);
                }
-               
+
+               public object ChooseOption (Dictionary<string, object> options, object parent=null)
+               {
+                       object res = null;
+                       ChooseOptionDialog dialog = new ChooseOptionDialog ();
+                       dialog.Options = options;
+                       if (parent != null) {
+                               dialog.TransientFor = (parent as Widget).Toplevel as Gtk.Window;
+                       } else {
+                               dialog.TransientFor = mainWindow as Gtk.Window;
+                       }
+                       if (dialog.Run () == (int)ResponseType.Ok) {
+                               res = dialog.SelectedOption;
+                       }
+                       dialog.Destroy ();
+                       return res;
+               }
+
                public List<EditionJob> ConfigureRenderingJob (Playlist playlist)
                {
                        VideoEditionProperties vep;
@@ -257,6 +274,19 @@ namespace LongoMatch.Gui
                        dialog.Destroy();       
                }
                
+               public ProjectDescription ChooseProject (List<ProjectDescription> projects)
+               {
+                       Log.Information ("Choosing project");
+                       ProjectDescription pd = null;
+                       ChooseProjectDialog dialog = new ChooseProjectDialog ();
+                       dialog.Fill (projects);
+                       if (dialog.Run () == (int)ResponseType.Ok) {
+                               pd = dialog.Project;
+                       }
+                       dialog.Destroy ();
+                       return pd;
+               }
+               
                public void SelectProject(List<ProjectDescription> projects) {
                        Log.Information ("Select project");
                        mainWindow.SelectProject (projects);
diff --git a/LongoMatch.GUI/LongoMatch.GUI.csproj b/LongoMatch.GUI/LongoMatch.GUI.csproj
index e8d8b4a..e81e6eb 100644
--- a/LongoMatch.GUI/LongoMatch.GUI.csproj
+++ b/LongoMatch.GUI/LongoMatch.GUI.csproj
@@ -178,6 +178,10 @@
     <Compile Include="gtk-gui\LongoMatch.Gui.Component.GameDescriptionHeader.cs" />
     <Compile Include="Gui\Component\VideoFileInfo.cs" />
     <Compile Include="gtk-gui\LongoMatch.Gui.Component.VideoFileInfo.cs" />
+    <Compile Include="Gui\Dialog\ChooseProjectDialog.cs" />
+    <Compile Include="gtk-gui\LongoMatch.Gui.Dialog.ChooseProjectDialog.cs" />
+    <Compile Include="Gui\Dialog\ChooseOptionDialog.cs" />
+    <Compile Include="gtk-gui\LongoMatch.Gui.Dialog.ChooseOptionDialog.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="gtk-gui\gui.stetic">
diff --git a/LongoMatch.GUI/Makefile.am b/LongoMatch.GUI/Makefile.am
index f951205..ec32ccb 100644
--- a/LongoMatch.GUI/Makefile.am
+++ b/LongoMatch.GUI/Makefile.am
@@ -38,6 +38,8 @@ SOURCES = Gui/Cairo.cs \
        Gui/Dialog/About.cs \
        Gui/Dialog/BusyDialog.cs \
        Gui/Dialog/CalendarDialog.cs \
+       Gui/Dialog/ChooseOptionDialog.cs \
+       Gui/Dialog/ChooseProjectDialog.cs \
        Gui/Dialog/CodecsChoiceDialog.cs \
        Gui/Dialog/DatabasesManager.cs \
        Gui/Dialog/DrawingTool.cs \
@@ -108,6 +110,8 @@ SOURCES = Gui/Cairo.cs \
        gtk-gui/LongoMatch.Gui.Component.VideoPreferencesPanel.cs \
        gtk-gui/LongoMatch.Gui.Dialog.BusyDialog.cs \
        gtk-gui/LongoMatch.Gui.Dialog.CalendarDialog.cs \
+       gtk-gui/LongoMatch.Gui.Dialog.ChooseOptionDialog.cs \
+       gtk-gui/LongoMatch.Gui.Dialog.ChooseProjectDialog.cs \
        gtk-gui/LongoMatch.Gui.Dialog.CodecsChoiceDialog.cs \
        gtk-gui/LongoMatch.Gui.Dialog.DatabasesManager.cs \
        gtk-gui/LongoMatch.Gui.Dialog.DrawingTool.cs \
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.ChooseOptionDialog.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.ChooseOptionDialog.cs
new file mode 100644
index 0000000..ad0b97a
--- /dev/null
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.ChooseOptionDialog.cs
@@ -0,0 +1,80 @@
+
+// This file has been generated by the GUI designer. Do not modify.
+namespace LongoMatch.Gui.Dialog
+{
+       public partial class ChooseOptionDialog
+       {
+               private global::Gtk.Alignment alignment1;
+               private global::Gtk.VBox optionsbox;
+               private global::Gtk.Button buttonCancel;
+               private global::Gtk.Button buttonOk;
+
+               protected virtual void Build ()
+               {
+                       global::Stetic.Gui.Initialize (this);
+                       // Widget LongoMatch.Gui.Dialog.ChooseOptionDialog
+                       this.Name = "LongoMatch.Gui.Dialog.ChooseOptionDialog";
+                       this.Title = "";
+                       this.Icon = global::Stetic.IconLoader.LoadIcon (this, "longomatch", 
global::Gtk.IconSize.Menu);
+                       this.TypeHint = ((global::Gdk.WindowTypeHint)(1));
+                       this.WindowPosition = ((global::Gtk.WindowPosition)(4));
+                       this.Modal = true;
+                       this.DestroyWithParent = true;
+                       this.Gravity = ((global::Gdk.Gravity)(5));
+                       this.SkipPagerHint = true;
+                       this.SkipTaskbarHint = true;
+                       // Internal child LongoMatch.Gui.Dialog.ChooseOptionDialog.VBox
+                       global::Gtk.VBox w1 = this.VBox;
+                       w1.Name = "dialog1_VBox";
+                       w1.BorderWidth = ((uint)(2));
+                       // Container child dialog1_VBox.Gtk.Box+BoxChild
+                       this.alignment1 = new global::Gtk.Alignment (0.5F, 0.5F, 0F, 0F);
+                       this.alignment1.Name = "alignment1";
+                       // Container child alignment1.Gtk.Container+ContainerChild
+                       this.optionsbox = new global::Gtk.VBox ();
+                       this.optionsbox.Name = "optionsbox";
+                       this.optionsbox.Spacing = 6;
+                       this.alignment1.Add (this.optionsbox);
+                       w1.Add (this.alignment1);
+                       global::Gtk.Box.BoxChild w3 = ((global::Gtk.Box.BoxChild)(w1 [this.alignment1]));
+                       w3.Position = 0;
+                       // Internal child LongoMatch.Gui.Dialog.ChooseOptionDialog.ActionArea
+                       global::Gtk.HButtonBox w4 = this.ActionArea;
+                       w4.Name = "dialog1_ActionArea";
+                       w4.Spacing = 10;
+                       w4.BorderWidth = ((uint)(5));
+                       w4.LayoutStyle = ((global::Gtk.ButtonBoxStyle)(4));
+                       // Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild
+                       this.buttonCancel = new global::Gtk.Button ();
+                       this.buttonCancel.CanDefault = true;
+                       this.buttonCancel.CanFocus = true;
+                       this.buttonCancel.Name = "buttonCancel";
+                       this.buttonCancel.UseStock = true;
+                       this.buttonCancel.UseUnderline = true;
+                       this.buttonCancel.Label = "gtk-cancel";
+                       this.AddActionWidget (this.buttonCancel, -6);
+                       global::Gtk.ButtonBox.ButtonBoxChild w5 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w4 
[this.buttonCancel]));
+                       w5.Expand = false;
+                       w5.Fill = false;
+                       // Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild
+                       this.buttonOk = new global::Gtk.Button ();
+                       this.buttonOk.CanDefault = true;
+                       this.buttonOk.CanFocus = true;
+                       this.buttonOk.Name = "buttonOk";
+                       this.buttonOk.UseStock = true;
+                       this.buttonOk.UseUnderline = true;
+                       this.buttonOk.Label = "gtk-ok";
+                       this.AddActionWidget (this.buttonOk, -5);
+                       global::Gtk.ButtonBox.ButtonBoxChild w6 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w4 
[this.buttonOk]));
+                       w6.Position = 1;
+                       w6.Expand = false;
+                       w6.Fill = false;
+                       if ((this.Child != null)) {
+                               this.Child.ShowAll ();
+                       }
+                       this.DefaultWidth = 504;
+                       this.DefaultHeight = 191;
+                       this.Show ();
+               }
+       }
+}
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.ChooseProjectDialog.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.ChooseProjectDialog.cs
new file mode 100644
index 0000000..c204e91
--- /dev/null
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.ChooseProjectDialog.cs
@@ -0,0 +1,72 @@
+
+// This file has been generated by the GUI designer. Do not modify.
+namespace LongoMatch.Gui.Dialog
+{
+       public partial class ChooseProjectDialog
+       {
+               private global::LongoMatch.Gui.Component.ProjectListWidget projectlistwidget1;
+               private global::Gtk.Button buttonCancel;
+               private global::Gtk.Button okButton;
+
+               protected virtual void Build ()
+               {
+                       global::Stetic.Gui.Initialize (this);
+                       // Widget LongoMatch.Gui.Dialog.ChooseProjectDialog
+                       this.Name = "LongoMatch.Gui.Dialog.ChooseProjectDialog";
+                       this.Title = global::Mono.Unix.Catalog.GetString ("Choose project");
+                       this.Icon = global::Stetic.IconLoader.LoadIcon (this, "longomatch", 
global::Gtk.IconSize.Menu);
+                       this.TypeHint = ((global::Gdk.WindowTypeHint)(1));
+                       this.WindowPosition = ((global::Gtk.WindowPosition)(4));
+                       this.Modal = true;
+                       this.Gravity = ((global::Gdk.Gravity)(5));
+                       this.SkipPagerHint = true;
+                       // Internal child LongoMatch.Gui.Dialog.ChooseProjectDialog.VBox
+                       global::Gtk.VBox w1 = this.VBox;
+                       w1.Name = "dialog1_VBox";
+                       w1.BorderWidth = ((uint)(2));
+                       // Container child dialog1_VBox.Gtk.Box+BoxChild
+                       this.projectlistwidget1 = new global::LongoMatch.Gui.Component.ProjectListWidget ();
+                       this.projectlistwidget1.Events = ((global::Gdk.EventMask)(256));
+                       this.projectlistwidget1.Name = "projectlistwidget1";
+                       w1.Add (this.projectlistwidget1);
+                       global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(w1 
[this.projectlistwidget1]));
+                       w2.Position = 0;
+                       // Internal child LongoMatch.Gui.Dialog.ChooseProjectDialog.ActionArea
+                       global::Gtk.HButtonBox w3 = this.ActionArea;
+                       w3.Name = "dialog1_ActionArea";
+                       w3.Spacing = 10;
+                       w3.BorderWidth = ((uint)(5));
+                       w3.LayoutStyle = ((global::Gtk.ButtonBoxStyle)(4));
+                       // Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild
+                       this.buttonCancel = new global::Gtk.Button ();
+                       this.buttonCancel.CanDefault = true;
+                       this.buttonCancel.CanFocus = true;
+                       this.buttonCancel.Name = "buttonCancel";
+                       this.buttonCancel.UseStock = true;
+                       this.buttonCancel.UseUnderline = true;
+                       this.buttonCancel.Label = "gtk-cancel";
+                       this.AddActionWidget (this.buttonCancel, -6);
+                       global::Gtk.ButtonBox.ButtonBoxChild w4 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w3 
[this.buttonCancel]));
+                       w4.Expand = false;
+                       w4.Fill = false;
+                       // Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild
+                       this.okButton = new global::Gtk.Button ();
+                       this.okButton.CanFocus = true;
+                       this.okButton.Name = "okButton";
+                       this.okButton.UseStock = true;
+                       this.okButton.UseUnderline = true;
+                       this.okButton.Label = "gtk-ok";
+                       this.AddActionWidget (this.okButton, -5);
+                       global::Gtk.ButtonBox.ButtonBoxChild w5 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w3 
[this.okButton]));
+                       w5.Position = 1;
+                       w5.Expand = false;
+                       w5.Fill = false;
+                       if ((this.Child != null)) {
+                               this.Child.ShowAll ();
+                       }
+                       this.DefaultWidth = 699;
+                       this.DefaultHeight = 481;
+                       this.Show ();
+               }
+       }
+}
diff --git a/LongoMatch.GUI/gtk-gui/gui.stetic b/LongoMatch.GUI/gtk-gui/gui.stetic
index c0baa57..cb007c7 100644
--- a/LongoMatch.GUI/gtk-gui/gui.stetic
+++ b/LongoMatch.GUI/gtk-gui/gui.stetic
@@ -11424,4 +11424,161 @@ Installing these codecs will therefore be entirely at your risk.</property>
       </widget>
     </child>
   </widget>
-</stetic-interface>
\ No newline at end of file
+  <widget class="Gtk.Dialog" id="LongoMatch.Gui.Dialog.ChooseProjectDialog" design-size="699 481">
+    <property name="MemberName" />
+    <property name="Title" translatable="yes">Choose project</property>
+    <property name="Icon">stock:longomatch Menu</property>
+    <property name="TypeHint">Dialog</property>
+    <property name="WindowPosition">CenterOnParent</property>
+    <property name="Modal">True</property>
+    <property name="Gravity">Center</property>
+    <property name="SkipPagerHint">True</property>
+    <property name="Buttons">2</property>
+    <property name="HelpButton">False</property>
+    <child internal-child="VBox">
+      <widget class="Gtk.VBox" id="dialog1_VBox">
+        <property name="MemberName" />
+        <property name="BorderWidth">2</property>
+        <child>
+          <widget class="LongoMatch.Gui.Component.ProjectListWidget" id="projectlistwidget1">
+            <property name="MemberName" />
+            <property name="Events">ButtonPressMask</property>
+          </widget>
+          <packing>
+            <property name="Position">0</property>
+            <property name="AutoSize">True</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+    <child internal-child="ActionArea">
+      <widget class="Gtk.HButtonBox" id="dialog1_ActionArea">
+        <property name="MemberName" />
+        <property name="Spacing">10</property>
+        <property name="BorderWidth">5</property>
+        <property name="Size">2</property>
+        <property name="LayoutStyle">End</property>
+        <child>
+          <widget class="Gtk.Button" id="buttonCancel">
+            <property name="MemberName" />
+            <property name="CanDefault">True</property>
+            <property name="CanFocus">True</property>
+            <property name="UseStock">True</property>
+            <property name="Type">StockItem</property>
+            <property name="StockId">gtk-cancel</property>
+            <property name="ResponseId">-6</property>
+            <property name="label">gtk-cancel</property>
+          </widget>
+          <packing>
+            <property name="Expand">False</property>
+            <property name="Fill">False</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="Gtk.Button" id="okButton">
+            <property name="MemberName" />
+            <property name="CanFocus">True</property>
+            <property name="UseStock">True</property>
+            <property name="Type">StockItem</property>
+            <property name="StockId">gtk-ok</property>
+            <property name="ResponseId">-5</property>
+            <property name="label">gtk-ok</property>
+          </widget>
+          <packing>
+            <property name="Position">1</property>
+            <property name="Expand">False</property>
+            <property name="Fill">False</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+  <widget class="Gtk.Dialog" id="LongoMatch.Gui.Dialog.ChooseOptionDialog" design-size="504 191">
+    <property name="MemberName" />
+    <property name="Title" translatable="yes" />
+    <property name="Icon">stock:longomatch Menu</property>
+    <property name="TypeHint">Dialog</property>
+    <property name="WindowPosition">CenterOnParent</property>
+    <property name="Modal">True</property>
+    <property name="DestroyWithParent">True</property>
+    <property name="Gravity">Center</property>
+    <property name="SkipPagerHint">True</property>
+    <property name="SkipTaskbarHint">True</property>
+    <property name="Buttons">2</property>
+    <property name="HelpButton">False</property>
+    <child internal-child="VBox">
+      <widget class="Gtk.VBox" id="dialog1_VBox">
+        <property name="MemberName" />
+        <property name="BorderWidth">2</property>
+        <child>
+          <widget class="Gtk.Alignment" id="alignment1">
+            <property name="MemberName" />
+            <property name="Xscale">0</property>
+            <property name="Yscale">0</property>
+            <child>
+              <widget class="Gtk.VBox" id="optionsbox">
+                <property name="MemberName" />
+                <property name="Spacing">6</property>
+                <child>
+                  <placeholder />
+                </child>
+                <child>
+                  <placeholder />
+                </child>
+                <child>
+                  <placeholder />
+                </child>
+              </widget>
+            </child>
+          </widget>
+          <packing>
+            <property name="Position">0</property>
+            <property name="AutoSize">True</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+    <child internal-child="ActionArea">
+      <widget class="Gtk.HButtonBox" id="dialog1_ActionArea">
+        <property name="MemberName" />
+        <property name="Spacing">10</property>
+        <property name="BorderWidth">5</property>
+        <property name="Size">2</property>
+        <property name="LayoutStyle">End</property>
+        <child>
+          <widget class="Gtk.Button" id="buttonCancel">
+            <property name="MemberName" />
+            <property name="CanDefault">True</property>
+            <property name="CanFocus">True</property>
+            <property name="UseStock">True</property>
+            <property name="Type">StockItem</property>
+            <property name="StockId">gtk-cancel</property>
+            <property name="ResponseId">-6</property>
+            <property name="label">gtk-cancel</property>
+          </widget>
+          <packing>
+            <property name="Expand">False</property>
+            <property name="Fill">False</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="Gtk.Button" id="buttonOk">
+            <property name="MemberName" />
+            <property name="CanDefault">True</property>
+            <property name="CanFocus">True</property>
+            <property name="UseStock">True</property>
+            <property name="Type">StockItem</property>
+            <property name="StockId">gtk-ok</property>
+            <property name="ResponseId">-5</property>
+            <property name="label">gtk-ok</property>
+          </widget>
+          <packing>
+            <property name="Position">1</property>
+            <property name="Expand">False</property>
+            <property name="Fill">False</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+</stetic-interface>
diff --git a/LongoMatch.Services/Services/ToolsManager.cs b/LongoMatch.Services/Services/ToolsManager.cs
index f75ac34..970f33f 100644
--- a/LongoMatch.Services/Services/ToolsManager.cs
+++ b/LongoMatch.Services/Services/ToolsManager.cs
@@ -44,8 +44,9 @@ namespace LongoMatch.Services
                        this.dbManager = dbManager;
                        ProjectImporters = new List<ProjectImporter> ();
                        
-                       RegisterImporter (Project.Import, Constants.PROJECT_NAME,
-                                         new string[] {"*"+Constants.PROJECT_EXT }, false);
+                       RegisterImporter (Project.Import, Catalog.GetString ("Import project"),
+                                         Constants.PROJECT_NAME,
+                                         new string[] {"*"+Constants.PROJECT_EXT }, false, false);
 
                        Config.EventsBroker.OpenedProjectChanged += (pr, pt, f, a) => {
                                this.openedProject = pr;
@@ -80,14 +81,17 @@ namespace LongoMatch.Services
                }
 
                public void RegisterImporter (Func<string, Project> importFunction,
-                                             string filterName, string[] extensions, 
-                                             bool needsEdition)
+                                             string description, string filterName,
+                                             string[] extensions, bool needsEdition,
+                                             bool canOverwrite)
                {
                        ProjectImporter importer = new ProjectImporter {
+                               Description = description,
                                ImportFunction=importFunction,
                                FilterName=filterName,
                                Extensions=extensions,
-                               NeedsEdition=needsEdition
+                               NeedsEdition=needsEdition,
+                               CanOverwrite=canOverwrite,
                        };
                        ProjectImporters.Add (importer);
                }
@@ -120,6 +124,12 @@ namespace LongoMatch.Services
                        }
                }
 
+               ProjectImporter ChooseImporter (IEnumerable<ProjectImporter> importers)
+               {
+                       Dictionary<string, object> options = importers.ToDictionary (i => i.Description, i => 
(object)i);
+                       return (ProjectImporter) Config.GUIToolkit.ChooseOption (options);
+               }
+ 
                void ImportProject ()
                {
                        Project project;
@@ -143,12 +153,16 @@ namespace LongoMatch.Services
                         * is not a valid project */
                        try {
                                string extension = "*" + Path.GetExtension (fileName);
-                               importer = ProjectImporters.Where (p => p.Extensions.Contains 
(extension)).FirstOrDefault ();
-                               if (importer != null) {
-                                       project = importer.ImportFunction (fileName);
-                               } else {
+                               IEnumerable<ProjectImporter> importers =  ProjectImporters.Where
+                                       (p => p.Extensions.Contains (extension));
+                               if (importers.Count () == 0) {
                                        throw new Exception (Catalog.GetString ("Plugin not found"));
+                               } else if (importers.Count () == 1) {
+                                       importer = importers.First();
+                               } else {
+                                       importer = ChooseImporter (importers);
                                }
+                               project = importer.ImportFunction (fileName);
                                if (importer.NeedsEdition) {
                                        Config.EventsBroker.EmitNewProject (project);
                                } else {
@@ -159,9 +173,10 @@ namespace LongoMatch.Services
                                                }
                                        }
                                        /* If the project exists ask if we want to overwrite it */
-                                       if (DB.Exists (project)) {
+                                       if (!importer.CanOverwrite && DB.Exists (project)) {
                                                var res = guiToolkit.QuestionMessage (Catalog.GetString ("A 
project already exists for this ID:") +
-                                                                                     project.ID + "\n" +     
  Catalog.GetString ("Do you want to overwrite it?"), null);
+                                                                                     project.ID + "\n" +
+                                                                                     Catalog.GetString ("Do 
you want to overwrite it?"), null);
                                                if (!res)
                                                        return;
                                                DB.UpdateProject (project);
@@ -213,6 +228,11 @@ namespace LongoMatch.Services
                        set;
                }
 
+               public string Description {
+                       get;
+                       set;
+               }
+               
                public string [] Extensions {
                        get;
                        set;
@@ -227,6 +247,11 @@ namespace LongoMatch.Services
                        get;
                        set;
                }
+
+               public bool CanOverwrite {
+                       get;
+                       set;
+               }
        }
 }
 


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