-
Notifications
You must be signed in to change notification settings - Fork 7
/
RController.h
348 lines (262 loc) · 11.5 KB
/
RController.h
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/*
* R.app : a Cocoa front end to: "R A Computer Language for Statistical Data Analysis"
*
* R.app Copyright notes:
* Copyright (C) 2004-5 The R Foundation
* written by Stefano M. Iacus and Simon Urbanek
*
*
* R Copyright notes:
* Copyright (C) 1995-1996 Robert Gentleman and Ross Ihaka
* Copyright (C) 1998-2001 The R Development Core Team
* Copyright (C) 2002-2004 The R Foundation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* A copy of the GNU General Public License is available via WWW at
* http://www.gnu.org/copyleft/gpl.html. You can also obtain it by
* writing to the Free Software Foundation, Inc., 59 Temple Place,
* Suite 330, Boston, MA 02111-1307 USA.
*
* $Id: RController.h 8064 2022-04-02 23:14:19Z urbaneks $
*/
#import "RGUI.h"
#include <R.h>
#include <Rinternals.h>
#include "REngine/Rcallbacks.h"
#include <R_ext/eventloop.h>
#import <sys/types.h>
#import "CCComp.h"
#import <WebKit/WebKit.h>
#import "Tools/History.h"
#import "Tools/ConnectionCache.h"
#import "PrefPanes/PrefWindowController.h"
#define RToolbarIdentifier @"R Toolbar Identifier"
#define FontSizeToolbarItemIdentifier @"Font Size Item Identifier"
#define NewEditWinToolbarItemIdentifier @"New Edit Window Item Identifier"
#define SaveDocToolbarItemIdentifier @"Save R ConsoleWindow Item Identifier"
#define SourceRCodeToolbarIdentifier @"Source/Load R Code Identifier"
#define InterruptToolbarItemIdentifier @"Interrupt Computation Item Identifier"
#define NewQuartzToolbarItemIdentifier @"New Quartz Device Item Identifier"
#define LoadFileInEditorToolbarItemIdentifier @"Load File in Editor Item Identifier"
#define AuthenticationToolbarItemIdentifier @"Authentication Item Identifier"
#define ShowHistoryToolbarItemIdentifier @"Show History Item Identifier"
#define QuitRToolbarItemIdentifier @"Quit R Item Identifier"
#define X11ToolbarItemIdentifier @"X11 Item Identifier"
#define SetColorsToolbarItemIdentifier @"SetColors Item Identifier"
#import "AMPrefs/AMPreferenceWindowController.h"
#import "Preferences.h"
#import "PreferenceKeys.h"
#import "RTextView.h"
#import "RConsoleTextStorage.h"
#import "RProgressIndicator.h"
// R defines "error" which is deadly as we use open ... with ... error: where error then gets replaced by Rf_error
#ifdef error
#undef error
#endif
@interface RController : NSObject <REPLHandler, CocoaHandler, PreferencesDependent, NSTextStorageDelegate, NSToolbarDelegate>
{
IBOutlet RTextView *consoleTextView;
IBOutlet RProgressIndicator *progressWheel;
IBOutlet NSTableView *historyView; /* TableView for the package manager */
IBOutlet NSTextField *WDirView; /* Mini-TextField for the working directory */
IBOutlet NSSearchField *helpSearch; /* help search field */
IBOutlet NSButton *clearHistory;
IBOutlet NSButton *loadHistory;
IBOutlet NSButton *saveHistory;
IBOutlet NSButton *deleteEntry;
IBOutlet NSDrawer *HistoryDrawer;
IBOutlet NSWindow *RConsoleWindow;
IBOutlet NSTextField *statusLine;
IBOutlet NSSearchField *searchInWebViewSearchField;
IBOutlet NSPanel *searchInWebViewSheet;
IBOutlet NSMenu *reinterpretEncodingMenu;
IBOutlet NSSearchField *historySearchField;
WebView *currentWebViewForFindAction;
id searchInWebViewWindow;
NSTimer *timer;
NSTimer *RLtimer;
NSTimer *Flushtimer;
NSTimer *WDirtimer;
History *hist;
NSToolbar *toolbar;
NSToolbarItem *toolbarStopItem;
RConsoleTextStorage *textStorage; /* the global Console textStorage */
NSString *textViewSync;
NSString *requestSaveAction;
IBOutlet NSStepper *fontSizeStepper;
IBOutlet NSTextField *fontSizeField;
IBOutlet NSView *fontSizeView;
IBOutlet PrefWindowController *prefsCtrl;
unsigned committedLength; // any text before this position cannot be edited by the user
unsigned promptPosition; // the last prompt is positioned at this position
unsigned outputPosition; // any output (stdxx or consWrite) is to be place here, if -1 then the text can be appended
int outputOverwrite; // length of text that can be overwriten on output
NSUInteger lastCommittedLength;
int stdoutFD;
int stderrFD;
int rootFD;
pid_t childPID;
BOOL runSystemAsRoot;
BOOL busyRFlag;
BOOL appLaunched;
BOOL argsHints;
int currentConsoleWidth;
char *readConsTransBuffer; // transfer buffer returned by handeReadConsole
int readConsTransBufferSize; // size of the above buffer
NSMutableArray *consoleColors;
NSArray *consoleColorsKeys;
NSArray *defaultConsoleColors;
NSArray *filteredHistory;
NSMutableArray *consoleInputQueue;
NSString *currentConsoleInput;
BOOL forceStdFlush;
BOOL terminating;
BOOL processingEvents;
BOOL breakPending;
BOOL isREditMode;
BOOL ignoreMagnifyingEvent;
char *writeBuffer;
char *writeBufferPos;
int writeBufferLen;
int writeBufferType;
NSCharacterSet *specialCharacters;
NSString *lastShownWD; // holds current directory after it has been shown (in non-abreviated form)
NSMutableArray *pendingDocsToOpen; // paths of documents to open once initialized
NSString *home;
NSString *lastFunctionForHint;
NSString *lastFunctionHintText;
NSString *appSupportPath;
NSMenuItem *toggleFullScreenMenuItem;
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
#define USE_APPNAP_API
@property (strong) id activity;
#endif
+ (NSString*) userLibraryPath;
/* process pending events. if blocking is set to YES then the method waits indefinitely for one event. otherwise only pending events are processed. */
- (void) doProcessEvents: (BOOL) blocking;
- (void) addChildProcess: (pid_t) pid;
- (void) rmChildProcess: (pid_t) pid;
- (void) setRootFlag: (BOOL) flag;
- (BOOL) getRootFlag;
- (void) setRootFD: (int) fd;
- (BOOL) textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector;
- (BOOL) textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString;
/* write to the console bypassing any cache buffers - for internal use only! */
- (void) writeConsoleDirectly: (NSString*) text withColor: (NSColor*) color;
/* sendInput is an alias for "consoleInput: text interactive: YES" */
- (void) sendInput: (NSString*) text;
/* replace the current console input with the "cmd" string. if "inter" is set to YES, then the input is immediatelly committed, otherwise it is only written to the input area, but not committed. Int tje interactive mode an optimization is made to not display the content before commit, because the lines are displayed as they are processed anyway. */
- (void) consoleInput: (NSString*) cmd interactive: (BOOL) inter;
- (IBAction)otherEventLoops:(id)sender;
- (IBAction)flushconsole:(id)sender;
-(IBAction) fontSizeBigger:(id)sender;
-(IBAction) fontSizeSmaller:(id)sender;
-(IBAction) changeFontSize:(id)sender;
- (void) fontSizeChangedBy:(float)delta withSender:(id)sender;
-(IBAction) getWorkingDir:(id)sender;
-(IBAction) resetWorkingDir:(id)sender;
-(IBAction) setWorkingDir:(id)sender;
-(IBAction) showWorkingDir:(id)sender;
-(IBAction) runX11:(id)sender;
-(IBAction) openColors:(id)sender;
-(IBAction) checkForUpdates:(id)sender;
-(IBAction) showVignettes:(id)sender;
-(IBAction) clearConsole:(id)sender;
-(IBAction) toggleFullScreenMode:(id)sender;
-(IBAction) searchInHistory:(id)sender;
-(IBAction) activateSearchInHistory:(id)sender;
- (int) numberOfRowsInTableView: (NSTableView *)tableView;
- (id) tableView: (NSTableView *)tableView
objectValueForTableColumn: (NSTableColumn *)tableColumn
row: (int)row;
- (int) quitRequest: (int) saveFlag withCode: (int) code last: (int) runLast;
- (IBAction)doClearHistory:(id)sender;
- (IBAction)doLoadHistory:(id)sender;
- (IBAction)doSaveHistory:(id)sender;
- (IBAction)historyDoubleClick:(id)sender;
- (IBAction)historyDeleteEntry:(id)sender;
- (IBAction)newQuartzDevice:(id)sender;
- (IBAction)breakR:(id)sender;
- (IBAction)quitR:(id)sender;
- (IBAction)toggleHistory:(id)sender;
- (IBAction)toggleAuthentication:(id)sender;
- (IBAction)installFromBinary:(id)sender;
- (IBAction)installFromDir:(id)sender;
- (IBAction)installFromSource:(id)sender;
- (IBAction)togglePackageInstaller:(id)sender;
- (IBAction)openDocument:(id)sender;
- (IBAction)customizeEncodingList:(id)sender;
- (IBAction)loadWorkSpace:(id)sender;
- (IBAction)loadWorkSpaceFile:(id)sender;
- (IBAction)saveWorkSpace:(id)sender;
- (IBAction)saveWorkSpaceFile:(id)sender;
- (IBAction)clearWorkSpace:(id)sender;
- (IBAction)showWorkSpace:(id)sender;
- (IBAction)togglePackageManager:(id)sender;
- (IBAction)toggleDataManager:(id)sender;
- (IBAction)toggleWSBrowser:(id)sender;
- (IBAction)performHelpSearch:(id)sender;
- (IBAction)editObject:(id)sender;
- (IBAction)sourceFile:(id)sender;
- (IBAction)sourceOrLoadFile:(id)sender;
- (IBAction)makeConsoleKey:(id)sender;
- (IBAction)makeLastQuartzKey:(id)sender;
- (IBAction)makeLastEditorKey:(id)sender;
- (void) shouldClearWS:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
- (void) addConnectionLog;
- (void) writeLogsWithBytes: (char*) buf length: (int) len type: (int) outputType;
- (void) openHelpFor: (char*) topic;
- (void)setupToolbar;
- (int) isImageData:(NSString *)fname;
- (void) loadFile:(NSString *)fname;
- (void) RConsoleDidResize: (NSNotification *)notification;
- (void) setOptionWidth:(BOOL)force;
- (IBAction) setDefaultColors:(id)sender;
+ (RController*) sharedController;
- (NSView*) searchToolbarView;
- (void) flushROutput;
- (void) flushTimerHook: (NSTimer*) source; // hook for flush timer
- (void) handleWriteConsole: (NSString *)txt;
- (void) handleWritePrompt: (NSString *)prompt;
- (void) handleProcessEvents;
- (void) handleFlushConsole;
- (void) handleBusy: (BOOL)i;
- (int) handleChooseFile: (char *)buf len:(int)len isNew:(int)isNew;
- (void) handlePromptRdFileAtPath: (NSString*)filepath isTempFile:(BOOL)isTempFile;
- (void) setStatusLineText: (NSString*) text;
- (NSString*) statusLineText;
- (BOOL) hintForFunction: (NSString*) fn;
- (NSFont*) currentFont;
- (NSWindow*) window;
- (NSTextView *)getRTextView;
- (NSWindow *)getRConsoleWindow;
- (BOOL)appLaunched;
- (NSString*) home;
- (NSString*) currentWorkingDirectory;
- (NSString*)getAppSupportPath;
- (int) helpServerPort;
- (BOOL)isREditMode;
- (void)ignoreMagnifyingEventTimer;
- (IBAction)performFindPanelAction:(id)sender;
- (IBAction)performFindPanelFindInWebViewAction:(id)sender;
- (IBAction)closeFindInWebViewSheet:(id)sender;
- (void)resizeSearchInWebViewWindow:(NSNotification*)aNotification;
- (BOOL)windowShouldClose:(id)sender;
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
- (void)updateReInterpretEncodingMenu;
- (void) helpSearchTypeChanged;
- (NSUInteger)lastCommittedLength;
// Service methods
- (void)doPerformServiceRunInConsole:(NSPasteboard *)pboard userData:(NSString *)data error:(NSString **)error;
- (void)doPerformServiceOpenRScript:(NSPasteboard *)pboard userData:(NSString *)data error:(NSString **)error;
@end