Repository navigation
Expand file tree
/
Copy pathAppStackSettingsDialog.cs
More file actions
413 lines (394 loc) · 21.2 KB
/
Copy pathAppStackSettingsDialog.cs
File metadata and controls
413 lines (394 loc) · 21.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
using System.Drawing.Drawing2D;
sealed class StackSettingsDialog : Form
{
readonly AppStackConfig draft;
readonly FlowLayoutPanel cards;
readonly StackPreview preview;
readonly Button add;
readonly Button save;
readonly Label status;
readonly CheckBox enabledToggle;
public AppStackConfig Config { get; private set; }
public StackSettingsDialog(AppStackConfig current)
{
draft = (current ?? new AppStackConfig()).Copy();
Config = draft.Copy();
Text = Localization.T("winBar · App stacks", "winBar · App-Stapel");
Font = new Font("Segoe UI", 10);
AutoScaleMode = AutoScaleMode.Dpi;
ClientSize = new Size(720, 680);
MinimumSize = new Size(620, 580);
StartPosition = FormStartPosition.CenterParent;
BackColor = Color.FromArgb(242, 246, 251);
var layout = new TableLayoutPanel { Dock = DockStyle.Fill, ColumnCount = 1, RowCount = 4, Margin = Padding.Empty };
layout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
layout.RowStyles.Add(new RowStyle(SizeType.Absolute, 188));
layout.RowStyles.Add(new RowStyle(SizeType.Absolute, 156));
layout.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
layout.RowStyles.Add(new RowStyle(SizeType.Absolute, 74));
Controls.Add(layout);
var hero = new Panel { Dock = DockStyle.Fill, BackColor = Color.FromArgb(22, 34, 53) };
layout.Controls.Add(hero, 0, 0);
hero.Controls.Add(new Label
{
Text = Localization.T("App stacks", "App-Stapel"), Font = new Font("Segoe UI Semibold", 22, FontStyle.Bold),
ForeColor = Color.White, Location = new Point(26, 14), Size = new Size(420, 54)
});
hero.Controls.Add(new Label
{
Text = Localization.T("More apps. Fewer icons.", "Mehr Apps. Weniger Symbole."), Font = new Font("Segoe UI", 10),
ForeColor = Color.FromArgb(170, 194, 227), AutoSize = true, Location = new Point(29, 64)
});
preview = new StackPreview(draft) { Location = new Point(26, 105), Size = new Size(650, 56), Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top };
hero.Controls.Add(preview);
hero.Resize += (_, _) => preview.Width = Math.Max(400, hero.ClientSize.Width - 52);
var options = new Panel { Dock = DockStyle.Fill, BackColor = Color.FromArgb(242, 246, 251) };
layout.Controls.Add(options, 0, 1);
enabledToggle = new CheckBox { Text = Localization.T("Use app stacks", "App-Stapel verwenden"), Checked = draft.Enabled, AutoSize = true, Location = new Point(25, 14) };
enabledToggle.CheckedChanged += (_, _) => { draft.Enabled = enabledToggle.Checked; preview.Invalidate(); ValidateDraft(); };
options.Controls.Add(enabledToggle);
var auto = new CheckBox { Text = Localization.T("Compact when the taskbar fills up", "Bei voller Taskleiste kompakt"), Checked = draft.AutoCompact, AutoSize = true, Location = new Point(25, 47) };
options.Controls.Add(auto);
var thresholdLabel = new Label { Text = Localization.T("At", "Ab"), AutoSize = true, Location = new Point(368, 49) };
options.Controls.Add(thresholdLabel);
var threshold = new NumericUpDown
{
Minimum = 45, Maximum = 95, Increment = 5, Value = Math.Clamp(draft.CompactAtPercent, 45, 95),
Location = new Point(400, 45), Width = 70, Enabled = draft.AutoCompact
};
options.Controls.Add(threshold);
options.Controls.Add(new Label { Text = "%", AutoSize = true, Location = new Point(477, 49) });
auto.CheckedChanged += (_, _) => { draft.AutoCompact = auto.Checked; threshold.Enabled = auto.Checked; };
threshold.ValueChanged += (_, _) => draft.CompactAtPercent = (int)threshold.Value;
options.Controls.Add(new Label
{
Text = Localization.T("Drag one taskbar icon onto another to make a folder, or select apps below.\nOpen each folder on hover or click; Alt shows its taskbar buttons.",
"Ziehe ein Taskbar-Icon auf ein anderes oder wähle unten Apps aus.\nWähle pro Ordner Hover oder Klick; Alt zeigt seine Taskbar-Buttons."),
ForeColor = Color.FromArgb(80, 97, 122), Location = new Point(28, 76), Size = new Size(650, 72),
Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top
});
cards = new FlowLayoutPanel
{
Dock = DockStyle.Fill, AutoScroll = true, FlowDirection = FlowDirection.TopDown,
WrapContents = false, Padding = new Padding(21, 10, 21, 12), BackColor = Color.FromArgb(242, 246, 251)
};
cards.Resize += (_, _) => ResizeCards();
layout.Controls.Add(cards, 0, 2);
var footer = new Panel { Dock = DockStyle.Fill, BackColor = Color.FromArgb(248, 250, 253) };
layout.Controls.Add(footer, 0, 3);
add = new ModernButton { Text = Localization.T("+ Stack", "+ Stapel"), Location = new Point(24, 17), Size = new Size(104, 36), FlatStyle = FlatStyle.Flat };
add.FlatAppearance.BorderColor = Color.FromArgb(171, 190, 218);
add.Click += (_, _) => AddGroup();
footer.Controls.Add(add);
status = new Label { ForeColor = Color.FromArgb(82, 98, 120), Location = new Point(139, 15), Size = new Size(280, 44), Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top };
footer.Controls.Add(status);
var cancel = new ModernButton { Text = Localization.T("Cancel", "Abbrechen"), Size = new Size(98, 36), Anchor = AnchorStyles.Top | AnchorStyles.Right, FlatStyle = FlatStyle.Flat };
cancel.FlatAppearance.BorderSize = 0;
cancel.Click += (_, _) => { DialogResult = DialogResult.Cancel; Close(); };
footer.Controls.Add(cancel);
save = new ModernButton
{
Text = Localization.T("Save", "Speichern"), Size = new Size(105, 36), Anchor = AnchorStyles.Top | AnchorStyles.Right,
BackColor = Color.FromArgb(50, 95, 164), ForeColor = Color.White, FlatStyle = FlatStyle.Flat
};
save.FlatAppearance.BorderSize = 0;
save.Click += (_, _) =>
{
if (!draft.IsValid(out _)) return;
Config = draft.Copy();
DialogResult = DialogResult.OK;
Close();
};
footer.Controls.Add(save);
void ArrangeFooter()
{
save.Left = footer.ClientSize.Width - save.Width - 24;
cancel.Left = save.Left - cancel.Width - 8;
status.Width = Math.Max(100, cancel.Left - status.Left - 12);
save.Top = cancel.Top = add.Top = 17;
}
footer.Resize += (_, _) => ArrangeFooter();
Shown += (_, _) => ArrangeFooter();
AcceptButton = save;
CancelButton = cancel;
RenderCards();
}
void AddGroup()
{
if (draft.Groups.Count >= 4) return;
using var picker = new RunningAppPickerDialog([]);
if (picker.ShowDialog(this) != DialogResult.OK) return;
enabledToggle.Checked = true;
var members = picker.SelectedMembers;
draft.Groups.Add(new AppStackGroup
{
Name = $"{Localization.T("Stack", "Stapel")} {draft.Groups.Count + 1}",
ContentMode = 2,
Members = members,
LaunchPaths = members.Select(member => member.LaunchPath).OfType<string>()
.Distinct(StringComparer.OrdinalIgnoreCase).ToList()
});
RenderCards();
}
void RenderCards()
{
cards.SuspendLayout();
try
{
cards.Controls.Clear();
for (int i = 0; i < draft.Groups.Count; i++) cards.Controls.Add(CreateCard(draft.Groups[i], i));
ResizeCards();
}
finally { cards.ResumeLayout(); }
preview.Invalidate();
ValidateDraft();
}
void ResizeCards()
{
int width = Math.Max(500, cards.ClientSize.Width - cards.Padding.Horizontal - 23);
foreach (Control card in cards.Controls) card.Width = width;
}
Control CreateCard(AppStackGroup group, int index)
{
var card = new StackCard { Height = 388, Width = Math.Max(500, cards.ClientSize.Width - 65), Margin = new Padding(0, 0, 0, 11) };
card.Controls.Add(new Label
{
Text = $"{Localization.T("Stack", "Stapel")} {index + 1}", Font = new Font("Segoe UI Semibold", 11, FontStyle.Bold),
ForeColor = Color.FromArgb(34, 51, 77), AutoSize = true, Location = new Point(16, 11)
});
var active = new CheckBox { Text = Localization.T("Active", "Aktiv"), Checked = group.Enabled, AutoSize = true, Location = new Point(250, 13) };
active.CheckedChanged += (_, _) => { group.Enabled = active.Checked; preview.Invalidate(); ValidateDraft(); };
card.Controls.Add(active);
var remove = new ModernButton { Text = "×", AccessibleName = Localization.T("Delete stack", "Stapel löschen"), Size = new Size(36, 29), FlatStyle = FlatStyle.Flat, Anchor = AnchorStyles.Right | AnchorStyles.Top };
remove.FlatAppearance.BorderSize = 0;
remove.Location = new Point(card.Width - remove.Width - 10, 9);
remove.Click += (_, _) => { draft.Groups.Remove(group); RenderCards(); };
card.Controls.Add(remove);
card.Controls.Add(Caption("Name", 18, 43));
card.Controls.Add(Caption(Localization.T("Apps in stack", "Apps im Stapel"), 247, 43));
var name = new TextBox { Text = group.Name, Location = new Point(18, 65), Width = 210 };
name.TextChanged += (_, _) => { group.Name = name.Text; preview.Invalidate(); ValidateDraft(); };
card.Controls.Add(name);
group.Members ??= [];
group.LaunchPaths ??= [];
var paths = new Label { ForeColor = Color.FromArgb(70, 92, 122), Location = new Point(247, 65), Width = 280, Height = 30,
AutoEllipsis = true };
void UpdatePaths()
{
if (group.Members.Count >= 2)
paths.Text = string.Join(" · ", group.Members.Select(member => member.Name));
else
paths.Text = Localization.T($"Legacy pinned positions {group.Start}–{group.Start + group.Count - 1}",
$"Bisherige Pin-Positionen {group.Start}–{group.Start + group.Count - 1}");
}
UpdatePaths();
card.Controls.Add(paths);
ModernButton? reorder = null;
var choose = new ModernButton { Text = Localization.T("Choose apps…", "Apps wählen…"), Location = new Point(18, 105), Size = new Size(190, 34), FlatStyle = FlatStyle.Flat };
choose.FlatAppearance.BorderColor = Color.FromArgb(167, 190, 221);
choose.Click += (_, _) =>
{
using var picker = new RunningAppPickerDialog(group.Members);
if (picker.ShowDialog(this) != DialogResult.OK) return;
group.Members = picker.SelectedMembers;
group.LaunchPaths = group.Members.Select(member => member.LaunchPath).OfType<string>()
.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
UpdatePaths();
if (reorder != null) reorder.Enabled = group.Members.Count >= 2;
preview.Invalidate();
ValidateDraft();
};
card.Controls.Add(choose);
var colorButton = new ModernButton
{
Text = Localization.T("Folder color…", "Ordnerfarbe…"),
Location = new Point(247, 105), Size = new Size(155, 34), FlatStyle = FlatStyle.Flat
};
void RefreshColor()
{
colorButton.BackColor = group.FolderColor is int rgb ? Color.FromArgb(rgb) : Color.FromArgb(67, 94, 132);
colorButton.ForeColor = Color.White;
}
colorButton.Click += (_, _) =>
{
using var picker = new ColorDialog { FullOpen = true, Color = group.FolderColor is int rgb ? Color.FromArgb(rgb) : Color.FromArgb(67, 94, 132) };
if (picker.ShowDialog(this) != DialogResult.OK) return;
group.FolderColor = Color.FromArgb(255, picker.Color).ToArgb();
RefreshColor(); preview.Invalidate();
};
RefreshColor();
card.Controls.Add(colorButton);
var automaticColor = new ModernButton
{
Text = Localization.T("Auto", "Auto"), Location = new Point(410, 105), Size = new Size(70, 34), FlatStyle = FlatStyle.Flat
};
automaticColor.Click += (_, _) => { group.FolderColor = null; RefreshColor(); preview.Invalidate(); };
card.Controls.Add(automaticColor);
card.Controls.Add(Caption(Localization.T("Folder contents", "Ordnerinhalt"), 18, 147));
var contentMode = new ComboBox
{
DropDownStyle = ComboBoxStyle.DropDownList, Location = new Point(18, 166), Width = 210
};
contentMode.Items.AddRange([
Localization.T("Favorites", "Favoriten"),
Localization.T("Running only", "Nur laufende"),
Localization.T("Running first", "Laufende zuerst")
]);
contentMode.SelectedIndex = Math.Clamp(group.ContentMode, 0, 2);
contentMode.SelectedIndexChanged += (_, _) => group.ContentMode = contentMode.SelectedIndex;
card.Controls.Add(contentMode);
card.Controls.Add(new Label
{
Text = Localization.T("Running only shows open apps.",
"Nur laufende zeigt offene Apps."),
ForeColor = Color.FromArgb(107, 122, 142), Location = new Point(247, 169), Size = new Size(290, 42)
});
card.Controls.Add(Caption(Localization.T("Folder shortcut", "Ordnerkürzel"), 247, 215));
var shortcut = new ComboBox { DropDownStyle = ComboBoxStyle.DropDownList,
Location = new Point(247, 237), Width = 190 };
shortcut.Items.Add(Localization.T("Off", "Aus"));
for (int function = 1; function <= 12; function++)
shortcut.Items.Add(Localization.T($"Ctrl + Alt + F{function}", $"Strg + Alt + F{function}"));
shortcut.SelectedIndex = Math.Clamp(group.ShortcutFunctionKey, 0, 12);
shortcut.SelectedIndexChanged += (_, _) => { group.ShortcutFunctionKey = shortcut.SelectedIndex; ValidateDraft(); };
card.Controls.Add(shortcut);
reorder = new ModernButton { Text = Localization.T("Reorder apps…", "Apps sortieren…"),
Location = new Point(18, 237), Size = new Size(190, 31), FlatStyle = FlatStyle.Flat,
Enabled = group.Members.Count >= 2 };
reorder.Click += (_, _) =>
{
using var dialog = new StackMemberOrderDialog(group.Members);
if (dialog.ShowDialog(this) != DialogResult.OK) return;
group.Members = dialog.OrderedMembers;
UpdatePaths(); preview.Invalidate();
};
card.Controls.Add(reorder);
card.Controls.Add(Caption(Localization.T("App tile click", "Klick auf App-Kachel"), 18, 277));
var appClick = new ComboBox
{
DropDownStyle = ComboBoxStyle.DropDownList, Location = new Point(18, 298), Width = 210
};
appClick.Items.AddRange([
Localization.T("Recent window", "Letztes Fenster"),
Localization.T("Window overview", "Fensterübersicht")
]);
appClick.SelectedIndex = Math.Clamp(group.AppClickMode, 0, 1);
appClick.SelectedIndexChanged += (_, _) => group.AppClickMode = appClick.SelectedIndex;
card.Controls.Add(appClick);
card.Controls.Add(new Label
{
Text = Localization.T("Closed apps launch as usual.",
"Geschlossene Apps starten normal."),
ForeColor = Color.FromArgb(107, 122, 142), Location = new Point(247, 301), Size = new Size(290, 21)
});
card.Controls.Add(Caption(Localization.T("Running app mark", "Markierung laufender Apps"), 247, 322));
var runningMark = new ComboBox
{
DropDownStyle = ComboBoxStyle.DropDownList, Location = new Point(247, 343), Width = 190
};
runningMark.Items.AddRange([
Localization.T("● Dot", "● Punkt"),
Localization.T("▬ Pill", "▬ Kapsel"),
Localization.T("◯ Halo", "◯ Ring"),
Localization.T("No mark", "Keine Markierung")
]);
runningMark.SelectedIndex = Math.Clamp(group.RunningMarkStyle, 0, 3);
runningMark.SelectedIndexChanged += (_, _) => group.RunningMarkStyle = runningMark.SelectedIndex;
card.Controls.Add(runningMark);
var openOnClick = new CheckBox
{
Text = Localization.T("Open this folder on click", "Diesen Ordner per Klick öffnen"),
Checked = group.OpenOnClick, AutoSize = true, Location = new Point(18, 348)
};
openOnClick.CheckedChanged += (_, _) => group.OpenOnClick = openOnClick.Checked;
card.Controls.Add(openOnClick);
card.Resize += (_, _) => remove.Left = card.Width - remove.Width - 10;
return card;
}
static Label Caption(string text, int x, int y) => new()
{
Text = text, AutoSize = true, Location = new Point(x, y),
ForeColor = Color.FromArgb(96, 111, 135), Font = new Font("Segoe UI", 8.5f)
};
void ValidateDraft()
{
bool valid = draft.IsValid(out var reason);
save.Enabled = valid;
status.Text = valid ? Localization.T($"{draft.Groups.Count} of 4 stacks", $"{draft.Groups.Count} von 4 Stapeln") : reason;
status.ForeColor = valid ? Color.FromArgb(82, 98, 120) : Color.FromArgb(176, 57, 70);
add.Enabled = draft.Groups.Count < 4;
}
sealed class StackCard : Panel
{
public StackCard()
{
DoubleBuffered = true;
BackColor = Color.FromArgb(250, 252, 255);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
using var border = new Pen(Color.FromArgb(204, 217, 234));
using var path = new GraphicsPath();
path.AddRoundedRectangle(new Rectangle(1, 1, Width - 3, Height - 3), new Size(14, 14));
e.Graphics.DrawPath(border, path);
}
}
sealed class StackPreview : Control
{
readonly AppStackConfig config;
public StackPreview(AppStackConfig config)
{
this.config = config;
DoubleBuffered = true;
AccessibleName = Localization.T("App stack preview", "Vorschau der App-Stapel");
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
using var bar = new GraphicsPath();
bar.AddRoundedRectangle(new Rectangle(1, 1, Width - 3, Height - 3), new Size(18, 18));
using var fill = new LinearGradientBrush(ClientRectangle, Color.FromArgb(64, 84, 113), Color.FromArgb(42, 59, 85), LinearGradientMode.Vertical);
e.Graphics.FillPath(fill, bar);
using var outline = new Pen(Color.FromArgb(117, 151, 191));
e.Graphics.DrawPath(outline, bar);
using var icon = new SolidBrush(Color.FromArgb(183, 209, 242));
e.Graphics.FillRectangle(icon, 20, 18, 13, 13);
e.Graphics.FillRectangle(icon, 35, 18, 13, 13);
int x = 79;
var groups = config.Groups ?? [];
if (groups.Count == 0)
{
for (int i = 0; i < 4; i++) { e.Graphics.FillEllipse(icon, x, 14, 23, 23); x += 40; }
}
else
{
foreach (var group in groups.Take(4))
{
using var pill = new GraphicsPath();
pill.AddRoundedRectangle(new Rectangle(x, 9, 59, 38), new Size(13, 13));
using var pillFill = new SolidBrush(group.Enabled
? group.FolderColor is int rgb ? Color.FromArgb(rgb) : Color.FromArgb(90, 117, 153)
: Color.FromArgb(72, 86, 110));
e.Graphics.FillPath(pillFill, pill);
using var pillEdge = new Pen(Color.FromArgb(141, 175, 217));
e.Graphics.DrawPath(pillEdge, pill);
var initial = string.IsNullOrWhiteSpace(group.Name) ? "•" : group.Name.Trim()[0].ToString().ToUpperInvariant();
using var font = new Font("Segoe UI Semibold", 12, FontStyle.Bold);
TextRenderer.DrawText(e.Graphics, initial, font, new Rectangle(x + 5, 13, 29, 27), Color.White,
TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
using var count = new Font("Segoe UI", 9, FontStyle.Bold);
TextRenderer.DrawText(e.Graphics, (group.Members is { Count: >= 2 } ? group.Members.Count : Math.Clamp(group.Count, 2, 31)).ToString(), count,
new Rectangle(x + 36, 16, 19, 22), Color.FromArgb(195, 221, 255),
TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
x += 72;
}
}
using var clock = new Font("Segoe UI Semibold", 10, FontStyle.Bold);
TextRenderer.DrawText(e.Graphics, "10:24", clock, new Rectangle(Width - 83, 13, 66, 28), Color.White,
TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
}
}
}