Skip to content

Commit

Permalink
* Today's work
Browse files Browse the repository at this point in the history
  • Loading branch information
PWagner1 committed Feb 8, 2023
1 parent 89388f1 commit ea0da9b
Show file tree
Hide file tree
Showing 8 changed files with 473 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Krypton.Ribbon
{
public class KryptonRibbonGroupThemeComboBox : KryptonRibbonGroupComboBox
{
#region Instance Fields
private readonly ICollection<string> _supportedThemesNames;
private int _selectedIndex;
#endregion

#region Public

/// <summary>
/// Helper, to return a new list of names
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public List<string> SupportedThemesList => _supportedThemesNames.ToList();

/// <summary>
/// Gets and sets the ThemeSelectedIndex.
/// </summary>
[Category(@"Visuals")]
[Description(@"Theme Selected Index. (Default = `Office 365 - Blue`)")]
[DefaultValue(33)]
public int ThemeSelectedIndex
{
get => _selectedIndex;

set => SelectedIndex = value;
}

private void ResetThemeSelectedIndex() => _selectedIndex = 33;

private bool ShouldSerializeThemeSelectedIndex() => _selectedIndex != 33;

/// <summary>
/// Gets and sets the ThemeSelectedIndex.
/// </summary>
[Category(@"Visuals")]
[Description(@"Custom Theme to use when `Custom` is selected")]
[DefaultValue(null)]
public KryptonCustomPaletteBase KryptonCustomPalette { get; set; }

[EditorBrowsable(EditorBrowsableState.Never)]
public KryptonManager Manager
{
get;

} = new();

#endregion

#region Identity

/// <summary>Initializes a new instance of the <see cref="KryptonRibbonGroupThemeComboBox" /> class.</summary>
public KryptonRibbonGroupThemeComboBox()
{
DropDownStyle = ComboBoxStyle.DropDownList;

_supportedThemesNames = RibbonThemeManager.SupportedInternalThemeNames;

_selectedIndex = 33;

Items.AddRange(_supportedThemesNames.ToArray());

SelectedIndex = _selectedIndex;
}

#endregion

#region Implementation

/// <summary>Returns the palette mode.</summary>
/// <returns>
/// <br />
/// </returns>
public PaletteMode ReturnPaletteMode() => Manager.GlobalPaletteMode;

#endregion

#region Protected Overrides

protected override void OnSelectedIndexChanged(EventArgs e)
{
RibbonThemeManager.ApplyTheme(Text, Manager);

ThemeSelectedIndex = SelectedIndex;

base.OnSelectedIndexChanged(e);
if ((RibbonThemeManager.GetThemeManagerMode(Text) == PaletteMode.Custom) && (KryptonCustomPalette != null))
{
Manager.GlobalPalette = KryptonCustomPalette;
}
}


#endregion

#region Removed Designer visibility



#endregion
}
}
224 changes: 182 additions & 42 deletions Source/Krypton Components/Krypton.Ribbon/Palette/RibbonThemeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,105 @@ namespace Krypton.Ribbon
/// </summary>
public class RibbonThemeManager
{
#region Methods
#region Theme Array
/// <summary>
/// Propagates the theme selector.
/// The supported themes
/// </summary>
/// <param name="target">The target.</param>
public static void PropagateThemeSelector(KryptonRibbonGroupComboBox target)
{
foreach (var theme in ThemeManager.SupportedInternalThemeNames)
// TODO: This should use the list from Z:\GitHub\Krypton-Suite\Standard-Toolkit\Source\Krypton Components\Krypton.Toolkit\Converters\PaletteModeConverter.cs
private static readonly BiDictionary<string, PaletteMode> _supportedThemes = new(new Dictionary<string, PaletteMode>
{
target.Items.Add(theme);
}
}
{ @"Professional - System", PaletteMode.ProfessionalSystem },
{ @"Professional - Office 2003", PaletteMode.ProfessionalOffice2003 },
{ @"Office 2007 - Blue", PaletteMode.Office2007Blue },
{ @"Office 2007 - Blue (Dark Mode)", PaletteMode.Office2007BlueDarkMode },
{ @"Office 2007 - Blue (Light Mode)", PaletteMode.Office2007BlueLightMode },
{ @"Office 2007 - Silver", PaletteMode.Office2007Silver },
{ @"Office 2007 - Silver (Dark Mode)", PaletteMode.Office2007SilverDarkMode },
{ @"Office 2007 - Silver (Light Mode)", PaletteMode.Office2007SilverLightMode },
{ @"Office 2007 - White", PaletteMode.Office2007White },
{ @"Office 2007 - Black", PaletteMode.Office2007Black },
{ @"Office 2007 - Black (Dark Mode)", PaletteMode.Office2007BlackDarkMode },
{ @"Office 2007 - Dark Gray", PaletteMode.Office2007DarkGray },
{ @"Office 2010 - Blue", PaletteMode.Office2010Blue },
{ @"Office 2010 - Blue (Dark Mode)", PaletteMode.Office2010BlueDarkMode },
{ @"Office 2010 - Blue (Light Mode)", PaletteMode.Office2010BlueLightMode },
{ @"Office 2010 - Silver", PaletteMode.Office2010Silver },
{ @"Office 2010 - Silver (Dark Mode)", PaletteMode.Office2010SilverDarkMode },
{ @"Office 2010 - Silver (Light Mode)", PaletteMode.Office2010SilverLightMode },
{ @"Office 2010 - White", PaletteMode.Office2010White },
{ @"Office 2010 - Black", PaletteMode.Office2010Black },
{ @"Office 2010 - Black (Dark Mode)", PaletteMode.Office2010BlackDarkMode },
{ @"Office 2010 - Dark Gray", PaletteMode.Office2010DarkGray },
{ @"Office 2013 - Dark Gray", PaletteMode.Office2013DarkGray },
//{ @"Office 2013", PaletteMode.Office2013 },
{ @"Office 2013 - White", PaletteMode.Office2013White },
{ @"Sparkle - Blue", PaletteMode.SparkleBlue },
{ @"Sparkle - Blue (Dark Mode)", PaletteMode.SparkleBlueDarkMode },
{ @"Sparkle - Blue (Light Mode)", PaletteMode.SparkleBlueLightMode },
{ @"Sparkle - Orange", PaletteMode.SparkleOrange },
{ @"Sparkle - Orange (Dark Mode)", PaletteMode.SparkleOrangeDarkMode },
{ @"Sparkle - Orange (Light Mode)", PaletteMode.SparkleOrangeLightMode },
{ @"Sparkle - Purple", PaletteMode.SparklePurple },
{ @"Sparkle - Purple (Dark Mode)", PaletteMode.SparklePurpleDarkMode },
{ @"Sparkle - Purple (Light Mode)", PaletteMode.SparklePurpleLightMode },
{ @"Microsoft 365 - Blue", PaletteMode.Microsoft365Blue },
{ @"Microsoft 365 - Blue (Dark Mode)", PaletteMode.Microsoft365BlueDarkMode },
{ @"Microsoft 365 - Blue (Light Mode)", PaletteMode.Microsoft365BlueLightMode },
{ @"Microsoft 365 - Silver", PaletteMode.Microsoft365Silver },
{ @"Microsoft 365 - Silver (Dark Mode)", PaletteMode.Microsoft365SilverDarkMode },
{ @"Microsoft 365 - Silver (Light Mode)", PaletteMode.Microsoft365SilverLightMode },
{ @"Microsoft 365 - White", PaletteMode.Microsoft365White },
{ @"Microsoft 365 - Black", PaletteMode.Microsoft365Black },
{ @"Microsoft 365 - Black (Dark Mode)", PaletteMode.Microsoft365BlackDarkMode },
{ @"Microsoft 365 - Dark Gray", PaletteMode.Microsoft365DarkGray },
{ @"Custom", PaletteMode.Custom }
});

#endregion

#region Public

/// <summary>
/// Propagates the theme selector.
/// Gets the supported theme array.
/// </summary>
/// <param name="target">The target.</param>
public static void PropagateThemeSelector(KryptonRibbonGroupDomainUpDown target)
/// <value>
/// The supported theme array.
/// </value>
public static ICollection<string> SupportedInternalThemeNames => _supportedThemes.GetAllFirsts();

#endregion

#region Implementation

/// <summary>
/// Applies the theme.
/// </summary>
/// <param name="mode">The mode.</param>
/// <param name="manager">The manager.</param>
private static void ApplyTheme(PaletteMode mode, KryptonManager manager) => manager.GlobalPaletteMode = mode;

/// <summary>Gets the palette mode.</summary>
/// <param name="manager">The manager.</param>
/// <returns>The current <see cref="PaletteMode"/>.</returns>
public static PaletteMode GetPaletteMode(KryptonManager manager) => ReturnPaletteMode(manager.GlobalPaletteMode);

private static PaletteMode ReturnPaletteMode(string themeName)
{
foreach (var theme in ThemeManager.SupportedInternalThemeNames)
{
target.Items.Add(theme);
}
// Note: Needs to be filled out
return PaletteMode.Custom;
}

#region Built-in Redundancy
/// <summary>Returns the palette mode.</summary>
/// <param name="paletteMode">The palette mode manager.</param>
/// <returns>The selected <see cref="PaletteMode"/>.</returns>
private static PaletteMode ReturnPaletteMode(PaletteMode paletteMode) => paletteMode;

/// <summary>
/// Gets the current palette mode.
/// Applies the theme.
/// </summary>
/// <param name="themeName">Name of the theme.</param>
/// <param name="manager">The manager.</param>
/// <returns>The current <see cref="PaletteMode"/>.</returns>
public static PaletteMode GetCurrentPaletteMode(KryptonManager manager) => manager.GlobalPaletteMode;
public static void ApplyTheme(string themeName, KryptonManager manager) => ApplyTheme(_supportedThemes.GetByFirst(themeName), manager);

/// <summary>
/// Sets the theme.
Expand All @@ -57,62 +124,135 @@ public static void PropagateThemeSelector(KryptonRibbonGroupDomainUpDown target)
/// <param name="manager">The manager.</param>
public static void SetTheme(string themeName, KryptonManager manager)
{
ThemeManager.SetTheme(themeName, manager);
try
{
ApplyTheme(themeName, manager);

ApplyGlobalTheme(manager, GetPaletteMode(manager));
}
catch (Exception exc)
{
ExceptionHandler.CaptureException(exc);
}
}

/// <summary>
/// Returns the palette mode manager as string.
/// </summary>
/// <param name="paletteMode">The palette mode manager.</param>
/// <param name="manager">The manager.</param>
/// <returns>The current <see cref="PaletteMode"/> as a string.</returns>
/// <returns>The chosen theme as a string.</returns>
public static string ReturnPaletteModeAsString(PaletteMode paletteMode, KryptonManager manager = null)
{
return ThemeManager.ReturnPaletteModeAsString(paletteMode, manager);
var mode = manager?.GlobalPaletteMode ?? paletteMode;

return _supportedThemes.GetBySecond(mode);
}

/// <summary>
/// Applies the global theme.
/// Loads the custom theme.
/// </summary>
/// <param name="palette">The palette.</param>
/// <param name="manager">The manager.</param>
/// <param name="paletteMode">The palette mode manager.</param>
private static void ApplyGlobalTheme(KryptonManager manager, PaletteMode paletteMode)
/// <param name="themeFile">A custom theme file.</param>
/// <param name="silent">if set to <c>true</c> [silent].</param>
public static void LoadCustomTheme(KryptonCustomPaletteBase palette, KryptonManager manager, string themeFile = "", bool silent = false)
{
try
{
manager.GlobalPaletteMode = paletteMode;
//throw new ApplicationException(@"Currently not implemented correctly");

// Declare new instances
palette = new KryptonCustomPaletteBase();

manager = new KryptonManager();

// Prompt user for palette definition

// TODO: Add silent option
if (silent)
{
if (themeFile is not ("" and ""))
{
palette.Import(themeFile, silent);
}
}
else
{
palette.Import();
}

// Set manager
manager.GlobalPalette = palette;

ApplyTheme(PaletteMode.Custom, manager);
}
catch
catch (Exception exc)
{
// TODO: Used DebugUtilities
throw;
ExceptionHandler.CaptureException(exc);
}
}

/// <summary>
/// Applies the theme mode.
/// Returns the palette mode as string.
/// </summary>
/// <param name="themeName">Name of the theme.</param>
/// <returns>The <see cref="PaletteMode"/> equivalent.</returns>
public static PaletteMode ApplyThemeMode(string themeName)
/// <param name="paletteMode">The palette mode.</param>
/// <returns></returns>
public static string ReturnPaletteModeAsString(PaletteMode paletteMode)
{
PaletteMode mode = (PaletteMode)Enum.Parse(typeof(PaletteMode), themeName);
PaletteModeConverter modeConverter = new();

return mode;
return modeConverter.ConvertToString(paletteMode);
}

/// <summary>
/// Applies the global theme.
/// </summary>
/// <param name="manager">The manager.</param>
/// <param name="paletteMode">The palette mode manager.</param>
public static void ApplyGlobalTheme(KryptonManager manager, PaletteMode paletteMode)
{
try
{
manager.GlobalPaletteMode = paletteMode;
}
catch (Exception exc)
{
ExceptionHandler.CaptureException(exc);
}
}

private static void AddToCollection(IList target, string[] excludes)
{
try
{
foreach (var theme in SupportedInternalThemeNames)
{
if (!excludes.Any(t => theme.IndexOf(t, StringComparison.InvariantCultureIgnoreCase) > -1))
{
target.Add(theme);
}
}
}
catch (Exception exc)
{
ExceptionHandler.CaptureException(exc);
}
}

/// <summary>
/// Applies the theme manager mode.
/// </summary>
/// <param name="themeName">Name of the theme.</param>
/// <returns>The <see cref="PaletteMode"/> equivalent.</returns>
public static PaletteMode ApplyThemeManagerMode(string themeName)
{
PaletteMode modeManager = (PaletteMode)Enum.Parse(typeof(PaletteMode), themeName);
public static PaletteMode GetThemeManagerMode(string themeName) => _supportedThemes.GetByFirst(themeName);

return modeManager;
}
#endregion
/// <summary>
/// Propagates the theme selector.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="excludePartials">do not include any string containing</param>
public static void PropagateThemeSelector(KryptonRibbonGroupThemeComboBox target, params string[] excludePartials) => AddToCollection(target.Items, excludePartials);

#endregion
}
Expand Down
Loading

0 comments on commit ea0da9b

Please sign in to comment.