void SetupAQuickLink(MefAddIns.Extensibility.mef_IBase thisAddIn) { if (true == thisAddIn.CalledFrom.QuickLinkShows) { if (thisAddIn.ActiveForm() == null) { lg.Instance.Line("MainFormBase->HandleAddInClick", ProblemType.WARNING, "can't, no form active!"); } else { //if (thisAddIn.QuickLinkMenuItem is ToolStripButton) { ToolStripButton link = new ToolStripButton(); link.Name = "quicklink"; link.Tag = thisAddIn; link.Text = thisAddIn.CalledFrom.MyMenuName; link.BackColor = Color.Yellow; link.Click += HandleQuickLinkClick; //thisAddIn.QuickLinkMenuItem = link; thisAddIn.Hookups.Add(link); //FooterStatus.Items.Add ((ToolStripButton)thisAddIn.QuickLinkMenuItem); FooterStatus.Items.Add(link); } } } }
/// <summary> /// Handles the add in click. (When the menu option that was added for the AddIn is clicked by usr) /// </summary> /// <param name='sender'> /// Sender. /// </param> /// <param name='e'> /// E. /// </param> void HandleAddInClick(object sender, EventArgs e) { // the tag contains the original addin if ((sender as ToolStripItem).Tag != null) { MefAddIns.Extensibility.mef_IBase thisAddIn = ((MefAddIns.Extensibility.mef_IBase)(sender as ToolStripItem).Tag); RunAddInAction(thisAddIn); // just a quick test to see if databse string made it in //NewMessage.Show (((MefAddIns.Extensibility.mef_IBase)(sender as ToolStripItem).Tag).Storage.ToString()); } }
/// <summary> /// Builds the addin tool strip. (Wrapper function) /// </summary> /// <param name='AddIn'> /// Add in. /// </param> /// <param name='but'> /// But. /// </param> void BuildAddinToolStrip(MefAddIns.Extensibility.mef_IBase AddIn, ToolStripItem but) { but.Name = AddIn.CalledFrom.GUID; but.Tag = AddIn; AddIn.DelegateTargetForGetAfterRespondInformation = HandleRespondInformationFromAddin; but.AutoSize = true; but.Click += HandleAddInClick; if (AddIn.CalledFrom.Image != null) { but.Image = AddIn.CalledFrom.Image; } but.ToolTipText = AddIn.CalledFrom.ToolTip; AddIn.Hookups.Add(but); }
void RunAddInAction(MefAddIns.Extensibility.mef_IBase thisAddIn) { object NeededInfo = GetInformationForAddInBeforeRun(thisAddIn.TypeOfInformationNeeded); // if we have NO type info needed, we proceed. Otherwise, we must supply that info too if ((thisAddIn.TypeOfInformationNeeded == 0) || (thisAddIn.TypeOfInformationNeeded > 0 && NeededInfo != null)) { thisAddIn.SetBeforeRespondInformation(NeededInfo); thisAddIn.path_filelocation = path; thisAddIn.RespondToMenuOrHotkey(this); // this routine sends the needed info to the callback which was setup at Initialization // we don't call this externally, it is called internally //thisAddIn.GetAfterRespondInformation(); //object InfoFromAddIn = thisAddIn.GetAfterRespondInformation(); //HandleRespondInformationFromAddin(InfoFromAddIn, thisAddIn.TypeOfInformationSentBack); SetupAQuickLink(thisAddIn); } else { lg.Instance.Line("MainFormBase->HandleAddInClick", ProblemType.WARNING, String.Format("Addin {0} did not get called because TypeOfInformation or NeededInfo unavailable.", thisAddIn.Name)); } }
/// <summary> /// Starts the and stop plug ins. /// </summary> void StartAndStopPlugIns() { if (null != addIns) { List <MefAddIns.Extensibility.mef_IBase> FullListOfAddins = addIns.BuildListOfAddins(); List <string> myList = addIns.GetListOfInstalledPlugs(); // TO DO: Need to set up an IsActive system. For now assume active=true; for (int i = 0; i < FullListOfAddins.Count; i++) { MefAddIns.Extensibility.mef_IBase AddIn = FullListOfAddins [i]; MefAddIns.Extensibility.mef_IBase AddInAlreadyIn = null; if (AddInsLoaded != null) { AddInAlreadyIn = AddInsLoaded.Find(mef_IBase => mef_IBase.CalledFrom.GUID == AddIn.CalledFrom.GUID); } else { AddInsLoaded = new List <MefAddIns.Extensibility.mef_IBase> (); } if (AddInAlreadyIn == null) { if (myList.Contains(AddIn.CalledFrom.GUID) == true) { // If Plug not already Loaded then Load it //NewMessage.Show ("Adding " + AddIn.Name); AddInsLoaded.Add(AddIn); AddIn.RegisterType(); AddIn.AssignHotkeys(ref Hotkeys, ref AddIn, RunAddInAction); if (AddIn.CalledFrom.IsNoteAction == true) { // allow addins to override the noteaction menu name here if they are deploying with both a menu and note action string menuNameToUse = AddIn.CalledFrom.MyMenuName; if (AddIn.CalledFrom.NoteActionMenuOverride != Constants.BLANK) { menuNameToUse = AddIn.CalledFrom.NoteActionMenuOverride; } NoteTextAction tmp = new NoteTextAction(AddIn.ActionWithParamForNoteTextActions, AddIn.BuildFileNameForActionWithParam, menuNameToUse, AddIn.CalledFrom.ToolTip); tmp.Parent = NoteTextActions; NoteTextActions.Add(tmp); AddIn.Hookups.Add(tmp); } // February 2013 - removed the else. NoteActions and things with menus do not need exclusivity if (AddIn.CalledFrom.IsOnAMenu == true) { string myMenuName = AddIn.CalledFrom.MyMenuName; if (Constants.BLANK != myMenuName) { string parentName = AddIn.CalledFrom.ParentMenuName; if (Constants.BLANK != parentName) { if (AddIn.CalledFrom.IsOnContextStrip == true) { // search for a context strip ContextMenuStrip strip = ContextMenus.Find(ContextMenuStrip => ContextMenuStrip.Name == parentName); if (strip != null) { ToolStripButton but = new ToolStripButton(AddIn.CalledFrom.MyMenuName); BuildAddinToolStrip(AddIn, but); strip.Items.Add(but); } } else // search The MainMenuInstead { // add this menu option ToolStripItem[] items = MainMenu.Items.Find(parentName, true); if (items.Length > 0) { if (items [0].GetType() == typeof(ToolStripMenuItem)) { if (((ToolStripMenuItem)items [0]).DropDown != null) { ToolStripButton but = new ToolStripButton(AddIn.CalledFrom.MyMenuName); BuildAddinToolStrip(AddIn, but); //but.Tag = AddIn; //but.AutoSize = true; //but.Click += HandleAddInClick; ((ToolStripMenuItem)items [0]).DropDownItems.Add(but); // hack to make sure menu is 'wide enough' tried associating contextmenustrip but that did not help ((ToolStripMenuItem)items [0]).DropDownItems.Remove(((ToolStripMenuItem)items [0]).DropDownItems.Add("removeme")); //((ContextMenuStrip)((ToolStripMenuItem)items[0]).DropDown).Items.Add (but); // but.ToolTipText = AddIn.CalledFrom.ToolTip; // AdvancedStrip.Items.Add (but); //((ContextMenuStrip)((ToolStripMenuItem)items[0]).Tag).Items.Add (but); // if (AddIn.CalledFrom.Image != null) // { // but.Image = AddIn.CalledFrom.Image; // } // AddIn.Hookups.Add (but); } else { NewMessage.Show(Loc.Instance.GetString("A dropdown contextmenustrip needs to be defined for parent menu item")); } } } } // searching thru main mnenu } else { // create us as a parent ToolStripMenuItem parent = new ToolStripMenuItem(AddIn.CalledFrom.MyMenuName); // parent.Click += HandleAddInClick; // parent.Tag= AddIn; // parent.ToolTipText = AddIn.CalledFrom.ToolTip; // if (AddIn.CalledFrom.Image != null) // { // parent.Image = AddIn.CalledFrom.Image; // } BuildAddinToolStrip(AddIn, parent); MainMenu.Items.Add(parent); //AddIn.Hookups.Add (parent); } } } // OnAMenu } // Is allowed to be loaded (i.e., set in Options) // We call this method. If this is a notetype we get registered, others ignore it } //Not Added Yet } // Remove installed plugins if (addIns.Count > 0) { bool MustExit = false; // We exist but we are not on the AddMe list. // This means we need to be removed for (int i = AddInsLoaded.Count - 1; i >= 0; i--) { MefAddIns.Extensibility.mef_IBase addin = AddInsLoaded [i]; // look at each plug and decide if it should be removed (i.e., it is no longer in the list to add if (myList.Contains(addin.CalledFrom.GUID) == false) { // we are NOT in the list but we exist in the active list // this means we must be destroyed!! // NewMessage.Show ("Destroy : " + addin.CalledFrom.GUID); foreach (IDisposable connection in addin.Hookups) { // NewMessage.Show ("Removing " + connection.ToString()); connection.Dispose(); } if (addin.DeregisterType() == true) { NewMessage.Show(Loc.Instance.GetString("Because a NoteType (or other advanced AddIn) was removed, we must shut down now, because any Layout open will not be able to be edited until this NoteType is added again.")); MustExit = true; } AddInsLoaded.Remove(addin); } } if (true == MustExit) { Application.Exit(); } } // count > 0 } }
/// <summary> /// Assigns the hotkeys. (Intended to overriden by children, if necessary) /// </summary> public virtual void AssignHotkeys(ref List <HotKeys.KeyData> HotKeys, ref MefAddIns.Extensibility.mef_IBase addin, Action <MefAddIns.Extensibility.mef_IBase> Runner) { }