Fixed: deviation from cocoa when calling setTitle:'' (#2607)

This commit is contained in:
daboe01
2018-08-20 11:40:00 +02:00
committed by Martin Carlberg
parent e7eff3e585
commit 091debd2a7
2 changed files with 25 additions and 2 deletions
+10 -2
View File
@@ -491,9 +491,17 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
if (index < 0)
{
[self addItemWithTitle:aTitle];
index = [self numberOfItems] - 1;
// this ist to match cocoa where setting an empty string does not add it but simply clears the title
// and sets objectValue to -1
if (aTitle === '')
[self selectItemAtIndex:-1];
else
{
[self addItemWithTitle:aTitle];
index = [self numberOfItems] - 1;
}
}
[self selectItemAtIndex:index];
@@ -75,9 +75,24 @@
// https://github.com/280north/cappuccino/pull/1018
[popUpButton2 selectItemWithTag:2];
// manual test for https://github.com/cappuccino/cappuccino/issues/2471
var button2 = [CPButton buttonWithTitle:@"Set title to: ''"];
[button2 setCenter:CGPointMake([contentView center].x, 0)];
[button2 setFrameOrigin:CGPointMake(CGRectGetMinX([button frame]), CGRectGetMaxY([button frame]) + 20)];
[button2 setTarget:self];
[button2 setAction:@selector(setTitleToEmptyString:)];
[contentView addSubview:button2];
[theWindow orderFront:self];
}
- (@action)setTitleToEmptyString:(id)sender
{
[popUpButton setTitle:''];
}
- (@action)removeItems:(id)sender
{
[popUpButton2 removeAllItems];