Skip to content
This repository was archived by the owner on Jul 24, 2025. It is now read-only.

Commit c275aa6

Browse files
Fix #988
1 parent 06a3708 commit c275aa6

File tree

4 files changed

+148
-31
lines changed

4 files changed

+148
-31
lines changed

LenovoLegionToolkit.WPF/Controls/Dashboard/Edit/EditDashboardGroupControl.cs

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
using System.Threading.Tasks;
55
using System.Windows;
66
using System.Windows.Controls;
7-
using System.Windows.Controls.Primitives;
8-
using LenovoLegionToolkit.WPF.Extensions;
97
using LenovoLegionToolkit.WPF.Resources;
108
using LenovoLegionToolkit.WPF.Utils;
9+
using LenovoLegionToolkit.WPF.Windows.Dashboard;
1110
using Wpf.Ui.Common;
1211
using Wpf.Ui.Controls;
1312
using Button = Wpf.Ui.Controls.Button;
14-
using MenuItem = Wpf.Ui.Controls.MenuItem;
1513

1614
namespace LenovoLegionToolkit.WPF.Controls.Dashboard.Edit;
1715

@@ -97,7 +95,7 @@ public EditDashboardGroupControl(DashboardGroup dashboardGroup, Func<IEnumerable
9795
_moveUpButton.Click += (_, _) => MoveUp?.Invoke(this, EventArgs.Empty);
9896
_moveDownButton.Click += (_, _) => MoveDown?.Invoke(this, EventArgs.Empty);
9997
_deleteButton.Click += (_, _) => Delete?.Invoke(this, EventArgs.Empty);
100-
_addItemButton.Click += (_, _) => ShowContextMenu();
98+
_addItemButton.Click += (_, _) => ShowAddItemWindow();
10199

102100
_buttonsStackPanel.Children.Add(_editButton);
103101
_buttonsStackPanel.Children.Add(_moveUpButton);
@@ -150,32 +148,10 @@ private async Task EditNameAsync()
150148
_cardHeaderControl.Title = result;
151149
}
152150

153-
private void ShowContextMenu()
151+
private void ShowAddItemWindow()
154152
{
155-
var allItems = Enum.GetValues<DashboardItem>();
156-
var existingItems = _getExistingItems().ToArray();
157-
158-
var menuItems = new List<MenuItem>();
159-
160-
foreach (var item in allItems)
161-
{
162-
var menuItem = new MenuItem { SymbolIcon = item.GetIcon(), Header = item.GetTitle() };
163-
menuItem.Click += (_, _) => AddItem(item);
164-
menuItem.IsEnabled = !existingItems.Contains(item);
165-
menuItems.Add(menuItem);
166-
}
167-
168-
var contextMenu = new ContextMenu
169-
{
170-
PlacementTarget = _addItemButton,
171-
Placement = PlacementMode.Bottom,
172-
};
173-
174-
foreach (var menuItem in menuItems.OrderBy(mi => mi.Header))
175-
contextMenu.Items.Add(menuItem);
176-
177-
_addItemButton.ContextMenu = contextMenu;
178-
_addItemButton.ContextMenu.IsOpen = true;
153+
var window = new AddDashboardItemWindow(_getExistingItems, AddItem) { Owner = Window.GetWindow(this) };
154+
window.ShowDialog();
179155
}
180156

181157
private void AddItem(DashboardItem dashboardItem)

LenovoLegionToolkit.WPF/Windows/Automation/AddAutomationStepWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
xmlns:utils="clr-namespace:LenovoLegionToolkit.WPF.Utils"
88
xmlns:wpfui="http://schemas.lepo.co/wpfui/2022/xaml"
99
Title="{x:Static resources:Resource.AddAutomationStepWindow_Title}"
10-
Width="500"
10+
Width="600"
1111
Height="570"
1212
MinWidth="500"
1313
MinHeight="400"
@@ -68,4 +68,4 @@
6868

6969
</Grid>
7070
</Grid>
71-
</local:BaseWindow>
71+
</local:BaseWindow>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<local:BaseWindow
2+
x:Class="LenovoLegionToolkit.WPF.Windows.Dashboard.AddDashboardItemWindow"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="clr-namespace:LenovoLegionToolkit.WPF.Windows"
6+
xmlns:resources="clr-namespace:LenovoLegionToolkit.WPF.Resources"
7+
xmlns:utils="clr-namespace:LenovoLegionToolkit.WPF.Utils"
8+
xmlns:wpfui="http://schemas.lepo.co/wpfui/2022/xaml"
9+
Title="{x:Static resources:Resource.Add}"
10+
Width="600"
11+
Height="570"
12+
MinWidth="500"
13+
MinHeight="400"
14+
FlowDirection="{x:Static utils:LocalizationHelper.Direction}"
15+
ResizeMode="CanMinimize"
16+
ShowInTaskbar="False"
17+
WindowStartupLocation="CenterOwner">
18+
19+
<Grid>
20+
<Grid.RowDefinitions>
21+
<RowDefinition Height="Auto" />
22+
<RowDefinition Height="*" />
23+
<RowDefinition Height="Auto" />
24+
<RowDefinition Height="Auto" />
25+
</Grid.RowDefinitions>
26+
27+
<wpfui:TitleBar
28+
Grid.Row="0"
29+
CanMaximize="false"
30+
ShowMaximize="false"
31+
ShowMinimize="false"
32+
UseSnapLayout="false" />
33+
34+
<Grid
35+
Grid.Row="0"
36+
Height="24"
37+
Margin="12,8,12,8">
38+
<Grid.ColumnDefinitions>
39+
<ColumnDefinition Width="*" />
40+
<ColumnDefinition Width="Auto" />
41+
</Grid.ColumnDefinitions>
42+
43+
<TextBlock
44+
Grid.Column="0"
45+
VerticalAlignment="Center"
46+
FontSize="12"
47+
IsHitTestVisible="False"
48+
Text="{x:Static resources:Resource.Add}" />
49+
50+
</Grid>
51+
52+
<wpfui:DynamicScrollViewer Grid.Row="1" Margin="12,0,0,12">
53+
<StackPanel x:Name="_content" Margin="0,0,12,0" />
54+
</wpfui:DynamicScrollViewer>
55+
56+
<Grid Grid.Row="2" Margin="0,0,12,12">
57+
<Grid.ColumnDefinitions>
58+
<ColumnDefinition Width="*" />
59+
<ColumnDefinition Width="Auto" />
60+
</Grid.ColumnDefinitions>
61+
62+
<wpfui:Button
63+
Grid.Column="1"
64+
MinWidth="100"
65+
Margin="8,0,0,0"
66+
Click="CancelButton_Click"
67+
Content="{x:Static resources:Resource.Cancel}" />
68+
69+
</Grid>
70+
</Grid>
71+
</local:BaseWindow>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using System.Windows;
6+
using LenovoLegionToolkit.WPF.Controls;
7+
using LenovoLegionToolkit.WPF.Extensions;
8+
using Wpf.Ui.Common;
9+
using Wpf.Ui.Controls;
10+
11+
namespace LenovoLegionToolkit.WPF.Windows.Dashboard;
12+
13+
public partial class AddDashboardItemWindow
14+
{
15+
private readonly Func<IEnumerable<DashboardItem>> _existingItems;
16+
private readonly Action<DashboardItem> _addDashboardItem;
17+
18+
public AddDashboardItemWindow(Func<IEnumerable<DashboardItem>> existingItems, Action<DashboardItem> addDashboardItem)
19+
{
20+
_existingItems = existingItems;
21+
_addDashboardItem = addDashboardItem;
22+
23+
InitializeComponent();
24+
25+
IsVisibleChanged += AddAutomationStepWindow_IsVisibleChanged;
26+
}
27+
28+
private async void AddAutomationStepWindow_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
29+
{
30+
if (IsVisible)
31+
await RefreshAsync();
32+
}
33+
34+
private void CancelButton_Click(object sender, RoutedEventArgs e) => Close();
35+
36+
private Task RefreshAsync()
37+
{
38+
_content.Children.Clear();
39+
40+
var allItems = Enum.GetValues<DashboardItem>();
41+
var existingItems = _existingItems().ToArray();
42+
43+
foreach (var item in allItems)
44+
_content.Children.Add(CreateCardControl(item));
45+
46+
return Task.CompletedTask;
47+
}
48+
49+
private UIElement CreateCardControl(DashboardItem item)
50+
{
51+
var control = new CardControl
52+
{
53+
Icon = item.GetIcon(),
54+
Header = new CardHeaderControl
55+
{
56+
Title = item.GetTitle(),
57+
Accessory = new SymbolIcon { Symbol = SymbolRegular.ChevronRight24 }
58+
},
59+
Margin = new(0, 8, 0, 0),
60+
};
61+
62+
control.Click += (_, _) =>
63+
{
64+
_addDashboardItem(item);
65+
Close();
66+
};
67+
68+
return control;
69+
}
70+
}

0 commit comments

Comments
 (0)