[longomatch] Expand and collapse rows with a single click



commit 4c8f4efacf6f3580eb9d39cd289bda16bc13d4f9
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Nov 25 19:41:12 2014 +0100

    Expand and collapse rows with a single click

 LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs |    1 +
 LongoMatch.GUI/Gui/TreeView/PlayListTreeView.cs |   17 +++++++++
 LongoMatch.GUI/Gui/TreeView/PlayersTreeView.cs  |   42 +++++++++++++++-------
 LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs    |   20 ++++++++++-
 4 files changed, 64 insertions(+), 16 deletions(-)
---
diff --git a/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs b/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
index e2719f7..aad35b0 100644
--- a/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
+++ b/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
@@ -50,6 +50,7 @@ namespace LongoMatch.Gui.Component
                        Selection.SelectFunction = SelectFunction;
                        RowActivated += new RowActivatedHandler (OnTreeviewRowActivated);
                        HeadersVisible = false;
+                       ShowExpanders = false;
                        
                        TreeViewColumn custColumn = new TreeViewColumn ();
                        CellRenderer cr = new PlaysCellRenderer ();
diff --git a/LongoMatch.GUI/Gui/TreeView/PlayListTreeView.cs b/LongoMatch.GUI/Gui/TreeView/PlayListTreeView.cs
index 200e281..90161e1 100644
--- a/LongoMatch.GUI/Gui/TreeView/PlayListTreeView.cs
+++ b/LongoMatch.GUI/Gui/TreeView/PlayListTreeView.cs
@@ -35,6 +35,7 @@ namespace LongoMatch.Gui.Component
        {
                Project project;
                TreeIter selectedIter;
+               TreePath pathClicked;
                Playlist dragSourcePlaylist;
                IPlaylistElement dragSourceElement;
 
@@ -43,6 +44,7 @@ namespace LongoMatch.Gui.Component
                        HeadersVisible = false;
                        EnableGridLines = TreeViewGridLines.None;
                        EnableTreeLines = false;
+                       ShowExpanders = false;
                        
                        TreeViewColumn custColumn = new TreeViewColumn ();
                        CellRenderer cr = new PlaysCellRenderer ();
@@ -218,6 +220,8 @@ namespace LongoMatch.Gui.Component
                                                ShowPlaylistElementMenu (playlist, el as IPlaylistElement, 
parent);
                                        }
                                }
+                       } else {
+                               GetPathAtPos ((int) evnt.X, (int) evnt.Y, out pathClicked);
                        }
                        return base.OnButtonPressEvent (evnt);
                }
@@ -319,6 +323,19 @@ namespace LongoMatch.Gui.Component
                        base.OnDragBegin (context);
                }
 
+               protected override bool OnButtonReleaseEvent (Gdk.EventButton evnt)
+               {
+                       if (pathClicked != null) {
+                               if (GetRowExpanded (pathClicked)) {
+                                       CollapseRow (pathClicked);
+                               } else {
+                                       ExpandRow (pathClicked, true);
+                               }
+                               pathClicked = null;
+                       }
+                       return base.OnButtonReleaseEvent (evnt);
+               }
+
                protected override bool OnKeyPressEvent (Gdk.EventKey evnt)
                {
                        return false;
diff --git a/LongoMatch.GUI/Gui/TreeView/PlayersTreeView.cs b/LongoMatch.GUI/Gui/TreeView/PlayersTreeView.cs
index 37ce3d7..8a3e7be 100644
--- a/LongoMatch.GUI/Gui/TreeView/PlayersTreeView.cs
+++ b/LongoMatch.GUI/Gui/TreeView/PlayersTreeView.cs
@@ -31,6 +31,8 @@ namespace LongoMatch.Gui.Component
        public partial class PlayersTreeView : ListTreeViewBase
        {
 
+               TreePath pathClicked;
+
                public PlayersTreeView() {
                        this.Team = Team.LOCAL;
                }
@@ -69,32 +71,44 @@ namespace LongoMatch.Gui.Component
                        return false;
                }
 
-               override protected bool OnButtonPressEvent(Gdk.EventButton evnt)
+               protected override bool OnButtonReleaseEvent (Gdk.EventButton evnt)
+               {
+                       if (pathClicked != null) {
+                               if (GetRowExpanded (pathClicked)) {
+                                       CollapseRow (pathClicked);
+                               } else {
+                                       ExpandRow (pathClicked, true);
+                               }
+                               pathClicked = null;
+                       }
+                       return base.OnButtonReleaseEvent (evnt);
+               }
+
+               override protected bool OnButtonPressEvent (Gdk.EventButton evnt)
                {
-                       TreePath[] paths = Selection.GetSelectedRows();
+                       TreePath[] paths = Selection.GetSelectedRows ();
 
-                       if (Misc.RightButtonClicked (evnt))
-                       {
+                       if (Misc.RightButtonClicked (evnt)) {
                                // We don't want to unselect the play when several
                                // plays are selected and we clik the right button
                                // For multiedition
-                               if(paths.Length <= 1) {
-                                       base.OnButtonPressEvent(evnt);
-                                       paths = Selection.GetSelectedRows();
+                               if (paths.Length <= 1) {
+                                       base.OnButtonPressEvent (evnt);
+                                       paths = Selection.GetSelectedRows ();
                                }
 
-                               if(paths.Length == 1) {
-                                       TimeNode selectedTimeNode = GetValueFromPath(paths[0]) as TimeNode;
-                                       if(selectedTimeNode is TimelineEvent) {
+                               if (paths.Length == 1) {
+                                       TimeNode selectedTimeNode = GetValueFromPath (paths [0]) as TimeNode;
+                                       if (selectedTimeNode is TimelineEvent) {
                                                ShowMenu ();
                                        }
-                               }
-                               else if(paths.Length > 1) {
+                               } else if (paths.Length > 1) {
                                        ShowMenu ();
                                }
-                       }
-                       else
+                       } else {
+                               GetPathAtPos ((int) evnt.X, (int) evnt.Y, out pathClicked);
                                base.OnButtonPressEvent(evnt);
+                       }
                        return true;
                }
 
diff --git a/LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs b/LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs
index d653845..363ed38 100644
--- a/LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs
+++ b/LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs
@@ -42,7 +42,7 @@ namespace LongoMatch.Gui.Component
                int startX, startY;
                TargetList targetList;
                TargetEntry[] targetEntry;
-               bool dragging, dragStarted;
+               bool dragging, dragStarted, catClicked;
                TreeViewDropPosition dropPos;
 
                public PlaysTreeView ()
@@ -249,10 +249,25 @@ namespace LongoMatch.Gui.Component
 
                protected override bool OnButtonReleaseEvent (Gdk.EventButton evnt)
                {
-                       dragging = dragStarted = false;
+                       if (catClicked && !dragStarted) {
+                               TreePath path;
+                               GetPathAtPos ((int)evnt.X, (int)evnt.Y, out path);
+                               if (GetRowExpanded (path)) {
+                                       CollapseRow (path);
+                               } else {
+                                       ExpandRow (path, true);
+                               }
+                       }
+                       dragging = dragStarted = catClicked = false;
                        return base.OnButtonReleaseEvent (evnt);
                }
 
+               protected override bool OnExpandCollapseCursorRow (bool logical, bool expand, bool open_all)
+               {
+                       Console.WriteLine (logical + " " + expand + " " + open_all);
+                       return base.OnExpandCollapseCursorRow (logical, expand, open_all);
+               }
+               
                override protected bool OnButtonPressEvent (Gdk.EventButton evnt)
                {
                        TreePath[] paths = Selection.GetSelectedRows ();
@@ -285,6 +300,7 @@ namespace LongoMatch.Gui.Component
                                paths = Selection.GetSelectedRows ();
                                if (paths.Length == 1 && GetValueFromPath (paths [0]) is EventType) {
                                        dragging = true;
+                                       catClicked = true;
                                        dragStarted = false;
                                        startX = (int)evnt.X;
                                        startY = (int)evnt.Y;


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