Permalink
Browse files

small fixes/changes

added workaround that prevents modal alerts from being displayed on screens other than the one with the menu bar
  • Loading branch information...
1 parent 64e05ed commit b270db53dbca1b6ff23e70b47397a92de9ce48b7 @mrRay committed Oct 27, 2016
Showing with 71 additions and 10 deletions.
  1. +4 −6 ISF Editor/ISFPDownloader.m
  2. +1 −0 VVBasics/src/VVBasicMacros.h
  3. +66 −4 VVBasics/src/VVBasicMacros.m
@@ -63,13 +63,13 @@ - (void) awakeFromNib {
keyEquivalent:@""] autorelease];
[tmpMenu addItem:tmpMenuItem];
- NSArray *functionTypes = @[@"generator", @"filter", @"transition"];
+ NSArray *functionTypes = @[@"Generator", @"Filter", @"Transition"];
for (NSString *functionType in functionTypes) {
tmpMenuItem = [[[NSMenuItem alloc]
initWithTitle:functionType
action:nil
keyEquivalent:@""] autorelease];
- [tmpMenuItem setRepresentedObject:functionType];
+ [tmpMenuItem setRepresentedObject:[functionType lowercaseString]];
[tmpMenu addItem:tmpMenuItem];
}
@@ -84,7 +84,7 @@ - (void) awakeFromNib {
- (void) populateCategoriesPUB {
- NSLog(@"%s",__func__);
+ //NSLog(@"%s",__func__);
// first, populate the categories PUB with a list of standard categories that will be used until we download the official list of categories from the server
NSArray *defaultCats = @[@"Generator", @"Color Effect", @"Color Adjustment",@"Halftone Effect", @"Geometry Adjustment",@"Blur",@"Sharpen",@"Stylize",@"Glitch",@"Tile Effect",@"Distortion Effect",@"Film",@"Masking",@"Patterns"];
[self populateCategoriesPUBWithCategories:defaultCats];
@@ -97,7 +97,6 @@ - (void) populateCategoriesPUB {
[dl performAsync:YES withBlock:^(VVCURLDL *finished) {
NSString *responseString = [finished responseString];
NSDictionary *topLevelJSONObj = [responseString objectFromJSONString];
- NSLog(@"\t\traw categories are %@",topLevelJSONObj);
NSMutableArray *tmpCatArray = MUTARRAY;
//NSLog(@"\t\tcategories topLevelJSONObj is %@",topLevelJSONObj);
if (topLevelJSONObj!=nil && [topLevelJSONObj isKindOfClass:[NSDictionary class]]) {
@@ -110,7 +109,6 @@ - (void) populateCategoriesPUB {
}
}
}
- NSLog(@"\t\tfetched categories from server: %@",tmpCatArray);
[self populateCategoriesPUBWithCategories:tmpCatArray];
}];
}
@@ -412,7 +410,7 @@ - (void) downloadResultsForURLString:(NSString *)address {
[dl appendStringToHeader:@"Accept: application/json"];
[dl performAsync:YES withBlock:^(VVCURLDL *finished) {
//NSLog(@"\t\tdownloaded string %@",[finished responseString]);
- //NSLog(@"\t\tdownloaded JSON object %@",[[finished responseString] objectFromJSONString]);
+ NSLog(@"\t\tdownloaded JSON object %@",[[finished responseString] objectFromJSONString]);
NSString *responseString = [finished responseString];
NSArray *topLevelJSONObj = [responseString objectFromJSONString];
if (topLevelJSONObj==nil || ![topLevelJSONObj isKindOfClass:[NSArray class]]) {
@@ -156,6 +156,7 @@
#if !TARGET_OS_IPHONE
+#import <AppKit/AppKit.h>
// not actually a macro- a function to replace NSRunAlertPanel, which is deprecated in 10.10
NSInteger VVRunAlertPanel(NSString *title, NSString *msg, NSString *btnA, NSString *btnB, NSString *btnC);
NSInteger VVRunAlertPanelSuppressString(NSString *title, NSString *msg, NSString *btnA, NSString *btnB, NSString *btnC, NSString *suppressString, BOOL *returnSuppressValue);
@@ -3,12 +3,57 @@
#if !TARGET_OS_IPHONE
+@interface NSAlert (NSAlertAdditions)
+- (NSInteger) runModalForWindow:(NSWindow *)aWindow;
+@end
+@implementation NSAlert (NSAlertAdditions)
+- (NSInteger) runModalForWindow:(NSWindow *)aWindow {
+ __block NSInteger returnMe = 0;
+ __block id bss = self;
+ // this code is in a block because it must be executed on the main thread (AppKit isn't threadsafe)
+ void (^tmpBlock)(void) = ^(void) {
+ // configure the buttons to trigger a method we're adding to NSAlert in this category
+ for (NSButton *button in [bss buttons]) {
+ [button setTarget:bss];
+ [button setAction:@selector(closeAlertsAppModalSession:)];
+ }
+ // open the sheet as modal for the passed window
+ [bss beginSheetModalForWindow:aWindow completionHandler:nil];
+ // start a modal session for the window- this will ensure that any events outside the window are ignored
+ returnMe = [NSApp runModalForWindow:[bss window]];
+
+ // ...execution won't pass this point until the NSApp modal session above is ended (happens when a button is clicked)...
+
+ // end the sheet we began with 'beginSheetModalForWindow'
+ [NSApp endSheet:[bss window]];
+ };
+ // execute the block, ensuring that it happens synchronously and on the main thread
+ if (![NSThread isMainThread])
+ dispatch_sync(dispatch_get_main_queue(), tmpBlock);
+ else
+ tmpBlock();
+ return returnMe;
+}
+- (IBAction) closeAlertsAppModalSession:(id)sender {
+ NSUInteger senderButtonIndex = [[self buttons] indexOfObject:sender];
+ NSInteger returnMe = 0;
+ if (senderButtonIndex == NSAlertFirstButtonReturn)
+ returnMe = NSAlertFirstButtonReturn;
+ else if (senderButtonIndex == NSAlertSecondButtonReturn)
+ returnMe = NSAlertSecondButtonReturn;
+ else if (senderButtonIndex == NSAlertThirdButtonReturn)
+ returnMe = NSAlertThirdButtonReturn;
+ else
+ returnMe = NSAlertThirdButtonReturn + (senderButtonIndex - 2);
+
+ [NSApp stopModalWithCode:returnMe];
+}
+@end
NSInteger VVRunAlertPanel(NSString *title, NSString *msg, NSString *btnA, NSString *btnB, NSString *btnC) {
return VVRunAlertPanelSuppressString(title, msg, btnA, btnB, btnC, nil, NULL);
}
-
NSInteger VVRunAlertPanelSuppressString(NSString *title, NSString *msg, NSString *btnA, NSString *btnB, NSString *btnC, NSString *suppressString, BOOL *returnSuppressValue) {
- NSInteger returnMe;
+ __block NSInteger returnMe;
NSAlert *macroLocalAlert = [NSAlert alertWithError:[NSError
errorWithDomain:@""
code:0
@@ -37,8 +82,25 @@ NSInteger VVRunAlertPanelSuppressString(NSString *title, NSString *msg, NSString
[macroLocalAlert setShowsSuppressionButton:NO];
}
- returnMe = [macroLocalAlert runModal];
- //NSLog(@"\t\treturning %ld",returnMe);
+ // so, -[NSAlert runModal] should be handling all this- but we can't do that, because sometimes NSAlert will display the modal dialog on the non-main screen. to work around this, we have to create an invisible window on the main screen, and attach the alert to it as a sheet that uses a modal session to restrict user interaction.
+ NSRect mainScreenRect = [[[NSScreen screens] objectAtIndex:0] frame];
+ NSRect clearWinRect = NSMakeRect(VVMIDX(mainScreenRect)-250, (mainScreenRect.size.height*0.66) + mainScreenRect.origin.y - 100, 500, 200);
+ NSWindow *clearWin = [[NSWindow alloc] initWithContentRect:clearWinRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
+ [clearWin setHasShadow:NO];
+ [clearWin setOpaque:NO];
+ [clearWin setBackgroundColor:[NSColor clearColor]];
+ //[clearWin useOptimizedDrawing:YES];
+ [clearWin setHidesOnDeactivate:YES];
+ [clearWin setLevel:NSModalPanelWindowLevel];
+ [clearWin setIgnoresMouseEvents:YES];
+
+ //NSLog(@"\t\ttelling the app to run a modal session for the clear window...");
+ returnMe = [macroLocalAlert runModalForWindow:clearWin];
+
+ // get rid of the clear window...
+ [clearWin orderOut:nil];
+ [clearWin release];
+ clearWin = nil;
if (showsSuppressionButton && returnSuppressValue!=NULL) {
*returnSuppressValue = ([[macroLocalAlert suppressionButton] intValue]==NSOnState) ? YES : NO;

0 comments on commit b270db5

Please sign in to comment.