Beispiel #1
0
        internal void DetermineSubType()
        {
            // Parse the contents of the file and see if we have a windows form or a windows control
            XSharpProjectNode projectNode = ProjectMgr as XSharpProjectNode;

            XSharpModel.XFile xfile = projectNode.ProjectModel.FindFullPath(this.Url);
            if (xfile != null)
            {
                xfile.WaitParsing();
            }
            // (something that inherits from system.windows.forms.form or system.windows.forms.usercontrol
            // We should do this with proper parsing. For now we simply test the first word after the INHERIT keyword
            // and then parse and bind to see if we can find the first type in the file.
            if (this.FileType == XFileType.SourceCode && this.Url.IndexOf(".designer.", StringComparison.OrdinalIgnoreCase) == -1)
            {
                string SubType = "";
                string token   = "INHERIT";
                string source  = System.IO.File.ReadAllText(this.Url);
                int    pos     = source.IndexOf(token, StringComparison.OrdinalIgnoreCase);
                if (pos > 0)
                {
                    source = source.Substring(pos + token.Length);
                    var words = source.Split(";\t \r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    if (words.Length > 0)
                    {
                        var parentclass = words[0].ToLower();
                        switch (parentclass)
                        {
                        case "form":
                        case "system.windows.forms.form":
                            SubType = ProjectFileAttributeValue.Form;
                            break;

                        case "usercontrol":
                        case "system.windows.forms.usercontrol":
                            SubType = ProjectFileAttributeValue.UserControl;
                            break;
                        }
                        if (SubType != null && this.ItemNode.GetMetadata(ProjectFileConstants.SubType) != SubType)
                        {
                            this.ItemNode.SetMetadata(ProjectFileConstants.SubType, SubType);
                            this.ItemNode.RefreshProperties();
                            this.UpdateHasDesigner();
                            this.ReDraw(UIHierarchyElement.Icon);
                        }
                    }
                }
            }
            return;
        }
Beispiel #2
0
        internal void DetermineSubType()
        {
            // Parse the contents of the file and see if we have a windows form or a windows control
            XSharpProjectNode projectNode = ProjectMgr as XSharpProjectNode;

            XSharpModel.XFile xfile = projectNode.ProjectModel.FindFullPath(this.Url);
            if (xfile == null)
            {
                projectNode.ProjectModel.AddFile(this.Url);
                xfile = projectNode.ProjectModel.FindFullPath(this.Url);
            }
            if (xfile != null)
            {
                xfile.WaitParsing();
            }
            // (something that inherits from system.windows.forms.form or system.windows.forms.usercontrol
            // We should do this with proper parsing. For now we simply test the first word after the INHERIT keyword
            // and then parse and bind to see if we can find the first type in the file.
            if (this.FileType == XFileType.SourceCode && this.Url.IndexOf(".designer.", StringComparison.OrdinalIgnoreCase) == -1)
            {
                string SubType = "";
                string token   = "INHERIT";
                string source  = System.IO.File.ReadAllText(this.Url);
                int    pos     = source.IndexOf(token, StringComparison.OrdinalIgnoreCase);
                if (pos > 0)
                {
                    source = source.Substring(pos + token.Length);
                    var words = source.Split(";\t \r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    if (words.Length > 0)
                    {
                        var parentclass = words[0].ToLower();
                        SubType = typeNameToSubtype(parentclass);
                        if (string.IsNullOrEmpty(SubType))
                        {
                            var usings = new List <string>();
                            if (xfile != null)
                            {
                                usings.AddRange(xfile.Usings);
                            }
                            var mgr  = this.ProjectMgr as XSharpProjectNode;
                            var type = mgr.ResolveType(parentclass, usings);
                            if (type != null)
                            {
                                while (type.BaseType != null)
                                {
                                    var bt = type.BaseType;
                                    SubType = typeNameToSubtype(bt.Name);
                                    if (!String.IsNullOrEmpty(SubType))
                                    {
                                        break;
                                    }
                                    type = bt;
                                }
                            }
                            else
                            {
                                var xtype = mgr.ResolveXType(parentclass, usings);
                                if (xtype != null)
                                {
                                    while (xtype != null && !String.IsNullOrEmpty(xtype.ParentName))
                                    {
                                        var parent = xtype.ParentName;
                                        SubType = typeNameToSubtype(parent);
                                        if (!String.IsNullOrEmpty(SubType))
                                        {
                                            break;
                                        }
                                        xtype = mgr.ResolveXType(parent, usings);
                                    }
                                }
                            }
                        }
                        if (SubType != null && this.ItemNode.GetMetadata(ProjectFileConstants.SubType) != SubType)
                        {
                            this.ItemNode.SetMetadata(ProjectFileConstants.SubType, SubType);
                            this.ItemNode.RefreshProperties();
                            this.UpdateHasDesigner();
                            this.ReDraw(UIHierarchyElement.Icon);
                        }
                    }
                }
            }
            return;
        }