From b604ec7b9a1d062b3508fbabe668f87d296c04c9 Mon Sep 17 00:00:00 2001
From: muellerp <Philipp1.Mueller@Student.Reutlingen-University.de>
Date: Wed, 8 Jan 2025 18:16:43 +0100
Subject: [PATCH 1/3] first draft of process list

---
 .../Assets/distractingPrograms.json           |  14 +
 .../InnoLabProjektDektopApp.csproj            |   4 +
 .../InnoLabProjektDektopApp.csproj.user       |   3 +
 .../Screens/FirstLaunch/03_0Distractions.xaml |   2 +-
 .../FirstLaunch/03_0Distractions.xaml.cs      |  11 +-
 .../Screens/FirstLaunch/03_2ProgramsList.xaml | 175 +++++++++
 .../FirstLaunch/03_2ProgramsList.xaml.cs      | 334 ++++++++++++++++++
 .../Screens/Regulaer/01Overview.xaml.cs       |   3 +-
 .../Services/ProcessMonitor.cs                |  10 +
 9 files changed, 551 insertions(+), 5 deletions(-)
 create mode 100644 InnoLabProjektDektopApp/InnoLabProjektDektopApp/Assets/distractingPrograms.json
 create mode 100644 InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml
 create mode 100644 InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml.cs

diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Assets/distractingPrograms.json b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Assets/distractingPrograms.json
new file mode 100644
index 0000000..2d5a7c5
--- /dev/null
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Assets/distractingPrograms.json
@@ -0,0 +1,14 @@
+{
+    "Programs": [
+        {
+            "processName": "steam",
+            "mainWindowTitle": "The Steam Game Launcher",
+            "distracting": true
+        },
+        {
+            "processName": "discord",
+            "mainWindowTitle": "Messaging service",
+            "distracting": true
+        }
+    ]
+}
\ No newline at end of file
diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/InnoLabProjektDektopApp.csproj b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/InnoLabProjektDektopApp.csproj
index 5e480db..63aa5dd 100644
--- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/InnoLabProjektDektopApp.csproj
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/InnoLabProjektDektopApp.csproj
@@ -15,6 +15,7 @@
 
   <ItemGroup>
     <None Remove="Assets\blockedProcesses.json" />
+    <None Remove="Assets\distractingPrograms.json" />
     <None Remove="Assets\distractingWebsites.json" />
     <None Remove="Assets\gamesicon.png" />
     <None Remove="Assets\icon.ico" />
@@ -55,6 +56,9 @@
     <Content Include="Assets\blockedProcesses.json">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
+    <Content Include="Assets\distractingPrograms.json">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
     <Content Include="Assets\distractingWebsites.json">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/InnoLabProjektDektopApp.csproj.user b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/InnoLabProjektDektopApp.csproj.user
index af921af..ca4b48d 100644
--- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/InnoLabProjektDektopApp.csproj.user
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/InnoLabProjektDektopApp.csproj.user
@@ -12,6 +12,9 @@
     </Compile>
   </ItemGroup>
   <ItemGroup>
+    <Page Update="Screens\FirstLaunch\03_2ProgramsList.xaml">
+      <SubType>Designer</SubType>
+    </Page>
     <Page Update="Screens\FirstLaunch\03_1DistractionsList.xaml">
       <SubType>Designer</SubType>
     </Page>
diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_0Distractions.xaml b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_0Distractions.xaml
index 5a06954..e62c6ab 100644
--- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_0Distractions.xaml
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_0Distractions.xaml
@@ -68,7 +68,7 @@
             </Grid>
             <TextBlock Style="{StaticResource StandardText}" Text="By clicking on each category, you can change the programs/websites that should be marked as distracting."/>
 
-            <ScrollViewer VerticalScrollBarVisibility="Auto" Margin="20,10,0,8" Height="100">
+            <ScrollViewer VerticalScrollBarVisibility="Auto" Margin="20,0,0,8" Height="0">
                 <StackPanel x:Name="SearchResultsPanel" />
             </ScrollViewer>
 
diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_0Distractions.xaml.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_0Distractions.xaml.cs
index 8714279..554562b 100644
--- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_0Distractions.xaml.cs
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_0Distractions.xaml.cs
@@ -228,9 +228,14 @@ namespace InnoLabProjektDektopApp
 
                 if (!string.IsNullOrEmpty(category))
                 {
-
-                    this.NavigationService.Navigate(new DistractionsList(category));
-
+                    if(category == "Other Programs")
+                    {
+                        this.NavigationService.Navigate(new ProgramsList());
+                    }
+                    else
+                    {
+                        this.NavigationService.Navigate(new DistractionsList(category));
+                    }
                 }
             }
         }
diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml
new file mode 100644
index 0000000..8263e95
--- /dev/null
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml
@@ -0,0 +1,175 @@
+<Page x:Class="InnoLabProjektDektopApp.ProgramsList"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:InnoLabProjektDektopApp"
+        xmlns:header="clr-namespace:InnoLabProjektDektopApp.Screens.Templates"
+        mc:Ignorable="d">
+    <Grid>
+        <StackPanel Margin="20,20,20,20">
+            <Grid>
+                <Grid.ColumnDefinitions>
+                    <ColumnDefinition Width="*" />
+                    <ColumnDefinition Width="Auto" />
+                </Grid.ColumnDefinitions>
+
+                <Button Width="40" 
+        Height="40" 
+        Background="White" 
+        BorderBrush="Black" 
+        BorderThickness="1" 
+        HorizontalAlignment="Left" 
+        VerticalAlignment="Top" 
+        Click="BackButton_Click">
+                    <Button.Template>
+                        <ControlTemplate TargetType="Button">
+                            <Grid>
+                                <Ellipse Fill="Gray" />
+                                <TextBlock Text="←" 
+                           FontSize="16" 
+                           VerticalAlignment="Center" 
+                           HorizontalAlignment="Center" />
+                            </Grid>
+                        </ControlTemplate>
+                    </Button.Template>
+                </Button>
+
+
+                <!-- Überschrift -->
+                <TextBlock Grid.Column="0"
+                           Style="{StaticResource Header1}" 
+                           Text="Edit the list of websites and programs for this category" 
+                           HorizontalAlignment="Left" Margin="0,46,0,-46" />
+
+                <!-- Suchfeld -->
+                <DockPanel Grid.Column="1" HorizontalAlignment="Right" Margin="10,0,0,0">
+                    <!-- TextBox für Suche -->
+                    <Grid>
+                        <TextBox x:Name="SearchBox"
+                 Width="150" 
+                 Height="30" 
+                 FontSize="14" 
+                 VerticalAlignment="Center" 
+                 Padding="5"
+                 HorizontalAlignment="Left" 
+                 Foreground="Black" 
+                 Background="Transparent"
+                 BorderBrush="Gray" 
+                 BorderThickness="1" 
+                 TextChanged="SearchBox_TextChanged" />
+
+                        <TextBlock x:Name="SearchPlaceholder"
+                   Text="Search..."
+                   VerticalAlignment="Center"
+                   HorizontalAlignment="Left"
+                   Foreground="Gray"
+                   FontSize="14"
+                   Padding="5"
+                   IsHitTestVisible="False"
+                   Margin="5,0,0,0" />
+                    </Grid>
+
+                    <!-- Lupe-Symbol -->
+                    <Button Width="30" 
+                            Height="30" 
+                            Margin="5,0,0,0" 
+                            VerticalAlignment="Center" 
+                            HorizontalAlignment="Right">
+                        <TextBlock Text="🔍" 
+                                   FontSize="14" 
+                                   VerticalAlignment="Center" 
+                                   HorizontalAlignment="Center" />
+                    </Button>
+                </DockPanel>
+            </Grid>
+            <TextBlock Style="{StaticResource StandardText}" Margin="0,40,0,0"
+                       Text="By clicking on a toggle, you can change the programs/websites that should be marked as distracting." />
+
+            <Border Background="#2C2C2C" CornerRadius="10" Padding="10" Margin="0,10,0,0">
+                <Grid>
+                    <Grid.ColumnDefinitions>
+                        <ColumnDefinition Width="2*" />
+                        <ColumnDefinition Width="3*" />
+                        <ColumnDefinition Width="2*" />
+                        <ColumnDefinition Width="Auto" />
+                    </Grid.ColumnDefinitions>
+
+                    <!-- Label -->
+                    <TextBlock Text="Add a distracting website:" 
+        VerticalAlignment="Center" 
+        Foreground="White" 
+        FontSize="14" 
+        FontWeight="Bold" 
+        Grid.Column="0" 
+        Margin="10,0,10,0" />
+
+                    <!-- Input Field with Placeholder -->
+                    <Grid Grid.Column="1" VerticalAlignment="Center" Margin="0,0,10,0">
+                        <TextBox x:Name="UrlInputBox" 
+  VerticalAlignment="Center" 
+  Padding="5" 
+  FontSize="14" 
+  Background="Transparent" 
+  Foreground="White" 
+  BorderBrush="Gray" 
+  BorderThickness="1" 
+  TextChanged="UrlInputBox_TextChanged" />
+                        <TextBlock x:Name="UrlPlaceholder" 
+    Text="Url" 
+    VerticalAlignment="Center" 
+    Foreground="Gray" 
+    FontSize="14" 
+    Padding="5" 
+    IsHitTestVisible="False" 
+    Margin="5,0,0,0" />
+                    </Grid>
+
+                    <!-- Add Button -->
+                    <Button Width="30" 
+     Height="30" 
+     VerticalAlignment="Center" 
+     HorizontalAlignment="Right" 
+     Grid.Column="3" 
+     Margin="0" 
+     BorderThickness="0" 
+     ToolTip="Add"
+      Click="AddButton_Click">
+                        <TextBlock Text="+" 
+            FontSize="20" 
+            Foreground="#333436" 
+            VerticalAlignment="Center" 
+            HorizontalAlignment="Center" 
+                        />
+                    </Button>
+                </Grid>
+            </Border>
+
+            <!-- Überschrift -->
+            <Grid>
+                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,10,0,10" Width="350">
+                    <CheckBox x:Name="OtherProgramsCheckBox" IsChecked="True" VerticalAlignment="Center"/>
+                    <TextBlock x:Name="HeaderTextBlock"
+                                Style="{StaticResource Header2}" 
+                                Text="CATEGORY" RenderTransformOrigin="0.548,1.689" Margin="10,0,0,0"/>
+                </StackPanel>
+                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,10,0,10" Width="350">
+                    <TextBlock x:Name="HeaderTextBlock2"
+                                Style="{StaticResource Header2}" 
+                                Text="Running Programs" RenderTransformOrigin="0.548,1.689" Margin="0,0,0,0" HorizontalAlignment="Right"/>
+                    <Button Width="110" Margin="70,0,0,0" ToolTip="Refresh" Click="RefreshButton_Click">
+                        <TextBlock Text="Click to Refresh"/>
+                    </Button>
+                </StackPanel>
+            </Grid>
+        </StackPanel>
+        <ScrollViewer VerticalScrollBarVisibility="Auto" Margin="20,215,20,8" Width="400px" HorizontalAlignment="Left">
+            <StackPanel x:Name="ItemsPanel" />
+        </ScrollViewer>
+        <ScrollViewer VerticalScrollBarVisibility="Auto" Margin="20,215,20,8" Width="400px" HorizontalAlignment="Right">
+            <StackPanel x:Name="ItemsPanel2" />
+        </ScrollViewer>
+
+
+    </Grid>
+</Page>
\ No newline at end of file
diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml.cs
new file mode 100644
index 0000000..43feefa
--- /dev/null
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml.cs
@@ -0,0 +1,334 @@
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using InnoLabProjektDektopApp.Services;
+using System.Diagnostics;
+using static InnoLabProjektDektopApp.DistractionsList;
+using System;
+
+
+namespace InnoLabProjektDektopApp
+{
+    public partial class ProgramsList : Page
+    {
+        private Dictionary<string, List<ProcessEntry>> _data;
+        private readonly string _jsonFilePath;
+
+        public ProgramsList()
+        {
+            InitializeComponent();
+            _jsonFilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets", "distractingPrograms.json");
+            LoadCategoryItems();
+        }
+
+        private void SearchBox_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            // Platzhalter ein- oder ausblenden
+            if (!string.IsNullOrEmpty(SearchBox.Text))
+            {
+                SearchPlaceholder.Visibility = Visibility.Collapsed; // Ausblenden
+            }
+            else
+            {
+                SearchPlaceholder.Visibility = Visibility.Visible; // Einblenden
+            }
+
+            // Filterlogik für die Suchergebnisse
+            string searchText = SearchBox.Text?.ToLower() ?? string.Empty;
+
+            // Clear current UI
+            ItemsPanel.Children.Clear();
+
+            // Filter items based on search text
+            if (_data != null && _data.TryGetValue("Programs", out List<ProcessEntry>? value))
+            {
+                var filteredItems = value.Where(
+                    item => string.IsNullOrEmpty(searchText) || 
+                    item.ProcessName.Contains(searchText, StringComparison.CurrentCultureIgnoreCase))
+                    .ToList();
+
+                foreach (var item in filteredItems)
+                {
+                    // Create a StackPanel for each filtered item
+                    var stackPanel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(5, 2, 5, 2) };
+
+                    var checkBox = new CheckBox
+                    {
+                        Content = $"{item.ProcessName}: {item.MainWindowTitle}",
+                        Margin = new Thickness(5),
+                        IsChecked = item.IsDistracting,
+                        Tag = item
+                    };
+
+                    checkBox.Checked += CheckBox_CheckedChanged;
+                    checkBox.Unchecked += CheckBox_CheckedChanged;
+
+                    stackPanel.Children.Add(checkBox);
+
+                    // Add the filtered StackPanel to ItemsPanel
+                    ItemsPanel.Children.Add(stackPanel);
+                }
+            }
+        }
+
+
+
+        private void AddButton_Click(object sender, RoutedEventArgs e)
+        {
+            string enteredUrl = UrlInputBox.Text.Trim();
+
+            if (string.IsNullOrEmpty(enteredUrl))
+            {
+                MessageBox.Show("Please enter a URL.", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+
+            // Add the new URL to the current category
+            if (!_data.ContainsKey("Programs"))
+            {
+                _data["Programs"] = new List<ProcessEntry>();
+            }
+
+            _data["Programs"].Add(new ProcessEntry
+            {
+                ProcessName = enteredUrl,
+                MainWindowTitle = enteredUrl,
+                IsDistracting = true
+            });
+
+            // Save changes to the JSON
+            SaveData();
+
+            // Add to UI dynamically
+            var stackPanel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(5, 2, 5, 2) };
+
+            var checkBox = new CheckBox
+            {
+                Content = $"{enteredUrl}: {enteredUrl}",
+                Margin = new Thickness(5),
+                IsChecked = true,
+                Tag = new ProcessEntry { ProcessName = enteredUrl, MainWindowTitle = enteredUrl, IsDistracting = true }
+            };
+
+            checkBox.Checked += CheckBox_CheckedChanged;
+            checkBox.Unchecked += CheckBox_CheckedChanged;
+
+            stackPanel.Children.Add(checkBox);
+            ItemsPanel.Children.Add(stackPanel);
+
+            MessageBox.Show($"Process '{enteredUrl}' has been added to the 'Programs' category.", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
+
+            // Clear the input field
+            UrlInputBox.Clear();
+        }
+
+        private void RefreshButton_Click(object sender, RoutedEventArgs e)
+        {
+            var windowedProcesses = ProcessMonitor.GetWindowedProcesses();
+            ItemsPanel2.Children.Clear();
+            foreach (var process in windowedProcesses)
+            {
+                // check if the process is not already in the list
+                if(_data["Programs"].Any(p => p.ProcessName == process.Name.ToLower())) continue;
+
+                var stackPanel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(5, 2, 5, 2) };
+
+                // a button with the tag "+"next to the button write the processName: mainWindowTitle
+                // if a process has been added to the left list (clicked the Add button), delete its entry from the right list
+
+                var button = new Button
+                {
+                    Content = "+",
+                    Width = 30,
+                    Margin = new Thickness(5)
+                };
+
+                var textBlock = new TextBlock
+                {
+                    Text = $"{process.Name}: {process.MainWindowTitle}",
+                    Margin = new Thickness(5)
+                };
+
+                button.Click += (s, args) =>
+                {
+                    var processName = process.Name;
+                    var mainWindowTitle = process.MainWindowTitle;
+                    // Check if the process is already in the list
+                    if (_data.ContainsKey("Programs") && _data["Programs"].Any(p => p.ProcessName == processName))
+                    {
+                        MessageBox.Show($"Process '{processName}' is already added.", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
+                        return;
+                    }
+                    // Add the process to the list
+                    if (!_data.ContainsKey("Programs"))
+                    {
+                        _data["Programs"] = new List<ProcessEntry>();
+                    }
+                    _data["Programs"].Add(new ProcessEntry
+                    {
+                        ProcessName = processName,
+                        MainWindowTitle = mainWindowTitle,
+                        IsDistracting = true
+                    });
+                    // Save changes to the JSON
+                    SaveData();
+                    // Add to UI dynamically
+                    var newStackPanel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(5, 2, 5, 2) };
+                    var newCheckBox = new CheckBox
+                    {
+                        Content = $"{processName}: {mainWindowTitle}",
+                        Margin = new Thickness(5),
+                        IsChecked = true,
+                        Tag = new ProcessEntry { ProcessName = processName, MainWindowTitle = mainWindowTitle, IsDistracting = true }
+                    };
+                    newCheckBox.Checked += CheckBox_CheckedChanged;
+                    newCheckBox.Unchecked += CheckBox_CheckedChanged;
+                    newStackPanel.Children.Add(newCheckBox);
+                    ItemsPanel.Children.Add(newStackPanel);
+                };
+
+                stackPanel.Children.Add(button);
+                stackPanel.Children.Add(textBlock);
+                ItemsPanel2.Children.Add(stackPanel);
+            }
+        }
+
+
+        private void UrlInputBox_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            // Überprüfen, ob die TextBox leer ist
+            if (!string.IsNullOrEmpty(UrlInputBox.Text))
+            {
+                UrlPlaceholder.Visibility = Visibility.Collapsed; // Placeholder ausblenden
+            }
+            else
+            {
+                UrlPlaceholder.Visibility = Visibility.Visible; // Placeholder anzeigen
+            }
+        }
+
+        private void LoadCategoryItems()
+        {
+            try
+            {
+                LoadProgramList();
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show($"Error loading items: {ex.Message}");
+            }
+        }
+
+        public void LoadProgramList()
+        {
+            try
+            {
+                // JSON-Datei lesen
+                string jsonContent = File.ReadAllText(_jsonFilePath);
+
+                // JSON deserialisieren
+                _data = JsonSerializer.Deserialize<Dictionary<string, List<ProcessEntry>>>(jsonContent);
+
+                if (_data != null && _data.ContainsKey("Programs"))
+                {
+                    // Kategorie-Elemente laden
+                    var items = _data["Programs"];
+                    foreach (var item in items)
+                    {
+                        // Checkbox erstellen
+                        var stackPanel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(5, 2, 5, 2) };
+
+                        var checkBox = new CheckBox
+                        {
+                            Content = $"{item.ProcessName}: {item.MainWindowTitle}",
+                            Margin = new Thickness(5),
+                            IsChecked = item.IsDistracting,
+                            Tag = item // Speichert die Referenz zum Item
+                        };
+
+                        checkBox.Checked += CheckBox_CheckedChanged;
+                        checkBox.Unchecked += CheckBox_CheckedChanged;
+
+                        stackPanel.Children.Add(checkBox);
+
+                        // Elemente zur Liste hinzufügen
+                        ItemsPanel.Children.Add(stackPanel);
+                    }
+
+                    // Überschrift setzen
+                    HeaderTextBlock.Text = "Programs";
+                }
+                else
+                {
+                    MessageBox.Show($"No items found for category 'Programs'.");
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show($"Error loading items: {ex.Message}");
+            }
+
+            var processes = ProcessMonitor.GetWindowedProcesses();
+            foreach (var process in processes)
+            {
+                Debug.WriteLine($"Process: {process.Name}, Title: {process.MainWindowTitle}");
+            }
+        }
+
+
+        private void CheckBox_CheckedChanged(object sender, RoutedEventArgs e)
+        {
+            if (sender is CheckBox checkBox && checkBox.Tag is ProcessEntry item)
+            {
+                // Wert in der JSON-Datenstruktur aktualisieren
+                item.IsDistracting = checkBox.IsChecked ?? false;
+
+                // Änderungen in die Datei schreiben
+                SaveData();
+            }
+        }
+
+        private void SaveData()
+        {
+            try
+            {
+                string updatedJson = JsonSerializer.Serialize(_data, new JsonSerializerOptions { WriteIndented = true });
+                File.WriteAllText(_jsonFilePath, updatedJson);
+                MessageBox.Show("Data saved successfully!");
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show($"Error saving data: {ex.Message}");
+            }
+        }
+
+        private void BackButton_Click(object sender, RoutedEventArgs e)
+        {
+            this.NavigationService.Navigate(new Distractions());
+        }
+
+        public class ProcessEntry
+        {
+            [JsonPropertyName("processName")]
+            public required string ProcessName { get; set; }
+
+            [JsonPropertyName("mainWindowTitle")]
+            public required string MainWindowTitle { get; set; }
+
+            [JsonPropertyName("distracting")]
+            public bool IsDistracting { get; set; }
+        }
+    }
+}
\ No newline at end of file
diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/01Overview.xaml.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/01Overview.xaml.cs
index 50efb6f..c19a49b 100644
--- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/01Overview.xaml.cs
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/01Overview.xaml.cs
@@ -125,7 +125,8 @@ namespace InnoLabProjektDektopApp
         // Ereignis-Handler für den "Edit Profile"-Button
         private void EditProfile_Click(object sender, RoutedEventArgs e)
         {
-            MessageBox.Show("Edit Profile clicked!");
+            var distractions = new Distractions();
+            this.NavigationService.Navigate(distractions);
         }
 
         // Ereignis-Handler für den "Add Profile"-Button
diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs
index 7312695..b13ca92 100644
--- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs
@@ -71,6 +71,16 @@ namespace InnoLabProjektDektopApp.Services
             Debug.WriteLine($"Distraction stage: {stage}");
         }
 
+
+        public static List<(string Name, string MainWindowTitle)> GetWindowedProcesses()
+        {
+            var processes = Process.GetProcesses()
+                                   .Where(p => !string.IsNullOrWhiteSpace(p.MainWindowTitle))
+                                   .Select(p => (p.ProcessName, p.MainWindowTitle))
+                                   .ToList();
+            return processes;
+        }
+
         private void HandleNewProcess(ManagementBaseObject e)
         {
             var processName = Path.GetFileNameWithoutExtension((string)((ManagementBaseObject)e["TargetInstance"])["Name"]);
-- 
GitLab


From e3d53ce327291dd4358edf66bdacaee8e75597d8 Mon Sep 17 00:00:00 2001
From: muellerp <Philipp1.Mueller@Student.Reutlingen-University.de>
Date: Wed, 8 Jan 2025 20:11:09 +0100
Subject: [PATCH 2/3] added edit button

---
 .../InnoLabProjektDektopApp.csproj.user       |   6 +
 .../Screens/FirstLaunch/03_2ProgramsList.xaml |  16 +-
 .../FirstLaunch/03_2ProgramsList.xaml.cs      | 187 +++++++++++-------
 .../Services/ProcessMonitor.cs                |   3 +-
 .../Utils/InputDialog.xaml                    |  14 ++
 .../Utils/InputDialog.xaml.cs                 |  33 ++++
 6 files changed, 176 insertions(+), 83 deletions(-)
 create mode 100644 InnoLabProjektDektopApp/InnoLabProjektDektopApp/Utils/InputDialog.xaml
 create mode 100644 InnoLabProjektDektopApp/InnoLabProjektDektopApp/Utils/InputDialog.xaml.cs

diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/InnoLabProjektDektopApp.csproj.user b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/InnoLabProjektDektopApp.csproj.user
index ca4b48d..92b7ce6 100644
--- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/InnoLabProjektDektopApp.csproj.user
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/InnoLabProjektDektopApp.csproj.user
@@ -10,6 +10,9 @@
     <Compile Update="Screens\Templates\HeaderTemplate.xaml.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Update="Utils\InputDialog.xaml.cs">
+      <SubType>Code</SubType>
+    </Compile>
   </ItemGroup>
   <ItemGroup>
     <Page Update="Screens\FirstLaunch\03_2ProgramsList.xaml">
@@ -48,5 +51,8 @@
     <Page Update="Styles\Styles.xaml">
       <SubType>Designer</SubType>
     </Page>
+    <Page Update="Utils\InputDialog.xaml">
+      <SubType>Designer</SubType>
+    </Page>
   </ItemGroup>
 </Project>
\ No newline at end of file
diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml
index 8263e95..25c5982 100644
--- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml
@@ -39,7 +39,7 @@
                 <!-- Überschrift -->
                 <TextBlock Grid.Column="0"
                            Style="{StaticResource Header1}" 
-                           Text="Edit the list of websites and programs for this category" 
+                           Text="Edit the list of distracting programs" 
                            HorizontalAlignment="Left" Margin="0,46,0,-46" />
 
                 <!-- Suchfeld -->
@@ -84,7 +84,7 @@
                 </DockPanel>
             </Grid>
             <TextBlock Style="{StaticResource StandardText}" Margin="0,40,0,0"
-                       Text="By clicking on a toggle, you can change the programs/websites that should be marked as distracting." />
+                       Text="By clicking on a toggle, you can change the programs that should be marked as distracting." />
 
             <Border Background="#2C2C2C" CornerRadius="10" Padding="10" Margin="0,10,0,0">
                 <Grid>
@@ -96,7 +96,7 @@
                     </Grid.ColumnDefinitions>
 
                     <!-- Label -->
-                    <TextBlock Text="Add a distracting website:" 
+                    <TextBlock Text="Add a distracting program:" 
         VerticalAlignment="Center" 
         Foreground="White" 
         FontSize="14" 
@@ -116,7 +116,7 @@
   BorderThickness="1" 
   TextChanged="UrlInputBox_TextChanged" />
                         <TextBlock x:Name="UrlPlaceholder" 
-    Text="Url" 
+    Text="process name" 
     VerticalAlignment="Center" 
     Foreground="Gray" 
     FontSize="14" 
@@ -153,20 +153,20 @@
                                 Style="{StaticResource Header2}" 
                                 Text="CATEGORY" RenderTransformOrigin="0.548,1.689" Margin="10,0,0,0"/>
                 </StackPanel>
-                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,10,0,10" Width="350">
+                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,10,0,10" Width="430">
                     <TextBlock x:Name="HeaderTextBlock2"
                                 Style="{StaticResource Header2}" 
                                 Text="Running Programs" RenderTransformOrigin="0.548,1.689" Margin="0,0,0,0" HorizontalAlignment="Right"/>
-                    <Button Width="110" Margin="70,0,0,0" ToolTip="Refresh" Click="RefreshButton_Click">
+                    <Button Width="110" Margin="150,0,0,0" ToolTip="Refresh" Click="RefreshButton_Click">
                         <TextBlock Text="Click to Refresh"/>
                     </Button>
                 </StackPanel>
             </Grid>
         </StackPanel>
-        <ScrollViewer VerticalScrollBarVisibility="Auto" Margin="20,215,20,8" Width="400px" HorizontalAlignment="Left">
+        <ScrollViewer VerticalScrollBarVisibility="Auto" Margin="20,225,20,8" Width="400px" HorizontalAlignment="Left">
             <StackPanel x:Name="ItemsPanel" />
         </ScrollViewer>
-        <ScrollViewer VerticalScrollBarVisibility="Auto" Margin="20,215,20,8" Width="400px" HorizontalAlignment="Right">
+        <ScrollViewer VerticalScrollBarVisibility="Auto" Margin="20,225,20,8" Width="400px" HorizontalAlignment="Right">
             <StackPanel x:Name="ItemsPanel2" />
         </ScrollViewer>
 
diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml.cs
index 43feefa..0da899c 100644
--- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml.cs
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml.cs
@@ -17,6 +17,7 @@ using InnoLabProjektDektopApp.Services;
 using System.Diagnostics;
 using static InnoLabProjektDektopApp.DistractionsList;
 using System;
+using InnoLabProjektDektopApp.Utils;
 
 
 namespace InnoLabProjektDektopApp
@@ -30,7 +31,8 @@ namespace InnoLabProjektDektopApp
         {
             InitializeComponent();
             _jsonFilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets", "distractingPrograms.json");
-            LoadCategoryItems();
+            LoadProgramList();
+            RefreshRunningProcessList();
         }
 
         private void SearchBox_TextChanged(object sender, TextChangedEventArgs e)
@@ -101,6 +103,14 @@ namespace InnoLabProjektDektopApp
                 _data["Programs"] = new List<ProcessEntry>();
             }
 
+            // Check if the process is already in the list
+            if (_data["Programs"].Any(p => p.ProcessName.Equals(enteredUrl, StringComparison.CurrentCultureIgnoreCase)))
+            {
+                MessageBox.Show($"Process '{enteredUrl}' is already added.", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
+                UrlInputBox.Clear();
+                return;
+            }
+
             _data["Programs"].Add(new ProcessEntry
             {
                 ProcessName = enteredUrl,
@@ -128,26 +138,29 @@ namespace InnoLabProjektDektopApp
             stackPanel.Children.Add(checkBox);
             ItemsPanel.Children.Add(stackPanel);
 
-            MessageBox.Show($"Process '{enteredUrl}' has been added to the 'Programs' category.", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
-
             // Clear the input field
             UrlInputBox.Clear();
+
+            // Refresh Panel to exclude duplicates
+            RefreshRunningProcessList();
         }
 
         private void RefreshButton_Click(object sender, RoutedEventArgs e)
+        {
+            RefreshRunningProcessList();
+        }
+
+        private void RefreshRunningProcessList()
         {
             var windowedProcesses = ProcessMonitor.GetWindowedProcesses();
             ItemsPanel2.Children.Clear();
             foreach (var process in windowedProcesses)
             {
                 // check if the process is not already in the list
-                if(_data["Programs"].Any(p => p.ProcessName == process.Name.ToLower())) continue;
+                if (_data["Programs"].Any(p => p.ProcessName.Equals(process.Name, StringComparison.CurrentCultureIgnoreCase))) continue;
 
                 var stackPanel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(5, 2, 5, 2) };
 
-                // a button with the tag "+"next to the button write the processName: mainWindowTitle
-                // if a process has been added to the left list (clicked the Add button), delete its entry from the right list
-
                 var button = new Button
                 {
                     Content = "+",
@@ -157,46 +170,14 @@ namespace InnoLabProjektDektopApp
 
                 var textBlock = new TextBlock
                 {
-                    Text = $"{process.Name}: {process.MainWindowTitle}",
-                    Margin = new Thickness(5)
+                    Text = $"{process.MainWindowTitle} ({process.Name})",
+                    Margin = new Thickness(5),
+                    ToolTip = $"{process.MainWindowTitle} ({process.Name})"
                 };
 
                 button.Click += (s, args) =>
                 {
-                    var processName = process.Name;
-                    var mainWindowTitle = process.MainWindowTitle;
-                    // Check if the process is already in the list
-                    if (_data.ContainsKey("Programs") && _data["Programs"].Any(p => p.ProcessName == processName))
-                    {
-                        MessageBox.Show($"Process '{processName}' is already added.", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
-                        return;
-                    }
-                    // Add the process to the list
-                    if (!_data.ContainsKey("Programs"))
-                    {
-                        _data["Programs"] = new List<ProcessEntry>();
-                    }
-                    _data["Programs"].Add(new ProcessEntry
-                    {
-                        ProcessName = processName,
-                        MainWindowTitle = mainWindowTitle,
-                        IsDistracting = true
-                    });
-                    // Save changes to the JSON
-                    SaveData();
-                    // Add to UI dynamically
-                    var newStackPanel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(5, 2, 5, 2) };
-                    var newCheckBox = new CheckBox
-                    {
-                        Content = $"{processName}: {mainWindowTitle}",
-                        Margin = new Thickness(5),
-                        IsChecked = true,
-                        Tag = new ProcessEntry { ProcessName = processName, MainWindowTitle = mainWindowTitle, IsDistracting = true }
-                    };
-                    newCheckBox.Checked += CheckBox_CheckedChanged;
-                    newCheckBox.Unchecked += CheckBox_CheckedChanged;
-                    newStackPanel.Children.Add(newCheckBox);
-                    ItemsPanel.Children.Add(newStackPanel);
+                    AddProcessFromList(process.Name, process.MainWindowTitle);
                 };
 
                 stackPanel.Children.Add(button);
@@ -205,6 +186,84 @@ namespace InnoLabProjektDektopApp
             }
         }
 
+        private void AddProcessFromList(string processName, string mainWindowTitle)
+        {
+            // Check if the process is already in the list
+            if (_data.TryGetValue("Programs", out List<ProcessEntry>? value) && value.Any(p => p.ProcessName.Equals(processName, StringComparison.CurrentCultureIgnoreCase)))
+            {
+                MessageBox.Show($"Process '{processName}' is already added.", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+
+            //show a message box to give the user the option to change the main window title
+            var inputDialog = new InputDialog("Enter a new Title:", mainWindowTitle); // Assuming InputDialog is a custom dialog
+            if (inputDialog.ShowDialog() == true)
+            {
+                mainWindowTitle = inputDialog.Input; // Get updated title
+            }
+
+            if (inputDialog.DialogResult == false) return;
+
+
+            // Add the process to the list
+            if (!_data.ContainsKey("Programs"))
+            {
+                _data["Programs"] = [];
+            }
+            _data["Programs"].Add(new ProcessEntry
+            {
+                ProcessName = processName,
+                MainWindowTitle = mainWindowTitle,
+                IsDistracting = true
+            });
+
+            ShowNewItemInList(processName, mainWindowTitle, true);
+            RefreshRunningProcessList();
+
+            // Save changes to the JSON
+            SaveData();
+        }
+
+        private void ShowNewItemInList(string processName, string mainWindowTitle, bool isDistracting)
+        {
+            // Add to UI dynamically
+            var newStackPanel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(5, 2, 5, 2) };
+            var newCheckBox = new CheckBox
+            {
+                Content = $"{mainWindowTitle} ({processName})",
+                Margin = new Thickness(5),
+                IsChecked = true,
+                ToolTip = $"{mainWindowTitle} ({processName})",
+                Tag = new ProcessEntry { ProcessName = processName, MainWindowTitle = mainWindowTitle, IsDistracting = true }
+            };
+            newCheckBox.Checked += CheckBox_CheckedChanged;
+            newCheckBox.Unchecked += CheckBox_CheckedChanged;
+
+            var editButton = new Button
+            {
+                Content = "Edit",
+                Margin = new Thickness(5, 0, 0, 0),
+                Tag = newCheckBox // Store reference to checkbox for easier editing
+            };
+            editButton.Click += (s, e) => EditItemInList(processName, mainWindowTitle);
+
+            newStackPanel.Children.Add(newCheckBox);
+            newStackPanel.Children.Add(editButton);
+            ItemsPanel.Children.Add(newStackPanel);
+        }
+
+        private void EditItemInList(string processName, string mainWindowTitle)
+        {
+            var inputDialog = new InputDialog("Enter a new Title:", mainWindowTitle);
+            inputDialog.ShowDialog();
+            if (inputDialog.DialogResult == false || inputDialog.Input.Length == 0) return;
+
+            _data["Programs"].FirstOrDefault(p => p.ProcessName.Equals(processName, StringComparison.CurrentCultureIgnoreCase))!.MainWindowTitle = inputDialog.Input;
+
+            SaveData();
+            RefreshProgramList();
+        }
+
 
         private void UrlInputBox_TextChanged(object sender, TextChangedEventArgs e)
         {
@@ -219,16 +278,19 @@ namespace InnoLabProjektDektopApp
             }
         }
 
-        private void LoadCategoryItems()
+        public void RefreshProgramList()
         {
-            try
-            {
-                LoadProgramList();
-            }
-            catch (Exception ex)
+            ItemsPanel.Children.Clear();
+
+            // Kategorie-Elemente laden
+            var items = _data["Programs"];
+            foreach (var item in items)
             {
-                MessageBox.Show($"Error loading items: {ex.Message}");
+                ShowNewItemInList(item.ProcessName, item.MainWindowTitle, item.IsDistracting);
             }
+
+            // Überschrift setzen
+            HeaderTextBlock.Text = "Programs";
         }
 
         public void LoadProgramList()
@@ -247,24 +309,7 @@ namespace InnoLabProjektDektopApp
                     var items = _data["Programs"];
                     foreach (var item in items)
                     {
-                        // Checkbox erstellen
-                        var stackPanel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(5, 2, 5, 2) };
-
-                        var checkBox = new CheckBox
-                        {
-                            Content = $"{item.ProcessName}: {item.MainWindowTitle}",
-                            Margin = new Thickness(5),
-                            IsChecked = item.IsDistracting,
-                            Tag = item // Speichert die Referenz zum Item
-                        };
-
-                        checkBox.Checked += CheckBox_CheckedChanged;
-                        checkBox.Unchecked += CheckBox_CheckedChanged;
-
-                        stackPanel.Children.Add(checkBox);
-
-                        // Elemente zur Liste hinzufügen
-                        ItemsPanel.Children.Add(stackPanel);
+                        ShowNewItemInList(item.ProcessName, item.MainWindowTitle, item.IsDistracting);
                     }
 
                     // Überschrift setzen
@@ -279,12 +324,6 @@ namespace InnoLabProjektDektopApp
             {
                 MessageBox.Show($"Error loading items: {ex.Message}");
             }
-
-            var processes = ProcessMonitor.GetWindowedProcesses();
-            foreach (var process in processes)
-            {
-                Debug.WriteLine($"Process: {process.Name}, Title: {process.MainWindowTitle}");
-            }
         }
 
 
diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs
index b13ca92..026c355 100644
--- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs
@@ -25,7 +25,7 @@ namespace InnoLabProjektDektopApp.Services
         public ProcessMonitor()
         {
             blockedProcesses = LoadBlockedProcesses();
-
+            
         }
 
         public async void StartMonitoring()
@@ -76,6 +76,7 @@ namespace InnoLabProjektDektopApp.Services
         {
             var processes = Process.GetProcesses()
                                    .Where(p => !string.IsNullOrWhiteSpace(p.MainWindowTitle))
+                                   .Where(p => p.ProcessName.ToLower() != "coflow")
                                    .Select(p => (p.ProcessName, p.MainWindowTitle))
                                    .ToList();
             return processes;
diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Utils/InputDialog.xaml b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Utils/InputDialog.xaml
new file mode 100644
index 0000000..c479217
--- /dev/null
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Utils/InputDialog.xaml
@@ -0,0 +1,14 @@
+<Window x:Class="InnoLabProjektDektopApp.Utils.InputDialog"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        Title="Input Dialog" Height="150" Width="300" WindowStartupLocation="CenterOwner">
+    <StackPanel Margin="10">
+        <TextBlock x:Name="PromptText" Text="Enter your input:" Margin="0,0,0,10" TextWrapping="Wrap"/>
+        <TextBox x:Name="InputTextBox" Margin="0,0,0,10"/>
+        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
+            <Button Content="OK" Click="OK_Click" Width="75" Margin="0,0,10,0" IsDefault="True"/>
+            <Button Content="Cancel" Click="Cancel_Click" Width="75" IsCancel="True"/>
+        </StackPanel>
+    </StackPanel>
+</Window>
+
diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Utils/InputDialog.xaml.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Utils/InputDialog.xaml.cs
new file mode 100644
index 0000000..a335da0
--- /dev/null
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Utils/InputDialog.xaml.cs
@@ -0,0 +1,33 @@
+using System.Windows;
+
+namespace InnoLabProjektDektopApp.Utils
+{
+    /// <summary>
+    /// Interaction logic for InputDialog.xaml
+    /// </summary>
+    public partial class InputDialog : Window
+    {
+        public string Input { get; private set; }
+
+        public InputDialog(string prompt, string defaultValue = "")
+        {
+            InitializeComponent();
+            PromptText.Text = prompt; // Ensure XAML has a TextBlock named PromptText
+            InputTextBox.Text = defaultValue; // Ensure XAML has a TextBox named InputTextBox
+            InputTextBox.Focus();
+        }
+
+        private void OK_Click(object sender, RoutedEventArgs e)
+        {
+            Input = InputTextBox.Text;
+            DialogResult = true; // Sets DialogResult and allows the window to close
+            Close();
+        }
+
+        private void Cancel_Click(object sender, RoutedEventArgs e)
+        {
+            DialogResult = false; // Indicates cancellation
+            Close();
+        }
+    }
+}
-- 
GitLab


From 4629541788c0318b5ec18c69ccac30c0efe75f34 Mon Sep 17 00:00:00 2001
From: muellerp <Philipp1.Mueller@Student.Reutlingen-University.de>
Date: Wed, 15 Jan 2025 17:07:13 +0100
Subject: [PATCH 3/3] fixed search in programs list

---
 .../FirstLaunch/03_2ProgramsList.xaml.cs      | 25 +++++--------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml.cs
index 0da899c..c323f92 100644
--- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml.cs
+++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/FirstLaunch/03_2ProgramsList.xaml.cs
@@ -64,23 +64,7 @@ namespace InnoLabProjektDektopApp
                 foreach (var item in filteredItems)
                 {
                     // Create a StackPanel for each filtered item
-                    var stackPanel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(5, 2, 5, 2) };
-
-                    var checkBox = new CheckBox
-                    {
-                        Content = $"{item.ProcessName}: {item.MainWindowTitle}",
-                        Margin = new Thickness(5),
-                        IsChecked = item.IsDistracting,
-                        Tag = item
-                    };
-
-                    checkBox.Checked += CheckBox_CheckedChanged;
-                    checkBox.Unchecked += CheckBox_CheckedChanged;
-
-                    stackPanel.Children.Add(checkBox);
-
-                    // Add the filtered StackPanel to ItemsPanel
-                    ItemsPanel.Children.Add(stackPanel);
+                    ShowNewItemInList(item.ProcessName, item.MainWindowTitle, item.IsDistracting);
                 }
             }
         }
@@ -232,9 +216,9 @@ namespace InnoLabProjektDektopApp
             {
                 Content = $"{mainWindowTitle} ({processName})",
                 Margin = new Thickness(5),
-                IsChecked = true,
+                IsChecked = isDistracting,
                 ToolTip = $"{mainWindowTitle} ({processName})",
-                Tag = new ProcessEntry { ProcessName = processName, MainWindowTitle = mainWindowTitle, IsDistracting = true }
+                Tag = new ProcessEntry { ProcessName = processName, MainWindowTitle = mainWindowTitle, IsDistracting = isDistracting }
             };
             newCheckBox.Checked += CheckBox_CheckedChanged;
             newCheckBox.Unchecked += CheckBox_CheckedChanged;
@@ -334,6 +318,9 @@ namespace InnoLabProjektDektopApp
                 // Wert in der JSON-Datenstruktur aktualisieren
                 item.IsDistracting = checkBox.IsChecked ?? false;
 
+                // Write the value into the _data dictionary
+                _data["Programs"].FirstOrDefault(p => p.ProcessName.Equals(item.ProcessName, StringComparison.CurrentCultureIgnoreCase))!.IsDistracting = item.IsDistracting;
+
                 // Änderungen in die Datei schreiben
                 SaveData();
             }
-- 
GitLab