use reflection to handle the TreeView and launching of the demos

Add a DemoAttribute to all the demos to support this

svn path=/trunk/gtk-sharp/; revision=37669
This commit is contained in:
John Luke 2004-12-12 22:11:44 +00:00
parent 304f9404b4
commit 4da41dbe67
24 changed files with 110 additions and 123 deletions

View File

@ -17,6 +17,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("Application Window", "DemoApplicationWindow.cs")]
public class DemoApplicationWindow : Window
{
// for the statusbar

View File

@ -0,0 +1,36 @@
using System;
namespace GtkDemo
{
[AttributeUsage (AttributeTargets.Class)]
public class DemoAttribute : Attribute
{
string label, filename, parent;
public DemoAttribute (string label, string filename) : this (label, filename, null)
{
}
public DemoAttribute (string label, string filename, string parent)
{
this.label = label;
this.filename = filename;
this.parent = parent;
}
public string Filename {
get { return filename; }
}
public string Label {
get { return label; }
}
public string Parent {
get {
return parent;
}
}
}
}

View File

@ -16,6 +16,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("Button Boxes", "DemoButtonBox.cs")]
public class DemoButtonBox : Gtk.Window
{
public DemoButtonBox () : base ("Button Boxes")

View File

@ -3,6 +3,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("Clipboard", "DemoClipboard.cs")]
public class DemoClipboard : Gtk.Window
{
Entry pasteEntry, copyEntry;

View File

@ -18,6 +18,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("Color Selection", "DemoColorSelection.cs")]
public class DemoColorSelection : Gtk.Window
{
private Gdk.Color color;

View File

@ -22,6 +22,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("Dialog and Message Boxes", "DemoDialog.cs")]
public class DemoDialog : Gtk.Window
{
private Entry entry1;

View File

@ -28,6 +28,7 @@ using Gdk;
namespace GtkDemo
{
[Demo ("Drawing Area", "DemoDrawingArea.cs")]
public class DemoDrawingArea : Gtk.Window
{
private static Pixmap pixmap = null;

View File

@ -20,6 +20,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("Editable Cells", "DemoEditableCells.cs", "Tree View")]
public class DemoEditableCells : Gtk.Window
{
private ListStore store;

View File

@ -3,6 +3,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("Entry Completion", "DemoEntryCompletion.cs")]
public class DemoEntryCompletion : Dialog
{
public DemoEntryCompletion () : base ("Demo Entry Completion", null, DialogFlags.DestroyWithParent)

View File

@ -3,6 +3,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("Expander", "DemoExpander.cs")]
public class DemoExpander : Gtk.Dialog
{
public DemoExpander () : base ("Demo Expander", null, DialogFlags.DestroyWithParent)

View File

@ -9,6 +9,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("Hyper Text", "DemoHyperText.cs", "Text Widget")]
public class DemoHyperText : Gtk.Window
{
bool hoveringOverLink = false;

View File

@ -34,6 +34,7 @@ using Gdk;
namespace GtkDemo
{
[Demo ("Images", "DemoImages.cs")]
public class DemoImages : Gtk.Window
{
private Gtk.Image progressiveImage;

View File

@ -21,6 +21,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("List Store", "DemoListStore.cs", "Tree View")]
public class DemoListStore : Gtk.Window
{
ListStore store;

View File

@ -6,6 +6,7 @@
// Copyright (C) 2003, Ximian Inc.
using System;
using System.Collections;
using System.IO;
using System.Reflection;
@ -154,139 +155,70 @@ namespace GtkDemo
private TreeStore FillTree ()
{
// title, filename, italic
store = new TreeStore (typeof (string), typeof (string), typeof (bool));
TreeIter parent;
store = new TreeStore (typeof (string), typeof (System.Type), typeof (bool));
Hashtable parents = new Hashtable ();
TreeIter parent;
store.AppendValues ("Application Window", "DemoApplicationWindow.cs", false);
store.AppendValues ("Button Boxes", "DemoButtonBox.cs", false);
store.AppendValues ("Change Display (0%)", "DemoChangeDisplay.cs", false);
store.AppendValues ("Clipboard", "DemoClipboard.cs", false);
store.AppendValues ("Color Selector", "DemoColorSelection.cs", false);
store.AppendValues ("Dialog and Message Boxes", "DemoDialog.cs", false);
store.AppendValues ("Drawing Area", "DemoDrawingArea.cs", false);
store.AppendValues ("Entry Completion", "DemoEntryCompletion.cs", false);
store.AppendValues ("Expander", "DemoExpander.cs", false);
store.AppendValues ("Images", "DemoImages.cs", false);
store.AppendValues ("Menus", "DemoMenus.cs", false);
store.AppendValues ("Paned Widget", "DemoPanes.cs", false);
store.AppendValues ("Pixbuf", "DemoPixbuf.cs", false);
store.AppendValues ("Size Groups", "DemoSizeGroup.cs", false);
store.AppendValues ("Stock Item and Icon Browser (10% complete)", "DemoStockBrowser.cs", false);
parent = store.AppendValues ("Text Widget");
store.AppendValues (parent, "HyperText (50%)", "DemoHyperText.cs", false);
store.AppendValues (parent, "Multiple Views", "DemoTextView.cs", false);
parent = store.AppendValues ("Tree View");
store.AppendValues (parent, "Editable Cells", "DemoEditableCells.cs", false);
store.AppendValues (parent, "List Store", "DemoListStore.cs", false);
store.AppendValues (parent, "Tree Store", "DemoTreeStore.cs", false);
store.AppendValues ("UIManager", "DemoUIManager.cs", false);
Type[] types = Assembly.GetExecutingAssembly ().GetTypes ();
foreach (Type t in types)
{
if (t.IsDefined (typeof (DemoAttribute), false))
{
object[] att = t.GetCustomAttributes (typeof (DemoAttribute), false);
foreach (DemoAttribute demo in att)
{
if (demo.Parent != null)
{
if (!parents.Contains (demo.Parent))
parents.Add (demo.Parent, store.AppendValues (demo.Parent));
parent = (TreeIter) parents[demo.Parent];
store.AppendValues (parent, demo.Label, t, false);
}
else
{
store.AppendValues (demo.Label, t, false);
}
}
}
}
store.SetSortColumnId (0, SortType.Ascending);
return store;
}
private void OnTreeChanged (object o, EventArgs args)
{
TreeIter iter;
TreeModel model;
if (treeView.Selection.GetSelected (out model, out iter))
{
string file = (string) model.GetValue (iter, 1);
if (file != null)
LoadFile (file);
TreeIter iter;
TreeModel model;
model.SetValue (iter, 2, true);
if (!oldSelection.Equals (TreeIter.Zero))
model.SetValue (oldSelection, 2, false);
oldSelection = iter;
}
if (treeView.Selection.GetSelected (out model, out iter))
{
Type type = (Type) model.GetValue (iter, 1);
if (type != null)
{
object[] atts = type.GetCustomAttributes (typeof (DemoAttribute), false);
string file = ((DemoAttribute) atts[0]).Filename;
LoadFile (file);
}
model.SetValue (iter, 2, true);
if (!oldSelection.Equals (TreeIter.Zero))
model.SetValue (oldSelection, 2, false);
oldSelection = iter;
}
}
private void OnRowActivated (object o, RowActivatedArgs args)
{
switch (args.Path.ToString ()) {
case "0":
new DemoApplicationWindow ();
break;
case "1":
new DemoButtonBox ();
break;
case "2":
//
break;
case "3":
new DemoClipboard ();
break;
case "4":
new DemoColorSelection ();
break;
case "5":
new DemoDialog ();
break;
case "6":
new DemoDrawingArea ();
break;
case "7":
new DemoEntryCompletion ();
break;
case "8":
new DemoExpander ();
break;
case "9":
new DemoImages ();
break;
case "10":
new DemoMenus ();
break;
case "11":
new DemoPanes ();
break;
case "12":
new DemoPixbuf ();
break;
case "13":
new DemoSizeGroup ();
break;
case "14":
new DemoStockBrowser ();
break;
case "15":
ToggleRow (args.Path);
break;
case "15:0":
new DemoHyperText ();
break;
case "15:1":
new DemoTextView ();
break;
case "16":
ToggleRow (args.Path);
break;
case "16:0":
new DemoEditableCells ();
break;
case "16:1":
new DemoListStore ();
break;
case "16:2":
new DemoTreeStore ();
break;
case "17":
new DemoUIManager ();
break;
default:
break;
}
}
TreeIter iter;
void ToggleRow (TreePath path)
{
bool isExpanded = treeView.GetRowExpanded (path);
if (isExpanded)
treeView.CollapseRow (path);
else
treeView.ExpandRow (path, false);
}
if (treeView.Model.GetIter (out iter, args.Path))
{
Type type = (Type) treeView.Model.GetValue (iter, 1);
if (type != null)
Activator.CreateInstance (type);
}
}
private void WindowDelete (object o, DeleteEventArgs args)
{

View File

@ -45,6 +45,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("Menus", "DemoMenus.cs")]
public class DemoMenus : Gtk.Window
{
public DemoMenus () : base ("Menus")

View File

@ -26,6 +26,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("Paned Widget", "DemoPanes.cs")]
public class DemoPanes : Gtk.Window
{
private VPaned vpaned;

View File

@ -27,7 +27,7 @@ using System;
namespace GtkDemo
{
[Demo ("Pixbuf", "DemoPixbuf.cs")]
public class DemoPixbuf : Gtk.Window
{
const int FrameDelay = 50;

View File

@ -26,6 +26,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("Size Group", "DemoSizeGroup.cs")]
public class DemoSizeGroup : Dialog
{
private SizeGroup sizeGroup;

View File

@ -11,6 +11,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("Stock Item and Icon Browser", "DemoStockBrowser.cs")]
public class DemoStockBrowser : Gtk.Window
{
class StockInfo

View File

@ -21,6 +21,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("Multiple Views", "DemoTextView.cs", "Text Widget")]
public class DemoTextView : Gtk.Window
{
TextView view1;

View File

@ -22,6 +22,7 @@ using GLib;
namespace GtkDemo
{
[Demo ("TreeStore", "DemoTreeStore.cs", "Tree View")]
public class DemoTreeStore : Gtk.Window
{
private TreeStore store;

View File

@ -3,6 +3,7 @@ using Gtk;
namespace GtkDemo
{
[Demo ("UIManager", "DemoUIManager.cs")]
public class DemoUIManager : Window
{
VBox vbox;

View File

@ -8,6 +8,7 @@ EXTRA_DIST = $(sources) $(image_names)
sources = \
DemoApplicationWindow.cs \
DemoAttribute.cs \
DemoButtonBox.cs \
DemoClipboard.cs \
DemoColorSelection.cs \

View File

@ -3,7 +3,6 @@ General
DemoMain
- syntax highlighting
- use reflection to fill the tree/launch demos
DemoStockBrowser
- underline _label properly