[longomatch] Add support for timers in tagging buttons



commit 59c31e8d0814ff60ff0c45e2aa94015b37e267f1
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Nov 11 01:29:43 2013 +0100

    Add support for timers in tagging buttons

 LongoMatch.Core/Handlers/Handlers.cs               |    4 +-
 LongoMatch.Core/Interfaces/GUI/IMainWindow.cs      |    1 +
 LongoMatch.GUI/Gui/Component/ButtonTagger.cs       |  162 ++++++++++++++++++++
 LongoMatch.GUI/Gui/Component/ButtonsWidget.cs      |  108 +++++---------
 LongoMatch.GUI/Gui/MainWindow.cs                   |   12 ++-
 LongoMatch.GUI/LongoMatch.GUI.mdp                  |    2 +
 LongoMatch.GUI/Makefile.am                         |    2 +
 .../LongoMatch.Gui.Component.ButtonTagger.cs       |   50 ++++++
 .../LongoMatch.Gui.Component.ButtonsWidget.cs      |   30 +----
 .../LongoMatch.Gui.Component.Stats.Plotter.cs      |    1 +
 LongoMatch.GUI/gtk-gui/gui.stetic                  |   63 ++++----
 LongoMatch.GUI/gtk-gui/objects.xml                 |   12 ++
 LongoMatch.Services/Services/EventsManager.cs      |   27 +++-
 13 files changed, 337 insertions(+), 137 deletions(-)
---
diff --git a/LongoMatch.Core/Handlers/Handlers.cs b/LongoMatch.Core/Handlers/Handlers.cs
index 33fab57..5d7f071 100644
--- a/LongoMatch.Core/Handlers/Handlers.cs
+++ b/LongoMatch.Core/Handlers/Handlers.cs
@@ -34,9 +34,11 @@ namespace LongoMatch.Handlers
        /* A new play needs to be create for a specific category at the current play time */
        public delegate void NewTagHandler(Category category);
        /* Signal the start time to tag a new play */
-       public delegate void NewTagStartHandler();
+       public delegate void NewTagStartHandler (Category category);
        /* Signal the stop time to tag a new play */
        public delegate void NewTagStopHandler(Category category);
+       /* Signal cancellation of tag */
+       public delegate void NewTagCancelHandler(Category category);
        /* A new play needs to be created at a defined frame */
        public delegate void NewTagAtFrameHandler(Category category,int frame);
        //A play was edited
diff --git a/LongoMatch.Core/Interfaces/GUI/IMainWindow.cs b/LongoMatch.Core/Interfaces/GUI/IMainWindow.cs
index 049aefb..f247fff 100644
--- a/LongoMatch.Core/Interfaces/GUI/IMainWindow.cs
+++ b/LongoMatch.Core/Interfaces/GUI/IMainWindow.cs
@@ -31,6 +31,7 @@ namespace LongoMatch.Interfaces.GUI
                event NewTagHandler NewTagEvent;
                event NewTagStartHandler NewTagStartEvent;
                event NewTagStopHandler NewTagStopEvent;
+               event NewTagCancelHandler NewTagCancelEvent;
                event PlaySelectedHandler PlaySelectedEvent;
                event NewTagAtFrameHandler NewTagAtFrameEvent;
                event TagPlayHandler TagPlayEvent;
diff --git a/LongoMatch.GUI/Gui/Component/ButtonTagger.cs b/LongoMatch.GUI/Gui/Component/ButtonTagger.cs
new file mode 100644
index 0000000..09e9d07
--- /dev/null
+++ b/LongoMatch.GUI/Gui/Component/ButtonTagger.cs
@@ -0,0 +1,162 @@
+//
+//  Copyright (C) 2013 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 Gtk;
+using Gdk;
+
+using LongoMatch.Common;
+using LongoMatch.Handlers;
+using LongoMatch.Store;
+
+namespace LongoMatch.Gui.Component
+{
+       [System.ComponentModel.ToolboxItem(true)]
+       public partial class ButtonTagger : Gtk.Bin
+       {
+               public event NewTagHandler NewTag;
+               public event NewTagStartHandler NewTagStart;
+               public event NewTagStopHandler NewTagStop;
+               public event NewTagCancelHandler NewTagCancel;
+               
+               Category category;
+               Button tagButton;
+               Label label;
+               Time start, current;
+               TagMode mode;
+               Color black, grey;
+               
+               public ButtonTagger (Category category)
+               {
+                       this.Build ();
+                       black = new Color();
+                       Color.Parse ("black", ref black);
+                       Color.Parse ("grey", ref grey);
+                       this.category = category;
+                       CreateButton ();
+                       cancelbutton.Clicked += OnButtonClicked;
+                       CurrentTime = new Time {MSeconds = 0};
+                       mode = TagMode.Predifined;
+               }
+
+               public TagMode  Mode {
+                       set {
+                               mode = value;
+                               if (mode == TagMode.Predifined) {
+                                       cancelbutton.Visible = false;
+                               } else {
+                                       if (start == null) {
+                                               cancelbutton.Visible = start != null;
+                                       }
+                               }
+                       }
+               }
+               
+               public Time CurrentTime {
+                       set {
+                               current = value;
+                               if (mode == TagMode.Free && start != null) {
+                                       Time ellapsed = value - start;
+                                       label.Markup = String.Format ("{0} {1}", 
+                                                                     GLib.Markup.EscapeText (category.Name),
+                                                                     ellapsed.ToSecondsString());
+                               } else {
+                                       label.Markup =  GLib.Markup.EscapeText (category.Name);
+                               }
+                       }
+               }
+
+               void ChangeButton (bool started) {
+                       if (started) {
+                               label.ModifyFg(StateType.Normal, Helpers.Misc.ToGdkColor(category.Color));
+                               label.ModifyFg(StateType.Prelight, black);
+                               tagButton.ModifyBg(StateType.Normal, grey);
+                               tagButton.ModifyBg(StateType.Prelight, 
Helpers.Misc.ToGdkColor(category.Color));
+                       } else {
+                               label.ModifyFg(StateType.Normal, black);
+                               label.ModifyFg(StateType.Prelight, Helpers.Misc.ToGdkColor(category.Color));
+                               tagButton.ModifyBg(StateType.Normal, Helpers.Misc.ToGdkColor(category.Color));
+                               tagButton.ModifyBg(StateType.Prelight, grey);
+                       }
+               }
+                               
+               void EmitStartTag () {
+                       if (NewTagStart != null)
+                               NewTagStart (category);
+                       cancelbutton.Visible = true;
+                       ChangeButton (true);
+               }
+
+               void EmitStopTag () {
+                       if (NewTagStop != null)
+                               NewTagStop (category);
+                       cancelbutton.Visible = false;
+                       ChangeButton (false);
+               }
+               
+               void EmitCancelTag () {
+                       cancelbutton.Visible = false;
+                       start = null;
+                       ChangeButton (false);
+                       if (NewTagCancel != null)
+                               NewTagCancel (category);
+               }
+               
+               void EmitNewTag () {
+                       if (NewTag != null)
+                               NewTag (category);
+               }
+               
+               void OnButtonClicked (object sender, EventArgs args)
+               {
+                       if (sender == tagButton) {
+                               if (mode == TagMode.Predifined) {
+                                       EmitNewTag ();
+                               } else {
+                                       if (start == null) {
+                                               start = current;
+                                               EmitStartTag ();
+                                       } else {
+                                               EmitStopTag ();
+                                               start = null;
+                                       }
+                               }
+                       } else {
+                               EmitCancelTag ();
+                       }
+               }
+               
+               void CreateButton () {
+                       label = new Label();
+                       label.Markup = GLib.Markup.EscapeText (category.Name);
+                       label.Justify = Justification.Center;
+                       label.Ellipsize = Pango.EllipsizeMode.Middle;
+                       label.CanFocus = false;
+            
+                       tagButton = new Button();
+                       tagButton.Add(label);
+                       tagButton.Clicked += new EventHandler(OnButtonClicked);
+                       tagButton.CanFocus = false;
+                       
+                       label.Show();
+                       tagButton.Show();
+                       buttonbox.PackStart (tagButton);
+                       ChangeButton (false);
+               }
+       }
+}
+
diff --git a/LongoMatch.GUI/Gui/Component/ButtonsWidget.cs b/LongoMatch.GUI/Gui/Component/ButtonsWidget.cs
index a84bc9d..118554e 100644
--- a/LongoMatch.GUI/Gui/Component/ButtonsWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/ButtonsWidget.cs
@@ -34,30 +34,36 @@ namespace LongoMatch.Gui.Component
        [System.ComponentModel.ToolboxItem(true)]
        public partial class ButtonsWidget : Gtk.Bin
        {
-
-               private Categories categories;
-               private TagMode tagMode;
-               private Dictionary<Widget, Category> buttonsDic;
-
                public event NewTagHandler NewMarkEvent;
                public event NewTagStartHandler NewMarkStartEvent;
                public event NewTagStopHandler NewMarkStopEvent;
+               public event NewTagCancelHandler NewMarkCancelEvent;
 
+               Categories categories;
+               TagMode tagMode;
+               Dictionary<ButtonTagger, Category> buttonsDic;
 
                public ButtonsWidget()
                {
                        this.Build();
+                       buttonsDic = new Dictionary<ButtonTagger, Category>();
                        Mode = TagMode.Predifined;
-                       buttonsDic = new Dictionary<Widget, Category>();
                }
 
                public TagMode Mode {
                        set {
-                               bool isPredef = (value == TagMode.Predifined);
-                               table1.Visible = isPredef;
-                               starttagbutton.Visible = !isPredef;
-                               cancelbutton.Visible = false;
                                tagMode = value;
+                               foreach (ButtonTagger b in buttonsDic.Keys) {
+                                       b.Mode = tagMode;
+                               }
+                       }
+               }
+               
+               public Time CurrentTime {
+                       set {
+                               foreach (ButtonTagger b in buttonsDic.Keys) {
+                                       b.CurrentTime = value;
+                               }
                        }
                }
 
@@ -78,77 +84,41 @@ namespace LongoMatch.Gui.Component
                                table1.NRows =(uint)(sectionsCount/10);
 
                                for(int i=0; i<sectionsCount; i++) {
-                                       Button b = new Button();
-                                       Label l = new Label();
                                        Category cat = value[i];
+                                       ButtonTagger b = new ButtonTagger (cat);
+                                       b.NewTag += (category) => {
+                                               if (NewMarkEvent != null) {
+                                                       NewMarkEvent (category);
+                                               }
+                                       };
+                                       b.NewTagStart += (category) => {
+                                               if (NewMarkStartEvent != null) {
+                                                       NewMarkStartEvent (category);
+                                               }
+                                       };
+                                       b.NewTagStop += (category) => {
+                                               if (NewMarkStopEvent != null) {
+                                                       NewMarkStopEvent (category);
+                                               }
+                                       };
+                                       b.NewTagCancel += (category) => {
+                                               if (NewMarkCancelEvent != null) {
+                                                       NewMarkCancelEvent (category);
+                                               }
+                                       };
+                                       b.Mode = tagMode;
 
                                        uint row_top =(uint)(i/table1.NColumns);
                                        uint row_bottom = (uint) row_top+1 ;
                                        uint col_left = (uint) i%table1.NColumns;
                                        uint col_right = (uint) col_left+1 ;
 
-                                       l.Markup = GLib.Markup.EscapeText (cat.Name);
-                                       l.Justify = Justification.Center;
-                                       l.Ellipsize = Pango.EllipsizeMode.Middle;
-                                       l.CanFocus = false;
-                                       
-                                       var c = new Color();
-                                       Color.Parse("black", ref c);
-                                       l.ModifyFg(StateType.Normal, c);
-                                       l.ModifyFg(StateType.Prelight, Helpers.Misc.ToGdkColor(cat.Color));
-                    l.Markup = cat.Name;
-
-                                       b.Add(l);
-                                       b.Name = i.ToString();
-                                       b.Clicked += new EventHandler(OnButtonClicked);
-                                       b.CanFocus = false;
-                                       b.ModifyBg(StateType.Normal, Helpers.Misc.ToGdkColor(cat.Color));
-
-                                       l.Show();
-                                       b.Show();
-
                                        table1.Attach(b,col_left,col_right,row_top,row_bottom);
 
                                        buttonsDic.Add(b, cat);
+                                       b.Show();
                                }
                        }
                }
-
-               protected virtual void OnButtonClicked(object sender,  System.EventArgs e)
-               {
-                       if(categories == null)
-                               return;
-                       Widget w = (Button)sender;
-                       if(tagMode == TagMode.Predifined) {
-                               if(NewMarkEvent != null)
-                                       NewMarkEvent(buttonsDic[w]);
-                       } else {
-                               starttagbutton.Visible = true;
-                               table1.Visible = false;
-                               cancelbutton.Visible = false;
-                               if(NewMarkStopEvent != null)
-                                       NewMarkStopEvent(buttonsDic[w]);
-                       }
-               }
-
-               protected virtual void OnStartTagClicked(object sender, System.EventArgs e)
-               {
-                       if(categories == null)
-                               return;
-
-                       starttagbutton.Visible = false;
-                       table1.Visible = true;
-                       cancelbutton.Visible = true;
-
-                       if(NewMarkStartEvent != null)
-                               NewMarkStartEvent();
-               }
-
-               protected virtual void OnCancelbuttonClicked(object sender, System.EventArgs e)
-               {
-                       starttagbutton.Visible = true;
-                       table1.Visible = false;
-                       cancelbutton.Visible = false;
-               }
        }
 }
diff --git a/LongoMatch.GUI/Gui/MainWindow.cs b/LongoMatch.GUI/Gui/MainWindow.cs
index 54c81b2..c60c41a 100644
--- a/LongoMatch.GUI/Gui/MainWindow.cs
+++ b/LongoMatch.GUI/Gui/MainWindow.cs
@@ -49,6 +49,7 @@ namespace LongoMatch.Gui
                public event NewTagHandler NewTagEvent;
                public event NewTagStartHandler NewTagStartEvent;
                public event NewTagStopHandler NewTagStopEvent;
+               public event NewTagCancelHandler NewTagCancelEvent;
                public event PlaySelectedHandler PlaySelectedEvent;
                public event NewTagAtFrameHandler NewTagAtFrameEvent;
                public event TagPlayHandler TagPlayEvent;
@@ -259,6 +260,7 @@ namespace LongoMatch.Gui
                        buttonswidget.NewMarkEvent += EmitNewTag;;
                        buttonswidget.NewMarkStartEvent += EmitNewTagStart;
                        buttonswidget.NewMarkStopEvent += EmitNewTagStop;
+                       buttonswidget.NewMarkCancelEvent += EmitNewTagCancel;
                        timeline.NewMarkEvent += EmitNewTagAtFrame;
 
                        /* Connect TimeNodeChanged events */
@@ -769,6 +771,7 @@ namespace LongoMatch.Gui
                                guTimeline.CurrentFrame = frame;
                        }
                        gameunitstaggerwidget1.CurrentTime = new Time{MSeconds = (int)currentTime};
+                       buttonswidget.CurrentTime = new Time{MSeconds = (int)currentTime};
                }
                
                protected virtual void OnUpdate(Version version, string URL) {
@@ -863,9 +866,9 @@ namespace LongoMatch.Gui
                                NewTagEvent(category);
                }
 
-               private void EmitNewTagStart() {
+               private void EmitNewTagStart(Category category) {
                        if (NewTagStartEvent != null)
-                               NewTagStartEvent ();
+                               NewTagStartEvent (category);
                }
 
                private void EmitNewTagStop(Category category) {
@@ -873,6 +876,11 @@ namespace LongoMatch.Gui
                                NewTagStopEvent (category);
                }
                
+               private void EmitNewTagCancel(Category category) {
+                       if (NewTagCancelEvent != null)
+                               NewTagCancelEvent (category);
+               }
+               
                private void EmitRenderPlaylist(IPlayList playlist) {
                        if (RenderPlaylistEvent != null)
                                RenderPlaylistEvent(playlist);
diff --git a/LongoMatch.GUI/LongoMatch.GUI.mdp b/LongoMatch.GUI/LongoMatch.GUI.mdp
index 8a65c18..8bd5390 100644
--- a/LongoMatch.GUI/LongoMatch.GUI.mdp
+++ b/LongoMatch.GUI/LongoMatch.GUI.mdp
@@ -201,6 +201,8 @@
     <File subtype="Code" buildaction="Compile" 
name="gtk-gui/LongoMatch.Gui.Component.Stats.PlayerCategoryViewer.cs" />
     <File subtype="Code" buildaction="Compile" name="Gui/Component/Stats/PlayerSubcategoryViewer.cs" />
     <File subtype="Code" buildaction="Compile" 
name="gtk-gui/LongoMatch.Gui.Component.Stats.PlayerSubcategoryViewer.cs" />
+    <File subtype="Code" buildaction="Compile" name="Gui/Component/ButtonTagger.cs" />
+    <File subtype="Code" buildaction="Compile" name="gtk-gui/LongoMatch.Gui.Component.ButtonTagger.cs" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="atk-sharp, Version=2.12.0.0, Culture=neutral, 
PublicKeyToken=35e10195dab3c99f" />
diff --git a/LongoMatch.GUI/Makefile.am b/LongoMatch.GUI/Makefile.am
index 14556fc..2325e69 100644
--- a/LongoMatch.GUI/Makefile.am
+++ b/LongoMatch.GUI/Makefile.am
@@ -8,6 +8,7 @@ SOURCES = \
        gtk-gui/LongoMatch.Gui.Base.TemplatesEditorBase.cs \
        gtk-gui/LongoMatch.Gui.Base.TimelineWidgetBase.cs \
        gtk-gui/LongoMatch.Gui.Component.ButtonsWidget.cs \
+       gtk-gui/LongoMatch.Gui.Component.ButtonTagger.cs \
        gtk-gui/LongoMatch.Gui.Component.CategoryProperties.cs \
        gtk-gui/LongoMatch.Gui.Component.CoordinatesTagger.cs \
        gtk-gui/LongoMatch.Gui.Component.DrawingToolBox.cs \
@@ -75,6 +76,7 @@ SOURCES = \
        Gui/Base/TimelineWidgetBase.cs \
        Gui/Base/TimeScaleBase.cs \
        Gui/Component/ButtonsWidget.cs \
+       Gui/Component/ButtonTagger.cs \
        Gui/Component/CategoriesTemplateEditor.cs \
        Gui/Component/CategoryProperties.cs \
        Gui/Component/CoordinatesTagger.cs \
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.ButtonTagger.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.ButtonTagger.cs
new file mode 100644
index 0000000..0ecd93f
--- /dev/null
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.ButtonTagger.cs
@@ -0,0 +1,50 @@
+
+// This file has been generated by the GUI designer. Do not modify.
+namespace LongoMatch.Gui.Component
+{
+       public partial class ButtonTagger
+       {
+               private global::Gtk.HBox buttonbox;
+               private global::Gtk.Button cancelbutton;
+               
+               protected virtual void Build ()
+               {
+                       global::Stetic.Gui.Initialize (this);
+                       // Widget LongoMatch.Gui.Component.ButtonTagger
+                       global::Stetic.BinContainer.Attach (this);
+                       this.Name = "LongoMatch.Gui.Component.ButtonTagger";
+                       // Container child LongoMatch.Gui.Component.ButtonTagger.Gtk.Container+ContainerChild
+                       this.buttonbox = new global::Gtk.HBox ();
+                       this.buttonbox.Name = "buttonbox";
+                       // Container child buttonbox.Gtk.Box+BoxChild
+                       this.cancelbutton = new global::Gtk.Button ();
+                       this.cancelbutton.Name = "cancelbutton";
+                       this.cancelbutton.UseUnderline = true;
+                       // Container child cancelbutton.Gtk.Container+ContainerChild
+                       global::Gtk.Alignment w1 = new global::Gtk.Alignment (0.5F, 0.5F, 0F, 0F);
+                       // Container child GtkAlignment.Gtk.Container+ContainerChild
+                       global::Gtk.HBox w2 = new global::Gtk.HBox ();
+                       w2.Spacing = 2;
+                       // Container child GtkHBox.Gtk.Container+ContainerChild
+                       global::Gtk.Image w3 = new global::Gtk.Image ();
+                       w3.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-cancel", 
global::Gtk.IconSize.Menu);
+                       w2.Add (w3);
+                       // Container child GtkHBox.Gtk.Container+ContainerChild
+                       global::Gtk.Label w5 = new global::Gtk.Label ();
+                       w2.Add (w5);
+                       w1.Add (w2);
+                       this.cancelbutton.Add (w1);
+                       this.buttonbox.Add (this.cancelbutton);
+                       global::Gtk.Box.BoxChild w9 = ((global::Gtk.Box.BoxChild)(this.buttonbox 
[this.cancelbutton]));
+                       w9.PackType = ((global::Gtk.PackType)(1));
+                       w9.Position = 1;
+                       w9.Expand = false;
+                       w9.Fill = false;
+                       this.Add (this.buttonbox);
+                       if ((this.Child != null)) {
+                               this.Child.ShowAll ();
+                       }
+                       this.Hide ();
+               }
+       }
+}
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.ButtonsWidget.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.ButtonsWidget.cs
index f95b46f..04b6032 100644
--- a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.ButtonsWidget.cs
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.ButtonsWidget.cs
@@ -5,8 +5,6 @@ namespace LongoMatch.Gui.Component
        public partial class ButtonsWidget
        {
                private global::Gtk.VBox vbox1;
-               private global::Gtk.Button cancelbutton;
-               private global::Gtk.Button starttagbutton;
                private global::Gtk.Table table1;
                
                protected virtual void Build ()
@@ -20,42 +18,18 @@ namespace LongoMatch.Gui.Component
                        this.vbox1.Name = "vbox1";
                        this.vbox1.Spacing = 6;
                        // Container child vbox1.Gtk.Box+BoxChild
-                       this.cancelbutton = new global::Gtk.Button ();
-                       this.cancelbutton.Name = "cancelbutton";
-                       this.cancelbutton.UseUnderline = true;
-                       this.cancelbutton.Label = global::Mono.Unix.Catalog.GetString ("Cancel");
-                       this.vbox1.Add (this.cancelbutton);
-                       global::Gtk.Box.BoxChild w1 = ((global::Gtk.Box.BoxChild)(this.vbox1 
[this.cancelbutton]));
-                       w1.Position = 0;
-                       w1.Expand = false;
-                       w1.Fill = false;
-                       // Container child vbox1.Gtk.Box+BoxChild
-                       this.starttagbutton = new global::Gtk.Button ();
-                       this.starttagbutton.Name = "starttagbutton";
-                       this.starttagbutton.UseUnderline = true;
-                       this.starttagbutton.Label = global::Mono.Unix.Catalog.GetString ("Tag new play");
-                       this.vbox1.Add (this.starttagbutton);
-                       global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(this.vbox1 
[this.starttagbutton]));
-                       w2.Position = 1;
-                       w2.Expand = false;
-                       w2.Fill = false;
-                       // Container child vbox1.Gtk.Box+BoxChild
                        this.table1 = new global::Gtk.Table (((uint)(5)), ((uint)(4)), false);
                        this.table1.Name = "table1";
                        this.table1.RowSpacing = ((uint)(1));
                        this.table1.ColumnSpacing = ((uint)(1));
                        this.vbox1.Add (this.table1);
-                       global::Gtk.Box.BoxChild w3 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.table1]));
-                       w3.Position = 2;
+                       global::Gtk.Box.BoxChild w1 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.table1]));
+                       w1.Position = 0;
                        this.Add (this.vbox1);
                        if ((this.Child != null)) {
                                this.Child.ShowAll ();
                        }
-                       this.cancelbutton.Hide ();
-                       this.starttagbutton.Hide ();
                        this.Show ();
-                       this.cancelbutton.Clicked += new global::System.EventHandler 
(this.OnCancelbuttonClicked);
-                       this.starttagbutton.Clicked += new global::System.EventHandler 
(this.OnStartTagClicked);
                }
        }
 }
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.Stats.Plotter.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.Stats.Plotter.cs
index ad9cc26..9d59a08 100644
--- a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.Stats.Plotter.cs
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.Stats.Plotter.cs
@@ -31,6 +31,7 @@ namespace LongoMatch.Gui.Component.Stats
                        this.historadiobutton = new global::Gtk.RadioButton 
(global::Mono.Unix.Catalog.GetString ("Histogram"));
                        this.historadiobutton.CanFocus = true;
                        this.historadiobutton.Name = "historadiobutton";
+                       this.historadiobutton.Active = true;
                        this.historadiobutton.DrawIndicator = true;
                        this.historadiobutton.UseUnderline = true;
                        this.historadiobutton.Group = new global::GLib.SList (global::System.IntPtr.Zero);
diff --git a/LongoMatch.GUI/gtk-gui/gui.stetic b/LongoMatch.GUI/gtk-gui/gui.stetic
index 5bdf90d..8ecfafa 100644
--- a/LongoMatch.GUI/gtk-gui/gui.stetic
+++ b/LongoMatch.GUI/gtk-gui/gui.stetic
@@ -919,38 +919,6 @@
         <property name="MemberName" />
         <property name="Spacing">6</property>
         <child>
-          <widget class="Gtk.Button" id="cancelbutton">
-            <property name="MemberName" />
-            <property name="Visible">False</property>
-            <property name="Type">TextOnly</property>
-            <property name="Label" translatable="yes">Cancel</property>
-            <property name="UseUnderline">True</property>
-            <signal name="Clicked" handler="OnCancelbuttonClicked" />
-          </widget>
-          <packing>
-            <property name="Position">0</property>
-            <property name="AutoSize">True</property>
-            <property name="Expand">False</property>
-            <property name="Fill">False</property>
-          </packing>
-        </child>
-        <child>
-          <widget class="Gtk.Button" id="starttagbutton">
-            <property name="MemberName" />
-            <property name="Visible">False</property>
-            <property name="Type">TextOnly</property>
-            <property name="Label" translatable="yes">Tag new play</property>
-            <property name="UseUnderline">True</property>
-            <signal name="Clicked" handler="OnStartTagClicked" />
-          </widget>
-          <packing>
-            <property name="Position">1</property>
-            <property name="AutoSize">True</property>
-            <property name="Expand">False</property>
-            <property name="Fill">False</property>
-          </packing>
-        </child>
-        <child>
           <widget class="Gtk.Table" id="table1">
             <property name="MemberName" />
             <property name="NRows">5</property>
@@ -1019,7 +987,7 @@
             </child>
           </widget>
           <packing>
-            <property name="Position">2</property>
+            <property name="Position">0</property>
             <property name="AutoSize">True</property>
           </packing>
         </child>
@@ -8876,6 +8844,7 @@ Defining &lt;b&gt; Game Units &lt;/b&gt; will help you during the analysis to in
                 <property name="MemberName" />
                 <property name="CanFocus">True</property>
                 <property name="Label" translatable="yes">Histogram</property>
+                <property name="Active">True</property>
                 <property name="DrawIndicator">True</property>
                 <property name="HasLabel">True</property>
                 <property name="UseUnderline">True</property>
@@ -9442,4 +9411,32 @@ Defining &lt;b&gt; Game Units &lt;/b&gt; will help you during the analysis to in
       </widget>
     </child>
   </widget>
+  <widget class="Gtk.Bin" id="LongoMatch.Gui.Component.ButtonTagger" design-size="204 43">
+    <property name="MemberName" />
+    <property name="Visible">False</property>
+    <child>
+      <widget class="Gtk.HBox" id="buttonbox">
+        <property name="MemberName" />
+        <child>
+          <placeholder />
+        </child>
+        <child>
+          <widget class="Gtk.Button" id="cancelbutton">
+            <property name="MemberName" />
+            <property name="Type">TextAndIcon</property>
+            <property name="Icon">stock:gtk-cancel Menu</property>
+            <property name="Label" translatable="yes" />
+            <property name="UseUnderline">True</property>
+          </widget>
+          <packing>
+            <property name="PackType">End</property>
+            <property name="Position">1</property>
+            <property name="AutoSize">True</property>
+            <property name="Expand">False</property>
+            <property name="Fill">False</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
 </stetic-interface>
\ No newline at end of file
diff --git a/LongoMatch.GUI/gtk-gui/objects.xml b/LongoMatch.GUI/gtk-gui/objects.xml
index fafc111..e2b33a3 100644
--- a/LongoMatch.GUI/gtk-gui/objects.xml
+++ b/LongoMatch.GUI/gtk-gui/objects.xml
@@ -31,6 +31,7 @@
         <signal name="NewMarkEvent" />
         <signal name="NewMarkStartEvent" />
         <signal name="NewMarkStopEvent" />
+        <signal name="NewMarkCancelEvent" />
       </itemgroup>
     </signals>
   </object>
@@ -440,4 +441,15 @@
     <itemgroups />
     <signals />
   </object>
+  <object type="LongoMatch.Gui.Component.ButtonTagger" palette-category="General" allow-children="false" 
base-type="Gtk.Bin">
+    <itemgroups />
+    <signals>
+      <itemgroup label="ButtonTagger Signals">
+        <signal name="NewTag" />
+        <signal name="NewTagStart" />
+        <signal name="NewTagStop" />
+        <signal name="NewTagCancel" />
+      </itemgroup>
+    </signals>
+  </object>
 </objects>
\ No newline at end of file
diff --git a/LongoMatch.Services/Services/EventsManager.cs b/LongoMatch.Services/Services/EventsManager.cs
index 6329a33..f7db18a 100644
--- a/LongoMatch.Services/Services/EventsManager.cs
+++ b/LongoMatch.Services/Services/EventsManager.cs
@@ -45,6 +45,7 @@ namespace LongoMatch.Services
                ProjectType projectType;
                Time startTime;
                PlaysFilter filter;
+               Dictionary<Category, Time> catsTime;
                
                IGUIToolkit guiToolkit;
                IMainWindow mainWindow;
@@ -60,6 +61,7 @@ namespace LongoMatch.Services
                        player = mainWindow.Player;
                        capturer = mainWindow.Capturer;
                        drawingManager = new VideoDrawingsManager(player);
+                       catsTime = new Dictionary<Category, Time>();
                        ConnectSignals();
                }
 
@@ -75,6 +77,7 @@ namespace LongoMatch.Services
                        this.filter = filter;
                        this.openedProject = project;
                        this.projectType = projectType;
+                       catsTime.Clear ();
                }
 
                private void ConnectSignals() {
@@ -84,6 +87,7 @@ namespace LongoMatch.Services
                        mainWindow.NewTagEvent += OnNewTag;
                        mainWindow.NewTagStartEvent += OnNewPlayStart;
                        mainWindow.NewTagStopEvent += OnNewPlayStop;
+                       mainWindow.NewTagCancelEvent += OnNewPlayCancel;
                        mainWindow.NewTagAtFrameEvent += OnNewTagAtFrame;
                        mainWindow.TimeNodeChanged += OnTimeNodeChanged;
                        mainWindow.PlaysDeletedEvent += OnPlaysDeleted;
@@ -228,14 +232,22 @@ namespace LongoMatch.Services
                        ProcessNewTag(category,pos);
                }
 
-               public virtual void OnNewPlayStart() {
-                       startTime = new Time {MSeconds = (int)player.CurrentTime};
+               public virtual void OnNewPlayStart (Category category) {
+                       catsTime.Add (category, new Time {MSeconds = (int)player.CurrentTime});
                        Log.Debug("New play start time: " + startTime);
                }
-
+               
                public virtual void OnNewPlayStop(Category category) {
                        int diff;
-                       Time stopTime = new Time {MSeconds = (int)player.CurrentTime};
+                       Time startTime, stopTime;
+                       
+                       if (!catsTime.ContainsKey (category)) {
+                               Log.Error ("Can't add new play, no start time for this play");
+                               return;
+                       }
+                       startTime = catsTime[category];
+                       catsTime.Remove (category);
+                       stopTime = new Time {MSeconds = (int)player.CurrentTime};
 
                        Log.Debug("New play stop time: " + stopTime);
                        diff = stopTime.MSeconds - startTime.MSeconds;
@@ -254,6 +266,13 @@ namespace LongoMatch.Services
                        }
                        AddNewPlay(startTime, stopTime, category);
                }
+               
+               public virtual void OnNewPlayCancel (Category category) {
+                       try {
+                               catsTime.Remove (category);
+                       } catch {
+                       }
+               }
 
                private void LaunchPlayTagger(Play play, bool showAllTags) {
                        guiToolkit.TagPlay(play, openedProject.Categories,


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