[longomatch] Use the plays menu everywhere



commit b2bf64758ac8dd750ec79384dd3b53c59b889e2c
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Fri Jun 27 18:37:00 2014 +0200

    Use the plays menu everywhere

 .../Gui/Component/PlayersListTreeWidget.cs         |    6 -
 .../Gui/Component/PlaysListTreeWidget.cs           |    6 -
 .../Gui/Component/PlaysPositionViewer.cs           |    4 +-
 .../Gui/Component/PlaysSelectionWidget.cs          |    8 -
 LongoMatch.GUI/Gui/Component/Timeline.cs           |    2 +-
 LongoMatch.GUI/Gui/Menu/PlaysMenu.cs               |   78 ++++++++--
 LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs    |  157 +++-----------------
 LongoMatch.GUI/Gui/TreeView/PlayersTreeView.cs     |    9 +-
 LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs       |    7 +-
 9 files changed, 89 insertions(+), 188 deletions(-)
---
diff --git a/LongoMatch.GUI/Gui/Component/PlayersListTreeWidget.cs 
b/LongoMatch.GUI/Gui/Component/PlayersListTreeWidget.cs
index 9307299..efa7003 100644
--- a/LongoMatch.GUI/Gui/Component/PlayersListTreeWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/PlayersListTreeWidget.cs
@@ -83,12 +83,6 @@ namespace LongoMatch.Gui.Component
                        playerstreeview.Project = Project;
                }
 
-               public bool PlayListLoaded {
-                       set {
-                               playerstreeview.PlayListLoaded=value;
-                       }
-               }
-
                public void Clear() {
                        playerstreeview.Model = null;
                }
diff --git a/LongoMatch.GUI/Gui/Component/PlaysListTreeWidget.cs 
b/LongoMatch.GUI/Gui/Component/PlaysListTreeWidget.cs
index b366169..b77cb4b 100644
--- a/LongoMatch.GUI/Gui/Component/PlaysListTreeWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/PlaysListTreeWidget.cs
@@ -117,12 +117,6 @@ namespace LongoMatch.Gui.Component
                        }
                }
 
-               public bool PlayListLoaded {
-                       set {
-                               treeview.PlayListLoaded=value;
-                       }
-               }
-               
                private TreeStore GetModel(Project project){
                        Dictionary<Category, TreeIter> itersDic = new Dictionary<Category, TreeIter>();
                        Gtk.TreeStore dataFileListStore = new Gtk.TreeStore(typeof(Play));
diff --git a/LongoMatch.GUI/Gui/Component/PlaysPositionViewer.cs 
b/LongoMatch.GUI/Gui/Component/PlaysPositionViewer.cs
index 11ba49e..bcaf8cb 100644
--- a/LongoMatch.GUI/Gui/Component/PlaysPositionViewer.cs
+++ b/LongoMatch.GUI/Gui/Component/PlaysPositionViewer.cs
@@ -28,6 +28,7 @@ namespace LongoMatch.Gui.Component
        {
        
                PlaysMenu menu;
+               MediaFile file;
 
                public PlaysPositionViewer ()
                {
@@ -45,6 +46,7 @@ namespace LongoMatch.Gui.Component
 
                public void LoadProject (Project project) {
                        if (project != null) {
+                               file = project.Description.File;
                                field.Tagger.Background = project.GetBackground (FieldPositionType.Field);
                                hfield.Tagger.Background = project.GetBackground 
(FieldPositionType.HalfField);
                                goal.Tagger.Background = project.GetBackground (FieldPositionType.Goal);
@@ -87,7 +89,7 @@ namespace LongoMatch.Gui.Component
                        if (plays == null || plays.Count == 0) {
                                return;
                        }
-                       menu.ShowMenu (plays);
+                       menu.ShowMenu (plays, file);
                }
 
                protected override void OnDestroyed ()
diff --git a/LongoMatch.GUI/Gui/Component/PlaysSelectionWidget.cs 
b/LongoMatch.GUI/Gui/Component/PlaysSelectionWidget.cs
index 7f94e33..0b3b88f 100644
--- a/LongoMatch.GUI/Gui/Component/PlaysSelectionWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/PlaysSelectionWidget.cs
@@ -70,14 +70,6 @@ namespace LongoMatch.Gui.Component
                        visitorPlayersList.Clear();
                }
                
-               public bool PlayListLoaded {
-                       set {
-                               playsList.PlayListLoaded = value;
-                               localPlayersList.PlayListLoaded = value;
-                               visitorPlayersList.PlayListLoaded = value;
-                       }
-               }
-               
                public void AddPlay(Play play) {
                        playsList.AddPlay(play);
                        UpdateTeamsModels();
diff --git a/LongoMatch.GUI/Gui/Component/Timeline.cs b/LongoMatch.GUI/Gui/Component/Timeline.cs
index 45e8e1f..b4dd9e8 100644
--- a/LongoMatch.GUI/Gui/Component/Timeline.cs
+++ b/LongoMatch.GUI/Gui/Component/Timeline.cs
@@ -160,7 +160,7 @@ namespace LongoMatch.Gui.Component
                
                void HandleShowMenu (List<Play> plays, Category cat, Time time)
                {
-                       menu.ShowMenu (plays, cat, time, projectFile);
+                       menu.ShowTimelineMenu (plays, cat, time, projectFile);
                }
        }
 }
diff --git a/LongoMatch.GUI/Gui/Menu/PlaysMenu.cs b/LongoMatch.GUI/Gui/Menu/PlaysMenu.cs
index 954be6b..09d1e44 100644
--- a/LongoMatch.GUI/Gui/Menu/PlaysMenu.cs
+++ b/LongoMatch.GUI/Gui/Menu/PlaysMenu.cs
@@ -28,7 +28,9 @@ namespace LongoMatch.Gui.Menus
        public class PlaysMenu: Gtk.Menu
        {
        
-               MenuItem newPlay, del, tag, addPLN, snapshot, render;
+               public event EventHandler EditNameEvent;
+
+               MenuItem edit, newPlay, del, addPLN, snapshot, render, duplicate, moveCat;
                List<Play> plays;
                Category cat;
                Time time;
@@ -40,12 +42,24 @@ namespace LongoMatch.Gui.Menus
                        CreateMenu ();
                }
                
-               public void ShowMenu (List<Play> plays) {
-                       ShowMenu (plays, null, null, null);
+               public void ShowListMenu (List<Play> plays, MediaFile projectFile,
+                                         List<Category> categories) {
+                       ShowMenu (plays, null, null, null, categories, true);
+               }
+
+               public void ShowMenu (List<Play> plays, MediaFile projectFile) {
+                       ShowMenu (plays, null, null, projectFile, null, false);
+               }
+               
+               public void ShowTimelineMenu (List<Play> plays, Category cat, Time time,
+                                             MediaFile projectFile)
+               {
+                       ShowMenu (plays, cat, time, projectFile, null, false);
                }
                
-               public void ShowMenu (List<Play> plays, Category cat, Time time,
-                                     MediaFile projectFile) {
+               private void ShowMenu (List<Play> plays, Category cat, Time time,
+                                      MediaFile projectFile, List<Category> categories,
+                                      bool editableName) {
                        this.plays = plays;
                        this.cat = cat;
                        this.time = time;
@@ -62,11 +76,13 @@ namespace LongoMatch.Gui.Menus
                        if (plays == null)
                                plays = new List<Play> ();
                        
-                       tag.Visible = plays.Count == 1;
+                       edit.Visible = editableName;
                        snapshot.Visible = plays.Count == 1;
-                       del.Visible = plays.Count > 0;;
-                       addPLN.Visible = plays.Count > 0;;
-                       render.Visible = plays.Count > 0;;
+                       moveCat.Visible = plays.Count == 1 && categories != null;
+                       del.Visible = plays.Count > 0;
+                       addPLN.Visible = plays.Count > 0;
+                       render.Visible = plays.Count > 0;
+                       duplicate.Visible = plays.Count > 0;
 
                        if (plays.Count > 0 ) {
                                string label = String.Format ("{0} ({1})",Catalog.GetString("Delete"), 
plays.Count);
@@ -75,7 +91,25 @@ namespace LongoMatch.Gui.Menus
                                GtkGlue.MenuItemSetLabel (addPLN, label);
                                label = String.Format ("{0} ({1})", Catalog.GetString("Export to video 
file"), plays.Count);
                                GtkGlue.MenuItemSetLabel (render, label);
+                               label = String.Format ("{0} ({1})", Catalog.GetString("Duplicate "), 
plays.Count);
+                               GtkGlue.MenuItemSetLabel (duplicate, label);
+                       }
+                       
+                       if (moveCat.Visible) {
+                               Menu catMenu = new Menu();
+                               foreach (Category c in categories) {
+                                       if (plays[0].Category == c)
+                                               continue;
+                                       var item = new MenuItem (c.Name);
+                                       catMenu.Append (item);
+                                       item.Activated += (sender, e) => {
+                                               Config.EventsBroker.EmitPlayCategoryChanged (plays[0], c);
+                                       }; 
+                               }
+                               catMenu.ShowAll();
+                               moveCat.Submenu = catMenu;
                        }
+                       
                        Popup();
                }
                
@@ -84,18 +118,25 @@ namespace LongoMatch.Gui.Menus
                        Add (newPlay);
                        newPlay.Activated += HandleNePlayActivated;
 
-                       tag = new MenuItem(Catalog.GetString("Edit tags"));
-                       tag.Activated += (sender, e) => Config.EventsBroker.EmitTagPlay (plays[0]);
-                       Add (tag);
-                       
-                       snapshot = new MenuItem(Catalog.GetString("Export to PGN images"));
-                       snapshot.Activated += (sender, e) => Config.EventsBroker.EmitSnapshotSeries 
(plays[0]);
-                       Add (snapshot);
+                       edit = new MenuItem (Catalog.GetString ("Edit name"));
+                       edit.Activated += (sender, e) => {
+                               if (EditNameEvent != null) {
+                                       EditNameEvent (this, null);
+                               }
+                       };
+                       Add (edit);
+
+                       moveCat = new MenuItem (Catalog.GetString ("Move to"));
+                       Add (moveCat);
 
                        del = new MenuItem ("");
                        del.Activated += (sender, e) => Config.EventsBroker.EmitPlaysDeleted (plays);
                        Add (del);
                        
+                       duplicate = new MenuItem ("");
+                       duplicate.Activated += (sender, e) => Config.EventsBroker.EmitDuplicatePlay (plays);
+                       Add (duplicate);
+
                        addPLN = new MenuItem ("");
                        addPLN.Activated += (sender, e) => Config.EventsBroker.EmitPlayListNodeAdded (plays);
                        Add (addPLN);
@@ -103,6 +144,11 @@ namespace LongoMatch.Gui.Menus
                        render = new MenuItem ("");
                        render.Activated += (sender, e) => EmitRenderPlaylist (plays);
                        Add (render);
+                       
+                       snapshot = new MenuItem(Catalog.GetString("Export to PGN images"));
+                       snapshot.Activated += (sender, e) => Config.EventsBroker.EmitSnapshotSeries 
(plays[0]);
+                       Add (snapshot);
+
                        ShowAll ();
                }
 
diff --git a/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs b/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
index 9cfb845..5ded8d9 100644
--- a/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
+++ b/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
@@ -17,6 +17,7 @@
 //
 
 using System;
+using System.Linq;
 using System.Collections.Generic;
 using Gdk;
 using Gtk;
@@ -28,6 +29,7 @@ using LongoMatch.Store;
 using LongoMatch.Gui.Helpers;
 using Image = LongoMatch.Common.Image;
 using Color = Gdk.Color;
+using LongoMatch.Gui.Menus;
 
 namespace LongoMatch.Gui.Component
 {
@@ -35,15 +37,11 @@ namespace LongoMatch.Gui.Component
 
        public abstract class ListTreeViewBase:TreeView
        {
-               // Plays menu
-               protected Menu menu, catMenu;
-               protected MenuItem tag, delete, addPLN, deleteKeyFrame, snapshot;
-               protected MenuItem name, render, moveCat, duplicate;
-
                protected Gtk.CellRendererText nameCell;
                protected Gtk.TreeViewColumn nameColumn;
                protected bool editing;
                protected bool enableCategoryMove = false;
+               protected PlaysMenu playsMenu;
                
                TreeModelFilter modelFilter;
                PlaysFilter filter;
@@ -58,9 +56,6 @@ namespace LongoMatch.Gui.Component
                        RowActivated += new RowActivatedHandler(OnTreeviewRowActivated);
                        HeadersVisible = false;
 
-                       SetMenu();
-                       PlayListLoaded = false;
-
                        nameColumn = new Gtk.TreeViewColumn();
                        nameColumn.Title = "Name";
                        nameCell = new Gtk.CellRendererText();
@@ -72,6 +67,8 @@ namespace LongoMatch.Gui.Component
                        nameColumn.SetCellDataFunc(miniatureCell, new Gtk.TreeCellDataFunc(RenderMiniature));
                        nameColumn.SetCellDataFunc(nameCell, new Gtk.TreeCellDataFunc(RenderName));
 
+                       playsMenu = new PlaysMenu ();
+                       playsMenu.EditNameEvent += OnEdit;
                        AppendColumn(nameColumn);
 
                }
@@ -81,12 +78,6 @@ namespace LongoMatch.Gui.Component
                        set;
                }
 
-               public bool PlayListLoaded {
-                       set {
-                               addPLN.Sensitive = value;
-                       }
-               }
-
                public PlaysFilter Filter {
                        set {
                                filter = value;
@@ -104,20 +95,8 @@ namespace LongoMatch.Gui.Component
                }
 
                public Project Project {
-                       set {
-                               if (!enableCategoryMove)
-                                       return;
-                               catsDict = new Dictionary<MenuItem, Category>();
-                               catMenu = new Menu();
-                               foreach (Category cat in value.Categories.List) {
-                                       var item = new MenuItem (cat.Name);
-                                       catMenu.Append (item);
-                                       catsDict.Add(item, cat);
-                                       item.Activated += OnCatChanged; 
-                               }
-                               catMenu.ShowAll();
-                               moveCat.Submenu = catMenu;
-                       }
+                       set;
+                       protected get;
                }
                
                new public TreeStore Model {
@@ -138,51 +117,22 @@ namespace LongoMatch.Gui.Component
                        }
                }
 
-               protected void SetMenu() {
-                       menu = new Menu();
-
-                       name = new MenuItem(Catalog.GetString("Edit name"));
-                       tag = new MenuItem(Catalog.GetString("Edit tags"));
-                       duplicate = new MenuItem(Catalog.GetString("Duplicate"));
-                       delete = new MenuItem(Catalog.GetString("Delete"));
-                       deleteKeyFrame = new MenuItem(Catalog.GetString("Delete key frame"));
-                       addPLN = new MenuItem(Catalog.GetString("Add to playlist"));
-                       addPLN.Sensitive=false;
-                       render = new MenuItem(Catalog.GetString("Export to video file"));
-                       snapshot = new MenuItem(Catalog.GetString("Export to PGN images"));
-                       moveCat = new MenuItem(Catalog.GetString("Move to category"));
-                       
-                       menu.Append(name);
-                       menu.Append(tag);
-                       menu.Append(addPLN);
-                       menu.Append(delete);
-                       menu.Append(duplicate);
-                       menu.Append(deleteKeyFrame);
-                       menu.Append(render);
-                       menu.Append(snapshot);
-                       menu.Append(moveCat);
-
-                       name.Activated += OnEdit;
-                       tag.Activated += OnTag;
-                       duplicate.Activated += OnDuplicate;
-                       addPLN.Activated += OnAdded;
-                       delete.Activated += OnDeleted;
-                       deleteKeyFrame.Activated += OnDeleteKeyFrame;
-                       render.Activated += OnRender;
-                       snapshot.Activated += OnSnapshot;
-                       menu.ShowAll();
-               }
-               
                protected Play SelectedPlay {
                        get {
                                return GetValueFromPath(Selection.GetSelectedRows()[0]) as Play;
                        }
                }
-
-               protected void MultiSelectMenu(bool enabled) {
-                       name.Sensitive = !enabled;
-                       snapshot.Sensitive = !enabled;
-                       tag.Sensitive = !enabled;
+               
+               protected List<Play> SelectedPlays {
+                       get {
+                               return Selection.GetSelectedRows().Select (
+                                       p => GetValueFromPath(p) as Play).ToList ();
+                       }
+               }
+               
+               protected void ShowMenu () {
+                       playsMenu.ShowListMenu (SelectedPlays, Project.Description.File,
+                                               Project.Categories.List);
                }
 
                protected object GetValueFromPath(TreePath path) {
@@ -294,47 +244,7 @@ namespace LongoMatch.Gui.Component
                        Config.EventsBroker.EmitPlaySelected (item as Play);
                }
 
-               protected void OnDeleted(object obj, EventArgs args) {
-                       List <Play> playsList = new List<Play>();
-                       List <TreeIter> iters = new List<TreeIter>();
-                       TreePath[] paths = Selection.GetSelectedRows();
-
-                       /* Get the iter for all of the paths first, because the path changes
-                        * each time a row is deleted */
-                       foreach(var path in paths) {
-                               TreeIter iter;
-                               modelFilter.GetIter(out iter, path);
-                               playsList.Add((Play)modelFilter.GetValue(iter, 0));
-                               iters.Add(iter);
-                       }
-                       /* Delete all the iters now */
-                       for(int i=0; i< iters.Count; i++) {
-                               TreeIter iter = iters[i];
-                               Model.Remove(ref iter);
-                       }
-                       
-                       Config.EventsBroker.EmitPlaysDeleted (playsList);
-               }
-
-               protected void OnDeleteKeyFrame(object obj, EventArgs args) {
-                       var msg = Catalog.GetString("Do you want to delete the key frame for this play?");
-                       if (MessagesHelpers.QuestionMessage (Toplevel, msg)) {
-                               TreePath[] paths = Selection.GetSelectedRows();
-                               for(int i=0; i<paths.Length; i++) {
-                                       Play tNode = (Play)GetValueFromPath(paths[i]);
-                                       tNode.Drawings.Clear();
-                               }
-                               // Refresh the thumbnails
-                               QueueDraw();
-                       }
-               }
-
-               void OnDuplicate (object sender, EventArgs e)
-               {
-                       Config.EventsBroker.EmitDuplicatePlay (SelectedPlay);
-               }
-
-               protected virtual void OnEdit(object obj, EventArgs args) {
+               protected virtual void OnEdit (object obj, EventArgs args) {
                        TreePath[] paths = Selection.GetSelectedRows();
 
                        editing = true;
@@ -342,35 +252,6 @@ namespace LongoMatch.Gui.Component
                        SetCursor(paths[0],  nameColumn, true);
                }
 
-               protected void OnAdded(object obj, EventArgs args) {
-                       List<Play> list = new List<Play>();
-                       TreePath[] paths = Selection.GetSelectedRows();
-                       for(int i=0; i<paths.Length; i++) {
-                               Play tNode = (Play)GetValueFromPath(paths[i]);
-                               list.Add (tNode);
-                       }
-                       Config.EventsBroker.EmitPlayListNodeAdded (list);
-               }
-
-               protected void OnTag(object obj, EventArgs args) {
-                       Config.EventsBroker.EmitTagPlay (SelectedPlay);
-                       Refilter();
-               }
-
-               protected void OnSnapshot(object obj, EventArgs args) {
-                       Config.EventsBroker.EmitSnapshotSeries (SelectedPlay);
-               }
-               
-               protected void OnRender(object obj, EventArgs args) {
-                       if (NewRenderingJob != null)
-                               NewRenderingJob(this, null);
-               }
-               
-               protected void OnCatChanged(object obj, EventArgs args) {
-                       Config.EventsBroker.EmitPlayCategoryChanged (SelectedPlay,
-                                                                    catsDict[obj as MenuItem]);
-               }
-
                protected void OnFilterUpdated() {
                        modelFilter.Refilter();
                }
diff --git a/LongoMatch.GUI/Gui/TreeView/PlayersTreeView.cs b/LongoMatch.GUI/Gui/TreeView/PlayersTreeView.cs
index d2e65a5..e7b9842 100644
--- a/LongoMatch.GUI/Gui/TreeView/PlayersTreeView.cs
+++ b/LongoMatch.GUI/Gui/TreeView/PlayersTreeView.cs
@@ -35,8 +35,6 @@ namespace LongoMatch.Gui.Component
 
                public PlayersTreeView() {
                        this.Team = Team.LOCAL;
-                       tag.Visible = false;
-                       delete.Visible = false;
                        SetPlayersMenu();
                }
 
@@ -114,16 +112,13 @@ namespace LongoMatch.Gui.Component
                                if(paths.Length == 1) {
                                        TimeNode selectedTimeNode = GetValueFromPath(paths[0]) as TimeNode;
                                        if(selectedTimeNode is Play) {
-                                               deleteKeyFrame.Sensitive = (selectedTimeNode as 
Play).HasDrawings;
-                                               MultiSelectMenu(false);
-                                               menu.Popup();
+                                               ShowMenu ();
                                        } else {
                                                playersMenu.Popup();
                                        }
                                }
                                else if(paths.Length > 1) {
-                                       MultiSelectMenu(true);
-                                       menu.Popup();
+                                       ShowMenu ();
                                }
                        }
                        else
diff --git a/LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs b/LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs
index 5094ce2..e5570c2 100644
--- a/LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs
+++ b/LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs
@@ -235,9 +235,7 @@ namespace LongoMatch.Gui.Component
                                if(paths.Length == 1) {
                                        TimeNode selectedTimeNode = GetValueFromPath(paths[0]) as TimeNode;
                                        if(selectedTimeNode is Play) {
-                                               deleteKeyFrame.Sensitive = (selectedTimeNode as 
Play).HasDrawings;
-                                               MultiSelectMenu(false);
-                                               menu.Popup();
+                                               ShowMenu ();
                                        }
                                        else {
                                                SetupSortMenu((selectedTimeNode as Category).SortMethod);
@@ -245,8 +243,7 @@ namespace LongoMatch.Gui.Component
                                        }
                                }
                                else if(paths.Length > 1) {
-                                       MultiSelectMenu(true);
-                                       menu.Popup();
+                                       ShowMenu ();
                                }
                        }
                        else


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