Fix an exception or crash when choosing unnamed colors for themes.

Fix possible error "Control does not support transparent background colors" when modifying themes.
Fix changes to the active theme not being saved reliably.
This commit is contained in:
Riley McArdle
2013-03-20 22:20:58 -05:00
parent 1dea64d2eb
commit 4f06a48d16
4 changed files with 45 additions and 16 deletions

View File

@@ -1,3 +1,7 @@
Fixed an exception or crash when choosing unnamed colors for themes.
Fixed possible error "Control does not support transparent background colors" when modifying themes.
Fixed changes to the active theme not being saved reliably.
1.71 Beta 3 (2013-03-20):
Fixed issue MR-397 - Putty disappears from the screen
Fixed issue MR-398 - Full Screen mode doesn't correctly make use of available space

View File

@@ -114,7 +114,7 @@ Namespace Themes
Return _toolbarBackgroundColor
End Get
Set(value As Color)
If _toolbarBackgroundColor = value Then Return
If _toolbarBackgroundColor = value Or value.A < 255 Then Return
_toolbarBackgroundColor = value
NotifyPropertyChanged("ToolbarBackgroundColor")
End Set
@@ -147,7 +147,7 @@ Namespace Themes
Return _connectionsPanelBackgroundColor
End Get
Set(value As Color)
If _connectionsPanelBackgroundColor = value Or value = Color.Transparent Then Return
If _connectionsPanelBackgroundColor = value Or value.A < 255 Then Return
_connectionsPanelBackgroundColor = value
NotifyPropertyChanged("ConnectionsPanelBackgroundColor")
End Set
@@ -192,7 +192,7 @@ Namespace Themes
Return _searchBoxBackgroundColor
End Get
Set(value As Color)
If _searchBoxBackgroundColor = value Or value = Color.Transparent Then Return
If _searchBoxBackgroundColor = value Or value.A < 255 Then Return
_searchBoxBackgroundColor = value
NotifyPropertyChanged("SearchBoxBackgroundColor")
End Set
@@ -239,7 +239,7 @@ Namespace Themes
Return _configPanelBackgroundColor
End Get
Set(value As Color)
If _configPanelBackgroundColor = value Or value = Color.Transparent Then Return
If _configPanelBackgroundColor = value Or value.A < 255 Then Return
_configPanelBackgroundColor = value
NotifyPropertyChanged("ConfigPanelBackgroundColor")
End Set
@@ -284,7 +284,7 @@ Namespace Themes
Return _configPanelHelpBackgroundColor
End Get
Set(value As Color)
If _configPanelHelpBackgroundColor = value Or value = Color.Transparent Then Return
If _configPanelHelpBackgroundColor = value Or value.A < 255 Then Return
_configPanelHelpBackgroundColor = value
NotifyPropertyChanged("ConfigPanelHelpBackgroundColor")
End Set

View File

@@ -73,16 +73,21 @@ Namespace Themes
Return _activeTheme
End Get
Set(value As ThemeInfo)
If _activeTheme Is Nothing OrElse Not _activeTheme.Equals(value) Then
If _activeThemeHandlerSet Then RemoveHandler _activeTheme.PropertyChanged, AddressOf NotifyThemeChanged
_activeTheme = value
AddHandler _activeTheme.PropertyChanged, AddressOf NotifyThemeChanged
_activeThemeHandlerSet = True
NotifyThemeChanged(_activeTheme, New PropertyChangedEventArgs(""))
' We need to set ActiveTheme to the new theme to make sure it references the right object.
' However, if both themes have the same properties, we don't need to raise a notification event.
Dim needNotify As Boolean = True
If _activeTheme IsNot Nothing Then
If _activeTheme.Equals(value) Then needNotify = False
End If
If _activeThemeHandlerSet Then RemoveHandler _activeTheme.PropertyChanged, AddressOf NotifyThemeChanged
_activeTheme = value
AddHandler _activeTheme.PropertyChanged, AddressOf NotifyThemeChanged
_activeThemeHandlerSet = True
If needNotify Then NotifyThemeChanged(_activeTheme, New PropertyChangedEventArgs(""))
End Set
End Property
#End Region

View File

@@ -39,7 +39,7 @@ Namespace Themes
color = propertyInfo.GetValue(themeInfo, Nothing)
xmlTextWriter.WriteStartElement("Color")
xmlTextWriter.WriteAttributeString("Name", propertyInfo.Name)
xmlTextWriter.WriteAttributeString("Value", color.Name)
xmlTextWriter.WriteAttributeString("Value", EncodeColorName(color))
xmlTextWriter.WriteEndElement() ' Color
Next
@@ -91,12 +91,32 @@ Namespace Themes
colorValue = colorNode.Attributes("Value").Value
propertyInfo = themeType.GetProperty(colorName)
If propertyInfo Is Nothing OrElse Not propertyInfo.PropertyType Is colorType Then Continue For
propertyInfo.SetValue(themeInfo, Color.FromName(colorValue), Nothing)
propertyInfo.SetValue(themeInfo, DecodeColorName(colorValue), Nothing)
Next
themes.Add(themeInfo)
Next
Return themes
End Function
Private Shared Function EncodeColorName(ByVal color As Color) As String
If color.IsNamedColor Then
Return color.Name
Else
Dim argb As Integer = color.ToArgb()
Dim hexValue As String = Hex(argb)
Dim paddedHex As String = hexValue.PadLeft(8, "0")
Return paddedHex
End If
End Function
Private Shared Function DecodeColorName(ByVal name As String) As Color
Dim regex As New System.Text.RegularExpressions.Regex("^[0-9a-fA-F]{8}$")
If regex.Match(name).Success Then
Return Color.FromArgb(Convert.ToInt32(name, 16))
Else
Return Color.FromName(name)
End If
End Function
End Class
End Namespace