mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[New Utility]Mouse Without Borders
* Integrate Mouse Without Borders into PowerToys --------- Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
This commit is contained in:
committed by
Jaime Bernardo
parent
a0b9af039d
commit
29eebe16a4
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Helpers
|
||||
{
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
public class IndexedItem<T>
|
||||
#pragma warning restore SA1649 // File name should match first type name
|
||||
{
|
||||
public T Item { get; set; }
|
||||
|
||||
public int Index { get; set; }
|
||||
|
||||
public IndexedItem(T item, int index)
|
||||
{
|
||||
Item = item;
|
||||
Index = index;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable SA1402 // File may only contain a single type
|
||||
public class IndexedObservableCollection<T> : ObservableCollection<IndexedItem<T>>
|
||||
#pragma warning restore SA1402 // File may only contain a single type
|
||||
{
|
||||
public IndexedObservableCollection(IEnumerable<T> items)
|
||||
{
|
||||
int index = 0;
|
||||
foreach (var item in items)
|
||||
{
|
||||
Add(new IndexedItem<T>(item, index++));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<T> ToEnumerable()
|
||||
{
|
||||
return this.Select(x => x.Item);
|
||||
}
|
||||
|
||||
public void Swap(int index1, int index2)
|
||||
{
|
||||
var temp = this[index1];
|
||||
this[index1] = this[index2];
|
||||
this[index2] = temp;
|
||||
|
||||
// Update the original index of the items
|
||||
this[index1].Index = index1;
|
||||
this[index2].Index = index2;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user