/// <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> /// 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> /// 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 a <see cref="Theme"/> that is a copy of another <see cref="Theme"/>. /// </summary> /// <param name="type">The type of this theme.</param> /// <param name="identifier">A unique identifier for this theme.</param> /// <param name="name">The friendly name for this theme, or <c>null</c> if no friendly name is specified.</param> /// <param name="theme">A theme from which to copy colors.</param> /// <returns>A <see cref="Theme"/> that is a copy of another <see cref="Theme"/>.</returns> public static Theme FromTheme(ThemeType type, string identifier, string name, Theme theme) { return new Theme(type, identifier, name, theme); }
/// <summary> /// Sets all of the properties, except for <see cref="Type"/> and <see cref="Identifier"/>, from another /// instance of the <see cref="Theme"/> class. /// </summary> /// <param name="theme">Another instance of the <see cref="Theme"/> class.</param> public void Set(Theme theme) { this.Name = theme.Name; this.BackgroundColor = theme.BackgroundColor; this.ProgressBarColor = theme.ProgressBarColor; this.ProgressBackgroundColor = theme.ProgressBackgroundColor; this.ExpirationFlashColor = theme.ExpirationFlashColor; this.PrimaryTextColor = theme.PrimaryTextColor; this.PrimaryHintColor = theme.PrimaryHintColor; this.SecondaryTextColor = theme.SecondaryTextColor; this.SecondaryHintColor = theme.SecondaryHintColor; this.ButtonColor = theme.ButtonColor; this.ButtonHoverColor = theme.ButtonHoverColor; }
/// <summary> /// Reverts changes to the currently selected theme. /// </summary> private void RevertChanges() { if (this.State == ThemeManagerWindowState.UserThemeEdited) { this.EditedTheme = this.CloneThemeForEditing(this.SelectedTheme); this.State = ThemeManagerWindowState.UserThemeUnedited; this.UnfocusAll(); } }
/// <summary> /// Returns an object that can be set for the <see cref="MenuItem.Header"/> of a <see cref="MenuItem"/> that /// displays a <see cref="Theme"/>. /// </summary> /// <param name="theme">A <see cref="Theme"/>.</param> /// <returns>An object that can be set for the <see cref="MenuItem.Header"/>.</returns> private object GetHeaderForTheme(Theme theme) { Border border = new Border(); border.Background = theme.ProgressBarBrush; border.CornerRadius = new CornerRadius(2); border.Width = 8; border.Height = 8; TextBlock textBlock = new TextBlock(); textBlock.Text = theme.Name ?? Properties.Resources.ContextMenuUnnamedTheme; textBlock.Margin = new Thickness(5, 0, 0, 0); StackPanel stackPanel = new StackPanel(); stackPanel.Orientation = Orientation.Horizontal; stackPanel.Children.Add(border); stackPanel.Children.Add(textBlock); return stackPanel; }
/// <summary> /// Returns the light variant of a theme. /// </summary> /// <param name="theme">A theme.</param> /// <returns>The light variant of the <paramref name="theme"/>.</returns> public Theme GetLightVariantForTheme(Theme theme) { switch (theme.Type) { case ThemeType.BuiltInLight: return theme; case ThemeType.BuiltInDark: return this.GetThemeOrDefaultByIdentifier(theme.Identifier.Replace("-dark", string.Empty)); case ThemeType.UserProvided: return this.DefaultTheme; default: throw new ArgumentException(); } }
/// <summary> /// Removes a theme, and updates any timers using the theme to use the default theme. /// </summary> /// <param name="theme">A <see cref="Theme"/>.</param> public void Remove(Theme theme) { foreach (Timer timer in TimerManager.Instance.Timers.Where(t => t.Options.Theme == theme)) { timer.Options.Theme = this.DefaultTheme; } this.themes.Remove(theme); }
/// <summary> /// Adds a theme based on another theme. /// </summary> /// <param name="theme">A <see cref="Theme"/>.</param> /// <returns>The newly added theme.</returns> public Theme AddThemeBasedOnTheme(Theme theme) { string identifier = Guid.NewGuid().ToString(); string name = Resources.ThemeManagerNewTheme; Theme newTheme = Theme.FromTheme(ThemeType.UserProvided, identifier, name, theme); this.Add(newTheme); return newTheme; }
/// <summary> /// Returns the dark variant of a theme. /// </summary> /// <param name="theme">A theme.</param> /// <returns>The dark variant of the <paramref name="theme"/>.</returns> public Theme GetDarkVariantForTheme(Theme theme) { switch (theme.Type) { case ThemeType.BuiltInLight: return this.GetThemeOrDefaultByIdentifier(theme.Identifier + "-dark"); case ThemeType.BuiltInDark: return theme; case ThemeType.UserProvided: return this.DefaultDarkTheme; default: throw new ArgumentException(); } }
/// <summary> /// Adds a theme. /// </summary> /// <param name="theme">A <see cref="Theme"/>.</param> public void Add(Theme theme) { if (this.GetThemeByIdentifier(theme.Identifier) == null) { this.themes.Add(theme); } }
/// <summary> /// Binds the <see cref="TimerWindow"/> event handlers and controls to a timer. /// </summary> private void BindTimer() { this.Timer.Started += this.TimerStarted; this.Timer.Paused += this.TimerPaused; this.Timer.Resumed += this.TimerResumed; this.Timer.Stopped += this.TimerStopped; this.Timer.Expired += this.TimerExpired; this.Timer.Tick += this.TimerTick; this.Timer.PropertyChanged += this.TimerPropertyChanged; this.Options.PropertyChanged += this.TimerOptionsPropertyChanged; this.theme = this.Options.Theme; this.theme.PropertyChanged += this.ThemePropertyChanged; this.UpdateBoundControls(); }
/// <summary> /// Invoked when a <see cref="TimerOptions"/> property value changes. /// </summary> /// <param name="sender">The <see cref="TimerOptions"/>.</param> /// <param name="e">The event data.</param> private void TimerOptionsPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "Theme") { this.theme.PropertyChanged -= this.ThemePropertyChanged; this.theme = this.Options.Theme; this.theme.PropertyChanged += this.ThemePropertyChanged; } this.UpdateBoundControls(); }
/// <summary> /// Binds the <see cref="TimerWindow"/> to the controls. /// </summary> private void BindTimerWindow() { if (this.timerWindow.Theme.Type == ThemeType.UserProvided) { this.EditedTheme = this.CloneThemeForEditing(this.timerWindow.Theme); this.SelectedTheme = this.timerWindow.Theme; this.State = ThemeManagerWindowState.UserThemeUnedited; } else { this.EditedTheme = this.timerWindow.Theme; this.SelectedTheme = this.timerWindow.Theme; this.State = ThemeManagerWindowState.BuiltInTheme; } }
/// <summary> /// Returns the next <see cref="Theme"/> value in <paramref name="remainingArgs"/>, or throws an exception if /// <paramref name="remainingArgs"/> is empty or the next argument is not "last" or a valid representation of a /// <see cref="Theme"/>. /// </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="Theme"/> value in <paramref name="remainingArgs"/></returns> /// <exception cref="ParseException">If <paramref name="remainingArgs"/> is empty or the next argument is not /// "last" or a valid representation of a <see cref="Theme"/>.</exception> private static Theme GetThemeValue(string arg, Queue<string> remainingArgs, Theme last) { string value = GetRequiredValue(arg, remainingArgs); switch (value.ToLowerInvariant()) { case "last": return last; default: Theme theme = ThemeManager.Instance.GetThemeByIdentifier(value.ToLowerInvariant()) ?? ThemeManager.Instance.GetThemeByName(value, StringComparison.CurrentCultureIgnoreCase); if (theme == null) { string message = string.Format( Resources.ResourceManager.GetEffectiveProvider(), Resources.CommandLineArgumentsParseExceptionInvalidValueForSwitchFormatString, arg, value); throw new ParseException(message); } return theme; } }
/// <summary> /// Clones a theme. This creates a clone of an existing <see cref="Theme"/>, but with a new identifier and a /// <see cref="ThemeType.UserProvided"/> type. /// </summary> /// <param name="theme">A <see cref="Theme"/>.</param> /// <returns>The cloned theme.</returns> private Theme CloneThemeForEditing(Theme theme) { string identifier = Guid.NewGuid().ToString(); return Theme.FromTheme(ThemeType.UserProvided, identifier, theme.Name, theme); }
/// <summary> /// Initializes a new instance of the <see cref="Theme"/> class. /// </summary> /// <param name="type">The type of this theme.</param> /// <param name="identifier">A unique identifier for this theme.</param> /// <param name="name">The friendly name for this theme, or <c>null</c> if no friendly name is specified.</param> /// <param name="theme">A theme from which to copy colors.</param> public Theme(ThemeType type, string identifier, string name, Theme theme) : this(type, identifier, name, theme.backgroundColor, theme.progressBarColor, theme.progressBackgroundColor, theme.expirationFlashColor, theme.primaryTextColor, theme.primaryHintColor, theme.secondaryTextColor, theme.secondaryHintColor, theme.buttonColor, theme.buttonHoverColor) { }
/// <summary> /// Returns a <see cref="ThemeInfo"/> for the specified <see cref="Theme"/>. /// </summary> /// <param name="options">A <see cref="Theme"/>.</param> /// <returns>A <see cref="ThemeInfo"/> for the specified <see cref="Theme"/>.</returns> public static ThemeInfo FromTheme(Theme options) { if (options == null) { return null; } return options.ToThemeInfo(); }
/// <summary> /// Creates a <see cref="MenuItem"/> for a <see cref="Theme"/>. /// </summary> /// <param name="theme">A <see cref="Theme"/>.</param> private void CreateThemeMenuItem(Theme theme) { MenuItem menuItem = new MenuItem(); menuItem.Header = this.GetHeaderForTheme(theme); menuItem.Tag = theme; menuItem.IsCheckable = true; menuItem.Click += this.ThemeMenuItemClick; menuItem.Click += this.CheckableMenuItemClick; this.themeMenuItem.Items.Add(menuItem); this.selectableThemeMenuItems.Add(menuItem); }