Commit b2e49bf0 authored by Diederik van Arkel's avatar Diederik van Arkel
Browse files

Added launching of documents;

parent 8785038f
......@@ -35,3 +35,7 @@ ShellDefault :: !{#Char} !(PSt .l) -> (!Int,!(PSt .l))
GetDialogBackgroundColour :: !(PSt .l) -> (!Colour, !PSt .l)
isWindow :: !Id *(PSt .l) -> (Bool,*(PSt .l))
/////////
LaunchTheDocument :: !String !String !Int !*a -> (!Int,!*a)
......@@ -196,3 +196,200 @@ isWindow wId ps
# (s,ps) = accPIO getWindowsStack ps
= (isMember wId s, ps)
/////////////////////
import nodebug
import code from "cUtilSystem."
LaunchTheDocument :: !String !String !Int !*a -> (!Int,!*a)
LaunchTheDocument docPath appPath appCreator env
# (error_n,appSpec,tb) = FSMakeFSSpec appPath OSNewToolbox
| error_n <> 0 = trace_n` ("LaunchTheDocument",1,appPath,error_n) (error_n,env)
# (error_n,docSpec,tb) = FSMakeFSSpec docPath tb
| error_n <> 0 = trace_n` ("LaunchTheDocument",2,docPath,error_n) (error_n,env)
# (error_n,tb) = LaunchTheDocument docSpec appCreator appSpec tb
= trace_n` ("LaunchTheDocument",3,appCreator,error_n) (error_n,env)
where
LaunchTheDocument :: !String !Int !String !*Toolbox -> (!Int,!*Toolbox)
LaunchTheDocument _ _ _ _ = code {
ccall LaunchTheDocument "sIs:I:I"
}
/*
import appleevents
KAEApplicationDied :== 0x6F626974; // 'obit'
KAEOpenDocuments :== 0x6F646F63; // 'odoc'
TypeList :== 0x6C697374; // 'list'
send_command_to_clean_compiler :: !String !String !String !Bool -> (!Int,!Int,!String);
send_command_to_clean_compiler signature name command wait_for_reply
# (os_error_code,error_n,output_string,tb)
= send_command_to_clean_compiler0 signature command wait_for_reply OSNewToolbox
| error_n<>(-2)
= (os_error_code,error_n,output_string);
# (error_n,fsspec,tb) = FSMakeFSSpec name tb
| error_n <> 0
= (error_n,-2,output_string)
# (launch_error_n,tb) = LaunchApplicationFSSpec fsspec 0xCA00 tb
// # (launch_error_n,_)
// = LaunchApplication name 0xCA000000 OSNewToolbox; // Hangs under OS X?
| launch_error_n>=0
# (os_error_code,error_n,output_string,tb)
= send_command_to_clean_compiler0 signature command wait_for_reply tb
= (os_error_code,error_n,output_string)
= (os_error_code,-2,output_string);
send_command_to_clean_compiler0 :: !String !String !Bool !*OSToolbox -> (!Int,!Int,!String,!*OSToolbox);
send_command_to_clean_compiler0 signature command wait tb
| error_code1<>0
= (error_code1,-1,"NewPtr failed",tb);
// # error_code2 = AECreateDesc TypeApplSignature "MPSX" descriptor; // Tool Server
# error_code2
= trace_n "AECreateDesc" AECreateDesc TypeApplSignature signature descriptor;
| error_code2<>0
= (free_memory error_code2,-1,"AECreateDesc failed",tb);
# error_code3
= trace_n "AECreateAppleEvent" AECreateAppleEvent KCoreEventClass KAEOpenDocuments descriptor KAutoGenerateReturnID KAnyTransactionID apple_event;
| error_code3<>0
= (free_descriptor_and_memory error_code3,-1,"AECreateAppleEvent failed",tb);
# error_code4
// err = AECreateList(NULL, 0, false, &fileList);
= trace_n "AEPutParamPtr" AEPutParamPtr apple_event KeyDirectObject TypeChar command;
| error_code4<>0
= (free_apple_event_and_desciptor_and_memory error_code4,-1,"AEPutParamPtr failed",tb);
/*
err = NewAlias(NULL, &the_file, &docAlias);
HLock((Handle) docAlias);
err = AECreateDesc(typeAlias, (Ptr) (*docAlias),
GetHandleSize((Handle) docAlias), &fileListElt);
HUnlock((Handle) docAlias);
*/
//err = AEPutDesc(&fileList, 0, &fileListElt);
# error_code5
= case wait of
True -> trace_n "AESend wait" AESend apple_event result_apple_event KAEWaitReply KAENormalPriority KNoTimeOut 0 0;
// True -> loop OSNewToolbox;
_ -> trace_n "AESend nowait" AESend apple_event 0 KAEQueueReply KAENormalPriority KNoTimeOut 0 0;
| error_code5==(-600)
= (free_apple_event_and_desciptor_and_memory error_code5,-2,"AESend failed",tb);
| error_code5==(-609)
= (free_apple_event_and_desciptor_and_memory error_code5,-2,"AESend failed",tb);
| error_code5==(-903)
= (free_apple_event_and_desciptor_and_memory error_code5,-2,"need to add HighLevel event aware to SIZE resource of IDE...",tb);
| error_code5==(-1712)
= (free_apple_event_and_desciptor_and_memory error_code5,-1,"AESend failed; Application died",tb);
| error_code5<>0
= (free_apple_event_and_desciptor_and_memory error_code5,-1,"AESend failed",tb);
| not wait
= (free_apple_event_and_desciptor_and_memory error_code5,0,"",tb);
# (error_code6,_,v1,_)
= trace_n "AEGetIntParamPtr" AEGetIntParamPtr result_apple_event KeyErrorNumber TypeLongInteger;
# (error_code7,_,s2)
= trace_n "AEGetStringParamPtr" AEGetStringParamPtr result_apple_event KeyErrorString TypeChar result_string;
# os_error_code
= trace_n "fraeaaeadam" free_result_apple_event_and_apple_event_and_desciptor_and_memory error_code6 error_code7
# error_n
// = if (error_code6<0) 0 v1
= if (error_code6<>0) 0 v1
# output_string
= if (error_code7<>0) "" (result_string % (0,s2-1))
# tb = trace_n` ("CALL",error_code6,v1,error_code7,s2) tb
= (os_error_code,error_n,output_string,tb)
where
loop tb
# err = AESend apple_event result_apple_event KAEWaitReply KAENormalPriority (60) 0 0;
| err==(-1712)
# (avail,what,message,when,wherex,wherey,modifiers,tb) = EventAvail NetworkMask tb
| avail && what == HighLevelEvent && message == KCoreEventClass && wherex == KAEApplicationDied
= -1712
= loop tb
= err
result_string = createArray 5120 '0';
(memory,error_code1,_)
= NewPtr (SizeOfAEDesc+SizeOfAppleEvent+SizeOfAppleEvent) 0;
descriptor
= memory;
apple_event
= memory+SizeOfAEDesc;
result_apple_event
= memory+SizeOfAEDesc+SizeOfAppleEvent;
free_result_apple_event_and_apple_event_and_desciptor_and_memory error_code6 error_code7
| error_code6==error_code6 && error_code7==error_code7
= free_apple_event_and_desciptor_and_memory free_error_code;
where
free_error_code = AEDisposeDesc result_apple_event;
free_apple_event_and_desciptor_and_memory error_code
| error_code==0
= free_descriptor_and_memory free_error_code;
| free_error_code==0
= free_descriptor_and_memory error_code;
= free_descriptor_and_memory error_code;
where
free_error_code = AEDisposeDesc apple_event;
free_descriptor_and_memory error_code
| error_code==0
= free_memory free_error_code;
| free_error_code==0
= free_memory error_code;
= free_memory error_code;
where
free_error_code = AEDisposeDesc descriptor;
free_memory error_code
| error_code==0
= if (free_error_code==255) 0 free_error_code;
| free_error_code==0
= error_code;
= error_code;
where
(free_error_code,_) = DisposPtr memory 0;
DisposPtr p t
# t = DisposePtr p t
= MemError t
where
MemError :: !*Toolbox -> (!Int,!*Toolbox)
MemError _ = code {
ccall MemError "P:I:I"
}
/*
LSLaunchFSRefSpec inLaunchSpec;
/* app to use, can be NULL*/
inLaunchSpec.appRef = &outAppRef;
/* items to open/print, can be NULL*/
inLaunchSpec.numDocs = numDocuments;
/* array of FSRefs*/
inLaunchSpec.itemRefs = documentRefArray;
/* passed untouched to application as optional parameter*/
inLaunchSpec.passThruParams = nil;
/* default = open, async, use Info.plist, start Classic*/
inLaunchSpec.launchFlags = kLSLaunchDefaults;
/* used if you register for app birth/death notification*/
inLaunchSpec.asyncRefCon = nil;
err = LSOpenFromRefSpec( &inLaunchSpec, &outLaunchedRef );
extern OSStatus
LSOpenFromRefSpec(
const LSLaunchFSRefSpec * inLaunchSpec,
FSRef * outLaunchedRef) /* can be NULL */
struct LSLaunchFSRefSpec {
const FSRef * appRef; /* app to use, can be NULL*/
UInt32 numDocs; /* items to open/print, can be NULL*/
const FSRef * itemRefs; /* array of FSRefs*/
const AEDesc * passThruParams; /* passed untouched to application as optional parameter*/
LSLaunchFlags launchFlags;
void * asyncRefCon; /* used if you register for app birth/death notification*/
};
typedef struct LSLaunchFSRefSpec LSLaunchFSRefSpec;
*/
*/
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment