Add Checkbox for per monitor selection

This commit is contained in:
donlaci
2024-06-27 20:10:44 +02:00
parent c4a93d2482
commit e0bdba9772
8 changed files with 114 additions and 11 deletions

View File

@@ -18,7 +18,7 @@ namespace ProjectsEditor.Models
public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
{
if (item is string)
if (item is MonitorHeaderRow)
{
return HeaderTemplate;
}

View File

@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectsEditor.Models
{
internal sealed class MonitorHeaderRow
{
public string MonitorName { get; set; }
public string SelectString { get; set; }
}
}

View File

@@ -151,7 +151,8 @@ namespace ProjectsEditor.Models
ILookup<MonitorSetup, Application> apps = Applications.Where(x => !x.Minimized).ToLookup(x => x.MonitorSetup);
foreach (var appItem in apps.OrderBy(x => x.Key.MonitorDpiUnawareBounds.Left).ThenBy(x => x.Key.MonitorDpiUnawareBounds.Top))
{
applicationsListed.Add(appItem.Key.MonitorInfo);
MonitorHeaderRow mhr = new MonitorHeaderRow { MonitorName = appItem.Key.MonitorInfo, SelectString = Properties.Resources.SelectAllAppsOnMonitor + " " + appItem.Key.MonitorInfo };
applicationsListed.Add(mhr);
foreach (Application app in appItem)
{
applicationsListed.Add(app);
@@ -161,7 +162,8 @@ namespace ProjectsEditor.Models
var minimizedApps = Applications.Where(x => x.Minimized);
if (minimizedApps.Any())
{
applicationsListed.Add("Minimized Apps");
MonitorHeaderRow mhr = new MonitorHeaderRow { MonitorName = Properties.Resources.Minimized_Apps, SelectString = Properties.Resources.SelectAllMinimizedApps };
applicationsListed.Add(mhr);
foreach (Application app in minimizedApps)
{
applicationsListed.Add(app);

View File

@@ -13,14 +13,30 @@
<BooleanToVisibilityConverter x:Key="BoolToVis" />
<DataTemplate x:Key="headerTemplate">
<Border>
<TextBlock
Text="{Binding .}"
Foreground="{DynamicResource PrimaryForegroundBrush}"
FontSize="14"
FontWeight="Normal"
Margin="0,20,20,5"
VerticalAlignment="Center"/>
<Border
HorizontalAlignment="Stretch">
<DockPanel
HorizontalAlignment="Stretch"
>
<TextBlock
DockPanel.Dock="Left"
Text="{Binding MonitorName}"
Foreground="{DynamicResource PrimaryForegroundBrush}"
FontSize="14"
FontWeight="Normal"
Margin="0,0,20,0"
VerticalAlignment="Center"/>
<CheckBox
DockPanel.Dock="Right"
HorizontalAlignment="Right"
x:Name="SelectAllOnMonitorCheckBox"
Tag="{Binding MonitorName}"
Margin="10,0,0,0"
FontSize="14"
Content="{Binding SelectString}"
Checked="SelectAllOnMonitorCheckBox_Modified"
Unchecked="SelectAllOnMonitorCheckBox_Modified"/>
</DockPanel>
</Border>
</DataTemplate>
<DataTemplate x:Key="appTemplate">

View File

@@ -105,5 +105,14 @@ namespace ProjectsEditor
bool newValue = SelectAllCheckBox.IsChecked == true;
_mainViewModel.UpdateIsSelectedStates(project, newValue);
}
private void SelectAllOnMonitorCheckBox_Modified(object sender, RoutedEventArgs e)
{
Project project = this.DataContext as Project;
CheckBox checkBox = (CheckBox)sender;
string monitorInfo = (string)checkBox.Tag;
bool newValue = checkBox.IsChecked == true;
_mainViewModel.UpdateIsSelectedStates(project, monitorInfo, newValue);
}
}
}

View File

@@ -258,6 +258,15 @@ namespace ProjectsEditor.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Minimized Apps.
/// </summary>
public static string Minimized_Apps {
get {
return ResourceManager.GetString("Minimized_Apps", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to minutes ago.
/// </summary>
@@ -447,6 +456,24 @@ namespace ProjectsEditor.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Select All Apps on.
/// </summary>
public static string SelectAllAppsOnMonitor {
get {
return ResourceManager.GetString("SelectAllAppsOnMonitor", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Select All Minimized Apps.
/// </summary>
public static string SelectAllMinimizedApps {
get {
return ResourceManager.GetString("SelectAllMinimizedApps", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Select All Apps in Project.
/// </summary>

View File

@@ -183,6 +183,9 @@
<data name="MainTitle" xml:space="preserve">
<value>Projects demo app</value>
</data>
<data name="Minimized_Apps" xml:space="preserve">
<value>Minimized Apps</value>
</data>
<data name="MinutesAgo" xml:space="preserve">
<value>minutes ago</value>
</data>
@@ -246,6 +249,12 @@
<data name="SecondsAgo" xml:space="preserve">
<value>seconds ago</value>
</data>
<data name="SelectAllAppsOnMonitor" xml:space="preserve">
<value>Select All Apps on</value>
</data>
<data name="SelectAllMinimizedApps" xml:space="preserve">
<value>Select All Minimized Apps</value>
</data>
<data name="SelectedAllInProject" xml:space="preserve">
<value>Select All Apps in Project</value>
</data>

View File

@@ -367,5 +367,26 @@ namespace ProjectsEditor.ViewModels
project.OnPropertyChanged(new PropertyChangedEventArgs(nameof(Project.IsAnySelected)));
project.OnPropertyChanged(new PropertyChangedEventArgs(nameof(Project.CanBeSaved)));
}
internal void UpdateIsSelectedStates(Project project, string monitorInfo, bool newValue)
{
IEnumerable<Application> apps;
if (monitorInfo == Properties.Resources.Minimized_Apps)
{
apps = project.Applications.Where(app => app.Minimized);
}
else
{
Monitor monitor = project.Monitors.Where(x => x.MonitorInfo == monitorInfo).Single();
apps = project.Applications.Where(app => !app.Minimized && app.MonitorNumber == monitor.MonitorNumber);
}
foreach (Application app in apps)
{
app.IsSelected = newValue;
}
project.OnPropertyChanged(new PropertyChangedEventArgs(nameof(Project.IsAnySelected)));
}
}
}