-
-
Notifications
You must be signed in to change notification settings - Fork 622
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
Open
01Dri
wants to merge
18
commits into
Flow-Launcher:dev
Choose a base branch
from
01Dri:feature/history-calc-plugin
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
283cbe4
first implementation of history
01Dri f4ac497
HasCalculationOperator method to just add calc in history if have a o…
01Dri 05eae58
setting to enable or disable history
01Dri e4f5dee
badge in history item and fix some bugs
01Dri dc2dfb7
calculator tests with history
01Dri a7c1f33
validation to add or not result in history
01Dri df72b99
debounce logic to add result in history
01Dri 4fc3016
code quality
01Dri 6d93ce0
fix unit tests and code quality
01Dri ed6cccf
order to remove the last item added
01Dri 83efd29
new modes to save history
01Dri e7d0dd3
query and enter mode
01Dri 0d1b2bb
Merge branch 'dev' into feature/history-calc-plugin
01Dri 2f7f2bb
Update Plugins/Flow.Launcher.Plugin.Calculator/Storage/History.cs
01Dri 264d9ad
code quality after ai review
01Dri a745873
Merge branch 'feature/history-calc-plugin' of https://github.com/01Dr…
01Dri a7efe5d
revert changes pt-br
01Dri 285859d
Change history badge icon to clearer one
DavidGBrett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Plugins/Flow.Launcher.Plugin.Calculator/HistoryCreationMode.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } |
101 changes: 101 additions & 0 deletions
101
Plugins/Flow.Launcher.Plugin.Calculator/HistoryHelper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
| } |
|
DavidGBrett marked this conversation as resolved.
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
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?
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. The recent commit a7efe5d seems intended to revert that but there are still changes showing up for me |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.