[longomatch] Add same menu options in the timeline like in the list



commit 9a2f1e9331b6571625b0d213ab572d14cf4122b0
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed Jun 12 20:41:46 2013 +0200

    Add same menu options in the timeline like in the list

 LongoMatch.GUI/Gui/Base/TimeScaleBase.cs           |   78 +++++++++++++-------
 .../Gui/Component/PlaysListTreeWidget.cs           |    6 +-
 .../Gui/Component/PlaysSelectionWidget.cs          |    2 +-
 LongoMatch.GUI/Gui/Component/TimeLineWidget.cs     |   50 +++++++++++--
 LongoMatch.GUI/Gui/Component/TimeScale.cs          |   54 ++++++++++++++
 LongoMatch.GUI/Gui/MainWindow.cs                   |    4 +
 LongoMatch.GUI/gtk-gui/objects.xml                 |    6 +-
 7 files changed, 160 insertions(+), 40 deletions(-)
---
diff --git a/LongoMatch.GUI/Gui/Base/TimeScaleBase.cs b/LongoMatch.GUI/Gui/Base/TimeScaleBase.cs
index 111e431..589e166 100644
--- a/LongoMatch.GUI/Gui/Base/TimeScaleBase.cs
+++ b/LongoMatch.GUI/Gui/Base/TimeScaleBase.cs
@@ -20,6 +20,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using Cairo;
 using Gdk;
 using Gtk;
@@ -58,10 +59,10 @@ namespace LongoMatch.Gui.Base
                Menu deleteMenu;
                Menu menu;
                MenuItem delete;
-               Dictionary<MenuItem,T> dic;
 
                Pango.Layout layout;
                
+               protected Dictionary<MenuItem,T> menuToNodeDict;
                protected string elementName = "";
                protected int cursorFrame;
 
@@ -76,13 +77,11 @@ namespace LongoMatch.Gui.Base
                        Size((int)(frames/pixelRatio),SECTION_HEIGHT);
                        Events = EventMask.PointerMotionMask | EventMask.ButtonPressMask | 
EventMask.ButtonReleaseMask ;
 
-                       dic = new Dictionary<MenuItem, T>();
+                       menuToNodeDict = new Dictionary<MenuItem, T>();
                        
                        layout =  new Pango.Layout(PangoContext);
                        layout.Wrap = Pango.WrapMode.Char;
                        layout.Alignment = Pango.Alignment.Left;
-
-                       SetMenu();
                }
 
                public uint PixelRatio {
@@ -137,19 +136,55 @@ namespace LongoMatch.Gui.Base
                
                abstract protected void AddNewTimeNode();
                
-               void SetMenu() {
-                       MenuItem newTimeNode;
-
+               virtual protected void ExpandMenu (List<T> timenodes, Dictionary<T, Menu> menusDict) {}
+               
+               void ShowMenu (List<T> timenodes) {
+                       Menu menu;
+                       Dictionary <T, Menu> menusDict;
+                       
+                       if (timenodes.Contains(SelectedTimeNode)) {
+                               timenodes = timenodes.GetRange(0, 1);
+                       }
+                       
                        menu = new Menu();
-                       delete = new MenuItem(Catalog.GetString("Delete ") + elementName);
+                       menusDict = CreateCommonMenu (timenodes, menu);
+                       ExpandMenu (timenodes, menusDict);
+                       menu.ShowAll();
+                       menu.Popup();
+               }
+               
+               Dictionary<T, Menu> CreateCommonMenu(List<T> timenodes, Menu menu) {
+                       MenuItem newTimeNode;
+                       Dictionary <T, Menu> menusDict;
+                       
+                       menusDict = new Dictionary<T, Menu>();
+                       menuToNodeDict.Clear();
                        newTimeNode = new MenuItem(Catalog.GetString("Add new ") + elementName);
 
                        menu.Append(newTimeNode);
-                       menu.Append(delete);
-
                        newTimeNode.Activated += new EventHandler(OnNewTimeNode);
 
-                       menu.ShowAll();
+                       if (timenodes.Count == 1) {
+                               menusDict.Add (timenodes[0], menu);
+                       } else {
+                               foreach(T tn in timenodes) {
+                                       Menu catMenu = new Menu();
+                                       MenuItem catItem = new MenuItem(tn.Name);
+                                       menu.Append (catItem);
+                                       catItem.Submenu = catMenu;
+                                       menusDict.Add(tn, catMenu);
+                               }
+                       }
+                       
+                       foreach(T tn in timenodes) {
+                               //We scan all the time Nodes looking for one matching the cursor selectcio
+                               //And we add them to the delete menu
+                               MenuItem del = new MenuItem(Catalog.GetString("Delete "));
+                               del.Activated += new EventHandler(OnDelete);
+                               menusDict[tn].Append(del);
+                               menuToNodeDict.Add(del,tn);
+                       }
+                       return menusDict;
                }
                
                void DrawTimeNodes(Gdk.Window win) {
@@ -226,22 +261,11 @@ namespace LongoMatch.Gui.Base
                }
 
                void ProcessButton3(double X) {
+                       List<T> selected;
+                       
                        cursorFrame =(int)(X*pixelRatio);
-                       deleteMenu = new Menu();
-                       delete.Submenu=deleteMenu;
-                       dic.Clear();
-                       foreach(T tn in list) {
-                               //We scan all the time Nodes looking for one matching the cursor selectcio
-                               //And we add them to the delete menu
-                               if(tn.HasFrame(cursorFrame)) {
-                                       MenuItem del = new MenuItem(Catalog.GetString("Delete "+tn.Name));
-                                       del.Activated += new EventHandler(OnDelete);
-                                       deleteMenu.Append(del);
-                                       dic.Add(del,tn);
-                               }
-                       }
-                       menu.ShowAll();
-                       menu.Popup();
+                       selected = list.Where (tn => tn.HasFrame (cursorFrame)).ToList();
+                       ShowMenu(selected);
                }
 
                void ProcessButton1(EventButton evnt) {
@@ -289,7 +313,7 @@ namespace LongoMatch.Gui.Base
 
                void OnDelete(object obj, EventArgs args) {
                        T tNode;
-                       dic.TryGetValue((MenuItem)obj, out tNode);
+                       menuToNodeDict.TryGetValue((MenuItem)obj, out tNode);
                        if(tNode != null) {
                                var list = new List<T>();
                                list.Add(tNode);
diff --git a/LongoMatch.GUI/Gui/Component/PlaysListTreeWidget.cs 
b/LongoMatch.GUI/Gui/Component/PlaysListTreeWidget.cs
index 003d7b1..2b561c5 100644
--- a/LongoMatch.GUI/Gui/Component/PlaysListTreeWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/PlaysListTreeWidget.cs
@@ -45,7 +45,7 @@ namespace LongoMatch.Gui.Component
                public event PlayCategoryChangedHandler PlayCategoryChanged;
                public event SnapshotSeriesHandler SnapshotSeriesEvent;
                public event TagPlayHandler TagPlay;
-               public event RenderPlaylistHandler RenderPlaylistEvent;
+               public event RenderPlaylistHandler RenderPlaylist;
 
                ITemplatesService ts;
 
@@ -241,8 +241,8 @@ namespace LongoMatch.Gui.Component
                                                              project.Description.File, 1, true));
                        }
                        
-                       if (RenderPlaylistEvent != null)
-                               RenderPlaylistEvent(playlist);
+                       if (RenderPlaylist != null)
+                               RenderPlaylist (playlist);
                }
        }
 }
diff --git a/LongoMatch.GUI/Gui/Component/PlaysSelectionWidget.cs 
b/LongoMatch.GUI/Gui/Component/PlaysSelectionWidget.cs
index 61ec087..f79b75b 100644
--- a/LongoMatch.GUI/Gui/Component/PlaysSelectionWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/PlaysSelectionWidget.cs
@@ -140,7 +140,7 @@ namespace LongoMatch.Gui.Component
                        localPlayersList.SnapshotSeriesEvent += EmitSnapshotSeries;
                        visitorPlayersList.SnapshotSeriesEvent += EmitSnapshotSeries;
 
-                       playsList.RenderPlaylistEvent += EmitRenderPlaylist;
+                       playsList.RenderPlaylist += EmitRenderPlaylist;
                        localPlayersList.RenderPlaylistEvent += EmitRenderPlaylist;
                        visitorPlayersList.RenderPlaylistEvent += EmitRenderPlaylist;
                        
diff --git a/LongoMatch.GUI/Gui/Component/TimeLineWidget.cs b/LongoMatch.GUI/Gui/Component/TimeLineWidget.cs
index 6d54cc0..756f0f2 100644
--- a/LongoMatch.GUI/Gui/Component/TimeLineWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/TimeLineWidget.cs
@@ -27,6 +27,7 @@ using LongoMatch.Handlers;
 using LongoMatch.Store;
 using LongoMatch.Store.Templates;
 using LongoMatch.Common;
+using LongoMatch.Interfaces;
 
 namespace LongoMatch.Gui.Component {
 
@@ -37,6 +38,10 @@ namespace LongoMatch.Gui.Component {
                public event PlaySelectedHandler TimeNodeSelected;
                public event PlaysDeletedHandler TimeNodeDeleted;
                public event NewTagAtFrameHandler NewMarkEvent;
+               public event PlayListNodeAddedHandler PlayListNodeAdded;
+               public event SnapshotSeriesHandler SnapshotSeries;
+               public event TagPlayHandler TagPlay;
+               public event RenderPlaylistHandler RenderPlaylist;
 
                private Categories categories;
 
@@ -70,10 +75,14 @@ namespace LongoMatch.Gui.Component {
                                List<Play> playsList = project.PlaysInCategory(cat);
                                TimeScale ts = new TimeScale(cat, playsList, frames, filter);
                                tsList[cat] = ts;
-                               ts.TimeNodeChanged += new TimeNodeChangedHandler(OnTimeNodeChanged);
-                               ts.TimeNodeSelected += new PlaySelectedHandler(OnTimeNodeSelected);
-                               ts.TimeNodeDeleted += new PlaysDeletedHandler(OnTimeNodeDeleted);
-                               ts.NewMarkAtFrameEvent += new NewTagAtFrameHandler(OnNewMark);
+                               ts.TimeNodeChanged += HandleTimeNodeChanged;
+                               ts.TimeNodeSelected += HandleTimeNodeSelected;
+                               ts.TimeNodeDeleted += HandleTimeNodeDeleted;
+                               ts.NewMarkAtFrameEvent += HandleNewMark;
+                               ts.TagPlay += HandleTagPlay;
+                               ts.RenderPlaylist += HandleRenderPlaylist;
+                               ts.SnapshotSeries += HandleSnapshotSeries;
+                               ts.PlayListNodeAdded += HandlePlayListNodeAdded; 
                                TimelineBox.PackStart(ts,false,true,0);
                                ts.Show();
                        }
@@ -94,24 +103,49 @@ namespace LongoMatch.Gui.Component {
                        }
                }
                
-               protected virtual void OnNewMark(Category category, int frame) {
+               void HandleNewMark(Category category, int frame) {
                        if(NewMarkEvent != null)
                                NewMarkEvent(category,frame);
                }
 
-               protected virtual void OnTimeNodeChanged(TimeNode tn, object val) {
+               void HandleTimeNodeChanged(TimeNode tn, object val) {
                        if(TimeNodeChanged != null)
                                TimeNodeChanged(tn,val);
                }
 
-               protected virtual void OnTimeNodeSelected(Play tn) {
+               void HandleTimeNodeSelected(Play tn) {
                        if(TimeNodeSelected != null)
                                TimeNodeSelected(tn);
                }
                
-               protected virtual void OnTimeNodeDeleted(List<Play> plays) {
+               void HandleTimeNodeDeleted(List<Play> plays) {
                        if(TimeNodeDeleted != null)
                                TimeNodeDeleted(plays);
                }
+               
+               void HandleTagPlay (Play play)
+               {
+                       if (TagPlay != null)
+                               TagPlay (play);
+               }
+
+               void HandlePlayListNodeAdded (Play play)
+               {
+                       if (PlayListNodeAdded != null)
+                               PlayListNodeAdded (play);
+               }
+
+               void HandleSnapshotSeries (Play play)
+               {
+                       if (SnapshotSeries != null)
+                               SnapshotSeries (play);
+               }
+
+               void HandleRenderPlaylist (IPlayList playlist)
+               {
+                       if (RenderPlaylist != null)
+                               RenderPlaylist (playlist);
+               }
+
        }
 }
diff --git a/LongoMatch.GUI/Gui/Component/TimeScale.cs b/LongoMatch.GUI/Gui/Component/TimeScale.cs
index df524ec..ea76705 100644
--- a/LongoMatch.GUI/Gui/Component/TimeScale.cs
+++ b/LongoMatch.GUI/Gui/Component/TimeScale.cs
@@ -45,6 +45,10 @@ namespace LongoMatch.Gui.Component
                public event TimeNodeChangedHandler TimeNodeChanged;
                public event PlaySelectedHandler TimeNodeSelected;
                public event PlaysDeletedHandler TimeNodeDeleted;
+               public event PlayListNodeAddedHandler PlayListNodeAdded;
+               public event SnapshotSeriesHandler SnapshotSeries;
+               public event TagPlayHandler TagPlay;
+               public event RenderPlaylistHandler RenderPlaylist;
 
 
                public TimeScale(Category category, List<Play> list, uint frames, PlaysFilter filter): 
base(list, frames, filter)
@@ -57,6 +61,32 @@ namespace LongoMatch.Gui.Component
                        };
                }
 
+               override protected void ExpandMenu (List<Play> plays, Dictionary<Play, Menu> menusDict) {
+                       foreach (Play play in plays) {
+                               MenuItem tag, addPLN, snapshot, render;
+                               Menu menu = menusDict[play];
+                       
+                               tag = new MenuItem(Catalog.GetString("Edit tags"));
+                               addPLN = new MenuItem(Catalog.GetString("Add to playlist"));
+                               render = new MenuItem(Catalog.GetString("Export to video file"));
+                               snapshot = new MenuItem(Catalog.GetString("Export to PGN images"));
+                               
+                               tag.Activated += HandleTag;
+                               addPLN.Activated += HandleAddPlayListNode;
+                               render.Activated += HandleRender;
+                               snapshot.Activated += HandleSnapshot;
+                               
+                               menu.Add (tag);
+                               menu.Add (addPLN);
+                               menu.Add (render);
+                               menu.Add (snapshot);
+                               menuToNodeDict.Add (tag, play);
+                               menuToNodeDict.Add (addPLN, play);
+                               menuToNodeDict.Add (render, play);
+                               menuToNodeDict.Add (snapshot, play);
+                       }
+               }
+
                public void AddPlay(Play play) {
                        AddTimeNode(play);
                }
@@ -85,5 +115,29 @@ namespace LongoMatch.Gui.Component
                                NewMarkAtFrameEvent(category, cursorFrame);
                }
                
+               void HandleSnapshot (object sender, EventArgs e)
+               {
+                       if (SnapshotSeries != null)
+                               SnapshotSeries (menuToNodeDict[sender as MenuItem]);
+                       
+               }
+
+               void HandleRender (object sender, EventArgs e)
+               {
+                       
+               }
+
+               void HandleAddPlayListNode (object sender, EventArgs e)
+               {
+                       if (PlayListNodeAdded != null)
+                               PlayListNodeAdded (menuToNodeDict[sender as MenuItem]);
+                       
+               }
+
+               void HandleTag (object sender, EventArgs e)
+               {
+                       if (TagPlay != null)
+                               TagPlay(menuToNodeDict[sender as MenuItem]);
+               }
        }
 }
diff --git a/LongoMatch.GUI/Gui/MainWindow.cs b/LongoMatch.GUI/Gui/MainWindow.cs
index 6b4f6c0..139deab 100644
--- a/LongoMatch.GUI/Gui/MainWindow.cs
+++ b/LongoMatch.GUI/Gui/MainWindow.cs
@@ -280,15 +280,19 @@ namespace LongoMatch.Gui
 
                        /* Connect PlayListNodeAdded events */
                        playsSelection.PlayListNodeAdded += OnPlayListNodeAdded;
+                       timeline.PlayListNodeAdded += OnPlayListNodeAdded;
 
                        /* Connect tags events */
                        playsSelection.TagPlay += EmitTagPlay;
+                       timeline.TagPlay += EmitTagPlay;
 
                        /* Connect SnapshotSeries events */
                        playsSelection.SnapshotSeries += EmitSnapshotSeries;
+                       timeline.SnapshotSeries += EmitSnapshotSeries;
 
                        playlist.RenderPlaylistEvent += EmitRenderPlaylist;
                        playsSelection.RenderPlaylist += EmitRenderPlaylist;
+                       timeline.RenderPlaylist += EmitRenderPlaylist;
                        
                        renderingstatebar1.ManageJobs += (e, o) => {EmitManageJobs();};
                        
diff --git a/LongoMatch.GUI/gtk-gui/objects.xml b/LongoMatch.GUI/gtk-gui/objects.xml
index ee5c21b..5d578d5 100644
--- a/LongoMatch.GUI/gtk-gui/objects.xml
+++ b/LongoMatch.GUI/gtk-gui/objects.xml
@@ -219,6 +219,10 @@
         <signal name="TimeNodeChanged" />
         <signal name="TimeNodeSelected" />
         <signal name="TimeNodeDeleted" />
+        <signal name="PlayListNodeAdded" />
+        <signal name="TagPlay" />
+        <signal name="SnapshotSeries" />
+        <signal name="RenderPlaylist" />
       </itemgroup>
     </signals>
   </object>
@@ -279,7 +283,7 @@
         <signal name="PlayCategoryChanged" />
         <signal name="SnapshotSeriesEvent" />
         <signal name="TagPlay" />
-        <signal name="RenderPlaylistEvent" />
+        <signal name="RenderPlaylist" />
       </itemgroup>
     </signals>
   </object>


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