Skip to content

Commit

Permalink
Updated for tools pain day
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-r-g committed Dec 9, 2022
1 parent 72dcfe2 commit 3a34c6b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 40 deletions.
1 change: 0 additions & 1 deletion .addon
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"ResourcePaths": [],
"HasCode": true,
"CodePath": "code",
"RootNamespace": "Tools",
"Metadata": {
"ProjectTemplate": null
}
Expand Down
4 changes: 2 additions & 2 deletions code/DiagnosticsListView.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Sandbox.Internal;
using Tools;
using Editor;
using Sandbox.Internal;

namespace Gooman.Tools.ProjectDiagnostics;

Expand Down
40 changes: 3 additions & 37 deletions code/ProjectDiagnostics.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Sandbox;
using Editor;
using Sandbox;
using Sandbox.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using Tools;

namespace Gooman.Tools.ProjectDiagnostics;

Expand Down Expand Up @@ -52,10 +52,6 @@ public sealed class ProjectDiagnostics : Widget
/// </summary>
private readonly ComboBox ProjectFilterBox;
/// <summary>
/// Check box for whether or not to hide unaffiliated diagnostics.
/// </summary>
private readonly CheckBox HideUnaffiliatedDiagnosticsCheckBox;
/// <summary>
/// The visual list of all diagnostics.
/// </summary>
private readonly DiagnosticsListView DiagnosticsView;
Expand All @@ -80,10 +76,6 @@ public sealed class ProjectDiagnostics : Widget
/// The current filter for projects.
/// </summary>
private string FilteredProject = "all";
/// <summary>
/// Whether or not to hide unaffiliated diagnostics in projects.
/// </summary>
private bool HideUnaffiliatedDiagnostics = false;

/// <summary>
/// Initializes a new instance of <see cref="ProjectDiagnostics"/>.
Expand Down Expand Up @@ -153,12 +145,6 @@ public ProjectDiagnostics( Widget parent ) : base( parent )
};
ResetFilterBox();

HideUnaffiliatedDiagnosticsCheckBox = new CheckBox( "Hide unaffialiated diagnostics", this )
{
Toggled = ToggleDiagnosticsCheckBox,
StatusTip = "Whether or not to hide diagnostics from projects not directly affiliated with the compiled project"
};

var clearButton = new Button( string.Empty, "delete", this )
{
ButtonType = "clear",
Expand All @@ -168,7 +154,6 @@ public ProjectDiagnostics( Widget parent ) : base( parent )
clearButton.SetProperty( "cssClass", "clear" );

layout.Add( ProjectFilterBox );
layout.Add( HideUnaffiliatedDiagnosticsCheckBox );
layout.Add( clearButton );

// Error list.
Expand All @@ -185,7 +170,6 @@ public ProjectDiagnostics( Widget parent ) : base( parent )
ShowInfo = Cookie.Get( "project_diag_info_shown", true );
ShowWarnings = Cookie.Get( "project_diag_warnings_shown", true );
ShowErrors = Cookie.Get( "project_diag_errors_shown", true );
HideUnaffiliatedDiagnosticsCheckBox.Value = Cookie.Get( "project_diag_hide_unaf_diag", false );
// Update.
UpdateErrors();
}
Expand Down Expand Up @@ -254,14 +238,11 @@ private void ResetFilterBox()
/// </summary>
/// <param name="projectName">If provided, sets the project name filter.</param>
/// <param name="hideUnaffiliatedDiagnostics">If provided, sets whether or not to hide unaffiliated diagnostics.</param>
private void UpdateErrors( string projectName = null, bool? hideUnaffiliatedDiagnostics = null )
private void UpdateErrors( string projectName = null )
{
if ( projectName is not null )
FilteredProject = projectName;

if ( hideUnaffiliatedDiagnostics is not null )
HideUnaffiliatedDiagnostics = hideUnaffiliatedDiagnostics.Value;

// Fast path
if ( Diagnostics.Count == 0 || (!ShowInfo && !ShowWarnings && !ShowErrors) )
{
Expand Down Expand Up @@ -312,24 +293,9 @@ private bool FilterDiagnostic( ICSharpCompiler.Diagnostic diagnostic )
if ( FilteredProject != "all" && diagnostic.Project != FilteredProject )
return false;

var projectName = diagnostic.Project;
var relatedProject = Utility.Projects.GetAll().First( proj => proj.Config.FullIdent == projectName );
if ( HideUnaffiliatedDiagnostics && !diagnostic.FilePath.StartsWith( relatedProject.GetRootPath() ) )
return false;

return true;
}

/// <summary>
/// Callback method when the <see cref="HideUnaffiliatedDiagnosticsCheckBox"/> value has changed.
/// </summary>
private void ToggleDiagnosticsCheckBox()
{
var hide = HideUnaffiliatedDiagnosticsCheckBox.State == CheckState.On;
UpdateErrors( null, hide );
Cookie.Set( "project_diag_hide_unaf_diag", hide );
}

/// <summary>
/// Paints a button.
/// </summary>
Expand Down

0 comments on commit 3a34c6b

Please sign in to comment.