Created
January 3, 2011 22:39
-
-
Save Konctantin/764106 to your computer and use it in GitHub Desktop.
load plugins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/PacketViewer/FrmMain.cs b/PacketViewer/FrmMain.cs | |
index 1ce86d5..8e622be 100644 | |
--- a/PacketViewer/FrmMain.cs | |
+++ b/PacketViewer/FrmMain.cs | |
@@ -9,23 +9,61 @@ using System.Windows.Forms; | |
using Kamilla; | |
using Kamilla.WorldOfWarcraft; | |
using PacketViewer.Properties; | |
+using PluginInterface; | |
+using System.ComponentModel.Composition; | |
+using System.ComponentModel.Composition.Hosting; | |
namespace PacketViewer | |
{ | |
- internal partial class FrmMain : Form | |
+ public partial class FrmMain : Form | |
{ | |
+ private DirectoryCatalog m_catalog; | |
+ | |
public List<PacketParser> Parsers = new List<PacketParser>(); | |
+ | |
+ [ImportMany(AllowRecomposition = true)] | |
+ List<IPlugin> Plugins { get; set; } | |
public FrmMain(string filename) | |
{ | |
InitializeComponent(); | |
+ m_catalog = new DirectoryCatalog(Application.StartupPath); | |
+ var container = new CompositionContainer(m_catalog); | |
+ container.ComposeParts(this); | |
+ | |
+ LoadPluginsMenu(); | |
+ | |
this.Icon = Resources.Earth; | |
_rbSeachDown.Checked = true; | |
if (filename != String.Empty) | |
LoadFile(filename); | |
} | |
- | |
+ | |
+ private void LoadPluginsMenu() | |
+ { | |
+ if (Plugins == null) | |
+ return; | |
+ if (Plugins.Count == 0) | |
+ return; | |
+ | |
+ tsmPlugins.Enabled = true; | |
+ | |
+ for (int i = 0; i < Plugins.Count; ++i) | |
+ { | |
+ ToolStripMenuItem item = new ToolStripMenuItem(Plugins[i].Name); | |
+ item.Tag = i; | |
+ item.Click += new EventHandler(plugin_item_Click); | |
+ tsmPlugins.DropDownItems.Add(item); | |
+ } | |
+ } | |
+ | |
+ private void plugin_item_Click(object sender, EventArgs e) | |
+ { | |
+ ToolStripMenuItem item = (sender as ToolStripMenuItem); | |
+ Plugins[(int)item.Tag].Run(new List<object>()); | |
+ } | |
+ | |
private int SelectedIndex | |
{ | |
get { return PacketView.SelectedIndices.Count > 0 ? PacketView.SelectedIndices[0] : -1; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment