From ba9df402b09711e9968bdea3fd2df6daafea94e9 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Thu, 9 Sep 2010 11:57:29 -0700 Subject: [PATCH] Use a CPTextField for hex input in CPSliderColorPicker The old DOM based field only accepted a few characters, and not even hex chars. Backspace and other expected functionality was broken. Switching to a CPTextField makes it behave as expected. --- AppKit/CPSliderColorPicker.j | 50 ++++++++++++------------------------ 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/AppKit/CPSliderColorPicker.j b/AppKit/CPSliderColorPicker.j index 6c02cfb16..14d911bdc 100644 --- a/AppKit/CPSliderColorPicker.j +++ b/AppKit/CPSliderColorPicker.j @@ -47,6 +47,7 @@ CPTextField _saturationLabel; CPTextField _brightnessLabel; CPTextField _hexLabel; + CPTextField _hexValue; #if PLATFORM(DOM) DOMElement _redValue; @@ -55,7 +56,6 @@ DOMElement _hueValue; DOMElement _saturationValue; DOMElement _brightnessValue; - DOMElement _hexValue; #endif } @@ -273,36 +273,13 @@ [_hexLabel setStringValue: "Hex"]; [_hexLabel setTextColor:[CPColor blackColor]]; -#if PLATFORM(DOM) //hex input box - _hexValue = _redValue.cloneNode(false); - _hexValue.style.top = "228px"; - _hexValue.style.width = "80px"; - _hexValue.style.left = "35px"; - _hexValue.onkeypress = function(aDOMEvent) - { - aDOMEvent = aDOMEvent || window.event; - if (aDOMEvent.keyCode == 13) - { - var newColor = [CPColor colorWithHexString: this.value]; - - if(newColor) - { - [self setColor: newColor]; - [[self colorPanel] setColor: newColor]; - } - - if(aDOMEvent.preventDefault) - aDOMEvent.preventDefault(); - else if(aDOMEvent.stopPropagation) - aDOMEvent.stopPropagation(); - - this.blur(); - } - }; - - _contentView._DOMElement.appendChild(_hexValue); -#endif + _hexValue = [CPTextField textFieldWithStringValue: @"" placeholder: @"" width: 80]; + [_hexValue setFrameOrigin: CGPointMake(32, 225)]; + [_hexValue setEditable: YES]; + [_hexValue setBezeled: YES]; + [_hexValue setDelegate: self]; + [_contentView addSubview: _hexValue]; [_contentView addSubview: _rgbLabel]; [_contentView addSubview: _redLabel]; @@ -394,9 +371,7 @@ - (void)updateHex:(CPColor)aColor { -#if PLATFORM(DOM) - _hexValue.value = [aColor hexString]; -#endif + [_hexValue setStringValue:[aColor hexString]]; } - (void)updateRGBSliders:(CPColor)aColor @@ -431,4 +406,13 @@ return [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:CPColorPicker] pathForResource:"slider_button_h.png"] size:CGSizeMake(32, 32)]; } +- (void)controlTextDidEndEditing:(CPNotification)aNotification +{ + var newColor = [CPColor colorWithHexString:[[_hexValue stringValue] stringByTrimmingWhitespace]]; + if (newColor) { + [self setColor: newColor]; + [[self colorPanel] setColor: newColor]; + } +} + @end