lethain / mahou

A Cappuccino, Yahoo! BOSS, and Google App Engine based web search

This URL has Read+Write access

mahou / static / WLTextField.j
100644 41 lines (32 sloc) 0.815 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import <Foundation/CPObject.j>
import <AppKit/CPTextField.j>
 
@implementation WLTextField : CPTextField
{
  CPString placeholderString;
}
 
-(CPString) stringValue {
  var s = [super stringValue];
  if ([s caseInsensitiveCompare:placeholderString]==0) {
    return @"";
  }
  return s;
}
 
-(BOOL)becomeFirstResponder {
  if ([[self stringValue] caseInsensitiveCompare:[self placeholderString]]==0) {
    [self setStringValue:@""];
  }
  return [super becomeFirstResponder];
}
 
-(BOOL)resignFirstResponder {
  if ([[self stringValue] caseInsensitiveCompare:@""]==0) {
    [self setStringValue:[self placeholderString]];
  }
  return [super resignFirstResponder];
}
 
-(void)setPlaceholderString: (CPString)aString {
  placeholderString = aString;
}
 
-(CPString)placeholderString {
  return placeholderString;
}
 
 
@end