mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-22 01:58:04 +00:00
* added test project * run fz test * rename proj * editor test project * check if FZ is running * rename * added assert messages * spelling * dev docs * spelling * update to latest stable * exclude ui tests deps * update packages list in notice.md * added sample tests * added file for tests run * removed unrecognized * removed run * fix test configuration * rename job * change dependance * run test template * removed condition * tabulation fix * removed arg * removed dependance * removed log * removed parameters * test * test * added parameters * pool * pool * vs test * dependance * download artifact * publish artifact * artifact publish conditions * artifact name, default download path * set folders * prepare dotnet and vstest platform * copy all * target dotnet8 * test build agents * set vs test version * spellcheck * set test platform version * package feed selector * hardcoded vstest location * are other tests running? * location * vstest.console * upd command * script path * search vstest.console * vs path * tools dir * check files * try full path * try vstest task * try full path in vstest task * change path, remove unnecessary * test with full vsconsole path * winappdriver task * changed args and condition * default address * added start operation type * task name * remove resolution * Update run-ui-tests-ci.yml * Update run-ui-tests-ci.yml * Update run-ui-tests-ci.yml * Update run-ui-tests-ci.yml * AgentResolution should be a string * Update run-ui-tests-ci.yml testing against what WinUI gallery has for agent * Update run-ui-tests-ci.yml * Update run-ui-tests-ci.yml * added WinAppDriver.exe * spellcheck * remove task * checkout * path * src dir variable * added init to the second project * set longer timeout * try waiting * rerun * log session info * exclude WinAppDriver files from spell-check * split io class: editor params * remove unnecessary * move data to the common project * io test helper * write retry * Moved constants * file utils * prepare editor files before launch * remove unused file * spellcheck * create directory * fixed cleaning up * remove WinAppDriver from deps * start WinAppDriver from the default installation path * installation script * Revert "spellcheck" This reverts commit 4bdc3957305daa20a5901aae83de0622ec41a93d. * Revert "exclude WinAppDriver files from spell-check" This reverts commit 21ee6db3f5afb4cae9ea51d9468c07caa8dbc0f4. * install * installation argument * spellcheck * change winappdriver path in fz tests * delete iohelper * update docs * deleted obsolete winappdriver tests * net version * try without vstest location * spellcheck * Revert "try without vstest location" This reverts commit 7cd39f3ae6735f53f7deea8d91312a8046309459. * moved json tag constants to the common project
405 lines
11 KiB
C#
405 lines
11 KiB
C#
// 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.ComponentModel;
|
|
using System.Globalization;
|
|
using System.Runtime.CompilerServices;
|
|
using FancyZonesEditorCommon.Data;
|
|
|
|
namespace FancyZonesEditor.Models
|
|
{
|
|
// Base LayoutModel
|
|
// Manages common properties and base persistence
|
|
public abstract class LayoutModel : INotifyPropertyChanged
|
|
{
|
|
protected LayoutModel()
|
|
{
|
|
_guid = Guid.NewGuid();
|
|
Type = LayoutType.Custom;
|
|
|
|
MainWindowSettingsModel.DefaultLayouts.PropertyChanged += DefaultLayouts_PropertyChanged;
|
|
}
|
|
|
|
protected LayoutModel(string name)
|
|
: this()
|
|
{
|
|
Name = name;
|
|
}
|
|
|
|
protected LayoutModel(string uuid, string name, LayoutType type)
|
|
: this()
|
|
{
|
|
_guid = Guid.Parse(uuid);
|
|
Name = name;
|
|
Type = type;
|
|
}
|
|
|
|
protected LayoutModel(string name, LayoutType type)
|
|
: this(name)
|
|
{
|
|
_guid = Guid.NewGuid();
|
|
Type = type;
|
|
}
|
|
|
|
protected LayoutModel(LayoutModel other)
|
|
{
|
|
_guid = other._guid;
|
|
_name = other._name;
|
|
Type = other.Type;
|
|
_isSelected = other._isSelected;
|
|
_isApplied = other._isApplied;
|
|
_sensitivityRadius = other._sensitivityRadius;
|
|
_zoneCount = other._zoneCount;
|
|
_quickKey = other._quickKey;
|
|
}
|
|
|
|
// Name - the display name for this layout model - is also used as the key in the registry
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return _name;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (_name != value)
|
|
{
|
|
_name = value;
|
|
FirePropertyChanged(nameof(Name));
|
|
}
|
|
}
|
|
}
|
|
|
|
private string _name;
|
|
|
|
public LayoutType Type { get; set; }
|
|
|
|
#pragma warning disable CA1720 // Identifier contains type name (Not worth the effort to change this now.)
|
|
public Guid Guid
|
|
#pragma warning restore CA1720 // Identifier contains type name
|
|
{
|
|
get
|
|
{
|
|
return _guid;
|
|
}
|
|
}
|
|
|
|
private Guid _guid;
|
|
|
|
public string Uuid
|
|
{
|
|
get
|
|
{
|
|
return "{" + Guid.ToString().ToUpperInvariant() + "}";
|
|
}
|
|
}
|
|
|
|
public bool IsCustom
|
|
{
|
|
get
|
|
{
|
|
return Type == LayoutType.Custom;
|
|
}
|
|
}
|
|
|
|
// IsSelected (not-persisted) - tracks whether or not this LayoutModel is selected in the picker
|
|
// TODO: once we switch to a picker per monitor, we need to move this state to the view
|
|
public bool IsSelected
|
|
{
|
|
get
|
|
{
|
|
return _isSelected;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (_isSelected != value)
|
|
{
|
|
_isSelected = value;
|
|
FirePropertyChanged(nameof(IsSelected));
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool _isSelected;
|
|
|
|
// IsApplied (not-persisted) - tracks whether or not this LayoutModel is applied in the picker
|
|
public bool IsApplied
|
|
{
|
|
get
|
|
{
|
|
return _isApplied;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (_isApplied != value)
|
|
{
|
|
_isApplied = value;
|
|
FirePropertyChanged(nameof(IsApplied));
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool _isApplied;
|
|
|
|
public bool IsHorizontalDefault
|
|
{
|
|
get
|
|
{
|
|
return MainWindowSettingsModel.DefaultLayouts.Layouts[(int)MonitorConfigurationType.Horizontal].Uuid == this.Uuid;
|
|
}
|
|
}
|
|
|
|
public bool CanBeSetAsHorizontalDefault
|
|
{
|
|
get
|
|
{
|
|
return MainWindowSettingsModel.DefaultLayouts.Layouts[(int)MonitorConfigurationType.Horizontal].Uuid != this.Uuid;
|
|
}
|
|
}
|
|
|
|
public bool IsVerticalDefault
|
|
{
|
|
get
|
|
{
|
|
return MainWindowSettingsModel.DefaultLayouts.Layouts[MonitorConfigurationType.Vertical].Uuid == this.Uuid;
|
|
}
|
|
}
|
|
|
|
public bool CanBeSetAsVerticalDefault
|
|
{
|
|
get
|
|
{
|
|
return MainWindowSettingsModel.DefaultLayouts.Layouts[MonitorConfigurationType.Vertical].Uuid != this.Uuid;
|
|
}
|
|
}
|
|
|
|
public int SensitivityRadius
|
|
{
|
|
get
|
|
{
|
|
return _sensitivityRadius;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (value != _sensitivityRadius)
|
|
{
|
|
_sensitivityRadius = value;
|
|
FirePropertyChanged(nameof(SensitivityRadius));
|
|
}
|
|
}
|
|
}
|
|
|
|
private int _sensitivityRadius = LayoutDefaultSettings.DefaultSensitivityRadius;
|
|
|
|
public int SensitivityRadiusMinimum
|
|
{
|
|
get
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public int SensitivityRadiusMaximum
|
|
{
|
|
get
|
|
{
|
|
return 1000;
|
|
}
|
|
}
|
|
|
|
public List<string> QuickKeysAvailable
|
|
{
|
|
get
|
|
{
|
|
List<string> result = new List<string>();
|
|
foreach (var pair in MainWindowSettingsModel.LayoutHotkeys.SelectedKeys)
|
|
{
|
|
if (string.IsNullOrEmpty(pair.Value) || pair.Value == Uuid)
|
|
{
|
|
result.Add(pair.Key);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public string QuickKey
|
|
{
|
|
get
|
|
{
|
|
return _quickKey == -1 ? Properties.Resources.Quick_Key_None : _quickKey.ToString(CultureInfo.CurrentCulture);
|
|
}
|
|
|
|
set
|
|
{
|
|
var intValue = -1;
|
|
string none = Properties.Resources.Quick_Key_None;
|
|
|
|
if (value != none && int.TryParse(value, out var parsedInt))
|
|
{
|
|
intValue = parsedInt;
|
|
}
|
|
|
|
if (intValue != _quickKey)
|
|
{
|
|
string prev = _quickKey == -1 ? none : _quickKey.ToString(CultureInfo.CurrentCulture);
|
|
_quickKey = intValue;
|
|
|
|
if (intValue != -1)
|
|
{
|
|
MainWindowSettingsModel.LayoutHotkeys.SelectKey(value, Uuid);
|
|
}
|
|
else
|
|
{
|
|
MainWindowSettingsModel.LayoutHotkeys.FreeKey(prev);
|
|
}
|
|
|
|
FirePropertyChanged(nameof(QuickKey));
|
|
}
|
|
}
|
|
}
|
|
|
|
private int _quickKey = -1;
|
|
|
|
// TemplateZoneCount - number of zones selected in the picker window for template layouts
|
|
public int TemplateZoneCount
|
|
{
|
|
get
|
|
{
|
|
return _zoneCount;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (value != _zoneCount)
|
|
{
|
|
_zoneCount = value;
|
|
InitTemplateZones();
|
|
FirePropertyChanged(nameof(TemplateZoneCount));
|
|
FirePropertyChanged(nameof(IsZoneAddingAllowed));
|
|
}
|
|
}
|
|
}
|
|
|
|
public int TemplateZoneCountMinimum
|
|
{
|
|
get
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
public int TemplateZoneCountMaximum
|
|
{
|
|
get
|
|
{
|
|
return 128;
|
|
}
|
|
}
|
|
|
|
private int _zoneCount = LayoutDefaultSettings.DefaultZoneCount;
|
|
|
|
public bool IsZoneAddingAllowed
|
|
{
|
|
get
|
|
{
|
|
return TemplateZoneCount < LayoutDefaultSettings.MaxZones;
|
|
}
|
|
}
|
|
|
|
// implementation of INotifyPropertyChanged
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
// FirePropertyChanged -- wrapper that calls INPC.PropertyChanged
|
|
protected virtual void FirePropertyChanged([CallerMemberName] string propertyName = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
// Removes this Layout from the registry and the loaded CustomModels list
|
|
public void Delete()
|
|
{
|
|
if (_quickKey != -1)
|
|
{
|
|
MainWindowSettingsModel.LayoutHotkeys.FreeKey(QuickKey);
|
|
}
|
|
|
|
var customModels = MainWindowSettingsModel.CustomModels;
|
|
int i = customModels.IndexOf(this);
|
|
if (i != -1)
|
|
{
|
|
customModels.RemoveAt(i);
|
|
}
|
|
}
|
|
|
|
public void RestoreTo(LayoutModel layout)
|
|
{
|
|
layout.SensitivityRadius = SensitivityRadius;
|
|
layout.TemplateZoneCount = TemplateZoneCount;
|
|
}
|
|
|
|
// Adds new custom Layout
|
|
public void AddCustomLayout(LayoutModel model)
|
|
{
|
|
bool updated = false;
|
|
var customModels = MainWindowSettingsModel.CustomModels;
|
|
for (int i = 0; i < customModels.Count && !updated; i++)
|
|
{
|
|
if (customModels[i].Uuid == model.Uuid)
|
|
{
|
|
customModels[i] = model;
|
|
updated = true;
|
|
}
|
|
}
|
|
|
|
if (!updated)
|
|
{
|
|
customModels.Add(model);
|
|
}
|
|
}
|
|
|
|
// InitTemplateZones
|
|
// Creates zones based on template zones count
|
|
public abstract void InitTemplateZones();
|
|
|
|
// Callbacks that the base LayoutModel makes to derived types
|
|
protected abstract void PersistData();
|
|
|
|
public abstract LayoutModel Clone();
|
|
|
|
public void Persist()
|
|
{
|
|
PersistData();
|
|
FirePropertyChanged(nameof(PersistData));
|
|
}
|
|
|
|
public void LayoutHotkeys_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
{
|
|
foreach (var pair in MainWindowSettingsModel.LayoutHotkeys.SelectedKeys)
|
|
{
|
|
if (pair.Value == Uuid)
|
|
{
|
|
QuickKey = pair.Key.ToString();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void DefaultLayouts_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
{
|
|
FirePropertyChanged(nameof(IsHorizontalDefault));
|
|
FirePropertyChanged(nameof(IsVerticalDefault));
|
|
FirePropertyChanged(nameof(CanBeSetAsHorizontalDefault));
|
|
FirePropertyChanged(nameof(CanBeSetAsVerticalDefault));
|
|
}
|
|
}
|
|
}
|