[longomatch] Add sorting to the projects list
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add sorting to the projects list
- Date: Tue, 28 Oct 2014 09:50:27 +0000 (UTC)
commit 5c4fc72b53778b8a558f7a8e71a9c070551ca0d0
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Tue Oct 21 17:51:46 2014 +0200
Add sorting to the projects list
LongoMatch.GUI/Gui/Component/ProjectListWidget.cs | 124 ++++++++++++--------
.../LongoMatch.Gui.Component.ProjectListWidget.cs | 25 +++-
LongoMatch.GUI/gtk-gui/gui.stetic | 18 +++
3 files changed, 114 insertions(+), 53 deletions(-)
---
diff --git a/LongoMatch.GUI/Gui/Component/ProjectListWidget.cs
b/LongoMatch.GUI/Gui/Component/ProjectListWidget.cs
index 13105ce..998857c 100644
--- a/LongoMatch.GUI/Gui/Component/ProjectListWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/ProjectListWidget.cs
@@ -17,33 +17,22 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
//
-
using System;
using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using Mono.Unix;
+using Gdk;
using Gtk;
-
-using LongoMatch.Core.Common;
using LongoMatch.Core.Handlers;
using LongoMatch.Core.Store;
-using LongoMatch.Video.Utils;
-using Gdk;
-
-
namespace LongoMatch.Gui.Component
{
-
-
[System.ComponentModel.Category("LongoMatch")]
[System.ComponentModel.ToolboxItem(true)]
public partial class ProjectListWidget : Gtk.Bin
{
public event ProjectsSelectedHandler ProjectsSelected;
public event ProjectSelectedHandler ProjectSelected;
-
+
const int COL_DISPLAY_NAME = 0;
const int COL_PIXBUF = 1;
const int COL_PROJECT_DESCRIPTION = 2;
@@ -52,9 +41,9 @@ namespace LongoMatch.Gui.Component
ListStore store;
bool swallowSignals;
- public ProjectListWidget()
+ public ProjectListWidget ()
{
- this.Build();
+ this.Build ();
//GtkGlue.EntrySetIcon (filterEntry, GtkGlue.EntryIconPosition.Secondary,
"gtk-clear");
store = CreateStore ();
@@ -63,6 +52,11 @@ namespace LongoMatch.Gui.Component
iconview.SelectionChanged += OnSelectionChanged;
iconview.ItemActivated += HandleItemActivated;
iconview.ItemWidth = 200;
+ sortcombobox.Changed += (sender, e) => {
+ /* Hack to make it actually resort */
+ store.SetSortColumnId (-2 , SortType.Ascending);
+ store.SetSortColumnId (0, SortType.Ascending);
+ };
}
public SelectionMode SelectionMode {
@@ -70,18 +64,17 @@ namespace LongoMatch.Gui.Component
iconview.SelectionMode = value;
}
}
-
+
public void Fill (List<ProjectDescription> projects)
{
Pixbuf image;
swallowSignals = true;
this.projects = projects;
store.Clear ();
- foreach (ProjectDescription pdesc in projects)
- {
+ foreach (ProjectDescription pdesc in projects) {
if (pdesc.FileSet.Preview != null) {
image = pdesc.FileSet.Preview.Value;
- } else {
+ } else {
image = Stetic.IconLoader.LoadIcon (this, Gtk.Stock.Harddisk,
IconSize.Dialog);
}
store.AppendValues (pdesc.Title, image, pdesc);
@@ -89,9 +82,10 @@ namespace LongoMatch.Gui.Component
swallowSignals = false;
}
- public void RemoveProjects(List<ProjectDescription> projects) {
+ public void RemoveProjects (List<ProjectDescription> projects)
+ {
foreach (ProjectDescription project in projects) {
- this.projects.Remove(project);
+ this.projects.Remove (project);
}
Fill (this.projects);
if (ProjectsSelected != null) {
@@ -99,59 +93,93 @@ namespace LongoMatch.Gui.Component
}
}
- public void ClearSearch() {
- filterEntry.Text="";
+ public void ClearSearch ()
+ {
+ filterEntry.Text = "";
}
-
+
ListStore CreateStore ()
{
- store = new ListStore (typeof (string), typeof (Gdk.Pixbuf), typeof
(ProjectDescription));
- store.DefaultSortFunc = SortFunc;
- store.SetSortColumnId (COL_DISPLAY_NAME, SortType.Ascending);
+ store = new ListStore (typeof(string), typeof(Gdk.Pixbuf),
typeof(ProjectDescription));
+ store.SetSortFunc (0, SortFunc);
+ store.SetSortColumnId (0, SortType.Ascending);
filter = new Gtk.TreeModelFilter (store, null);
filter.VisibleFunc = new Gtk.TreeModelFilterVisibleFunc (FilterTree);
iconview.Model = filter;
return store;
}
+ int CompareString (string s1, string s2)
+ {
+ if (s1 != null && s2 != null) {
+ return s1.CompareTo (s2);
+ } else if (s1 != null) {
+ return 1;
+ } else if (s2 != null) {
+ return - 1;
+ }
+ return 0;
+ }
+
int SortFunc (TreeModel model, TreeIter a, TreeIter b)
{
- ProjectDescription pa = (ProjectDescription) model.GetValue (a,
COL_PROJECT_DESCRIPTION);
- ProjectDescription pb = (ProjectDescription) model.GetValue (b,
COL_PROJECT_DESCRIPTION);
+ ProjectDescription p1, p2;
+
+ p1 = (ProjectDescription)model.GetValue (a, COL_PROJECT_DESCRIPTION);
+ p2 = (ProjectDescription)model.GetValue (b, COL_PROJECT_DESCRIPTION);
+
+ if (p1 == null) {
+ return -1;
+ } else if (p2 == null) {
+ return 1;
+ }
- return (int) (pa.LastModified.Ticks - pb.LastModified.Ticks);
+ if (sortcombobox.Active == 0) {
+ return CompareString (p1.Title, p2.Title);
+ } else if (sortcombobox.Active == 1) {
+ return (int)(p1.MatchDate.Ticks - p2.MatchDate.Ticks);
+ } else if (sortcombobox.Active == 2) {
+ return (int)(p1.LastModified.Ticks - p2.LastModified.Ticks);
+ } else if (sortcombobox.Active == 3) {
+ return CompareString (p1.Season, p2.Season);
+ } else if (sortcombobox.Active == 4) {
+ return CompareString (p1.Competition, p2.Competition);
+ } else {
+ return p1.Title.CompareTo(p2.Title);
+ }
}
-
- protected virtual void OnFilterentryChanged(object sender, System.EventArgs e)
+
+ protected virtual void OnFilterentryChanged (object sender, System.EventArgs e)
{
- filter.Refilter();
+ filter.Refilter ();
}
- private bool FilterTree(Gtk.TreeModel model, Gtk.TreeIter iter)
+ private bool FilterTree (Gtk.TreeModel model, Gtk.TreeIter iter)
{
- ProjectDescription project =(ProjectDescription) model.GetValue(iter,
COL_PROJECT_DESCRIPTION);
+ ProjectDescription project = (ProjectDescription)model.GetValue (iter,
COL_PROJECT_DESCRIPTION);
- if(project == null)
+ if (project == null)
return true;
- if(filterEntry.Text == "")
+ if (filterEntry.Text == "")
return true;
- if(project.Title.IndexOf(filterEntry.Text) > -1)
+ if (project.Title.IndexOf (filterEntry.Text) > -1)
return true;
- else if(project.Season.IndexOf(filterEntry.Text) > -1)
+ else if (project.Season.IndexOf (filterEntry.Text) > -1)
return true;
- else if(project.Competition.IndexOf(filterEntry.Text) > -1)
+ else if (project.Competition.IndexOf (filterEntry.Text) > -1)
return true;
- else if(project.LocalName.IndexOf(filterEntry.Text) > -1)
+ else if (project.LocalName.IndexOf (filterEntry.Text) > -1)
return true;
- else if(project.VisitorName.IndexOf(filterEntry.Text) > -1)
+ else if (project.VisitorName.IndexOf (filterEntry.Text) > -1)
return true;
else
return false;
}
- protected virtual void OnSelectionChanged(object o, EventArgs args) {
+ protected virtual void OnSelectionChanged (object o, EventArgs args)
+ {
TreeIter iter;
List<ProjectDescription> list;
TreePath[] pathArray;
@@ -159,13 +187,13 @@ namespace LongoMatch.Gui.Component
if (swallowSignals)
return;
- if(ProjectsSelected != null) {
- list = new List<ProjectDescription>();
+ if (ProjectsSelected != null) {
+ list = new List<ProjectDescription> ();
pathArray = iconview.SelectedItems;
- for(int i=0; i< pathArray.Length; i++) {
- iconview.Model.GetIterFromString (out iter, pathArray[i].ToString());
- list.Add ((ProjectDescription) iconview.Model.GetValue (iter,
COL_PROJECT_DESCRIPTION));
+ for (int i=0; i< pathArray.Length; i++) {
+ iconview.Model.GetIterFromString (out iter, pathArray [i].ToString
());
+ list.Add ((ProjectDescription)iconview.Model.GetValue (iter,
COL_PROJECT_DESCRIPTION));
}
ProjectsSelected (list);
}
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.ProjectListWidget.cs
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.ProjectListWidget.cs
index 7ec2a23..2331ba2 100644
--- a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.ProjectListWidget.cs
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.ProjectListWidget.cs
@@ -8,6 +8,7 @@ namespace LongoMatch.Gui.Component
private global::Gtk.HBox hbox1;
private global::Gtk.Label filterlabel;
private global::Gtk.Entry filterEntry;
+ private global::Gtk.ComboBox sortcombobox;
private global::Gtk.ScrolledWindow scrolledwindow2;
private global::Gtk.IconView iconview;
@@ -43,11 +44,25 @@ namespace LongoMatch.Gui.Component
this.hbox1.Add (this.filterEntry);
global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(this.hbox1
[this.filterEntry]));
w2.Position = 1;
- this.vbox2.Add (this.hbox1);
- global::Gtk.Box.BoxChild w3 = ((global::Gtk.Box.BoxChild)(this.vbox2 [this.hbox1]));
- w3.Position = 0;
+ // Container child hbox1.Gtk.Box+BoxChild
+ this.sortcombobox = global::Gtk.ComboBox.NewText ();
+ this.sortcombobox.AppendText (global::Mono.Unix.Catalog.GetString ("Sort by name"));
+ this.sortcombobox.AppendText (global::Mono.Unix.Catalog.GetString ("Sort by date"));
+ this.sortcombobox.AppendText (global::Mono.Unix.Catalog.GetString ("Sort by
modification date"));
+ this.sortcombobox.AppendText (global::Mono.Unix.Catalog.GetString ("Sort by season"));
+ this.sortcombobox.AppendText (global::Mono.Unix.Catalog.GetString ("Sort by
competition"));
+ this.sortcombobox.Name = "sortcombobox";
+ this.sortcombobox.Active = 0;
+ this.hbox1.Add (this.sortcombobox);
+ global::Gtk.Box.BoxChild w3 = ((global::Gtk.Box.BoxChild)(this.hbox1
[this.sortcombobox]));
+ w3.Position = 2;
w3.Expand = false;
w3.Fill = false;
+ this.vbox2.Add (this.hbox1);
+ global::Gtk.Box.BoxChild w4 = ((global::Gtk.Box.BoxChild)(this.vbox2 [this.hbox1]));
+ w4.Position = 0;
+ w4.Expand = false;
+ w4.Fill = false;
// Container child vbox2.Gtk.Box+BoxChild
this.scrolledwindow2 = new global::Gtk.ScrolledWindow ();
this.scrolledwindow2.CanFocus = true;
@@ -58,8 +73,8 @@ namespace LongoMatch.Gui.Component
this.iconview.Name = "iconview";
this.scrolledwindow2.Add (this.iconview);
this.vbox2.Add (this.scrolledwindow2);
- global::Gtk.Box.BoxChild w5 = ((global::Gtk.Box.BoxChild)(this.vbox2
[this.scrolledwindow2]));
- w5.Position = 1;
+ global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.vbox2
[this.scrolledwindow2]));
+ w6.Position = 1;
this.Add (this.vbox2);
if ((this.Child != null)) {
this.Child.ShowAll ();
diff --git a/LongoMatch.GUI/gtk-gui/gui.stetic b/LongoMatch.GUI/gtk-gui/gui.stetic
index dd25713..54b7253 100644
--- a/LongoMatch.GUI/gtk-gui/gui.stetic
+++ b/LongoMatch.GUI/gtk-gui/gui.stetic
@@ -45,6 +45,24 @@
<property name="AutoSize">True</property>
</packing>
</child>
+ <child>
+ <widget class="Gtk.ComboBox" id="sortcombobox">
+ <property name="MemberName" />
+ <property name="IsTextCombo">True</property>
+ <property name="Items" translatable="yes">Sort by name
+Sort by date
+Sort by modification date
+Sort by season
+Sort by competition</property>
+ <property name="Active">0</property>
+ </widget>
+ <packing>
+ <property name="Position">2</property>
+ <property name="AutoSize">True</property>
+ <property name="Expand">False</property>
+ <property name="Fill">False</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="Position">0</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]