diff --git a/src/modules/Projects/ProjectsEditor/App.xaml.cs b/src/modules/Projects/ProjectsEditor/App.xaml.cs index 9188150718..65d320e97b 100644 --- a/src/modules/Projects/ProjectsEditor/App.xaml.cs +++ b/src/modules/Projects/ProjectsEditor/App.xaml.cs @@ -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) { diff --git a/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj b/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj index c7865cd484..d7b17ffa4f 100644 --- a/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj +++ b/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj @@ -100,6 +100,7 @@ + diff --git a/src/modules/Projects/ProjectsEditor/Utils/Settings.cs b/src/modules/Projects/ProjectsEditor/Utils/Settings.cs new file mode 100644 index 0000000000..22d0f9ab4c --- /dev/null +++ b/src/modules/Projects/ProjectsEditor/Utils/Settings.cs @@ -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(ProjectsModuleName); + return settings; + } + } +} diff --git a/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs b/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs index 2f9909a9cb..40a61b18a3 100644 --- a/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs +++ b/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs @@ -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 Projects { get; set; } = new ObservableCollection(); @@ -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; diff --git a/src/settings-ui/Settings.UI.Library/ProjectsProperties.cs b/src/settings-ui/Settings.UI.Library/ProjectsProperties.cs index 6a33222ab9..e127a629d0 100644 --- a/src/settings-ui/Settings.UI.Library/ProjectsProperties.cs +++ b/src/settings-ui/Settings.UI.Library/ProjectsProperties.cs @@ -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); diff --git a/src/settings-ui/Settings.UI.Library/ProjectsSettings.cs b/src/settings-ui/Settings.UI.Library/ProjectsSettings.cs index c1a7200b31..512505a076 100644 --- a/src/settings-ui/Settings.UI.Library/ProjectsSettings.cs +++ b/src/settings-ui/Settings.UI.Library/ProjectsSettings.cs @@ -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); + } } }