/// <include file='doc\VsWindowPane.uex' path='docs/doc[@for="VsWindowPane.IVsToolboxUser.IsSupported"]/*' /> /// <devdoc> /// </devdoc> int IVsToolboxUser.IsSupported(NativeMethods.IOleDataObject pDO) { int supported = NativeMethods.S_FALSE; if (toolboxService == null) { toolboxService = (IToolboxService)GetService(typeof(IToolboxService)); } if (toolboxService != null && toolboxService.IsSupported(pDO, DesignerHost)) { supported = NativeMethods.S_OK; } if (toolboxUser == null) { toolboxUser = (IVsToolboxUser)GetService(typeof(IVsToolboxUser)); } if (toolboxUser != null) { if (toolboxUser.IsSupported(pDO) == NativeMethods.S_OK) { supported = NativeMethods.S_OK; } } return(supported); }
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[] { }); }
private void OnStatusPaste(object sender, EventArgs e) { MenuCommand command = (MenuCommand)sender; command.Enabled = false; object primarySelection = this.selectionService.PrimarySelection; CompositeActivityDesigner parentDesigner = ActivityDesigner.GetDesigner(primarySelection as Activity) as CompositeActivityDesigner; if (parentDesigner == null) { parentDesigner = ActivityDesigner.GetParentDesigner(primarySelection); } if ((parentDesigner != null) && parentDesigner.IsEditable) { IDesignerHost host = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost; IToolboxService service = (IToolboxService)this.serviceProvider.GetService(typeof(IToolboxService)); IDataObject dataObject = Clipboard.GetDataObject(); if (((dataObject != null) && (host != null)) && ((dataObject.GetDataPresent("CF_WINOEDESIGNERCOMPONENTS") || (service == null)) || service.IsSupported(dataObject, host))) { System.Workflow.ComponentModel.Design.HitTestInfo insertLocation = null; if (primarySelection is System.Workflow.ComponentModel.Design.HitTestInfo) { insertLocation = (System.Workflow.ComponentModel.Design.HitTestInfo)primarySelection; } else if (primarySelection is CompositeActivity) { insertLocation = new System.Workflow.ComponentModel.Design.HitTestInfo(parentDesigner, HitTestLocations.Designer); } else if (primarySelection is Activity) { Activity item = primarySelection as Activity; CompositeActivity parent = item.Parent; CompositeActivityDesigner designer = ActivityDesigner.GetDesigner(parent) as CompositeActivityDesigner; if (designer != null) { insertLocation = new ConnectorHitTestInfo(designer, HitTestLocations.Designer, parent.Activities.IndexOf(item) + 1); } } ICollection activities = null; try { activities = CompositeActivityDesigner.DeserializeActivitiesFromDataObject(this.serviceProvider, dataObject); } catch (CheckoutException exception) { if (exception != CheckoutException.Canceled) { throw exception; } } command.Enabled = ((activities != null) && (insertLocation != null)) && parentDesigner.CanInsertActivities(insertLocation, new List <Activity>(Helpers.GetTopLevelActivities(activities)).AsReadOnly()); } } }
public FireflyComponentBrowser() : base(null) { // Set the window title reading it from the resources. this.Caption = "Firefly Toolbox"; // Set the image that will appear on the tab of the window frame // when docked with an other window // The resource ID correspond to the one defined in the resx file // while the Index is the offset in the bitmap strip. Each image in // the strip being 16x16. this.BitmapResourceID = 301; this.BitmapIndex = 1; control = new MyControl(); Panel p = new Panel(); p.BorderStyle = BorderStyle.None; p.Dock = DockStyle.Fill; p.BackColor = SystemColors.ControlDark; System.Windows.Forms.TreeView treeView = new TreeView(); ImageListManager imageList = new ImageListManager(); imageList.SetToTreeView(treeView); //treeView.Dock = DockStyle.Fill; treeView.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom; treeView.BorderStyle = BorderStyle.None; uint cookie = 0; Cmd addSelectedControlToToolBox = delegate { try { IToolboxService toolboxService = (IToolboxService)this.GetService(typeof(IToolboxService)); toolboxService.AddToolboxItem((ToolboxItem)treeView.SelectedNode.Tag, toolboxService.SelectedCategory ?? "General"); } catch { } }; ToolStrip toolStrip = new ToolStrip(); toolStrip.GripStyle = ToolStripGripStyle.Hidden; //toolStrip.Dock = DockStyle.Top; ProfessionalColorTable professionalColorTable = new ProfessionalColorTable(); professionalColorTable.UseSystemColors = true; ToolStripProfessionalRenderer toolStripRenderer = new ToolStripProfessionalRenderer(professionalColorTable); toolStripRenderer.RoundedEdges = false; toolStrip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; toolStrip.Renderer = toolStripRenderer; control.Controls.Add(p); toolStrip.AutoSize = false; toolStrip.Bounds = new Rectangle(1, 0, p.Width - 2, toolStrip.Height + 1); treeView.Bounds = new Rectangle(1, toolStrip.Height + 1, p.Width - 2, p.Height - toolStrip.Height - 2); // p.Padding = new Padding(1,0,1,1); // treeView.Margin = new Padding(0, 1, 0, 0); p.Controls.Add(treeView); p.Controls.Add(toolStrip); imageList.Add("Assembly", Resources.Assembly); imageList.Add("Namespace", Resources.Namespace); Bitmap bmp = Resources.AddToFavoritesHS; ToolStripButton addToToolBoxButton = new ToolStripButton(bmp); addToToolBoxButton.ToolTipText = "Add to tool box"; addToToolBoxButton.ImageTransparentColor = System.Drawing.Color.Black; toolStrip.Items.Add(addToToolBoxButton); addToToolBoxButton.Click += delegate { addSelectedControlToToolBox(); }; ContextMenuStrip contextMenu = new ContextMenuStrip(); ToolStripMenuItem addToToolBoxMenuItem = new ToolStripMenuItem("&Add to tool box", bmp); addToToolBoxMenuItem.ImageTransparentColor = System.Drawing.Color.Black; addToToolBoxMenuItem.Click += delegate { addSelectedControlToToolBox(); }; contextMenu.Items.Add(addToToolBoxMenuItem); ToolStripMenuItem about = new ToolStripMenuItem("A&bout"); about.Click += delegate { new AboutBox().ShowDialog(); }; contextMenu.Items.Add(new ToolStripSeparator()); contextMenu.Items.Add(about); treeView.BeforeSelect += delegate(object sender, TreeViewCancelEventArgs e) { addToToolBoxButton.Enabled = e.Node.Tag != null; addToToolBoxMenuItem.Enabled = e.Node.Tag != null; }; treeView.ContextMenuStrip = contextMenu; treeView.MouseDown += delegate(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { TreeNode node = treeView.HitTest(e.Location).Node; if (node != null) { treeView.SelectedNode = node; if (treeView.SelectedNode.Tag != null) { contextMenu.Show(treeView, e.Location); } } } }; SelectionHandler selectionHandler = new SelectionHandler(treeView); treeView.KeyDown += delegate(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Apps && treeView.SelectedNode.Tag != null) { contextMenu.Show(treeView, 0, 0); } }; bool reloading = false; System.Windows.Forms.ToolStripProgressBar progress = new ToolStripProgressBar(); progress.Visible = false; progress.Height = 10; progress.ProgressBar.Height = 10; System.Windows.Forms.ToolStripLabel loading = new ToolStripLabel(); loading.Text = "Loading..."; loading.Visible = false; Thread theThread = null; Bitmap bmp1 = Resources.Refresh; ToolStripButton refreshButton = new ToolStripButton(bmp1); refreshButton.ToolTipText = "Refresh"; refreshButton.ImageTransparentColor = System.Drawing.Color.Black; toolStrip.Items.Add(refreshButton); Action <bool> end = delegate(bool treeEnabled) { reloading = false; DoOnUIThread(delegate() { progress.Visible = false; loading.Visible = false; refreshButton.Enabled = true; treeView.Enabled = treeEnabled; }); selectionHandler.EndLoading(); theThread = null; }; Action <string> reportMessage = delegate(string message) { IVsOutputWindow outWindow = GetService(typeof(SVsOutputWindow)) as IVsOutputWindow; if (outWindow != null) { Guid generalWindowGuid = Microsoft.VisualStudio.VSConstants.GUID_OutWindowGeneralPane; IVsOutputWindowPane windowPane; outWindow.GetPane(ref generalWindowGuid, out windowPane); windowPane.OutputString(message); } }; Action <Exception> reportException = delegate(Exception ex) { reportMessage(string.Format("{0}\n\n{1}\n", ex.Message, ex.StackTrace)); }; Action <bool> reloadTree = delegate(bool forceRefresh) { if (reloading) { return; } reloading = true; EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE)); IDesignerHost designerHost = GetActiveDesigner(dte); if (designerHost == null) { end(false); return; } IToolboxService toolboxService = (IToolboxService)designerHost.GetService( typeof(IToolboxService)); Type rootBaseType = null; try { if (designerHost.RootComponent == null) { end(false); return; } rootBaseType = designerHost.RootComponent.GetType(); } catch { end(false); return; } if (!forceRefresh && _lastDesignedType != typeof(object)) { end(_lastDesignedType == rootBaseType); return; } _lastDesignedType = rootBaseType; DoOnUIThread(delegate() { progress.Visible = true; loading.Visible = true; refreshButton.Enabled = false; progress.Value = 1; treeView.Nodes.Clear(); }); selectionHandler.Reloadion(); theThread = new Thread( delegate() { lock (reloadLock) { try { VSLangProj.VSProject proj = (VSLangProj.VSProject)dte.ActiveDocument.ProjectItem.ContainingProject.Object; string projectOutputFileName = System.IO.Path.Combine( proj.Project.ConfigurationManager. ActiveConfiguration .Properties.Item("OutputPath").Value. ToString(), proj.Project.Properties.Item("OutputFileName"). Value. ToString ()); string fullProjectOutputFileName = System.IO.Path.IsPathRooted(projectOutputFileName) ? projectOutputFileName : System.IO.Path.Combine( System.IO.Path.GetDirectoryName( proj.Project.FileName), projectOutputFileName); AddAssembly addAssembly = delegate(string assemblyPath, bool publicTypesOnly) { AppDomainSetup ads = new AppDomainSetup(); ads.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); AppDomain appDomainForAssemblyLoading = AppDomain.CreateDomain( "AppDomainForAssemblyLoading", null, ads); System.Collections.Generic.SortedDictionary <string, System.Collections.Generic.SortedDictionary <string, TreeNode> > nodes = new System.Collections.Generic.SortedDictionary <string, System.Collections.Generic.SortedDictionary <string, TreeNode> >(); AssemblyName assemblyName = null; try { assemblyName = ((AssemblyNameProxy) appDomainForAssemblyLoading.CreateInstanceAndUnwrap( typeof(AssemblyNameProxy).Assembly.FullName, typeof(AssemblyNameProxy).FullName)).GetAssemblyName(assemblyPath); ResolveEventHandler resolve = delegate(object sender, ResolveEventArgs args) { return(args.Name == Assembly.GetExecutingAssembly().FullName ? Assembly.GetExecutingAssembly() : null); }; AppDomain.CurrentDomain.AssemblyResolve += resolve; AssemblyLoader assemblyLoader = (AssemblyLoader) appDomainForAssemblyLoading.CreateInstanceFromAndUnwrap( Assembly.GetExecutingAssembly().Location, typeof(AssemblyLoaderClass).FullName); AppDomain.CurrentDomain.AssemblyResolve -= resolve; assemblyLoader.DoOnTypes(assemblyName, System.IO.Path.GetDirectoryName(fullProjectOutputFileName), new AssemblyLoaderClientClass( delegate(string typeNamespace, ToolboxItem item) { try { if (toolboxService.IsSupported(toolboxService.SerializeToolboxItem(item), designerHost)) { item.Lock(); System.Windows.Forms.TreeNode node = new TreeNode(); DoOnUIThread( delegate() { node = new TreeNode(item.DisplayName); node.Tag = item; imageList.Add(item.TypeName, item.Bitmap); node.ImageIndex = imageList.GetImageIndexFor(item.TypeName); node.SelectedImageIndex = imageList.GetImageIndexFor(item.TypeName); }); System.Collections.Generic.SortedDictionary <string, TreeNode> componentNodes; if (!nodes.TryGetValue(typeNamespace, out componentNodes)) { componentNodes = new System.Collections.Generic.SortedDictionary < string, TreeNode>(); nodes.Add(typeNamespace, componentNodes); } componentNodes.Add(item.DisplayName, node); } } catch (Exception e) { try { reportMessage( string.Format( "Firefly Toolbox error - Exception occured on load of " + item.TypeName + " the exception is:\n" + e)); } catch { } } }), publicTypesOnly); } catch (Exception e) { try { DoOnUIThread( delegate() { System.Windows.Forms.TreeNode node = new TreeNode(); node.Text = "Error loading " + assemblyName + " - " + e.ToString(); treeView.Nodes.Add(node); }); reportMessage( string.Format( "Firefly Toolbox error - Exception occured on load of " + assemblyName.ToString() + " the exception is:\n" + e)); ReflectionTypeLoadException le = e as ReflectionTypeLoadException; if (le != null) { foreach (Exception ie in le.LoaderExceptions) { reportMessage( string.Format( "loader exception exception exception is:\n" + ie)); } } } catch { } } finally { AppDomain.Unload(appDomainForAssemblyLoading); } if (nodes.Count > 0) { DoOnUIThread( delegate { treeView.BeginUpdate(); try { System.Windows.Forms.TreeNode assemblyNode = new TreeNode(assemblyName.Name); assemblyNode.ImageIndex = imageList.GetImageIndexFor("Assembly"); assemblyNode.SelectedImageIndex = imageList.GetImageIndexFor("Assembly"); treeView.Nodes.Add(assemblyNode); foreach (System.Collections.Generic.KeyValuePair <string, System.Collections.Generic.SortedDictionary <string, TreeNode> > pair in nodes) { TreeNode namespaceNode = new TreeNode(pair.Key); namespaceNode.ImageIndex = imageList.GetImageIndexFor("Namespace"); namespaceNode.SelectedImageIndex = imageList.GetImageIndexFor("Namespace"); assemblyNode.Nodes.Add(namespaceNode); foreach (TreeNode n in pair.Value.Values) { namespaceNode.Nodes.Add(n); selectionHandler.Loaded(n); } imageList.CommitToUi(); } } finally { treeView.EndUpdate(); if (treeView.SelectedNode != null) { treeView.Update(); treeView.Select(); } } }); } }; System.Collections.Generic.SortedDictionary <string, Cmd> addAssemblies = new System.Collections.Generic.SortedDictionary <string, Cmd>(); if (System.IO.File.Exists(fullProjectOutputFileName)) { addAssemblies[Path.GetFileName(fullProjectOutputFileName)] = delegate { addAssembly(fullProjectOutputFileName, false); }; } foreach ( VSLangProj.Reference reference in proj.References) { string path = reference.Path; addAssemblies[Path.GetFileName(path)] = delegate { addAssembly(path, true); }; } DoOnUIThread( delegate() { progress.ProgressBar.Maximum = addAssemblies.Count + 1; }); foreach (Cmd cmd in addAssemblies.Values) { cmd(); DoOnUIThread( delegate() { try { progress.ProgressBar.Value++; } catch { } }); } } catch (Exception ex) { if (!(ex is ThreadAbortException)) { reportException(ex); } } finally { end(true); } } }); theThread.Start(); }; loading.Click += delegate { reloading = false; theThread.Abort(); end(true); }; refreshButton.Click += delegate { reloadTree(true); }; toolStrip.Items.Add(progress); toolStrip.Items.Add(loading); mySelectionListener listener = new mySelectionListener(treeView, delegate() { reloadTree(false); }); control.Load += delegate { IVsMonitorSelection monitor = (IVsMonitorSelection)GetService(typeof(IVsMonitorSelection)); monitor.AdviseSelectionEvents(listener, out cookie); reloadTree(false); }; control.Disposed += delegate { IVsMonitorSelection monitor = (IVsMonitorSelection)GetService(typeof(IVsMonitorSelection)); monitor.UnadviseSelectionEvents(cookie); }; treeView.ItemDrag += delegate(object sender, ItemDragEventArgs e) { IToolboxService toolboxService = (IToolboxService)this.GetService(typeof(IToolboxService)); System.Windows.Forms.TreeNode node = (System.Windows.Forms.TreeNode)e.Item; if (node.Tag == null) { return; } System.Windows.Forms.DataObject dataObject = toolboxService.SerializeToolboxItem( (ToolboxItem)node.Tag) as System.Windows.Forms.DataObject; treeView.DoDragDrop(dataObject, System.Windows.Forms.DragDropEffects.All); }; }