/// <summary> /// Swaps the order of the two specified tool components /// </summary> public void ExchangeToolComponents(string categoryName, string fullName1, string fullName2) { foreach (Category category in categories) { if (category.Name == categoryName) { int index1 = -1; int index2 = -1; for (int i = 0; i < category.ToolComponents.Count; ++i) { ToolComponent component = (ToolComponent)category.ToolComponents[i]; if (component.FullName == fullName1) { index1 = i; } else if (component.FullName == fullName2) { index2 = i; } if (index1 != -1 && index2 != -1) { ToolComponent component1 = (ToolComponent)category.ToolComponents[index1]; category.ToolComponents[index1] = category.ToolComponents[index2]; category.ToolComponents[index2] = component1; return; } } } } }
public bool LoadToolComponentLibrary(string fileName) { if (!File.Exists(fileName)) { return(false); } try { XmlDocument doc = new XmlDocument(); doc.Load(fileName); if (doc.DocumentElement.Name != "SharpDevelopControlLibrary" || doc.DocumentElement.Attributes["version"] == null || doc.DocumentElement.Attributes["version"].InnerText != VERSION) { return(false); } foreach (XmlNode node in doc.DocumentElement["Assemblies"].ChildNodes) { if (node.Name == "Assembly") { string assemblyName = node.Attributes["assembly"].InnerText; if (node.Attributes["path"] != null) { assemblies.Add(new ComponentAssembly(assemblyName, node.Attributes["path"].InnerText)); } else { assemblies.Add(new ComponentAssembly(assemblyName)); } } } foreach (XmlNode node in doc.DocumentElement["Categories"].ChildNodes) { if (node.Name == "Category") { string name = node.Attributes["name"].InnerText; Category newCategory = new Category(name); foreach (XmlNode componentNode in node.ChildNodes) { //在此加载工具栏xml文件里的属性 ToolComponent newToolComponent = new ToolComponent(componentNode.Attributes["class"].InnerText, componentNode.Attributes["displayname"].InnerText, componentNode.Attributes["image"].InnerText, (ComponentAssembly)assemblies[Int32.Parse(componentNode.Attributes["assembly"].InnerText)], IsEnabled(componentNode.Attributes["enabled"])); newCategory.ToolComponents.Add(newToolComponent); } categories.Add(newCategory); } } } catch { return(false); } return(true); }
public object Clone() { ToolComponent toolComponent = new ToolComponent(); toolComponent.FullName = fullName; toolComponent.AssemblyName = assemblyName; toolComponent.IsEnabled = isEnabled; return(toolComponent); }
public bool LoadToolComponentLibrary(string fileName) { if (!File.Exists(fileName)) { return(false); } try { XmlDocument doc = new XmlDocument(); doc.Load(fileName); if (doc.DocumentElement.Name != "SharpDevelopControlLibrary" || doc.DocumentElement.Attributes["version"] == null || doc.DocumentElement.Attributes["version"].InnerText != VERSION) { return(false); } foreach (XmlNode node in doc.DocumentElement["Assemblies"].ChildNodes) { if (node.Name == "Assembly") { string assemblyName = node.Attributes["assembly"].InnerText; if (node.Attributes["path"] != null) { assemblies.Add(new ComponentAssembly(assemblyName, node.Attributes["path"].InnerText)); } else { assemblies.Add(new ComponentAssembly(assemblyName)); } } } foreach (XmlNode node in doc.DocumentElement["Categories"].ChildNodes) { if (node.Name == "Category") { string name = PascalABCCompiler.StringResources.Get(node.Attributes["name"].InnerText);//roman// Category newCategory = new Category(name); foreach (XmlNode componentNode in node.ChildNodes) { ToolComponent newToolComponent = new ToolComponent(componentNode.Attributes["class"].InnerText, (ComponentAssembly)assemblies[Int32.Parse(componentNode.Attributes["assembly"].InnerText)], IsEnabled(componentNode.Attributes["enabled"])); newCategory.ToolComponents.Add(newToolComponent); } categories.Add(newCategory); } } } catch (Exception e) { ICSharpCode.Core.LoggingService.Warn("ComponentLibraryLoader.LoadToolComponentLibrary: " + e.Message); return(false); } return(true); }
public Bitmap GetIcon(ToolComponent component) { Assembly asm = component.LoadAssembly(); Type type = asm.GetType(component.FullName); Bitmap b = null; if (type != null) { object[] attributes = type.GetCustomAttributes(false); foreach (object attr in attributes) { if (attr is ToolboxBitmapAttribute) { ToolboxBitmapAttribute toolboxBitmapAttribute = (ToolboxBitmapAttribute)attr; b = new Bitmap(toolboxBitmapAttribute.GetImage(type)); b.MakeTransparent(); break; } } } if (b == null) { try { Stream imageStream = asm.GetManifestResourceStream(component.FullName + ".bmp"); if (imageStream != null) { b = new Bitmap(Image.FromStream(imageStream)); b.MakeTransparent(); } } catch (Exception e) { ICSharpCode.Core.LoggingService.Warn("ComponentLibraryLoader.GetIcon: " + e.Message); } } // TODO: Maybe default icon needed ??!?! return(b); }
void AddComponentsToList(Assembly assembly, string loadPath) { if (assembly != null) { Hashtable images = new Hashtable(); ImageList il = new ImageList(); // try to load res icon string[] imgNames = assembly.GetManifestResourceNames(); foreach (string im in imgNames) { try { Bitmap b = new Bitmap(Image.FromStream(assembly.GetManifestResourceStream(im))); b.MakeTransparent(); images[im] = il.Images.Count; il.Images.Add(b); } catch {} } try { componentListView.SmallImageList = il; foreach (Type t in assembly.GetExportedTypes()) { if (!t.IsAbstract) { if (t.IsDefined(typeof(ToolboxItemFilterAttribute), true) || t.IsDefined(typeof(ToolboxItemAttribute), true) || typeof(System.ComponentModel.IComponent).IsAssignableFrom(t)) { object[] attributes = t.GetCustomAttributes(false); object[] filterAttrs = t.GetCustomAttributes(typeof(DesignTimeVisibleAttribute), true); foreach (DesignTimeVisibleAttribute visibleAttr in filterAttrs) { if (!visibleAttr.Visible) { goto skip; } } if (images[t.FullName + ".bmp"] == null) { if (t.IsDefined(typeof(ToolboxBitmapAttribute), false)) { foreach (object attr in attributes) { if (attr is ToolboxBitmapAttribute) { ToolboxBitmapAttribute toolboxBitmapAttribute = (ToolboxBitmapAttribute)attr; images[t.FullName + ".bmp"] = il.Images.Count; Bitmap b = new Bitmap(toolboxBitmapAttribute.GetImage(t)); b.MakeTransparent(Color.Fuchsia); il.Images.Add(b); break; } } } } ListViewItem newItem = new ListViewItem(t.Name); newItem.SubItems.Add(t.Namespace); newItem.SubItems.Add(assembly.ToString()); newItem.SubItems.Add(assembly.Location); newItem.SubItems.Add(t.Namespace); if (images[t.FullName + ".bmp"] != null) { newItem.ImageIndex = (int)images[t.FullName + ".bmp"]; } newItem.Checked = true; ToolComponent toolComponent = new ToolComponent(t.FullName, new ComponentAssembly(assembly.FullName, loadPath), true); newItem.Tag = toolComponent; componentListView.Items.Add(newItem); ToolboxItem item = new ToolboxItem(t); skip :; } } } } catch (Exception e) { ClearComponentsList(e.Message); } } }
void AddComponentsToList(Assembly assembly, string loadPath) { if (assembly != null) { Hashtable images = new Hashtable(); ImageList il = new ImageList(); // try to load res icon string[] imgNames = assembly.GetManifestResourceNames(); foreach (string im in imgNames) { try { Bitmap b = new Bitmap(Image.FromStream(assembly.GetManifestResourceStream(im))); b.MakeTransparent(); images[im] = il.Images.Count; il.Images.Add(b); } catch {} } try { componentListView.SmallImageList = il; foreach (Type t in assembly.GetExportedTypes()) { if (!t.IsAbstract) { if (t.IsDefined(typeof(ToolboxItemFilterAttribute), true) || t.IsDefined(typeof(ToolboxItemAttribute), true) || typeof(System.ComponentModel.IComponent).IsAssignableFrom(t)) { object[] attributes = t.GetCustomAttributes(false); object[] filterAttrs = t.GetCustomAttributes(typeof(DesignTimeVisibleAttribute), true); foreach (DesignTimeVisibleAttribute visibleAttr in filterAttrs) { if (!visibleAttr.Visible) { goto skip; } } if (images[t.FullName + ".bmp"] == null) { if (t.IsDefined(typeof(ToolboxBitmapAttribute), false)) { foreach (object attr in attributes) { if (attr is ToolboxBitmapAttribute) { ToolboxBitmapAttribute toolboxBitmapAttribute = (ToolboxBitmapAttribute)attr; images[t.FullName + ".bmp"] = il.Images.Count; Bitmap b = new Bitmap(toolboxBitmapAttribute.GetImage(t)); b.MakeTransparent(Color.Fuchsia); il.Images.Add(b); break; } } } } ListViewItem newItem = new ListViewItem(t.Name); newItem.SubItems.Add(t.Namespace); newItem.SubItems.Add(assembly.ToString()); newItem.SubItems.Add(assembly.Location); newItem.SubItems.Add(t.Namespace); if (images[t.FullName + ".bmp"] != null) { newItem.ImageIndex = (int)images[t.FullName + ".bmp"]; } newItem.Checked = true; ToolComponent toolComponent = new ToolComponent(t.FullName, new ComponentAssembly(assembly.FullName, loadPath), true); newItem.Tag = toolComponent; componentListView.Items.Add(newItem); ToolboxItem item = new ToolboxItem(t); skip:; } } } } catch (Exception e) { ClearComponentsList(e.Message); } } }
void componentListViewItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e) { ToolComponent tc = (ToolComponent)((ListView)ControlDictionary["componentListView"]).Items[e.Index].Tag; tc.IsEnabled = !tc.IsEnabled; }
public Bitmap GetIcon(ToolComponent component) { Assembly asm = component.LoadAssembly(); Type type = asm.GetType(component.FullName); Bitmap b = null; if (type != null) { object[] attributes = type.GetCustomAttributes(false); foreach (object attr in attributes) { if (attr is ToolboxBitmapAttribute) { ToolboxBitmapAttribute toolboxBitmapAttribute = (ToolboxBitmapAttribute)attr; b = new Bitmap(toolboxBitmapAttribute.GetImage(type)); b.MakeTransparent(); break; } } } if (b == null) { try { Stream imageStream = asm.GetManifestResourceStream(component.FullName + ".bmp"); if (imageStream != null) { b = new Bitmap(Image.FromStream(imageStream)); b.MakeTransparent(); } } catch (Exception e) { ICSharpCode.Core.LoggingService.Warn("ComponentLibraryLoader.GetIcon: " + e.Message); } } // TODO: Maybe default icon needed ??!?! return b; }
public bool LoadToolComponentLibrary(string fileName) { if (!File.Exists(fileName)) { return false; } try { XmlDocument doc = new XmlDocument(); doc.Load(fileName); if (doc.DocumentElement.Name != "SharpDevelopControlLibrary" || doc.DocumentElement.Attributes["version"] == null || doc.DocumentElement.Attributes["version"].InnerText != VERSION) { return false; } foreach (XmlNode node in doc.DocumentElement["Assemblies"].ChildNodes) { if (node.Name == "Assembly") { string assemblyName = node.Attributes["assembly"].InnerText; if (node.Attributes["path"] != null) { assemblies.Add(new ComponentAssembly(assemblyName, node.Attributes["path"].InnerText)); } else { assemblies.Add(new ComponentAssembly(assemblyName)); } } } foreach (XmlNode node in doc.DocumentElement["Categories"].ChildNodes) { if (node.Name == "Category") { string name = PascalABCCompiler.StringResources.Get(node.Attributes["name"].InnerText);//roman// Category newCategory = new Category(name); foreach (XmlNode componentNode in node.ChildNodes) { ToolComponent newToolComponent = new ToolComponent(componentNode.Attributes["class"].InnerText, (ComponentAssembly)assemblies[Int32.Parse(componentNode.Attributes["assembly"].InnerText)], IsEnabled(componentNode.Attributes["enabled"])); newCategory.ToolComponents.Add(newToolComponent); } categories.Add(newCategory); } } } catch (Exception e) { ICSharpCode.Core.LoggingService.Warn("ComponentLibraryLoader.LoadToolComponentLibrary: " + e.Message); return false; } return true; }
public object Clone() { ToolComponent toolComponent = new ToolComponent(); toolComponent.FullName = fullName; toolComponent.AssemblyName = assemblyName; toolComponent.IsEnabled = isEnabled; return toolComponent; }