public virtual IList<ItemToolboxNode> Load (LoaderContext ctx, string filename)
		{
			SystemPackage sp = Runtime.SystemAssemblyService.DefaultAssemblyContext.GetPackageFromPath (filename);
			ReferenceType rt;
			string rname;
			
			if (sp != null) {
				rt = ReferenceType.Package;
				rname = Runtime.SystemAssemblyService.DefaultAssemblyContext.GetAssemblyFullName (filename, null);
			} else {
				rt = ReferenceType.Assembly;
				rname = filename;
			}
			
			List<ItemToolboxNode> list = new List<ItemToolboxNode> ();
			var types = Runtime.RunInMainThread (delegate {
				// Stetic is not thread safe, it has to be used from the gui thread
				return GuiBuilderService.SteticApp.GetComponentTypes (filename);
			}).Result;
			foreach (ComponentType ct in types) {
				if (ct.Category == "window")
					continue;
				ComponentToolboxNode cn = new ComponentToolboxNode (ct);
				cn.ReferenceType = rt;
				cn.Reference = rname;
				list.Add (cn);
			}
			return list;
		}
        void CheckReference(ComponentToolboxNode node)
        {
            if (node.Reference == null)
            {
                return;
            }

            ProjectReference pref;

            // If the class name includes an assembly name it means that the
            // widget is implemented in another assembly, not in the one that
            // has the objects.xml file.
            int i = node.ClassName.IndexOf(',');

            if (i != -1)
            {
                string asm = node.ClassName.Substring(i + 1).Trim();
                if (asm == "gtk-sharp")
                {
                    // If we are adding a widget to a window, the project must already have a gtk# reference
                    return;
                }

                asm = gproject.Project.AssemblyContext.GetAssemblyFullName(asm, gproject.Project.TargetFramework);
                if (asm == null)
                {
                    return;
                }
                if (gproject.Project.AssemblyContext.GetPackagesFromFullName(asm).Length > 0)
                {
                    pref = new ProjectReference(ReferenceType.Gac, asm);
                }
                else
                {
                    asm  = gproject.Project.AssemblyContext.GetAssemblyLocation(asm, gproject.Project.TargetFramework);
                    pref = new ProjectReference(ReferenceType.Assembly, asm);
                }
            }
            else
            {
                pref = new ProjectReference(node.ReferenceType, node.Reference);
            }

            foreach (ProjectReference pr in gproject.Project.References)
            {
                if (pr.Reference == pref.Reference)
                {
                    return;
                }
            }
            gproject.Project.References.Add(pref);
        }
        //Used if ToolboxItemFilterAttribute demands ToolboxItemFilterType.Custom
        //If not expecting it, should just return false
        bool IToolboxConsumer.CustomFilterSupports(ItemToolboxNode item)
        {
            ComponentToolboxNode cnode = item as ComponentToolboxNode;

            if (cnode != null && gproject.SteticProject != null)
            {
                if (cnode.GtkVersion == null || Mono.Addins.Addin.CompareVersions(gproject.SteticProject.TargetGtkVersion, cnode.GtkVersion) <= 0)
                {
                    return(true);
                }
            }
            return(false);
        }
 void IToolboxConsumer.DragItem(ItemToolboxNode item, Gtk.Widget source, Gdk.DragContext ctx)
 {
     if (designer != null)
     {
         ComponentToolboxNode node = item as ComponentToolboxNode;
         if (node != null)
         {
             if (node.Reference == null)
             {
                 designer.BeginComponentDrag(node.ComponentType, source, ctx);
             }
             else
             {
                 designer.BeginComponentDrag(node.Name, node.ClassName, source, ctx, delegate { CheckReference(node); });
             }
         }
     }
 }
		public IEnumerable<ItemToolboxNode> GetDynamicItems (IToolboxConsumer consumer)
		{
			GuiBuilderView view = consumer as GuiBuilderView;
			if (view == null)
				return null;
			
			ComponentType[] types = view.GetComponentTypes ();
			if (types == null)
				return null;
				
			Hashtable refs = new Hashtable ();
			Hashtable projects = new Hashtable ();
			string of = FileService.GetFullPath (view.Project.GetOutputFileName (IdeApp.Workspace.ActiveConfiguration));
			projects [of] = view.Project.Name;
			foreach (ProjectReference pr in ((DotNetProject)view.Project).References)
				foreach (string f in pr.GetReferencedFileNames (IdeApp.Workspace.ActiveConfiguration)) {
					if (pr.ReferenceType == ReferenceType.Project)
						projects[FileService.GetFullPath (f)] = pr.Reference;
					else
						refs[FileService.GetFullPath (f)] = f;
				}
			
			List<ItemToolboxNode> list = new List<ItemToolboxNode> ();
			foreach (ComponentType type in types) {
				if (type.Category == "window")
					continue;

				string fullName = null;
				if (!String.IsNullOrEmpty (type.Library))
					fullName = FileService.GetFullPath (type.Library);

				if (type.ClassName == "Gtk.Action" || (fullName != null && refs.Contains (fullName))) {
					ComponentToolboxNode node = new ComponentToolboxNode (type);
					list.Add (node);
				} else if (fullName != null && projects.Contains (fullName)) {
					ComponentToolboxNode node = new ComponentToolboxNode (type);
					node.Category = (string) projects [fullName];
					list.Add (node);
				}
			}
			list.Sort ();
			return list;
		}
Example #6
0
        public virtual IList <ItemToolboxNode> Load(LoaderContext ctx, string filename)
        {
            SystemPackage sp = Runtime.SystemAssemblyService.DefaultAssemblyContext.GetPackageFromPath(filename);
            ReferenceType rt;
            string        rname;

            if (sp != null)
            {
                rt    = ReferenceType.Package;
                rname = Runtime.SystemAssemblyService.DefaultAssemblyContext.GetAssemblyFullName(filename, null);
            }
            else
            {
                rt    = ReferenceType.Assembly;
                rname = filename;
            }

            List <ItemToolboxNode> list = new List <ItemToolboxNode> ();

            if (ctx.CancellationToken.IsCancellationRequested)
            {
                return(list);
            }

            var types = Runtime.RunInMainThread(delegate {
                // Stetic is not thread safe, it has to be used from the gui thread
                return(GuiBuilderService.SteticApp.GetComponentTypes(filename));
            }).WaitAndGetResult(ctx.CancellationToken);

            foreach (ComponentType ct in types)
            {
                if (ct.Category == "window")
                {
                    continue;
                }
                ComponentToolboxNode cn = new ComponentToolboxNode(ct);
                cn.ReferenceType = rt;
                cn.Reference     = rname;
                list.Add(cn);
            }
            return(list);
        }
        public virtual IList <ItemToolboxNode> Load(LoaderContext ctx, string filename)
        {
            SystemPackage sp = Runtime.SystemAssemblyService.DefaultAssemblyContext.GetPackageFromPath(filename);
            ReferenceType rt;
            string        rname;

            if (sp != null)
            {
                rt    = ReferenceType.Package;
                rname = Runtime.SystemAssemblyService.DefaultAssemblyContext.GetAssemblyFullName(filename, null);
            }
            else
            {
                rt    = ReferenceType.Assembly;
                rname = filename;
            }

            List <ItemToolboxNode> list = new List <ItemToolboxNode> ();

            ComponentType[] types = null;
            DispatchService.GuiSyncDispatch(delegate
            {
                // Stetic is not thread safe, it has to be used from the gui thread
                types = GuiBuilderService.SteticApp.GetComponentTypes(filename);
            });
            foreach (ComponentType ct in types)
            {
                if (ct.Category == "window")
                {
                    continue;
                }
                ComponentToolboxNode cn = new ComponentToolboxNode(ct);
                cn.ReferenceType = rt;
                cn.Reference     = rname;
                list.Add(cn);
            }
            return(list);
        }
		void CheckReference (ComponentToolboxNode node)
		{
			if (node.Reference == null)
				return;
			
			MonoDevelop.Projects.ProjectReference pref;
			
			// If the class name includes an assembly name it means that the
			// widget is implemented in another assembly, not in the one that
			// has the objects.xml file.
			int i = node.ClassName.IndexOf (',');
			if (i != -1) {
				string asm = node.ClassName.Substring (i+1).Trim ();
				if (asm == "gtk-sharp")
					// If we are adding a widget to a window, the project must already have a gtk# reference
					return;
				
				asm = gproject.Project.AssemblyContext.GetAssemblyFullName (asm, gproject.Project.TargetFramework);
				if (asm == null)
					return;
				if (gproject.Project.AssemblyContext.GetPackagesFromFullName (asm).Length > 0) {
					pref = MonoDevelop.Projects.ProjectReference.CreateAssemblyReference (asm);
				} else {
					asm = gproject.Project.AssemblyContext.GetAssemblyLocation (asm, gproject.Project.TargetFramework);
					pref = MonoDevelop.Projects.ProjectReference.CreateAssemblyFileReference (asm);
				}
			}
			else
				pref = MonoDevelop.Projects.ProjectReference.CreateCustomReference (node.ReferenceType, node.Reference);
			
			foreach (var pr in gproject.Project.References) {
				if (pr.Reference == pref.Reference)
					return;
			}
			gproject.Project.References.Add (pref);
		}
Example #9
0
        public IEnumerable <ItemToolboxNode> GetDynamicItems(IToolboxConsumer consumer)
        {
            DesignerPage view = consumer as DesignerPage;

            if (view == null)
            {
                return(null);
            }

            ComponentType[] types = view.GetComponentTypes();
            if (types == null)
            {
                return(null);
            }

            Hashtable refs     = new Hashtable();
            Hashtable projects = new Hashtable();
            string    of       = FileService.GetFullPath(view.Project.GetOutputFileName(IdeApp.Workspace.ActiveConfiguration));

            projects [of] = view.Project.Name;
            foreach (ProjectReference pr in ((DotNetProject)view.Project).References)
            {
                foreach (string f in pr.GetReferencedFileNames(IdeApp.Workspace.ActiveConfiguration))
                {
                    if (pr.ReferenceType == ReferenceType.Project)
                    {
                        projects[FileService.GetFullPath(f)] = pr.Reference;
                    }
                    else
                    {
                        refs[FileService.GetFullPath(f)] = f;
                    }
                }
            }

            List <ItemToolboxNode> list = new List <ItemToolboxNode> ();

            foreach (ComponentType type in types)
            {
                if (type.Category == "window")
                {
                    continue;
                }

                string fullName = null;
                if (!String.IsNullOrEmpty(type.Library))
                {
                    fullName = FileService.GetFullPath(type.Library);
                }

                if (type.ClassName == "Gtk.Action" || (fullName != null && refs.Contains(fullName)))
                {
                    ComponentToolboxNode node = new ComponentToolboxNode(type);
                    list.Add(node);
                }
                else if (fullName != null && projects.Contains(fullName))
                {
                    ComponentToolboxNode node = new ComponentToolboxNode(type);
                    node.Category = (string)projects [fullName];
                    list.Add(node);
                }
            }
            list.Sort();
            return(list);
        }