Files
DeskCore/MainWindow.Pages.cs
T
2026-10-03 19:51:56 +00:00

135 lines
5.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace DeskCore;
/// <summary>Einstellungen für Desktop-Seiten, das Aufziehen neuer Boxen und die Tönung der Desktop-Icons.</summary>
public partial class MainWindow
{
public record PageRow(int Index, string Name, string Info, Brush Dot);
private bool _loadingDesktopSettings;
private void LoadDesktopSettings()
{
_loadingDesktopSettings = true;
DrawFencesToggle.IsChecked = S.DrawFences;
PageWheelBox.IsChecked = S.PageWheel;
PageWheelBox.IsEnabled = S.Pages.Count > 1;
var res = Application.Current.Resources;
PageList.ItemsSource = S.Pages.Select((name, i) =>
{
int boxes = S.Fences.Count(f => f.Page == i);
var info = (boxes == 1 ? "1 Box" : $"{boxes} Boxen") + (i == S.CurrentPage ? " · wird gerade angezeigt" : "");
return new PageRow(i, name, info, (Brush)res[i == S.CurrentPage ? "AccentBrush" : "ControlStrongStrokeBrush"]);
}).ToList();
DesktopTintSwatches.Children.Clear();
void AddSwatch(string? hex, Brush brush, string tip)
{
var rb = new RadioButton
{
Style = (Style)res["SwatchRadio"], GroupName = "desktoptint", Background = brush, ToolTip = tip,
IsChecked = S.DesktopTint == hex,
};
rb.Checked += (_, _) =>
{
if (_loadingDesktopSettings) return;
S.DesktopTint = hex;
S.Save();
DesktopTintStrength.IsEnabled = hex is not null;
DesktopIcons.RefreshCache();
DesktopTint.Refresh(force: true);
};
DesktopTintSwatches.Children.Add(rb);
}
AddSwatch(null, Brushes.Transparent, "Keine Tönung");
foreach (var (name, hex) in CategoryColors.All.Concat([("Grau", "#8A8A8A"), ("Weiß", "#F5F5F5")]))
AddSwatch(hex, CategoryColors.Brush(hex)!, name);
DesktopTintStrength.Value = Math.Round(S.DesktopTintStrength * 100);
DesktopTintStrength.IsEnabled = S.DesktopTint is not null;
_loadingDesktopSettings = false;
}
private void DrawFencesToggle_Click(object sender, RoutedEventArgs e)
{
S.DrawFences = DrawFencesToggle.IsChecked == true;
S.Save();
DesktopToggle.Apply();
}
private void PageWheel_Click(object sender, RoutedEventArgs e)
{
S.PageWheel = PageWheelBox.IsChecked == true;
S.Save();
DesktopToggle.Apply();
}
private void DesktopTintStrength_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (_loadingDesktopSettings || !IsLoaded) return;
S.DesktopTintStrength = DesktopTintStrength.Value / 100;
S.Save();
DesktopTint.Refresh(force: true);
}
// ---------- Seiten ----------
private static string? ValidatePageName(string t, int except) =>
t.Trim().Length == 0 ? "Bitte einen Namen eingeben."
: S.Pages.Where((_, i) => i != except).Any(p => string.Equals(p, t.Trim(), StringComparison.OrdinalIgnoreCase))
? "Diesen Namen gibt es schon." : null;
private void AddPage_Click(object sender, RoutedEventArgs e)
{
var name = Dialog.Prompt(this, "Neue Desktop-Seite", "Name der Seite (z. B. „Arbeit“ oder „Freizeit“):",
$"Seite {S.Pages.Count + 1}", "Hinzufügen", t => ValidatePageName(t, -1));
if (name is null) return;
S.Pages.Add(name.Trim());
S.Save();
DesktopToggle.Apply();
LoadDesktopSettings();
ShowToast($"Seite „{name.Trim()}“ hinzugefügt",
"Mit „Anzeigen“ wechselst du hin – neue Boxen landen immer auf der gerade angezeigten Seite.");
}
private void ShowPage_Click(object sender, RoutedEventArgs e)
{
if ((sender as FrameworkElement)?.Tag is int i) FenceManager.SwitchPage(i);
LoadDesktopSettings();
}
private void RenamePage_Click(object sender, RoutedEventArgs e)
{
if ((sender as FrameworkElement)?.Tag is not int i || i >= S.Pages.Count) return;
var name = Dialog.Prompt(this, "Seite umbenennen", "Neuer Name:", S.Pages[i], "Umbenennen", t => ValidatePageName(t, i));
if (name is null) return;
S.Pages[i] = name.Trim();
S.Save();
LoadDesktopSettings();
}
private void DeletePage_Click(object sender, RoutedEventArgs e)
{
if ((sender as FrameworkElement)?.Tag is not int i || i >= S.Pages.Count) return;
if (S.Pages.Count < 2)
{
ShowToast("Die letzte Seite kann nicht gelöscht werden", "", info: true);
return;
}
var name = S.Pages[i];
int boxes = S.Fences.Count(f => f.Page == i);
if (boxes > 0 && !Dialog.Confirm(this, "Seite löschen",
$"Auf „{name}“ liegen {boxes} Box(en). Sie wandern auf die Seite „{S.Pages[i == 0 ? 1 : i - 1]}“.",
"Löschen"))
return;
FenceManager.DeletePage(i);
DesktopToggle.Apply();
Refresh();
LoadDesktopSettings();
ShowToast($"Seite „{name}“ gelöscht", "");
}
}