Skip to content

Commit 95a4e43

Browse files
author
Hans-Jörg Bibiko
committed
• initial commit to support "Rd Documention File" editing; not yet fully implemented but workable
- Rd files are assigned to R.app - Rd file editor has its own toolbar and added "HTML Preview" - Rd file will be parsed to build section list for pop-menu in toolbar (same approach as for function list of R files) ... work in progress git-svn-id: https://svn.r-project.org/R-packages/trunk/Mac-GUI@5993 694ef91d-65df-0310-b7bb-92e67a308ead
1 parent 36f5f51 commit 95a4e43

13 files changed

+504
-55
lines changed

HelpManager.h

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
- (void)setSearchType:(int)type;
6666
- (int)searchType;
6767

68+
- (void)showHelpFileForURL:(NSURL*)url;
69+
6870
- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame;
6971

7072
@end

HelpManager.m

+10
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ + (id) sharedController{
256256
return sharedHMController;
257257
}
258258

259+
- (void)showHelpFileForURL:(NSURL*)url
260+
{
261+
if(url != nil) {
262+
[[HelpView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
263+
[helpWindow makeKeyAndOrderFront:self];
264+
return;
265+
}
266+
NSBeep();
267+
}
268+
259269
- (IBAction)printDocument:(id)sender
260270
{
261271
NSPrintInfo *printInfo;

Info.plist

+21
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@
2828
<key>NSDocumentClass</key>
2929
<string>RDocument</string>
3030
</dict>
31+
<dict>
32+
<key>CFBundleTypeExtensions</key>
33+
<array>
34+
<string>Rd</string>
35+
<string>rd</string>
36+
</array>
37+
<key>CFBundleTypeIconFile</key>
38+
<string>Rdoc.icns</string>
39+
<key>CFBundleTypeName</key>
40+
<string>Rd Documentation File</string>
41+
<key>CFBundleTypeOSTypes</key>
42+
<array>
43+
<string>****</string>
44+
</array>
45+
<key>CFBundleTypeRole</key>
46+
<string>Editor</string>
47+
<key>LSIsAppleDefaultForType</key>
48+
<true/>
49+
<key>NSDocumentClass</key>
50+
<string>RDocument</string>
51+
</dict>
3152
<dict>
3253
<key>CFBundleTypeName</key>
3354
<string>Quartz Graphics</string>

R.xcodeproj/project.pbxproj

+17
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@
196196
BC53A82013BDB5ED009488EE /* NSArray_RAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = BC53A81E13BDB5ED009488EE /* NSArray_RAdditions.h */; };
197197
BC53A82113BDB5ED009488EE /* NSArray_RAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = BC53A81F13BDB5ED009488EE /* NSArray_RAdditions.m */; };
198198
BC81712F13321873004B52A0 /* SelectEncodingsPanel.xib in Resources */ = {isa = PBXBuildFile; fileRef = BC81712D13321873004B52A0 /* SelectEncodingsPanel.xib */; };
199+
BC884B6B14BAD86C00DEFFE0 /* RdEditorToolbar.h in Headers */ = {isa = PBXBuildFile; fileRef = BC884B6914BAD86C00DEFFE0 /* RdEditorToolbar.h */; };
200+
BC884B6C14BAD86C00DEFFE0 /* RdEditorToolbar.m in Sources */ = {isa = PBXBuildFile; fileRef = BC884B6A14BAD86C00DEFFE0 /* RdEditorToolbar.m */; };
199201
BCBA744713B089D8001B440B /* RDataEditorTableView.h in Headers */ = {isa = PBXBuildFile; fileRef = BCBA744513B089D8001B440B /* RDataEditorTableView.h */; };
200202
BCBA744813B089D8001B440B /* RDataEditorTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = BCBA744613B089D8001B440B /* RDataEditorTableView.m */; };
201203
BCCE4A38130AB3C6003325EB /* RScriptEditorTokens.h in Headers */ = {isa = PBXBuildFile; fileRef = BCCE4A37130AB3C6003325EB /* RScriptEditorTokens.h */; };
@@ -209,6 +211,8 @@
209211
BCEFEBD81336705800CED44F /* RFontPreviewTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = BCEFEBD61336705800CED44F /* RFontPreviewTextField.m */; };
210212
BCEFEBE21336709A00CED44F /* RColorWellCell.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEFEBE01336709A00CED44F /* RColorWellCell.h */; };
211213
BCEFEBE31336709A00CED44F /* RColorWellCell.m in Sources */ = {isa = PBXBuildFile; fileRef = BCEFEBE11336709A00CED44F /* RColorWellCell.m */; };
214+
BCF5D88A14BB564A000A71F6 /* RdScriptEditorTokens.l in Sources */ = {isa = PBXBuildFile; fileRef = BCF5D88914BB564A000A71F6 /* RdScriptEditorTokens.l */; };
215+
BCF5D88C14BB5666000A71F6 /* RdScriptEditorTokens.h in Headers */ = {isa = PBXBuildFile; fileRef = BCF5D88B14BB5666000A71F6 /* RdScriptEditorTokens.h */; };
212216
D41DED4C073B3EE400B900F2 /* EditorPrefPane.h in Headers */ = {isa = PBXBuildFile; fileRef = D41DED4A073B3EE400B900F2 /* EditorPrefPane.h */; };
213217
D41DED4D073B3EE400B900F2 /* EditorPrefPane.m in Sources */ = {isa = PBXBuildFile; fileRef = D41DED4B073B3EE400B900F2 /* EditorPrefPane.m */; };
214218
D41DED59073B3FF700B900F2 /* RDocumentController.h in Headers */ = {isa = PBXBuildFile; fileRef = D41DED57073B3FF700B900F2 /* RDocumentController.h */; };
@@ -468,6 +472,8 @@
468472
BC6682FF13390A15005ACB30 /* fr */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = fr; path = fr.lproj/SyntaxColorsPrefPane.xib; sourceTree = "<group>"; };
469473
BC6DECCE133267F900C852C1 /* it */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = it; path = it.lproj/SelectEncodingsPanel.xib; sourceTree = "<group>"; };
470474
BC81712E13321873004B52A0 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/SelectEncodingsPanel.xib; sourceTree = "<group>"; };
475+
BC884B6914BAD86C00DEFFE0 /* RdEditorToolbar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RdEditorToolbar.h; sourceTree = "<group>"; };
476+
BC884B6A14BAD86C00DEFFE0 /* RdEditorToolbar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RdEditorToolbar.m; sourceTree = "<group>"; };
471477
BC9EF20313326D98005E61C6 /* nl */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = nl; path = nl.lproj/SelectEncodingsPanel.xib; sourceTree = "<group>"; };
472478
BCB297AD133B7EDD007899E0 /* de */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = de; path = de.lproj/Vignettes.xib; sourceTree = "<group>"; };
473479
BCB297AE133B7EE2007899E0 /* it */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = it; path = it.lproj/Vignettes.xib; sourceTree = "<group>"; };
@@ -488,6 +494,8 @@
488494
BCEFEBD61336705800CED44F /* RFontPreviewTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RFontPreviewTextField.m; sourceTree = "<group>"; };
489495
BCEFEBE01336709A00CED44F /* RColorWellCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RColorWellCell.h; sourceTree = "<group>"; };
490496
BCEFEBE11336709A00CED44F /* RColorWellCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RColorWellCell.m; sourceTree = "<group>"; };
497+
BCF5D88914BB564A000A71F6 /* RdScriptEditorTokens.l */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.lex; path = RdScriptEditorTokens.l; sourceTree = "<group>"; };
498+
BCF5D88B14BB5666000A71F6 /* RdScriptEditorTokens.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RdScriptEditorTokens.h; sourceTree = "<group>"; };
491499
D41DED4A073B3EE400B900F2 /* EditorPrefPane.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditorPrefPane.h; sourceTree = "<group>"; };
492500
D41DED4B073B3EE400B900F2 /* EditorPrefPane.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EditorPrefPane.m; sourceTree = "<group>"; };
493501
D41DED57073B3FF700B900F2 /* RDocumentController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RDocumentController.h; sourceTree = "<group>"; };
@@ -855,6 +863,8 @@
855863
BC1952B11330C9D400D52B29 /* RChooseEncodingPopupAccessory.h */,
856864
BCCE4A37130AB3C6003325EB /* RScriptEditorTokens.h */,
857865
BCCE4A39130AB3E3003325EB /* RScriptEditorTokens.l */,
866+
BCF5D88914BB564A000A71F6 /* RdScriptEditorTokens.l */,
867+
BCF5D88B14BB5666000A71F6 /* RdScriptEditorTokens.h */,
858868
BC12B311130A65CE009F7D3F /* RScriptEditorTextView.h */,
859869
BC12B312130A65CE009F7D3F /* RScriptEditorTextView.m */,
860870
D490C1EA07B400870034B42F /* RRulerView.h */,
@@ -867,6 +877,8 @@
867877
687B4F0607942C1500074042 /* RDocumentWinCtrl.m */,
868878
68756ED807FDDAEF0014821A /* REditorToolbar.h */,
869879
68756ED907FDDAEF0014821A /* REditorToolbar.m */,
880+
BC884B6914BAD86C00DEFFE0 /* RdEditorToolbar.h */,
881+
BC884B6A14BAD86C00DEFFE0 /* RdEditorToolbar.m */,
870882
);
871883
name = Editor;
872884
sourceTree = "<group>";
@@ -980,6 +992,8 @@
980992
BC469AED13B655270079D4E9 /* RDataEditorTableHeaderCell.h in Headers */,
981993
BC53A82013BDB5ED009488EE /* NSArray_RAdditions.h in Headers */,
982994
BCDF1C9113C2F160001216D9 /* RDataEditorTableHeaderView.h in Headers */,
995+
BC884B6B14BAD86C00DEFFE0 /* RdEditorToolbar.h in Headers */,
996+
BCF5D88C14BB5666000A71F6 /* RdScriptEditorTokens.h in Headers */,
983997
);
984998
runOnlyForDeploymentPostprocessing = 0;
985999
};
@@ -1031,6 +1045,7 @@
10311045
isa = PBXProject;
10321046
buildConfigurationList = 680F0B3A0997CE66009CDBE8 /* Build configuration list for PBXProject "R" */;
10331047
compatibilityVersion = "Xcode 2.4";
1048+
developmentRegion = English;
10341049
hasScannedForEncodings = 1;
10351050
knownRegions = (
10361051
English,
@@ -1232,6 +1247,8 @@
12321247
BC469AEE13B655270079D4E9 /* RDataEditorTableHeaderCell.m in Sources */,
12331248
BC53A82113BDB5ED009488EE /* NSArray_RAdditions.m in Sources */,
12341249
BCDF1C9213C2F160001216D9 /* RDataEditorTableHeaderView.m in Sources */,
1250+
BC884B6C14BAD86C00DEFFE0 /* RdEditorToolbar.m in Sources */,
1251+
BCF5D88A14BB564A000A71F6 /* RdScriptEditorTokens.l in Sources */,
12351252
);
12361253
runOnlyForDeploymentPostprocessing = 0;
12371254
};

RDocument.h

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363

6464
- (BOOL) isRTF;
6565

66+
- (BOOL) convertRd2HTML;
67+
6668
- (NSTextView *)textView;
6769

6870
@end

RDocument.m

+72-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#import "RController.h"
3636
#import "Preferences.h"
3737
#import "RChooseEncodingPopupAccessory.h"
38+
#import "REngine.h"
39+
#import "HelpManager.h"
3840

3941
// R defines "error" which is deadly as we use open ... with ... error: where error then gets replaced by Rf_error
4042
#ifdef error
@@ -213,7 +215,7 @@ - (void) loadInitialContents
213215
SLog(@" - new string contents (%d chars) for window controller %@", [cs length], wc);
214216
// Important! otherwise the save box won't know
215217
[wc setFileEncoding:documentEncoding];
216-
if(![initialContentsType isEqualToString:ftRSource]) {
218+
if(![initialContentsType isEqualToString:ftRSource] && ![initialContentsType isEqualToString:ftRdDoc]) {
217219
SLog(@" - set plain text mode");
218220
[wc setPlain:YES];
219221
}
@@ -419,6 +421,75 @@ - (BOOL) isRTF
419421
return (([self fileName] && [[[self fileName] lowercaseString] hasSuffix:@".rtf"]) || ([self fileType] && [[self fileType] hasSuffix:@".rtf"]));
420422
}
421423

424+
- (BOOL) convertRd2HTML
425+
{
426+
427+
REngine *re = [REngine mainEngine];
428+
429+
NSString *tempName = [NSTemporaryDirectory() stringByAppendingPathComponent: [NSString stringWithFormat: @"%.0f.", [NSDate timeIntervalSinceReferenceDate] * 1000.0]];
430+
NSString *RhomeCSS = @"R.css";
431+
RSEXP *xx = [re evaluateString:@"R.home()"];
432+
if(xx) {
433+
NSString *Rhome = [xx string];
434+
if(Rhome) {
435+
RhomeCSS = [NSString stringWithFormat:@"file://%@/doc/html/R.css", Rhome];
436+
}
437+
[xx release];
438+
}
439+
440+
441+
NSError *error;
442+
NSString *inputFile = [NSString stringWithFormat: @"%@%@", tempName, @"rd"];
443+
NSString *htmlOutputFile = [NSString stringWithFormat: @"%@%@", tempName, @"html"];
444+
NSString *errorOutputFile = [NSString stringWithFormat: @"%@%@", tempName, @"txt"];
445+
446+
NSURL *htmlOutputFileURL = [NSURL URLWithString:htmlOutputFile];
447+
448+
[[[myWinCtrl textView] string] writeToFile:inputFile atomically:YES encoding:NSUTF8StringEncoding error:&error];
449+
450+
NSString *convCmd = [NSString stringWithFormat:@"system(\"R CMD Rdconv -t html '%@' 2> '%@' | perl -pe 's!R.css!%@!'> '%@'\", intern=TRUE, wait=TRUE)", inputFile, errorOutputFile, RhomeCSS, htmlOutputFile];
451+
452+
if (![re beginProtected]) {
453+
SLog(@"RDocument.convertRd2HTML bailed because protected REngine entry failed [***]");
454+
return NO;
455+
}
456+
xx = [re evaluateString:convCmd];
457+
[re endProtected];
458+
if(xx) {
459+
[xx release];
460+
NSString *errMessage = [[NSString alloc] initWithContentsOfFile:errorOutputFile encoding:NSUTF8StringEncoding error:nil];
461+
if(errMessage && [errMessage length]) {
462+
463+
errMessage = [errMessage stringByReplacingOccurrencesOfString:inputFile withString:@"Rd file"];
464+
465+
NSAlert *alert = [NSAlert alertWithMessageText:NLS(@"Rd convertion warnings")
466+
defaultButton:NLS(@"OK")
467+
alternateButton:nil
468+
otherButton:nil
469+
informativeTextWithFormat:errMessage];
470+
471+
[alert setAlertStyle:NSWarningAlertStyle];
472+
[alert runModal];
473+
474+
}
475+
476+
[[HelpManager sharedController] showHelpFileForURL:htmlOutputFileURL];
477+
478+
if (![re beginProtected]) {
479+
SLog(@"RDocument.convertRd2HTML bailed because protected REngine entry failed for removing temporary files[***]");
480+
return NO;
481+
}
482+
// After 200 secs all temporary files will be deleted even if R was quitted meanwhile
483+
[re executeString:[NSString stringWithFormat:@"system(\"sleep 200 && rm -f '%@' && rm -f '%@' && rm -f '%@'\", wait=FALSE)", inputFile, htmlOutputFile, errorOutputFile]];
484+
[re endProtected];
485+
486+
return YES;
487+
}
488+
489+
return NO;
490+
491+
}
492+
422493
- (void)sheetDidEnd:(id)sheet returnCode:(int)returnCode contextInfo:(NSString*)contextInfo
423494
{
424495
// Order out the sheet - could be a NSPanel or NSWindow

RDocumentController.h

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#import "RDocument.h"
3535

3636
#define ftRSource @"R Source File"
37+
#define ftRdDoc @"Rd Documentation File"
3738
#define ftQuartz @"Quartz Graphics"
3839

3940
#define defaultDocumentType ftRSource

RDocumentWinCtrl.h

+2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ extern NSColor *shColorIdentifier;
116116
- (void) setPlain: (BOOL) plain; // plain = don't use highlighting even if preferences say so
117117
- (BOOL) plain;
118118

119+
- (BOOL) isRdDocument;
120+
119121
- (int) fileEncoding;
120122
- (void) setFileEncoding: (int) encoding;
121123

0 commit comments

Comments
 (0)