From 589564a36f9fb0fa566762321fe9439febbfadfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Fri, 28 Jan 2022 15:25:24 +0100 Subject: [PATCH] support exporting atomic tables from table views everywhere when in edit mode --- HISTORY.md | 1 + src/tables.js | 53 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 4d3360de..dc3d3687 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -26,6 +26,7 @@ * blocks: support exporting numbers and text from result bubbles * objects: support exporting numbers and text from speech balloons when in edit mode * lists: support exporting atomic lists from list watchers everywhere when in edit mode +* tables: support exporting atomic tables from table views everywhere when in edit mode ### 2022-01-27 * blocks, gui: support dragging costumes and sounds out from result bubbles diff --git a/src/tables.js b/src/tables.js index 30cac939..e4cd4016 100644 --- a/src/tables.js +++ b/src/tables.js @@ -7,7 +7,7 @@ written by Jens Mönig jens@moenig.org - Copyright (C) 2021 by Jens Mönig + Copyright (C) 2022 by Jens Mönig This file is part of Snap!. @@ -69,7 +69,7 @@ MorphicPreferences, FrameMorph, HandleMorph, DialogBoxMorph, StringMorph, isNil, SpriteMorph, Context, Costume, BlockEditorMorph, SymbolMorph, IDE_Morph, Sound, SyntaxElementMorph, MenuMorph, SpriteBubbleMorph, SpeechBubbleMorph, CellMorph, ListWatcherMorph, BoxMorph, Variable, isSnapObject, useBlurredShadows, -CostumeIconMorph, SoundIconMorph*/ +CostumeIconMorph, SoundIconMorph, localize*/ /*jshint esversion: 6*/ @@ -1111,7 +1111,11 @@ TableMorph.prototype.columnAt = function (relativeX) { // TableMorph context menu TableMorph.prototype.userMenu = function () { - var menu = new MenuMorph(this); + var menu = new MenuMorph(this), + world = this.world(), + ide = detect(world.children, m => m instanceof IDE_Morph); + + if (ide.isAppMode) {return; } if (this.parentThatIsA(TableDialogMorph)) { if (this.colWidths.length) { menu.addItem('reset columns', 'resetColumns'); @@ -1121,11 +1125,6 @@ TableMorph.prototype.userMenu = function () { menu.addItem( 'blockify', () => { - var world = this.world(), - ide = detect( - world.children, - m => m instanceof IDE_Morph - ); this.table.blockify().pickUp(world); world.hand.grabOrigin = { origin: ide.palette, @@ -1133,6 +1132,24 @@ TableMorph.prototype.userMenu = function () { }; } ); + menu.addItem( + 'export', + () => { + if (this.table.canBeCSV()) { + ide.saveFileAs( + this.table.asCSV(), + 'text/csv;charset=utf-8', // RFC 4180 + localize('data') // name + ); + } else { + ide.saveFileAs( + this.table.asJSON(true), // guessObjects + 'text/json;charset=utf-8', + localize('data') // name + ); + } + } + ); } menu.addItem('open in another dialog...', 'openInDialog'); return menu; @@ -1146,8 +1163,6 @@ TableMorph.prototype.userMenu = function () { menu.addItem( 'blockify', () => { - var world = this.world(), - ide = detect(world.children, m => m instanceof IDE_Morph); this.table.blockify().pickUp(world); world.hand.grabOrigin = { origin: ide.palette, @@ -1155,6 +1170,24 @@ TableMorph.prototype.userMenu = function () { }; } ); + menu.addItem( + 'export', + () => { + if (this.table.canBeCSV()) { + ide.saveFileAs( + this.table.asCSV(), + 'text/csv;charset=utf-8', // RFC 4180 + localize('data') // name + ); + } else { + ide.saveFileAs( + this.table.asJSON(true), // guessObjects + 'text/json;charset=utf-8', + localize('data') // name + ); + } + } + ); } menu.addLine(); menu.addItem('open in dialog...', 'openInDialog');