On Fri, 2008-11-14 at 15:48 -0500, Adam Tauno Williams wrote:
> > This is a follow up to:
> > http://go-mono.com/forums/#nabble-td19464372
> > Mike Kestner wrote:
> > > Now that we have GInterface registration, I think I'd like to move
> > > NodeStore to use an internal managed TreeModel implementation and get
> > > rid of the glue model it currently utilizes. Then the TreeSortable
> > > interface could be implemented in managed code as well to provide
> > > sorting on the NodeStore.
> > > Maybe I'll make that an evening and weekend project, or of course, I'd
> > > be happy to work with anyone who wants to take a stab at it and provide
> > > a patch.
> > Any luck?
> Nothing to my knowledge.
> I'm wondering if it wouldn't, in the end, be easier just to kick
> TreeView and NodeView to the curb and try to use the ListView
> implemented by Banshee (the Hyena subproject)
> <http://www.koders.com/csharp/fid17F12F323AA7D9B9E693343447AF53895134E809.aspx>.
>
Attached is a demo app that uses the beautiful ListView from Hyena; it
sorts, selects, and does a popup menu. IMO, much easier to understand
than TreeView/ListView. Only thing I haven't done yet is filter.
Item.cs - the object managed by the model
Model.cs - the model used by the view, basically a wrapper around IList
View.cs - the view
// Item.cs
//
// Copyright (C) 2008 Whitemice Consulting
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//
using System;
namespace ListView
{
public class Item
{
public Item (int i, Random rand)
{
a = Guid.NewGuid ().ToString ();
b = rand.Next (0, 255);
c = rand.NextDouble ();
d = String.Format ("Item {0}", i);
f = rand.Next (0, 1) == 1;
g = rand.Next (0, 5);
}
string a; public string A { get { return a; } }
int b; public int B { get { return b; } }
double c; public double C { get { return c; } }
string d; public string D { get { return d; } }
bool f; public bool F { get { return f; } set { f = value; } }
int g;
public int G
{
get { return g; }
set
{
Console.WriteLine("Set prop g to value {0}", g);
g = value;
}
}
} // end ModelItem
}
// Main.cs
//
// Copyright (C) 2008 Whitemice Consulting
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//
using System;
using System.Collections;
using System.Collections.Generic;
using Gtk;
using Hyena.Data;
using Hyena.Collections;
using Hyena.Gui;
using Hyena.Data.Gui;
namespace ListView
{
class MainClass
{
public static void Main (string[] args)
{
Application.Init ();
ListView.Window w = new ListView.Window();
Application.Run ();
}
}
}
// Model.cs
//
// Copyright (C) 2008 Whitemice Consulting
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//
using System;
using System.Collections;
using System.Collections.Generic;
using Gtk;
using Hyena.Data;
using Hyena.Collections;
using Hyena.Gui;
using Hyena.Data.Gui;
using Selection = Hyena.Collections.Selection;
namespace ListView
{
public class Model : IListModel<Item>, ISortable
{
private ISortableColumn sortColumn;
private List<Item> store = new List<Item> ();
private Selection selection = new Selection ();
public event EventHandler Cleared;
public event EventHandler Reloaded;
public Model ()
{
Random random = new Random (0);
for (int i = 0; i < 100000; i++) {
store.Add (new Item (i, random));
}
}
public void Clear ()
{
}
public void Reload ()
{
this.Reloaded(this, null);
}
public int Count {
get { return store.Count; }
}
public bool CanReorder {
get { return false; }
}
public Item this[int index] {
get { return store[index]; }
}
public Selection Selection {
get { return selection; }
}
// Sortability
public bool Sort(ISortableColumn column)
{
sortColumn = column;;
store.Sort(
delegate(Item i1, Item i2)
{
int v;
switch(SortColumn.SortKey)
{
case "A": v = i1.A.CompareTo(i2.A); break;
case "G": v = i1.G.CompareTo(i2.G); break;
default: v = 0; break;
}
if (SortColumn.SortType == Hyena.Data.SortType.Descending)
v = (v * (-1));
return v;
});
Console.WriteLine();
return false;
}
public ISortableColumn SortColumn
{
get
{
return sortColumn;
}
}
} // end Model
}
// View.cs
//
// Copyright (C) 2008 Whitemice Consulting
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//
using System;
using System.Collections;
using System.Collections.Generic;
using Gtk;
using Hyena.Data;
using Hyena.Collections;
using Hyena.Gui;
using Hyena.Data.Gui;
namespace ListView
{
public class View : ListView<Item>
{
public View ()
{
ColumnController = new ColumnController ();
ColumnController.AddRange (
new Column (String.Empty, new ColumnCellCheckBox ("F", true), 1),
new Column ("Apples", new ColumnCellText ("B", true), 1),
new Column ("Pears", new ColumnCellText ("C", true), 1),
new SortableColumn("How Hot", new ColumnCellRating("G", true), 1, "G", true),
new Column ("Peaches", new ColumnCellText ("D", true), 1),
new SortableColumn ("GUID", new ColumnCellText ("A", true), 1, "A", true)
);
this.RowActivated += new RowActivatedHandler<Item>(OnRowActivated);
}
protected override bool OnPopupMenu()
{
Console.WriteLine("OnPopupMenu");
if (Selection.Count > 0)
{
Item i = Model[Selection.FirstIndex];
Menu menu = new Menu();
MenuItem item = new MenuItem(i.A);
menu.Append(item);
menu.Popup (null, null, null, 3, Gtk.Global.CurrentEventTime);
menu.ShowAll();
} else Console.WriteLine("No selection!");
return true;
}
public void OnRowActivated(object sender, RowActivatedArgs<Item> args)
{
Console.WriteLine("Activated {0}", args.RowValue.A);
}
} // end View
}
// Window.cs
//
// Copyright (C) 2008 Whitemice Consulting
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//
using System;
using System.Collections;
using System.Collections.Generic;
using Gtk;
using Hyena.Data;
using Hyena.Collections;
using Hyena.Gui;
using Hyena.Data.Gui;
namespace ListView
{
public class Window : Gtk.Window
{
View view;
Model model;
public Window() : base("ListView")
{
WindowPosition = WindowPosition.Center;
SetDefaultSize (800, 600);
ScrolledWindow scroll = new ScrolledWindow ();
scroll.HscrollbarPolicy = PolicyType.Automatic;
scroll.VscrollbarPolicy = PolicyType.Automatic;
view = new ListView.View ();
model = new ListView.Model ();
view.SetModel (model);
view.Selection.Changed += SelectionChanged;
scroll.Add (view);
Add (scroll);
ShowAll();
} // end ctor
public void SelectionChanged(object sender, EventArgs e)
{
Console.WriteLine("Selection changed");
}
} // end Window
}
_______________________________________________
Gtk-sharp-list maillist - Gtk-sharp-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list