Skip to content

Commit

Permalink
Merge pull request #2 from NiceAustrian/main
Browse files Browse the repository at this point in the history
Applied WPF Design Concepts and added some C# Syntax + CommunityToolk…
  • Loading branch information
CalaxDev authored Feb 9, 2024
2 parents cd3e5e3 + 0e6d073 commit ee70d05
Show file tree
Hide file tree
Showing 13 changed files with 474 additions and 528 deletions.
14 changes: 1 addition & 13 deletions Switchy/Switchy/App.xaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
<Application x:Class="Switchy.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Switchy"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style TargetType="StackPanel" x:Key="GlobalStackPanelStyle">
<Style.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="0,0,0,20" />
<Setter Property="Height" Value="30" />
<Setter Property="Width" Value="35" />
</Style>
</Style.Resources>
</Style>
</Application.Resources>
StartupUri="View/MainWindow.xaml">
</Application>
18 changes: 7 additions & 11 deletions Switchy/Switchy/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using System.Configuration;
using System.Data;
using System.Windows;
using System.Windows;

namespace Switchy
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
namespace Switchy;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
79 changes: 0 additions & 79 deletions Switchy/Switchy/MainWindow.xaml

This file was deleted.

136 changes: 0 additions & 136 deletions Switchy/Switchy/MainWindow.xaml.cs

This file was deleted.

66 changes: 28 additions & 38 deletions Switchy/Switchy/Model/ProcessListViewItem.cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,42 @@
using System.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace Switchy.Model
namespace Switchy.Model;

public partial class ProcessListViewItem(Process p) : ObservableObject
{
public class ProcessListViewItem : INotifyPropertyChanged
private Process _process = p;
[ObservableProperty]
private bool _isExited;
public Process Process
{
public Process Process { get; }
public bool HasExited { get; internal set; }
public event PropertyChangedEventHandler? PropertyChanged;

public ProcessListViewItem(Process p)
get
{
Process = p;
return _process;
}
private set
{
_process = value;

try //Needed to prevent application crash when executing switchy without debug mode or admin rights; Effectively disables process exit listview binding however.
{
p.EnableRaisingEvents = true;
p.Exited += P_Exited;
_process.EnableRaisingEvents = true;
_process.Exited += P_Exited;
}
catch (Exception) { }
}

private void P_Exited(object? sender, EventArgs e)
{
this.HasExited = true;
NotifyPropertyChanged(nameof(Process.HasExited));
catch { }
}
}

public override string ToString()
{
return Process?.ProcessName ?? "No Process";
}
private void P_Exited(object? sender, EventArgs e)
=> IsExited = true;

public override bool Equals(object? obj)
{
if (obj is ProcessListViewItem it)
return Process.Id.Equals(it.Process.Id);
public override string ToString()
=> Process?.ProcessName ?? "No Process";

return false;
}
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public override bool Equals(object? obj)
=> obj is ProcessListViewItem it && Process.Id.Equals(it.Process.Id);

public override int GetHashCode()
{
return HashCode.Combine(Process.Id);
}
}
public override int GetHashCode()
=> HashCode.Combine(Process.Id);
}
6 changes: 6 additions & 0 deletions Switchy/Switchy/Switchy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
</ItemGroup>

</Project>
Loading

0 comments on commit ee70d05

Please sign in to comment.