[longomatch] Add support for reordering events in the list
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add support for reordering events in the list
- Date: Wed, 5 Nov 2014 19:01:31 +0000 (UTC)
commit 7e636d361dd8e1b655abc2cb67a3b0c0f25f1002
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Thu Oct 30 16:33:32 2014 +0100
Add support for reordering events in the list
LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs | 110 ++++----
LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs | 312 +++++++++++++++--------
2 files changed, 263 insertions(+), 159 deletions(-)
---
diff --git a/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs b/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
index adbbf78..ddff0ff 100644
--- a/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
+++ b/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
@@ -15,44 +15,40 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
-
using System;
-using System.Linq;
using System.Collections.Generic;
+using System.Linq;
using Gdk;
using Gtk;
-using Mono.Unix;
-
using LongoMatch.Core.Common;
+using LongoMatch.Core.Interfaces.Drawing;
using LongoMatch.Core.Store;
using LongoMatch.Drawing;
+using LongoMatch.Drawing.Cairo;
+using LongoMatch.Gui.Menus;
+using Color = Gdk.Color;
using Image = LongoMatch.Core.Common.Image;
using Point = LongoMatch.Core.Common.Point;
-using Color = Gdk.Color;
-using LongoMatch.Gui.Menus;
-using LongoMatch.Drawing.Cairo;
-using LongoMatch.Core.Interfaces.Drawing;
namespace LongoMatch.Gui.Component
{
-
-
public abstract class ListTreeViewBase:TreeView
{
protected bool editing;
protected bool enableCategoryMove = false;
protected PlaysMenu playsMenu;
-
- TreeModelFilter modelFilter;
+ protected TreeModelFilter modelFilter;
+ protected TreeModelSort modelSort;
+ protected TreeStore childModel;
EventsFilter filter;
public event EventHandler NewRenderingJob;
- public ListTreeViewBase()
+ public ListTreeViewBase ()
{
Selection.Mode = SelectionMode.Multiple;
Selection.SelectFunction = SelectFunction;
- RowActivated += new RowActivatedHandler(OnTreeviewRowActivated);
+ RowActivated += new RowActivatedHandler (OnTreeviewRowActivated);
HeadersVisible = false;
TreeViewColumn custColumn = new TreeViewColumn ();
@@ -62,7 +58,7 @@ namespace LongoMatch.Gui.Component
playsMenu = new PlaysMenu ();
playsMenu.EditPlayEvent += HandleEditPlayEvent;
- AppendColumn(custColumn);
+ AppendColumn (custColumn);
}
public bool Colors {
@@ -74,77 +70,83 @@ namespace LongoMatch.Gui.Component
set {
filter = value;
filter.FilterUpdated += OnFilterUpdated;
- Refilter();
+ Refilter ();
}
get {
return filter;
}
}
-
- public void Refilter() {
+
+ public void Refilter ()
+ {
if (modelFilter != null)
- modelFilter.Refilter();
+ modelFilter.Refilter ();
}
public Project Project {
set;
protected get;
}
-
+
new public TreeStore Model {
set {
- if(value != null) {
+ childModel = value;
+ if (value != null) {
modelFilter = new TreeModelFilter (value, null);
modelFilter.VisibleFunc = new TreeModelFilterVisibleFunc
(FilterFunction);
- value.SetSortFunc(0, SortFunction);
- value.SetSortColumnId(0,SortType.Ascending);
+ modelSort = new TreeModelSort (modelFilter);
+ modelSort.SetSortFunc (0, SortFunction);
+ modelSort.SetSortColumnId (0, SortType.Ascending);
// Assign the filter as our tree's model
- base.Model = modelFilter;
+ base.Model = modelSort;
} else {
base.Model = null;
}
}
get {
- return (base.Model as TreeModelFilter).ChildModel as TreeStore;
+ return childModel;
}
}
protected TimelineEvent SelectedPlay {
get {
- return GetValueFromPath(Selection.GetSelectedRows()[0]) as TimelineEvent;
+ return GetValueFromPath (Selection.GetSelectedRows () [0]) as TimelineEvent;
}
}
-
+
protected List<TimelineEvent> SelectedPlays {
get {
- return Selection.GetSelectedRows().Select (
- p => GetValueFromPath(p) as TimelineEvent).ToList ();
+ return Selection.GetSelectedRows ().Select (
+ p => GetValueFromPath (p) as TimelineEvent).ToList ();
}
}
-
- protected void ShowMenu () {
+
+ protected void ShowMenu ()
+ {
playsMenu.ShowListMenu (Project, SelectedPlays);
}
- protected object GetValueFromPath(TreePath path) {
+ protected object GetValueFromPath (TreePath path)
+ {
Gtk.TreeIter iter;
- modelFilter.GetIter(out iter, path);
- return modelFilter.GetValue(iter,0);
+ modelSort.GetIter (out iter, path);
+ return modelSort.GetValue (iter, 0);
}
-
- protected bool FilterFunction(TreeModel model, TreeIter iter) {
+
+ protected bool FilterFunction (TreeModel model, TreeIter iter)
+ {
if (Filter == null)
return true;
- object o = model.GetValue(iter, 0);
- return Filter.IsVisible(o);
- }
+ object o = model.GetValue (iter, 0);
+ return Filter.IsVisible (o);
+ }
- protected virtual void OnTreeviewRowActivated(object o, Gtk.RowActivatedArgs args)
+ protected virtual void OnTreeviewRowActivated (object o, Gtk.RowActivatedArgs args)
{
Gtk.TreeIter iter;
- modelFilter.GetIter(out iter, args.Path);
- object item = modelFilter.GetValue(iter, 0);
- if(!(item is TimelineEvent))
+ modelFilter.GetIter (out iter, args.Path);
+ object item = modelFilter.GetValue (iter, 0);
+ if (!(item is TimelineEvent))
return;
Config.EventsBroker.EmitLoadEvent (item as TimelineEvent);
@@ -156,10 +158,11 @@ namespace LongoMatch.Gui.Component
Config.EventsBroker.EmitTeamTagsChanged ();
}
- protected void OnFilterUpdated() {
+ protected void OnFilterUpdated ()
+ {
Refilter ();
}
-
+
protected void RenderElement (TreeViewColumn column, CellRenderer cell, TreeModel model,
TreeIter iter)
{
var item = model.GetValue (iter, 0);
@@ -168,23 +171,24 @@ namespace LongoMatch.Gui.Component
c.Count = model.IterNChildren (iter);
}
- protected abstract bool SelectFunction(TreeSelection selection, TreeModel model, TreePath
path, bool selected);
- protected abstract int SortFunction(TreeModel model, TreeIter a, TreeIter b);
-
+ protected abstract bool SelectFunction (TreeSelection selection, TreeModel model, TreePath
path, bool selected);
+
+ protected abstract int SortFunction (TreeModel model, TreeIter a, TreeIter b);
}
-
- public class PlaysCellRenderer: CellRenderer {
+
+ public class PlaysCellRenderer: CellRenderer
+ {
public object Item {
get;
set;
}
-
+
public int Count {
get;
set;
}
-
+
public override void GetSize (Widget widget, ref Rectangle cell_area, out int x_offset, out
int y_offset, out int width, out int height)
{
x_offset = 0;
@@ -203,7 +207,7 @@ namespace LongoMatch.Gui.Component
protected override void Render (Drawable window, Widget widget, Rectangle backgroundArea,
Rectangle cellArea, Rectangle exposeArea, CellRendererState
flags)
{
- CellState state = (CellState) flags;
+ CellState state = (CellState)flags;
using (IContext context = new CairoContext (window)) {
Area bkg = new Area (new Point (backgroundArea.X, backgroundArea.Y),
diff --git a/LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs b/LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs
index b2550e8..f1593b0 100644
--- a/LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs
+++ b/LongoMatch.GUI/Gui/TreeView/PlaysTreeView.cs
@@ -17,8 +17,8 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
//
-
using System;
+using Gdk;
using Gtk;
using LongoMatch.Core.Common;
using LongoMatch.Core.Handlers;
@@ -27,92 +27,98 @@ using EventType = LongoMatch.Core.Store.EventType;
namespace LongoMatch.Gui.Component
{
-
-
[System.ComponentModel.Category("LongoMatch")]
[System.ComponentModel.ToolboxItem(true)]
public class PlaysTreeView : ListTreeViewBase
{
public event EditEventTypeHandler EditProperties;
-
//Categories menu
Menu categoriesMenu;
RadioAction sortByName, sortByStart, sortByStop, sortByDuration;
-
- public PlaysTreeView() {
+ TreeIter srcIter;
+ EventType draggedEventType;
+ int startX, startY;
+ TargetList targetList;
+ TargetEntry[] targetEntry;
+ bool dragging, dragStarted;
+ TreeViewDropPosition dropPos;
+
+ public PlaysTreeView ()
+ {
enableCategoryMove = true;
- SetCategoriesMenu();
+ SetCategoriesMenu ();
+ targetEntry = new TargetEntry [] { new TargetEntry ("event-type-dnd",
TargetFlags.Widget, 0) };
+ targetList = new TargetList (targetEntry);
+ this.EnableModelDragDest (targetEntry, DragAction.Move);
}
new public TreeStore Model {
set {
- if(value != null) {
- value.SetSortFunc(0, SortFunction);
- value.SetSortColumnId(0,SortType.Ascending);
- }
base.Model = value;
}
get {
return base.Model as TreeStore;
}
}
-
- private void SetCategoriesMenu() {
+
+ private void SetCategoriesMenu ()
+ {
Gtk.Action editProp, sortMenu;
UIManager manager;
ActionGroup g;
- manager= new UIManager();
- g = new ActionGroup("CategoriesMenuGroup");
+ manager = new UIManager ();
+ g = new ActionGroup ("CategoriesMenuGroup");
- editProp = new Gtk.Action("EditPropAction", Mono.Unix.Catalog.GetString("Edit
properties"), null, "gtk-edit");
- sortMenu = new Gtk.Action("SortMenuAction", Mono.Unix.Catalog.GetString("Sort
Method"), null, null);
- sortByName = new Gtk.RadioAction("SortByNameAction",
Mono.Unix.Catalog.GetString("Sort by name"), null, null, 1);
- sortByStart = new Gtk.RadioAction("SortByStartAction",
Mono.Unix.Catalog.GetString("Sort by start time"), null, null, 2);
- sortByStop = new Gtk.RadioAction("SortByStopAction",
Mono.Unix.Catalog.GetString("Sort by stop time"), null, null, 3);
- sortByDuration = new Gtk.RadioAction("SortByDurationAction",
Mono.Unix.Catalog.GetString("Sort by duration"), null, null, 3);
+ editProp = new Gtk.Action ("EditPropAction", Mono.Unix.Catalog.GetString ("Edit
properties"), null, "gtk-edit");
+ sortMenu = new Gtk.Action ("SortMenuAction", Mono.Unix.Catalog.GetString ("Sort
Method"), null, null);
+ sortByName = new Gtk.RadioAction ("SortByNameAction", Mono.Unix.Catalog.GetString
("Sort by name"), null, null, 1);
+ sortByStart = new Gtk.RadioAction ("SortByStartAction", Mono.Unix.Catalog.GetString
("Sort by start time"), null, null, 2);
+ sortByStop = new Gtk.RadioAction ("SortByStopAction", Mono.Unix.Catalog.GetString
("Sort by stop time"), null, null, 3);
+ sortByDuration = new Gtk.RadioAction ("SortByDurationAction",
Mono.Unix.Catalog.GetString ("Sort by duration"), null, null, 3);
- sortByName.Group = new GLib.SList(System.IntPtr.Zero);
+ sortByName.Group = new GLib.SList (System.IntPtr.Zero);
sortByStart.Group = sortByName.Group;
sortByStop.Group = sortByName.Group;
sortByDuration.Group = sortByName.Group;
- g.Add(editProp, null);
- g.Add(sortMenu, null);
- g.Add(sortByName, null);
- g.Add(sortByStart, null);
- g.Add(sortByStop, null);
- g.Add(sortByDuration, null);
+ g.Add (editProp, null);
+ g.Add (sortMenu, null);
+ g.Add (sortByName, null);
+ g.Add (sortByStart, null);
+ g.Add (sortByStop, null);
+ g.Add (sortByDuration, null);
- manager.InsertActionGroup(g,0);
+ manager.InsertActionGroup (g, 0);
- manager.AddUiFromString("<ui>"+
- " <popup action='CategoryMenu'>"+
- " <menuitem action='EditPropAction'/>"+
- " <menu action='SortMenuAction'>"+
- " <menuitem action='SortByNameAction'/>"+
- " <menuitem action='SortByStartAction'/>"+
- " <menuitem action='SortByStopAction'/>"+
- " <menuitem action='SortByDurationAction'/>"+
- " </menu>"+
- " </popup>"+
- "</ui>");
+ manager.AddUiFromString ("<ui>" +
+ " <popup action='CategoryMenu'>" +
+ " <menuitem action='EditPropAction'/>" +
+ " <menu action='SortMenuAction'>" +
+ " <menuitem action='SortByNameAction'/>" +
+ " <menuitem action='SortByStartAction'/>" +
+ " <menuitem action='SortByStopAction'/>" +
+ " <menuitem action='SortByDurationAction'/>" +
+ " </menu>" +
+ " </popup>" +
+ "</ui>");
- categoriesMenu = manager.GetWidget("/CategoryMenu") as Menu;
+ categoriesMenu = manager.GetWidget ("/CategoryMenu") as Menu;
sortByName.Activated += OnSortActivated;
sortByStart.Activated += OnSortActivated;
sortByStop.Activated += OnSortActivated;
sortByDuration.Activated += OnSortActivated;
editProp.Activated += delegate(object sender, EventArgs e) {
- EditProperties(GetValueFromPath(Selection.GetSelectedRows()[0]) as EventType);
+ EditProperties (GetValueFromPath (Selection.GetSelectedRows () [0]) as
EventType);
};
}
- private void SetupSortMenu(SortMethodType sortMethod) {
- switch(sortMethod) {
+ private void SetupSortMenu (SortMethodType sortMethod)
+ {
+ switch (sortMethod) {
case SortMethodType.SortByName:
sortByName.Active = true;
break;
@@ -128,70 +134,67 @@ namespace LongoMatch.Gui.Component
}
}
- protected override int SortFunction(TreeModel model, TreeIter a, TreeIter b) {
- TreeStore store;
- TimeNode tna, tnb;
- TreeIter parent;
- int depth;
- EventType eventType;
+ protected override int SortFunction (TreeModel model, TreeIter a, TreeIter b)
+ {
+ object objecta, objectb;
+ TimelineEvent tna, tnb;
- if(model == null)
+ if (model == null)
return 0;
- store = model as TreeStore;
-
- // Retrieve the iter parent and its depth
- // When a new play is inserted, one of the iters is not a valid
- // in the model. Get the values from the valid one
- if(store.IterIsValid(a)) {
- store.IterParent(out parent, a);
- depth = store.IterDepth(a);
- }
- else {
- store.IterParent(out parent, b);
- depth = store.IterDepth(b);
+ objecta = model.GetValue (a, 0);
+ objectb = model.GetValue (b, 0);
+
+ if (objecta == null && objectb == null) {
+ return 0;
+ } else if (objecta == null) {
+ return -1;
+ } else if (objectb == null) {
+ return 1;
}
-
+
// Dont't store categories
- if(depth == 0)
- return int.Parse(model.GetPath(a).ToString())
- - int.Parse(model.GetPath(b).ToString());
-
- eventType = model.GetValue(parent,0) as EventType;
- tna = model.GetValue(a, 0)as TimeNode;
- tnb = model.GetValue(b, 0) as TimeNode;
-
- switch(eventType.SortMethod) {
- case(SortMethodType.SortByName):
- return String.Compare(tna.Name, tnb.Name);
- case(SortMethodType.SortByStartTime):
- return (tna.Start - tnb.Start).MSeconds;
- case(SortMethodType.SortByStopTime):
- return (tna.Stop - tnb.Stop).MSeconds;
- case(SortMethodType.SortByDuration):
- return (tna.Duration - tnb.Duration).MSeconds;
- default:
+ if (objecta is EventType && objectb is EventType) {
+ return int.Parse (model.GetPath (a).ToString ())
+ - int.Parse (model.GetPath (b).ToString ());
+ } else if (objecta is TimelineEvent && objectb is TimelineEvent) {
+ tna = objecta as TimelineEvent;
+ tnb = objectb as TimelineEvent;
+ switch (tna.EventType.SortMethod) {
+ case(SortMethodType.SortByName):
+ return String.Compare (tna.Name, tnb.Name);
+ case(SortMethodType.SortByStartTime):
+ return (tna.Start - tnb.Start).MSeconds;
+ case(SortMethodType.SortByStopTime):
+ return (tna.Stop - tnb.Stop).MSeconds;
+ case(SortMethodType.SortByDuration):
+ return (tna.Duration - tnb.Duration).MSeconds;
+ default:
+ return 0;
+ }
+ } else {
return 0;
}
}
-
- private void OnSortActivated(object o, EventArgs args) {
+
+ private void OnSortActivated (object o, EventArgs args)
+ {
EventType eventType;
RadioAction sender;
sender = o as RadioAction;
- eventType = GetValueFromPath(Selection.GetSelectedRows()[0]) as EventType;
+ eventType = GetValueFromPath (Selection.GetSelectedRows () [0]) as EventType;
- if(sender == sortByName)
+ if (sender == sortByName)
eventType.SortMethod = SortMethodType.SortByName;
- else if(sender == sortByStart)
+ else if (sender == sortByStart)
eventType.SortMethod = SortMethodType.SortByStartTime;
- else if(sender == sortByStop)
+ else if (sender == sortByStop)
eventType.SortMethod = SortMethodType.SortByStopTime;
else
eventType.SortMethod = SortMethodType.SortByDuration;
// Redorder plays
- Model.SetSortFunc(0, SortFunction);
+ modelSort.SetSortFunc (0, SortFunction);
}
override protected bool SelectFunction (TreeSelection selection, TreeModel model, TreePath
path, bool selected)
@@ -223,43 +226,140 @@ namespace LongoMatch.Gui.Component
return true;
}
- override protected bool OnButtonPressEvent(Gdk.EventButton evnt)
+ protected override bool OnMotionNotifyEvent (EventMotion evnt)
{
- TreePath[] paths = Selection.GetSelectedRows();
+ if (dragging && !dragStarted) {
+ if (Math.Sqrt (Math.Pow (startX - evnt.X, 2) + Math.Pow (startY - evnt.Y, 2))
5) {
+ Gtk.Drag.Begin (this, targetList, DragAction.Move, 1, evnt);
+ dragStarted = true;
+ }
+ }
+ return base.OnMotionNotifyEvent (evnt);
+ }
+
+ protected override bool OnButtonReleaseEvent (Gdk.EventButton evnt)
+ {
+ dragging = dragStarted = false;
+ return base.OnButtonReleaseEvent (evnt);
+ }
- if((evnt.Type == Gdk.EventType.ButtonPress) && (evnt.Button == 3))
- {
+ override protected bool OnButtonPressEvent (Gdk.EventButton evnt)
+ {
+ TreePath[] paths = Selection.GetSelectedRows ();
+
+ if ((evnt.Type == Gdk.EventType.ButtonPress) && (evnt.Button == 1)) {
+ base.OnButtonPressEvent (evnt);
+ paths = Selection.GetSelectedRows ();
+ if (paths.Length == 1 && GetValueFromPath (paths [0]) is EventType) {
+ dragging = true;
+ dragStarted = false;
+ startX = (int)evnt.X;
+ startY = (int)evnt.Y;
+ }
+ return true;
+ }
+
+ if ((evnt.Type == Gdk.EventType.ButtonPress) && (evnt.Button == 3)) {
// 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 (paths.Length == 1) {
+ TimeNode selectedTimeNode = GetValueFromPath (paths [0]) as TimeNode;
if (selectedTimeNode != null) {
ShowMenu ();
} else {
- EventType eventType = GetValueFromPath(paths[0]) as EventType;
- SetupSortMenu(eventType.SortMethod);
- categoriesMenu.Popup();
+ EventType eventType = GetValueFromPath (paths [0]) as
EventType;
+ SetupSortMenu (eventType.SortMethod);
+ categoriesMenu.Popup ();
}
- }
- else if(paths.Length > 1) {
+ } else if (paths.Length > 1) {
ShowMenu ();
}
+ } else
+ base.OnButtonPressEvent (evnt);
+ return true;
+ }
+
+ protected override bool OnKeyPressEvent (Gdk.EventKey evnt)
+ {
+ return false;
+ }
+
+ void DisableDragInto (TreePath path, DragContext context, uint time, TreeViewDropPosition pos)
+ {
+ if (pos == TreeViewDropPosition.IntoOrAfter) {
+ pos = TreeViewDropPosition.After;
+ } else if (pos == TreeViewDropPosition.IntoOrBefore) {
+ pos = TreeViewDropPosition.Before;
}
- else
- base.OnButtonPressEvent(evnt);
+ SetDragDestRow (path, pos);
+ dropPos = pos;
+ Gdk.Drag.Status (context, context.SuggestedAction, time);
+ }
+
+ protected override bool OnDragDrop (DragContext context, int x, int y, uint time)
+ {
+ TreePath path;
+ TreeViewDropPosition pos;
+ if (GetDestRowAtPos (x, y, out path, out pos)) {
+ TreeIter destIter;
+
+ Project.EventTypes.Remove (draggedEventType);
+ Project.EventTypes.Insert (path.Indices [0], draggedEventType);
+
+ Model.GetIter (out destIter, path);
+ if (dropPos == TreeViewDropPosition.After) {
+ Model.MoveAfter (srcIter, destIter);
+ } else {
+ Model.MoveBefore (srcIter, destIter);
+ }
+ Refilter ();
+ }
+ Gtk.Drag.Finish (context, true, false, time);
return true;
}
- protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
+ protected override bool OnDragMotion (DragContext context, int x, int y, uint time)
{
+ TreePath path;
+ TreeViewDropPosition pos;
+
+ if (GetDestRowAtPos (x, y, out path, out pos)) {
+ EventType ev = GetValueFromPath (path) as EventType;
+ if (ev != null) {
+ DisableDragInto (path, context, time, pos);
+ return true;
+ } else {
+ return false;
+ }
+ }
return false;
}
+
+ protected override void OnDragBegin (DragContext context)
+ {
+ TreePath path;
+ TreeViewColumn col;
+ int cellX, cellY;
+
+ GetPathAtPos (startX, startY, out path, out col, out cellX, out cellY);
+ draggedEventType = GetValueFromPath (path) as EventType;
+
+
+ if (draggedEventType != null) {
+ GetPathAtPos (startX, startY, out path, out col, out cellX, out cellY);
+ Model.GetIter (out srcIter, path);
+ Pixmap rowPix = CreateRowDragIcon (path);
+ Gtk.Drag.SetIconPixmap (context, rowPix.Colormap, rowPix, null, startX + 1,
cellY + 1);
+ } else {
+ Gtk.Drag.Finish (context, false, false, context.StartTime);
+ }
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]