private void GetToolbarItemsFromXml(XPathNavigator node, List <McToolbarItem> itemsCollection) { foreach (XPathNavigator node1 in node.SelectChildren(string.Empty, string.Empty)) { McToolbarItem mcToolbarItem1 = new McToolbarItem(); switch (node1.Name) { case "Text": mcToolbarItem1.ItemType = McToolbarItemType.Text; break; case "Splitter": mcToolbarItem1.ItemType = McToolbarItemType.Splitter; break; case "Button": mcToolbarItem1.ItemType = McToolbarItemType.Button; break; case "Menu": mcToolbarItem1.ItemType = McToolbarItemType.Menu; break; case "SplitButton": mcToolbarItem1.ItemType = McToolbarItemType.SplitButton; break; default: throw new NotSupportedException(string.Format("Unknown nodeType: {0}", (object)node.Name)); } string attribute1 = node1.GetAttribute("id", string.Empty); string attribute2 = node1.GetAttribute("text", string.Empty); string attribute3 = node1.GetAttribute("imageUrl", string.Empty); string attribute4 = node1.GetAttribute("cssClass", string.Empty); string attribute5 = node1.GetAttribute("align", string.Empty); string attribute6 = node1.GetAttribute("handler", string.Empty); string attribute7 = node1.GetAttribute("commandName", string.Empty); string attribute8 = node1.GetAttribute("itemSplitter", string.Empty); string attribute9 = node1.GetAttribute("tooltip", string.Empty); string attribute10 = node1.GetAttribute("permissions", string.Empty); McToolbarItemAlign toolbarItemAlign = McToolbarItemAlign.Left; McToolbarItemSplitter toolbarItemSplitter = McToolbarItemSplitter.None; if (attribute5 != string.Empty) { try { toolbarItemAlign = (McToolbarItemAlign)Enum.Parse(typeof(McToolbarItemAlign), attribute5); } catch { throw; } } if (attribute8 != string.Empty) { try { toolbarItemSplitter = (McToolbarItemSplitter)Enum.Parse(typeof(McToolbarItemSplitter), attribute8); } catch { throw; } } mcToolbarItem1.Id = attribute1; mcToolbarItem1.Text = UtilHelper.GetResFileString(attribute2); if (attribute3 != string.Empty && (mcToolbarItem1.ItemType == McToolbarItemType.Button || mcToolbarItem1.ItemType == McToolbarItemType.SplitButton || mcToolbarItem1.ItemType == McToolbarItemType.Menu)) { mcToolbarItem1.CssClass += "x-btn-wrap x-btn x-btn-text-icon "; } mcToolbarItem1.ImageUrl = this.ResolveClientUrl(attribute3); mcToolbarItem1.CssClass += attribute4; mcToolbarItem1.ItemAlign = toolbarItemAlign; mcToolbarItem1.Handler = attribute6; mcToolbarItem1.Tooltip = UtilHelper.GetResFileString(attribute9); CommandParameters cp = new CommandParameters(attribute7); Dictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary.Add("GridId", this.GridId); dictionary.Add("GridClientId", this.GridClientId); dictionary.Add("permissions", attribute10); if (!string.IsNullOrEmpty(this.ContainerId)) { dictionary.Add("ContainerId", this.ContainerId); } cp.CommandArguments = dictionary; bool isEnabled = true; if (attribute7 != string.Empty) { string str = CommandManager.GetCurrent(this.Page).AddCommand(this.ClassName, this.ViewName, this.PlaceName, cp, out isEnabled); dictionary.Add("CommandManagerScript", str); cp.CommandArguments = dictionary; mcToolbarItem1.Params = cp.ToString(); mcToolbarItem1.Handler = "defaultToolbarOnClick"; } if (mcToolbarItem1.ItemType == McToolbarItemType.Menu || mcToolbarItem1.ItemType == McToolbarItemType.SplitButton) { if (node1.SelectChildren(string.Empty, string.Empty).Count > 0) { this.GetToolbarItemsFromXml(node1, mcToolbarItem1.Items); if (mcToolbarItem1.Items.Count == 0) { continue; } } else { continue; } } if (isEnabled && (toolbarItemSplitter == McToolbarItemSplitter.Both || toolbarItemSplitter == McToolbarItemSplitter.Left)) { McToolbarItem mcToolbarItem2 = new McToolbarItem(McToolbarItemType.Splitter); mcToolbarItem2.ItemAlign = toolbarItemAlign; itemsCollection.Add(mcToolbarItem2); } if (isEnabled) { itemsCollection.Add(mcToolbarItem1); } if (isEnabled && (toolbarItemSplitter == McToolbarItemSplitter.Both || toolbarItemSplitter == McToolbarItemSplitter.Right)) { McToolbarItem mcToolbarItem2 = new McToolbarItem(McToolbarItemType.Splitter); mcToolbarItem2.ItemAlign = toolbarItemAlign; itemsCollection.Add(mcToolbarItem2); } } }
/// <summary> /// Gets the toolbar items from XML. /// </summary> /// <param name="node">The node.</param> /// <param name="itemsCollection">The items collection.</param> private void GetToolbarItemsFromXml(XPathNavigator node, List <McToolbarItem> itemsCollection) { foreach (XPathNavigator toolbarItem in node.SelectChildren(string.Empty, string.Empty)) { McToolbarItem item = new McToolbarItem(); switch (toolbarItem.Name) { case "Text": { item.ItemType = McToolbarItemType.Text; break; } case "Splitter": { item.ItemType = McToolbarItemType.Splitter; break; } case "Button": { item.ItemType = McToolbarItemType.Button; break; } case "Menu": { item.ItemType = McToolbarItemType.Menu; break; } case "SplitButton": { item.ItemType = McToolbarItemType.SplitButton; break; } default: { throw new NotSupportedException(String.Format("Unknown nodeType: {0}", node.Name)); } } string Id = toolbarItem.GetAttribute("id", string.Empty); string Text = toolbarItem.GetAttribute("text", string.Empty); string ImageUrl = toolbarItem.GetAttribute("imageUrl", string.Empty); string CssClass = toolbarItem.GetAttribute("cssClass", string.Empty); string Align = toolbarItem.GetAttribute("align", string.Empty); string Handler = toolbarItem.GetAttribute("handler", string.Empty); string CommandName = toolbarItem.GetAttribute("commandName", string.Empty); string ItemSplitter = toolbarItem.GetAttribute("itemSplitter", string.Empty); string Tooltip = toolbarItem.GetAttribute("tooltip", string.Empty); McToolbarItemAlign itemAlign = McToolbarItemAlign.Left; McToolbarItemSplitter itemSplitter = McToolbarItemSplitter.None; #region Set enum: McToolbarItemAlign if (Align != string.Empty) { try { itemAlign = (McToolbarItemAlign)Enum.Parse(typeof(McToolbarItemAlign), Align); } catch { throw; } } #endregion #region Set enum: McToolbarItemSplitter if (ItemSplitter != string.Empty) { try { itemSplitter = (McToolbarItemSplitter)Enum.Parse(typeof(McToolbarItemSplitter), ItemSplitter); } catch { throw; } } #endregion item.Id = Id; item.Text = CHelper.GetResFileString(Text); if (ImageUrl != string.Empty && (item.ItemType == McToolbarItemType.Button || item.ItemType == McToolbarItemType.SplitButton)) { item.CssClass += "x-btn-wrap x-btn x-btn-text-icon "; } item.ImageUrl = this.ResolveClientUrl(ImageUrl); // this.ResolveUrl dont work here item.CssClass += CssClass; item.ItemAlign = itemAlign; item.Handler = Handler; item.Tooltip = CHelper.GetResFileString(Tooltip); CommandParameters param = new CommandParameters(CommandName); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("GridId", this.GridId); param.CommandArguments = dic; bool isEnable = true; if (CommandName != string.Empty) { string commandManagerScript = CommandManager.GetCurrent(this.Page).AddCommand(this.ClassName, this.ViewName, this.PlaceName, param, out isEnable); dic.Add("CommandManagerScript", commandManagerScript); item.Params = param.ToString(); item.Handler = defaultClientHandler; } if (item.ItemType == McToolbarItemType.Menu || item.ItemType == McToolbarItemType.SplitButton) { GetToolbarItemsFromXml(toolbarItem, item.Items); } if (isEnable && (itemSplitter == McToolbarItemSplitter.Both || itemSplitter == McToolbarItemSplitter.Left)) { McToolbarItem splitItem = new McToolbarItem(McToolbarItemType.Splitter); splitItem.ItemAlign = itemAlign; itemsCollection.Add(splitItem); } if (isEnable) { itemsCollection.Add(item); } if (isEnable && (itemSplitter == McToolbarItemSplitter.Both || itemSplitter == McToolbarItemSplitter.Right)) { McToolbarItem splitItem = new McToolbarItem(McToolbarItemType.Splitter); splitItem.ItemAlign = itemAlign; itemsCollection.Add(splitItem); } } }
private void BindFromObject(ToolBarItem[] itemCollection, List <McToolbarItem> toolbarItemsCollection) { if (itemCollection == null) { return; } foreach (ToolBarItem toolBarItem in itemCollection) { McToolbarItem mcToolbarItem1 = new McToolbarItem(); if (toolBarItem is Menu) { mcToolbarItem1.ItemType = McToolbarItemType.Menu; } else if (toolBarItem is Button) { mcToolbarItem1.ItemType = McToolbarItemType.Button; } else if (toolBarItem is SplitButton) { mcToolbarItem1.ItemType = McToolbarItemType.SplitButton; } else if (toolBarItem is Text) { mcToolbarItem1.ItemType = McToolbarItemType.Text; } else if (toolBarItem is Splitter) { mcToolbarItem1.ItemType = McToolbarItemType.Splitter; } McToolbarItemAlign toolbarItemAlign = McToolbarItemAlign.Left; McToolbarItemSplitter toolbarItemSplitter = McToolbarItemSplitter.None; if (!string.IsNullOrEmpty(toolBarItem.align)) { try { toolbarItemAlign = (McToolbarItemAlign)Enum.Parse(typeof(McToolbarItemAlign), toolBarItem.align); } catch { throw; } } if (!string.IsNullOrEmpty(toolBarItem.itemSplitter)) { try { toolbarItemSplitter = (McToolbarItemSplitter)Enum.Parse(typeof(McToolbarItemSplitter), toolBarItem.itemSplitter); } catch { throw; } } if (toolBarItem.imageUrl != string.Empty && (mcToolbarItem1.ItemType == McToolbarItemType.Button || mcToolbarItem1.ItemType == McToolbarItemType.SplitButton || mcToolbarItem1.ItemType == McToolbarItemType.Menu)) { mcToolbarItem1.CssClass += "x-btn-wrap x-btn x-btn-text-icon "; } mcToolbarItem1.Id = toolBarItem.id; mcToolbarItem1.Text = this.IsTopMenuWelcomeText(toolBarItem.text) ? this.GetTopMenuWelcomeText(toolBarItem.text) : UtilHelper.GetResFileString(toolBarItem.text); mcToolbarItem1.ImageUrl = this.ResolveClientUrl(toolBarItem.imageUrl); mcToolbarItem1.CssClass += toolBarItem.cssClass; mcToolbarItem1.ItemAlign = toolbarItemAlign; mcToolbarItem1.Handler = toolBarItem.handler; mcToolbarItem1.Tooltip = UtilHelper.GetResFileString(toolBarItem.tooltip); bool isEnabled = true; if (!string.IsNullOrEmpty(toolBarItem.commandName)) { CommandParameters cp = new CommandParameters(toolBarItem.commandName); Dictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary.Add("GridId", this.GridId); dictionary.Add("GridClientId", this.GridClientId); dictionary.Add("permissions", toolBarItem.permissions); if (!string.IsNullOrEmpty(this.ContainerId)) { dictionary.Add("ContainerId", this.ContainerId); } cp.CommandArguments = dictionary; string str = CommandManager.GetCurrent(this.Page).AddCommand(this.ClassName, this.ViewName, this.PlaceName, cp, out isEnabled); dictionary.Add("CommandManagerScript", str); cp.CommandArguments = dictionary; mcToolbarItem1.Params = cp.ToString(); mcToolbarItem1.Handler = "defaultToolbarOnClick"; } if (mcToolbarItem1.ItemType == McToolbarItemType.Menu || mcToolbarItem1.ItemType == McToolbarItemType.SplitButton) { if (toolBarItem is Menu) { this.BindFromObject((toolBarItem as Menu).Items, mcToolbarItem1.Items); } else if (toolBarItem is SplitButton) { this.BindFromObject((toolBarItem as SplitButton).Items, mcToolbarItem1.Items); } } if (isEnabled && (toolbarItemSplitter == McToolbarItemSplitter.Both || toolbarItemSplitter == McToolbarItemSplitter.Left)) { McToolbarItem mcToolbarItem2 = new McToolbarItem(McToolbarItemType.Splitter); mcToolbarItem2.ItemAlign = toolbarItemAlign; toolbarItemsCollection.Add(mcToolbarItem2); } if (isEnabled) { toolbarItemsCollection.Add(mcToolbarItem1); } if (isEnabled && (toolbarItemSplitter == McToolbarItemSplitter.Both || toolbarItemSplitter == McToolbarItemSplitter.Right)) { McToolbarItem mcToolbarItem2 = new McToolbarItem(McToolbarItemType.Splitter); mcToolbarItem2.ItemAlign = toolbarItemAlign; toolbarItemsCollection.Add(mcToolbarItem2); } } }
/// <summary> /// Gets the toolbar items from XML. /// </summary> /// <param name="node">The node.</param> /// <param name="itemsCollection">The items collection.</param> private void GetToolbarItemsFromXml(XPathNavigator node, List<McToolbarItem> itemsCollection) { foreach (XPathNavigator toolbarItem in node.SelectChildren(string.Empty, string.Empty)) { McToolbarItem item = new McToolbarItem(); switch (toolbarItem.Name) { case "Text": { item.ItemType = McToolbarItemType.Text; break; } case "Splitter": { item.ItemType = McToolbarItemType.Splitter; break; } case "Button": { item.ItemType = McToolbarItemType.Button; break; } case "Menu": { item.ItemType = McToolbarItemType.Menu; break; } case "SplitButton": { item.ItemType = McToolbarItemType.SplitButton; break; } default: { throw new NotSupportedException(String.Format("Unknown nodeType: {0}", node.Name)); } } string Id = toolbarItem.GetAttribute("id", string.Empty); string Text = toolbarItem.GetAttribute("text", string.Empty); string ImageUrl = toolbarItem.GetAttribute("imageUrl", string.Empty); string CssClass = toolbarItem.GetAttribute("cssClass", string.Empty); string Align = toolbarItem.GetAttribute("align", string.Empty); string Handler = toolbarItem.GetAttribute("handler", string.Empty); string CommandName = toolbarItem.GetAttribute("commandName", string.Empty); string ItemSplitter = toolbarItem.GetAttribute("itemSplitter", string.Empty); string Tooltip = toolbarItem.GetAttribute("tooltip", string.Empty); McToolbarItemAlign itemAlign = McToolbarItemAlign.Left; McToolbarItemSplitter itemSplitter = McToolbarItemSplitter.None; #region Set enum: McToolbarItemAlign if (Align != string.Empty) { try { itemAlign = (McToolbarItemAlign)Enum.Parse(typeof(McToolbarItemAlign), Align); } catch { throw; } } #endregion #region Set enum: McToolbarItemSplitter if (ItemSplitter != string.Empty) { try { itemSplitter = (McToolbarItemSplitter)Enum.Parse(typeof(McToolbarItemSplitter), ItemSplitter); } catch { throw; } } #endregion item.Id = Id; item.Text = CHelper.GetResFileString(Text); if (ImageUrl != string.Empty && (item.ItemType == McToolbarItemType.Button || item.ItemType == McToolbarItemType.SplitButton)) item.CssClass += "x-btn-wrap x-btn x-btn-text-icon "; item.ImageUrl = this.ResolveClientUrl(ImageUrl); // this.ResolveUrl dont work here item.CssClass += CssClass; item.ItemAlign = itemAlign; item.Handler = Handler; item.Tooltip = CHelper.GetResFileString(Tooltip); CommandParameters param = new CommandParameters(CommandName); Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("GridId", this.GridId); param.CommandArguments = dic; bool isEnable = true; if (CommandName != string.Empty) { string commandManagerScript = CommandManager.GetCurrent(this.Page).AddCommand(this.ClassName, this.ViewName, this.PlaceName, param, out isEnable); dic.Add("CommandManagerScript", commandManagerScript); item.Params = param.ToString(); item.Handler = defaultClientHandler; } if (item.ItemType == McToolbarItemType.Menu || item.ItemType == McToolbarItemType.SplitButton) GetToolbarItemsFromXml(toolbarItem, item.Items); if (isEnable && (itemSplitter == McToolbarItemSplitter.Both || itemSplitter == McToolbarItemSplitter.Left)) { McToolbarItem splitItem = new McToolbarItem(McToolbarItemType.Splitter); splitItem.ItemAlign = itemAlign; itemsCollection.Add(splitItem); } if (isEnable) itemsCollection.Add(item); if (isEnable && (itemSplitter == McToolbarItemSplitter.Both || itemSplitter == McToolbarItemSplitter.Right)) { McToolbarItem splitItem = new McToolbarItem(McToolbarItemType.Splitter); splitItem.ItemAlign = itemAlign; itemsCollection.Add(splitItem); } } }