void miAdd_Click(object sender, EventArgs e)
 {
     if (toolbox != null && itemList != null)
     {
         string[] saTypes = TypeImporter.SelectTypes();
         if (saTypes != null && saTypes.Length > 0)
         {
             for (int i = 0; i < saTypes.Length; i++)
             {
                 Type tp = Type.GetType(saTypes[i]);
                 if (tp != null)
                 {
                     xToolboxItem x;
                     x = new xToolboxItem(tp);
                     itemList.Items.Add(x);
                 }
                 else
                 {
                     MessageBox.Show(FindForm(), string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                               "Cannot load {0}", saTypes[i]), "Load types", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             AdjustSize();
             toolbox.Changed = true;
             toolbox.AdjustTabPos(this.Index - 1);
         }
     }
 }
예제 #2
0
        public void AddToolboxItem(string tab, Guid projectGuid, Type tp, string name, Bitmap img, Dictionary <string, object> properties)
        {
            xToolboxItem      ti   = createItem(tp, name, img, properties);
            ToolboxTabProject ptab = CreateProjectTab(tab, projectGuid);

            ptab.AddItem(ti);
        }
예제 #3
0
        private xToolboxItem createItem(Type tp, string name, Bitmap img, Dictionary <string, object> properties)
        {
            xToolboxItem ti = new xToolboxItem(tp, img);

            ti.IsTransient = true;
            if (properties != null)
            {
                foreach (KeyValuePair <string, object> kv in properties)
                {
                    ti.Properties.Add(kv.Key, kv.Value);
                }
            }
            ti.DisplayName = name;
            return(ti);
        }
 void miDel_Click(object sender, EventArgs e)
 {
     if (itemList.SelectedIndex > 0)
     {
         if (MessageBox.Show(this.FindForm(), "Do you want to remove this item?", "Toolbox", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             xToolboxItem x = itemList.Items[itemList.SelectedIndex] as xToolboxItem;
             if (x != null)
             {
                 itemList.Items.RemoveAt(itemList.SelectedIndex);
                 AdjustSize();
                 toolbox.Changed = true;
                 toolbox.AdjustTabPos(this.Index - 1);
             }
         }
     }
 }
예제 #5
0
        public Hashtable GetAllToolboxItems()
        {
            Hashtable ht = new Hashtable();

            if (toolTabs != null)
            {
                for (int i = 0; i < toolTabs.Length; i++)
                {
                    for (int j = 0; j < toolTabs[i].ToolboxItemCount; j++)
                    {
                        xToolboxItem xt = toolTabs[i][j + 1] as xToolboxItem;
                        if (xt != null)
                        {
                            ht[xt.Type] = xt;
                        }
                    }
                }
            }
            return(ht);
        }
예제 #6
0
 public void SetSelectedToolboxItem(ToolboxItem toolboxItem)
 {
     if (selectedList != null)
     {
         xToolboxItem x = toolboxItem as xToolboxItem;
         if (x != null)
         {
             Type t = x.Type;
             for (int i = 0; i < selectedList.Items.Count; i++)
             {
                 xToolboxItem item = selectedList.Items[i] as xToolboxItem;
                 if (item.Type.Equals(t))
                 {
                     selectedList.SelectedIndex = i;
                     break;
                 }
             }
         }
     }
 }
예제 #7
0
        public void SaveCustomToolboxTabs()
        {
            XmlDocument xml  = new XmlDocument();
            XmlNode     root = xml.CreateElement("Toolbox");

            xml.AppendChild(root);
            if (toolTabs != null)
            {
                for (int i = 0; i < toolTabs.Length; i++)
                {
                    ToolboxTab2 tab = toolTabs[i];
                    if (tab != null && tab.Persist)
                    {
                        XmlNode      node = xml.CreateElement("ToolboxTab");
                        XmlAttribute xa   = xml.CreateAttribute("title");
                        xa.Value = tab.Name;
                        node.Attributes.Append(xa);
                        //
                        if (tab.IsCustom)
                        {
                            xa       = xml.CreateAttribute("readonly");
                            xa.Value = "false";
                            node.Attributes.Append(xa);
                        }
                        root.AppendChild(node);
                        for (int j = 0; j < tab.ToolboxItemCount; j++)
                        {
                            xToolboxItem x = tab[j + 1] as xToolboxItem;
                            if (x != null && x.Type != null)
                            {
                                node.AppendChild(x.CreateNode(xml));
                            }
                        }
                    }
                }
            }
            xml.Save(_toolboxXml);
            Changed = false;
        }
예제 #8
0
        public void AddToolboxItem(string tab, Type tp, string name, Bitmap img, Dictionary <string, object> properties)
        {
            xToolboxItem ti = createItem(tp, name, img, properties);

            AddToolboxItem(ti, tab);
        }
예제 #9
0
 public void ReadFromXmlFile(out string error)
 {
     if (_toolboxXml == null || _toolboxXml.Length == 0)
     {
         error = "ToolboxXml is empty";
         return;
     }
     if (!System.IO.File.Exists(_toolboxXml))
     {
         error = "ToolboxXml does not exist at " + _toolboxXml;
         return;
     }
     error = "";
     try
     {
         StreamReader sr  = new StreamReader(_toolboxXml);
         XmlDocument  xml = new XmlDocument();
         xml.LoadXml(sr.ReadToEnd());
         sr.Close();
         foreach (XmlNode nodeDoc in xml.ChildNodes)
         {
             if (string.CompareOrdinal(nodeDoc.Name, "Toolbox") == 0)
             {
                 foreach (XmlNode node in nodeDoc.ChildNodes)
                 {
                     if (string.CompareOrdinal(node.Name, "ToolboxTab") == 0)
                     {
                         XmlAttribute xa = node.Attributes["title"];
                         if (xa != null && xa.Value != null && xa.Value.Length > 0)
                         {
                             string name      = xa.Value;
                             bool   bReadOnly = true;
                             xa = node.Attributes["readonly"];
                             if (xa != null && xa.Value != null && xa.Value.Length > 0)
                             {
                                 bReadOnly = (string.Compare(xa.Value, "false", StringComparison.OrdinalIgnoreCase) != 0);
                             }
                             ToolboxTab2 tab = CreateTab(name, bReadOnly, -1);
                             foreach (XmlNode nd in node.ChildNodes)
                             {
                                 if (string.CompareOrdinal(nd.Name, "Item") == 0)
                                 {
                                     try
                                     {
                                         string s = nd.InnerText.Replace("\r", "").Replace("\n", "").Trim();
                                         Type   t = Type.GetType(s);
                                         if (t != null)
                                         {
                                             xToolboxItem xi;
                                             xa = nd.Attributes["Type"];
                                             if (xa != null)
                                             {
                                                 Type xt = Type.GetType(xa.Value);
                                                 xi = (xToolboxItem)Activator.CreateInstance(xt, new object[] { t });
                                             }
                                             else
                                             {
                                                 xi = new xToolboxItem(t);
                                             }
                                             xi.ReadNode(nd);
                                             tab.AddItem(xi);
                                         }
                                     }
                                     catch (Exception ee)
                                     {
                                         if (error.Length == 0)
                                         {
                                             error += ee.Message;
                                         }
                                         else
                                         {
                                             error += "\r\n" + ee.Message;
                                         }
                                     }
                                 }
                             }
                             tab.AdjustSize();
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         error = string.Format(CultureInfo.InvariantCulture, "{0}. \r\n{1}", e.Message, e.StackTrace);
     }
     OnResize(null);
     AdjustTabPos(0);
 }
 void itemList_MouseMove(object sender, MouseEventArgs e)
 {
     if (e.Button != MouseButtons.Left || itemList.SelectedIndex <= 0 || itemList.SelectedIndex != nSelectedIndex)
     {
         bPrepareDrag = false;
     }
     if (bPrepareDrag)
     {
         if (Math.Abs(e.X - x0) > 3 || Math.Abs(e.Y - y0) > 3)
         {
             ToolboxItem     tbi = itemList.Items[itemList.SelectedIndex] as ToolboxItem;
             xToolboxItem    xt  = tbi as xToolboxItem;
             InterfaceVOB    vob = ((IServiceContainer)toolbox.Host).GetService(typeof(InterfaceVOB)) as InterfaceVOB;
             IToolboxService tbs = ((IServiceContainer)toolbox.Host).GetService(typeof(IToolboxService)) as IToolboxService;
             if (tbs == null)
             {
                 if (vob == null)
                 {
                     bool          b   = true;
                     TraceLogClass log = new TraceLogClass();
                     log.Log("service InterfaceVOB not available", ref b);
                 }
                 else
                 {
                     PassData data = new PassData();
                     vob.SendNotice(enumVobNotice.GetToolbox, data);
                     tbs = data.Data as IToolboxService;
                 }
             }
             if (tbs != null)
             {
                 bool bCanDrop = true;
                 if (vob != null)
                 {
                     if (xt != null)
                     {
                         if (xt.Properties != null && xt.Properties.Contains("ClassId"))
                         {
                             ToolboxItemXType.SelectedToolboxClassId   = (UInt32)(xt.Properties["ClassId"]);
                             ToolboxItemXType.SelectedToolboxType      = null;
                             ToolboxItemXType.SelectedToolboxTypeKey   = null;
                             ToolboxItemXType.SelectedToolboxClassName = (string)(xt.Properties["DisplayName"]);
                         }
                         else
                         {
                             PassData pd = new PassData();
                             pd.Key        = xt.Type;
                             pd.Data       = true;
                             pd.Attributes = xt.Properties;
                             vob.SendNotice(enumVobNotice.ObjectCanCreate, pd);
                             bCanDrop = (bool)pd.Data;
                             if (bCanDrop && pd.Attributes != null)
                             {
                                 ToolboxItem tx0 = pd.Attributes as ToolboxItem;
                                 if (tx0 != null)
                                 {
                                     tbi = tx0;
                                 }
                             }
                         }
                     }
                 }
                 if (bCanDrop)
                 {
                     try
                     {
                         DataObject d = tbs.SerializeToolboxItem(tbi) as DataObject;
                         toolbox.HideToolBox(this, null);
                         itemList.DoDragDrop(d, DragDropEffects.Copy);
                     }
                     catch (Exception ex)
                     {
                         bool          b   = true;
                         TraceLogClass log = new TraceLogClass();
                         log.Log(this.FindForm(), ex, ref b);
                     }
                 }
             }
         }
     }
 }
        private void list_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // Regardless of which kind of click this is, we need to change the selection.
            // First we grab the bounds of the old selected tool so that we can de-higlight it.
            //
            ListBox lbSender = sender as ListBox;

            if (selectedIndex < 0)
            {
                selectedIndex = 0;
            }
            bPrepareDrag  = false;
            selectedIndex = lbSender.IndexFromPoint(e.X, e.Y);             // change our selection
            if (selectedIndex < 0)
            {
                selectedIndex = 0;
            }
            lbSender.SelectedIndex = selectedIndex;
            if (selectedIndex >= 0)
            {
                if (e.Button == MouseButtons.Right)
                {
                    ContextMenu mnu = new ContextMenu();
                    MenuItem    mi;
                    if (!_readOnly)
                    {
                        mi        = new MenuItem("Add Toolbox Item");
                        mi.Click += new EventHandler(miAdd_Click);
                        mi.Tag    = selectedIndex;
                        mnu.MenuItems.Add(mi);
                        if (selectedIndex > 0)
                        {
                            ToolboxItem item = lbSender.Items[selectedIndex] as ToolboxItem;
                            mi        = new MenuItem("Delete " + item.DisplayName);
                            mi.Click += new EventHandler(miDel_Click);
                            mi.Tag    = selectedIndex;
                            mnu.MenuItems.Add(mi);
                        }
                        Form f = lbSender.FindForm();
                        if (f != null)
                        {
                            Point p = lbSender.Parent.PointToScreen(new Point(e.X, e.Y));
                            p = f.PointToClient(p);
                            mnu.Show(f, p);
                        }
                    }
                }
                else
                {
                    if (toolbox != null && toolbox.Host != null)
                    {
                        // If this is a double-click, then the user wants to add the selected component
                        // to the default location on the designer, with the default size. We call
                        // ToolPicked on the current designer (as a IToolboxUser) to place the tool.
                        // The IToolboxService calls SelectedToolboxItemUsed(), which calls this control's
                        // SelectPointer() method.
                        //

                        if (e.Clicks == 2)
                        {
                            IToolboxUser tbu = toolbox.Host.GetDesigner(toolbox.Host.RootComponent) as IToolboxUser;
                            if (tbu != null)
                            {
                                ToolboxItemXType.SelectedToolboxTypeKey = string.Empty;
                                ToolboxItem  ti  = (ToolboxItem)(lbSender.Items[selectedIndex]);
                                xToolboxItem xti = ti as xToolboxItem;
                                if (xti != null)
                                {
                                    if (typeof(ToolboxItemXType).IsAssignableFrom(xti.Type))
                                    {
                                        ToolboxItemXType.SelectedToolboxTypeKey = ti.DisplayName;
                                        ToolboxItemXType.SelectedToolboxClassId = 0;
                                        ToolboxItemXType.SelectedToolboxType    = null;
                                    }
                                    else
                                    {
                                        if (xti.Properties.Contains("ClassId"))
                                        {
                                            ToolboxItemXType.SelectedToolboxClassId = (UInt32)xti.Properties["ClassId"];
                                            ToolboxItemXType.SelectedToolboxTypeKey = string.Empty;
                                            ToolboxItemXType.SelectedToolboxType    = null;
                                        }
                                        if (xti.Properties.Contains("DisplayName"))
                                        {
                                            ToolboxItemXType.SelectedToolboxClassName = (string)xti.Properties["DisplayName"];
                                        }
                                    }
                                }

                                tbu.ToolPicked(ti);
                                toolbox.HideToolBox(this, null);
                            }
                        }
                        // Otherwise this is either a single click or a drag. Either way, we do the same
                        // thing: start a drag--if this is just a single click, then the drag will
                        // abort as soon as there's a MouseUp event.
                        //
                        else if (e.Clicks < 2)
                        {
                            x0             = e.X;
                            y0             = e.Y;
                            nSelectedIndex = selectedIndex;
                            bPrepareDrag   = true;
                        }
                    }
                }
            }
        }