Beispiel #1
0
        protected virtual void MasterChanged(object sender, EventArgs e)
        {
            if (IsPartialView || !HasMaster)
            {
                return;
            }

            if (masterEntry.Text == oldMaster)
            {
                return;
            }
            oldMaster = masterEntry.Text;

            primaryPlaceholderStore.Clear();
            ContentPlaceHolders.Clear();

            string realPath = project.VirtualToLocalPath(oldMaster, null);

            if (!File.Exists(realPath))
            {
                return;
            }

            var pd = ProjectDomService.GetParsedDocument(ProjectDomService.GetProjectDom(project), realPath)
                     as AspNetParsedDocument;

            if (pd != null)
            {
                try {
                    var visitor = new ContentPlaceHolderVisitor();
                    pd.RootNode.AcceptVisit(visitor);
                    ContentPlaceHolders.AddRange(visitor.PlaceHolders);

                    for (int i = 0; i < ContentPlaceHolders.Count; i++)
                    {
                        string placeholder = ContentPlaceHolders[i];
                        primaryPlaceholderStore.AppendValues(placeholder);

                        if (placeholder.Contains("main") || placeholder.Contains("Main") ||
                            placeholder.Contains("content") || placeholder.Contains("Main"))
                        {
                            primaryPlaceholderCombo.Active = i;
                        }
                    }
                } catch (Exception ex) {
                    LoggingService.LogError("Unhandled exception getting master regions for '" + realPath + "'", ex);
                }
            }

            Validate();
        }
        public override void ModifyTags(MonoDevelop.Projects.SolutionItem policyParent, MonoDevelop.Projects.Project project, string language, string identifier, string fileName, ref Dictionary <string, string> tags)
        {
            base.ModifyTags(policyParent, project, language, identifier, fileName, ref tags);
            if (fileName == null)
            {
                return;
            }

            tags["AspNetMaster"]        = "";
            tags["AspNetMasterContent"] = "";

            AspNetAppProject aspProj = project as AspNetAppProject;

            if (aspProj == null)
            {
                throw new InvalidOperationException("MasterContentFileDescriptionTemplate is only valid for ASP.NET projects");
            }

            ProjectFile masterPage = null;

            var dialog = new MonoDevelop.Ide.Projects.ProjectFileSelectorDialog(aspProj, null, "*.master");

            try
            {
                dialog.Title = GettextCatalog.GetString("Select a Master Page...");
                int response = MonoDevelop.Ide.MessageService.RunCustomDialog(dialog);
                if (response == (int)Gtk.ResponseType.Ok)
                {
                    masterPage = dialog.SelectedFile;
                }
            }
            finally
            {
                dialog.Destroy();
            }
            if (masterPage == null)
            {
                return;
            }

            tags["AspNetMaster"] = aspProj.LocalToVirtualPath(masterPage);

            try
            {
                var pd = TypeSystemService.ParseFile(project, masterPage.FilePath)
                         as AspNetParsedDocument;
                if (pd == null)
                {
                    return;
                }

                var visitor = new ContentPlaceHolderVisitor();
                pd.RootNode.AcceptVisit(visitor);

                var sb = new System.Text.StringBuilder();
                foreach (string id in visitor.PlaceHolders)
                {
                    sb.Append("<asp:Content ContentPlaceHolderID=\"");
                    sb.Append(id);
                    sb.Append("\" ID=\"");
                    sb.Append(id);
                    sb.Append("Content\" runat=\"server\">\n</asp:Content>\n");
                }

                tags["AspNetMasterContent"] = sb.ToString();
            }
            catch (Exception ex)
            {
                //no big loss if we just insert blank space
                //it's just a template for the user to start editing
                LoggingService.LogWarning("Error generating AspNetMasterContent for template", ex);
            }
        }