Skip to content

Commit

Permalink
Split off Highlight and Tasks options classes
Browse files Browse the repository at this point in the history
  • Loading branch information
menees committed Apr 25, 2020
1 parent 5484e0c commit 3f4aeb0
Show file tree
Hide file tree
Showing 18 changed files with 463 additions and 256 deletions.
25 changes: 1 addition & 24 deletions src/Menees.VsTools/BaseConverter/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
[Guid(Guids.BaseConverterOptionsString)]
[DefaultProperty(nameof(TrimLeadingZerosEndian))] // Make this get focus in the PropertyGrid first since its category is alphabetically first.
[SuppressMessage("Internal class never created.", "CA1812", Justification = "Created via reflection by VS.")]
internal class Options : DialogPage
internal class Options : OptionsBase
{
#region Constructors

Expand All @@ -44,12 +44,6 @@ public Options()

#endregion

#region Public Events

public event EventHandler Applied;

#endregion

#region Public Browsable Properties (for Options page)

[Category("Base Converter")]
Expand Down Expand Up @@ -93,22 +87,5 @@ public Options()
public NumberType BaseConverterNumberType { get; set; }

#endregion

#region Protected Methods

protected override void OnApply(PageApplyEventArgs e)
{
base.OnApply(e);

// Raise an event so non-modal windows like BaseConverterControl
// can get a notification that they may need to update.
if (e.ApplyBehavior == ApplyKind.Apply && this.Applied != null)
{
EventHandler eh = this.Applied;
eh(this, e);
}
}

#endregion
}
}
4 changes: 2 additions & 2 deletions src/Menees.VsTools/Editor/ClassifierBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
ThreadHelper.ThrowIfNotOnUIThread();
if (span.Length > 0)
{
this.GetClassificationSpans(result, span, MainPackage.GeneralOptions);
this.GetClassificationSpans(result, span, MainPackage.HighlightOptions);
}

return result;
Expand Down Expand Up @@ -104,7 +104,7 @@ protected virtual void Dispose(bool disposing)
}
}

protected abstract void GetClassificationSpans(List<ClassificationSpan> result, SnapshotSpan span, Options options);
protected abstract void GetClassificationSpans(List<ClassificationSpan> result, SnapshotSpan span, HighlightOptions options);

// If we're passed a specific option ID, then return false because we can't read it here to tell if it changed.
// If we're passed null or empty, then return true as if something changed.
Expand Down
2 changes: 1 addition & 1 deletion src/Menees.VsTools/Editor/FindResultsClassifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public FindResultsClassifier(ITextBuffer buffer, IClassificationTypeRegistryServ

#region Protected Methods

protected override void GetClassificationSpans(List<ClassificationSpan> result, SnapshotSpan span, Options options)
protected override void GetClassificationSpans(List<ClassificationSpan> result, SnapshotSpan span, HighlightOptions options)
{
bool showFileNames = options.HighlightFindResultsFileNames;
bool showMatches = options.HighlightFindResultsMatches;
Expand Down
169 changes: 169 additions & 0 deletions src/Menees.VsTools/Editor/HighlightOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
namespace Menees.VsTools.Editor
{
#region Using Directives

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics.CodeAnalysis;
using System.Drawing.Design;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

#endregion

// Note: The MainPackage has ProvideOptionPage and ProvideProfile attributes
// that associate this class with our package. Helpful pages:
// http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.dialogpage(v=vs.110).aspx
// http://msdn.microsoft.com/en-us/library/bb162586(v=vs.110).aspx
// http://bloggingabout.net/blogs/perikles/archive/2006/11/22/How-to-dynamically-Import_2F00_Export-setting-in-Visual-Studio-2005_2E00_.aspx
[Guid(Guids.HighlightOptionsString)]
[DefaultProperty(nameof(HighlightFindResultsDetails))] // Make this get focus in the PropertyGrid first since its category is alphabetically first.
[SuppressMessage("Internal class never created.", "CA1812", Justification = "Created via reflection by VS.")]
internal sealed class HighlightOptions : OptionsBase
{
#region Internal Constants

internal const string DefaultCaption = "Highlight";

#endregion

#region Private Data Members

private List<OutputHighlight> outputHighlights;

#endregion

#region Constructors

public HighlightOptions()
{
this.HighlightOutputText = true;
this.OutputHighlights = CreateDefaultOutputHighlights();
this.HighlightFindResultsDetails = true;
this.HighlightFindResultsFileNames = true;
this.HighlightFindResultsMatches = true;
}

#endregion

#region Public Browsable Properties (for Options page)

[Category("Output Windows")]
[DisplayName("Highlight output window text")]
[Description("Whether pattern-matched lines in output windows should be highlighted.")]
[DefaultValue(true)]
public bool HighlightOutputText { get; set; }

[Category("Output Windows")]
[DisplayName("Output patterns to highlight")]
[Description("Defines regular expressions used to highlight lines in output windows.")]
[TypeConverter(typeof(OutputHighlightListTypeConverter))]
[Editor(typeof(CollectionEditor), typeof(UITypeEditor))]
public List<OutputHighlight> OutputHighlights
{
get
{
return this.outputHighlights;
}

set
{
// Reset to the default highlights if the user deletes them all.
if (value == null || value.Count == 0)
{
this.outputHighlights = CreateDefaultOutputHighlights();
}
else
{
this.outputHighlights = value;
}
}
}

[Category("Find Windows")]
[DisplayName("Highlight Find Results details")]
[Description("Whether non-matched details in Find Results windows should be highlighted.")]
[DefaultValue(true)]
public bool HighlightFindResultsDetails { get; set; }

[Category("Find Windows")]
[DisplayName("Highlight Find Results file names")]
[Description("Whether file names in Find Results windows should be highlighted.")]
[DefaultValue(true)]
public bool HighlightFindResultsFileNames { get; set; }

[Category("Find Windows")]
[DisplayName("Highlight Find Results matches")]
[Description("Whether search term/expression matches in Find Results windows should be highlighted.")]
[DefaultValue(true)]
public bool HighlightFindResultsMatches { get; set; }

#endregion

#region Private Methods

private static List<OutputHighlight> CreateDefaultOutputHighlights()
{
List<OutputHighlight> result = new List<OutputHighlight>();

ISet<string> knownOutputContentTypes = OutputHighlight.GetKnownOutputContentTypes();

string[] buildContent = OutputHighlight.ValidateContentTypes(new[] { "BuildOutput", "BuildOrderOutput" }, knownOutputContentTypes);
if (buildContent.Length > 0)
{
result.Add(new OutputHighlight("Code Analysis Success", OutputHighlightType.None, @"\s0 error\(s\), 0 warning\(s\)$", buildContent));
}

// The "Ext: ExceptionBreaker (Diagnostic)" pane uses a general Output content type.
// We have to match this before the normal "exception:" rule.
result.Add(new OutputHighlight(
"Previous/Conflicting Exception",
OutputHighlightType.None,
@"^\s*(Previous|Conflicting) exception:")
{ MatchCase = true });

string[] debugContent = OutputHighlight.ValidateContentTypes(new[] { "DebugOutput" }, knownOutputContentTypes);
if (debugContent.Length > 0)
{
result.Add(new OutputHighlight("Exception", OutputHighlightType.Error, @"(exception:|stack trace:)", debugContent));
result.Add(new OutputHighlight("Exception At", OutputHighlightType.Error, @"^\s+at\s", debugContent));
}

string[] testsContent = OutputHighlight.ValidateContentTypes(new[] { "TestsOutput" }, knownOutputContentTypes);
if (testsContent.Length > 0)
{
result.Add(new OutputHighlight("Test Host Abort", OutputHighlightType.Error, @"^The active (\w+\s)+was aborted\s", testsContent));
result.Add(new OutputHighlight("Test Host Exception", OutputHighlightType.Error, @"\wException:\s", testsContent) { MatchCase = true });
}

string[] tfsContent = OutputHighlight.ValidateContentTypes(new[] { "TFSourceControlOutput" }, knownOutputContentTypes);
if (tfsContent.Length > 0)
{
result.Add(new OutputHighlight("TFS Error Code", OutputHighlightType.Error, @"^TF\d+\:\s", tfsContent));
result.Add(new OutputHighlight("TFS Unable To Get", OutputHighlightType.Warning, @"\WUnable to perform the get operation\W", tfsContent));
result.Add(new OutputHighlight("TFS Newer Version", OutputHighlightType.Warning, @"(\W|^)newer version exists in source control$", tfsContent));
result.Add(new OutputHighlight("TFS Auto Resolve", OutputHighlightType.Information, @"^Automatically resolved conflict\:\W", tfsContent));
result.Add(new OutputHighlight("TFS Check In", OutputHighlightType.Information, @"^Changeset \d+ successfully checked in\.$", tfsContent));
result.Add(new OutputHighlight("TFS Check Out", OutputHighlightType.Detail, @"\Whas been automatically checked out\W", tfsContent));
result.Add(new OutputHighlight("TFS Open For Edit", OutputHighlightType.Detail, @"^\s*opened for edit in\s", tfsContent));
result.Add(new OutputHighlight("TFS File Path", OutputHighlightType.Detail, @"^\$/.+\:$", tfsContent));
}

// These apply to all Output windows, so put them last. The Header/Footer pattern has to come
// before the Error pattern because builds use the word "failed" in the output footer.
result.Add(new OutputHighlight("Header/Footer", OutputHighlightType.Header, @"------ |========== "));
result.Add(new OutputHighlight("Exception cache is built", OutputHighlightType.None, @"^Exception cache is built\:"));
result.Add(new OutputHighlight("Error", OutputHighlightType.Error, @"(\W|^)(error|fail|failed|exception)\W"));
result.Add(new OutputHighlight("Warning", OutputHighlightType.Warning, @"(\W|^)warning\W"));
result.Add(new OutputHighlight("Information", OutputHighlightType.Information, @"(\W|^)information\W"));

return result;
}

#endregion
}
}
4 changes: 2 additions & 2 deletions src/Menees.VsTools/Editor/OutputClassifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public OutputClassifier(ITextBuffer buffer, IClassificationTypeRegistryService r

#region Protected Methods

protected override void GetClassificationSpans(List<ClassificationSpan> result, SnapshotSpan span, Options options)
protected override void GetClassificationSpans(List<ClassificationSpan> result, SnapshotSpan span, HighlightOptions options)
{
if (this.CacheHighlights(options))
{
Expand Down Expand Up @@ -96,7 +96,7 @@ protected override void ContentTypeChanged(ITextBuffer buffer, ContentTypeChange

#region Private Methods

private bool CacheHighlights(Options options)
private bool CacheHighlights(HighlightOptions options)
{
bool result = options != null && options.HighlightOutputText;

Expand Down
4 changes: 4 additions & 0 deletions src/Menees.VsTools/Guids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ internal static class Guids

public const string GeneralOptionsString = "bd511b61-46fe-4997-965b-c5408b6be977";

public const string HighlightOptionsString = "47c7cdc7-44c2-4107-8aa0-a0cb73b468a0";

public const string TasksOptionsString = "3e8cab32-2743-4c91-9826-62e717281ea8";

public static readonly Guid MeneesVsToolsPackage = new Guid(MeneesVsToolsPackageString);

public static readonly Guid MeneesVsToolsCommandSet = new Guid(MeneesVsToolsCommandSetString);
Expand Down
38 changes: 37 additions & 1 deletion src/Menees.VsTools/MainPackage.VsAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#endregion

#pragma warning disable SA1515
#pragma warning disable SA1515 // SingleLineCommentsMustBePrecededByBlankLine
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
// Tells the PkgDef creation utility (CreatePkgDef.exe) that this class is a package.
// Registers the information needed to show this package in the Help/About dialog of Visual Studio.
Expand Down Expand Up @@ -71,6 +71,42 @@
isToolsOptionPage: true,
DescriptionResourceID = 114,
MigrationType = ProfileMigrationType.PassThrough)] // Registers settings persistence. Affects Import/Export Settings.
[ProvideOptionPage(
typeof(Tasks.Options),
categoryName: Title,
pageName: TasksWindow.DefaultCaption,
categoryResourceID: 113,
pageNameResourceID: 116,
supportsAutomation: false,
SupportsProfiles = true,
ProfileMigrationType = ProfileMigrationType.PassThrough)] // Registers an Options page
[ProvideProfile(
typeof(Tasks.Options),
categoryName: Title,
objectName: TasksWindow.DefaultCaption,
categoryResourceID: 113,
objectNameResourceID: 116,
isToolsOptionPage: true,
DescriptionResourceID = 114,
MigrationType = ProfileMigrationType.PassThrough)] // Registers settings persistence. Affects Import/Export Settings.
[ProvideOptionPage(
typeof(HighlightOptions),
categoryName: Title,
pageName: HighlightOptions.DefaultCaption,
categoryResourceID: 113,
pageNameResourceID: 117,
supportsAutomation: false,
SupportsProfiles = true,
ProfileMigrationType = ProfileMigrationType.PassThrough)] // Registers an Options page
[ProvideProfile(
typeof(HighlightOptions),
categoryName: Title,
objectName: HighlightOptions.DefaultCaption,
categoryResourceID: 113,
objectNameResourceID: 117,
isToolsOptionPage: true,
DescriptionResourceID = 114,
MigrationType = ProfileMigrationType.PassThrough)] // Registers settings persistence. Affects Import/Export Settings.
#pragma warning restore SA1515
public sealed partial class MainPackage
{
Expand Down
Loading

0 comments on commit 3f4aeb0

Please sign in to comment.