/// <summary> /// Gets a set of exported <see cref="IAction"/>s. /// </summary> /// <param name="site">The action model site at which the actions should reside.</param> /// <param name="mouseInformation">The mouse input when the action model was requested, such as in response to a context menu request.</param> /// <returns>A set of exported <see cref="IAction"/>s.</returns> public override IActionSet GetExportedActions(string site, IMouseInformation mouseInformation) { IResourceResolver resolver = new ApplicationThemeResourceResolver(this.GetType(), true); string @namespace = typeof(RoiCalloutGraphic).FullName; List<IAction> actions = new List<IAction>(); MenuAction hideAction = new MenuAction(@namespace + ":toggle", new ActionPath(site + "/MenuShowAnalysis", resolver), ClickActionFlags.None, resolver); hideAction.GroupHint = new GroupHint("Tools.Measurements.Display"); hideAction.Label = SR.MenuShowAnalysis; hideAction.Checked = this.ShowAnalysis; hideAction.Persistent = true; hideAction.SetClickHandler(this.ToggleShowAnalysis); actions.Add(hideAction); if (AllowRename) { MenuAction renameAction = new MenuAction(@namespace + ":rename", new ActionPath(site + "/MenuRename", resolver), ClickActionFlags.None, resolver); renameAction.GroupHint = new GroupHint("Tools.Measurements.Properties"); renameAction.Label = SR.MenuRename; renameAction.Persistent = true; renameAction.SetClickHandler(this.Rename); actions.Add(renameAction); } IActionSet actionSet = new ActionSet(actions); if (this.ShowAnalysis) { var analyzerActionSets = GetAnalyzersExportedActions(site, mouseInformation); if (analyzerActionSets != null) { foreach(var set in analyzerActionSets) { actionSet = actionSet.Union(set); } } } IActionSet other = base.GetExportedActions(site, mouseInformation); if (other != null) actionSet = actionSet.Union(other); return actionSet; }
/// <summary> /// Builds an in-memory abstract action model from the specified XML model and the specified set of known actions. /// </summary> /// <remarks> /// This method functions similarly to <see cref="BuildAndSynchronize"/> except that the resulting action model /// consists solely of <see cref="AbstractAction"/>s which are not actually associated with any concrete actions on tools or components. /// </remarks> /// <param name="namespace">A namespace to qualify the site.</param> /// <param name="site">The site.</param> /// <param name="actions">The set of actions to include. This set should be prefiltered on <paramref name="site"/>.</param> /// <returns>An <see cref="ActionModelNode"/> representing the root of the action model.</returns> public ActionModelRoot BuildAbstractActionModel(string @namespace, string site, IActionSet actions) { // do one time initialization if (_actionModelXmlDoc == null) Initialize(); string actionModelId = string.Format("{0}:{1}", @namespace, site); IDictionary<string, IAction> actionMap = BuildActionMap(actions); XmlElement xmlActionModel = FindXmlActionModel(actionModelId); if (xmlActionModel == null) { xmlActionModel = Synchronize(actionModelId, actionMap); } else { // clone the model because we don't want to be modifying the actual action model yet xmlActionModel = (XmlElement) xmlActionModel.CloneNode(true); //Fix all the group hints. UpdateGroupHints(xmlActionModel, actionMap); // if there are new persistent actions that aren't already in the xml, insert them now foreach (IAction action in actionMap.Values) { if (action.Persistent) { if (AppendActionToXmlModel(_actionModelXmlDoc, xmlActionModel, action)) Platform.Log(LogLevel.Debug, "Inserted {0}", action.ActionID); } } List<XmlElement> childNodes = GetActionNodeList(xmlActionModel); List<IAction> abstractActions = new List<IAction>(childNodes.Count); foreach (XmlElement childElement in childNodes) { if (childElement.Name == "action") { string actionId = childElement.GetAttribute("id"); if (string.IsNullOrEmpty(actionId)) { Platform.Log(LogLevel.Debug, "Invalid action model entry with null ID in /action-models/action-model[@id='{0}']", actionModelId); continue; } try { if (actionMap.ContainsKey(actionId)) { abstractActions.Add(AbstractAction.Create(actionMap[actionId])); } } catch (Exception ex) { Platform.Log(LogLevel.Debug, ex, "Invalid action model entry at /action-models/action-model[@id='{0}']/action[@id='{1}']", actionModelId, actionId); } } } actions = new ActionSet(abstractActions); actionMap = BuildActionMap(actions); } return Build(site, xmlActionModel, actionMap); }
public override IActionSet GetExportedActions(string site, ClearCanvas.ImageViewer.InputManagement.IMouseInformation mouseInformation) { IResourceResolver resolver = new ResourceResolver(GetType(), true); var @namespace = GetType().FullName; var hideAction = new MenuAction(@namespace + ":toggle", new ActionPath(site + "/MenuSetMarkupColorForUser", resolver), ClickActionFlags.None, resolver); hideAction.Label = "Set User Markup Color"; hideAction.Persistent = true; hideAction.SetClickHandler(OpenAimMarkupColorOptions); IActionSet actions = new ActionSet(new IAction[] { hideAction }); var other = base.GetExportedActions(site, mouseInformation); if (other != null) actions = actions.Union(other); return actions; }
/// <summary> /// Builds an in-memory abstract action model from the specified XML model and the specified set of known actions. /// </summary> /// <remarks> /// This method functions similarly to <see cref="BuildAndSynchronize"/> except that the resulting action model /// consists solely of <see cref="AbstractAction"/>s which are not actually associated with any concrete actions on tools or components. /// </remarks> /// <param name="namespace">A namespace to qualify the site.</param> /// <param name="site">The site.</param> /// <param name="actions">The set of actions to include. This set should be prefiltered on <paramref name="site"/>.</param> /// <returns>An <see cref="ActionModelNode"/> representing the root of the action model.</returns> public ActionModelRoot BuildAbstractActionModel(string @namespace, string site, IActionSet actions) { // do one time initialization if (_actionModelXmlDoc == null) { Initialize(); } string actionModelId = string.Format("{0}:{1}", @namespace, site); IDictionary <string, IAction> actionMap = BuildActionMap(actions); XmlElement xmlActionModel = FindXmlActionModel(actionModelId); if (xmlActionModel == null) { xmlActionModel = Synchronize(actionModelId, actionMap); } else { // clone the model because we don't want to be modifying the actual action model yet xmlActionModel = (XmlElement)xmlActionModel.CloneNode(true); //Fix all the group hints. UpdateGroupHints(xmlActionModel, actionMap); // if there are new persistent actions that aren't already in the xml, insert them now foreach (IAction action in actionMap.Values) { if (action.Persistent) { if (AppendActionToXmlModel(_actionModelXmlDoc, xmlActionModel, action)) { Platform.Log(LogLevel.Debug, "Inserted {0}", action.ActionID); } } } List <XmlElement> childNodes = GetActionNodeList(xmlActionModel); List <IAction> abstractActions = new List <IAction>(childNodes.Count); foreach (XmlElement childElement in childNodes) { if (childElement.Name == "action") { string actionId = childElement.GetAttribute("id"); if (string.IsNullOrEmpty(actionId)) { Platform.Log(LogLevel.Debug, "Invalid action model entry with null ID in /action-models/action-model[@id='{0}']", actionModelId); continue; } try { if (actionMap.ContainsKey(actionId)) { abstractActions.Add(AbstractAction.Create(actionMap[actionId])); } } catch (Exception ex) { Platform.Log(LogLevel.Debug, ex, "Invalid action model entry at /action-models/action-model[@id='{0}']/action[@id='{1}']", actionModelId, actionId); } } } actions = new ActionSet(abstractActions); actionMap = BuildActionMap(actions); } return(Build(site, xmlActionModel, actionMap)); }