///-------------------------------------------------------------------------------- /// <summary>This method displays a message in the status area.</summary> /// /// <param name="statusMessage">The message to show.</param> /// <param name="appendMessage">Flag indicating whether message should be appended to existing message.</param> ///-------------------------------------------------------------------------------- public void ShowStatus(string statusMessage, bool appendMessage) { int frozen; StatusBar.IsFrozen(out frozen); if (frozen == 0) { if (appendMessage == true) { if (statusMessage != "Ready") { // add status message to job message string text; StatusBar.GetText(out text); if (text != String.Empty) { text = "; " + text; } StatusBar.SetText(statusMessage + text); StatusBar.FreezeOutput(0); } } else { // replace status message with current message StatusBar.SetText(statusMessage); StatusBar.FreezeOutput(0); } } }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE; Document doc = dte.ActiveDocument; TextDocument txtDoc = doc.Object() as TextDocument; var text = txtDoc.CreateEditPoint(txtDoc.StartPoint).GetText(txtDoc.EndPoint); text = text.Replace("\r", ""); uint cookie = 0; StatusBar.Progress(ref cookie, 1, string.Empty, 0, 0); if (txtDoc.Language == "HTMLX" || txtDoc.Language == "HTML") { var html = text; var elementList = new List <HtmlElement>(); var parsed = _parser.ParseHtml(html, elementList, txtDoc, StatusBar, ref cookie); var cssFileContent = string.Empty; if (elementList.Any()) { foreach (var item in elementList) { var cssClass = string.Empty; if (string.IsNullOrEmpty(item.Class)) { cssClass = string.Format(".{0}", string.IsNullOrEmpty(item.Id) ? CreateUniqueElementKey(item.Name, item.LineNumber) : item.Id); } else { cssClass = string.Format(".{0} .{1}", item.Class, CreateUniqueElementKey(item.Name, item.LineNumber)); } var idAttr = string.IsNullOrEmpty(item.Id) ? string.Empty : string.Format("id=\"{0}\"", item.Id); var replaceText = string.Format("{0} {1} class=\"{2}\"", item.Name, idAttr, cssClass.Replace(".", string.Empty)); parsed = parsed.Replace(item.Guid, replaceText); cssFileContent += string.Format("{0}{{{1}}}\n\n", cssClass, "\n" + item.Style); } //css file beautification cssFileContent = cssFileContent.Replace(";", ";\n"); //update html file var txtSelHtml = (TextSelection)doc.Selection; txtSelHtml.SelectAll(); txtSelHtml.Delete(); txtSelHtml.Insert(parsed); //create css file var docName = doc.Name.Substring(0, doc.Name.IndexOf('.')); docName = string.Format("{0}.css", docName); dte.ItemOperations.NewFile(@"General\Text File", docName, EnvDTE.Constants.vsViewKindTextView); var txtSelCss = (TextSelection)dte.ActiveDocument.Selection; txtSelCss.SelectAll(); txtSelCss.Delete(); txtSelCss.Insert(cssFileContent); } else { VsShellUtilities.ShowMessageBox(this.ServiceProvider, "Not found inline css.", "That's Cool!", OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); } } else { VsShellUtilities.ShowMessageBox(this.ServiceProvider, "This is not a html file!", "Oops!", OLEMSGICON.OLEMSGICON_WARNING, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); } // Clear the progress bar. StatusBar.Progress(ref cookie, 0, string.Empty, 0, 0); StatusBar.FreezeOutput(0); StatusBar.Clear(); }