Skip to content
2 changes: 1 addition & 1 deletion WDAC-Policy-Wizard/app/src/BuildPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace WDAC_Wizard
{
public partial class BuildPage : UserControl
public partial class BuildPage : UserControl, IWizardPage
{
public string XmlFilePath { get; set; } // File path for the WDAC policy XML file
public string BinFilePath { get; set; } // File path for the WDAC policy binary file
Expand Down
2 changes: 1 addition & 1 deletion WDAC-Policy-Wizard/app/src/ConfigTemplate_Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace WDAC_Wizard
{
public partial class ConfigTemplate_Control : UserControl
public partial class ConfigTemplate_Control : UserControl, IWizardPage
{
public MainWindow _MainWindow;
private WDAC_Policy Policy;
Expand Down
6 changes: 3 additions & 3 deletions WDAC-Policy-Wizard/app/src/EditWorkflow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion WDAC-Policy-Wizard/app/src/EditWorkflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace WDAC_Wizard
{
public partial class EditWorkflow : UserControl
public partial class EditWorkflow : UserControl, IWizardPage
{
public string EditPath { get; set; }
private int NumberRules;
Expand Down
23 changes: 16 additions & 7 deletions WDAC-Policy-Wizard/app/src/EventLogRuleConfiguration.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 39 additions & 24 deletions WDAC-Policy-Wizard/app/src/EventLogRuleConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace WDAC_Wizard
{
public partial class EventLogRuleConfiguration : UserControl
public partial class EventLogRuleConfiguration : UserControl, IWizardPage
{
private List<CiEvent> CiEvents;
// Declare an ArrayList to serve as the data store.
Expand Down Expand Up @@ -94,6 +94,10 @@ private void DisplayEvents()
this.DisplayObjects.Add(dpObject);
this.eventsDataGridView.RowCount += 1;
}

// Size each column to fit its text. Columns remain user-resizable afterwards
// since AutoSizeColumnsMode stays None.
GridLayoutHelper.AutoFitColumns(this.eventsDataGridView);
}

/// <summary>
Expand Down Expand Up @@ -188,15 +192,14 @@ private void RowSelectionChanged(object sender, EventArgs e)
return;
}

// Set the UI
ResetCustomRulesPanel();
SetPublisherPanel(this.CiEvents[selectedRow].SignerInfo.IssuerName,
this.CiEvents[selectedRow].SignerInfo.PublisherName,
this.CiEvents[selectedRow].OriginalFilename,
this.CiEvents[selectedRow].FileVersion,
this.CiEvents[selectedRow].ProductName);

// Update the selected row before refreshing the UI so that the
// rule type panel reflects the newly selected event.
this.SelectedRow = selectedRow;

// Set the UI. Keep the user's current rule type selection and
// repopulate the matching panel for the newly selected row.
ResetCustomRulesPanel();
RefreshRulePanelForSelectedRow();
}

/// <summary>
Expand All @@ -206,29 +209,27 @@ private void RowSelectionChanged(object sender, EventArgs e)
/// <param name="e"></param>
private void EventRowClick(object sender, DataGridViewCellEventArgs e)
{
// Set the UI
ResetCustomRulesPanel();

int selectedRow = e.RowIndex;
if(selectedRow >= this.CiEvents.Count)
{
return;
}

// Header selected, sort table
if(selectedRow == -1)
{
SortDataGrid(sender, e);
return;
}

SetPublisherPanel(this.CiEvents[selectedRow].SignerInfo.IssuerName,
this.CiEvents[selectedRow].SignerInfo.PublisherName,
this.CiEvents[selectedRow].OriginalFilename,
this.CiEvents[selectedRow].FileVersion,
this.CiEvents[selectedRow].ProductName);

if(selectedRow >= this.CiEvents.Count)
{
return;
}

// Update the selected row before refreshing the UI
this.SelectedRow = selectedRow;

// Set the UI. Keep the user's current rule type selection and
// repopulate the matching panel for the newly selected row.
ResetCustomRulesPanel();
RefreshRulePanelForSelectedRow();
}

/// <summary>
Expand Down Expand Up @@ -410,8 +411,8 @@ private void ResetCustomRulesPanel()
this.versionTextBox.Clear();
this.productTextBox.Clear();

// Dropdown
this.ruleTypeComboBox.SelectedIndex = 0;
// NOTE: The rule type dropdown is intentionally left unchanged so the
// user's selection persists as they navigate between rows.
}


Expand Down Expand Up @@ -725,6 +726,20 @@ private void RuleTypeChanged(object sender, EventArgs e)
// Path
// File Attributes
// File Hash
RefreshRulePanelForSelectedRow();
}

/// <summary>
/// Populates the rule details panel for the currently selected row based
/// on the rule type currently chosen in the dropdown. The dropdown
/// selection is intentionally preserved as the user navigates rows.
/// </summary>
private void RefreshRulePanelForSelectedRow()
{
if (this.SelectedRow < 0 || this.SelectedRow >= this.CiEvents.Count)
{
return;
}

HideAllPanels();

Expand Down
3 changes: 2 additions & 1 deletion WDAC-Policy-Wizard/app/src/Exceptions_Control.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions WDAC-Policy-Wizard/app/src/Exceptions_Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ public void AddException()
this.displayObjects.Add(displayObject);
this.dataGridView_Exceptions.RowCount += 1;

// Size each column to fit its text. Columns remain user-resizable afterwards
// since AutoSizeColumnsMode stays None.
GridLayoutHelper.AutoFitColumns(this.dataGridView_Exceptions);

// Scroll to bottom to see new rule added to list
this.dataGridView_Exceptions.FirstDisplayedScrollingRowIndex = this.dataGridView_Exceptions.RowCount - 1;
this.ExceptionRule = new PolicyCustomRules();
Expand Down
55 changes: 55 additions & 0 deletions WDAC-Policy-Wizard/app/src/GridLayoutHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System.Windows.Forms;

namespace WDAC_Wizard
{
/// <summary>
/// Helper utilities for DataGridView layout behavior shared across the wizard pages.
/// </summary>
internal static class GridLayoutHelper
{
/// <summary>
/// Sizes each column to fit its content. The columns remain user-resizable afterwards
/// because the grid's AutoSizeColumnsMode is left as None.
/// The resize is deferred until the grid has a created handle so that text measurement
/// works correctly (calling it too early, e.g. during Load, is a silent no-op).
/// </summary>
/// <param name="grid">The DataGridView to resize.</param>
public static void AutoFitColumns(DataGridView grid)
{
if (grid == null)
{
return;
}

void Resize()
{
if (grid.IsDisposed || grid.ColumnCount == 0)
{
return;
}

grid.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
}

if (grid.IsHandleCreated)
{
// Defer to the message loop so it runs after the current layout pass completes.
grid.BeginInvoke((MethodInvoker)Resize);
}
else
{
// Handle not created yet (e.g. populated during Load). Resize once it is.
void Handler(object sender, System.EventArgs e)
{
grid.HandleCreated -= Handler;
grid.BeginInvoke((MethodInvoker)Resize);
}

grid.HandleCreated += Handler;
}
}
}
}
Loading