-
-
Notifications
You must be signed in to change notification settings - Fork 621
FEATURE: Calculator Plugin History #4454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 12 commits
283cbe4
f4ac497
05eae58
e4f5dee
dc2dfb7
a7c1f33
df72b99
4fc3016
6d93ce0
ed6cccf
83efd29
e7d0dd3
0d1b2bb
2f7f2bb
264d9ad
a745873
a7efe5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using Flow.Launcher.Localization.Attributes; | ||
|
|
||
| namespace Flow.Launcher.Plugin.Calculator | ||
| { | ||
| /// <summary> | ||
| /// Represents the different modes for saving calculator calculations into the history. | ||
| /// </summary> | ||
| [EnumLocalize] | ||
| public enum HistoryCreationMode | ||
| { | ||
| /// <summary> | ||
| /// Saves calculations into the history automatically as the query is typed. | ||
| /// </summary> | ||
| [EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_calculator_history_creation_mode_on_query))] | ||
| OnQuery, | ||
|
|
||
| /// <summary> | ||
| /// Saves calculations into the history only when the action is executed (e.g. Enter is pressed). | ||
| /// </summary> | ||
| [EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_calculator_history_creation_mode_on_enter))] | ||
| OnEnter | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| using System; | ||
| using System.Globalization; | ||
| using Flow.Launcher.Plugin; | ||
| using Flow.Launcher.Plugin.Calculator.Storage; | ||
|
|
||
| namespace Flow.Launcher.Plugin.Calculator | ||
| { | ||
| /// <summary> | ||
| /// Helper class providing utility methods for formatting relative time strings and creating pending history items. | ||
| /// </summary> | ||
| internal static class HistoryHelper | ||
| { | ||
| /// <summary> | ||
| /// Formats a DateTime value into a localized relative time string (e.g. "just now", "5 minutes ago"). | ||
| /// </summary> | ||
| /// <param name="context">The plugin init context used to retrieve localized strings.</param> | ||
| /// <param name="calculatedAt">The time when the calculation was recorded.</param> | ||
| /// <returns>A localized relative time delta string.</returns> | ||
| public static string GetTimeDeltaString(PluginInitContext context, DateTime calculatedAt) | ||
| { | ||
| var now = DateTime.Now; | ||
| var timeSpan = now - calculatedAt; | ||
|
|
||
| if (timeSpan.TotalSeconds < 0) | ||
| { | ||
| timeSpan = TimeSpan.Zero; | ||
| } | ||
|
|
||
| if (timeSpan.TotalSeconds < 60) | ||
| { | ||
| return context == null ? "just now" : Localize.flowlauncher_plugin_calculator_time_just_now(); | ||
| } | ||
| if (timeSpan.TotalMinutes < 60) | ||
| { | ||
| var minutes = (int)timeSpan.TotalMinutes; | ||
| if (minutes == 1) | ||
| { | ||
| return context == null ? "1 minute ago" : Localize.flowlauncher_plugin_calculator_time_minute_ago(); | ||
| } | ||
| return context == null ? $"{minutes} minutes ago" : Localize.flowlauncher_plugin_calculator_time_minutes_ago(minutes); | ||
| } | ||
| if (timeSpan.TotalHours < 24) | ||
| { | ||
| var hours = (int)timeSpan.TotalHours; | ||
| if (hours == 1) | ||
| { | ||
| return context == null ? "1 hour ago" : Localize.flowlauncher_plugin_calculator_time_hour_ago(); | ||
| } | ||
| return context == null ? $"{hours} hours ago" : Localize.flowlauncher_plugin_calculator_time_hours_ago(hours); | ||
| } | ||
| if (timeSpan.TotalDays < 30) | ||
| { | ||
| var days = (int)timeSpan.TotalDays; | ||
| if (days == 1) | ||
| { | ||
| return context == null ? "1 day ago" : Localize.flowlauncher_plugin_calculator_time_day_ago(); | ||
| } | ||
| return context == null ? $"{days} days ago" : Localize.flowlauncher_plugin_calculator_time_days_ago(days); | ||
| } | ||
| if (timeSpan.TotalDays < 365) | ||
| { | ||
| var months = (int)(timeSpan.TotalDays / 30); | ||
| if (months == 1) | ||
| { | ||
| return context == null ? "1 month ago" : Localize.flowlauncher_plugin_calculator_time_month_ago(); | ||
| } | ||
| return context == null ? $"{months} months ago" : Localize.flowlauncher_plugin_calculator_time_months_ago(months); | ||
| } | ||
| var years = (int)(timeSpan.TotalDays / 365); | ||
| if (years == 1) | ||
| { | ||
| return context == null ? "1 year ago" : Localize.flowlauncher_plugin_calculator_time_year_ago(); | ||
| } | ||
| return context == null ? $"{years} years ago" : Localize.flowlauncher_plugin_calculator_time_years_ago(years); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a <see cref="PendingHistoryItem"/> representing a calculation that is currently being typed by the user. | ||
| /// </summary> | ||
| /// <param name="context">The plugin init context.</param> | ||
| /// <param name="result">The query result object.</param> | ||
| /// <param name="calcResult">The text representation of the calculation result.</param> | ||
| /// <param name="expression">The math expression string.</param> | ||
| /// <returns>A new <see cref="PendingHistoryItem"/> instance.</returns> | ||
| public static PendingHistoryItem CreatePendingHistoryItem(PluginInitContext context, Result result, string calcResult, string expression) | ||
| { | ||
| var calculatedAt = DateTime.Now; | ||
| var copyToClipboard = context == null | ||
| ? "Copy this number to the clipboard" | ||
| : Localize.flowlauncher_plugin_calculator_copy_number_to_clipboard(); | ||
| var timeDeltaStr = GetTimeDeltaString(context, calculatedAt); | ||
| var historySubtitle = context == null | ||
| ? string.Format(CultureInfo.CurrentCulture, "Calculated {0}", timeDeltaStr) | ||
| : Localize.flowlauncher_plugin_calculator_history_subtitle(timeDeltaStr); | ||
| var subtitle = | ||
| $"{calcResult} - {copyToClipboard}" + | ||
| $"\n{historySubtitle}"; | ||
| return new PendingHistoryItem(result, expression, result.Action, subtitle, calculatedAt); | ||
| } | ||
| } | ||
| } |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can confirm this is from icons8 which we already give attribution to so is safe to use My concern is that at a small scale its not too readable I found another alternative, which might be slightly more clear - though still not ideal
|
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, could you please revert changes in this file? |

Uh oh!
There was an error while loading. Please reload this page.