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 namespace GtkDemo
{ {
[Demo ("Application Window", "DemoApplicationWindow.cs")]
public class DemoApplicationWindow : Window public class DemoApplicationWindow : Window
{ {
// for the statusbar // 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 namespace GtkDemo
{ {
[Demo ("Button Boxes", "DemoButtonBox.cs")]
public class DemoButtonBox : Gtk.Window public class DemoButtonBox : Gtk.Window
{ {
public DemoButtonBox () : base ("Button Boxes") public DemoButtonBox () : base ("Button Boxes")

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,6 +6,7 @@
// Copyright (C) 2003, Ximian Inc. // Copyright (C) 2003, Ximian Inc.
using System; using System;
using System.Collections;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
@ -154,33 +155,34 @@ namespace GtkDemo
private TreeStore FillTree () private TreeStore FillTree ()
{ {
// title, filename, italic // title, filename, italic
store = new TreeStore (typeof (string), typeof (string), typeof (bool)); store = new TreeStore (typeof (string), typeof (System.Type), typeof (bool));
Hashtable parents = new Hashtable ();
TreeIter parent; TreeIter parent;
store.AppendValues ("Application Window", "DemoApplicationWindow.cs", false); Type[] types = Assembly.GetExecutingAssembly ().GetTypes ();
store.AppendValues ("Button Boxes", "DemoButtonBox.cs", false); foreach (Type t in types)
store.AppendValues ("Change Display (0%)", "DemoChangeDisplay.cs", false); {
store.AppendValues ("Clipboard", "DemoClipboard.cs", false); if (t.IsDefined (typeof (DemoAttribute), false))
store.AppendValues ("Color Selector", "DemoColorSelection.cs", false); {
store.AppendValues ("Dialog and Message Boxes", "DemoDialog.cs", false); object[] att = t.GetCustomAttributes (typeof (DemoAttribute), false);
store.AppendValues ("Drawing Area", "DemoDrawingArea.cs", false); foreach (DemoAttribute demo in att)
store.AppendValues ("Entry Completion", "DemoEntryCompletion.cs", false); {
store.AppendValues ("Expander", "DemoExpander.cs", false); if (demo.Parent != null)
store.AppendValues ("Images", "DemoImages.cs", false); {
store.AppendValues ("Menus", "DemoMenus.cs", false); if (!parents.Contains (demo.Parent))
store.AppendValues ("Paned Widget", "DemoPanes.cs", false); parents.Add (demo.Parent, store.AppendValues (demo.Parent));
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);
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; return store;
} }
@ -191,9 +193,13 @@ namespace GtkDemo
if (treeView.Selection.GetSelected (out model, out iter)) if (treeView.Selection.GetSelected (out model, out iter))
{ {
string file = (string) model.GetValue (iter, 1); Type type = (Type) model.GetValue (iter, 1);
if (file != null) if (type != null)
{
object[] atts = type.GetCustomAttributes (typeof (DemoAttribute), false);
string file = ((DemoAttribute) atts[0]).Filename;
LoadFile (file); LoadFile (file);
}
model.SetValue (iter, 2, true); model.SetValue (iter, 2, true);
if (!oldSelection.Equals (TreeIter.Zero)) if (!oldSelection.Equals (TreeIter.Zero))
@ -204,88 +210,14 @@ namespace GtkDemo
private void OnRowActivated (object o, RowActivatedArgs args) private void OnRowActivated (object o, RowActivatedArgs args)
{ {
switch (args.Path.ToString ()) { TreeIter iter;
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;
}
}
void ToggleRow (TreePath path) if (treeView.Model.GetIter (out iter, args.Path))
{ {
bool isExpanded = treeView.GetRowExpanded (path); Type type = (Type) treeView.Model.GetValue (iter, 1);
if (isExpanded) if (type != null)
treeView.CollapseRow (path); Activator.CreateInstance (type);
else }
treeView.ExpandRow (path, false);
} }
private void WindowDelete (object o, DeleteEventArgs args) private void WindowDelete (object o, DeleteEventArgs args)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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