diff --git a/Flow.Launcher/Storage/LastOpenedHistoryResult.cs b/Flow.Launcher/Storage/LastOpenedHistoryResult.cs index b71282f14..7f571b768 100644 --- a/Flow.Launcher/Storage/LastOpenedHistoryResult.cs +++ b/Flow.Launcher/Storage/LastOpenedHistoryResult.cs @@ -1,4 +1,5 @@ using System; +using Flow.Launcher.Infrastructure; using Flow.Launcher.Plugin; namespace Flow.Launcher.Storage; @@ -56,24 +57,54 @@ public class LastOpenedHistoryResult : Result } /// - /// Selectively creates a deep copy of the required properties for . + /// Selectively creates a deep copy of the required properties for + /// based on the style of history- Last Opened or Query. /// This copy should be independent of original and full isolated. /// /// A new containing the same required data. - public LastOpenedHistoryResult DeepCopy() + public LastOpenedHistoryResult DeepCopyForHistoryStyle(bool isHistoryStyleLastOpened) { // queryValue and glyphValue are captured to ensure they are correctly referenced in the Action delegate. var queryValue = Query; var glyphValue = Glyph; + + var title = string.Empty; + var showBadge = false; + var badgeIcoPath = string.Empty; + var icoPath = string.Empty; + var glyph = null as GlyphInfo; + + if (isHistoryStyleLastOpened) + { + title = Title; + icoPath = IcoPath; + glyph = glyphValue != null + ? new GlyphInfo(glyphValue.FontFamily, glyphValue.Glyph) + : null; + showBadge = true; + badgeIcoPath = Constant.HistoryIcon; + } + else + { + title = Localize.executeQuery(Query); + icoPath = Constant.HistoryIcon; + glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE81C"); + showBadge = false; + } + return new LastOpenedHistoryResult { - Title = Title, - SubTitle = SubTitle, - PluginID = PluginID, + Title = title, + // Subtitle has datetime which can cause duplicates when saving. + SubTitle = Localize.lastExecuteTime(ExecutedDateTime), + // Empty PluginID so the source of last opened history results won't be updated, this copy is meant to be temporary. + PluginID = string.Empty, Query = Query, OriginQuery = new Query { TrimmedQuery = Query }, RecordKey = RecordKey, - IcoPath = IcoPath, + IcoPath = icoPath, + ShowBadge = showBadge, + BadgeIcoPath = badgeIcoPath, PluginDirectory = PluginDirectory, // Used for Query History style reopening Action = _ => @@ -84,9 +115,7 @@ public class LastOpenedHistoryResult : Result }, // Used for Last Opened History style reopening, currently need to be assigned at MainViewModel.cs AsyncAction = null, - Glyph = glyphValue != null - ? new GlyphInfo(glyphValue.FontFamily, glyphValue.Glyph) - : null, + Glyph = glyph, ExecutedDateTime = ExecutedDateTime // Note: Other properties are left as default — copy if needed. }; diff --git a/Flow.Launcher/Storage/QueryHistory.cs b/Flow.Launcher/Storage/QueryHistory.cs index 6af2a5908..91dee90df 100644 --- a/Flow.Launcher/Storage/QueryHistory.cs +++ b/Flow.Launcher/Storage/QueryHistory.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Text.Json.Serialization; using Flow.Launcher.Core.Plugin; -using Flow.Launcher.Infrastructure; using Flow.Launcher.Plugin; namespace Flow.Launcher.Storage @@ -35,9 +34,7 @@ namespace Flow.Launcher.Storage LastOpenedHistoryItems.Add(new LastOpenedHistoryResult { Title = Localize.executeQuery(item.Query), - IcoPath = null, OriginQuery = new Query { TrimmedQuery = item.Query }, - Glyph = null, Query = item.Query, Action = _ => { diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 63710b5fc..504ede103 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; @@ -1340,30 +1339,7 @@ namespace Flow.Launcher.ViewModel foreach (var item in historyItems) { - var copiedItem = item.DeepCopy(); - - if (Settings.HistoryStyle == HistoryStyle.Query) - { - copiedItem.Title = Localize.executeQuery(copiedItem.Query); - copiedItem.IcoPath = Constant.HistoryIcon; - // TODO: Add Glyph here - // copiedItem.Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE81C"); - } - else - { - if (string.IsNullOrEmpty(copiedItem.IcoPath)) // Must manually set missing image icon here - { - copiedItem.IcoPath = Constant.MissingImgIcon; - } - copiedItem.ShowBadge = true; - copiedItem.BadgeIcoPath = Constant.HistoryIcon; - } - - // Subtitle has datetime which can cause duplicates when saving. - copiedItem.SubTitle = Localize.lastExecuteTime(copiedItem.ExecutedDateTime); - - // Empty PluginID so the source of last opened history results won't be updated, these results are meant to be temporary copy. - copiedItem.PluginID = string.Empty; + var copiedItem = item.DeepCopyForHistoryStyle(Settings.HistoryStyle == HistoryStyle.LastOpened); if (Settings.HistoryStyle == HistoryStyle.LastOpened) {