Skip to content

Commit

Permalink
Removed broken AppleScript support; simpler code for menu event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
berniejenny committed Mar 31, 2018
1 parent 1feb0ac commit 7e6e3a5
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 267 deletions.
172 changes: 17 additions & 155 deletions AppController.m
Expand Up @@ -481,7 +481,8 @@ - (void)awakeFromNib

// button to resize info window needs transparent background outside the button area
[infoResizeButton setWantsLayer:YES];
infoResizeButton.layer.backgroundColor = [NSColor clearColor].CGColor;}
infoResizeButton.layer.backgroundColor = [NSColor clearColor].CGColor;
}

- (void)dealloc
{
Expand Down Expand Up @@ -1254,13 +1255,6 @@ -(IBAction)selItemNormal:(id)sender
[self fadeOutWindow];
}

-(void)takeScreenshotAndUpdateSimulation
{
// take a screenshot
[self takeScreenShot];
[self updateSimulation];
}

-(void) sleep:(float) millisec
{
struct timespec rqtp = { 0 };
Expand All @@ -1276,80 +1270,35 @@ -(void) hideMenu
[self sleep: MILLISEC_TO_HIDE_MENU];
}

/* sender == self indicates that this method is being called from an AppleScript */
-(void)selItem: (int) simID withIcon:(NSString*) iconName{
// close welcome dialog, should it still be open
[self closeWelcomeDialog:self];
simulationID = simID;
[statusItem setImage:[NSImage imageNamed:iconName]];
[self hideMenu];
[mainWindow setLevel: WINDOWLEVEL];
[self takeScreenShot];
[self updateSimulation];
}

-(IBAction)selItemProtan:(id)sender
{
// close welcome dialog, should it still be open
[self closeWelcomeDialog:self];
simulationID = protan;
[statusItem setImage:[NSImage imageNamed:@"menuIconProtan"]];

// hide the menu if this method was called from the menu
if (sender != nil && sender != self)
[self hideMenu];

// set the level of the main window to normal level if this method is called
// from an AppleScript, set it to a level covering the dock otherwise.
[mainWindow setLevel:sender == self ? kCGNormalWindowLevel : WINDOWLEVEL];

[self takeScreenshotAndUpdateSimulation];
[self selItem: protan withIcon: @"menuIconProtan"];
}

/* sender == self indicates that this method is being called from an AppleScript */
-(IBAction)selItemDeutan:(id)sender
{
// close welcome dialog, should it still be open
[self closeWelcomeDialog:self];
simulationID = deutan;
[statusItem setImage:[NSImage imageNamed:@"menuIconDeutan"]];

// hide the menu if this method was called from the menu
if (sender != nil && sender != self)
[self hideMenu];

// set the level of the main window to normal level if this method is called
// from an AppleScript, set it to a level covering the dock otherwise.
[mainWindow setLevel:sender == self ? kCGNormalWindowLevel : WINDOWLEVEL];

[self takeScreenshotAndUpdateSimulation];
[self selItem: deutan withIcon: @"menuIconDeutan"];
}

/* sender == self indicates that this method is being called from an AppleScript */
-(IBAction)selItemTritan:(id)sender
{
// close welcome dialog, should it still be open
[self closeWelcomeDialog:self];
simulationID = tritan;
[statusItem setImage:[NSImage imageNamed:@"menuIconTritan"]];

// hide the menu if this method was called from the menu
if (sender != nil && sender != self)
[self hideMenu];

// set the level of the main window to normal level if this method is called
// from an AppleScript, set it to a level covering the dock otherwise.
[mainWindow setLevel:sender == self ? kCGNormalWindowLevel : WINDOWLEVEL];

[self takeScreenshotAndUpdateSimulation];
[self selItem: tritan withIcon: @"menuIconTritan"];
}

/* sender == self indicates that this method is being called from an AppleScript */
-(IBAction)selItemGrayscale:(id)sender
{
// close welcome dialog, should it still be open
[self closeWelcomeDialog:self];
simulationID = grayscale;
[statusItem setImage:[NSImage imageNamed:@"menuIconGrayscale"]];

// hide the menu if this method was called from the menu
if (sender != nil && sender != self)
[self hideMenu];

// set the level of the main window to normal level if this method is called
// from an AppleScript, set it to a level covering the dock otherwise.
[mainWindow setLevel:sender == self ? kCGNormalWindowLevel : WINDOWLEVEL];

[self takeScreenshotAndUpdateSimulation];
[self selItem: grayscale withIcon: @"menuIconGrayscale"];
}

-(IBAction)selItemSave:(id)sender
Expand All @@ -1372,22 +1321,6 @@ -(IBAction)selItemSave:(id)sender
userInfo:nil repeats:YES] retain];
}

/*
-(IBAction)selItemHelp:(id)sender
{
// close welcome dialog, should it still be open
[self closeWelcomeDialog:self];
simulationID = normalView;
[self fadeOutWindow];
NSBundle * appBundle = [NSBundle mainBundle];
NSString * nsPath = [appBundle pathForResource: [NSString stringWithCString: "help"]
ofType:[NSString stringWithCString: "html"]
inDirectory:[NSString stringWithCString: "help"]];
if (nsPath)
AHGotoPage (NULL, (CFStringRef)nsPath, NULL);
}
*/

-(IBAction)selItemPreferences:(id)sender
{
// close welcome dialog, should it still be open
Expand Down Expand Up @@ -1776,75 +1709,4 @@ -(NSWindow*)aboutBox
return aboutBox;
}

/* return whether a applescript hanlder is supported */
- (BOOL)application:(NSApplication *)sender
delegateHandlesKey:(NSString *)key
{
if ([key isEqual:@"simulation"]) {
return YES;
} else {
return NO;
}
}

// for AppleScript support
- (NSString *)simulation
{
switch (simulationID) {
case normalView:
return @"normal";
case protan:
return @"protan";
case deutan:
return @"deutan";
case tritan:
return @"tritan";
case grayscale:
return @"grayscale";
}
return nil;
}

// for AppleScript support
- (void)setSimulation:(NSString *)key
{
if (key == nil)
return;

// test case insensitive for first 6 characters of key.
// i.e. 'deutan', 'deutanope', 'Deuteranopia' are all valid keys.
NSRange range = NSMakeRange (0, 6);

if ([key compare:@"normal" options:NSCaseInsensitiveSearch range:range] == NSOrderedSame) {
[statusItem setImage:[NSImage imageNamed:@"menuIcon"]];
simulationID = normalView;

// don't call [self finishFadeOut], which would call [NSApp hide:nil] to deactivate the app.
// Hiding this app will be done by the scripting engine.
// Instead, just order the mainWindow out.
[mainWindow orderOut:self];
return;
}

if ([key compare:@"deutan" options:NSCaseInsensitiveSearch range:range] == NSOrderedSame) {
[self selItemDeutan:self];
return;
}

if ([key compare:@"protan" options:NSCaseInsensitiveSearch range:range] == NSOrderedSame) {
[self selItemProtan:self];
return;
}

if ([key compare:@"tritan" options:NSCaseInsensitiveSearch range:range] == NSOrderedSame) {
[self selItemTritan:self];
return;
}

if ([key compare:@"grayscale" options:NSCaseInsensitiveSearch range:range] == NSOrderedSame) {
[self selItemGrayscale:self];
return;
}
}

@end
18 changes: 0 additions & 18 deletions ColorOracle.sdef

This file was deleted.

33 changes: 5 additions & 28 deletions ColorOracle.xcodeproj/project.pbxproj
Expand Up @@ -45,7 +45,6 @@
BAE416BE0A0896BB006994E7 /* 7.png in Resources */ = {isa = PBXBuildFile; fileRef = BAE416A60A0896BB006994E7 /* 7.png */; };
BAE416BF0A0896BB006994E7 /* 8.png in Resources */ = {isa = PBXBuildFile; fileRef = BAE416A70A0896BB006994E7 /* 8.png */; };
BAE416C00A0896BB006994E7 /* 9.png in Resources */ = {isa = PBXBuildFile; fileRef = BAE416A80A0896BB006994E7 /* 9.png */; };
BAE4186F0A08E948006994E7 /* ColorOracle.sdef in Resources */ = {isa = PBXBuildFile; fileRef = BAE4186E0A08E948006994E7 /* ColorOracle.sdef */; };
BAE7178309C316210030D896 /* icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = BAE7178209C316210030D896 /* icon.icns */; };
BAF9124E09BF91E00035C73D /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BAF9124D09BF91E00035C73D /* Carbon.framework */; };
C33A2411205E0A7F004DE561 /* menuIconGrayscale.tif in Resources */ = {isa = PBXBuildFile; fileRef = C33A2410205E0A7F004DE561 /* menuIconGrayscale.tif */; };
Expand All @@ -60,7 +59,6 @@
29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = "<group>"; };
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
32CA4F630368D1EE00C91783 /* test_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = test_Prefix.pch; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* Color Oracle.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Color Oracle.app"; sourceTree = BUILT_PRODUCTS_DIR; };
BA10336309C1B3730073BCE0 /* ClickableImageView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ClickableImageView.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -104,11 +102,10 @@
BAE416A60A0896BB006994E7 /* 7.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 7.png; sourceTree = "<group>"; };
BAE416A70A0896BB006994E7 /* 8.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 8.png; sourceTree = "<group>"; };
BAE416A80A0896BB006994E7 /* 9.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 9.png; sourceTree = "<group>"; };
BAE4186E0A08E948006994E7 /* ColorOracle.sdef */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.sdef; path = ColorOracle.sdef; sourceTree = "<group>"; };
BAE61D5F09C5B18A001C1FB4 /* InfoText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InfoText.h; sourceTree = "<group>"; };
BAE7178209C316210030D896 /* icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = icon.icns; sourceTree = "<group>"; };
BAEF496209C56C2A00D1B983 /* Microseconds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Microseconds.h; sourceTree = "<group>"; };
BAF9124D09BF91E00035C73D /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; sourceTree = "<absolute>"; };
C331DB15206F1F9B00149B74 /* test_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = test_Prefix.pch; sourceTree = "<group>"; };
C33A2410205E0A7F004DE561 /* menuIconGrayscale.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = menuIconGrayscale.tif; path = "Icon/Color Blindness Test/menuIconGrayscale.tif"; sourceTree = "<group>"; };
C33A2412205E2591004DE561 /* LaunchAtLoginController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LaunchAtLoginController.h; sourceTree = "<group>"; };
C33A2413205E2592004DE561 /* LaunchAtLoginController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LaunchAtLoginController.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -143,7 +140,6 @@
BA854B6D09C34CAB00BCBB77 /* TransparentWindow.h */,
BA854B6E09C34CAB00BCBB77 /* TransparentWindow.m */,
BAE61D5F09C5B18A001C1FB4 /* InfoText.h */,
BAEF496209C56C2A00D1B983 /* Microseconds.h */,
BADD54B709C9679A00C76C20 /* WindowLevel.h */,
);
name = Classes;
Expand Down Expand Up @@ -180,7 +176,6 @@
29B97314FDCFA39411CA2CEA /* test */ = {
isa = PBXGroup;
children = (
BAE4186E0A08E948006994E7 /* ColorOracle.sdef */,
080E96DDFE201D6D7F000001 /* Classes */,
29B97315FDCFA39411CA2CEA /* Other Sources */,
29B97317FDCFA39411CA2CEA /* Resources */,
Expand All @@ -193,8 +188,8 @@
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
isa = PBXGroup;
children = (
32CA4F630368D1EE00C91783 /* test_Prefix.pch */,
29B97316FDCFA39411CA2CEA /* main.m */,
C331DB15206F1F9B00149B74 /* test_Prefix.pch */,
);
name = "Other Sources";
sourceTree = "<group>";
Expand Down Expand Up @@ -267,7 +262,6 @@
8D1107290486CEB800E47090 /* Resources */,
8D11072C0486CEB800E47090 /* Sources */,
8D11072E0486CEB800E47090 /* Frameworks */,
BAE418810A08E9C9006994E7 /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -344,28 +338,11 @@
BAE416BE0A0896BB006994E7 /* 7.png in Resources */,
BAE416BF0A0896BB006994E7 /* 8.png in Resources */,
BAE416C00A0896BB006994E7 /* 9.png in Resources */,
BAE4186F0A08E948006994E7 /* ColorOracle.sdef in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
BAE418810A08E9C9006994E7 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "/usr/bin/sdp -f st -V 10.3 -o \"$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME/Contents/Resources\" \"$SOURCE_ROOT/ColorOracle.sdef\"";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
8D11072C0486CEB800E47090 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down Expand Up @@ -508,7 +485,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.6;
MACOSX_DEPLOYMENT_TARGET = 10.9;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
STRIP_INSTALLED_PRODUCT = NO;
Expand Down Expand Up @@ -546,7 +523,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.6;
MACOSX_DEPLOYMENT_TARGET = 10.9;
SDKROOT = macosx;
};
name = Release;
Expand Down Expand Up @@ -580,7 +557,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.6;
MACOSX_DEPLOYMENT_TARGET = 10.9;
SDKROOT = macosx;
};
name = Default;
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions English.lproj/MainMenu.nib/designable.nib

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Info.plist
Expand Up @@ -24,8 +24,6 @@
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
<string>1</string>
<key>NSAppleScriptEnabled</key>
<string>YES</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Expand Up @@ -2,7 +2,7 @@ The MIT License (MIT)

http://opensource.org/licenses/MIT

Copyright (c) 2006 - 2013 Bernhard Jenny and Nathaniel Vaughn Kelso
Copyright (c) 2006-2018 Bernhard Jenny and Nathaniel Vaughn Kelso

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
Expand Down

0 comments on commit 7e6e3a5

Please sign in to comment.