| 0: | // PluginManager.cs | |
| 1: | // Copyright (c) 2000 Mike Krueger | |
| 2: | // | |
| 3: | // This program is free software; you can redistribute it and/or modify | |
| 4: | // it under the terms of the GNU General Public License as published by | |
| 5: | // the Free Software Foundation; either version 2 of the License, or | |
| 6: | // (at your option) any later version. | |
| 7: | // | |
| 8: | // This program is distributed in the hope that it will be useful, | |
| 9: | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10: | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11: | // GNU General Public License for more details. | |
| 12: | // | |
| 13: | // You should have received a copy of the GNU General Public License | |
| 14: | // along with this program; if not, write to the Free Software | |
| 15: | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 16: | ||
| 17: | using System; | |
| 18: | using System.Collections; | |
| 19: | using System.IO; | |
| 20: | using System.Windows.Forms; | |
| 21: | using System.Xml; | |
| 22: | ||
| 23: | using SharpDevelop.Gui; | |
| 24: | using SharpDevelop.Actions.Menu; | |
| 25: | using SharpDevelop.Tool.Function; | |
| 26: | ||
| 27: | namespace SharpDevelop.Internal.Plugin { | |
| 28: | ||
| 29: | public class PluginManager | |
| 30: | { | |
| 31: | MainWindow window = null; | |
| 32: | ArrayList menuitems = new ArrayList(); | |
| 33: | ArrayList plugins = new ArrayList(); | |
| 34: | ||
| 35: | public PluginManager(MainWindow window) | |
| 36: | { | |
| 37: | this.window = window; | |
| 38: | try { | |
| 39: | FileUtility.SearchDirectory(Application.StartupPath + | |
| 40: | Path.DirectorySeparatorChar + ".." + | |
| 41: | Path.DirectorySeparatorChar + "add-ins" + | |
| 42: | Path.DirectorySeparatorChar + "plugins", "*.xml", new FileSearchDelegate(LoadPlugin)); | |
| 43: | } catch (Exception e) { // TODO | |
| 44: | MessageBox.Show("can't load plugins, check if the plugin directory exists.\n" + e.ToString(), "Can't load plugins", | |
| 45: | MessageBoxButtons.OK, MessageBoxIcon.Warning); | |
| 46: | plugins = new ArrayList(); | |
| 47: | } | |
| 48: | } | |
| 49: | ||
| 50: | void LoadPlugin(string filename) | |
| 51: | { | |
| 52: | XmlDocument doc = new XmlDocument(); | |
| 53: | doc.Load(filename); | |
| 54: | try { | |
| 55: | plugins.Add(new Plugin(window, Path.GetDirectoryName(filename), doc.DocumentElement)); | |
| 56: | } catch (Exception e) { | |
| 57: | MessageBox.Show("can't load plugin " + doc.DocumentElement.Attributes["NAME"].InnerText + "\n\nexception thrown : \n" + e.ToString(), "Can't load plugin", | |
| 58: | MessageBoxButtons.OK, MessageBoxIcon.Warning); | |
| 59: | } | |
| 60: | } | |
| 61: | ||
| 62: | public ArrayList PlugIns { | |
| 63: | get { | |
| 64: | return plugins; | |
| 65: | } | |
| 66: | } | |
| 67: | ||
| 68: | public ArrayList MenuItems { | |
| 69: | get { | |
| 70: | ArrayList items = new ArrayList(); | |
| 71: | for (int i = 0; i < plugins.Count; ++i) { | |
| 72: | MenuItem[] menuitems = ((Plugin)plugins[i]).MenuItems; | |
| 73: | foreach (MenuItem item in menuitems) | |
| 74: | items.Add(item); | |
| 75: | } | |
| 76: | return items; | |
| 77: | } | |
| 78: | } | |
| 79: | } | |
| 80: | } |
This page was automatically generated by SharpDevelop.