[New Utility]Mouse Without Borders

* Integrate Mouse Without Borders into PowerToys

---------

Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
This commit is contained in:
Andrey Nekrasov
2023-05-15 23:32:26 +01:00
committed by Jaime Bernardo
parent a0b9af039d
commit 29eebe16a4
304 changed files with 37234 additions and 133 deletions

View File

@@ -0,0 +1,42 @@
// 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.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace Microsoft.PowerToys.Settings.UI.Helpers
{
internal sealed class AsyncCommand : ICommand
{
private readonly Func<Task> _execute;
private readonly Func<bool> _canExecute;
public event EventHandler CanExecuteChanged;
public AsyncCommand(Func<Task> execute, Func<bool> canExecute = null)
{
_execute = execute;
_canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return _canExecute == null || _canExecute();
}
public async void Execute(object parameter)
{
await _execute();
}
public void RaiseCanExecuteChanged()
{
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -1,27 +0,0 @@
// 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.ComponentModel;
using System.Runtime.CompilerServices;
namespace Microsoft.PowerToys.Settings.UI.Helpers
{
public class Observable : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void Set<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (Equals(storage, value))
{
return;
}
storage = value;
OnPropertyChanged(propertyName);
}
protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}