mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 02:06:36 +02:00
* [PTRun] Implemented a new JSON storage method for PTRun settings files. * [PTRun] Removed uncessary parts. * [PTRun] Spell checks. * [PTRun] New JsonSerializerOptions added for information files. * [PTRun] Unnecessary null check is removed. * [PT Run] - ExtractFields function removed. - Creating instance is used instead of deserializing. * [PTRun] Build fix * [PTRun] Removed unncessary parts * [PTRun] CheckWithInformationFileToClear reversed. * [PTRun] Build fix. * [PTRun] Deserialization is used instead of key by key comparison. * [PTRun] Removed unncessary parts. * [PTRun] Removed unncessary parts. * [PTRun] Remove entry if query is null or empty.
64 lines
1.6 KiB
C#
64 lines
1.6 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.Linq;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace PowerLauncher.Storage
|
|
{
|
|
public class QueryHistory
|
|
{
|
|
[JsonInclude]
|
|
public List<HistoryItem> Items { get; private set; } = new List<HistoryItem>();
|
|
|
|
private readonly int _maxHistory = 300;
|
|
|
|
public void Add(string query)
|
|
{
|
|
if (string.IsNullOrEmpty(query))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Items.Count > _maxHistory)
|
|
{
|
|
Items.RemoveAt(0);
|
|
}
|
|
|
|
if (Items.Count > 0 && Items.Last().Query == query)
|
|
{
|
|
Items.Last().ExecutedDateTime = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
Items.Add(new HistoryItem
|
|
{
|
|
Query = query,
|
|
ExecutedDateTime = DateTime.Now,
|
|
});
|
|
}
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
for (int i = Items.Count - 1; i >= 0; i--)
|
|
{
|
|
if (string.IsNullOrEmpty(Items[i].Query))
|
|
{
|
|
Items.RemoveAt(i);
|
|
}
|
|
else
|
|
{
|
|
if (Items[i].ExecutedDateTime == DateTime.MinValue)
|
|
{
|
|
Items[i].ExecutedDateTime = DateTime.Now;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|