private void AddMenuItem(ToolStripItemCollection destinationItems, System.Windows.Controls.MenuItem menuItem) { string MenuHeader = (string)menuItem.Header; ToolStripMenuItem NewMenuItem; if (menuItem.Icon is Bitmap MenuBitmap) { NewMenuItem = new ToolStripMenuItem(MenuHeader, MenuBitmap); } else if (menuItem.Icon is Icon MenuIcon) { NewMenuItem = new ToolStripMenuItem(MenuHeader, MenuIcon.ToBitmap()); } else { NewMenuItem = new ToolStripMenuItem(MenuHeader); } NewMenuItem.Click += OnMenuClicked; // See PrepareMenuItem for using the visibility to carry Visible/Enabled flags NewMenuItem.Visible = (menuItem.Visibility != System.Windows.Visibility.Collapsed); NewMenuItem.Enabled = (menuItem.Visibility == System.Windows.Visibility.Visible); NewMenuItem.Checked = menuItem.IsChecked; destinationItems.Add(NewMenuItem); MenuTable.Add(NewMenuItem, this); CommandTable.Add(NewMenuItem, menuItem.Command); }
private static void InitializeCommandsAndIcons() { foreach (KeyValuePair <Assembly, List <IPluginClient> > Entry in LoadedPluginTable) { foreach (IPluginClient Plugin in Entry.Value) { List <ICommand> PluginCommandList = Plugin.CommandList; if (PluginCommandList != null) { List <ICommand> FullPluginCommandList = new List <ICommand>(); FullCommandList.Add(FullPluginCommandList, Plugin.Name); foreach (ICommand Command in PluginCommandList) { FullPluginCommandList.Add(Command); if (!IsSeparatorCommand(Command)) { CommandTable.Add(Command, Plugin); } } } Icon PluginIcon = Plugin.Icon; if (PluginIcon != null) { ConsolidatedPluginList.Add(Plugin); } } } }
private void ParseTextSection(string line) { // Check for label var labelIndex = line.IndexOf(":", StringComparison.Ordinal); if (labelIndex > -1) { var label = line.Substring(0, labelIndex); CommandTable.Add(label, CommandList.Count); if (line.Length > labelIndex + 1) { line = line.Substring(labelIndex + 1).Trim(' ', '\t'); } else { return; } } // Add new Command CommandList.Add(line); }
/// <summary> /// Sets up the command tables /// </summary> protected void InitCommandTables() { cmdTable = new CommandTable(); //help commands cmdTable.Add("commands", "cmds", CommandType.General, UserFlags.Normal, "Returns a list of all the commands available to you", null, new Action<User, string>(cmd_Commands)); //testing commands (temp?) cmdTable.Add("admin", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Admin)); cmdTable.Add("mod", "moderator", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Mod)); cmdTable.Add("thread", "threads", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Thread)); //normal user cmdTable.Add("join", "j", CommandType.General, UserFlags.Normal, "Joins a channel", null, new Action<User, string>(cmd_Join)); cmdTable.Add("rejoin", "rj", CommandType.General, UserFlags.Normal, "Rejoins your current channel", null, new Action<User, string>(cmd_Rejoin)); cmdTable.Add("stats", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Stats)); cmdTable.Add("users", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Users)); cmdTable.Add("whisper", "w", "message", "msg", "m", CommandType.General, UserFlags.Normal, "", null, new Action<User, List<User>, string>(cmd_Whisper)); cmdTable.Add("say", "talk", "s", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Talk)); cmdTable.Add("emote", "me", "em", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Emote)); cmdTable.Add("who", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Who)); //operator cmdTable.Add("kick", CommandType.Moderation, UserFlags.Operator, "Kicks a user from the channel", null, new Action<User, List<User>, string>(cmd_Kick)); cmdTable.Add("ban", CommandType.Moderation, UserFlags.Operator, "Bans a user from the channel", null, new Action<User, List<User>, string>(cmd_Ban)); cmdTable.Add("ipban", "banip", CommandType.Moderation, UserFlags.Operator, "Bans a user's IP from the channel", null, new Action<User, List<User>, string>(cmd_IPBan)); cmdTable.Add("unban", "unipban", "unbanip", CommandType.Moderation, UserFlags.Operator, "Unbans a user & their IP from the channel", null, new Action<User, List<User>, string>(cmd_Unban)); cmdTable.Add("op", "operator", CommandType.Moderation, UserFlags.Operator, "Gives up your operator status to another user", null, new Action<User, List<User>, string>(cmd_Op)); cmdTable.Add("resign", CommandType.General, UserFlags.Operator, "Gives up your operator status", null, new Action<User, string>(cmd_Resign)); //moderator //admin cmdTable.Add("invisible", "invis", CommandType.General, UserFlags.Admin, "", null, new Action<User, string>(cmd_Invisible)); cmdTable.Add("visible", "vis", CommandType.General, UserFlags.Admin, "", null, new Action<User, string>(cmd_Visible)); cmdTable.Add("pop", "move", CommandType.General, UserFlags.Admin, "", null, new Action<User, List<User>, string>(cmd_Pop)); }
public static bool Init(bool isElevated, string embeddedPluginName, Guid embeddedPluginGuid, Dispatcher dispatcher, IPluginLogger logger) { PluginInterfaceType = typeof(IPluginClient); Assembly CurrentAssembly = Assembly.GetExecutingAssembly(); string Location = CurrentAssembly.Location; string AppFolder = Path.GetDirectoryName(Location); int AssemblyCount = 0; int CompatibleAssemblyCount = 0; Dictionary <Assembly, List <Type> > PluginClientTypeTable = new Dictionary <Assembly, List <Type> >(); Assembly PluginAssembly; List <Type> PluginClientTypeList; if (embeddedPluginName != null) { AssemblyName[] AssemblyNames = CurrentAssembly.GetReferencedAssemblies(); foreach (AssemblyName name in AssemblyNames) { if (name.Name == embeddedPluginName) { FindPluginClientTypesByName(name, out PluginAssembly, out PluginClientTypeList); if (PluginAssembly != null && PluginClientTypeList != null && PluginClientTypeList.Count > 0) { PluginClientTypeTable.Add(PluginAssembly, PluginClientTypeList); } } } } string[] Assemblies = Directory.GetFiles(AppFolder, "*.dll"); foreach (string AssemblyPath in Assemblies) { FindPluginClientTypesByPath(AssemblyPath, out PluginAssembly, out PluginClientTypeList); if (PluginAssembly != null && PluginClientTypeList != null) { PluginClientTypeTable.Add(PluginAssembly, PluginClientTypeList); } } foreach (KeyValuePair <Assembly, List <Type> > Entry in PluginClientTypeTable) { AssemblyCount++; PluginAssembly = Entry.Key; PluginClientTypeList = Entry.Value; if (PluginClientTypeList.Count > 0) { CompatibleAssemblyCount++; CreatePluginList(PluginAssembly, PluginClientTypeList, embeddedPluginGuid, logger, out List <IPluginClient> PluginList); if (PluginList.Count > 0) { LoadedPluginTable.Add(PluginAssembly, PluginList); } } } if (LoadedPluginTable.Count > 0) { foreach (KeyValuePair <Assembly, List <IPluginClient> > Entry in LoadedPluginTable) { foreach (IPluginClient Plugin in Entry.Value) { IPluginSettings Settings = new PluginSettings(GuidToString(Plugin.Guid), logger); Plugin.Initialize(isElevated, dispatcher, Settings, logger); if (Plugin.RequireElevated) { RequireElevated = true; } } } foreach (KeyValuePair <Assembly, List <IPluginClient> > Entry in LoadedPluginTable) { foreach (IPluginClient Plugin in Entry.Value) { List <ICommand> PluginCommandList = Plugin.CommandList; if (PluginCommandList != null) { List <ICommand> FullPluginCommandList = new List <ICommand>(); FullCommandList.Add(FullPluginCommandList, Plugin.Name); foreach (ICommand Command in PluginCommandList) { FullPluginCommandList.Add(Command); if (Command != null) { CommandTable.Add(Command, Plugin); } } } Icon PluginIcon = Plugin.Icon; if (PluginIcon != null) { ConsolidatedPluginList.Add(Plugin); } } } foreach (IPluginClient Plugin in ConsolidatedPluginList) { if (Plugin.HasClickHandler) { PreferredPlugin = Plugin; break; } } if (PreferredPlugin == null && ConsolidatedPluginList.Count > 0) { PreferredPlugin = ConsolidatedPluginList[0]; } return(true); } else { logger.AddLog($"Could not load plugins, {AssemblyCount} assemblies found, {CompatibleAssemblyCount} are compatible."); return(false); } }