/// <include file='doc\VsWindowPane.uex' path='docs/doc[@for="VsWindowPane.IVsToolboxUser.ItemPicked"]/*' /> /// <devdoc> /// This happens when a user double-clicks a toolbox item. We add the /// item to the center of the form. /// </devdoc> void IVsToolboxUser.ItemPicked(NativeMethods.IOleDataObject pDO) { if (toolboxService == null) { toolboxService = (IToolboxService)GetService((typeof(IToolboxService))); } if (toolboxService != null) { ToolboxItem item = toolboxService.DeserializeToolboxItem(pDO, DesignerHost); if (item != null) { if (OnToolPicked(item)) { toolboxService.SelectedToolboxItemUsed(); } } } if (toolboxUser == null) { toolboxUser = (IVsToolboxUser)GetService(typeof(IVsToolboxUser)); } if (toolboxUser != null) { toolboxUser.ItemPicked(pDO); } }
/// <summary> /// get the current toolbox item from the drag event /// </summary> /// <param name="de"></param> /// <returns></returns> ToolboxItem GetToolboxItem(DragEventArgs de) { ToolboxItem t = null;; IToolboxService toolboxService = (IToolboxService)GetService(typeof(IToolboxService)); if (toolboxService != null && de != null) { t = toolboxService.DeserializeToolboxItem(de.Data); } return(t); }
protected override void OnDragEnter(DragEventArgs de) { IToolboxService toolboxService = (IToolboxService)designerHost.GetService(typeof(IToolboxService)); if (toolboxService != null) { ToolboxItem mouseDragTool = toolboxService.DeserializeToolboxItem(de.Data, designerHost); if (mouseDragTool != null) { designerHost.Activate(); } } base.OnDragEnter(de); }
public static Activity[] DeserializeActivitiesFromDataObject(IServiceProvider serviceProvider, IDataObject dataObj, bool addReference) { IDesignerHost designerHost = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost)); if (designerHost == null) { throw new InvalidOperationException("IDesignerHost is missing."); } if (dataObj == null) { return new Activity[] { } } ; object data = dataObj.GetData(CF_DESIGNER); ICollection activities = null; if (data is Stream) { BinaryFormatter formatter = new BinaryFormatter(); ((Stream)data).Seek(0, SeekOrigin.Begin); object serializationData = formatter.Deserialize((Stream)data); if (serializationData is SerializationStore) { // get component serialization service ComponentSerializationService css = serviceProvider.GetService(typeof(ComponentSerializationService)) as ComponentSerializationService; if (css == null) { throw new Exception("ComponentSerializationService is missing."); } // deserialize data activities = css.Deserialize((SerializationStore)serializationData); } } else { // Now check for a toolbox item. IToolboxService ts = (IToolboxService)serviceProvider.GetService(typeof(IToolboxService)); if (ts != null && ts.IsSupported(dataObj, designerHost)) { ToolboxItem toolBoxItem = ts.DeserializeToolboxItem(dataObj, designerHost); if (toolBoxItem != null) { // this will make sure that we add the assembly reference to project if (addReference && toolBoxItem.AssemblyName != null) { ITypeResolutionService trs = serviceProvider.GetService(typeof(ITypeResolutionService)) as ITypeResolutionService; if (trs != null) { trs.ReferenceAssembly(toolBoxItem.AssemblyName); } } ActivityToolboxItem ActivityToolboxItem = toolBoxItem as ActivityToolboxItem; if (addReference && ActivityToolboxItem != null) { activities = ActivityToolboxItem.CreateComponentsWithUI(designerHost); } else { activities = toolBoxItem.CreateComponents(designerHost); } } } } return((activities != null) ? (Activity[])(new ArrayList(activities).ToArray(typeof(Activity))) : new Activity[] { }); }
public override void OnDragDrop(Glyph g, DragEventArgs e) { ToolStripPanelSelectionGlyph glyph = g as ToolStripPanelSelectionGlyph; bool flag = false; ArrayList controls = null; DropSourceBehavior.BehaviorDataObject data = e.Data as DropSourceBehavior.BehaviorDataObject; if (data == null) { if ((e.Data is DataObject) && (controls == null)) { IToolboxService service = (IToolboxService)this.serviceProvider.GetService(typeof(IToolboxService)); IDesignerHost host = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost; if ((service != null) && (host != null)) { ToolboxItem tool = service.DeserializeToolboxItem(e.Data, host); if (((tool.GetType(host) == typeof(ToolStrip)) || (tool.GetType(host) == typeof(MenuStrip))) || (tool.GetType(host) == typeof(StatusStrip))) { ToolStripPanelDesigner designer = host.GetDesigner(this.relatedControl) as ToolStripPanelDesigner; if (designer != null) { OleDragDropHandler oleDragHandler = designer.GetOleDragHandler(); if (oleDragHandler != null) { oleDragHandler.CreateTool(tool, this.relatedControl, 0, 0, 0, 0, false, false); } } } } } } else { controls = new ArrayList(data.DragComponents); foreach (Component component in controls) { ToolStrip strip = component as ToolStrip; if ((strip != null) && (strip.Parent != this.relatedControl)) { flag = true; break; } } if (flag) { Control parent = this.relatedControl.Parent; if (parent != null) { try { parent.SuspendLayout(); this.ExpandPanel(false); Rectangle bounds = glyph.Bounds; glyph.IsExpanded = true; this.behaviorService.Invalidate(bounds); this.behaviorService.Invalidate(glyph.Bounds); this.ReParentControls(controls, e.Effect == DragDropEffects.Copy); } finally { parent.ResumeLayout(true); } } } data.CleanupDrag(); } }