support for viewing 2D lists as tables

dev
Jens Mönig 2016-02-24 11:35:18 +01:00
rodzic 645fb346ce
commit df0269f5cc
15 zmienionych plików z 1624 dodań i 202 usunięć

Wyświetl plik

@ -136,27 +136,20 @@
constructor for further details.
*/
/*global Array, BlinkerMorph, BouncerMorph, BoxMorph, CircleBoxMorph,
Color, ColorPaletteMorph, ColorPickerMorph, CursorMorph, Date,
FrameMorph, Function, GrayPaletteMorph, HandMorph, HandleMorph,
InspectorMorph, ListMorph, Math, MenuItemMorph, MenuMorph, Morph,
MorphicPreferences, MouseSensorMorph, Node, Object, PenMorph, Point,
Rectangle, ScrollFrameMorph, ShadowMorph, SliderButtonMorph,
SliderMorph, String, StringFieldMorph, StringMorph, TextMorph,
TriggerMorph, WorldMorph, clone, contains, copy, degrees, detect,
document, getDocumentPositionOf, isNaN, isObject, isString, newCanvas,
nop, parseFloat, radians, standardSettings, touchScreenSettings,
useBlurredShadows, version, window, SpeechBubbleMorph, modules, StageMorph,
fontHeight*/
/*global SpriteMorph, Context, ListWatcherMorph, CellMorph,
DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/
/*global IDE_Morph, BlockDialogMorph, BlockEditorMorph, localize, isNil*/
/*global Array, BoxMorph,
Color, ColorPaletteMorph, CursorMorph, FrameMorph, Function, HandleMorph,
Math, MenuMorph, Morph, MorphicPreferences, Object, Point, ScrollFrameMorph,
ShadowMorph, String, StringMorph, TextMorph, WorldMorph, contains, degrees,
detect, document, getDocumentPositionOf, isNaN, isString, newCanvas, nop,
parseFloat, radians, useBlurredShadows, SpeechBubbleMorph, modules,
StageMorph, fontHeight, TableFrameMorph, SpriteMorph, Context,
ListWatcherMorph, CellMorph, DialogBoxMorph, BlockInputFragmentMorph,
PrototypeHatBlockMorph, Costume, IDE_Morph, BlockDialogMorph,
BlockEditorMorph, localize, isNil*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2016-January-22';
modules.blocks = '2016-February-24';
var SyntaxElementMorph;
var BlockMorph;
@ -1790,6 +1783,11 @@ SyntaxElementMorph.prototype.showBubble = function (value, exportPic) {
morphToShow.isDraggable = false;
morphToShow.expand(this.parentThatIsA(ScrollFrameMorph).extent());
isClickable = true;
} else if (value instanceof TableFrameMorph) {
morphToShow = value;
morphToShow.isDraggable = false;
morphToShow.expand(this.parentThatIsA(ScrollFrameMorph).extent());
isClickable = true;
} else if (value instanceof Morph) {
img = value.fullImage();
morphToShow = new Morph();
@ -2600,6 +2598,7 @@ BlockMorph.prototype.restoreInputs = function (oldInputs) {
BlockMorph.prototype.showHelp = function () {
var myself = this,
ide = this.parentThatIsA(IDE_Morph),
blockEditor,
pic = new Image(),
help,
comment,
@ -2609,6 +2608,13 @@ BlockMorph.prototype.showHelp = function () {
this.definition.helpSpec() : this.selector,
ctx;
if (!ide) {
blockEditor = this.parentThatIsA(BlockEditorMorph);
if (blockEditor) {
ide = blockEditor.target.parentThatIsA(IDE_Morph);
}
}
pic.onload = function () {
help = newCanvas(new Point(pic.width, pic.height));
ctx = help.getContext('2d');
@ -3788,6 +3794,7 @@ CommandBlockMorph.prototype.userDestroyJustThis = function () {
above,
cslot = this.parentThatIsA(CSlotMorph);
this.topBlock().fullChanged();
if (this.parent) {
pb = this.parent.parentThatIsA(CommandBlockMorph);
}
@ -4404,7 +4411,7 @@ ReporterBlockMorph.prototype.snap = function (hand) {
target;
this.cachedSlotSpec = null;
if (!scripts instanceof ScriptsMorph) {
if (!(scripts instanceof ScriptsMorph)) {
return null;
}
@ -11242,7 +11249,7 @@ CommentMorph.prototype.snap = function (hand) {
var scripts = this.parent,
target;
if (!scripts instanceof ScriptsMorph) {
if (!(scripts instanceof ScriptsMorph)) {
return null;
}

Wyświetl plik

@ -108,7 +108,7 @@ WatcherMorph, Variable*/
// Global stuff ////////////////////////////////////////////////////////
modules.byob = '2016-January-18';
modules.byob = '2016-February-24';
// Declarations
@ -488,7 +488,7 @@ CustomCommandBlockMorph.prototype.restoreInputs = function (oldInputs) {
old = oldInputs[i];
if (old instanceof ReporterBlockMorph &&
(!(inp instanceof TemplateSlotMorph))) {
myself.silentReplaceInput(inp, old);
myself.silentReplaceInput(inp, old.fullCopy());
} else if (old instanceof InputSlotMorph
&& inp instanceof InputSlotMorph) {
inp.setContents(old.evaluate());

90
gui.js
Wyświetl plik

@ -54,24 +54,22 @@
*/
/*global modules, Morph, SpriteMorph, BoxMorph, SyntaxElementMorph, Color,
ListWatcherMorph, isString, TextMorph, newCanvas, useBlurredShadows,
radians, VariableFrame, StringMorph, Point, SliderMorph, MenuMorph,
morphicVersion, DialogBoxMorph, ToggleButtonMorph, contains,
ScrollFrameMorph, StageMorph, PushButtonMorph, InputFieldMorph, FrameMorph,
Process, nop, SnapSerializer, ListMorph, detect, AlignmentMorph, TabMorph,
Costume, CostumeEditorMorph, MorphicPreferences, touchScreenSettings,
standardSettings, Sound, BlockMorph, ToggleMorph, InputSlotDialogMorph,
ScriptsMorph, isNil, SymbolMorph, BlockExportDialogMorph,
BlockImportDialogMorph, SnapTranslator, localize, List, InputSlotMorph,
SnapCloud, Uint8Array, HandleMorph, SVG_Costume, fontHeight, hex_sha512,
sb, CommentMorph, CommandBlockMorph, BlockLabelPlaceHolderMorph, Audio,
SpeechBubbleMorph, ScriptFocusMorph, XML_Element, WatcherMorph,
BlockRemovalDialogMorph, saveAs*/
/*global modules, Morph, SpriteMorph, SyntaxElementMorph, Color,
ListWatcherMorph, TextMorph, newCanvas, useBlurredShadows, VariableFrame,
StringMorph, Point, MenuMorph, morphicVersion, DialogBoxMorph,
ToggleButtonMorph, contains, ScrollFrameMorph, StageMorph, PushButtonMorph,
InputFieldMorph, FrameMorph, Process, nop, SnapSerializer, ListMorph, detect,
AlignmentMorph, TabMorph, Costume, MorphicPreferences, Sound, BlockMorph,
ToggleMorph, InputSlotDialogMorph, ScriptsMorph, isNil, SymbolMorph,
BlockExportDialogMorph, BlockImportDialogMorph, SnapTranslator, localize,
List, InputSlotMorph, SnapCloud, Uint8Array, HandleMorph, SVG_Costume,
fontHeight, hex_sha512, sb, CommentMorph, CommandBlockMorph,
BlockLabelPlaceHolderMorph, Audio, SpeechBubbleMorph, ScriptFocusMorph,
XML_Element, WatcherMorph, BlockRemovalDialogMorph, saveAs, TableMorph*/
// Global stuff ////////////////////////////////////////////////////////
modules.gui = '2016-January-08';
modules.gui = '2016-February-24';
// Declarations
@ -1642,10 +1640,6 @@ IDE_Morph.prototype.droppedSVG = function (anImage, name) {
this.currentSprite.wearCostume(costume);
this.spriteBar.tabBar.tabTo('costumes');
this.hasChangedMedia = true;
this.showMessage(
'SVG costumes are\nnot yet fully supported\nin every browser',
2
);
};
IDE_Morph.prototype.droppedAudio = function (anAudio, name) {
@ -1847,7 +1841,9 @@ IDE_Morph.prototype.applySavedSettings = function () {
longform = this.getSetting('longform'),
longurls = this.getSetting('longurls'),
plainprototype = this.getSetting('plainprototype'),
keyboard = this.getSetting('keyboard');
keyboard = this.getSetting('keyboard'),
tables = this.getSetting('tables'),
tableLines = this.getSetting('tableLines');
// design
if (design === 'flat') {
@ -1894,6 +1890,20 @@ IDE_Morph.prototype.applySavedSettings = function () {
ScriptsMorph.prototype.enableKeyboard = false;
}
// tables
if (tables) {
List.prototype.enableTables = true;
} else {
List.prototype.enableTables = false;
}
// tableLines
if (tableLines) {
TableMorph.prototype.highContrast = true;
} else {
TableMorph.prototype.highContrast = false;
}
// plain prototype labels
if (plainprototype) {
BlockLabelPlaceHolderMorph.prototype.plainLabel = true;
@ -2427,6 +2437,40 @@ IDE_Morph.prototype.settingsMenu = function () {
'check to enable\nkeyboard editing support',
false
);
addPreference(
'Table support',
function () {
List.prototype.enableTables =
!List.prototype.enableTables;
if (List.prototype.enableTables) {
myself.saveSetting('tables', true);
} else {
myself.removeSetting('tables');
}
},
List.prototype.enableTables,
'uncheck to disable\nmulti-column list views',
'check for multi-column\nlist view support',
false
);
if (List.prototype.enableTables) {
addPreference(
'Table lines',
function () {
TableMorph.prototype.highContrast =
!TableMorph.prototype.highContrast;
if (TableMorph.prototype.highContrast) {
myself.saveSetting('tableLines', true);
} else {
myself.removeSetting('tableLines');
}
},
TableMorph.prototype.highContrast,
'uncheck for less contrast\nmulti-column list views',
'check for higher contrast\ntable views',
false
);
}
menu.addLine(); // everything below this line is stored in the project
addPreference(
'Thread safe scripts',
@ -2750,7 +2794,7 @@ IDE_Morph.prototype.aboutSnap = function () {
module, btn1, btn2, btn3, btn4, licenseBtn, translatorsBtn,
world = this.world();
aboutTxt = 'Snap! 4.0.4\nBuild Your Own Blocks\n\n'
aboutTxt = 'Snap! 4.0.5\nBuild Your Own Blocks\n\n'
+ 'Copyright \u24B8 2016 Jens M\u00F6nig and '
+ 'Brian Harvey\n'
+ 'jens@moenig.org, bh@cs.berkeley.edu\n\n'
@ -4037,7 +4081,7 @@ IDE_Morph.prototype.toggleStageSize = function (isSmall) {
myself.stageRatio = targetRatio;
delete myself.step;
myself.fps = 0;
myself.isSmallStage = !(targetRatio === 1);
myself.isSmallStage = (targetRatio !== 1);
myself.controlBar.stageSizeButton.refresh();
} else {
count += 1;
@ -7140,7 +7184,7 @@ StageHandleMorph.prototype.mouseDownLeft = function (pos) {
} else {
this.step = null;
ide.isSmallStage = !(ide.stageRatio === 1);
ide.isSmallStage = (ide.stageRatio !== 1);
ide.controlBar.stageSizeButton.refresh();
}
};

Wyświetl plik

@ -2867,3 +2867,7 @@ end - bulk of 151215
------
* Blocks: Fixed a slight rendering glitch when deleting reporters via the context menu
160224
------
* == v4.0.5 ==== - table views

Wyświetl plik

@ -185,7 +185,7 @@ SnapTranslator.dict.ar = {
'translator_e-mail':
'tarekgalal46@hotmail.com', // optional
'last_changed':
'2016-01-17', // this, too, will appear in the Translators tab
'2016-01-23', // this, too, will appear in the Translators tab
// GUI
// control bar:
@ -429,6 +429,8 @@ SnapTranslator.dict.ar = {
'دخـول',
'mouse-departed':
'مغـادرة',
'when %b':
'%b عندما',
'when I receive %msgHat':
'%msgHat رسـالة أستقبال عند',
'broadcast %msg':
@ -480,9 +482,9 @@ SnapTranslator.dict.ar = {
'call %repRing %inputs':
'إستدع %repRing %inputs',
'run %cmdRing w/continuation':
'نفّذ %cmdRing w/continuation',
'نفّذ %cmdRing (الفاعلية استمرار بقاء مع)',
'call %cmdRing w/continuation':
'استدع %cmdRing w/continuation',
'استدع %cmdRing (الفاعلية استمرار بقاء مع)',
'warp %c':
'تسريع %c',
'when I start as a clone':
@ -817,6 +819,12 @@ SnapTranslator.dict.ar = {
'حدد لجعل نهايات الخطوط\n قائمة الزاوية',
'uncheck for round ends of lines':
'أزل لجعل نهايات الخطوط \nدائرية',
'Inheritance support':
' توريث الخصائص بين الكائنات',
'uncheck to disable\nsprite inheritance features':
'أزل لألغاء تفعيل توريث الخصائص بين الكائنات',
'check for sprite\ninheritance features':
'حدد لتفعيل توريث الخصائص بين الكائنات',
// inputs
'with inputs':
@ -1328,7 +1336,6 @@ SnapTranslator.dict.ar = {
'أزل التحديد لألغاء مساعد التكويد',
'check for block\nto text mapping features':
'حَدد لتفعيل مساعد التكويد',
'current %dates':
'التاريخ الحالي %dates',
'year':'سنة',

Wyświetl plik

@ -6,7 +6,7 @@
written by Jens Mönig
Copyright (C) 2015 by Jens Mönig
Copyright (C) 2016 by Jens Mönig
This file is part of Snap!.
@ -185,7 +185,7 @@ SnapTranslator.dict.de = {
'translator_e-mail':
'jens@moenig.org', // optional
'last_changed':
'2015-12-22', // this, too, will appear in the Translators tab
'2016-02-24', // this, too, will appear in the Translators tab
// GUI
// control bar:
@ -815,6 +815,10 @@ SnapTranslator.dict.de = {
'Helles Design',
'Keyboard Editing':
'Tastaturunterstützung',
'Table support':
'Tabellenunterstützung',
'Table lines':
'Tabellen mit Linien',
'Thread safe scripts':
'Threadsicherheit',
'uncheck to allow\nscript reentrance':
@ -942,6 +946,18 @@ SnapTranslator.dict.de = {
'rename sound':
'Klang umbenennen',
// lists and tables
'list view...':
'Listenansicht...',
'table view...':
'tabellarische Ansicht...',
'open in dialog...':
'in neuem Fenster \u00f6ffnen',
'reset columns':
'Spaltenbreiten zur\u00fccksetzen',
'items':
'Elemente',
// dialogs
// buttons
'OK':

144
lists.js
Wyświetl plik

@ -7,7 +7,7 @@
written by Jens Mönig and Brian Harvey
jens@moenig.org, bh@cs.berkeley.edu
Copyright (C) 2015 by Jens Mönig and Brian Harvey
Copyright (C) 2016 by Jens Mönig and Brian Harvey
This file is part of Snap!.
@ -56,12 +56,13 @@
// Global settings /////////////////////////////////////////////////////
/*global modules, contains, BoxMorph, WorldMorph, HandleMorph,
PushButtonMorph, SyntaxElementMorph, Color, Point, WatcherMorph,
StringMorph, SpriteMorph, ScrollFrameMorph, CellMorph, ArrowMorph,
MenuMorph, snapEquals, Morph, isNil, localize, MorphicPreferences*/
/*global modules, BoxMorph, HandleMorph, PushButtonMorph, SyntaxElementMorph,
Color, Point, WatcherMorph, StringMorph, SpriteMorph, ScrollFrameMorph,
CellMorph, ArrowMorph, MenuMorph, snapEquals, Morph, isNil, localize,
MorphicPreferences, TableDialogMorph, SpriteBubbleMorph, SpeechBubbleMorph,
TableFrameMorph, TableMorph, Variable*/
modules.lists = '2015-November-20';
modules.lists = '2016-February-24';
var List;
var ListWatcherMorph;
@ -111,6 +112,12 @@ function List(array) {
this.lastChanged = Date.now();
}
// List global preferences
List.prototype.enableTables = false; // default, to not confuse NYC teachers
// List printing
List.prototype.toString = function () {
return 'a List [' + this.length + ' elements]';
};
@ -234,6 +241,79 @@ List.prototype.contains = function (element) {
});
};
// List table (2D) accessing (for table morph widget):
List.prototype.isTable = function () {
return this.enableTables && (this.length() > 100 || this.cols() > 1);
};
List.prototype.get = function (col, row) {
var r, len, cols;
if (!col) {
if (!row) {return [this.length()]; }
if (row > this.rows()) {return null; }
return this.rowName(row);
} else if (!row) {
if (this.cols() === 1) {return localize('items'); }
return this.colName(col);
}
r = this.at(row);
// encode "orphaned" as arrays and overshooting ones as Variables
if (r instanceof List) {
len = r.length();
cols = this.cols();
if (col > len) {
return null;
} else if (cols === 1 && len > 1) {
return [r];
} else if (col >= cols && len > cols) { // overshooting
return new Variable(r.at(col));
}
return r.at(col);
}
if (col === 1 && row <= this.rows()) {
return [r];
}
return null;
};
List.prototype.rows = function () {
return this.length();
};
List.prototype.cols = function () {
var r = (this.at(1));
return r instanceof List ? r.length() : 1;
};
List.prototype.colName = function (col) {
if (col > this.cols()) {return null; }
return String.fromCharCode(64 + ((col % 26) || 26)).repeat(
Math.floor((col - 1) / 26) + 1
);
};
List.prototype.rowName = function (row) {
return row;
};
List.prototype.columnNames = function () {
return [];
};
List.prototype.version = function (startRow, rows) {
var l = Math.min(startRow + rows, this.length()),
v = this.lastChanged,
r,
i;
for (i = startRow; i <= l; i += 1) {
r = this.at(i);
v = Math.max(v, r.lastChanged ? r.lastChanged : 0);
}
return v;
};
// List conversion:
List.prototype.asArray = function () {
@ -443,7 +523,7 @@ ListWatcherMorph.prototype.init = function (list, parentCell) {
);
this.color = new Color(220, 220, 220);
this.isDraggable = true;
this.isDraggable = false;
this.setExtent(new Point(80, 70).multiplyBy(
SyntaxElementMorph.prototype.scale
));
@ -694,6 +774,56 @@ ListWatcherMorph.prototype.expand = function (maxExtent) {
this.handle.setBottom(this.bottom() - 3);
};
// ListWatcherMorph context menu
ListWatcherMorph.prototype.userMenu = function () {
if (!List.prototype.enableTables) {
return this.escalateEvent('userMenu');
}
var menu = new MenuMorph(this),
myself = this;
menu.addItem('table view...', 'showTableView');
menu.addLine();
menu.addItem(
'open in dialog...',
function () {
new TableDialogMorph(myself.list).popUp(myself.world());
}
);
return menu;
};
ListWatcherMorph.prototype.showTableView = function () {
var view = this.parentThatIsAnyOf([
SpriteBubbleMorph,
SpeechBubbleMorph,
CellMorph
]);
if (!view) {return; }
if (view instanceof SpriteBubbleMorph) {
view.changed();
view.drawNew();
} else if (view instanceof SpeechBubbleMorph) {
view.contents = new TableFrameMorph(new TableMorph(this.list, 10));
view.contents.expand(this.extent());
view.drawNew(true);
} else { // watcher cell
view.drawNew(true, 'table');
view.contentsMorph.expand(this.extent());
}
view.fixLayout();
};
// ListWatcherMorph events:
ListWatcherMorph.prototype.mouseDoubleClick = function (pos) {
if (List.prototype.enableTables) {
new TableDialogMorph(this.list).popUp(this.world());
} else {
this.escalateEvent('mouseDoubleClick', pos);
}
};
// ListWatcherMorph hiding/showing:
ListWatcherMorph.prototype.show = function () {

Wyświetl plik

@ -42,7 +42,7 @@
/*global modules, contains*/
modules.locale = '2016-January-22';
modules.locale = '2016-February-24';
// Global stuff
@ -161,7 +161,7 @@ SnapTranslator.dict.de = {
'translator_e-mail':
'jens@moenig.org',
'last_changed':
'2015-12-22'
'2016-02-24'
};
SnapTranslator.dict.it = {
@ -565,5 +565,5 @@ SnapTranslator.dict.ar = {
'translator_e-mail':
'tarekgalal46@hotmail.com', // optional
'last_changed':
'2016-01-17'
'2016-02-24'
};

Wyświetl plik

@ -8,7 +8,7 @@
written by Jens Mönig
jens@moenig.org
Copyright (C) 2015 by Jens Mönig
Copyright (C) 2016 by Jens Mönig
This file is part of Snap!.
@ -974,7 +974,7 @@
single submorph's changes tremendous performance improvements can be
achieved by setting the trackChanges flag to false before propagating
the layout changes, setting it to true again and then storing the full
bounds of the surrounding morph. An an example refer to the
bounds of the surrounding morph. As an example refer to the
moveBy()
@ -1057,7 +1057,7 @@
/*global window, HTMLCanvasElement, getMinimumFontHeight, FileReader, Audio,
FileList, getBlurredShadowSupport*/
var morphicVersion = '2015-December-23';
var morphicVersion = '2016-February-24';
var modules = {}; // keep track of additional loaded modules
var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug
@ -2188,7 +2188,7 @@ Morph.uber = Node.prototype;
single submorph's changes tremendous performance improvements can be
achieved by setting the trackChanges flag to false before propagating
the layout changes, setting it to true again and then storing the full
bounds of the surrounding morph. An an example refer to the
bounds of the surrounding morph. As an example refer to the
fixLayout()

Wyświetl plik

@ -9,7 +9,7 @@
written by Jens Mönig
jens@moenig.org
Copyright (C) 2015 by Jens Mönig
Copyright (C) 2016 by Jens Mönig
This file is part of Snap!.
@ -65,67 +65,24 @@
*/
// globals from paint.js:
/*global PaintEditorMorph*/
// globals from lists.js:
/*global ListWatcherMorph*/
// gloabls from widgets.js:
/*global PushButtonMorph, ToggleMorph, DialogBoxMorph, InputFieldMorph*/
// gloabls from gui.js:
/*global WatcherMorph, SpriteIconMorph*/
// globals from threads.js:
/*global ArgMorph, BlockMorph, Process, StackFrame, ThreadManager,
VariableFrame, detect, threadsVersion*/
// globals from blocks.js:
/*global ArgMorph, ArrowMorph, BlockHighlightMorph, BlockMorph,
BooleanSlotMorph, BoxMorph, Color, ColorPaletteMorph, ColorSlotMorph,
CommandBlockMorph, CommandSlotMorph, FrameMorph, HatBlockMorph,
InputSlotMorph, MenuMorph, Morph, MultiArgMorph, Point,
ReporterBlockMorph, ScriptsMorph, ShaAwMorph, StringMorph,
SyntaxElementMorph, TextMorph, WorldMorph, blocksVersion, contains,
degrees, detect, getDocumentPositionOf, newCanvas, nop, radians,
useBlurredShadows*/
// globals from morphic.js:
/*global Array, BlinkerMorph, BouncerMorph, BoxMorph, CircleBoxMorph,
Color, ColorPaletteMorph, ColorPickerMorph, CursorMorph, Date,
FrameMorph, Function, GrayPaletteMorph, HandMorph, HandleMorph,
InspectorMorph, ListMorph, Math, MenuItemMorph, MenuMorph, Morph,
MorphicPreferences, MouseSensorMorph, Node, Object, PenMorph, Point,
Rectangle, ScrollFrameMorph, ShadowMorph, SliderButtonMorph,
SliderMorph, String, StringFieldMorph, StringMorph, TextMorph,
TriggerMorph, WorldMorph, contains, copy, degrees, detect,
document, getDocumentPositionOf, isNaN, isObject, isString, newCanvas,
nop, parseFloat, radians, standardSettings, touchScreenSettings,
useBlurredShadows, version, window, modules, IDE_Morph, VariableDialogMorph,
HTMLCanvasElement, Context, List, SpeechBubbleMorph, RingMorph, isNil,
FileReader*/
// globals from byob.js:
/*global CustomBlockDefinition, BlockEditorMorph, BlockDialogMorph,
PrototypeHatBlockMorph*/
// globals from locale.js:
/*global localize*/
// temporary globals
// Global stuff ////////////////////////////////////////////////////////
modules.objects = '2015-December-22';
/*global PaintEditorMorph, ListWatcherMorph, PushButtonMorph, ToggleMorph,
DialogBoxMorph, InputFieldMorph, SpriteIconMorph, BlockMorph,
ThreadManager, VariableFrame, detect, BlockMorph, BoxMorph, Color,
CommandBlockMorph, FrameMorph, HatBlockMorph, MenuMorph, Morph, MultiArgMorph,
Point, ReporterBlockMorph, ScriptsMorph, StringMorph, SyntaxElementMorph,
TextMorph, contains, degrees, detect, newCanvas, nop, radians, Array,
CursorMorph, Date, FrameMorph, HandMorph, Math, MenuMorph, Morph,
MorphicPreferences, Object, PenMorph, Point, Rectangle, ScrollFrameMorph,
SliderMorph, String, StringMorph, TextMorph, contains, copy, degrees, detect,
document, isNaN, isString, newCanvas, nop, parseFloat, radians, window,
modules, IDE_Morph, VariableDialogMorph, HTMLCanvasElement, Context, List,
SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph,
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
TableMorph, TableFrameMorph*/
modules.objects = '2016-February-24';
var SpriteMorph;
var StageMorph;
@ -1199,6 +1156,15 @@ SpriteMorph.prototype.initBlocks = function () {
defaults: [localize('each item')]
},
// Tables - experimental
doShowTable: {
dev: true,
type: 'command',
category: 'lists',
spec: 'show table %l'
},
// Code mapping - experimental
doMapCodeOrHeader: { // experimental
type: 'command',
@ -2140,6 +2106,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push(block('reportMap'));
blocks.push('-');
blocks.push(block('doForEach'));
blocks.push(block('doShowTable'));
}
/////////////////////////////////
@ -5773,6 +5740,7 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push(block('reportMap'));
blocks.push('-');
blocks.push(block('doForEach'));
blocks.push(block('doShowTable'));
}
/////////////////////////////////
@ -6198,7 +6166,7 @@ SpriteBubbleMorph.prototype.init = function (
// SpriteBubbleMorph contents formatting
SpriteBubbleMorph.prototype.dataAsMorph = function (data) {
SpriteBubbleMorph.prototype.dataAsMorph = function (data, toggle) {
var contents,
sprite = SpriteMorph.prototype,
isText,
@ -6236,15 +6204,24 @@ SpriteBubbleMorph.prototype.dataAsMorph = function (data) {
contents.silentSetHeight(data.height);
contents.image = data;
} else if (data instanceof List) {
contents = new ListWatcherMorph(data);
contents.isDraggable = false;
contents.update(true);
contents.step = contents.update;
if (this.stage) {
contents.expand(this.stage.extent().translateBy(
-2 * (this.edge + this.border + this.padding)
));
if (!toggle && data.isTable()) {
contents = new TableFrameMorph(new TableMorph(data, 10));
if (this.stage) {
contents.expand(this.stage.extent().translateBy(
-2 * (this.edge + this.border + this.padding)
));
}
} else {
contents = new ListWatcherMorph(data);
contents.update(true);
contents.step = contents.update;
if (this.stage) {
contents.expand(this.stage.extent().translateBy(
-2 * (this.edge + this.border + this.padding)
));
}
}
contents.isDraggable = false;
} else if (data instanceof Context) {
img = data.image();
contents = new Morph();
@ -6298,7 +6275,7 @@ SpriteBubbleMorph.prototype.setScale = function (scale) {
// SpriteBubbleMorph drawing:
SpriteBubbleMorph.prototype.drawNew = function () {
SpriteBubbleMorph.prototype.drawNew = function (toggle) {
var sprite = SpriteMorph.prototype;
// scale my settings
@ -6310,7 +6287,7 @@ SpriteBubbleMorph.prototype.drawNew = function () {
if (this.contentsMorph) {
this.contentsMorph.destroy();
}
this.contentsMorph = this.dataAsMorph(this.data);
this.contentsMorph = this.dataAsMorph(this.data, toggle);
this.add(this.contentsMorph);
// adjust my layout
@ -7030,24 +7007,26 @@ CellMorph.prototype.fixLayout = function () {
// CellMorph drawing:
CellMorph.prototype.drawNew = function () {
CellMorph.prototype.drawNew = function (toggle, type) {
var context,
txt,
img,
fontSize = SyntaxElementMorph.prototype.fontSize,
isSameList = this.contentsMorph instanceof ListWatcherMorph
&& (this.contentsMorph.list === this.contents);
&& (this.contentsMorph.list === this.contents),
isSameTable = this.contentsMorph instanceof TableFrameMorph
&& (this.contentsMorph.tableMorph.table === this.contents);
if (this.isBig) {
fontSize = fontSize * 1.5;
}
// re-build my contents
if (this.contentsMorph && !isSameList) {
if (toggle || (this.contentsMorph && !isSameList && !isSameTable)) {
this.contentsMorph.destroy();
}
if (!isSameList) {
if (toggle || (!isSameList && !isSameTable)) {
if (this.contents instanceof Morph) {
this.contentsMorph = this.contents;
} else if (isString(this.contents)) {
@ -7093,23 +7072,31 @@ CellMorph.prototype.drawNew = function () {
this.contentsMorph.silentSetHeight(img.height);
this.contentsMorph.image = img;
} else if (this.contents instanceof List) {
if (this.isCircular()) {
this.contentsMorph = new TextMorph(
'(...)',
fontSize,
null,
false, // bold
true, // italic
'center'
);
this.contentsMorph.setColor(new Color(255, 255, 255));
} else {
this.contentsMorph = new ListWatcherMorph(
if ('table' === type || (!toggle && this.contents.isTable())) {
this.contentsMorph = new TableFrameMorph(new TableMorph(
this.contents,
this
);
this.contentsMorph.isDraggable = false;
10
));
this.contentsMorph.expand(new Point(200, 150));
} else {
if (this.isCircular()) {
this.contentsMorph = new TextMorph(
'(...)',
fontSize,
null,
false, // bold
true, // italic
'center'
);
this.contentsMorph.setColor(new Color(255, 255, 255));
} else {
this.contentsMorph = new ListWatcherMorph(
this.contents,
this
);
}
}
this.contentsMorph.isDraggable = false;
} else {
this.contentsMorph = new TextMorph(
!isNil(this.contents) ? this.contents.toString() : '',
@ -7171,7 +7158,7 @@ CellMorph.prototype.drawNew = function () {
}
// position my contents
if (!isSameList) {
if (toggle || (!isSameList && !isSameTable)) {
this.contentsMorph.setCenter(this.center());
}
};
@ -7285,6 +7272,15 @@ CellMorph.prototype.mouseClickLeft = function (pos) {
}
};
CellMorph.prototype.mouseDoubleClick = function (pos) {
if (List.prototype.enableTables &&
this.currentValue instanceof List) {
new TableDialogMorph(this.contents).popUp(this.world());
} else {
this.escalateEvent('mouseDoubleClick', pos);
}
};
// WatcherMorph //////////////////////////////////////////////////////////
/*
@ -7580,6 +7576,15 @@ WatcherMorph.prototype.fixLayout = function () {
// WatcherMorph events:
WatcherMorph.prototype.mouseDoubleClick = function (pos) {
if (List.prototype.enableTables &&
this.currentValue instanceof List) {
new TableDialogMorph(this.currentValue).popUp(this.world());
} else {
this.escalateEvent('mouseDoubleClick', pos);
}
};
/*
// Scratch-like watcher-toggling, commented out b/c we have a drop-down menu

Wyświetl plik

@ -13,6 +13,7 @@
<script type="text/javascript" src="paint.js"></script>
<script type="text/javascript" src="lists.js"></script>
<script type="text/javascript" src="byob.js"></script>
<script type="text/javascript" src="tables.js"></script>
<script type="text/javascript" src="xml.js"></script>
<script type="text/javascript" src="store.js"></script>
<script type="text/javascript" src="locale.js"></script>

Wyświetl plik

@ -13,6 +13,7 @@
<script type="text/javascript" src="paint.js"></script>
<script type="text/javascript" src="lists.js"></script>
<script type="text/javascript" src="byob.js"></script>
<script type="text/javascript" src="tables.js"></script>
<script type="text/javascript" src="xml.js"></script>
<script type="text/javascript" src="store.js"></script>
<script type="text/javascript" src="locale.js"></script>

Wyświetl plik

@ -49,19 +49,18 @@
*/
/*global modules, XML_Element, VariableFrame, StageMorph,
SpriteMorph, WatcherMorph, Point, CustomBlockDefinition, Context,
ReporterBlockMorph, CommandBlockMorph, HatBlockMorph, RingMorph, contains,
detect, CustomCommandBlockMorph, CustomReporterBlockMorph, Color, List,
newCanvas, Costume, Sound, Audio, IDE_Morph, ScriptsMorph, BlockMorph,
ArgMorph, InputSlotMorph, TemplateSlotMorph, CommandSlotMorph,
/*global modules, XML_Element, VariableFrame, StageMorph, SpriteMorph,
WatcherMorph, Point, CustomBlockDefinition, Context, ReporterBlockMorph,
CommandBlockMorph, detect, CustomCommandBlockMorph, CustomReporterBlockMorph,
Color, List, newCanvas, Costume, Sound, Audio, IDE_Morph, ScriptsMorph,
BlockMorph, ArgMorph, InputSlotMorph, TemplateSlotMorph, CommandSlotMorph,
FunctionSlotMorph, MultiArgMorph, ColorSlotMorph, nop, CommentMorph, isNil,
localize, sizeOf, ArgLabelMorph, SVG_Costume, MorphicPreferences,
SyntaxElementMorph, Variable*/
// Global stuff ////////////////////////////////////////////////////////
modules.store = '2016-January-19';
modules.store = '2016-February-24';
// XML_Serializer ///////////////////////////////////////////////////////

1220
tables.js 100644

Plik diff jest za duży Load Diff

Wyświetl plik

@ -51,39 +51,17 @@
*/
// globals from blocks.js:
/*global ArgMorph, ArrowMorph, BlockHighlightMorph, BlockMorph,
BooleanSlotMorph, BoxMorph, Color, ColorPaletteMorph, ColorSlotMorph,
CommandBlockMorph, CommandSlotMorph, FrameMorph, HatBlockMorph,
InputSlotMorph, MenuMorph, Morph, MultiArgMorph, Point,
ReporterBlockMorph, ScriptsMorph, ShadowMorph, StringMorph,
SyntaxElementMorph, TextMorph, WorldMorph, blocksVersion, contains,
degrees, detect, getDocumentPositionOf, newCanvas, nop, radians,
useBlurredShadows, ReporterSlotMorph, CSlotMorph, RingMorph, IDE_Morph,
ArgLabelMorph, localize, XML_Element, hex_sha512*/
// globals from objects.js:
/*global StageMorph, SpriteMorph, StagePrompterMorph, Note*/
// globals from morphic.js:
/*global modules, isString, copy, isNil*/
// globals from gui.js:
/*global WatcherMorph*/
// globals from lists.js:
/*global List, ListWatcherMorph*/
/*global alert, console*/
// Global stuff ////////////////////////////////////////////////////////
modules.threads = '2016-January-19';
/*global ArgMorph, BlockMorph, CommandBlockMorph, CommandSlotMorph, Morph,
MultiArgMorph, Point, ReporterBlockMorph, SyntaxElementMorph, contains,
degrees, detect, nop, radians, ReporterSlotMorph, CSlotMorph, RingMorph,
IDE_Morph, ArgLabelMorph, localize, XML_Element, hex_sha512, TableDialogMorph,
StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy,
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph,
TableFrameMorph*/
modules.threads = '2016-February-24';
var ThreadManager;
var Process;
@ -303,6 +281,7 @@ ThreadManager.prototype.removeTerminatedProcesses = function () {
// and un-highlight their scripts
var remaining = [];
this.processes.forEach(function (proc) {
var result;
if ((!proc.isRunning() && !proc.errorFlag) || proc.isDead) {
if (proc.topBlock instanceof BlockMorph) {
proc.topBlock.removeHighlight();
@ -313,21 +292,24 @@ ThreadManager.prototype.removeTerminatedProcesses = function () {
proc.homeContext.receiver.stopTalking();
}
}
if (proc.topBlock instanceof ReporterBlockMorph || proc.isShowingResult) {
if (proc.topBlock instanceof ReporterBlockMorph ||
proc.isShowingResult) {
result = proc.homeContext.inputs[0];
if (proc.onComplete instanceof Function) {
proc.onComplete(proc.homeContext.inputs[0]);
proc.onComplete(result);
} else {
if (proc.homeContext.inputs[0] instanceof List) {
if (result instanceof List) {
proc.topBlock.showBubble(
new ListWatcherMorph(
proc.homeContext.inputs[0]
),
result.isTable() ?
new TableFrameMorph(
new TableMorph(result, 10)
)
: new ListWatcherMorph(result),
proc.exportResult
);
} else {
proc.topBlock.showBubble(
proc.homeContext.inputs[0],
result,
proc.exportResult
);
}
@ -1571,6 +1553,12 @@ Process.prototype.reportListContainsItem = function (list, element) {
return list.contains(element);
};
Process.prototype.doShowTable = function (list) {
// experimental
this.assertType(list, 'list');
new TableDialogMorph(list).popUp(this.blockReceiver().world());
};
// Process conditionals primitives
Process.prototype.doIf = function () {