forked from tomcool420/SMFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SMFCustomQueryMenu.m
158 lines (140 loc) · 3.71 KB
/
SMFCustomQueryMenu.m
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//
// SMFQueryMenu.m
// SMFramework
//
// Created by Thomas Cool on 11/5/10.
// Copyright 2010 tomcool.org. All rights reserved.
//
#import "SMFCustomQueryMenu.h"
#import "SMFMenuItem.h"
#import "SMFMediaPreview.h"
@implementation SMFCustomQueryMenu
@synthesize lastSearchedQuery=_lastSearchedQuery;
@synthesize delegate=_delegate;
@synthesize spinner =_spi;
-(id)init;
{
self=[super init];
_entryControl=[[BRTextEntryControl alloc] initWithTextEntryStyle:2];
[_entryControl setTextFieldDelegate:self];
CGRect f = [BRWindow interfaceFrame];
f.size.width=f.size.width/3.f;
double extra = [BRWindow interfaceFrame].size.width*(1/2.0f-1/3.0f)/2.0f;
f.origin=CGPointMake(extra, 100.0f);
[_entryControl setFrame:f];
[[self list] setDatasource:self];
[_entryControl setHidden:YES];
_spi=[[BRWaitSpinnerControl alloc] init];
CGRect sf=[BRWindow interfaceFrame];
sf.size.width=sf.size.height*0.1;
sf.origin.x=sf.size.width*1.0;
sf.origin.y=sf.size.height-sf.size.width*1.5;
sf.size.height=sf.size.width;
[_spi setFrame:sf];
// BRCursorControl *cc=[[BRCursorControl alloc]init];
// [self addControl:[cc autorelease]];
return self;
}
-(void)layoutSubcontrols
{
[super layoutSubcontrols];
[self addControl:_entryControl];
[self addControl:_spi];
}
-(void)reloadItems
{
[[self list] reload];
}
- (void) textDidChange: (id) sender
{
self.lastSearchedQuery=[[_entryControl textField] stringValue];
[self search:self.lastSearchedQuery];
}
- (void) textDidEndEditing: (id) sender
{
}
-(void)wasPushed
{
[super wasPushed];
}
-(BOOL)brEventAction:(id)action
{
switch ([action remoteAction]) {
case kBREventRemoteActionRight:
{
BRControl *old = [self focusedControl];
BOOL r = [super brEventAction:action];
BRControl *new = [self focusedControl];
if (old==_entryControl && new!=_entryControl) {
[_entryControl setHidden:YES];
[self resetPreviewController];
}
return r;
}
case kBREventRemoteActionLeft:
{
BRControl *old = [self focusedControl];
BOOL r = [super brEventAction:action];
BRControl *new = [self focusedControl];
if (new==_entryControl && old!=_entryControl) {
[_entryControl setHidden:NO];
[self resetPreviewController];
}
return r;
}
break;
default:
break;
}
return [super brEventAction:action];
}
- (long)defaultIndex { return 0;}
-(void)dealloc
{
[_entryControl removeFromParent];
[_entryControl release];
_entryControl=nil;
[super dealloc];
}
#pragma mark methods to overwrite
-(long)itemCount
{
return (long)2;
}
-(void)controlWasActivated
{
long count = [self itemCount];
if (count==0) {
[_entryControl setHidden:NO];
[self setFocusedControl:_entryControl];
}
[super controlWasActivated];
}
-(id)itemForRow:(long)row
{
SMFMenuItem *menuItem= [SMFMenuItem menuItem];
[menuItem setTitle:@"Hello"];
return menuItem;
}
-(id)titleForRow:(long)row
{
return @"Hello";
}
-(void)itemSelected:(long)selected
{
return;
}
- (float)heightForRow:(long)row { return 0.0f;}
- (BOOL)rowSelectable:(long)row { return YES;}
-(void)search:(NSString *)searchString
{
//Do Something
}
-(id)previewControlForItem:(long)item
{
if ([_entryControl isHidden]) {
return [SMFMediaPreview simplePreviewWithTitle:[self titleForRow:item] withSummary:nil withImage:[[BRThemeInfo sharedTheme]appleTVIcon]];
}
return nil;
}
@end