Skip to content

Commit 1be0496

Browse files
committed
Add search box to theme list view
1 parent 3449b5c commit 1be0496

File tree

4 files changed

+76
-9
lines changed

4 files changed

+76
-9
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## Recent Changes
4+
5+
### Enhancements
6+
7+
* Added Tahoe Abstract theme
8+
* Updated to .NET 10 which enables dark mode across entire application ([#553](https://github.com/t1m0thyj/WinDynamicDesktop/issues/553))
9+
10+
### Bug Fixes
11+
12+
* Reduced impact on Windows startup time ([#645](https://github.com/t1m0thyj/WinDynamicDesktop/issues/645))
13+
* Fixed error when applying "None" wallpaper theme ([#652](https://github.com/t1m0thyj/WinDynamicDesktop/issues/652))
14+
* Fixed wallpaper not always refreshing when PC resumes from sleep ([#657](https://github.com/t1m0thyj/WinDynamicDesktop/issues/657))
15+
316
## `5.6.1`
417

518
**Note:** PowerShell scripts that update Windows theme have been fixed to work with Windows 11 (thanks @KrakenByte27). Download the latest scripts from [here](https://github.com/t1m0thyj/WDD-scripts/tree/master/stable#readme).

src/ThemeDialog.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
using System.Windows.Forms;
1414
using WinDynamicDesktop.Properties;
1515

16-
#pragma warning disable SYSLIB5002
1716
namespace WinDynamicDesktop
1817
{
1918
public partial class ThemeDialog : Form
@@ -34,8 +33,10 @@ public ThemeDialog()
3433
Localization.TranslateForm(this);
3534
this.themeLinkLabel.Left += (this.importButton.Width - oldButtonWidth);
3635

36+
#pragma warning disable SYSLIB5002
3737
this.searchBoxButton.BackgroundImage = SystemColors.UseAlternativeColorSet ?
3838
Resources.IconSearch_Dark : Resources.IconSearch_Light;
39+
#pragma warning restore SYSLIB5002
3940
this.themeLinkLabel.LinkColor = SystemColors.HotTrack;
4041

4142
this.FormClosing += OnFormClosing;
@@ -187,6 +188,11 @@ private void UpdateSelectedItem()
187188
{
188189
if (listView1.SelectedItems.Count == 0)
189190
{
191+
if (listView1.Items.Count == 0)
192+
{
193+
previewer.ViewModel.PreviewTheme(null, null,
194+
ThemeThumbLoader.GetWindowsWallpaper(IsLockScreenSelected));
195+
}
190196
applyButton.Enabled = false;
191197
return;
192198
}
@@ -195,7 +201,7 @@ private void UpdateSelectedItem()
195201
bool themeDownloaded = true;
196202
ThemeConfig theme = null;
197203

198-
if (selectedIndex > 0)
204+
if (listView1.Items[selectedIndex].Tag != null)
199205
{
200206
string themeId = (string)listView1.Items[selectedIndex].Tag;
201207
selectedIndex = ThemeManager.themeSettings.FindIndex(t => t.themeId == themeId) + 1;
@@ -262,19 +268,21 @@ private void ThemeDialog_Load(object sender, EventArgs e)
262268

263269
private void searchBox_TextChanged(object sender, EventArgs e)
264270
{
265-
// TODO do actual filtering
271+
#pragma warning disable SYSLIB5002
266272
if (string.IsNullOrWhiteSpace(searchBox.Text))
267273
{
268274
this.searchBoxButton.BackgroundImage = SystemColors.UseAlternativeColorSet ?
269275
Resources.IconSearch_Dark : Resources.IconSearch_Light;
270-
//ThemeDialogUtils.ClearSearchFilter(listView1);
271276
}
272277
else
273278
{
274279
this.searchBoxButton.BackgroundImage = SystemColors.UseAlternativeColorSet ?
275280
Resources.IconDismiss_Dark : Resources.IconDismiss_Light;
276-
//ThemeDialogUtils.ApplySearchFilter(listView1, searchBox.Text);
277281
}
282+
#pragma warning restore SYSLIB5002
283+
284+
ThemeDialogUtils.ApplySearchFilter(listView1, searchBox.Text);
285+
UpdateSelectedItem();
278286
}
279287

280288
private void searchBoxButton_Click(object sender, EventArgs e)
@@ -395,14 +403,14 @@ private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
395403
e.Cancel = true;
396404
return;
397405
}
398-
else if (itemIndex > 0)
406+
else if (listView1.Items[itemIndex].Tag != null)
399407
{
400408
themeId = (string)listView1.Items[itemIndex].Tag;
401409
theme = ThemeManager.themeSettings.Find(t => t.themeId == themeId);
402410
}
403411

404412
bool isWindowsTheme = themeId == DefaultThemes.GetWindowsTheme()?.themeId;
405-
contextMenuStrip1.Items[0].Enabled = itemIndex > 0;
413+
contextMenuStrip1.Items[0].Enabled = theme != null;
406414
contextMenuStrip1.Items[1].Enabled = theme != null && ThemeManager.IsThemeDownloaded(theme) &&
407415
!isWindowsTheme;
408416

src/ThemeDialogUtils.cs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public ThemeLoadOpts(string activeTheme = null, string focusTheme = null)
2929
internal class ThemeDialogUtils
3030
{
3131
private static readonly Func<string, string> _ = Localization.GetTranslation;
32+
private static List<ListViewItem> allThemeItems = new List<ListViewItem>();
3233
private static SemaphoreSlim loadSemaphore = new SemaphoreSlim(1);
3334

3435
internal static string[] GetDisplayNames()
@@ -142,6 +143,51 @@ internal static void LoadImportedThemes(List<ThemeConfig> themes, ListView listV
142143
});
143144
}
144145

146+
internal static void ApplySearchFilter(ListView listView, string searchText)
147+
{
148+
searchText = searchText.Trim().ToLower();
149+
150+
// Save all items on first search
151+
if (allThemeItems.Count == 0 && listView.Items.Count > 0)
152+
{
153+
foreach (ListViewItem item in listView.Items)
154+
{
155+
allThemeItems.Add((ListViewItem)item.Clone());
156+
}
157+
}
158+
159+
listView.BeginUpdate();
160+
listView.Items.Clear();
161+
162+
// Filter and add items back
163+
foreach (ListViewItem item in allThemeItems)
164+
{
165+
if (string.IsNullOrWhiteSpace(searchText))
166+
{
167+
// Show all items when search is empty
168+
listView.Items.Add((ListViewItem)item.Clone());
169+
}
170+
else
171+
{
172+
// Get theme name (remove favorite star)
173+
string themeName = item.Text.Replace("★ ", "").ToLower();
174+
175+
if (themeName.Contains(searchText))
176+
{
177+
listView.Items.Add((ListViewItem)item.Clone());
178+
}
179+
}
180+
}
181+
182+
listView.EndUpdate();
183+
184+
// Update selection
185+
if (listView.Items.Count > 0 && listView.SelectedItems.Count == 0)
186+
{
187+
listView.Items[0].Selected = true;
188+
}
189+
}
190+
145191
internal static void UpdateConfigForDisplay(List<string> activeThemes)
146192
{
147193
int numNewDisplays = Screen.AllScreens.Length - activeThemes.Count + 1;
@@ -225,7 +271,7 @@ internal static void ToggleShowInstalledOnly(ListView listView, bool newValue)
225271
{
226272
foreach (ListViewItem item in listView.Items)
227273
{
228-
if (item.Index > 0)
274+
if (item.Tag != null)
229275
{
230276
string themeId = (string)item.Tag;
231277
ThemeConfig theme = ThemeManager.themeSettings.Find(t => t.themeId == themeId);

src/ThemeThumbLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public static void CacheThumbnails(System.Windows.Forms.ListView listView)
131131
{
132132
foreach (System.Windows.Forms.ListViewItem item in listView.Items)
133133
{
134-
if (item.Index == 0)
134+
if (item.Tag == null)
135135
{
136136
continue;
137137
}

0 commit comments

Comments
 (0)