private void UpdateWindowTitle() { switch (settings.WindowTitleMode) { case WindowTitleMode.Simple: if (lastWindowTitleMode != settings.WindowTitleMode) { WindowTitle = CreateWindowTitle(); OnPropertyChanged(nameof(WindowTitle)); lastWindowTitleMode = settings.WindowTitleMode; } break; case WindowTitleMode.Version: if (lastWindowTitleMode != settings.WindowTitleMode) { WindowTitle = CreateWindowTitle(); OnPropertyChanged(nameof(WindowTitle)); } break; case WindowTitleMode.ChannelStats: WindowTitle = CreateWindowTitle(); OnPropertyChanged(nameof(WindowTitle)); break; } lastWindowTitleMode = settings.WindowTitleMode; }
/// <summary> /// Sets all of the options from an instance of the <see cref="TimerOptionsInfo"/> class. /// </summary> /// <param name="info">A <see cref="TimerOptionsInfo"/>.</param> public void Set(TimerOptionsInfo info) { if (info == null) { throw new ArgumentNullException("info"); } this.title = info.Title; this.alwaysOnTop = info.AlwaysOnTop; this.promptOnExit = info.PromptOnExit; this.showProgressInTaskbar = info.ShowProgressInTaskbar; this.doNotKeepComputerAwake = info.DoNotKeepComputerAwake; this.showTimeElapsed = info.ShowTimeElapsed; this.loopTimer = info.LoopTimer; this.popUpWhenExpired = info.PopUpWhenExpired; this.closeWhenExpired = info.CloseWhenExpired; this.shutDownWhenExpired = info.ShutDownWhenExpired; //this.theme = Theme.FromIdentifier(info.ThemeIdentifier); this.sound = Sound.FromIdentifier(info.SoundIdentifier); this.loopSound = info.LoopSound; this.windowTitleMode = info.WindowTitleMode; this.windowSize = WindowSize.FromWindowSizeInfo(info.WindowSize); this.lockInterface = info.LockInterface; this.OnPropertyChanged( "Title", "AlwaysOnTop", "PromptOnExit", "ShowProgressInTaskbar", "DoNotKeepComputerAwake", "ShowTimeElapsed", "LoopTimer", "PopUpWhenExpired", "CloseWhenExpired", "ShutDownWhenExpired", "Theme", "Sound", "LoopSound", "WindowTitleMode", "WindowSize", "LockInterface"); }
/// <summary> /// Sets all of the options from another instance of the <see cref="TimerOptions"/> class. /// </summary> /// <param name="options">A <see cref="TimerOptions"/>.</param> public void Set(TimerOptions options) { if (options == null) { throw new ArgumentNullException("options"); } this.title = options.title; this.alwaysOnTop = options.alwaysOnTop; this.promptOnExit = options.promptOnExit; this.showProgressInTaskbar = options.showProgressInTaskbar; this.doNotKeepComputerAwake = options.doNotKeepComputerAwake; this.showTimeElapsed = options.showTimeElapsed; this.loopTimer = options.loopTimer; this.popUpWhenExpired = options.popUpWhenExpired; this.closeWhenExpired = options.closeWhenExpired; this.shutDownWhenExpired = options.shutDownWhenExpired; //this.theme = options.theme; this.sound = options.sound; this.loopSound = options.loopSound; this.windowTitleMode = options.windowTitleMode; this.windowSize = WindowSize.FromWindowSize(options.WindowSize); this.lockInterface = options.lockInterface; this.OnPropertyChanged( "Title", "AlwaysOnTop", "PromptOnExit", "ShowProgressInTaskbar", "DoNotKeepComputerAwake", "ShowTimeElapsed", "LoopTimer", "PopUpWhenExpired", "CloseWhenExpired", "ShutDownWhenExpired", "Theme", "Sound", "LoopSound", "WindowTitleMode", "WindowSize", "LockInterface"); }
/// <summary> /// Initializes a new instance of the <see cref="TimerOptions"/> class. /// </summary> public TimerOptions() { this.title = string.Empty; this.alwaysOnTop = false; this.promptOnExit = true; this.doNotKeepComputerAwake = false; this.showTimeElapsed = false; this.loopTimer = false; this.popUpWhenExpired = true; this.closeWhenExpired = false; this.shutDownWhenExpired = false; this.theme = Theme.DefaultTheme; this.sound = Sound.DefaultSound; this.loopSound = false; this.windowTitleMode = WindowTitleMode.ApplicationName; this.windowSize = new WindowSize( new Rect(double.PositiveInfinity, double.PositiveInfinity, 350, 150), WindowState.Normal, WindowState.Normal, false /* isFullScreen */); }
/// <summary> /// Reads the options from the <see cref="TimerOptions"/> and applies them to this menu. /// </summary> private void UpdateMenuFromOptions() { // Always on top this.alwaysOnTopMenuItem.IsChecked = this.timerWindow.Options.AlwaysOnTop; // Full screen this.fullScreenMenuItem.IsChecked = this.timerWindow.IsFullScreen; // Prompt on exit this.promptOnExitMenuItem.IsChecked = this.timerWindow.Options.PromptOnExit; // Show in notification area this.showInNotificationAreaMenuItem.IsChecked = Settings.Default.ShowInNotificationArea; // Loop timer if (this.timerWindow.Timer.SupportsLooping) { this.loopTimerMenuItem.IsEnabled = true; this.loopTimerMenuItem.IsChecked = this.timerWindow.Options.LoopTimer; } else { this.loopTimerMenuItem.IsEnabled = false; this.loopTimerMenuItem.IsChecked = false; } // Pop up when expired this.popUpWhenExpiredMenuItem.IsChecked = this.timerWindow.Options.PopUpWhenExpired; // Close when expired if ((!this.timerWindow.Options.LoopTimer || !this.timerWindow.Timer.SupportsLooping) && !this.timerWindow.Options.LoopSound) { this.closeWhenExpiredMenuItem.IsChecked = this.timerWindow.Options.CloseWhenExpired; this.closeWhenExpiredMenuItem.IsEnabled = true; } else { this.closeWhenExpiredMenuItem.IsChecked = false; this.closeWhenExpiredMenuItem.IsEnabled = false; } // Theme foreach (MenuItem menuItem in this.selectableThemeMenuItems) { Theme menuItemTheme = (Theme)menuItem.Tag; menuItem.IsChecked = menuItemTheme == this.timerWindow.Options.Theme; if (this.timerWindow.Options.Theme.Type == ThemeType.UserProvided) { menuItem.Visibility = menuItemTheme.Type == ThemeType.BuiltInLight || menuItemTheme.Type == ThemeType.UserProvided ? Visibility.Visible : Visibility.Collapsed; } else { menuItem.Visibility = menuItemTheme.Type == this.timerWindow.Options.Theme.Type || menuItemTheme.Type == ThemeType.UserProvided ? Visibility.Visible : Visibility.Collapsed; } } this.lightThemeMenuItem.IsChecked = this.timerWindow.Options.Theme.Type == ThemeType.BuiltInLight; this.darkThemeMenuItem.IsChecked = this.timerWindow.Options.Theme.Type == ThemeType.BuiltInDark; // Sound foreach (MenuItem menuItem in this.selectableSoundMenuItems) { menuItem.IsChecked = menuItem.Tag == this.timerWindow.Options.Sound; } // Loop sound this.loopSoundMenuItem.IsChecked = this.timerWindow.Options.LoopSound; // Do not keep computer awake this.doNotKeepComputerAwakeMenuItem.IsChecked = this.timerWindow.Options.DoNotKeepComputerAwake; // Open saved timers on startup this.openSavedTimersOnStartupMenuItem.IsChecked = Settings.Default.OpenSavedTimersOnStartup; // Show time elapsed this.showTimeElapsedMenuItem.IsChecked = this.timerWindow.Options.ShowTimeElapsed; // Shut down when expired if ((!this.timerWindow.Options.LoopTimer || !this.timerWindow.Timer.SupportsLooping) && !this.timerWindow.Options.LoopSound) { this.shutDownWhenExpiredMenuItem.IsChecked = this.timerWindow.Options.ShutDownWhenExpired; this.shutDownWhenExpiredMenuItem.IsEnabled = true; } else { this.shutDownWhenExpiredMenuItem.IsChecked = false; this.shutDownWhenExpiredMenuItem.IsEnabled = false; } // Window title foreach (MenuItem menuItem in this.selectableWindowTitleMenuItems) { WindowTitleMode windowTitleMode = (WindowTitleMode)menuItem.Tag; menuItem.IsChecked = windowTitleMode == this.timerWindow.Options.WindowTitleMode; } }
/// <summary> /// Returns the next <see cref="WindowTitleMode"/> value in <paramref name="remainingArgs"/>, or throws an /// exception if <paramref name="remainingArgs"/> is empty or the next argument is not "app", "left", "elapsed", /// "title", or "last". /// </summary> /// <param name="arg">The name of the argument for which the value is to be returned.</param> /// <param name="remainingArgs">The unparsed arguments.</param> /// <param name="last">The value of the argument returned when the user specifies "last".</param> /// <returns>The next <see cref="WindowTitleMode"/> value in <paramref name="remainingArgs"/>.</returns> /// <exception cref="ParseException">If <paramref name="remainingArgs"/> is empty or the next argument is not /// "app", "left", "elapsed", "title", or "last".</exception> private static WindowTitleMode GetWindowTitleModeValue(string arg, Queue <string> remainingArgs, WindowTitleMode last) { string value = GetRequiredValue(arg, remainingArgs); switch (value.ToLowerInvariant()) { case "app": return(WindowTitleMode.ApplicationName); case "left": return(WindowTitleMode.TimeLeft); case "elapsed": return(WindowTitleMode.TimeElapsed); case "title": return(WindowTitleMode.TimerTitle); case "left+title": return(WindowTitleMode.TimeLeftPlusTimerTitle); case "elapsed+title": return(WindowTitleMode.TimeElapsedPlusTimerTitle); case "title+left": return(WindowTitleMode.TimerTitlePlusTimeLeft); case "title+elapsed": return(WindowTitleMode.TimerTitlePlusTimeElapsed); case "last": return(last); default: string message = string.Format( Resources.ResourceManager.GetEffectiveProvider(), Resources.CommandLineArgumentsParseExceptionInvalidValueForSwitchFormatString, arg, value); throw new ParseException(message); } }
/// <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 all of the options from an instance of the <see cref="TimerOptionsInfo"/> class. /// </summary> /// <param name="info">A <see cref="TimerOptionsInfo"/>.</param> public void Set(TimerOptionsInfo info) { if (info == null) { throw new ArgumentNullException("info"); } this.title = info.Title; this.alwaysOnTop = info.AlwaysOnTop; this.promptOnExit = info.PromptOnExit; this.doNotKeepComputerAwake = info.DoNotKeepComputerAwake; this.showTimeElapsed = info.ShowTimeElapsed; this.loopTimer = info.LoopTimer; this.popUpWhenExpired = info.PopUpWhenExpired; this.closeWhenExpired = info.CloseWhenExpired; this.shutDownWhenExpired = info.ShutDownWhenExpired; this.theme = Theme.FromIdentifier(info.ThemeIdentifier); this.sound = Sound.FromIdentifier(info.SoundIdentifier); this.loopSound = info.LoopSound; this.windowTitleMode = info.WindowTitleMode; this.windowSize = WindowSize.FromWindowSizeInfo(info.WindowSize); this.OnPropertyChanged( "Title", "AlwaysOnTop", "PromptOnExit", "DoNotKeepComputerAwake", "ShowTimeElapsed", "LoopTimer", "PopUpWhenExpired", "CloseWhenExpired", "ShutDownWhenExpired", "Theme", "Sound", "LoopSound", "WindowTitleMode", "WindowSize"); }
/// <summary> /// Sets all of the options from another instance of the <see cref="TimerOptions"/> class. /// </summary> /// <param name="options">A <see cref="TimerOptions"/>.</param> public void Set(TimerOptions options) { if (options == null) { throw new ArgumentNullException("options"); } this.title = options.title; this.alwaysOnTop = options.alwaysOnTop; this.promptOnExit = options.promptOnExit; this.doNotKeepComputerAwake = options.doNotKeepComputerAwake; this.showTimeElapsed = options.showTimeElapsed; this.loopTimer = options.loopTimer; this.popUpWhenExpired = options.popUpWhenExpired; this.closeWhenExpired = options.closeWhenExpired; this.shutDownWhenExpired = options.shutDownWhenExpired; this.theme = options.theme; this.sound = options.sound; this.loopSound = options.loopSound; this.windowTitleMode = options.windowTitleMode; this.windowSize = WindowSize.FromWindowSize(options.WindowSize); this.OnPropertyChanged( "Title", "AlwaysOnTop", "PromptOnExit", "DoNotKeepComputerAwake", "ShowTimeElapsed", "LoopTimer", "PopUpWhenExpired", "CloseWhenExpired", "ShutDownWhenExpired", "Theme", "Sound", "LoopSound", "WindowTitleMode", "WindowSize"); }
/// <summary> /// Returns the next <see cref="WindowTitleMode"/> value in <paramref name="remainingArgs"/>, or throws an /// exception if <paramref name="remainingArgs"/> is empty or the next argument is not "app", "left", "elapsed", /// "title", or "last". /// </summary> /// <param name="arg">The name of the argument for which the value is to be returned.</param> /// <param name="remainingArgs">The unparsed arguments.</param> /// <param name="last">The value of the argument returned when the user specifies "last".</param> /// <returns>The next <see cref="WindowTitleMode"/> value in <paramref name="remainingArgs"/>.</returns> /// <exception cref="ParseException">If <paramref name="remainingArgs"/> is empty or the next argument is not /// "app", "left", "elapsed", "title", or "last".</exception> private static WindowTitleMode GetWindowTitleModeValue(string arg, Queue<string> remainingArgs, WindowTitleMode last) { string value = GetRequiredValue(arg, remainingArgs); switch (value.ToLowerInvariant()) { case "app": return WindowTitleMode.ApplicationName; case "left": return WindowTitleMode.TimeLeft; case "elapsed": return WindowTitleMode.TimeElapsed; case "title": return WindowTitleMode.TimerTitle; case "last": return last; default: string message = string.Format( Resources.ResourceManager.GetEffectiveProvider(), Resources.CommandLineArgumentsParseExceptionInvalidValueForSwitchFormatString, arg, value); throw new ParseException(message); } }