From 52254837413734720214bd20676cd5c4543b4068 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 1 Jan 2022 13:07:23 -0500 Subject: [PATCH] Add a preference for the PHP binary path for syntax highlighting. Other attempts like trying to find the executable via running a command in the user shell are flaky: not all users will have $PATH set up in non-interactive rc files, for example. --- CHANGES | 1 + Source/AppDelegate.m | 1 + Source/BSSourceView.m | 13 ++++++- Source/PreferenceNames.h | 3 ++ Source/PreferenceNames.m | 2 + en.lproj/Preferences.xib | 83 ++++++++++++++++++++++++++-------------- 6 files changed, 72 insertions(+), 31 deletions(-) diff --git a/CHANGES b/CHANGES index a3f4e48..9a190d7 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,7 @@ MacGDBp CHANGE LOG 2.0.4 ##################### - Fix: #266 Plain text fallback source display does not paint the ruler. +- New: #266 Add preference for PHP binary path for syntax highlighting. 2.0.3 diff --git a/Source/AppDelegate.m b/Source/AppDelegate.m index f059e2c..cfcad38 100644 --- a/Source/AppDelegate.m +++ b/Source/AppDelegate.m @@ -42,6 +42,7 @@ static NSString* const kAppcastUnstable = @"appcast-unstable.xml"; kPrefPort : @9000, kPrefInspectorWindowVisible : @YES, kPrefPathReplacements : [NSMutableArray array], + kPrefPhpPath : @"/usr/bin/php", #if USE_APP_SANDBOX kPrefFileAccessBookmarks : [NSMutableDictionary dictionary], #endif diff --git a/Source/BSSourceView.m b/Source/BSSourceView.m index fbd2766..d263060 100644 --- a/Source/BSSourceView.m +++ b/Source/BSSourceView.m @@ -16,6 +16,7 @@ #import "BSSourceView.h" +#import "PreferenceNames.h" #import "BSLineNumberRulerView.h" #import "BSSourceViewTextView.h" @@ -200,7 +201,14 @@ NSString* ColorHEXStringINIDirective(NSString* directive, NSColor* color) { NSPipe* errPipe = [NSPipe pipe]; NSTask* task = [[NSTask alloc] init]; - [task setLaunchPath:@"/usr/bin/php"]; // This is the path to the default Leopard PHP executable + NSString* phpPath = [[NSUserDefaults standardUserDefaults] stringForKey:kPrefPhpPath]; + if (!phpPath) { + // This is the path to the default Leopard PHP executable, but it will not + // exist on future macOS versions. + phpPath = @"/usr/bin/php"; + } + + [task setLaunchPath:phpPath]; [task setArguments:@[ @"--syntax-highlight", @"--define", ColorHEXStringINIDirective(@"highlight.string", [NSColor systemRedColor]), @@ -214,7 +222,8 @@ NSString* ColorHEXStringINIDirective(NSString* directive, NSColor* color) { [task setTerminationHandler:^(NSTask* taskBlock) { if (task.terminationStatus != 0) { NSLog(@"Failed to highlight PHP file %@. Termination status=%d. stderr: %@", - filePath, taskBlock.terminationStatus, [[errPipe fileHandleForReading] readDataToEndOfFile]); + filePath, taskBlock.terminationStatus, + [[NSString alloc] initWithData:[[errPipe fileHandleForReading] readDataToEndOfFile] encoding:NSUTF8StringEncoding]); } }]; [task launch]; diff --git a/Source/PreferenceNames.h b/Source/PreferenceNames.h index fa75db1..b80900b 100644 --- a/Source/PreferenceNames.h +++ b/Source/PreferenceNames.h @@ -25,6 +25,9 @@ extern NSString* const kPrefInspectorWindowVisible; // NSMutableArray of path replacements. extern NSString* const kPrefPathReplacements; +// NSString to the path to the PHP binary used for syntax highlighting. +extern NSString* const kPrefPhpPath; + #if USE_APP_SANDBOX // NSMutableDictionary of NSString paths to NSData file access bookmarks. extern NSString* const kPrefFileAccessBookmarks; diff --git a/Source/PreferenceNames.m b/Source/PreferenceNames.m index d5ded44..d6e9ec4 100644 --- a/Source/PreferenceNames.m +++ b/Source/PreferenceNames.m @@ -22,6 +22,8 @@ NSString* const kPrefInspectorWindowVisible = @"InspectorWindowVisible"; NSString* const kPrefPathReplacements = @"PathReplacements"; +NSString* const kPrefPhpPath = @"PhpPath"; + #if USE_APP_SANDBOX NSString* const kPrefFileAccessBookmarks = @"FileAccessBookmarks"; diff --git a/en.lproj/Preferences.xib b/en.lproj/Preferences.xib index f1832b3..ed65e20 100644 --- a/en.lproj/Preferences.xib +++ b/en.lproj/Preferences.xib @@ -1,8 +1,8 @@ - + - + @@ -25,7 +25,7 @@ - + @@ -35,16 +35,22 @@ + + + + + + @@ -65,11 +71,11 @@ - + - + @@ -78,7 +84,7 @@ - + @@ -98,7 +104,7 @@ - + @@ -121,7 +127,7 @@ - + @@ -134,7 +140,7 @@ - + @@ -142,8 +148,29 @@ + + + + + + + + + + + + + + + + + + + + + - + @@ -174,20 +201,19 @@ - - + + - - + + - @@ -201,9 +227,8 @@ - + - @@ -229,7 +254,7 @@ - + @@ -238,6 +263,7 @@ + @@ -285,20 +311,19 @@ - - + + - - + + - + - @@ -324,7 +349,7 @@ - + @@ -334,10 +359,10 @@ - + - + -- 2.22.5