/// <summary> /// Builds an in-memory action model from the specified XML model and the specified set of actions. /// </summary> /// <remarks> /// The actions will be ordered according to the XML model. Any actions that are not a part of the /// XML model will be added to the memory model and inserted into the XML model based on a 'group hint'. /// The XML model is automatically persisted, and new models that have never before been persisted /// will be added. /// </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 BuildAndSynchronize(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 = Synchronize(actionModelID, actionMap); ActionModelRoot modelRoot = Build(site, xmlActionModel, actionMap); return(modelRoot); }
/// <summary> /// Builds an in-memory action model from the specified XML model and the specified set of actions. /// The actions will be ordered according to the XML model. /// </summary> /// <param name="site">the action model site</param> /// <param name="xmlActionModel">an XML "action-model" node</param> /// <param name="actions">the set of actions that the model should contain</param> /// <returns>an <see cref="ActionModelNode"/> representing the root of the action model</returns> private static ActionModelRoot Build(string site, XmlElement xmlActionModel, IDictionary <string, IAction> actions) { ActionModelRoot model = new ActionModelRoot(site); List <XmlElement> actionNodes = GetActionNodeList(xmlActionModel); // process xml model, inserting actions in order for (int i = 0; i < actionNodes.Count; i++) { XmlElement xmlAction = actionNodes[i]; if (xmlAction.Name == "action") { string actionID = xmlAction.GetAttribute("id"); //This accounts for "former action IDs" because the same action will be in the map for each ID (current and former). if (actions.ContainsKey(actionID)) { IAction action = actions[actionID]; // update the action path from the xml ProcessXmlAction(xmlAction, action); // insert the action into the model model.InsertAction(action); } } else if (xmlAction.Name == "separator") { Path separatorPath = ProcessSeparator(actionNodes, i, actions); // insert separator into model if (separatorPath != null) { model.InsertSeparator(separatorPath); } } } return(model); }
private void BuildToolbars(IWorkspace workspace) { _toolBarBox.Remove(_toolBar); _toolBar.Destroy(); // make sure the old one is cleaned up! _toolBar = new Toolbar(); _toolBar.ToolbarStyle = ToolbarStyle.Icons; _toolBarBox.PackStart(_toolBar, true, true, 0); _tooltips = new Tooltips(); ActionModelRoot model = new ActionModelRoot(""); //model.Merge(WorkstationModel.ToolManager.ToolbarModel); model.Merge(DesktopApplication.ToolSet.ToolbarModel); if(workspace != null) { //model.Merge(workspace.ToolManager.ToolbarModel); model.Merge(workspace.ToolSet.ToolbarModel); } GtkToolbarBuilder.BuildToolbar(_toolBar, _tooltips, model); _toolBar.ShowAll(); }
private void BuildMenus(IWorkspace workspace) { foreach(Widget w in _mainMenu) { _mainMenu.Remove(w); w.Destroy(); } ActionModelRoot model = new ActionModelRoot(""); //model.Merge(WorkstationModel.ToolManager.MenuModel); model.Merge(DesktopApplication.ToolSet.MenuModel); if(workspace != null) { //model.Merge(workspace.ToolManager.MenuModel); model.Merge(workspace.ToolSet.MenuModel); } GtkMenuBuilder.BuildMenu(_mainMenu, model); _mainMenu.ShowAll(); }
public ActionModelRoot GetAbstractActionModel() { ActionModelRoot actionModelRoot = new ActionModelRoot(_site); this.CreateActionModelRoot(actionModelRoot); return actionModelRoot; }
/// <summary> /// Builds an in-memory action model from the specified XML model and the specified set of actions. /// The actions will be ordered according to the XML model. /// </summary> /// <param name="site">the action model site</param> /// <param name="xmlActionModel">an XML "action-model" node</param> /// <param name="actions">the set of actions that the model should contain</param> /// <returns>an <see cref="ActionModelNode"/> representing the root of the action model</returns> private static ActionModelRoot Build(string site, XmlElement xmlActionModel, IDictionary<string, IAction> actions) { ActionModelRoot model = new ActionModelRoot(site); List<XmlElement> actionNodes = GetActionNodeList(xmlActionModel); // process xml model, inserting actions in order for (int i = 0; i < actionNodes.Count; i++) { XmlElement xmlAction = actionNodes[i]; if (xmlAction.Name == "action") { string actionID = xmlAction.GetAttribute("id"); //This accounts for "former action IDs" because the same action will be in the map for each ID (current and former). if (actions.ContainsKey(actionID)) { IAction action = actions[actionID]; // update the action path from the xml ProcessXmlAction(xmlAction, action); // insert the action into the model model.InsertAction(action); } } else if (xmlAction.Name == "separator") { Path separatorPath = ProcessSeparator(actionNodes, i, actions); // insert separator into model if (separatorPath != null) model.InsertSeparator(separatorPath); } } return model; }
/// <summary> /// Persists an in-memory abstract action model to the XML model. /// </summary> /// <remarks> /// This method functions as a counterpart to <see cref="BuildAbstractActionModel"/>. The specified abstract action model /// (created by <see cref="BuildAbstractActionModel"/>, or potentially modified further) is flattened and its nodes /// written out to the XML mode, replacing any existing model at the same qualified site. This allows action model /// configuration interfaces to make changes to the action model. /// </remarks> /// <param name="namespace">A namespace to qualify the site.</param> /// <param name="site">The site.</param> /// <param name="abstractActionModel">The abstract action model to be persisted.</param> /// <returns>An <see cref="ActionModelNode"/> representing the root of the action model.</returns> public void PersistAbstractActionModel(string @namespace, string site, ActionModelRoot abstractActionModel) { // do one time initialization if (_actionModelXmlDoc == null) Initialize(); XmlElement separatorTemplate = _actionModelXmlDoc.CreateElement("separator"); string actionModelId = string.Format("{0}:{1}", @namespace, site); XmlElement xmlActionModel = FindXmlActionModel(actionModelId); if (xmlActionModel != null) { // clear the action model List<XmlNode> childrenToClear = CollectionUtils.Cast<XmlNode>(xmlActionModel.ChildNodes); foreach (XmlNode childNode in childrenToClear) xmlActionModel.RemoveChild(childNode); } else { // add a new action model this.GetActionModelsNode().AppendChild(xmlActionModel = CreateXmlActionModel(actionModelId)); } ActionModelNode[] leafNodes = abstractActionModel.GetLeafNodesInOrder(); for (int n = 0; n < leafNodes.Length; n++) { ActionModelNode leafNode = leafNodes[n]; if (leafNode is ActionNode) { xmlActionModel.AppendChild(CreateXmlAction(_actionModelXmlDoc, ((ActionNode) leafNode).Action)); } else if (leafNode is SeparatorNode) { xmlActionModel.AppendChild(separatorTemplate.Clone()); } } if (!_temporary) { this.ActionModelsXml = _actionModelXmlDoc; this.Save(); } }