| 714 |
iacus |
1 |
/*
|
|
|
2 |
* R.app : a Cocoa front end to: "R A Computer Language for Statistical Data Analysis"
|
|
|
3 |
*
|
|
|
4 |
* R.app Copyright notes:
|
| 1254 |
iacus |
5 |
* Copyright (C) 2004-5 The R Foundation
|
| 714 |
iacus |
6 |
* written by Stefano M. Iacus and Simon Urbanek
|
|
|
7 |
*
|
|
|
8 |
*
|
|
|
9 |
* R Copyright notes:
|
|
|
10 |
* Copyright (C) 1995-1996 Robert Gentleman and Ross Ihaka
|
|
|
11 |
* Copyright (C) 1998-2001 The R Development Core Team
|
|
|
12 |
* Copyright (C) 2002-2004 The R Foundation
|
|
|
13 |
*
|
|
|
14 |
* This program is free software; you can redistribute it and/or modify
|
|
|
15 |
* it under the terms of the GNU General Public License as published by
|
|
|
16 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
17 |
* (at your option) any later version.
|
|
|
18 |
*
|
|
|
19 |
* This program is distributed in the hope that it will be useful,
|
|
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
22 |
* GNU General Public License for more details.
|
|
|
23 |
*
|
|
|
24 |
* A copy of the GNU General Public License is available via WWW at
|
|
|
25 |
* http://www.gnu.org/copyleft/gpl.html. You can also obtain it by
|
|
|
26 |
* writing to the Free Software Foundation, Inc., 59 Temple Place,
|
|
|
27 |
* Suite 330, Boston, MA 02111-1307 USA.
|
|
|
28 |
*/
|
|
|
29 |
|
| 1048 |
urbaneks |
30 |
#import "RGUI.h"
|
| 568 |
iacus |
31 |
#import "HelpManager.h"
|
|
|
32 |
#import "RController.h"
|
| 816 |
urbaneks |
33 |
#import "REngine/REngine.h"
|
| 568 |
iacus |
34 |
|
|
|
35 |
static id sharedHMController;
|
|
|
36 |
|
|
|
37 |
@implementation HelpManager
|
|
|
38 |
|
|
|
39 |
- (id)init
|
|
|
40 |
{
|
|
|
41 |
self = [super init];
|
|
|
42 |
if (self) {
|
|
|
43 |
sharedHMController = self;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
return self;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
- (void)dealloc {
|
|
|
50 |
[super dealloc];
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
- (IBAction)runHelpSearch:(id)sender
|
|
|
54 |
{
|
|
|
55 |
if([[sender stringValue] length]==0)
|
|
|
56 |
return;
|
|
|
57 |
|
| 1136 |
urbaneks |
58 |
NSString *searchString;
|
|
|
59 |
NSCharacterSet *charSet;
|
|
|
60 |
charSet = [NSCharacterSet characterSetWithCharactersInString:@"'\""];
|
|
|
61 |
searchString = [[sender stringValue] stringByTrimmingCharactersInSet:charSet];
|
| 1483 |
urbaneks |
62 |
SLog(@"runHelpSearch: <%@>", searchString);
|
| 1136 |
urbaneks |
63 |
|
|
|
64 |
// [self sendInput:[NSString stringWithFormat:@"help(\"%@\")", searchString]];
|
| 1483 |
urbaneks |
65 |
if(searchType == kFuzzyMatch){
|
| 1136 |
urbaneks |
66 |
[[REngine mainEngine] executeString:[NSString stringWithFormat:@"print(help.search(\"%@\"))", searchString]];
|
| 568 |
iacus |
67 |
[sender setStringValue:@""];
|
|
|
68 |
} else {
|
| 1136 |
urbaneks |
69 |
[self showHelpFor: searchString];
|
| 568 |
iacus |
70 |
}
|
|
|
71 |
}
|
|
|
72 |
|
| 1155 |
urbaneks |
73 |
- (void)showHelpUsingFile: (NSString *)file topic: (NSString*) topic
|
| 1146 |
urbaneks |
74 |
{
|
|
|
75 |
NSString *url = [NSString stringWithFormat:@"file://%@",file];
|
| 1155 |
urbaneks |
76 |
// NSLog(@"showHelpUsingFile:\"%@\", topic=%@, URL=%@", file, topic, url);
|
| 1146 |
urbaneks |
77 |
if(url != nil)
|
|
|
78 |
[[HelpView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
|
|
|
79 |
[helpWindow makeKeyAndOrderFront:self];
|
|
|
80 |
}
|
|
|
81 |
|
| 1136 |
urbaneks |
82 |
- (void)showHelpFor:(NSString *)topic
|
|
|
83 |
{
|
|
|
84 |
NSString *searchString;
|
|
|
85 |
NSCharacterSet *charSet;
|
|
|
86 |
charSet = [NSCharacterSet characterSetWithCharactersInString:@"'\""];
|
|
|
87 |
searchString = [topic stringByTrimmingCharactersInSet:charSet];
|
|
|
88 |
// NSLog(@"showHelpFor: <%@>", searchString);
|
|
|
89 |
|
|
|
90 |
REngine *re = [REngine mainEngine];
|
|
|
91 |
RSEXP *x= [re evaluateString:[NSString stringWithFormat:@"as.character(help(\"%@\", htmlhelp=TRUE))",searchString]];
|
|
|
92 |
if ((x==nil) || ([x string]==NULL)) {
|
|
|
93 |
NSString *topicString = [[[NSString alloc] initWithString: @"Topic: "] stringByAppendingString:searchString];
|
|
|
94 |
int res = NSRunInformationalAlertPanel(NLS(@"Can't find help for topic, would you like to expand the search?"), topicString, NLS(@"No"), NLS(@"Yes"), nil);
|
|
|
95 |
if (!res)
|
|
|
96 |
[[REngine mainEngine] executeString:[NSString stringWithFormat:@"print(help.search(\"%@\"))", searchString]];
|
|
|
97 |
return;
|
|
|
98 |
}
|
|
|
99 |
NSString *url = [NSString stringWithFormat:@"file://%@",[x string]];
|
|
|
100 |
if(url != nil)
|
|
|
101 |
[[HelpView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
|
| 1490 |
urbaneks |
102 |
|
| 1136 |
urbaneks |
103 |
[helpWindow makeKeyAndOrderFront:self];
|
|
|
104 |
[x release];
|
|
|
105 |
}
|
|
|
106 |
|
| 1490 |
urbaneks |
107 |
- (NSWindow*) window
|
|
|
108 |
{
|
|
|
109 |
return helpWindow;
|
|
|
110 |
}
|
|
|
111 |
|
| 568 |
iacus |
112 |
- (IBAction)showMainHelp:(id)sender
|
|
|
113 |
{
|
|
|
114 |
REngine *re = [REngine mainEngine];
|
|
|
115 |
RSEXP *x = [re evaluateString:@"try(getOption(\"main.help.url\"))"];
|
|
|
116 |
|
|
|
117 |
if ((x==nil) | ([x string]==nil)){
|
|
|
118 |
[re executeString:@"try(main.help.url())"];
|
|
|
119 |
[x release];
|
|
|
120 |
x = [re evaluateString:@"try(getOption(\"main.help.url\"))"];
|
|
|
121 |
if((x == nil) | ([x string]==nil)){
|
|
|
122 |
[x release];
|
|
|
123 |
return;
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
NSString *url = [x string];
|
|
|
128 |
|
|
|
129 |
if(url != nil)
|
|
|
130 |
[[HelpView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
|
|
|
131 |
[helpWindow makeKeyAndOrderFront:self];
|
|
|
132 |
[x release];
|
|
|
133 |
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
- (IBAction)showRFAQ:(id)sender
|
|
|
137 |
{
|
| 1361 |
urbaneks |
138 |
NSString *url = [[NSBundle mainBundle] resourcePath];
|
|
|
139 |
if (!url) {
|
|
|
140 |
REngine *re = [REngine mainEngine];
|
|
|
141 |
RSEXP *x= [re evaluateString:@"file.path(R.home(),\"RMacOSX-FAQ.html\")"];
|
|
|
142 |
if(x==nil)
|
|
|
143 |
return;
|
|
|
144 |
url = [x string];
|
|
|
145 |
[x release];
|
|
|
146 |
if (url) url = [NSString stringWithFormat:@"file://%@", url];
|
|
|
147 |
} else
|
|
|
148 |
url = [NSString stringWithFormat:@"file://%@/RMacOSX-FAQ.html", url];
|
| 568 |
iacus |
149 |
|
| 1361 |
urbaneks |
150 |
if(url != nil) {
|
| 568 |
iacus |
151 |
[[HelpView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
|
| 1361 |
urbaneks |
152 |
[helpWindow makeKeyAndOrderFront:self];
|
|
|
153 |
}
|
| 568 |
iacus |
154 |
}
|
|
|
155 |
|
|
|
156 |
- (IBAction)whatsNew:(id)sender
|
|
|
157 |
{
|
|
|
158 |
REngine *re = [REngine mainEngine];
|
| 1422 |
urbaneks |
159 |
RSEXP *x= [re evaluateString:@"file.show(file.path(R.home(),\"NEWS\"))"];
|
| 568 |
iacus |
160 |
if(x==nil)
|
|
|
161 |
return;
|
|
|
162 |
[x release];
|
|
|
163 |
}
|
|
|
164 |
|
| 796 |
urbaneks |
165 |
+ (id) sharedController{
|
| 568 |
iacus |
166 |
return sharedHMController;
|
|
|
167 |
}
|
|
|
168 |
|
| 824 |
urbaneks |
169 |
- (IBAction)printDocument:(id)sender
|
|
|
170 |
{
|
|
|
171 |
NSPrintInfo *printInfo;
|
|
|
172 |
NSPrintInfo *sharedInfo;
|
|
|
173 |
NSPrintOperation *printOp;
|
|
|
174 |
NSMutableDictionary *printInfoDict;
|
|
|
175 |
NSMutableDictionary *sharedDict;
|
|
|
176 |
|
|
|
177 |
sharedInfo = [NSPrintInfo sharedPrintInfo];
|
|
|
178 |
sharedDict = [sharedInfo dictionary];
|
|
|
179 |
printInfoDict = [NSMutableDictionary dictionaryWithDictionary:
|
|
|
180 |
sharedDict];
|
|
|
181 |
|
|
|
182 |
printInfo = [[NSPrintInfo alloc] initWithDictionary: printInfoDict];
|
|
|
183 |
[printInfo setHorizontalPagination: NSFitPagination];
|
|
|
184 |
[printInfo setVerticalPagination: NSAutoPagination];
|
|
|
185 |
[printInfo setVerticallyCentered:NO];
|
|
|
186 |
|
|
|
187 |
printOp = [NSPrintOperation printOperationWithView:[[[HelpView mainFrame] frameView] documentView]
|
|
|
188 |
printInfo:printInfo];
|
|
|
189 |
[printOp setShowPanels:YES];
|
|
|
190 |
[printOp runOperation];
|
|
|
191 |
}
|
| 568 |
iacus |
192 |
|
| 1483 |
urbaneks |
193 |
- (void) setSearchType:(int) type
|
|
|
194 |
{
|
|
|
195 |
if (type==kFuzzyMatch || type==kExactMatch) {
|
|
|
196 |
NSMenu *m = [(NSSearchFieldCell*)searchField searchMenuTemplate];
|
|
|
197 |
|
|
|
198 |
searchType = type;
|
|
|
199 |
[[m itemWithTag:kFuzzyMatch] setState:(searchType==kFuzzyMatch)?NSOnState:NSOffState];
|
|
|
200 |
[[m itemWithTag:kExactMatch] setState:(searchType==kExactMatch)?NSOnState:NSOffState];
|
|
|
201 |
[(NSSearchFieldCell*)searchField setSearchMenuTemplate:m];
|
|
|
202 |
}
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
- (void) awakeFromNib
|
|
|
206 |
{
|
|
|
207 |
[self setSearchType:kExactMatch];
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
- (IBAction)changeSearchType:(id)sender
|
|
|
211 |
{
|
|
|
212 |
[self setSearchType:[sender tag]];
|
|
|
213 |
}
|
|
|
214 |
|
| 965 |
urbaneks |
215 |
- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
|
|
|
219 |
[back setEnabled: [sender canGoBack]];
|
|
|
220 |
[forward setEnabled: [sender canGoForward]];
|
|
|
221 |
}
|
|
|
222 |
|
| 568 |
iacus |
223 |
@end
|