Skip to content
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

Lack of a "Save" button/link #25

Merged
merged 4 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The original **Hourglass** FAQ can be found [here](https://chris.dziemborowicz.c
- [How do I save a timer?](#how-do-i-save-a-timer)
- [How do I clear saved timers?](#how-do-i-clear-saved-timers)
- [How do I set a title for a timer?](#how-do-i-set-a-title-for-a-timer)
- [How do I set a time for a timer?](#how-do-i-set-a-time-for-a-timer)
- [How do I change what is displayed in the timer window title?](#how-do-i-change-what-is-displayed-in-the-timer-window-title)
- [How do I change the timer window color theme?](#how-do-i-change-the-timer-window-color-theme)
- [Is there a dark color theme available?](#is-there-a-dark-color-theme-available)
Expand Down Expand Up @@ -291,18 +292,28 @@ And you can set the **Hourglass** to automatically open saved timers when it sta

## How do I save a timer?

A not expired yet timer is saved automatically when closed. See also [How do I resume a timer that I accidentally closed?](#how-do-i-resume-a-timer-that-i-accidentally-closed)
A not expired yet timer is saved automatically when closed if **Save timer on closing** option in the **Advanced options** submenu is checked.
You can change it in the close confirmation dialog shown if the **Prompt on close** in the timer window options menu is checked.

See also [How do I resume a timer that I accidentally closed?](#how-do-i-resume-a-timer-that-i-accidentally-closed)

> [!IMPORTANT]
> All the not expired yet timers are always saved on exit.

## How do I clear saved timers?

`Right Click` on any empty space in the timer window and select **Clear saved timers** from the **Saved timers** submenu.

## How do I set a title for a timer?

Click in the text field that says **Click to enter title**, enter a title and press `Enter`.
Click in the text field that says **Click to enter title** or press `F2`, enter a title and press `Enter`.

To clear a title that you entered, click the title text field, delete the title text and press `Enter`.

## How do I set a time for a timer?

Click in the time field or press `F4`, enter a time and press `Enter` to accept the new time or `Esc` to revert it back. In case of an error the red border will blink for a some time.

## How do I change what is displayed in the timer window title?

By default, the timer window title displays the application name **Hourglass**. You can change it to display the time left, the time elapsed or the timer title instead.
Expand Down
3 changes: 3 additions & 0 deletions Hourglass/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<setting name="OrderByTitleFirst" serializeAs="String">
<value>False</value>
</setting>
<setting name="SaveTimerOnClosing" serializeAs="String">
<value>True</value>
</setting>
</Hourglass.Properties.Settings>
</userSettings>
</configuration>
1 change: 1 addition & 0 deletions Hourglass/AppEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ private static void SetGlobalSettingsFromArguments(CommandLineArguments argument
{
Settings.Default.ShowInNotificationArea = arguments.ShowInNotificationArea;
Settings.Default.OpenSavedTimersOnStartup = arguments.OpenSavedTimers;
Settings.Default.SaveTimerOnClosing = arguments.SaveTimerOnClosing;
Settings.Default.Prefer24HourTime = arguments.Prefer24HourTime;
Settings.Default.ActivateNextWindow = arguments.ActivateNextWindow;
Settings.Default.OrderByTitleFirst = arguments.OrderByTitleFirst;
Expand Down
21 changes: 21 additions & 0 deletions Hourglass/CommandLineArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ public static string Usage
/// </summary>
public bool OpenSavedTimers { get; private set; }

/// <summary>
/// Gets a value indicating whether a timer should be saved on closing.
/// </summary>
public bool SaveTimerOnClosing { get; private set; }

/// <summary>
/// Gets a value indicating whether to prefer interpreting time of day values as 24-hour time.
/// </summary>
Expand Down Expand Up @@ -332,6 +337,7 @@ private static CommandLineArguments GetArgumentsFromMostRecentOptions()
Sound = options.Sound,
LoopSound = options.LoopSound,
OpenSavedTimers = Settings.Default.OpenSavedTimersOnStartup,
SaveTimerOnClosing = Settings.Default.SaveTimerOnClosing,
Prefer24HourTime = Settings.Default.Prefer24HourTime,
ActivateNextWindow = Settings.Default.ActivateNextWindow,
OrderByTitleFirst = Settings.Default.OrderByTitleFirst,
Expand Down Expand Up @@ -377,6 +383,7 @@ private static CommandLineArguments GetArgumentsFromFactoryDefaults()
Sound = defaultOptions.Sound,
LoopSound = defaultOptions.LoopSound,
OpenSavedTimers = false,
SaveTimerOnClosing = true,
Prefer24HourTime = false,
ActivateNextWindow = true,
OrderByTitleFirst = false,
Expand Down Expand Up @@ -717,6 +724,20 @@ private static CommandLineArguments GetCommandLineArguments(IEnumerable<string>
argumentsBasedOnFactoryDefaults.OpenSavedTimers = openSavedTimers;
break;

case "--save-timer-on-closing":
case "-sc":
case "/sc":
ThrowIfDuplicateSwitch(specifiedSwitches, "--save-timer-on-closing");

bool saveTimerOnClosing = GetBoolValue(
arg,
remainingArgs,
argumentsBasedOnMostRecentOptions.SaveTimerOnClosing);

argumentsBasedOnMostRecentOptions.SaveTimerOnClosing = saveTimerOnClosing;
argumentsBasedOnFactoryDefaults.SaveTimerOnClosing = saveTimerOnClosing;
break;

case "--prefer-24h-time":
case "-j":
case "/j":
Expand Down
4 changes: 2 additions & 2 deletions Hourglass/Managers/TimerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public bool SilentMode
/// <see cref="TimerState.Stopped"/>.
/// </summary>
#pragma warning disable S2365
public IReadOnlyCollection<Timer> ResumableTimers => _timers.Where(static t => t.State != TimerState.Stopped && !IsBoundToWindow(t)).ToArray();
public IReadOnlyCollection<Timer> ResumableTimers => _timers.Where(static t => t is { ShouldBeSaved: true, State: not TimerState.Stopped } && !IsBoundToWindow(t)).ToArray();
#pragma warning restore S2365

/// <summary>
Expand All @@ -87,7 +87,7 @@ public override void Initialize()
public override void Persist()
{
Settings.Default.Timers = _timers
.Where(static t => t.State != TimerState.Stopped && t.State != TimerState.Expired)
.Where(static t => t is { ShouldBeSaved: true, State: not TimerState.Stopped and not TimerState.Expired })
.Where(static t => !t.Options.LockInterface)
.Take(MaxSavedTimers)
.ToList();
Expand Down
18 changes: 18 additions & 0 deletions Hourglass/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Hourglass/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,10 @@ $</value>
<value>&amp;Close</value>
<comment>Close task dialog command</comment>
</data>
<data name="SaveTimerTaskDialogText" xml:space="preserve">
<value>Sa&amp;ve this timer</value>
<comment>Save this timer task dialog text</comment>
</data>
<data name="MinimizeWindowCloseTaskDialogCommand" xml:space="preserve">
<value>Mi&amp;nimize</value>
<comment>Minimize task dialog command</comment>
Expand Down Expand Up @@ -1128,6 +1132,10 @@ $</value>
<value>_Open saved timers on startup</value>
<comment>The text for the open saved timers on startup menu item, where the character following the optional underscore (_) is the access key</comment>
</data>
<data name="ContextMenuSaveTimerOnClosingMenuItem" xml:space="preserve">
<value>Sa_ve timer on closing</value>
<comment>The text for the save timer on closing menu item, where the character following the optional underscore (_) is the access key</comment>
</data>
<data name="ContextMenuShowElapsedTimeMenuItem" xml:space="preserve">
<value>_Show elapsed time instead of time left</value>
<comment>The text for the show elapsed time menu item, where the character following the optional underscore (_) is the access key</comment>
Expand Down
14 changes: 13 additions & 1 deletion Hourglass/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Hourglass/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@
<Setting Name="OrderByTitleFirst" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="SaveTimerOnClosing" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
8 changes: 8 additions & 0 deletions Hourglass/Resources/Usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ Options:
Default value last
Alias -v, /v

--save-timer-on-closing on|off|last
Saves the timer on closing.

Required no
Default value last
Alias -sc, /sc

--prefer-24h-time on|off|last
When the input used to start the timer contains a time of day that does
not explicitly specify "am" or "pm", prefer interpreting the input as a
Expand Down Expand Up @@ -351,6 +358,7 @@ Options:
--sound -s normal beep
--loop-sound -r off
--open-saved-timers -v off
--save-timer-on-closing -sc on
--prefer-24h-time -j off
--window-title -i app
--window-state -w normal
Expand Down
5 changes: 5 additions & 0 deletions Hourglass/Timing/TimerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ protected TimerBase(TimerInfo timerInfo)
/// </summary>
public TimerState State { get; private set; } = TimerState.Stopped;

/// <summary>
/// Gets or sets value indicating whether this timer should be saved on closing.
/// </summary>
public bool ShouldBeSaved { get; set; } = true;

/// <summary>
/// Gets the <see cref="DateTime"/> that this timer was started if the <see cref="State"/> is <see
/// cref="TimerState.Running"/> or <see cref="TimerState.Expired"/>, or <c>null</c> otherwise.
Expand Down
19 changes: 19 additions & 0 deletions Hourglass/Windows/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ public sealed class ContextMenu : System.Windows.Controls.ContextMenu
/// </summary>
private MenuItem _openSavedTimersOnStartupMenuItem = null!;

/// <summary>
/// The "Save timer on closing" <see cref="MenuItem"/>.
/// </summary>
private MenuItem _saveTimerOnClosingMenuItem = null!;

/// <summary>
/// The "Display time in the digital clock format" <see cref="MenuItem"/>.
/// </summary>
Expand Down Expand Up @@ -431,6 +436,9 @@ private void UpdateMenuFromOptions()
// Open saved timers on startup
_openSavedTimersOnStartupMenuItem.IsChecked = Settings.Default.OpenSavedTimersOnStartup;

// Save timer on closing
_saveTimerOnClosingMenuItem.IsChecked = Settings.Default.SaveTimerOnClosing;

// Prefer 24-hour time when parsing
_prefer24HourTimeMenuItem.IsChecked = Settings.Default.Prefer24HourTime;

Expand Down Expand Up @@ -536,6 +544,9 @@ private void UpdateOptionsFromMenu()
// Open saved timers on startup
Settings.Default.OpenSavedTimersOnStartup = _openSavedTimersOnStartupMenuItem.IsChecked;

// Save timer on closing
Settings.Default.SaveTimerOnClosing = _saveTimerOnClosingMenuItem.IsChecked;

// Prefer 24-hour time when parsing
Settings.Default.Prefer24HourTime = _prefer24HourTimeMenuItem.IsChecked;

Expand Down Expand Up @@ -923,6 +934,14 @@ private void BuildMenu()
_openSavedTimersOnStartupMenuItem.Click += CheckableMenuItemClick;
advancedOptionsMenuItem.Items.Add(_openSavedTimersOnStartupMenuItem);

// Save timer on closing
_saveTimerOnClosingMenuItem = new CheckableMenuItem
{
Header = Properties.Resources.ContextMenuSaveTimerOnClosingMenuItem
};
_saveTimerOnClosingMenuItem.Click += CheckableMenuItemClick;
advancedOptionsMenuItem.Items.Add(_saveTimerOnClosingMenuItem);

// Prefer 24-hour time when parsing
_prefer24HourTimeMenuItem = new CheckableMenuItem
{
Expand Down
11 changes: 10 additions & 1 deletion Hourglass/Windows/TimerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace Hourglass.Windows;
using System.Windows.Media.Animation;
using System.Windows.Shell;

using KPreisser.UI;

using Extensions;
using Managers;
using Properties;
Expand Down Expand Up @@ -2078,15 +2080,22 @@ private void ConfirmClose()
{
BringToFrontAndActivate();

var saveTimerOnClosingTaskDialogCheckBox = new TaskDialogCheckBox(Properties.Resources.SaveTimerTaskDialogText)
{
Checked = Settings.Default.SaveTimerOnClosing
};

MessageBoxResult result = this.ShowTaskDialog(
Properties.Resources.TimerWindowCloseTaskDialogInstruction,
Properties.Resources.CloseWindowCloseTaskDialogCommand,
Properties.Resources.MinimizeWindowCloseTaskDialogCommand);
Properties.Resources.MinimizeWindowCloseTaskDialogCommand,
saveTimerOnClosingTaskDialogCheckBox);

switch (result)
{
case MessageBoxResult.Yes:
ForceClose = true;
Timer.ShouldBeSaved = saveTimerOnClosingTaskDialogCheckBox.Checked;
Close();
return;
case MessageBoxResult.No:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ ngen-Hourglass.bat uninstall
- New option `--pause-after-loop-timer`, `-pl`, `/pl`
- New option `--order-by-title`, `-ot`, `/ot`
- Renamed option `--prompt-on-exit` to `--prompt-on-close`
- New option `--save-timer-on-closing`, `-sc`, `/sc`

See [command-line usage](https://github.com/i2van/hourglass/blob/develop/Hourglass/Resources/Usage.txt) for details.

Expand Down Expand Up @@ -105,6 +106,8 @@ See [command-line usage](https://github.com/i2van/hourglass/blob/develop/Hourgla
- The `Esc` shortcut minimizes the timer window.
- The `F11` shortcut makes the timer window full screen and back.
- The `Ctrl`+`N` shortcut creates a new timer window.
- The `F2` shortcut edits a timer window title.
- The `F4` shortcut edits a timer window time.

#### Context Menu

Expand All @@ -117,6 +120,7 @@ See [command-line usage](https://github.com/i2van/hourglass/blob/develop/Hourgla
- The **Advanced options** / **Show trigger time** timer window context menu option shows the trigger time in the timer window and in the notification area context menu. The command-line option is `--show-trigger-time`, `-st`, `/st`
- The **Advanced options** / **Activate next window when minimized or closed** timer window context menu option enables the next timer window activation when the current timer window is minimized or closed. The command-line option is `--activate-next`, `-an`, `/an`
- The **Advanced options** / **Order timers by title first then by time left** timer window context menu option orders the timers by the title first then by the time left. The command-line option is `--order-by-title`, `-ot`, `/ot`
- The **Advanced options** / **Save timer on closing** timer window context menu option enables timer window save on closing. The command-line option is `--save-timer-on-closing`, `-sc`, `/sc`
- The **Pause all** timer window context menu command pauses all the running timers. Command-line command is `pause`
- The **Resume all** timer window context menu command resumes all the paused timers. Command-line command is `resume`
- The **Pause after each loop** timer window context menu command pauses the loop timer when it expires. Command-line command is `--pause-after-loop-timer`, `-pl`, `/pl`
Expand Down