Merge branch 'dev/feature/projects' of https://github.com/microsoft/PowerToys into dev/feature/projects

This commit is contained in:
seraphima
2024-06-28 14:49:30 +02:00
11 changed files with 255 additions and 76 deletions

View File

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

View File

@@ -71,8 +71,21 @@ namespace ProjectsEditor.Models
} }
} }
private bool _isSelected;
[JsonIgnore] [JsonIgnore]
public bool IsSelected { get; set; } public bool IsSelected
{
get => _isSelected;
set
{
if (_isSelected != value)
{
_isSelected = value;
OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsSelected)));
}
}
}
[JsonIgnore] [JsonIgnore]
public bool IsHighlighted { get; set; } public bool IsHighlighted { get; set; }

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

@@ -121,7 +121,7 @@ namespace ProjectsEditor.Models
public bool CanBeSaved public bool CanBeSaved
{ {
get => Name.Length > 0 && Applications.Where(x => x.IsSelected).Any(); get => Name.Length > 0 && Applications.Count > 0;
} }
private bool _isPopupVisible; private bool _isPopupVisible;
@@ -151,7 +151,8 @@ namespace ProjectsEditor.Models
ILookup<MonitorSetup, Application> apps = Applications.Where(x => !x.Minimized).ToLookup(x => x.MonitorSetup); 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)) foreach (var appItem in apps.OrderBy(x => x.Key.MonitorDpiUnawareBounds.Left).ThenBy(x => x.Key.MonitorDpiUnawareBounds.Top))
{ {
applicationsListed.Add(appItem.Key.MonitorInfo); MonitorHeaderRow headerRow = new MonitorHeaderRow { MonitorName = appItem.Key.MonitorInfo, SelectString = Properties.Resources.SelectAllAppsOnMonitor + " " + appItem.Key.MonitorInfo };
applicationsListed.Add(headerRow);
foreach (Application app in appItem) foreach (Application app in appItem)
{ {
applicationsListed.Add(app); applicationsListed.Add(app);
@@ -161,7 +162,8 @@ namespace ProjectsEditor.Models
var minimizedApps = Applications.Where(x => x.Minimized); var minimizedApps = Applications.Where(x => x.Minimized);
if (minimizedApps.Any()) if (minimizedApps.Any())
{ {
applicationsListed.Add("Minimized Apps"); MonitorHeaderRow headerRow = new MonitorHeaderRow { MonitorName = Properties.Resources.Minimized_Apps, SelectString = Properties.Resources.SelectAllMinimizedApps };
applicationsListed.Add(headerRow);
foreach (Application app in minimizedApps) foreach (Application app in minimizedApps)
{ {
applicationsListed.Add(app); applicationsListed.Add(app);
@@ -177,11 +179,13 @@ namespace ProjectsEditor.Models
{ {
get get
{ {
int count = Applications.Where(x => x.IsSelected).Count(); int count = Applications.Count;
return count.ToString(CultureInfo.InvariantCulture) + " " + (count == 1 ? Properties.Resources.App : Properties.Resources.Apps); return count.ToString(CultureInfo.InvariantCulture) + " " + (count == 1 ? Properties.Resources.App : Properties.Resources.Apps);
} }
} }
public bool IsAnySelected { get => Applications?.Any(x => x.IsSelected) == true; }
public List<MonitorSetup> Monitors { get; set; } public List<MonitorSetup> Monitors { get; set; }
private BitmapImage _previewIcons; private BitmapImage _previewIcons;
@@ -216,7 +220,7 @@ namespace ProjectsEditor.Models
PackageFullName = item.PackageFullName, PackageFullName = item.PackageFullName,
Minimized = item.Minimized, Minimized = item.Minimized,
Maximized = item.Maximized, Maximized = item.Maximized,
IsSelected = item.IsSelected, IsSelected = false,
MonitorNumber = item.MonitorNumber, MonitorNumber = item.MonitorNumber,
IsNotFound = item.IsNotFound, IsNotFound = item.IsNotFound,
Position = new Application.WindowPosition() { X = item.Position.X, Y = item.Position.Y, Height = item.Position.Height, Width = item.Position.Width }, Position = new Application.WindowPosition() { X = item.Position.X, Y = item.Position.Y, Height = item.Position.Height, Width = item.Position.Width },

View File

@@ -13,14 +13,30 @@
<BooleanToVisibilityConverter x:Key="BoolToVis" /> <BooleanToVisibilityConverter x:Key="BoolToVis" />
<DataTemplate x:Key="headerTemplate"> <DataTemplate x:Key="headerTemplate">
<Border> <Border
<TextBlock HorizontalAlignment="Stretch">
Text="{Binding .}" <DockPanel
Foreground="{DynamicResource PrimaryForegroundBrush}" HorizontalAlignment="Stretch"
FontSize="14" >
FontWeight="Normal" <TextBlock
Margin="0,20,20,5" DockPanel.Dock="Left"
VerticalAlignment="Center"/> 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> </Border>
</DataTemplate> </DataTemplate>
<DataTemplate x:Key="appTemplate"> <DataTemplate x:Key="appTemplate">
@@ -103,7 +119,7 @@
</TextBlock> </TextBlock>
<CheckBox <CheckBox
Grid.Column="5" Grid.Column="5"
IsChecked="{Binding IsSelected, Mode=TwoWay}" IsChecked="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Checked="CheckBox_Checked" Checked="CheckBox_Checked"
Unchecked="CheckBox_Checked" Unchecked="CheckBox_Checked"
Margin="10"/> Margin="10"/>
@@ -151,21 +167,41 @@
Foreground="{DynamicResource PrimaryForegroundBrush}" Foreground="{DynamicResource PrimaryForegroundBrush}"
VerticalAlignment="Center"/> VerticalAlignment="Center"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="1" Orientation="Vertical"> <DockPanel Grid.Row="1">
<TextBlock Text="{x:Static props:Resources.ProjectName}" FontSize="14" FontWeight="Normal" Foreground="{DynamicResource PrimaryForegroundBrush}"/> <StackPanel DockPanel.Dock="Right" Orientation="Horizontal" >
<TextBox <Button x:Name="DeleteButton"
x:Name="EditNameTextBox" Margin="10,0,0,0"
Width="320" Height="36"
Text="{Binding Name, Mode=TwoWay}" Padding="24,0,24,0"
Background="{DynamicResource SecondaryBackgroundBrush}" Content="{x:Static props:Resources.DeleteSelected}"
BorderBrush="{DynamicResource PrimaryBorderBrush}" Background="{DynamicResource SecondaryBackgroundBrush}"
BorderThickness="2" AutomationProperties.Name="{x:Static props:Resources.Cancel}"
Margin="0,6,0,6" IsEnabled="{Binding IsAnySelected, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Left" Click="RemoveSelectedButtonClicked"/>
GotFocus="EditNameTextBox_GotFocus" <CheckBox
TextChanged="EditNameTextBox_TextChanged" x:Name="SelectAllCheckBox"
KeyDown="EditNameTextBoxKeyDown" /> Margin="10,0,0,0"
</StackPanel> FontSize="14"
Content="{x:Static props:Resources.SelectedAllInProject}"
Checked="SelectAllCheckBox_Modified"
Unchecked="SelectAllCheckBox_Modified"/>
</StackPanel>
<StackPanel DockPanel.Dock="Left" Orientation="Vertical">
<TextBlock Text="{x:Static props:Resources.ProjectName}" FontSize="14" FontWeight="Normal" Foreground="{DynamicResource PrimaryForegroundBrush}"/>
<TextBox
x:Name="EditNameTextBox"
Width="320"
Text="{Binding Name, Mode=TwoWay}"
Background="{DynamicResource SecondaryBackgroundBrush}"
BorderBrush="{DynamicResource PrimaryBorderBrush}"
BorderThickness="2"
Margin="0,6,0,6"
HorizontalAlignment="Left"
GotFocus="EditNameTextBox_GotFocus"
TextChanged="EditNameTextBox_TextChanged"
KeyDown="EditNameTextBoxKeyDown" />
</StackPanel>
</DockPanel>
<Border <Border
Grid.Row="2" Grid.Row="2"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
@@ -189,7 +225,7 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<ItemsControl <ItemsControl
ItemsSource="{Binding ApplicationsListed, Mode=OneWay}" ItemsSource="{Binding ApplicationsListed, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
ItemTemplateSelector="{StaticResource AppListDataTemplateSelector}"> ItemTemplateSelector="{StaticResource AppListDataTemplateSelector}">
</ItemsControl> </ItemsControl>
</Grid> </Grid>

View File

@@ -30,6 +30,7 @@ namespace ProjectsEditor
Models.Application application = checkBox.DataContext as Models.Application; Models.Application application = checkBox.DataContext as Models.Application;
Models.Project project = application.Parent; Models.Project project = application.Parent;
project.OnPropertyChanged(new PropertyChangedEventArgs(nameof(Project.CanBeSaved))); project.OnPropertyChanged(new PropertyChangedEventArgs(nameof(Project.CanBeSaved)));
project.OnPropertyChanged(new PropertyChangedEventArgs(nameof(Project.IsAnySelected)));
project.Initialize(); project.Initialize();
} }
@@ -40,6 +41,12 @@ namespace ProjectsEditor
_mainViewModel.SwitchToMainView(); _mainViewModel.SwitchToMainView();
} }
private void RemoveSelectedButtonClicked(object sender, RoutedEventArgs e)
{
Project projectToSave = this.DataContext as Project;
_mainViewModel.RemoveSelectedApps(projectToSave);
}
private void CancelButtonClicked(object sender, RoutedEventArgs e) private void CancelButtonClicked(object sender, RoutedEventArgs e)
{ {
_mainViewModel.CancelLastEdit(); _mainViewModel.CancelLastEdit();
@@ -91,5 +98,21 @@ namespace ProjectsEditor
project.Name = EditNameTextBox.Text; project.Name = EditNameTextBox.Text;
project.OnPropertyChanged(new PropertyChangedEventArgs(nameof(Project.CanBeSaved))); project.OnPropertyChanged(new PropertyChangedEventArgs(nameof(Project.CanBeSaved)));
} }
private void SelectAllCheckBox_Modified(object sender, RoutedEventArgs e)
{
Project project = this.DataContext as Project;
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

@@ -168,6 +168,15 @@ namespace ProjectsEditor.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Remove Selected Apps.
/// </summary>
public static string DeleteSelected {
get {
return ResourceManager.GetString("DeleteSelected", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Edit. /// Looks up a localized string similar to Edit.
/// </summary> /// </summary>
@@ -249,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> /// <summary>
/// Looks up a localized string similar to minutes ago. /// Looks up a localized string similar to minutes ago.
/// </summary> /// </summary>
@@ -438,6 +456,33 @@ 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>
public static string SelectedAllInProject {
get {
return ResourceManager.GetString("SelectedAllInProject", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Sort by. /// Looks up a localized string similar to Sort by.
/// </summary> /// </summary>

View File

@@ -150,6 +150,9 @@
<data name="Delete" xml:space="preserve"> <data name="Delete" xml:space="preserve">
<value>Remove</value> <value>Remove</value>
</data> </data>
<data name="DeleteSelected" xml:space="preserve">
<value>Remove Selected Apps</value>
</data>
<data name="Delete_Project_Dialog_Announce" xml:space="preserve"> <data name="Delete_Project_Dialog_Announce" xml:space="preserve">
<value>Delete project dialog.</value> <value>Delete project dialog.</value>
</data> </data>
@@ -180,6 +183,9 @@
<data name="MainTitle" xml:space="preserve"> <data name="MainTitle" xml:space="preserve">
<value>Projects demo app</value> <value>Projects demo app</value>
</data> </data>
<data name="Minimized_Apps" xml:space="preserve">
<value>Minimized Apps</value>
</data>
<data name="MinutesAgo" xml:space="preserve"> <data name="MinutesAgo" xml:space="preserve">
<value>minutes ago</value> <value>minutes ago</value>
</data> </data>
@@ -243,6 +249,15 @@
<data name="SecondsAgo" xml:space="preserve"> <data name="SecondsAgo" xml:space="preserve">
<value>seconds ago</value> <value>seconds ago</value>
</data> </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>
<data name="SortBy" xml:space="preserve"> <data name="SortBy" xml:space="preserve">
<value>Sort by</value> <value>Sort by</value>
</data> </data>

View File

@@ -48,8 +48,7 @@ namespace ProjectsEditor.Utils
Dictionary<string, int> repeatCounter = new Dictionary<string, int>(); Dictionary<string, int> repeatCounter = new Dictionary<string, int>();
var selectedApps = project.Applications.Where(x => x.IsSelected); foreach (Application app in project.Applications)
foreach (Application app in selectedApps)
{ {
if (repeatCounter.TryGetValue(app.AppPath, out int value)) if (repeatCounter.TryGetValue(app.AppPath, out int value))
{ {
@@ -64,12 +63,12 @@ namespace ProjectsEditor.Utils
} }
// remove those repeatIndexes, which are single 1-es (no repetitions) by setting them to 0 // remove those repeatIndexes, which are single 1-es (no repetitions) by setting them to 0
foreach (Application app in selectedApps.Where(x => repeatCounter[x.AppPath] == 1)) foreach (Application app in project.Applications.Where(x => repeatCounter[x.AppPath] == 1))
{ {
app.RepeatIndex = 0; app.RepeatIndex = 0;
} }
foreach (Application app in project.Applications.Where(x => !x.IsSelected)) foreach (Application app in project.Applications)
{ {
app.RepeatIndex = 0; app.RepeatIndex = 0;
} }
@@ -96,7 +95,7 @@ namespace ProjectsEditor.Utils
} }
Bitmap previewBitmap = new Bitmap(Scaled(bounds.Width + (verticalGaps.Count * gapWidth)), Scaled((bounds.Height * 1.2) + (horizontalGaps.Count * gapHeight))); Bitmap previewBitmap = new Bitmap(Scaled(bounds.Width + (verticalGaps.Count * gapWidth)), Scaled((bounds.Height * 1.2) + (horizontalGaps.Count * gapHeight)));
double desiredIconSize = Scaled(Math.Min(bounds.Width, bounds.Height)) * 0.3; double desiredIconSize = Scaled(Math.Min(bounds.Width, bounds.Height)) * 0.25;
using (Graphics g = Graphics.FromImage(previewBitmap)) using (Graphics g = Graphics.FromImage(previewBitmap))
{ {
g.SmoothingMode = SmoothingMode.AntiAlias; g.SmoothingMode = SmoothingMode.AntiAlias;
@@ -112,7 +111,7 @@ namespace ProjectsEditor.Utils
g.FillRectangle(monitorBrush, new Rectangle(TransformX(monitor.MonitorDpiAwareBounds.Left), TransformY(monitor.MonitorDpiAwareBounds.Top), Scaled(monitor.MonitorDpiAwareBounds.Width), Scaled(monitor.MonitorDpiAwareBounds.Height))); g.FillRectangle(monitorBrush, new Rectangle(TransformX(monitor.MonitorDpiAwareBounds.Left), TransformY(monitor.MonitorDpiAwareBounds.Top), Scaled(monitor.MonitorDpiAwareBounds.Width), Scaled(monitor.MonitorDpiAwareBounds.Height)));
} }
var appsToDraw = project.Applications.Where(x => x.IsSelected && !x.Minimized); var appsToDraw = project.Applications.Where(x => !x.Minimized);
// draw the highlighted app at the end to have its icon in the foreground for the case there are overlapping icons // draw the highlighted app at the end to have its icon in the foreground for the case there are overlapping icons
foreach (Application app in appsToDraw.Where(x => !x.IsHighlighted)) foreach (Application app in appsToDraw.Where(x => !x.IsHighlighted))
@@ -124,12 +123,13 @@ namespace ProjectsEditor.Utils
foreach (Application app in appsToDraw.Where(x => x.IsHighlighted)) foreach (Application app in appsToDraw.Where(x => x.IsHighlighted))
{ {
Rectangle rect = new Rectangle(TransformX(app.ScaledPosition.X), TransformY(app.ScaledPosition.Y), Scaled(app.ScaledPosition.Width), Scaled(app.ScaledPosition.Height)); Rectangle rect = new Rectangle(TransformX(app.ScaledPosition.X), TransformY(app.ScaledPosition.Y), Scaled(app.ScaledPosition.Width), Scaled(app.ScaledPosition.Height));
DrawWindow(g, brush, rect, app, desiredIconSize); Brush brushForHighlight = new SolidBrush(Common.ThemeManager.GetCurrentTheme() == Common.Theme.Dark ? Color.FromArgb(192, 255, 255, 255) : Color.FromArgb(192, 0, 0, 0));
DrawWindow(g, brushForHighlight, rect, app, desiredIconSize);
} }
// draw the minimized windows // draw the minimized windows
Rectangle rectMinimized = new Rectangle(0, Scaled((bounds.Height * 1.02) + (horizontalGaps.Count * gapHeight)), Scaled(bounds.Width + (verticalGaps.Count * gapWidth)), Scaled(bounds.Height * 0.18)); Rectangle rectMinimized = new Rectangle(0, Scaled((bounds.Height * 1.02) + (horizontalGaps.Count * gapHeight)), Scaled(bounds.Width + (verticalGaps.Count * gapWidth)), Scaled(bounds.Height * 0.18));
DrawWindow(g, brush, rectMinimized, project.Applications.Where(x => x.IsSelected && x.Minimized)); DrawWindow(g, brush, rectMinimized, project.Applications.Where(x => x.Minimized));
} }
using (var memory = new MemoryStream()) using (var memory = new MemoryStream())
@@ -264,8 +264,7 @@ namespace ProjectsEditor.Utils
public static BitmapImage DrawPreviewIcons(Project project) public static BitmapImage DrawPreviewIcons(Project project)
{ {
var selectedApps = project.Applications.Where(x => x.IsSelected); int appsCount = project.Applications.Count;
int appsCount = selectedApps.Count();
if (appsCount == 0) if (appsCount == 0)
{ {
return null; return null;
@@ -278,7 +277,7 @@ namespace ProjectsEditor.Utils
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
int appIndex = 0; int appIndex = 0;
foreach (var app in selectedApps) foreach (var app in project.Applications)
{ {
try try
{ {

View File

@@ -117,7 +117,7 @@ namespace ProjectsEditor.Utils
CommandLineArguments = app.CommandLineArguments, CommandLineArguments = app.CommandLineArguments,
Maximized = app.Maximized, Maximized = app.Maximized,
Minimized = app.Minimized, Minimized = app.Minimized,
IsSelected = true, IsSelected = false,
IsNotFound = false, IsNotFound = false,
Position = new Models.Application.WindowPosition() Position = new Models.Application.WindowPosition()
{ {
@@ -161,27 +161,24 @@ namespace ProjectsEditor.Utils
foreach (var app in project.Applications) foreach (var app in project.Applications)
{ {
if (app.IsSelected) wrapper.Applications.Add(new ProjectsData.ApplicationWrapper
{ {
wrapper.Applications.Add(new ProjectsData.ApplicationWrapper Application = app.AppName,
ApplicationPath = app.AppPath,
Title = app.AppTitle,
PackageFullName = app.PackageFullName,
CommandLineArguments = app.CommandLineArguments,
Maximized = app.Maximized,
Minimized = app.Minimized,
Position = new ProjectsData.ApplicationWrapper.WindowPositionWrapper
{ {
Application = app.AppName, X = app.Position.X,
ApplicationPath = app.AppPath, Y = app.Position.Y,
Title = app.AppTitle, Height = app.Position.Height,
PackageFullName = app.PackageFullName, Width = app.Position.Width,
CommandLineArguments = app.CommandLineArguments, },
Maximized = app.Maximized, Monitor = app.MonitorNumber,
Minimized = app.Minimized, });
Position = new ProjectsData.ApplicationWrapper.WindowPositionWrapper
{
X = app.Position.X,
Y = app.Position.Y,
Height = app.Position.Height,
Width = app.Position.Width,
},
Monitor = app.MonitorNumber,
});
}
} }
foreach (var monitor in project.Monitors) foreach (var monitor in project.Monitors)

View File

@@ -88,7 +88,7 @@ namespace ProjectsEditor.ViewModels
return false; return false;
} }
return x.Applications.Any(app => app.IsSelected && app.AppName.Contains(_searchTerm, StringComparison.InvariantCultureIgnoreCase)); return x.Applications.Any(app => app.AppName.Contains(_searchTerm, StringComparison.InvariantCultureIgnoreCase));
}); });
} }
@@ -159,18 +159,7 @@ namespace ProjectsEditor.ViewModels
editedProject.IsShortcutNeeded = projectToSave.IsShortcutNeeded; editedProject.IsShortcutNeeded = projectToSave.IsShortcutNeeded;
editedProject.PreviewIcons = projectToSave.PreviewIcons; editedProject.PreviewIcons = projectToSave.PreviewIcons;
editedProject.PreviewImage = projectToSave.PreviewImage; editedProject.PreviewImage = projectToSave.PreviewImage;
for (int appIndex = editedProject.Applications.Count - 1; appIndex >= 0; appIndex--) editedProject.Applications = projectToSave.Applications;
{
if (!projectToSave.Applications[appIndex].IsSelected)
{
editedProject.Applications.RemoveAt(appIndex);
}
else
{
editedProject.Applications[appIndex].IsSelected = true;
editedProject.Applications[appIndex].CommandLineArguments = projectToSave.Applications[appIndex].CommandLineArguments;
}
}
editedProject.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("AppsCountString")); editedProject.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("AppsCountString"));
editedProject.Initialize(); editedProject.Initialize();
@@ -360,5 +349,44 @@ namespace ProjectsEditor.ViewModels
project.IsPopupVisible = false; project.IsPopupVisible = false;
} }
} }
internal void UpdateIsSelectedStates(Project project, bool newValue)
{
foreach (Application app in project.Applications)
{
app.IsSelected = newValue;
}
project.OnPropertyChanged(new PropertyChangedEventArgs(nameof(Project.IsAnySelected)));
}
internal void RemoveSelectedApps(Project project)
{
project.Applications.RemoveAll(app => app.IsSelected);
project.OnPropertyChanged(new PropertyChangedEventArgs(nameof(Project.ApplicationsListed)));
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)));
}
} }
} }