diff options
-rw-r--r-- | SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist | 129 | ||||
-rw-r--r-- | Source/SPBundleEditorController.m | 2 |
2 files changed, 130 insertions, 1 deletions
diff --git a/SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist b/SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist new file mode 100644 index 00000000..86bf998a --- /dev/null +++ b/SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist @@ -0,0 +1,129 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>author</key> + <string>Hans-Jörg Bibiko</string> + <key>category</key> + <string>Copy</string> + <key>command</key> + <string>cat | perl -e ' + +# read first line to get the column names (header) +$firstLine = <>; + +# bail if nothing could read +if(!defined($firstLine)) { + exit 0; +} + +# store the column names +chomp($firstLine); +$firstLine =~ s/\"/\\\"/g; # escape " +@header = split(/\t/, $firstLine); + +$h_cnt = $#header; # number of columns + +# get the column definitions +open(META, $ENV{"SP_BUNDLE_INPUT_TABLE_METADATA"}) or die $!; +@meta = (); +while(<META>) { + chomp(); + my @arr = split(/\t/); + push @meta, \@arr; +} +close(META); + +print "{\n\t\"data\":\n\t[\n"; + +# read row data of each selected row +$rowData=<>; +while($rowData) { + + print "\t\t{\n"; + + # remove line ending + chomp($rowData); + + # escape " + $rowData=~s/\"/\\\"/g; + + # split column data which are tab-delimited + @data = split(/\t/, $rowData); + for($i=0; $i<=$h_cnt; $i++) { + + # re-escape \t and \n + $cellData = $data[$i]; + $cellData =~ s/↵/\n/g; + $cellData =~ s/⇥/\t/g; + + print "\t\t\t\"$header[$i]\": "; + + # check for data types + if($cellData eq "NULL") { + print "null"; + } + elsif($meta[$i]->[1] eq "integer" || $meta[$i]->[1] eq "float") { + print "$cellData"; + } else { + print "\"$cellData\""; + } + + # suppress last , + if($i<$h_cnt) { + print ","; + } + + print "\n"; + + } + + print "\t\t}"; + + # get next row + $rowData=<>; + + # suppress last , + if($rowData) { + print ","; + } + + print "\n"; +} + +print "\t]\n}\n"; + +' | __CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbcopy</string> + <key>contact</key> + <string>znvy@ovovxb.qr</string> + <key>description</key> + <string>Copies the selected rows excluding any BLOB data in a data table JSON formatted into the pasteboard. + +Version 1.0</string> + <key>input</key> + <string>selectedtablerowsastab</string> + <key>internalKeyEquivalent</key> + <dict> + <key>characters</key> + <string>C</string> + <key>keyCode</key> + <integer>8</integer> + <key>modifierFlags</key> + <integer>262144</integer> + </dict> + <key>keyEquivalent</key> + <string>^c</string> + <key>name</key> + <string>Copy as JSON</string> + <key>output</key> + <string>none</string> + <key>scope</key> + <string>datatable</string> + <key>tooltip</key> + <string>Copies the selected rows excluding any BLOB data JSON formatted into the pasteboard</string> + <key>uuid</key> + <string>CBB8B7A7-5AB9-4F4C-A404-D99CA9521337</string> + <key>isDefaultBundle</key> + <true/> +</dict> +</plist> diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index de779e67..ce80acde 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -1291,7 +1291,7 @@ [touchedBundleArray addObject:oldBundleName]; [self _updateBundleDataView]; - + [commandTextView setSelectedRange:NSMakeRange(0,0)]; } - (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(id)item |