Permalink
Browse files

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.
  • Loading branch information...
1 parent 1dea64d commit 4f06a48d16de06ebc38c29d5a47e0378f8f6fea3 @rmcardle rmcardle committed Mar 21, 2013
Showing with 43 additions and 14 deletions.
  1. +4 −0 CHANGELOG.TXT
  2. +5 −5 mRemoteV1/Themes/ThemeInfo.vb
  3. +12 −7 mRemoteV1/Themes/ThemeManager.vb
  4. +22 −2 mRemoteV1/Themes/ThemeSerializer.vb
View
@@ -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
@@ -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
@@ -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
+ ' 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
- _activeTheme = value
+ If _activeThemeHandlerSet Then RemoveHandler _activeTheme.PropertyChanged, AddressOf NotifyThemeChanged
- AddHandler _activeTheme.PropertyChanged, AddressOf NotifyThemeChanged
- _activeThemeHandlerSet = True
+ _activeTheme = value
- NotifyThemeChanged(_activeTheme, New PropertyChangedEventArgs(""))
- End If
+ AddHandler _activeTheme.PropertyChanged, AddressOf NotifyThemeChanged
+ _activeThemeHandlerSet = True
+
+ If needNotify Then NotifyThemeChanged(_activeTheme, New PropertyChangedEventArgs(""))
End Set
End Property
#End Region
@@ -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

0 comments on commit 4f06a48

Please sign in to comment.