mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
Implementing store of setting "order by".
This commit is contained in:
@@ -66,14 +66,6 @@ namespace ProjectsEditor
|
||||
|
||||
var parseResult = ProjectsEditorIO.ParseProjects(_mainViewModel);
|
||||
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
if (args != null && args.Length > 1)
|
||||
{
|
||||
Logger.LogInfo($"Started with a parameter: {args[1]}. Trying to launch that project.");
|
||||
_mainViewModel.LaunchProject(args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
// normal start of editor
|
||||
if (_mainWindow == null)
|
||||
{
|
||||
|
||||
@@ -100,6 +100,7 @@
|
||||
<ProjectReference Include="..\..\..\common\interop\PowerToys.Interop.vcxproj" />
|
||||
<ProjectReference Include="..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
|
||||
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
|
||||
33
src/modules/Projects/ProjectsEditor/Utils/Settings.cs
Normal file
33
src/modules/Projects/ProjectsEditor/Utils/Settings.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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 Microsoft.PowerToys.Settings.UI.Library;
|
||||
|
||||
namespace ProjectsEditor.Utils
|
||||
{
|
||||
public class Settings
|
||||
{
|
||||
private const string ProjectsModuleName = "Projects";
|
||||
private static SettingsUtils _settingsUtils = new SettingsUtils();
|
||||
|
||||
public static ProjectsSettings ReadSettings()
|
||||
{
|
||||
if (!_settingsUtils.SettingsExists(ProjectsModuleName))
|
||||
{
|
||||
////Logger.LogInfo("Projects settings.json was missing, creating a new one");
|
||||
var defaultProjectsSettings = new ProjectsSettings();
|
||||
defaultProjectsSettings.Save(_settingsUtils);
|
||||
return defaultProjectsSettings;
|
||||
}
|
||||
|
||||
ProjectsSettings settings = _settingsUtils.GetSettingsOrDefault<ProjectsSettings>(ProjectsModuleName);
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using ProjectsEditor.Data;
|
||||
using ProjectsEditor.Models;
|
||||
using ProjectsEditor.Utils;
|
||||
@@ -33,6 +34,7 @@ namespace ProjectsEditor.ViewModels
|
||||
private string projectNameBeingEdited;
|
||||
private MainWindow _mainWindow;
|
||||
private Timer lastUpdatedTimer;
|
||||
private ProjectsSettings settings;
|
||||
|
||||
public ObservableCollection<Project> Projects { get; set; } = new ObservableCollection<Project>();
|
||||
|
||||
@@ -124,6 +126,8 @@ namespace ProjectsEditor.ViewModels
|
||||
{
|
||||
_orderByIndex = value;
|
||||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(ProjectsView)));
|
||||
settings.Properties.SortBy = (ProjectsProperties.SortByProperty)value;
|
||||
settings.Save(new SettingsUtils());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +140,8 @@ namespace ProjectsEditor.ViewModels
|
||||
|
||||
public MainViewModel(ProjectsEditorIO projectsEditorIO)
|
||||
{
|
||||
settings = Utils.Settings.ReadSettings();
|
||||
_orderByIndex = (int)settings.Properties.SortBy;
|
||||
_projectsEditorIO = projectsEditorIO;
|
||||
lastUpdatedTimer = new System.Timers.Timer();
|
||||
lastUpdatedTimer.Interval = 1000;
|
||||
|
||||
@@ -9,6 +9,13 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ProjectsProperties
|
||||
{
|
||||
public enum SortByProperty
|
||||
{
|
||||
LastLaunched,
|
||||
Created,
|
||||
Name,
|
||||
}
|
||||
|
||||
public static readonly HotkeySettings DefaultHotkeyValue = new HotkeySettings(true, false, false, true, 0x4F);
|
||||
|
||||
public ProjectsProperties()
|
||||
@@ -19,6 +26,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
[JsonPropertyName("hotkey")]
|
||||
public KeyboardKeysProperty Hotkey { get; set; }
|
||||
|
||||
[JsonPropertyName("sortby")]
|
||||
public SortByProperty SortBy { get; set; }
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
@@ -11,6 +13,10 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public const string ModuleName = "Projects";
|
||||
public const string ModuleVersion = "0.0.1";
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
public ProjectsSettings()
|
||||
{
|
||||
@@ -31,5 +37,15 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void Save(ISettingsUtils settingsUtils)
|
||||
{
|
||||
// Save settings to file
|
||||
var options = _serializerOptions;
|
||||
|
||||
ArgumentNullException.ThrowIfNull(settingsUtils);
|
||||
|
||||
settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user