mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-11 21:27:11 +00:00
Merge branch 'master' of https://github.com/cappuccino/cappuccino
This commit is contained in:
+18
-3
@@ -36,6 +36,15 @@
|
||||
|
||||
@end
|
||||
|
||||
@protocol CPComboBoxDataSource <CPObject>
|
||||
|
||||
@optional
|
||||
- (CPString)comboBox:(CPComboBox)aComboBox completedString:(CPString)uncompletedString;
|
||||
- (id)comboBox:(CPComboBox)aComboBox objectValueForItemAtIndex:(int)index;
|
||||
- (int)comboBox:(CPComboBox)aComboBox indexOfItemWithStringValue:(CPString)stringValue;
|
||||
- (int)numberOfItemsInComboBox:(CPComboBox)aComboBox;
|
||||
|
||||
@end
|
||||
|
||||
CPComboBoxSelectionDidChangeNotification = @"CPComboBoxSelectionDidChangeNotification";
|
||||
CPComboBoxSelectionIsChangingNotification = @"CPComboBoxSelectionIsChangingNotification";
|
||||
@@ -183,7 +192,7 @@ var CPComboBoxTextSubview = @"text",
|
||||
|
||||
#pragma mark Setting a Delegate
|
||||
|
||||
- (id /*< CPComboBoxDelegate >*/)delegate
|
||||
- (id <CPComboBoxDelegate>)delegate
|
||||
{
|
||||
return [super delegate];
|
||||
}
|
||||
@@ -243,7 +252,7 @@ var CPComboBoxTextSubview = @"text",
|
||||
|
||||
#pragma mark Setting a Data Source
|
||||
|
||||
- (id /*< CPComboBoxDataSource >*/)dataSource
|
||||
- (id <CPComboBoxDataSource>)dataSource
|
||||
{
|
||||
if (!_usesDataSource)
|
||||
[self _dataSourceWarningForMethod:_cmd condition:NO];
|
||||
@@ -251,10 +260,12 @@ var CPComboBoxTextSubview = @"text",
|
||||
return _dataSource;
|
||||
}
|
||||
|
||||
- (void)setDataSource:(id /*< CPComboBoxDataSource >*/)aSource
|
||||
- (void)setDataSource:(id <CPComboBoxDataSource>)aSource
|
||||
{
|
||||
if (!_usesDataSource)
|
||||
{
|
||||
[self _dataSourceWarningForMethod:_cmd condition:NO];
|
||||
}
|
||||
else if (_dataSource !== aSource)
|
||||
{
|
||||
if (![aSource respondsToSelector:@selector(numberOfItemsInComboBox:)] ||
|
||||
@@ -263,7 +274,9 @@ var CPComboBoxTextSubview = @"text",
|
||||
CPLog.warn("Illegal %s data source (%s). Must implement numberOfItemsInComboBox: and comboBox:objectValueForItemAtIndex:", [self className], [aSource description]);
|
||||
}
|
||||
else
|
||||
{
|
||||
_dataSource = aSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -906,7 +919,9 @@ var CPComboBoxTextSubview = @"text",
|
||||
index = [_dataSource comboBox:self indexOfItemWithStringValue:stringValue]
|
||||
}
|
||||
else
|
||||
{
|
||||
index = [self indexOfItemWithObjectValue:stringValue];
|
||||
}
|
||||
|
||||
[_listDelegate selectRow:index];
|
||||
|
||||
|
||||
+36
-34
@@ -126,6 +126,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
BOOL _isSelectable;
|
||||
BOOL _isSecure;
|
||||
BOOL _willBecomeFirstResponderByClick;
|
||||
BOOL _invokedByKeyEvent;
|
||||
|
||||
BOOL _drawsBackground;
|
||||
|
||||
@@ -957,7 +958,6 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
if (newValue !== _stringValue)
|
||||
{
|
||||
[self _setStringValue:newValue];
|
||||
|
||||
[self _didEdit];
|
||||
}
|
||||
|
||||
@@ -973,7 +973,11 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
// to override this (escape to clear the text in a search field for example).
|
||||
[[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
|
||||
|
||||
// Set a flag so that key handling methods (such as deleteBackward:)
|
||||
// know they were invoked from a user event.
|
||||
_invokedByKeyEvent = YES;
|
||||
[self interpretKeyEvents:[anEvent]];
|
||||
_invokedByKeyEvent = NO;
|
||||
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
}
|
||||
@@ -1147,12 +1151,17 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
}
|
||||
|
||||
- (void)setObjectValue:(id)aValue
|
||||
{
|
||||
[self _setObjectValue:aValue useFormatter:YES];
|
||||
}
|
||||
|
||||
- (void)_setObjectValue:(id)aValue useFormatter:(BOOL)useFormatter
|
||||
{
|
||||
[super setObjectValue:aValue];
|
||||
|
||||
var formatter = [self formatter];
|
||||
|
||||
if (formatter)
|
||||
if (useFormatter && formatter)
|
||||
{
|
||||
// If there is a formatter, make sure the object value can be formatted successfully
|
||||
var formattedString = [self hasThemeState:CPThemeStateEditing] ? [formatter editingStringForObjectValue:aValue] : [formatter stringForObjectValue:aValue];
|
||||
@@ -1537,7 +1546,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
|
||||
var selectedRange = [self selectedRange];
|
||||
|
||||
if (selectedRange.length < 1)
|
||||
if (selectedRange.length === 0)
|
||||
{
|
||||
if (selectedRange.location < 1)
|
||||
return;
|
||||
@@ -1547,19 +1556,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
selectedRange.length += 1;
|
||||
}
|
||||
|
||||
var newValue = [_stringValue stringByReplacingCharactersInRange:selectedRange withString:""];
|
||||
|
||||
[self setStringValue:newValue];
|
||||
[self setSelectedRange:CPMakeRange(selectedRange.location, 0)];
|
||||
[self _didEdit];
|
||||
|
||||
#if PLATFORM(DOM)
|
||||
// Since we just performed the deletion manually, we don't need the browser to do anything else.
|
||||
// (Previously we would allow the event to propagate for the browser to delete 1 character only,
|
||||
// and we'd delete the rest manually. But this meant that if deleteBackward: was called without
|
||||
// it being a browser backspace event, 1 character would be left behind.)
|
||||
[[[self window] platformWindow] _propagateCurrentDOMEvent:NO];
|
||||
#endif
|
||||
[self _replaceCharactersInRange:selectedRange withCharacters:@""];
|
||||
}
|
||||
|
||||
- (void)delete:(id)sender
|
||||
@@ -1573,16 +1570,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
if (selectedRange.length < 1)
|
||||
return;
|
||||
|
||||
var newValue = [_stringValue stringByReplacingCharactersInRange:selectedRange withString:""];
|
||||
|
||||
[self setStringValue:newValue];
|
||||
[self setSelectedRange:CPMakeRange(selectedRange.location, 0)];
|
||||
[self _didEdit];
|
||||
|
||||
#if PLATFORM(DOM)
|
||||
// Since we just performed the deletion manually, we don't need the browser to do anything else.
|
||||
[[[self window] platformWindow] _propagateCurrentDOMEvent:NO];
|
||||
#endif
|
||||
[self _replaceCharactersInRange:selectedRange withCharacters:@""];
|
||||
}
|
||||
|
||||
- (void)deleteForward:(id)sender
|
||||
@@ -1592,24 +1580,38 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
|
||||
var selectedRange = [self selectedRange];
|
||||
|
||||
if (selectedRange.length < 1)
|
||||
if (selectedRange.length === 0)
|
||||
{
|
||||
if (selectedRange.location + 1 >= _stringValue.length)
|
||||
if (selectedRange.location >= _stringValue.length)
|
||||
return;
|
||||
|
||||
// Delete a single element forward from the insertion point if there's no selection.
|
||||
selectedRange.length += 1;
|
||||
}
|
||||
|
||||
var newValue = [_stringValue stringByReplacingCharactersInRange:selectedRange withString:""];
|
||||
[self _replaceCharactersInRange:selectedRange withCharacters:@""];
|
||||
}
|
||||
|
||||
[self setStringValue:newValue];
|
||||
[self setSelectedRange:CPMakeRange(selectedRange.location, 0)];
|
||||
[self _didEdit];
|
||||
- (void)_replaceCharactersInRange:(CPRange)range withCharacters:(CPString)characters
|
||||
{
|
||||
var newValue = [_stringValue stringByReplacingCharactersInRange:range withString:characters];
|
||||
|
||||
if (_invokedByKeyEvent)
|
||||
{
|
||||
[self _setStringValue:newValue];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self _setObjectValue:newValue useFormatter:NO];
|
||||
[self setSelectedRange:CPMakeRange(range.location, 0)];
|
||||
|
||||
#if PLATFORM(DOM)
|
||||
// Since we just performed the deletion manually, we don't need the browser to do anything else.
|
||||
[[[self window] platformWindow] _propagateCurrentDOMEvent:NO];
|
||||
// Since we just performed the deletion manually, we don't need the browser to do anything else.
|
||||
[[[self window] platformWindow] _propagateCurrentDOMEvent:NO];
|
||||
#endif
|
||||
}
|
||||
|
||||
[self _didEdit];
|
||||
}
|
||||
|
||||
#pragma mark Setting the Delegate
|
||||
|
||||
@@ -61,12 +61,12 @@ var randomFromTo = function(from, to)
|
||||
[recordField setObjectValue:record];
|
||||
}
|
||||
|
||||
- (void)setDate1:(id)sender
|
||||
- (@action)setDate1:(id)sender
|
||||
{
|
||||
[self setDate:dateField1];
|
||||
}
|
||||
|
||||
- (void)setDate2:(id)sender
|
||||
- (@action)setDate2:(id)sender
|
||||
{
|
||||
[self setDate:dateField2];
|
||||
}
|
||||
@@ -78,26 +78,71 @@ var randomFromTo = function(from, to)
|
||||
[field setObjectValue:date];
|
||||
}
|
||||
|
||||
- (void)objectValue1:(id)sender
|
||||
- (@action)objectValue1:(id)sender
|
||||
{
|
||||
CPLog.info("Date 1: %s", [[dateField1 objectValue] description]);
|
||||
}
|
||||
|
||||
- (void)objectValue2:(id)sender
|
||||
- (@action)objectValue2:(id)sender
|
||||
{
|
||||
CPLog.info("Date 2: %s", [[dateField2 objectValue] description]);
|
||||
}
|
||||
|
||||
- (void)setNil:(id)sender
|
||||
- (@action)setNil:(id)sender
|
||||
{
|
||||
[dateField1 setStringValue:nil]; // should log a warning and do nothing
|
||||
}
|
||||
|
||||
- (void)setEmptyOK:(id)sender
|
||||
- (@action)setEmptyOK:(id)sender
|
||||
{
|
||||
[[dateField2 formatter] setEmptyIsValid:[sender state] === CPOnState];
|
||||
}
|
||||
|
||||
- (@action)deleteBackward1:(id)sender
|
||||
{
|
||||
[dateField1 deleteBackward:self];
|
||||
}
|
||||
|
||||
- (@action)deleteBackward2:(id)sender
|
||||
{
|
||||
[dateField2 deleteBackward:self];
|
||||
}
|
||||
|
||||
- (@action)deleteBackward3:(id)sender
|
||||
{
|
||||
[textField deleteBackward:self];
|
||||
}
|
||||
|
||||
- (@action)deleteForward1:(id)sender
|
||||
{
|
||||
[dateField1 deleteForward:self];
|
||||
}
|
||||
|
||||
- (@action)deleteForward2:(id)sender
|
||||
{
|
||||
[dateField2 deleteForward:self];
|
||||
}
|
||||
|
||||
- (@action)deleteForward3:(id)sender
|
||||
{
|
||||
[textField deleteForward:self];
|
||||
}
|
||||
|
||||
- (@action)delete1:(id)sender
|
||||
{
|
||||
[dateField1 delete:self];
|
||||
}
|
||||
|
||||
- (@action)delete2:(id)sender
|
||||
{
|
||||
[dateField2 delete:self];
|
||||
}
|
||||
|
||||
- (@action)delete3:(id)sender
|
||||
{
|
||||
[textField delete:self];
|
||||
}
|
||||
|
||||
- (void)controlTextDidChange:(CPNotification)aNotification
|
||||
{
|
||||
var field = [aNotification object],
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user