Index: PluginManager.cs
===================================================================
RCS file: /cvs/gnome/tomboy/Tomboy/PluginManager.cs,v
retrieving revision 1.18
diff -u -p -u -r1.18 PluginManager.cs
--- PluginManager.cs	6 Sep 2006 18:47:51 -0000	1.18
+++ PluginManager.cs	29 Nov 2006 20:06:43 -0000
@@ -1,6 +1,6 @@
 
 using System;
-using System.Collections;
+using System.Collections.Generic;
 using System.Diagnostics;
 using System.Reflection;
 using System.IO;
@@ -8,11 +8,16 @@ using Mono.Unix.Native;
 
 namespace Tomboy
 {
-	public abstract class NotePlugin : IDisposable
+	public interface IPlugin : IDisposable
+	{
+	}
+
+	public abstract class NotePlugin : IPlugin
 	{
 		Note note;
-		ArrayList plugin_menu_items;
-		ArrayList text_menu_items;
+
+		List<Gtk.MenuItem> plugin_menu_items;
+		List<Gtk.MenuItem> text_menu_items;
 
 		public void Initialize (Note note)
 		{
@@ -93,7 +98,7 @@ namespace Tomboy
 		public void AddPluginMenuItem (Gtk.MenuItem item)
 		{
 			if (plugin_menu_items == null)
-				plugin_menu_items = new ArrayList ();
+				plugin_menu_items = new List<Gtk.MenuItem> ();
 
 			plugin_menu_items.Add (item);
 
@@ -104,7 +109,7 @@ namespace Tomboy
 		public void AddTextMenuItem (Gtk.MenuItem item)
 		{
 			if (text_menu_items == null)
-				text_menu_items = new ArrayList ();
+				text_menu_items = new List<Gtk.MenuItem> ();
 
 			text_menu_items.Add (item);
 
@@ -118,8 +123,8 @@ namespace Tomboy
 	public class PluginManager
 	{
 		string plugins_dir;
-		ArrayList plugin_types;
-		Hashtable plugin_hash;
+		IList<Type> plugin_types;
+		IDictionary<Note, IList<NotePlugin>> plugin_hash;
 		FileSystemWatcher dir_watcher;
 		FileSystemWatcher sys_dir_watcher;
 
@@ -166,7 +171,7 @@ namespace Tomboy
 			}
 			
 			plugin_types = FindPluginTypes ();
-			plugin_hash = new Hashtable ();
+			plugin_hash = new Dictionary<Note, IList<NotePlugin>>();
 		}
 
 		// Run file manager for ~/.tomboy/Plugins
@@ -203,18 +208,20 @@ namespace Tomboy
 
 		public void LoadPluginsForNote (Note note)
 		{
-			ArrayList note_plugins = new ArrayList ();
+			List<NotePlugin> note_plugins = new List<NotePlugin> ();
 
 			foreach (Type type in plugin_types) {
-				try {
-					NotePlugin plugin = (NotePlugin) 
-						Activator.CreateInstance (type);
-					if (plugin != null) {
-						plugin.Initialize (note);
-						note_plugins.Add (plugin);
+				if (typeof (NotePlugin).IsAssignableFrom (type)) {
+					try {
+						NotePlugin plugin = (NotePlugin) 
+							Activator.CreateInstance (type);
+						if (plugin != null) {
+							plugin.Initialize (note);
+							note_plugins.Add (plugin);
+						}
+					} catch (Exception e) {
+						// Do nothing
 					}
-				} catch (Exception e) {
-					// Do nothing
 				}
 			}
 
@@ -301,11 +308,17 @@ namespace Tomboy
 		void OnNoteDeleted (object sender, Note deleted)
 		{
 			// Clean out the plugins for this deleted note.
-			ArrayList note_plugins = (ArrayList) plugin_hash [deleted];
+			IList<NotePlugin> note_plugins = plugin_hash [deleted];
 
 			if (note_plugins != null) {
 				foreach (NotePlugin plugin in note_plugins) {
-					plugin.Dispose ();
+					try {
+						plugin.Dispose ();
+					} catch (Exception e) {
+						Logger.Fatal (
+							"Failed to dispose instance of {0}: {1}", 
+							plugin.GetType(), e);
+					}
 				}
 
 				note_plugins.Clear ();
@@ -319,7 +332,7 @@ namespace Tomboy
 			Logger.Log ("Plugin '{0}' Created", 
 					   Path.GetFileName (args.FullPath));
 
-			ArrayList asm_plugins = FindPluginTypesInFile (args.FullPath);
+			IList<Type> asm_plugins = FindPluginTypesInFile (args.FullPath);
 
 			// Add the plugin to the list
 			foreach (Type type in asm_plugins) {
@@ -336,7 +349,7 @@ namespace Tomboy
 
 					plugin.Initialize (note);
 
-					ArrayList note_plugins = (ArrayList) plugin_hash [note];
+					IList<NotePlugin> note_plugins = plugin_hash [note];
 					note_plugins.Add (plugin);
 				}
 			}
@@ -349,7 +362,7 @@ namespace Tomboy
 			Logger.Log ("Plugin '{0}' Deleted", 
 					   Path.GetFileName (args.FullPath));
 
-			ArrayList kill_list = new ArrayList ();
+			List<Type> kill_list = new List<Type> ();
 
 			// Find the plugins in the deleted assembly
 			foreach (Type type in plugin_types) {
@@ -363,7 +376,7 @@ namespace Tomboy
 			}
 
 			foreach (Note note in plugin_hash.Keys) {
-				ArrayList note_plugins = (ArrayList) plugin_hash [note];
+				IList<NotePlugin> note_plugins = plugin_hash [note];
 
 				for (int i = 0; i < note_plugins.Count; i++) {
 					NotePlugin plugin = (NotePlugin) note_plugins [i];
@@ -379,9 +392,9 @@ namespace Tomboy
 			kill_list.Clear ();
 		}
 
-		ArrayList FindPluginTypes ()
+		IList<Type> FindPluginTypes ()
 		{
-			ArrayList all_plugin_types = new ArrayList ();
+			IList<Type> all_plugin_types = new List<Type> ();
 
 			// Load the stock plugins
 			foreach (Type type in stock_plugins) {
@@ -389,14 +402,14 @@ namespace Tomboy
 			}
 
 			// Load system default plugins
-			ArrayList sys_plugin_types;
+			IList<Type> sys_plugin_types;
 			sys_plugin_types = FindPluginTypesInDirectory (Defines.SYS_PLUGINS_DIR);
 			foreach (Type type in sys_plugin_types) {
 				all_plugin_types.Add (type);
 			}
 
 			// Load user's plugins
-			ArrayList user_plugin_types = FindPluginTypesInDirectory (plugins_dir);
+			IList<Type> user_plugin_types = FindPluginTypesInDirectory (plugins_dir);
 			foreach (Type type in user_plugin_types) {
 				all_plugin_types.Add (type);
 			}
@@ -404,9 +417,9 @@ namespace Tomboy
 			return all_plugin_types;
 		}
 
-		static ArrayList FindPluginTypesInDirectory (string dirpath)
+		static IList<Type> FindPluginTypesInDirectory (string dirpath)
 		{
-			ArrayList dir_plugin_types = new ArrayList ();
+			IList<Type> dir_plugin_types = new List<Type> ();
 			string [] files;
 			
 			try {
@@ -422,7 +435,7 @@ namespace Tomboy
 				Console.Write ("Trying Plugin: {0} ... ", Path.GetFileName (file));
 				
 				try {
-					ArrayList asm_plugins = FindPluginTypesInFile (file);
+					IList<Type> asm_plugins = FindPluginTypesInFile (file);
 					foreach (Type type in asm_plugins) {
 						dir_plugin_types.Add (type);
 					}
@@ -434,20 +447,20 @@ namespace Tomboy
 			return dir_plugin_types;
 		}
 
-		static ArrayList FindPluginTypesInFile (string filepath)
+		static IList<Type> FindPluginTypesInFile (string filepath)
 		{
 			Assembly asm = Assembly.LoadFrom (filepath);
 			return FindPluginTypesInAssembly (asm);
 		}
 
-		static ArrayList FindPluginTypesInAssembly (Assembly asm)
+		static IList<Type> FindPluginTypesInAssembly (Assembly asm)
 		{
+			IList<Type> asm_plugins = new List<Type> ();
 			Type [] types = asm.GetTypes ();
-			ArrayList asm_plugins = new ArrayList ();
 			bool found_one = false;
 
 			foreach (Type type in types) {
-				if (type.IsSubclassOf (typeof (NotePlugin))) {
+				if (typeof (IPlugin).IsAssignableFrom (type)) {
 					Console.Write ("{0}. ", type.FullName);
 					asm_plugins.Add (type);
 					found_one = true;
