private WriterCommandDescriptor GetCommandDescriptor(ITypeDescriptorContext context, string name) { WriterCommandDescriptor result = null; foreach (object item in GetCommandDescriptors(context)) { if (item is WriterCommandDescriptor) { if (string.Compare(((WriterCommandDescriptor)item).CommandName, name, true) == 0) { result = (WriterCommandDescriptor)item; break; } } else if (item is WriterCommandModuleDescriptor) { WriterCommandModuleDescriptor module = (WriterCommandModuleDescriptor)item; foreach (WriterCommandDescriptor d in module.Commands) { if (string.Compare(d.CommandName, name, true) == 0) { result = d; break; } } if (result != null) { break; } } } return(result); }
public int Compare(object x, object y) { if (x is WriterCommandDescriptor) { return(string.Compare( ((WriterCommandDescriptor)x).CommandName, ((WriterCommandDescriptor)y).CommandName, true)); } else if (x is WriterCommandModuleDescriptor) { WriterCommandModuleDescriptor d1 = (WriterCommandModuleDescriptor)x; WriterCommandModuleDescriptor d2 = (WriterCommandModuleDescriptor)y; return(string.Compare(d1.Name, d2.Name, true)); } return(0); }
public static ArrayList GetCommandDescriptors(Type[] types) { ArrayList cmds = new ArrayList(); ArrayList mdls = new ArrayList(); //StringBuilder str = new StringBuilder(); //str.AppendLine("-------------"); //foreach (Type t in types) //{ // str.AppendLine("#" + t.FullName); //} //str.AppendLine("-------------"); //MessageBox.Show(str.ToString()); foreach (Type type in types) { if (type.IsSubclassOf(typeof(WriterCommand)) && type.Equals(typeof(WriterCommandDelegate)) == false) { WriterCommandDescriptor cmd = WriterCommandDescriptor.Create(type, false); if (cmd != null) { cmds.Add(cmd); } } else if (type.IsSubclassOf(typeof(CSWriterCommandModule))) { WriterCommandModuleDescriptor mdl = WriterCommandModuleDescriptor.Create(type, false); if (mdl != null) { mdls.Add(mdl); } } } cmds.Sort(new CommandDescriptorNameComparer()); mdls.Sort(new CommandDescriptorNameComparer()); ArrayList result = new ArrayList(); result.AddRange(cmds); result.AddRange(mdls); return(result); }
public static void FillTreeView(TreeView tvw, IEnumerable descriptors) { ImageList images = new ImageList(); images.Images.Add(CommandUtils.GetResourceImage( typeof(dlgCommandNameEditor).Assembly, "DCSoft.CSharpWriter.Commands.Images.CommandModule.bmp")); images.Images.Add(CommandUtils.GetResourceImage( typeof(dlgCommandNameEditor).Assembly, "DCSoft.CSharpWriter.Commands.Images.CommandDefault.bmp")); Dictionary <object, int> indexs = new Dictionary <object, int>(); // 初始化图标列表 foreach (object item in descriptors) { if (item is WriterCommandDescriptor) { WriterCommandDescriptor d = (WriterCommandDescriptor)item; if (d.Image != null) { images.Images.Add(d.Image); indexs[d] = images.Images.Count - 1; } else { indexs[d] = 1; } } else if (item is WriterCommandModuleDescriptor) { WriterCommandModuleDescriptor m = (WriterCommandModuleDescriptor)item; if (m.Image != null) { images.Images.Add(m.Image); indexs[m] = images.Images.Count - 1; } else { indexs[m] = 0; } foreach (WriterCommandDescriptor d in m.Commands) { if (d.Image != null) { images.Images.Add(d.Image); indexs[d] = images.Images.Count - 1; } else { indexs[d] = 1; } } } }//foreach tvw.ImageList = images; foreach (object item in descriptors) { if (item is WriterCommandDescriptor) { WriterCommandDescriptor d = (WriterCommandDescriptor)item; TreeNode cmdNode = new TreeNode(d.CommandName); cmdNode.Tag = item; if (indexs.ContainsKey(item)) { cmdNode.ImageIndex = indexs[item]; cmdNode.SelectedImageIndex = cmdNode.ImageIndex; } tvw.Nodes.Add(cmdNode); } else if (item is WriterCommandModuleDescriptor) { WriterCommandModuleDescriptor m = (WriterCommandModuleDescriptor)item; TreeNode moduleNode = new TreeNode(m.Name); moduleNode.Tag = m; if (indexs.ContainsKey(item)) { moduleNode.ImageIndex = indexs[item]; moduleNode.SelectedImageIndex = moduleNode.ImageIndex; } foreach (WriterCommandDescriptor d in m.Commands) { TreeNode cmdNode = new TreeNode(d.CommandName); cmdNode.Tag = d; if (indexs.ContainsKey(d)) { cmdNode.ImageIndex = indexs[d]; cmdNode.SelectedImageIndex = cmdNode.ImageIndex; } moduleNode.Nodes.Add(cmdNode); } tvw.Nodes.Add(moduleNode); } } }