Skip to content

Commit

Permalink
I these changes perform minor refactoring on the place where the drag…
Browse files Browse the repository at this point in the history
…Items list is store with the purpose of handling url schema and document open events that are raised before the application is even started.
  • Loading branch information
ronsaldo committed Mar 8, 2021
1 parent 924a24b commit d10e5ea
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 116 deletions.
6 changes: 6 additions & 0 deletions platforms/iOS/vm/OSX/SqueakOSXAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@
BOOL checkForFileNameOnFirstParm;
NSString *possibleImageNameAtLaunchTime;
sqSqueakOSXScreenAndWindow *windowHandler;

NSMutableArray* dragItems;
}

@property (nonatomic,weak) IBOutlet NSWindow *window;
@property (nonatomic,weak) IBOutlet NSView <sqSqueakOSXView> *mainView;
@property (nonatomic,strong) NSString *possibleImageNameAtLaunchTime;
@property (nonatomic,assign) BOOL checkForFileNameOnFirstParm;
@property (nonatomic, strong) sqSqueakNullScreenAndWindow *windowHandler;
@property (nonatomic, strong) NSMutableArray *dragItems;

- (BOOL)isImageFile:(NSString *)filePath;
- (NSURL*) dragURIAtIndex:(sqInt) index;

@end
73 changes: 66 additions & 7 deletions platforms/iOS/vm/OSX/SqueakOSXAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Some of this code was funded via a grant from the European Smalltalk User Group

#import "SqueakOSXAppDelegate.h"
#import "sqSqueakOSXApplication.h"
#import "sqSqueakOSXApplication+events.h"
#import "sqSqueakOSXScreenAndWindow.h"
#import "sqMacHostWindow.h"
#import "sqSqueakOSXInfoPlistInterface.h"
Expand All @@ -59,14 +60,20 @@ Some of this code was funded via a grant from the European Smalltalk User Group

@implementation SqueakOSXAppDelegate

@synthesize window,mainView,possibleImageNameAtLaunchTime,checkForFileNameOnFirstParm,windowHandler;
@synthesize window,mainView,possibleImageNameAtLaunchTime,checkForFileNameOnFirstParm,windowHandler,dragItems;

- (sqSqueakMainApplication *) makeApplicationInstance {
return AUTORELEASEOBJ([[sqSqueakOSXApplication alloc] init]);
}

- (void)applicationWillFinishLaunching:(NSNotification *)aNotification {
self.checkForFileNameOnFirstParm = YES;
dragItems = NULL;

NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
Expand All @@ -79,6 +86,9 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
gDelegateApp = self;
self.squeakApplication = [self makeApplicationInstance];
[self.squeakApplication setupEventQueue];
// Push the startup schema and open file events into the event queue.
if(self.dragItems && [self.dragItems count] > 0)
[(sqSqueakOSXApplication *) self.squeakApplication recordURLEvent: SQDragDrop numberOfFiles: [self.dragItems count]];
[self singleThreadStart];
// [self workerThreadStart];
}
Expand All @@ -88,6 +98,24 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
#endif
}

- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSString* urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSURL *url = [NSURL URLWithString: urlString];
dragItems = [NSMutableArray arrayWithCapacity: 1];
[dragItems addObject: url];

if(self.squeakApplication)
[(sqSqueakOSXApplication *) self.squeakApplication recordURLEvent: SQDragDrop numberOfFiles: 1];
}

- (NSURL*) dragURIAtIndex: (sqInt) index {
if (!self.dragItems || index < 1 || index > [self.dragItems count])
return NULL;

return (self.dragItems)[(NSUInteger) index - 1];
}

#ifdef PharoVM
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
shouldPresentNotification:(NSUserNotification *)notification
Expand Down Expand Up @@ -185,13 +213,34 @@ - (void) placeMainWindowOnLargerScreenGivenWidth: (sqInt) width height: (sqInt)
#endif
}

- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)fileName {
if (self.checkForFileNameOnFirstParm == YES) {
self.checkForFileNameOnFirstParm = NO;
self.possibleImageNameAtLaunchTime = fileName;
- (BOOL) isImageFile: (NSString *) filePath
{
NSFileManager *dfm = [NSFileManager defaultManager];
BOOL isDirectory;

[dfm fileExistsAtPath: filePath isDirectory: &isDirectory];

if (isDirectory)
return NO;

BOOL fileIsReadable = [[NSFileManager defaultManager] isReadableFileAtPath: filePath];

if (fileIsReadable == NO)
return NO;

if ([[[filePath lastPathComponent] pathExtension] compare: @"image" options: NSCaseInsensitiveSearch] == NSOrderedSame)
return YES;
} else {
if ([(sqSqueakOSXApplication*)self.squeakApplication isImageFile: fileName] == YES) {

return NO;
}

- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)fileName {
if([self isImageFile: fileName] == YES) {
if (self.checkForFileNameOnFirstParm == YES) {
self.checkForFileNameOnFirstParm = NO;
self.possibleImageNameAtLaunchTime = fileName;
return YES;
} else {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
LSLaunchURLSpec launchSpec;
launchSpec.appURL = (CFURLRef)CFBridgingRetain(url);
Expand All @@ -205,7 +254,17 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)fileNam
#pragma unused(err)
}
}
else
{
NSURL *url = [NSURL fileURLWithPath: fileName];
dragItems = [NSMutableArray arrayWithCapacity: 1];
[dragItems addObject: url];

if(self.squeakApplication)
[(sqSqueakOSXApplication *) self.squeakApplication recordURLEvent: SQDragDrop numberOfFiles: 1];
return YES;
}

return NO;
}

Expand Down
4 changes: 3 additions & 1 deletion platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.m
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,9 @@ - (void) recordURLEvent:(int)dragType numberOfFiles:(int)numFiles
evt.windowIndex = 0;
[self pushEventToQueue: (sqInputEvent *) &evt];

interpreterProxy->signalSemaphoreWithIndex(gDelegateApp.squeakApplication.inputSemaphoreIndex);
// interpreterProxy is nil when injecting events before startup.
if(interpreterProxy)
interpreterProxy->signalSemaphoreWithIndex(gDelegateApp.squeakApplication.inputSemaphoreIndex);
}

- (void) recordWindowEvent: (int) windowEventType window: (NSWindow *) window {
Expand Down
21 changes: 4 additions & 17 deletions platforms/iOS/vm/OSX/sqSqueakOSXApplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Some of this code was funded via a grant from the European Smalltalk User Group
#import "sqSqueakOSXApplication+imageReadWrite.h"
#import "sqSqueakOSXApplication+attributes.h"
#import "sqSqueakOSXViewFactory.h"
#import "SqueakOSXAppDelegate.h"

extern SqueakOSXAppDelegate *gDelegateApp;

#if !defined(IMAGE_DIALECT_NAME)
# if NewspeakVM
Expand Down Expand Up @@ -594,23 +597,7 @@ - (void) printUsageNotes

- (BOOL) isImageFile: (NSString *) filePath
{
NSFileManager *dfm = [NSFileManager defaultManager];
BOOL isDirectory;

[dfm fileExistsAtPath: filePath isDirectory: &isDirectory];

if (isDirectory)
return NO;

BOOL fileIsReadable = [[NSFileManager defaultManager] isReadableFileAtPath: filePath];

if (fileIsReadable == NO)
return NO;

if ([[[filePath lastPathComponent] pathExtension] compare: @"image" options: NSCaseInsensitiveSearch] == NSOrderedSame)
return YES;

return NO;
return [gDelegateApp isImageFile: filePath];
}

@end
Expand Down
1 change: 0 additions & 1 deletion platforms/iOS/vm/OSX/sqSqueakOSXCGView.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
int dragCount;
BOOL firstDrawCompleted;
BOOL syncNeeded;
NSMutableArray* dragItems;
CGDisplayFadeReservationToken fadeToken;
NSRect savedScreenBoundsAtTimeOfFullScreen;
CGColorSpaceRef colorspace;
Expand Down
30 changes: 3 additions & 27 deletions platforms/iOS/vm/OSX/sqSqueakOSXCGView.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Some of this code was funded via a grant from the European Smalltalk User Group

@implementation sqSqueakOSXCGView
@synthesize squeakTrackingRectForCursor,lastSeenKeyBoardStrokeDetails,
lastSeenKeyBoardModifierDetails,dragInProgress,dragCount,dragItems,windowLogic,savedScreenBoundsAtTimeOfFullScreen;
lastSeenKeyBoardModifierDetails,dragInProgress,dragCount,windowLogic,savedScreenBoundsAtTimeOfFullScreen;

#pragma mark Initialization / Release

Expand All @@ -83,14 +83,8 @@ - (void)initialize {
[self registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
dragInProgress = NO;
dragCount = 0;
dragItems = NULL;
clippyIsEmpty = YES;
colorspace = CGColorSpaceCreateDeviceRGB();

NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
}

- (void) initializeVariables {
Expand Down Expand Up @@ -618,12 +612,12 @@ - (void) draggingExited: (id<NSDraggingInfo>)info
[(sqSqueakOSXApplication *) gDelegateApp.squeakApplication recordDragEvent: SQDragLeave numberOfFiles: self.dragCount where: [info draggingLocation] windowIndex: self.windowLogic.windowIndex view: self];
self.dragCount = 0;
self.dragInProgress = NO;
self.dragItems = NULL;
gDelegateApp.dragItems = NULL;
}

- (BOOL) performDragOperation: (id<NSDraggingInfo>)info {
if (self.dragCount) {
self.dragItems = [self filterOutSqueakImageFilesFromDraggedURIs: info];
gDelegateApp.dragItems = [self filterOutSqueakImageFilesFromDraggedURIs: info];
[(sqSqueakOSXApplication *) gDelegateApp.squeakApplication recordDragEvent: SQDragDrop numberOfFiles: self.dragCount where: [info draggingLocation] windowIndex: self.windowLogic.windowIndex view: self];
}

Expand All @@ -649,24 +643,6 @@ - (BOOL) performDragOperation: (id<NSDraggingInfo>)info {
return YES;
}

- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSString* urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSURL *url = [NSURL URLWithString: urlString];
dragItems = [NSMutableArray arrayWithCapacity: 1];
[dragItems addObject: url];

[(sqSqueakOSXApplication *) gDelegateApp.squeakApplication recordURLEvent: SQDragDrop numberOfFiles: 1];
}

- (NSURL*) dragURIAtIndex: (sqInt) index {
if (!self.dragItems || index < 1 || index > [self.dragItems count])
return NULL;

return (self.dragItems)[(NSUInteger) index - 1];
}


- (BOOL)ignoreModifierKeysWhileDragging {
return YES;
}
Expand Down
8 changes: 4 additions & 4 deletions platforms/iOS/vm/OSX/sqSqueakOSXDropAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Some of this code was funded via a grant from the European Smalltalk User Group
#include "sqMacHostWindow.h"
#include "sq.h"
#import "sqSqueakOSXView.h"
#import "SqueakOSXAppDelegate.h"

extern SqueakOSXAppDelegate *gDelegateApp;
extern struct VirtualMachine* interpreterProxy;

sqInt dropInit(void) {
Expand All @@ -51,17 +53,15 @@ sqInt dropShutdown(void) {
};

char *dropRequestFileName(sqInt dropIndex) {
NSView <sqSqueakOSXView> *view = [((sqSqueakOSXScreenAndWindow*)((__bridge NSWindow *)windowHandleFromIndex(1)).delegate) getMainViewOnWindow];
NSURL *dragURIAtIndex = [view dragURIAtIndex: dropIndex];
NSURL *dragURIAtIndex = [gDelegateApp dragURIAtIndex: dropIndex];
if(!dragURIAtIndex || !dragURIAtIndex.fileURL)
return NULL;

return (char *) [dragURIAtIndex.path UTF8String];
}

char *dropRequestURI(sqInt dropIndex) {
NSView <sqSqueakOSXView> *view = [((sqSqueakOSXScreenAndWindow*)((__bridge NSWindow *)windowHandleFromIndex(1)).delegate) getMainViewOnWindow];
NSURL *dragURIAtIndex = [view dragURIAtIndex: dropIndex];
NSURL *dragURIAtIndex = [gDelegateApp dragURIAtIndex: dropIndex];
if(!dragURIAtIndex)
return NULL;

Expand Down
1 change: 0 additions & 1 deletion platforms/iOS/vm/OSX/sqSqueakOSXHeadlessView.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
int dragCount;
BOOL firstDrawCompleted;
BOOL syncNeeded;
NSMutableArray* dragItems;
CGDisplayFadeReservationToken fadeToken;
NSRect savedScreenBoundsAtTimeOfFullScreen;
CGColorSpaceRef colorspace;
Expand Down
3 changes: 1 addition & 2 deletions platforms/iOS/vm/OSX/sqSqueakOSXHeadlessView.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

@implementation sqSqueakOSXHeadlessView
@synthesize squeakTrackingRectForCursor,lastSeenKeyBoardStrokeDetails,
lastSeenKeyBoardModifierDetails,dragInProgress,dragCount,dragItems,windowLogic,savedScreenBoundsAtTimeOfFullScreen;
lastSeenKeyBoardModifierDetails,dragInProgress,dragCount,windowLogic,savedScreenBoundsAtTimeOfFullScreen;

#pragma mark Initialization / Release

Expand All @@ -76,7 +76,6 @@ - (void)initialize {
[self registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
dragInProgress = NO;
dragCount = 0;
dragItems = NULL;
clippyIsEmpty = YES;
colorspace = CGColorSpaceCreateDeviceRGB();
}
Expand Down
1 change: 0 additions & 1 deletion platforms/iOS/vm/OSX/sqSqueakOSXMetalView.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
int dragCount;
BOOL firstDrawCompleted;
BOOL syncNeeded;
NSMutableArray* dragItems;
CGDisplayFadeReservationToken fadeToken;
NSRect savedScreenBoundsAtTimeOfFullScreen;
CGColorSpaceRef colorspace;
Expand Down
29 changes: 3 additions & 26 deletions platforms/iOS/vm/OSX/sqSqueakOSXMetalView.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ @interface sqSqueakOSXMetalView ()

@implementation sqSqueakOSXMetalView
@synthesize squeakTrackingRectForCursor,lastSeenKeyBoardStrokeDetails,
lastSeenKeyBoardModifierDetails,dragInProgress,dragCount,dragItems,windowLogic,lastFrameSize,fullScreenInProgress,fullScreendispBitsIndex,graphicsCommandQueue;
lastSeenKeyBoardModifierDetails,dragInProgress,dragCount,windowLogic,lastFrameSize,fullScreenInProgress,fullScreendispBitsIndex,graphicsCommandQueue;

+ (BOOL) isMetalViewSupported {
// Try to create the MTL system device.
Expand Down Expand Up @@ -164,16 +164,10 @@ - (void)initialize {

dragInProgress = NO;
dragCount = 0;
dragItems = NULL;
clippyIsEmpty = YES;
colorspace = CGColorSpaceCreateDeviceRGB();
[self initializeSqueakColorMap];
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(didEnterFullScreen:) name:@"NSWindowDidEnterFullScreenNotification" object:nil];

NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
}

- (void) didEnterFullScreen: (NSNotification*) aNotification {
Expand Down Expand Up @@ -837,13 +831,13 @@ - (void) draggingExited: (id<NSDraggingInfo>)info
[(sqSqueakOSXApplication *) gDelegateApp.squeakApplication recordDragEvent: SQDragLeave numberOfFiles: self.dragCount where: [info draggingLocation] windowIndex: self.windowLogic.windowIndex view: self];
self.dragCount = 0;
self.dragInProgress = NO;
self.dragItems = NULL;
gDelegateApp.dragItems = NULL;
}

- (BOOL) performDragOperation: (id<NSDraggingInfo>)info {
// NSLog(@"performDragOperation %@",info);
if (self.dragCount) {
self.dragItems = [self filterOutSqueakImageFilesFromDraggedURIs: info];
gDelegateApp.dragItems = [self filterOutSqueakImageFilesFromDraggedURIs: info];
[(sqSqueakOSXApplication *) gDelegateApp.squeakApplication recordDragEvent: SQDragDrop numberOfFiles: self.dragCount where: [info draggingLocation] windowIndex: self.windowLogic.windowIndex view: self];
}

Expand All @@ -867,23 +861,6 @@ - (BOOL) performDragOperation: (id<NSDraggingInfo>)info {
return YES;
}

- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSString* urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSURL *url = [NSURL URLWithString: urlString];
dragItems = [NSMutableArray arrayWithCapacity: 1];
[dragItems addObject: url];

[(sqSqueakOSXApplication *) gDelegateApp.squeakApplication recordURLEvent: SQDragDrop numberOfFiles: 1];
}

- (NSURL*) dragURIAtIndex: (sqInt) index {
if (!self.dragItems || index < 1 || index > [self.dragItems count])
return NULL;

return (self.dragItems)[(NSUInteger) index - 1];
}

- (BOOL)ignoreModifierKeysWhileDragging {
return YES;
}
Expand Down
1 change: 0 additions & 1 deletion platforms/iOS/vm/OSX/sqSqueakOSXOpenGLView.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
int dragCount;
BOOL firstDrawCompleted;
BOOL syncNeeded;
NSMutableArray* dragItems;
CGDisplayFadeReservationToken fadeToken;
CGColorSpaceRef colorspace;
unsigned int* colorMap32;
Expand Down
Loading

0 comments on commit d10e5ea

Please sign in to comment.