Skip to content

Conversation

@xoascf
Copy link
Collaborator

@xoascf xoascf commented Aug 20, 2025

It should also save and restore the layout order.

Further testing is required. Since the code has not been reviewed, it may not adhere to best practices.

@xoascf xoascf requested a review from dremin August 20, 2025 01:04
@github-actions
Copy link

@xoascf xoascf requested a review from Copilot August 21, 2025 18:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for reordering notification icons via drag-and-drop functionality and saves/restores the layout order. The implementation uses the GongSolutions.Wpf.DragDrop library to enable interactive reordering of notification icons in the system tray.

Key changes:

  • Added NotifyIconOrder property to Settings class to persist icon order
  • Created NotifyIconDropHandler class to handle drag-and-drop operations
  • Modified NotifyIconList to use ObservableCollections instead of CollectionViewSources and implement order persistence

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
RetroBar/Utilities/Settings.cs Adds NotifyIconOrder property to store icon ordering
RetroBar/Utilities/NotifyIconDropHandler.cs Implements IDropTarget interface for drag-and-drop handling
RetroBar/Controls/NotifyIconList.xaml.cs Refactors collection management and adds order persistence logic
RetroBar/Controls/NotifyIconList.xaml Enables drag-and-drop on NotifyIcons ItemsControl

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

.ToList();

// Sort icons according to saved order
var sortedIcons = icons.OrderBy(i => Settings.Instance.NotifyIconOrder.IndexOf(i.GetInvertIdentifier())).ToList();
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using IndexOf for ordering will fail when icons are not in the saved order list. IndexOf returns -1 for missing items, which will cause all unknown icons to be sorted to the beginning with the same priority. Use a custom ordering logic that handles missing items by assigning them a default order value.

Suggested change
var sortedIcons = icons.OrderBy(i => Settings.Instance.NotifyIconOrder.IndexOf(i.GetInvertIdentifier())).ToList();
var sortedIcons = icons.OrderBy(i =>
{
int idx = Settings.Instance.NotifyIconOrder.IndexOf(i.GetInvertIdentifier());
return idx == -1 ? Settings.Instance.NotifyIconOrder.Count : idx;
}).ToList();

Copilot uses AI. Check for mistakes.
}
foreach (var icon in NotificationArea.PinnedIcons.Cast<ManagedShell.WindowsTray.NotifyIcon>().OrderBy(i => Settings.Instance.NotifyIconOrder.IndexOf(i.GetInvertIdentifier())))
{
pinnedNotifyIcons.Add(icon);
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same IndexOf issue as line 218. Missing icons from the saved order will all receive -1 and be grouped together at the beginning, losing their relative order.

Suggested change
pinnedNotifyIcons.Add(icon);
foreach (var tuple in NotificationArea.PinnedIcons.Cast<ManagedShell.WindowsTray.NotifyIcon>()
.Select((icon, idx) => new { icon, idx, orderIndex = Settings.Instance.NotifyIconOrder.IndexOf(icon.GetInvertIdentifier()) })
.OrderBy(t => t.orderIndex == -1 ? int.MaxValue : t.orderIndex)
.ThenBy(t => t.idx))
{
pinnedNotifyIcons.Add(tuple.icon);

Copilot uses AI. Check for mistakes.

public void SaveIconOrder()
{
var visibleIcons = new System.Collections.Generic.List<ManagedShell.WindowsTray.NotifyIcon>();
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the fully qualified type name 'System.Collections.Generic.List' is unnecessary since 'using System.Collections.Generic;' is already present. Use 'List<ManagedShell.WindowsTray.NotifyIcon>' instead.

Suggested change
var visibleIcons = new System.Collections.Generic.List<ManagedShell.WindowsTray.NotifyIcon>();
var visibleIcons = new List<ManagedShell.WindowsTray.NotifyIcon>();

Copilot uses AI. Check for mistakes.
@MatroskaBabushka
Copy link

@xoascf @dremin
Hello. So what is the state of this PR? Is this ready or does it need more work?
Thanks @xoascf for taking the time to make this feature, it is very usefull.

@kuku00GT
Copy link

kuku00GT commented Nov 6, 2025

Hi, will be this (drag-dropp icon ordering) finished soon and added to official release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] An ability to reorder tray icons with dragging Inability to save layout of tray items upon closing the software

3 participants