fix invaliid iter in DemoMain

some lame StockBrowser stuff

svn path=/trunk/gtk-sharp/; revision=32971
This commit is contained in:
John Luke 2004-08-28 20:04:41 +00:00
parent 282649ead0
commit 6cf715ac84
2 changed files with 79 additions and 14 deletions

View file

@ -22,7 +22,7 @@ namespace GtkDemo
private TextBuffer sourceBuffer = new TextBuffer (null); private TextBuffer sourceBuffer = new TextBuffer (null);
private TreeView treeView; private TreeView treeView;
private TreeStore store; private TreeStore store;
private TreeIter oldSelection; private TreeIter oldSelection = TreeIter.Zero;
public static void Main (string[] args) public static void Main (string[] args)
{ {
@ -194,6 +194,7 @@ namespace GtkDemo
LoadFile (file); LoadFile (file);
model.SetValue (iter, 2, true); model.SetValue (iter, 2, true);
if (!oldSelection.Equals (TreeIter.Zero))
model.SetValue (oldSelection, 2, false); model.SetValue (oldSelection, 2, false);
oldSelection = iter; oldSelection = iter;
} }

View file

@ -6,6 +6,7 @@
// (C) 2003 Ximian, Inc. // (C) 2003 Ximian, Inc.
using System; using System;
using System.Collections;
using Gtk; using Gtk;
namespace GtkDemo namespace GtkDemo
@ -36,13 +37,29 @@ namespace GtkDemo
list.Selection.Changed += new EventHandler (OnSelectionChanged); list.Selection.Changed += new EventHandler (OnSelectionChanged);
scrolledWindow.Add (list); scrolledWindow.Add (list);
Frame frame = new Frame ("Selected Item"); hbox.PackStart (CreateFrame (), false, false, 0);
frame.Add (new Label ("TODO"));
hbox.PackStart (frame, false, false, 0);
this.ShowAll (); this.ShowAll ();
} }
Frame CreateFrame ()
{
// Icon and Item / Icon Only / ???
// icon / blank
// _Add / blank
// Gtk.Stock.Cancel
// gtk-stock-cancel
Frame frame = new Frame ("Selected Item");
VBox vbox = new VBox (false, 3);
vbox.PackStart (new Label ("???"), false, true, 0);
vbox.PackStart (new Image (), false, true, 0);
vbox.PackStart (new Label ("_Add"), false, true, 0);
vbox.PackStart (new Label ("Gtk.Stock.Add"), false, true, 0);
vbox.PackStart (new Label ("gtk-stock-add"), false, true, 0);
frame.Add (vbox);
return frame;
}
private ListStore CreateStore () private ListStore CreateStore ()
{ {
// image, name, label, accel, id // image, name, label, accel, id
@ -54,30 +71,76 @@ namespace GtkDemo
{ {
Gtk.StockItem si = new StockItem (); Gtk.StockItem si = new StockItem ();
if (Gtk.StockManager.Lookup (s, ref si)) { if (Gtk.StockManager.Lookup (s, ref si)) {
Image icon = new Image (s, IconSize.Menu); Gdk.Pixbuf icon = new Image (s, IconSize.Menu).RenderIcon (s, IconSize.Menu, "");
// FIXME: si.Label needs to _AccelAware
store.AppendValues (icon, GetCLSName (si.StockId), si.Label, GetKeyName (si), si.StockId); store.AppendValues (icon, GetCLSName (si.StockId), si.Label, GetKeyName (si), si.StockId);
} }
else { else {
Console.WriteLine ("StockItem '{0}' could not be found.", s); //Console.WriteLine ("StockItem '{0}' could not be found.", s);
} }
} }
return store; return store;
} }
// changes 'gtk-stock-close' into 'Gtk.Stock.Close'
// should use StudlyCaps from gapi2xml.pl instead
string GetCLSName (string stockID) string GetCLSName (string stockID)
{ {
// TODO: change gtk-stock-close string cls = "";
// int Gtk.Stock.Close if (stockID.StartsWith ("gtk-"))
return stockID; cls = stockID.Substring (4, stockID.Length - 4);
char[] split = cls.ToCharArray ();
bool raiseNext = false;
ArrayList tmp = new ArrayList ();
tmp.Add (char.ToUpper (split[0]));
for (int i = 1; i < split.Length; i ++)
{
if (split[i] == '-') {
raiseNext = true;
continue;
} }
string GetKeyName (StockItem si) if (raiseNext) {
{ tmp.Add (char.ToUpper (split[i]));
// TODO: use si.Keyval and si.Modifier raiseNext = false;
}
else {
tmp.Add (split[i]);
}
}
split = new char[tmp.Count];
int j = 0;
foreach (char c in tmp)
split[j++] = c;
return "Gtk.Stock." + new string (split);
}
// use si.Keyval and si.Modifier
// to produce a reasonable representation // to produce a reasonable representation
// of the key binding // of the key binding
return "<ctl> + key"; string GetKeyName (StockItem si)
{
string mod = "";
string key = "";
switch (si.Modifier) {
// seems to be the only one used
case Gdk.ModifierType.ControlMask:
mod = "<Control>";
break;
default:
break;
}
if (si.Keyval > 0)
key = Gdk.Keyval.Name (si.Keyval);
return String.Format ("{0} {1}", mod, key);
} }
void OnSelectionChanged (object o, EventArgs args) void OnSelectionChanged (object o, EventArgs args)
@ -99,3 +162,4 @@ namespace GtkDemo
} }
} }
} }