CPSearchField changes from issue #194

This commit is contained in:
cacaodev authored and Ross Boucher committed 2009-12-03 19:24:43 -08:00
1 parent 44d6139db2
commit 01d60ad4e9
6 files changed
+464 -135

No files matched your search

+146
View File
@@ -0,0 +1,146 @@
/*
* AppController.j
*
* Created by __Me__ on __Date__.
* Copyright 2008 __MyCompanyName__. All rights reserved.
*/
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
var categories = ["firstName","lastName"];
@implementation AppController : CPObject
{
var searchField;
var table;
var tableArray;
var filteredArray;
var searchCategoryIndex;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
searchCategoryIndex = 0;
var theWindow = [[CPWindow alloc] initWithContentRect:CPMakeRect(0,10,500,300) styleMask:CPTitledWindowMask|CPResizableWindowMask],
contentView = [theWindow contentView];
var searchFieldContainer = [[CPView alloc] initWithFrame:CPMakeRect(10,10,220,50)];
[searchFieldContainer setBackgroundColor:[CPColor redColor]];
[searchFieldContainer setAutoresizingMask:CPViewWidthSizable];
searchField = [[CPSearchField alloc] initWithFrame:CPMakeRect(10,10,200,30)];
[searchField setRecentsAutosaveName:"autosave"];
[searchField setTarget:self];
[searchField setAction:@selector(updateFilter:)];
[searchField setAutoresizingMask:CPViewWidthSizable];
var template = [[CPMenu alloc] initWithTitle:@"Search Menu"];
var item;
item = [[CPMenuItem alloc] initWithTitle:@"Search by"
action:nil
keyEquivalent:@""];
[item setEnabled:NO];
[template addItem:item];
item = [[CPMenuItem alloc] initWithTitle:@"First Name"
action:@selector(changeCategory:)
keyEquivalent:@""];
[item setTarget:self];
[item setTag:1];
[template addItem:item];
item = [[CPMenuItem alloc] initWithTitle:@"Last Name"
action:@selector(changeCategory:)
keyEquivalent:@""];
[item setTarget:self];
[item setTag:2];
[template addItem:item];
item = [[CPMenuItem alloc] initWithTitle:@"Recent searches" action:NULL keyEquivalent:@""];
[item setTag:CPSearchFieldRecentsTitleMenuItemTag];
[template addItem:item];
item = [[CPMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
[item setTag:CPSearchFieldRecentsMenuItemTag];
[template addItem:item];
item = [[CPMenuItem alloc] initWithTitle:@"Clear recents" action:NULL keyEquivalent:@""];
[item setTag:CPSearchFieldClearRecentsMenuItemTag];
[template addItem:item];
[searchField setSearchMenuTemplate:template];
[searchFieldContainer addSubview:searchField];
[contentView addSubview:searchFieldContainer];
tableArray = [CPArray arrayWithObjects:
[CPDictionary dictionaryWithObjects:["Jimmy","McNulty",46] forKeys:["firstName","lastName","age"]],
[CPDictionary dictionaryWithObjects:["Kima","Greggs",41] forKeys:["firstName","lastName","age"]],
[CPDictionary dictionaryWithObjects:["Lester","Freamon",57] forKeys:["firstName","lastName","age"]],
[CPDictionary dictionaryWithObjects:["Kevin ","Russel",37] forKeys:["firstName","lastName","age"]],
[CPDictionary dictionaryWithObjects:["William","Moreland",53] forKeys:["firstName","lastName","age"]],
[CPDictionary dictionaryWithObjects:["Cedric","Daniels",47] forKeys:["firstName","lastName","age"]],
[CPDictionary dictionaryWithObjects:["Roland","Pryzbylewski",27] forKeys:["firstName","lastName","age"]],
[CPDictionary dictionaryWithObjects:["Omar","Little",29] forKeys:["firstName","lastName","age"]],
[CPDictionary dictionaryWithObjects:["Avon","Barkstale",49] forKeys:["firstName","lastName","age"]],
nil];
filteredArray = tableArray;
table = [[CPTableView alloc] initWithFrame:CPMakeRect(10,60,300,300)];
[table setUsesAlternatingRowBackgroundColors:YES];
var colone = [[CPTableColumn alloc] initWithIdentifier:@"firstName"];
[colone setWidth:150];
[table addTableColumn:colone];
var coltwo = [[CPTableColumn alloc] initWithIdentifier:@"lastName"];
[coltwo setWidth:150];
[table addTableColumn:coltwo];
[table setDataSource:self];
[contentView addSubview:table];
[self changeCategory:[[searchField menu] itemAtIndex:1]];
[self updateFilter:nil];
[theWindow center];
[theWindow orderFront:self];
}
- (int)numberOfRowsInTableView:(CPTableView)aTableView
{
return [filteredArray count];
}
- (id)tableView:(CPTableView)aTableView objectValueForTableColumn:(CPTableColumn)aTableColumn row:(int)rowIndex
{
return [filteredArray[rowIndex] objectForKey:[aTableColumn identifier]];
}
- (void)changeCategory:(CPMenuItem)menuItem
{
[[[searchField menu] itemArray] makeObjectsPerformSelector:@selector(setState:) withObject:0];
[menuItem setState:1];
searchCategoryIndex = [menuItem tag] - 1;
[searchField setPlaceholderString:[menuItem title]];
}
- (void)updateFilter:(id)sender
{
var searchString = [searchField stringValue];
filteredArray = [self filteredArrayWithString:searchString];
[table reloadData];
}
- (CPArray)filteredArrayWithString:(CPString)string
{
var keyPath = categories[searchCategoryIndex];
CPLogConsole("Filter the table here. Predicate would be *" + keyPath + " CONTAINS '" + string + "'*");
return tableArray;
}
@end
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CPApplicationDelegateClass</key>
<string>AppController</string>
<key>CPBundleName</key>
<string>Hello World</string>
<key>CPPrincipalClass</key>
<string>CPApplication</string>
</dict>
</plist>
+82
View File
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en" lang = "en">
<!--
index-debug.html
Untitled
Created by You on July 30, 2009.
Copyright 2009, Your Company All rights reserved.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>Untitled</title>
<script type = "text/javascript">
OBJJ_MAIN_FILE = "main.j";
OBJJ_INCLUDE_PATHS = ["Frameworks/Debug", "Frameworks", "SomethingElse"];
</script>
<script src = "Frameworks/Debug/Objective-J/Objective-J.js" type = "text/javascript"></script>
<script type = "text/javascript">
// DEBUG OPTIONS:
// Uncomment to enable printing of backtraces on exceptions:
objj_msgSend_decorate(objj_backtrace_decorator);
// Uncomment to enable runtime type checking:
objj_msgSend_decorate(objj_typecheck_decorator);
// Uncomment (along with both above) to print backtraces on type check errors:
objj_typecheck_prints_backtrace = true;
</script>
<style type = "text/css">
body{margin:0; padding:0;}
#container {position: absolute; top:50%; left:50%;}
#content {width:800px; text-align:center; margin-left: -400px; height:50px; margin-top:-25px; line-height: 50px;}
#content {font-family: "Helvetica", "Arial", sans-serif; font-size: 18px; color: black; text-shadow: 0px 1px 0px white; }
#loadgraphic {margin-right: 0.2em; margin-bottom:-2px;}
</style>
<!--[if lt IE 7]>
<STYLE type="text/css">
#container { position: relative; top: 50%; }
#content { position: relative;}
</STYLE>
<![endif]-->
</head>
<body style="">
<div id="loadingcontainer" style=" background-color: #eeeeee; overflow:hidden; width:100%; height:100%; position: absolute; top: 0; left: 0;">
<script type = "text/javascript">
document.write("<div id='container'><p id='content'>" +
"<img id='loadgraphic' width='16' height='16' src='Resources/spinner.gif' /> " +
"Loading Untitled...</p></div>");
</script>
<noscript>
<div id="container">
<div style="width: 440px; padding: 10px 25px 20px 25px; font-family: sans-serif; background-color: #ffffff; position: relative; left: -245px; top: -120px; text-align: center; -moz-border-radius: 20px; -webkit-border-radius: 20px; color: #555555">
<p style="line-height: 1.4em;">JavaScript is required for this site to work correctly but is either disabled or not supported by your browser.</p>
<p style="font-size:120%; padding:10px;"><a href="http://cappuccino.org/noscript">Show me how to enable JavaScript</a></p>
<p style="font-size:80%;">You may want to upgrade to a newer browser while you're at it:</p>
<ul style="margin:0;padding:0; text-align: center; font-size:80%;" >
<li style="display: inline;"><a href="http://www.apple.com/safari/download/">Safari</a></li>
<li style="display: inline;"><a href="http://www.mozilla.com/en-US/firefox/">Firefox</a></li>
<li style="display: inline;"><a href="http://www.google.com/chrome/">Chrome</a></li>
<li style="display: inline;"><a href="http://www.opera.com/download/">Opera</a></li>
<li style="display: inline;"><a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx">Internet Explorer</a></li>
</ul>
</div>
</div>
</noscript>
</div>
</body>
</html>
+36
View File
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en" lang = "en">
<!--
//
// index.html
//
// Created by __Me__ on __Date__.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
-->
<head>
<title>CPSearchField Demo</title>
<script type = "text/javascript">
OBJJ_MAIN_FILE = "main.j";
</script>
<script src = "Frameworks/Objective-J/Objective-J.js" type = "text/javascript"></script>
</head>
<body>
<div style="position: absolute; left: 50%; top: 50%;">
<center>
<img src = "Frameworks/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorSpinningStyleRegular.gif" style="left: -32px; position: relative; top: -32px;" />
</center>
</div>
</body>
</html>
+17
View File
@@ -0,0 +1,17 @@
/*
* main.j
*
* Created by __Me__ on __Date__.
* Copyright 2008 __MyCompanyName__. All rights reserved.
*/
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
@import "AppController.j"
function main(args, namedArgs)
{
CPApplicationMain(args, namedArgs);
}