diff options
author | Kevin Walzer <kw@codebykevin.com> | 2019-09-01 05:02:47 (GMT) |
---|---|---|
committer | Kevin Walzer <kw@codebykevin.com> | 2019-09-01 05:02:47 (GMT) |
commit | b47684b3d7c8ac79186f4928931bc520ea9fec42 (patch) | |
tree | 65591ef65d12fc6f537124604e392a4979471928 | |
parent | 3331acc1d00f09d5b8fb46e3e922af98f88fecc6 (diff) | |
download | tk-b47684b3d7c8ac79186f4928931bc520ea9fec42.zip tk-b47684b3d7c8ac79186f4928931bc520ea9fec42.tar.gz tk-b47684b3d7c8ac79186f4928931bc520ea9fec42.tar.bz2 |
More refinements
-rw-r--r-- | doc/tk_mac.n | 3 | ||||
-rw-r--r-- | library/tk.tcl | 21 | ||||
-rw-r--r-- | macosx/tkMacOSXHLEvents.c | 14 |
3 files changed, 26 insertions, 12 deletions
diff --git a/doc/tk_mac.n b/doc/tk_mac.n index a147a1d..bf9159a 100644 --- a/doc/tk_mac.n +++ b/doc/tk_mac.n @@ -124,7 +124,6 @@ proc ::tk::mac::OpenDocument {args} { } .CE .RE -Note: the application must be running for this command to work. .TP \fB::tk::mac::PrintDocument \fIfile...\fR . @@ -132,7 +131,7 @@ If a proc of this name is defined it is the default Apple Event handler for kAEPrintDocuments, .QW pdoc , the Apple Event sent when your application is asked to print a -document. It takes a single absolute file path as an argument. Note: the application must be running for this command to work. +document. It takes a single absolute file path as an argument. .TP \fB::tk::mac::Quit\fR . diff --git a/library/tk.tcl b/library/tk.tcl index 06185d2..deaf784 100644 --- a/library/tk.tcl +++ b/library/tk.tcl @@ -685,13 +685,24 @@ if {[tk windowingsystem] eq "aqua"} { } } -#register to send data to macOS Services + if {[tk windowingsystem] eq "aqua"} { -proc ::tk::RegisterServiceWidget {w} { - ::tk::mac::registerServiceWidget $w - } + #register to send data to macOS Services + proc ::tk::RegisterServiceWidget {w} { + ::tk::mac::registerServiceWidget $w + } + + #stub procedures to respond to "do script" Apple Events + proc ::tk::mac::DoScriptFile {file} { + source $file + } + proc ::tk::mac::DoScriptText {script} { + eval $script + } } + + # Run the Ttk themed widget set initialization if {$::ttk::library ne ""} { uplevel \#0 [list source $::ttk::library/ttk.tcl] @@ -722,6 +733,6 @@ proc tk::mac::LaunchURL {url} { proc saymyname {} { - exec say "my name is [exec whoami]" + puts "my name is [exec whoami]" } diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c index 7f55ea7..72c7d08 100644 --- a/macosx/tkMacOSXHLEvents.c +++ b/macosx/tkMacOSXHLEvents.c @@ -229,7 +229,7 @@ static char* scriptTextProc = "::tk::mac::DoScriptText"; */ err = AEGetParamPtr(theDesc, keyDirectObject, typeFileURL, &type, (Ptr) URLBuffer, URL_MAX_LENGTH, &actual); - if (err == noErr && actual > 0){ + if (err == noErr && actual > 0) { URLBuffer[actual] = '\0'; NSString *urlString = [NSString stringWithUTF8String:(char*)URLBuffer]; NSURL *fileURL = [NSURL URLWithString:urlString]; @@ -266,19 +266,24 @@ static char* scriptTextProc = "::tk::mac::DoScriptText"; * if that procedure exists. */ char *data = ckalloc(actual + 1); + if (noErr == AEGetParamPtr(theDesc, keyDirectObject, typeUTF8Text, &type, data, actual, NULL)) { Tcl_DString *textScriptCommand = &staticAEInfo.command; Tcl_DStringInit(textScriptCommand); - if (Tcl_FindCommand(_eventInterp, scriptTextProc, NULL, 0)){ + if (Tcl_FindCommand(_eventInterp, scriptTextProc, NULL, 0)) { Tcl_DStringAppend(textScriptCommand, scriptTextProc, -1); } else { Tcl_DStringAppend(textScriptCommand, "eval", -1); } + NSLog(@"data is %s", data); Tcl_DStringAppendElement(textScriptCommand, data); - NSLog(@"data is %s", data); - tclErr = Tcl_EvalEx(_eventInterp,Tcl_DStringValue(textScriptCommand),Tcl_DStringLength(textScriptCommand), TCL_EVAL_GLOBAL); + int tclErr = Tcl_EvalEx(_eventInterp,Tcl_DStringValue(textScriptCommand),Tcl_DStringLength(textScriptCommand), TCL_EVAL_GLOBAL); + if (tclErr!= TCL_OK) { + Tcl_BackgroundException(_eventInterp, tclErr); + } + Tcl_DStringFree(textScriptCommand); ckfree(data); } else { /* @@ -291,7 +296,6 @@ static char* scriptTextProc = "::tk::mac::DoScriptText"; staticAEInfo.procedure = scriptTextProc; Tcl_DoWhenIdle(ProcessAppleEventEventually, (ClientData)&staticAEInfo); } - } /* |