void ElementClickedEH(object sender, EventArgs e) { ContextMenuStrip popup = new ContextMenuStrip(); popup.AutoSize = true; ToolStripDropDownButton changeTo = new ToolStripDropDownButton("Change to..."); AdjustDropDownSize(popup, changeTo); changeTo.DropDown = new ToolStripDropDown(); changeTo.DropDown.Items.Add("Empty", null, new EventHandler(ChangeToEmptyEH)); changeTo.DropDown.Items.Add("Definition", null, new EventHandler(ChangeToDefinitionEH)); popup.Items.Add(changeTo); popup.Items.Add("Assign letter", null, new EventHandler(AssignLetterEH)); if (letter.Length > 0) //If a letter has been assigned, show this menu. { ToolStripButton definiteButton = new ToolStripButton("Definite", null, new EventHandler(DefiniteClickedEH)); definiteButton.Checked = fDefinite; popup.Items.Add(definiteButton); } popup.Opacity = 0.5; popup.PerformLayout(); popup.Show(_wControl, new Point(_wControl.Width, _wControl.Height)); popup.Update(); }
void ElementClickedEH(object sender, EventArgs e) { ContextMenuStrip popup = new ContextMenuStrip(); popup.AutoSize = true; ToolStripDropDownButton changeTo = new ToolStripDropDownButton("Change to..."); AdjustDropDownSize(popup, changeTo); changeTo.DropDown = new ToolStripDropDown(); changeTo.DropDown.Items.Add("Letter", null, new EventHandler(ChangeToLetterEH)); changeTo.DropDown.Items.Add("Definition", null, new EventHandler(ChangeToDefinitionEH)); popup.Items.Add(changeTo); popup.Opacity = 0.5; popup.PerformLayout(); popup.Show(_wControl, new Point(_wControl.Width, _wControl.Height)); popup.Update(); }
public PluginManager(string directory, ListView listView, ContextMenuStrip menuStrip) { // plugin file names in here string[] pluginFileNames = null; if (Directory.Exists(directory)) { // kind of speaks for itself here pluginFileNames = Directory.GetFiles(directory, "*.dll"); } // contains all the assemblies ICollection <Assembly> assemblies = new List <Assembly>(pluginFileNames.Length); foreach (string dllFile in pluginFileNames) { // loads all of the assemblies AssemblyName an = AssemblyName.GetAssemblyName(dllFile); Assembly assembly = Assembly.Load(an); assemblies.Add(assembly); } #region Column plugins // contains Type objects of all the plugins ICollection <Type> pluginTypes = new List <Type>(); foreach (Assembly assembly in assemblies) { if (assembly != null) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (type.IsInterface || type.IsAbstract) { continue; } else { Type _interface = type.GetInterface("IPluginBase"); if (_interface != null) { if (_interface.Name == "IPluginBase") { pluginTypes.Add(type); } } } } } } // inserts builtin plugins listView.Columns.Add(new ExplodeColumn(new BuiltinName())); listView.Columns.Add(new ExplodeColumn(new BuiltinSize())); listView.Columns.Add(new ExplodeColumn(new BuiltinFormat())); listView.Columns.Add(new ExplodeColumn(new BuiltinExtension())); // creates an instance of each type and inserts it into the ListView foreach (Type type in pluginTypes) { listView.Columns.Add(new ExplodeColumn((IPluginBase)Activator.CreateInstance(type))); } #endregion #region File type plugins // contains Type objects of all the plugins ICollection <Type> typePluginTypes = new List <Type>(); foreach (Assembly assembly in assemblies) { if (assembly != null) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (type.IsInterface || type.IsAbstract) { continue; } else { Type _interface = type.GetInterface("IFileTypeBase"); if (_interface != null) { if (_interface.Name == "IFileTypeBase") { typePluginTypes.Add(type); } } } } } } // creates an instance of each type foreach (Type type in typePluginTypes) { IFileTypeBase plugin = (IFileTypeBase)Activator.CreateInstance(type); _fileTypes.Add(plugin); } // adds builtin types _fileTypes.Add(new BuiltinTxt()); _fileTypes.Add(new BuiltinLnk()); _fileTypes.Add(new BuiltinExe()); #endregion #region Right-click menu plugins // contains Type objects of all the plugins ICollection <Type> menuPluginTypes = new List <Type>(); foreach (Assembly assembly in assemblies) { if (assembly != null) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (type.IsInterface || type.IsAbstract) { continue; } else { Type _interface = type.GetInterface("IMenuItemBase"); if (_interface != null) { if (_interface.Name == "IMenuItemBase") { menuPluginTypes.Add(type); } } } } } } //TODO: remove this line in the build, this is for testing menuPluginTypes.Add(typeof(BuiltinTestItem)); // creates an instance of each type foreach (Type type in menuPluginTypes) { ExplodeMenuStripItem plugin = new ExplodeMenuStripItem((IMenuItemBase)Activator.CreateInstance(type), listView); plugin.Text = plugin.handler.ActionName; // add to menu menuStrip.Items.Add(plugin); menuStrip.Update(); } #endregion }