Skip to content

Commit

Permalink
Improved List Views and UI/UX in AppControl Manager (#623)
Browse files Browse the repository at this point in the history
Added keyboard accelerator: CTRL + C for the pages that host a ListView so you can use that shortcut to copy the selected item(s) to the clipboard.

Improved the selection experience in ListViews by making right-click on a row to select that row and then open the context menu.

The settings cards in the Settings page are now interactive and can be clicked/touched to perform the main action in the card.

Added the delete option to the context menu of the ListViews that require it.

Added info bars to the base policy creation page so you can see the live status of policy creation/deployment.
  • Loading branch information
HotCakeX authored Feb 26, 2025
1 parent f678268 commit 709c257
Show file tree
Hide file tree
Showing 26 changed files with 852 additions and 283 deletions.
1 change: 1 addition & 0 deletions .github/workflows/osv-scanner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ permissions:
security-events: write
# Read commit contents
contents: read
actions: read

jobs:
scan-scheduled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
ScrollViewer.IsHorizontalRailEnabled="True"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ShowsScrollingPlaceholders="True"
ScrollViewer.VerticalScrollBarVisibility="Visible">
ScrollViewer.VerticalScrollBarVisibility="Visible"
ContainerContentChanging="ListView_ContainerContentChanging">

<ListView.Header>

Expand Down Expand Up @@ -177,7 +178,16 @@
<Grid.ContextFlyout>
<MenuFlyout>

<MenuFlyoutItem Text="Delete Row" Click="ListViewFlyoutMenuDelete_Click">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE74D;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>

<MenuFlyoutItem Text="Copy Row" Click="ListViewFlyoutMenuCopy_Click">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Key="C" Modifiers="Control" Invoked="CtrlC_Invoked"/>
</MenuFlyoutItem.KeyboardAccelerators>
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE8C8;" />
</MenuFlyoutItem.Icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using AppControlManager.Others;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Navigation;
using Windows.ApplicationModel.DataTransfer;
using WinRT;
Expand Down Expand Up @@ -320,7 +321,7 @@ private void ListViewFlyoutMenuCopy_Click(object sender, RoutedEventArgs e)
if (selectedItem is FileIdentity obj)

// Append each row's formatted data to the StringBuilder
_ = dataBuilder.AppendLine(ListViewUIHelpers.ConvertRowToText(obj));
_ = dataBuilder.AppendLine(ConvertRowToText(obj));

// Add a separator between rows for readability in multi-row copies
_ = dataBuilder.AppendLine(new string('-', 50));
Expand Down Expand Up @@ -612,15 +613,8 @@ private void ApplyFilters()
);
}

// Clear the current contents of the ObservableCollection
AllowNewAppsStart.Instance.EventLogsFileIdentities.Clear();

// Populate the ObservableCollection with the filtered results
// This triggers the UI to update the ListView based on the filtered data
foreach (FileIdentity result in filteredResults)
{
AllowNewAppsStart.Instance.EventLogsFileIdentities.Add(result);
}
AllowNewAppsStart.Instance.EventLogsFileIdentities = [.. filteredResults];

// Explicitly set the ListView's ItemsSource to ensure the data refreshes
FileIdentitiesListView.ItemsSource = AllowNewAppsStart.Instance.EventLogsFileIdentities;
Expand Down Expand Up @@ -649,16 +643,13 @@ private void ClearDataButton_Click(object sender, RoutedEventArgs e)
/// <param name="e"></param>
private void SelectAll_Click(object sender, RoutedEventArgs e)
{
_ = DispatcherQueue.TryEnqueue(() =>
{
// Clear existing selections
FileIdentitiesListView.SelectedItems.Clear();
// Clear existing selections
FileIdentitiesListView.SelectedItems.Clear();

foreach (FileIdentity fileIdentity in AllowNewAppsStart.Instance.EventLogsFileIdentities)
{
FileIdentitiesListView.SelectedItems.Add(fileIdentity); // Select each item
}
});
foreach (FileIdentity fileIdentity in AllowNewAppsStart.Instance.EventLogsFileIdentities)
{
FileIdentitiesListView.SelectedItems.Add(fileIdentity); // Select each item
}
}

/// <summary>
Expand All @@ -676,7 +667,7 @@ private void DeSelectAll_Click(object sender, RoutedEventArgs e)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DataGridFlyoutMenuDelete_Click(object sender, RoutedEventArgs e)
private void ListViewFlyoutMenuDelete_Click(object sender, RoutedEventArgs e)
{
// Collect the selected items to delete
List<FileIdentity> itemsToDelete = [.. FileIdentitiesListView.SelectedItems.Cast<FileIdentity>()];
Expand Down Expand Up @@ -711,4 +702,53 @@ internal void UpdateTotalLogs(bool? Zero = null)
AllowNewApps.Instance.UpdateEventLogsInfoBadge(AllowNewAppsStart.Instance.EventLogsFileIdentities.Count, 1);
}
}


#region Ensuring right-click on rows behaves better and normally on ListView

// When right-clicking on an unselected row, first it becomes selected and then the context menu will be shown for the selected row
// This is a much more expected behavior. Without this, the right-click would be meaningless on the ListView unless user left-clicks on the row first

private void ListView_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
{
// When the container is being recycled, detach the handler.
if (args.InRecycleQueue)
{
args.ItemContainer.RightTapped -= ListViewItem_RightTapped;
}
else
{
// Detach first to avoid multiple subscriptions, then attach the handler.
args.ItemContainer.RightTapped -= ListViewItem_RightTapped;
args.ItemContainer.RightTapped += ListViewItem_RightTapped;
}
}

private void ListViewItem_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
if (sender is ListViewItem item)
{
// If the item is not already selected, clear previous selections and select this one.
if (!item.IsSelected)
{
//clear for exclusive selection
FileIdentitiesListView.SelectedItems.Clear();
item.IsSelected = true;
}
}
}

#endregion


/// <summary>
/// CTRL + C shortcuts event handler
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
private void CtrlC_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
{
ListViewFlyoutMenuCopy_Click(sender, new RoutedEventArgs());
args.Handled = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
ScrollViewer.IsHorizontalRailEnabled="True"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ShowsScrollingPlaceholders="True"
ScrollViewer.VerticalScrollBarVisibility="Visible">
ScrollViewer.VerticalScrollBarVisibility="Visible"
ContainerContentChanging="ListView_ContainerContentChanging">

<ListView.Header>

Expand Down Expand Up @@ -169,7 +170,16 @@
<Grid.ContextFlyout>
<MenuFlyout>

<MenuFlyoutItem Text="Delete Row" Click="ListViewFlyoutMenuDelete_Click">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE74D;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>

<MenuFlyoutItem Text="Copy Row" Click="ListViewFlyoutMenuCopy_Click">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Key="C" Modifiers="Control" Invoked="CtrlC_Invoked"/>
</MenuFlyoutItem.KeyboardAccelerators>
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE8C8;" />
</MenuFlyoutItem.Icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using AppControlManager.Others;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Navigation;
using Windows.ApplicationModel.DataTransfer;
using WinRT;
Expand Down Expand Up @@ -284,7 +285,7 @@ private void ListViewFlyoutMenuCopy_Click(object sender, RoutedEventArgs e)
if (selectedItem is FileIdentity obj)

// Append each row's formatted data to the StringBuilder
_ = dataBuilder.AppendLine(ListViewUIHelpers.ConvertRowToText(obj));
_ = dataBuilder.AppendLine(ConvertRowToText(obj));

// Add a separator between rows for readability in multi-row copies
_ = dataBuilder.AppendLine(new string('-', 50));
Expand Down Expand Up @@ -554,15 +555,8 @@ private void ApplyFilters()
);
}

// Clear the current contents of the ObservableCollection
AllowNewAppsStart.Instance.LocalFilesFileIdentities.Clear();

// Populate the ObservableCollection with the filtered results
// This triggers the UI to update the ListView based on the filtered data
foreach (FileIdentity result in filteredResults)
{
AllowNewAppsStart.Instance.LocalFilesFileIdentities.Add(result);
}
AllowNewAppsStart.Instance.LocalFilesFileIdentities = [.. filteredResults];

// Explicitly set the ListView's ItemsSource to ensure the data refreshes
FileIdentitiesListView.ItemsSource = AllowNewAppsStart.Instance.LocalFilesFileIdentities;
Expand Down Expand Up @@ -591,17 +585,13 @@ private void ClearDataButton_Click(object sender, RoutedEventArgs e)
/// <param name="e"></param>
private void SelectAll_Click(object sender, RoutedEventArgs e)
{
_ = DispatcherQueue.TryEnqueue(() =>
{
// Clear existing selections
FileIdentitiesListView.SelectedItems.Clear();
// Clear existing selections
FileIdentitiesListView.SelectedItems.Clear();

foreach (FileIdentity fileIdentity in AllowNewAppsStart.Instance.LocalFilesFileIdentities)
{
FileIdentitiesListView.SelectedItems.Add(fileIdentity); // Select each item
}

});
foreach (FileIdentity fileIdentity in AllowNewAppsStart.Instance.LocalFilesFileIdentities)
{
FileIdentitiesListView.SelectedItems.Add(fileIdentity); // Select each item
}
}

/// <summary>
Expand All @@ -619,7 +609,7 @@ private void DeSelectAll_Click(object sender, RoutedEventArgs e)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DataGridFlyoutMenuDelete_Click(object sender, RoutedEventArgs e)
private void ListViewFlyoutMenuDelete_Click(object sender, RoutedEventArgs e)
{
// Collect the selected items to delete
List<FileIdentity> itemsToDelete = [.. FileIdentitiesListView.SelectedItems.Cast<FileIdentity>()];
Expand Down Expand Up @@ -654,4 +644,53 @@ internal void UpdateTotalLogs(bool? Zero = null)
AllowNewApps.Instance.UpdateLocalFilesInfoBadge(AllowNewAppsStart.Instance.LocalFilesFileIdentities.Count, 1);
}
}


#region Ensuring right-click on rows behaves better and normally on ListView

// When right-clicking on an unselected row, first it becomes selected and then the context menu will be shown for the selected row
// This is a much more expected behavior. Without this, the right-click would be meaningless on the ListView unless user left-clicks on the row first

private void ListView_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
{
// When the container is being recycled, detach the handler.
if (args.InRecycleQueue)
{
args.ItemContainer.RightTapped -= ListViewItem_RightTapped;
}
else
{
// Detach first to avoid multiple subscriptions, then attach the handler.
args.ItemContainer.RightTapped -= ListViewItem_RightTapped;
args.ItemContainer.RightTapped += ListViewItem_RightTapped;
}
}

private void ListViewItem_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
if (sender is ListViewItem item)
{
// If the item is not already selected, clear previous selections and select this one.
if (!item.IsSelected)
{
//clear for exclusive selection
FileIdentitiesListView.SelectedItems.Clear();
item.IsSelected = true;
}
}
}

#endregion


/// <summary>
/// CTRL + C shortcuts event handler
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
private void CtrlC_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
{
ListViewFlyoutMenuCopy_Click(sender, new RoutedEventArgs());
args.Handled = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
ScrollViewer.IsHorizontalRailEnabled="True"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ShowsScrollingPlaceholders="True"
ScrollViewer.VerticalScrollBarVisibility="Visible">
ScrollViewer.VerticalScrollBarVisibility="Visible"
ContainerContentChanging="ListView_ContainerContentChanging">

<ListView.Header>

Expand Down Expand Up @@ -181,6 +182,9 @@
<MenuFlyout>

<MenuFlyoutItem Text="Copy Row" Click="ListViewFlyoutMenuCopy_Click">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Key="C" Modifiers="Control" Invoked="CtrlC_Invoked"/>
</MenuFlyoutItem.KeyboardAccelerators>
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE8C8;" />
</MenuFlyoutItem.Icon>
Expand Down
Loading

0 comments on commit 709c257

Please sign in to comment.