Files
cappuccino/Tests/Manual/CPSearchField/AppController.j
T
Aparajita Fishman 2be149c486 Finished theming CPComboBox and reworked related themes...
- Using more logical scheme for widget layout. bezel-inset is inset from frame to the bezel image. border-inset is the inset from the frame to the visible border (if any), which usually is the width of a focus ring. content-inset is the inset from the border rect to the content frame, including the width of the border. This scheme makes it much easier to visualize what is happening, and also makes it possible to ensure a consistent margin between the content and the surrounding bezel border. It also allowed me to remove the funky +1 pixel hack in [CPTextField becomeFirstResponder].

- CPTextField (square and rounded) and CPTokenField had their theme insets reworked to fit the new scheme.

- Added missing disabled bezel for rounded textfield.

- All textfield focus rings look much nicer now (more like Cocoa). Previously the actual border of a textfield would shrink when focused, now it stays the same.

- In CPTokenField, wrapped all references to _inputElement in #if PLATFORM(DOM).

- Placeholder state was not being set correctly because a recent change to [CPTextField _updatePlaceholderState] uses the cached _stringValue instead of [self stringValue]. CPTokenField has its own override now that checks the token count.
2011-08-21 01:40:10 -04:00

136 lines
3.9 KiB
Plaintext

/*
* AppController.j
* CPSearchField
*
* Created by cacaodev on November 27, 2010.
* Copyright 2010, Your Company All rights reserved.
*/
var categories = ["firstName","lastName"],
MenuItemPrefix = @" ";
@implementation AppController : CPObject
{
CPWindow theWindow;
CPTextField predicateField;
CPSearchField searchField;
CPMenu searchMenuTemplate;
CPArray searchCategoryIndexes;
CPInteger searchCategoryIndex;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
searchCategoryIndex = 0;
searchCategoryIndexes = [CPArray arrayWithArray:[1, 2]];
searchField = [[CPSearchField alloc] initWithFrame:CPMakeRect(30, 72, 150, 30)];
[searchField setRecentsAutosaveName:"autosave"];
[searchField setTarget:self];
[searchField setAction:@selector(updateFilter:)];
[searchField setAutoresizingMask:CPViewMaxXMargin | CPViewMaxYMargin];
searchMenuTemplate = [searchField defaultSearchMenuTemplate];
[searchMenuTemplate insertItemWithTitle:@"Search By"
action:nil
keyEquivalent:@""
atIndex:0];
var item = [[CPMenuItem alloc] initWithTitle:MenuItemPrefix + @"First Name"
action:@selector(changeCategory:)
keyEquivalent:@""];
[item setTarget:self];
[item setTag:1];
[item setState:CPOnState];
[searchMenuTemplate insertItem:item atIndex:1];
item = [[CPMenuItem alloc] initWithTitle:MenuItemPrefix + @"Last Name"
action:@selector(changeCategory:)
keyEquivalent:@""];
[item setTarget:self];
[item setTag:2];
[item setState:CPOffState];
[searchMenuTemplate insertItem:item atIndex:2];
[searchField setSearchMenuTemplate:searchMenuTemplate];
var button = [[CPButton alloc] initWithFrame:CGRectMakeZero()];
[button setBackgroundColor:[CPColor greenColor]];
[button setBordered:NO];
[searchField setSearchButton:button];
button = [[CPButton alloc] initWithFrame:CGRectMakeZero()];
[button setBackgroundColor:[CPColor blueColor]];
[button setBordered:NO];
[searchField setCancelButton:button];
[[theWindow contentView] addSubview:searchField];
[self changeCategory:[[searchField menu] itemAtIndex:1]];
[self updateFilter:searchField];
[searchField setDelegate:self];
[theWindow center];
[theWindow orderFront:self];
}
- (void)controlTextDidChange:(id)note
{
CPLogConsole(_cmd);
}
- (void)awakeFromCib
{
[theWindow setBackgroundColor:[CPColor colorWithHexString:@"f3f4f5"]];
[theWindow setFullBridge:YES];
}
- (IBAction)sendsWholeSearchString:(id)sender
{
[searchField setSendsWholeSearchString:[sender state]];
}
- (IBAction)searchesImmediately:(id)sender
{
[searchField setSendsSearchStringImmediately:[sender state]];
}
- (void)changeCategory:(CPMenuItem)menuItem
{
searchCategoryIndex = [menuItem tag] - 1;
[searchField setPlaceholderString:[[menuItem title] substringFromIndex:[MenuItemPrefix length]]];
[self _updateSearchMenuTemplate];
}
- (void)_updateSearchMenuTemplate
{
for (var i = 0; i < searchCategoryIndexes.length; ++i)
[[searchMenuTemplate itemAtIndex:i + 1] setState:CPOffState];
[[searchMenuTemplate itemAtIndex:searchCategoryIndex + 1] setState:CPOnState];
[searchField setSearchMenuTemplate:searchMenuTemplate];
}
- (void)updateFilter:(id)sender
{
var searchString = [sender stringValue];
[self filteredArrayWithString:searchString];
}
- (void)filteredArrayWithString:(CPString)value
{
var keyPath = categories[searchCategoryIndex],
predicate = [CPPredicate predicateWithFormat:@"%K CONTAINS %@", keyPath, value];
[predicateField setStringValue:[predicate predicateFormat]];
}
@end