From 8db4e785aacec6159c83a9ab7702de50e68103b0 Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Sat, 3 Nov 2012 18:34:22 +0100 Subject: [PATCH] Update samples to use generic collections --- sample/Actions.cs | 6 +++--- sample/GtkDemo/DemoEditableCells.cs | 10 +++++----- sample/GtkDemo/DemoHyperText.cs | 9 ++++----- sample/GtkDemo/DemoMain.cs | 8 ++++---- sample/GtkDemo/DemoPanes.cs | 8 ++++---- sample/PolarFixed.cs | 6 +++--- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/sample/Actions.cs b/sample/Actions.cs index cc25aaaa7..f9880c12a 100644 --- a/sample/Actions.cs +++ b/sample/Actions.cs @@ -8,7 +8,7 @@ namespace GtkSamples { using Gtk; using System; - using System.Collections; + using System.Collections.Generic; public class Actions { static VBox box = null; @@ -19,7 +19,7 @@ namespace GtkSamples { static ActionGroup dynGroup = null; static uint mergeId = 0; static UIManager uim = null; - static Hashtable actions = new Hashtable (); + static Dictionary actions = new Dictionary (); /* XML description of the menus for the test app. The parser understands * a subset of the Bonobo UI XML format, and uses GMarkup for parsing */ @@ -299,7 +299,7 @@ namespace GtkSamples { static void OnSelect (object obj, EventArgs args) { - Gtk.Action action = (Gtk.Action) actions[obj]; + Gtk.Action action = actions[(Widget)obj]; if (action.Tooltip != null) statusbar.Push (0, action.Tooltip); } diff --git a/sample/GtkDemo/DemoEditableCells.cs b/sample/GtkDemo/DemoEditableCells.cs index df88ee485..56848af13 100644 --- a/sample/GtkDemo/DemoEditableCells.cs +++ b/sample/GtkDemo/DemoEditableCells.cs @@ -7,7 +7,7 @@ */ using System; -using System.Collections; +using System.Collections.Generic; using Gtk; namespace GtkDemo @@ -17,7 +17,7 @@ namespace GtkDemo { private ListStore store; private TreeView treeView; - private ArrayList articles; + private IList articles; public DemoEditableCells () : base ("Shopping list") { @@ -82,7 +82,7 @@ namespace GtkDemo private ListStore CreateModel () { // create array - articles = new ArrayList (); + articles = new List (); AddItems (); // create list store @@ -130,7 +130,7 @@ namespace GtkDemo Item foo; try { - foo = (Item) articles[i]; + foo = articles[i]; foo.Number = int.Parse (args.NewText); } catch (Exception e) { Console.WriteLine (e); @@ -147,7 +147,7 @@ namespace GtkDemo store.GetIter (out iter, path); int i = path.Indices[0]; - Item foo = (Item) articles[i]; + Item foo = articles[i]; foo.Product = args.NewText; store.SetValue (iter, (int) Column.Product, foo.Product); } diff --git a/sample/GtkDemo/DemoHyperText.cs b/sample/GtkDemo/DemoHyperText.cs index a657aaf20..4efd34edd 100644 --- a/sample/GtkDemo/DemoHyperText.cs +++ b/sample/GtkDemo/DemoHyperText.cs @@ -7,7 +7,7 @@ */ using System; -using System.Collections; +using System.Collections.Generic; using Gtk; namespace GtkDemo @@ -41,7 +41,7 @@ namespace GtkDemo ShowAll (); } - Hashtable tag_pages = new Hashtable (); + Dictionary tag_pages = new Dictionary (); // Inserts a piece of text into the buffer, giving it the usual // appearance of a hyperlink in a web browser: blue and underlined. @@ -100,9 +100,8 @@ namespace GtkDemo void FollowIfLink (TextView view, TextIter iter) { foreach (TextTag tag in iter.Tags) { - object page = tag_pages [tag]; - if (page is int) - ShowPage (view.Buffer, (int)page); + int page = tag_pages [tag]; + ShowPage (view.Buffer, (int)page); } } diff --git a/sample/GtkDemo/DemoMain.cs b/sample/GtkDemo/DemoMain.cs index b2b39dd29..961be1d69 100644 --- a/sample/GtkDemo/DemoMain.cs +++ b/sample/GtkDemo/DemoMain.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using System.Reflection; @@ -197,7 +197,7 @@ namespace GtkDemo { // title, filename, italic store = new TreeStore (typeof (string), typeof (System.Type), typeof (bool)); - Hashtable parents = new Hashtable (); + Dictionary parents = new Dictionary (); TreeIter parent; Type[] types = Assembly.GetExecutingAssembly ().GetTypes (); @@ -205,10 +205,10 @@ namespace GtkDemo object[] att = t.GetCustomAttributes (typeof (DemoAttribute), false); foreach (DemoAttribute demo in att) { if (demo.Parent != null) { - if (!parents.Contains (demo.Parent)) + if (!parents.ContainsKey (demo.Parent)) parents.Add (demo.Parent, store.AppendValues (demo.Parent)); - parent = (TreeIter) parents[demo.Parent]; + parent = parents[demo.Parent]; store.AppendValues (parent, demo.Label, t, false); } else { store.AppendValues (demo.Label, t, false); diff --git a/sample/GtkDemo/DemoPanes.cs b/sample/GtkDemo/DemoPanes.cs index 66f972c73..72db744eb 100644 --- a/sample/GtkDemo/DemoPanes.cs +++ b/sample/GtkDemo/DemoPanes.cs @@ -13,7 +13,7 @@ using System; -using System.Collections; +using System.Collections.Generic; using Gtk; namespace GtkDemo @@ -21,7 +21,7 @@ namespace GtkDemo [Demo ("Paned Widget", "DemoPanes.cs")] public class DemoPanes : Gtk.Window { - Hashtable children = new Hashtable (); + Dictionary children = new Dictionary (); public DemoPanes () : base ("Panes") { @@ -113,7 +113,7 @@ namespace GtkDemo private void ToggleResize (object obj, EventArgs args) { ToggleButton toggle = obj as ToggleButton; - Widget child = children[obj] as Widget; + Widget child = children[toggle]; Paned paned = child.Parent as Paned; Paned.PanedChild pc = paned[child] as Paned.PanedChild; @@ -123,7 +123,7 @@ namespace GtkDemo private void ToggleShrink (object obj, EventArgs args) { ToggleButton toggle = obj as ToggleButton; - Widget child = children[obj] as Widget; + Widget child = children[toggle]; Paned paned = child.Parent as Paned; Paned.PanedChild pc = paned[child] as Paned.PanedChild; diff --git a/sample/PolarFixed.cs b/sample/PolarFixed.cs index 5a3462dad..8c7b002db 100644 --- a/sample/PolarFixed.cs +++ b/sample/PolarFixed.cs @@ -1,16 +1,16 @@ // This is a completely pointless widget, but it shows how to subclass container... using System; -using System.Collections; +using System.Collections.Generic; using Gtk; using Gdk; class PolarFixed : Container { - ArrayList children; + IList children; public PolarFixed () { - children = new ArrayList (); + children = new List (); HasWindow = false; }