/// <summary> /// Shows windows for all saved timers. /// </summary> /// <param name="arguments">Parsed command-line arguments.</param> private static void ShowSavedTimerWindows(CommandLineArguments arguments) { foreach (Timer savedTimer in TimerManager.Instance.ResumableTimers) { TimerWindow window = new TimerWindow(); if (savedTimer.Options.WindowSize != null) { window.Restore(savedTimer.Options.WindowSize, RestoreOptions.AllowMinimized); } else { window.Restore(arguments.GetWindowSize(), RestoreOptions.AllowMinimized); } window.Show(savedTimer); } }
/// <summary> /// Shows a new timer window or windows for all saved timers, depending on whether the <see /// cref="CommandLineArguments"/> specify to open saved timers. /// </summary> /// <param name="arguments">Parsed command-line arguments.</param> private static void ShowTimerWindowsForArguments(CommandLineArguments arguments) { if (arguments.OpenSavedTimers && TimerManager.Instance.ResumableTimers.Any()) { ShowSavedTimerWindows(arguments); if (arguments.TimerStart != null) { ShowNewTimerWindow(arguments); } } else { ShowNewTimerWindow(arguments); } }
/// <summary> /// Sets global options from parsed command-line arguments. /// </summary> /// <param name="arguments">Parsed command-line arguments.</param> private static void SetGlobalSettingsFromArguments(CommandLineArguments arguments) { Settings.Default.ShowInNotificationArea = arguments.ShowInNotificationArea; Settings.Default.OpenSavedTimersOnStartup = arguments.OpenSavedTimers; }
/// <summary> /// Shows a new timer window. The window will run the <see cref="TimerStart"/> specified in the <see /// cref="CommandLineArguments"/>, or it will display in input mode if there is no <see cref="TimerStart"/>. /// </summary> /// <param name="arguments">Parsed command-line arguments.</param> private static void ShowNewTimerWindow(CommandLineArguments arguments) { TimerWindow window = new TimerWindow(arguments.TimerStart); window.Options.Set(arguments.GetTimerOptions()); window.Restore(arguments.GetWindowSize(), RestoreOptions.AllowMinimized); window.Show(); if (window.WindowState != WindowState.Minimized) { window.BringToFrontAndActivate(); } }
/// <summary> /// Parses command-line arguments. /// </summary> /// <param name="args">The command-line arguments.</param> /// <returns>The parsed command-line arguments.</returns> /// <exception cref="ParseException">If the command-line arguments could not be parsed.</exception> private static CommandLineArguments GetCommandLineArguments(IEnumerable <string> args) { CommandLineArguments argumentsBasedOnMostRecentOptions = GetArgumentsFromMostRecentOptions(); CommandLineArguments argumentsBasedOnFactoryDefaults = GetArgumentsFromFactoryDefaults(); bool useFactoryDefaults = false; HashSet <string> specifiedSwitches = new HashSet <string>(); Queue <string> remainingArgs = new Queue <string>(args); while (remainingArgs.Count > 0) { string arg = remainingArgs.Dequeue(); switch (arg) { case "--title": case "-t": ThrowIfDuplicateSwitch(specifiedSwitches, "--title"); string title = GetRequiredValue(arg, remainingArgs); argumentsBasedOnMostRecentOptions.Title = title; argumentsBasedOnFactoryDefaults.Title = title; break; case "--always-on-top": case "-a": ThrowIfDuplicateSwitch(specifiedSwitches, "--always-on-top"); bool alwaysOnTop = GetBoolValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.AlwaysOnTop); argumentsBasedOnMostRecentOptions.AlwaysOnTop = alwaysOnTop; argumentsBasedOnFactoryDefaults.AlwaysOnTop = alwaysOnTop; break; case "--full-screen": case "-f": ThrowIfDuplicateSwitch(specifiedSwitches, "--full-screen"); bool isFullScreen = GetBoolValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.IsFullScreen); argumentsBasedOnMostRecentOptions.IsFullScreen = isFullScreen; argumentsBasedOnFactoryDefaults.IsFullScreen = isFullScreen; break; case "--prompt-on-exit": case "-o": ThrowIfDuplicateSwitch(specifiedSwitches, "--prompt-on-exit"); bool promptOnExit = GetBoolValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.PromptOnExit); argumentsBasedOnMostRecentOptions.PromptOnExit = promptOnExit; argumentsBasedOnFactoryDefaults.PromptOnExit = promptOnExit; break; case "--do-not-keep-awake": case "-k": ThrowIfDuplicateSwitch(specifiedSwitches, "--do-not-keep-awake"); bool doNotKeepComputerAwake = GetBoolValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.DoNotKeepComputerAwake); argumentsBasedOnMostRecentOptions.DoNotKeepComputerAwake = doNotKeepComputerAwake; argumentsBasedOnFactoryDefaults.DoNotKeepComputerAwake = doNotKeepComputerAwake; break; case "--show-time-elapsed": case "-u": ThrowIfDuplicateSwitch(specifiedSwitches, "--show-time-elapsed"); bool showTimeElapsed = GetBoolValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.ShowTimeElapsed); argumentsBasedOnMostRecentOptions.ShowTimeElapsed = showTimeElapsed; argumentsBasedOnFactoryDefaults.ShowTimeElapsed = showTimeElapsed; break; case "--show-in-notification-area": case "-n": ThrowIfDuplicateSwitch(specifiedSwitches, "--show-in-notification-area"); bool showInNotificationArea = GetBoolValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.ShowInNotificationArea); argumentsBasedOnMostRecentOptions.ShowInNotificationArea = showInNotificationArea; argumentsBasedOnFactoryDefaults.ShowInNotificationArea = showInNotificationArea; break; case "--loop-timer": case "-l": ThrowIfDuplicateSwitch(specifiedSwitches, "--loop-timer"); bool loopTimer = GetBoolValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.LoopTimer); argumentsBasedOnMostRecentOptions.LoopTimer = loopTimer; argumentsBasedOnFactoryDefaults.LoopTimer = loopTimer; break; case "--pop-up-when-expired": case "-p": ThrowIfDuplicateSwitch(specifiedSwitches, "--pop-up-when-expired"); bool popUpWhenExpired = GetBoolValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.PopUpWhenExpired); argumentsBasedOnMostRecentOptions.PopUpWhenExpired = popUpWhenExpired; argumentsBasedOnFactoryDefaults.PopUpWhenExpired = popUpWhenExpired; break; case "--close-when-expired": case "-e": ThrowIfDuplicateSwitch(specifiedSwitches, "--close-when-expired"); bool closeWhenExpired = GetBoolValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.CloseWhenExpired); argumentsBasedOnMostRecentOptions.CloseWhenExpired = closeWhenExpired; argumentsBasedOnFactoryDefaults.CloseWhenExpired = closeWhenExpired; break; case "--shut-down-when-expired": case "-x": ThrowIfDuplicateSwitch(specifiedSwitches, "--shut-down-when-expired"); bool shutDownWhenExpired = GetBoolValue( arg, remainingArgs); argumentsBasedOnMostRecentOptions.ShutDownWhenExpired = shutDownWhenExpired; argumentsBasedOnFactoryDefaults.ShutDownWhenExpired = shutDownWhenExpired; break; case "--theme": case "-m": ThrowIfDuplicateSwitch(specifiedSwitches, "--theme"); Theme theme = GetThemeValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.Theme); argumentsBasedOnMostRecentOptions.Theme = theme; argumentsBasedOnFactoryDefaults.Theme = theme; break; case "--sound": case "-s": ThrowIfDuplicateSwitch(specifiedSwitches, "--sound"); Sound sound = GetSoundValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.Sound); argumentsBasedOnMostRecentOptions.Sound = sound; argumentsBasedOnFactoryDefaults.Sound = sound; break; case "--loop-sound": case "-r": ThrowIfDuplicateSwitch(specifiedSwitches, "--loop-sound"); bool loopSound = GetBoolValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.LoopSound); argumentsBasedOnMostRecentOptions.LoopSound = loopSound; argumentsBasedOnFactoryDefaults.LoopSound = loopSound; break; case "--open-saved-timers": case "-v": ThrowIfDuplicateSwitch(specifiedSwitches, "--open-saved-timers"); bool openSavedTimers = GetBoolValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.OpenSavedTimers); argumentsBasedOnMostRecentOptions.OpenSavedTimers = openSavedTimers; argumentsBasedOnFactoryDefaults.OpenSavedTimers = openSavedTimers; break; case "--window-title": case "-i": ThrowIfDuplicateSwitch(specifiedSwitches, "--window-title"); WindowTitleMode windowTitleMode = GetWindowTitleModeValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.WindowTitleMode); argumentsBasedOnMostRecentOptions.WindowTitleMode = windowTitleMode; argumentsBasedOnFactoryDefaults.WindowTitleMode = windowTitleMode; break; case "--window-state": case "-w": ThrowIfDuplicateSwitch(specifiedSwitches, "--window-state"); WindowState windowState = GetWindowStateValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.WindowState); argumentsBasedOnMostRecentOptions.WindowState = windowState; argumentsBasedOnFactoryDefaults.WindowState = windowState; break; case "--window-bounds": case "-b": ThrowIfDuplicateSwitch(specifiedSwitches, "--window-bounds"); Rect windowBounds = GetRectValue( arg, remainingArgs, argumentsBasedOnMostRecentOptions.WindowBounds); argumentsBasedOnMostRecentOptions.WindowBounds = argumentsBasedOnMostRecentOptions.WindowBounds.Merge(windowBounds); argumentsBasedOnFactoryDefaults.WindowBounds = argumentsBasedOnFactoryDefaults.WindowBounds.Merge(windowBounds); break; case "--use-factory-defaults": case "-d": ThrowIfDuplicateSwitch(specifiedSwitches, "--use-factory-defaults"); useFactoryDefaults = true; break; case "--help": case "-h": case "-?": ThrowIfDuplicateSwitch(specifiedSwitches, "--help"); argumentsBasedOnMostRecentOptions.ShouldShowUsage = true; argumentsBasedOnFactoryDefaults.ShouldShowUsage = true; break; default: if (IsSwitch(arg)) { string message = string.Format( Resources.ResourceManager.GetEffectiveProvider(), Resources.CommandLineArgumentsParseExceptionUnrecognizedSwitchFormatString, arg); throw new ParseException(message); } List <string> inputArgs = remainingArgs.ToList(); inputArgs.Insert(0, arg); remainingArgs.Clear(); TimerStart timerStart = GetTimerStartValue(inputArgs); argumentsBasedOnMostRecentOptions.TimerStart = timerStart; argumentsBasedOnFactoryDefaults.TimerStart = timerStart; break; } } return(useFactoryDefaults ? argumentsBasedOnFactoryDefaults : argumentsBasedOnMostRecentOptions); }
/// <summary> /// Sets global options from parsed command-line arguments. /// </summary> /// <param name="arguments">Parsed command-line arguments.</param> private static void SetGlobalSettingsFromArguments(CommandLineArguments arguments) { Settings.Default.ShowInNotificationArea = arguments.ShowInNotificationArea; }
/// <summary> /// Returns a new instance of the <see cref="TimerWindow"/> class for the parsed command-line arguments. /// </summary> /// <param name="arguments">Parsed command-line arguments.</param> /// <returns>A <see cref="TimerWindow"/>.</returns> private static TimerWindow GetTimerWindowFromArguments(CommandLineArguments arguments) { TimerWindow window = new TimerWindow(arguments.TimerStart); window.Options.Set(arguments.GetTimerOptions()); window.Restore(arguments.GetWindowSize(), RestoreOptions.AllowMinimized); return window; }