public static void ListAllProjectProperties(DTE dte) { StringBuilder output = new StringBuilder(); List <Project> selectedProjects = new List <Project>(); if (!GetSelectedProjects(dte, selectedProjects)) { OutputString(output, "One or more projects must be selected in Solution Explorer."); } else { bool first = true; foreach (Project project in selectedProjects) { if (!first) { OutputString(output, Environment.NewLine); } if (project != null) { OutputString(output, project.Name); OutputString(output, Environment.NewLine); const string Indent = "\t"; // Show project-level properties OutputProperties(output, project.Properties, Indent); // Show configuration-level properties if (project.ConfigurationManager != null) { foreach (Configuration configuration in project.ConfigurationManager.Cast <Configuration>().OrderBy(c => c.ConfigurationName)) { OutputString(output, Environment.NewLine); OutputString(output, Indent); OutputString(output, configuration.ConfigurationName); OutputString(output, Environment.NewLine); OutputProperties(output, configuration.Properties, Indent + Indent); } } } first = false; } } // Example from http://msdn.microsoft.com/en-us/library/envdte.dte.aspx dte.ItemOperations.NewFile(@"General\Text File", "Project Properties"); TextDocumentHandler handler = new TextDocumentHandler(dte); handler.SetSelectedText(output.ToString(), "List All Project Properties"); }
private void GenerateGuid() { TextDocumentHandler handler = new TextDocumentHandler(this.dte); if (handler.CanSetSelectedText) { Guid guid = Guid.NewGuid(); Options options = this.package.Options; string format; switch (options.GuidFormat) { case GuidFormat.Numbers: format = "N"; break; case GuidFormat.Braces: format = "B"; break; case GuidFormat.Parentheses: format = "P"; break; case GuidFormat.Structure: format = "X"; break; default: // GuidFormat.Dashes format = "D"; break; } string guidText = guid.ToString(format); if (options.UppercaseGuids) { guidText = guidText.ToUpper(); } // Set the selection to the new GUID handler.SetSelectedText(guidText, "Generate GUID"); } }
public static void AddToDoComment(DTE dte) { TextDocumentHandler handler = new TextDocumentHandler(dte); if (handler.TextDocument != null) { TextPoint bottomPoint = handler.Selection.BottomPoint; bool isAtEndOfLine = bottomPoint.AtEndOfLine || IsAtVisibleEndOfLine(bottomPoint); Language language = handler.Language; GetCommentStyle(language, false, !isAtEndOfLine, out string beginDelimiter, out string endDelimiter); StringBuilder sb = new StringBuilder(); sb.Append(beginDelimiter); if (sb.Length > 0) { sb.Append(' '); } sb.Append("TODO: "); int noteStartIndex = sb.Length; string memberName = GetMemberName(handler); sb.Append("Finish ").Append(memberName ?? "implementation").Append("."); int noteLength = sb.Length - noteStartIndex; sb.Append(" [").Append(Environment.UserName).Append(", ").Append(DateTime.Now.ToShortDateString()).Append(']'); if (!string.IsNullOrEmpty(endDelimiter)) { sb.Append(' ').Append(endDelimiter); } string comment = sb.ToString(); handler.SetSelectedText(comment, "Add TODO Comment"); // Select the note portion in case the user wants to edit it immediately. handler.Selection.MoveToAbsoluteOffset(handler.Selection.ActivePoint.AbsoluteCharOffset - comment.Length + noteStartIndex, false); handler.Selection.MoveToAbsoluteOffset(handler.Selection.ActivePoint.AbsoluteCharOffset + noteLength, true); } }