summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Ball <cycomachead@gmail.com>2014-05-24 22:02:00 -0700
committerMichael Ball <cycomachead@gmail.com>2014-05-24 22:02:00 -0700
commitbf03185eb083ea4171121d25ffda3041d91be8e7 (patch)
tree6c5c5522a2ef79992cee682b4ebeec8ba7e7502b
parent01b9417b87688b591fe3df2a55ec367dd72f027d (diff)
parent089d1500b41f00611603de936a65093d0dbb15ec (diff)
downloadsnap-bf03185eb083ea4171121d25ffda3041d91be8e7.tar.gz
snap-bf03185eb083ea4171121d25ffda3041d91be8e7.zip
Merge pull request #33 from jmoenig/master
update cs10 fork
-rw-r--r--gui.js49
-rwxr-xr-xhistory.txt8
-rw-r--r--morphic.js5
-rw-r--r--objects.js202
-rwxr-xr-xsnap.html1
-rw-r--r--threads.js16
6 files changed, 258 insertions, 23 deletions
diff --git a/gui.js b/gui.js
index 0f4f2eb..4de6b3d 100644
--- a/gui.js
+++ b/gui.js
@@ -68,7 +68,7 @@ sb, CommentMorph, CommandBlockMorph, BlockLabelPlaceHolderMorph, Audio*/
// Global stuff ////////////////////////////////////////////////////////
-modules.gui = '2014-February-13';
+modules.gui = '2014-May-20';
// Declarations
@@ -848,7 +848,7 @@ IDE_Morph.prototype.createCategories = function () {
this.add(this.categories);
};
-IDE_Morph.prototype.createPalette = function () {
+IDE_Morph.prototype.createPalette = function (forSearching) {
// assumes that the logo pane has already been created
// needs the categories pane for layout
var myself = this;
@@ -857,7 +857,15 @@ IDE_Morph.prototype.createPalette = function () {
this.palette.destroy();
}
- this.palette = this.currentSprite.palette(this.currentCategory);
+ if (forSearching) {
+ this.palette = new ScrollFrameMorph(
+ null,
+ null,
+ this.currentSprite.sliderColor
+ );
+ } else {
+ this.palette = this.currentSprite.palette(this.currentCategory);
+ }
this.palette.isDraggable = false;
this.palette.acceptsDrops = true;
this.palette.contents.acceptsDrops = false;
@@ -882,6 +890,7 @@ IDE_Morph.prototype.createPalette = function () {
this.add(this.palette);
this.palette.scrollX(this.palette.padding);
this.palette.scrollY(this.palette.padding);
+ return this.palette;
};
IDE_Morph.prototype.createStage = function () {
@@ -2273,23 +2282,7 @@ IDE_Morph.prototype.projectMenu = function () {
}
);
menu.addItem('Open...', 'openProjectsBrowser');
- menu.addItem(
- 'Save',
- function () {
- if (myself.source === 'examples') {
- myself.source = 'local'; // cannot save to examples
- }
- if (myself.projectName) {
- if (myself.source === 'local') { // as well as 'examples'
- myself.saveProject(myself.projectName);
- } else { // 'cloud'
- myself.saveProjectToCloud(myself.projectName);
- }
- } else {
- myself.saveProjectsBrowser();
- }
- }
- );
+ menu.addItem('Save', "save");
if (shiftClicked) {
menu.addItem(
'Save to disk',
@@ -2720,6 +2713,22 @@ IDE_Morph.prototype.newProject = function () {
this.fixLayout();
};
+IDE_Morph.prototype.save = function () {
+ if (this.source === 'examples') {
+ this.source = 'local'; // cannot save to examples
+ }
+ if (this.projectName) {
+ if (this.source === 'local') { // as well as 'examples'
+ this.saveProject(this.projectName);
+ } else { // 'cloud'
+ this.saveProjectToCloud(this.projectName);
+ }
+ } else {
+ this.saveProjectsBrowser();
+ }
+};
+
+
IDE_Morph.prototype.saveProject = function (name) {
var myself = this;
this.nextSteps([
diff --git a/history.txt b/history.txt
index af54766..126c11c 100755
--- a/history.txt
+++ b/history.txt
@@ -2125,3 +2125,11 @@ ______
------
* error message when trying to import a non-text file into a variable, thanks, Nate!
* fixed #407 (custom-block coloring w/ zebra off)
+
+140520
+------
+* Morphic: Prevent default action for ctrl-/cmd-key event
+* Snap.html: Focus the world canvas on startup, so Snap reacts to keyboard events right away
+* Threads: new Variable data structure, for refactoring upvar references, not yet used anywhere
+* Objects, GUI: Search Blocks, feature. Thanks, Kyle, for architecting and designing this!!!
+* Objects, GUI: Keyboard-shortcuts for opening (cmd-o), saving (cmd-s) projects and for finding blocks (cmd-f)
diff --git a/morphic.js b/morphic.js
index b55b180..7d1f53d 100644
--- a/morphic.js
+++ b/morphic.js
@@ -1035,7 +1035,7 @@
/*global window, HTMLCanvasElement, getMinimumFontHeight, FileReader, Audio,
FileList, getBlurredShadowSupport*/
-var morphicVersion = '2014-February-03';
+var morphicVersion = '2014-May-20';
var modules = {}; // keep track of additional loaded modules
var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug
@@ -10268,6 +10268,9 @@ WorldMorph.prototype.initEventListeners = function () {
}
event.preventDefault();
}
+ if (event.ctrlKey || event.metaKey) {
+ event.preventDefault();
+ }
},
false
);
diff --git a/objects.js b/objects.js
index d1e99ff..66ceb97 100644
--- a/objects.js
+++ b/objects.js
@@ -124,7 +124,7 @@ PrototypeHatBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.objects = '2014-May-02';
+modules.objects = '2014-May-20';
var SpriteMorph;
var StageMorph;
@@ -203,90 +203,106 @@ SpriteMorph.prototype.initBlocks = function () {
// Motion
forward: {
+ only: SpriteMorph,
type: 'command',
category: 'motion',
spec: 'move %n steps',
defaults: [10]
},
turn: {
+ only: SpriteMorph,
type: 'command',
category: 'motion',
spec: 'turn %clockwise %n degrees',
defaults: [15]
},
turnLeft: {
+ only: SpriteMorph,
type: 'command',
category: 'motion',
spec: 'turn %counterclockwise %n degrees',
defaults: [15]
},
setHeading: {
+ only: SpriteMorph,
type: 'command',
category: 'motion',
spec: 'point in direction %dir'
},
doFaceTowards: {
+ only: SpriteMorph,
type: 'command',
category: 'motion',
spec: 'point towards %dst'
},
gotoXY: {
+ only: SpriteMorph,
type: 'command',
category: 'motion',
spec: 'go to x: %n y: %n',
defaults: [0, 0]
},
doGotoObject: {
+ only: SpriteMorph,
type: 'command',
category: 'motion',
spec: 'go to %dst'
},
doGlide: {
+ only: SpriteMorph,
type: 'command',
category: 'motion',
spec: 'glide %n secs to x: %n y: %n',
defaults: [1, 0, 0]
},
changeXPosition: {
+ only: SpriteMorph,
type: 'command',
category: 'motion',
spec: 'change x by %n',
defaults: [10]
},
setXPosition: {
+ only: SpriteMorph,
type: 'command',
category: 'motion',
spec: 'set x to %n',
defaults: [0]
},
changeYPosition: {
+ only: SpriteMorph,
type: 'command',
category: 'motion',
spec: 'change y by %n',
defaults: [10]
},
setYPosition: {
+ only: SpriteMorph,
type: 'command',
category: 'motion',
spec: 'set y to %n',
defaults: [0]
},
bounceOffEdge: {
+ only: SpriteMorph,
type: 'command',
category: 'motion',
spec: 'if on edge, bounce'
},
xPosition: {
+ only: SpriteMorph,
type: 'reporter',
category: 'motion',
spec: 'x position'
},
yPosition: {
+ only: SpriteMorph,
type: 'reporter',
category: 'motion',
spec: 'y position'
},
direction: {
+ only: SpriteMorph,
type: 'reporter',
category: 'motion',
spec: 'direction'
@@ -309,24 +325,28 @@ SpriteMorph.prototype.initBlocks = function () {
spec: 'costume #'
},
doSayFor: {
+ only: SpriteMorph,
type: 'command',
category: 'looks',
spec: 'say %s for %n secs',
defaults: [localize('Hello!'), 2]
},
bubble: {
+ only: SpriteMorph,
type: 'command',
category: 'looks',
spec: 'say %s',
defaults: [localize('Hello!')]
},
doThinkFor: {
+ only: SpriteMorph,
type: 'command',
category: 'looks',
spec: 'think %s for %n secs',
defaults: [localize('Hmm...'), 2]
},
doThink: {
+ only: SpriteMorph,
type: 'command',
category: 'looks',
spec: 'think %s',
@@ -350,38 +370,45 @@ SpriteMorph.prototype.initBlocks = function () {
spec: 'clear graphic effects'
},
changeScale: {
+ only: SpriteMorph,
type: 'command',
category: 'looks',
spec: 'change size by %n',
defaults: [10]
},
setScale: {
+ only: SpriteMorph,
type: 'command',
category: 'looks',
spec: 'set size to %n %',
defaults: [100]
},
getScale: {
+ only: SpriteMorph,
type: 'reporter',
category: 'looks',
spec: 'size'
},
show: {
+ only: SpriteMorph,
type: 'command',
category: 'looks',
spec: 'show'
},
hide: {
+ only: SpriteMorph,
type: 'command',
category: 'looks',
spec: 'hide'
},
comeToFront: {
+ only: SpriteMorph,
type: 'command',
category: 'looks',
spec: 'go to front'
},
goBack: {
+ only: SpriteMorph,
type: 'command',
category: 'looks',
spec: 'go back %n layers',
@@ -390,17 +417,20 @@ SpriteMorph.prototype.initBlocks = function () {
// Looks - Debugging primitives for development mode
reportCostumes: {
+ dev: true,
type: 'reporter',
category: 'looks',
spec: 'wardrobe'
},
alert: {
+ dev: true,
type: 'command',
category: 'looks',
spec: 'alert %mult%s'
},
log: {
+ dev: true,
type: 'command',
category: 'looks',
spec: 'console log %mult%s'
@@ -454,6 +484,7 @@ SpriteMorph.prototype.initBlocks = function () {
// Sound - Debugging primitives for development mode
reportSounds: {
+ dev: true,
type: 'reporter',
category: 'sound',
spec: 'jukebox'
@@ -466,57 +497,67 @@ SpriteMorph.prototype.initBlocks = function () {
spec: 'clear'
},
down: {
+ only: SpriteMorph,
type: 'command',
category: 'pen',
spec: 'pen down'
},
up: {
+ only: SpriteMorph,
type: 'command',
category: 'pen',
spec: 'pen up'
},
setColor: {
+ only: SpriteMorph,
type: 'command',
category: 'pen',
spec: 'set pen color to %clr'
},
changeHue: {
+ only: SpriteMorph,
type: 'command',
category: 'pen',
spec: 'change pen color by %n',
defaults: [10]
},
setHue: {
+ only: SpriteMorph,
type: 'command',
category: 'pen',
spec: 'set pen color to %n',
defaults: [0]
},
changeBrightness: {
+ only: SpriteMorph,
type: 'command',
category: 'pen',
spec: 'change pen shade by %n',
defaults: [10]
},
setBrightness: {
+ only: SpriteMorph,
type: 'command',
category: 'pen',
spec: 'set pen shade to %n',
defaults: [100]
},
changeSize: {
+ only: SpriteMorph,
type: 'command',
category: 'pen',
spec: 'change pen size by %n',
defaults: [1]
},
setSize: {
+ only: SpriteMorph,
type: 'command',
category: 'pen',
spec: 'set pen size to %n',
defaults: [1]
},
doStamp: {
+ only: SpriteMorph,
type: 'command',
category: 'pen',
spec: 'stamp'
@@ -710,31 +751,37 @@ SpriteMorph.prototype.initBlocks = function () {
// Sensing
reportTouchingObject: {
+ only: SpriteMorph,
type: 'predicate',
category: 'sensing',
spec: 'touching %col ?'
},
reportTouchingColor: {
+ only: SpriteMorph,
type: 'predicate',
category: 'sensing',
spec: 'touching %clr ?'
},
reportColorIsTouchingColor: {
+ only: SpriteMorph,
type: 'predicate',
category: 'sensing',
spec: 'color %clr is touching %clr ?'
},
colorFiltered: {
+ dev: true,
type: 'reporter',
category: 'sensing',
spec: 'filtered for %clr'
},
reportStackSize: {
+ dev: true,
type: 'reporter',
category: 'sensing',
spec: 'stack size'
},
reportFrameCount: {
+ dev: true,
type: 'reporter',
category: 'sensing',
spec: 'frames'
@@ -746,6 +793,7 @@ SpriteMorph.prototype.initBlocks = function () {
defaults: [localize('what\'s your name?')]
},
reportLastAnswer: { // retained for legacy compatibility
+ dev: true,
type: 'reporter',
category: 'sensing',
spec: 'answer'
@@ -786,6 +834,7 @@ SpriteMorph.prototype.initBlocks = function () {
spec: 'reset timer'
},
reportTimer: { // retained for legacy compatibility
+ dev: true,
type: 'reporter',
category: 'sensing',
spec: 'timer'
@@ -969,12 +1018,14 @@ SpriteMorph.prototype.initBlocks = function () {
defaults: [localize('hello') + ' ' + localize('world'), " "]
},
reportTypeOf: { // only in dev mode for debugging
+ dev: true,
type: 'reporter',
category: 'operators',
spec: 'type of %s',
defaults: [5]
},
reportTextFunction: { // only in dev mode - experimental
+ dev: true,
type: 'reporter',
category: 'operators',
spec: '%txtfun of %s',
@@ -1083,6 +1134,7 @@ SpriteMorph.prototype.initBlocks = function () {
// MAP - experimental
reportMap: {
+ dev: true,
type: 'reporter',
category: 'lists',
spec: 'map %repRing over %l'
@@ -2068,6 +2120,7 @@ SpriteMorph.prototype.freshPalette = function (category) {
});
}
+ menu.addItem('find blocks...', function () {myself.searchBlocks(); });
if (canHidePrimitives()) {
menu.addItem(
'hide primitives',
@@ -2199,6 +2252,139 @@ SpriteMorph.prototype.freshPalette = function (category) {
return palette;
};
+// SpriteMorph blocks searching
+
+SpriteMorph.prototype.blocksMatching = function (searchString, strictly) {
+ // answer an array of block templates whose spec contains
+ // the given search string, ordered by descending relevance
+ var blocks = [],
+ blocksDict,
+ myself = this,
+ search = searchString.toLowerCase(),
+ stage = this.parentThatIsA(StageMorph);
+
+ function labelOf(aBlockSpec) {
+ var words = (BlockMorph.prototype.parseSpec(aBlockSpec)),
+ filtered = words.filter(
+ function (each) {return (each.indexOf('%') !== 0); }
+ );
+ return filtered.join(' ');
+ }
+
+ function fillDigits(anInt, totalDigits, fillChar) {
+ var ans = String(anInt);
+ while (ans.length < totalDigits) {ans = fillChar + ans; }
+ return ans;
+ }
+
+ function relevance(aBlockLabel, aSearchString) {
+ var lbl = ' ' + aBlockLabel,
+ idx = lbl.indexOf(aSearchString),
+ atWord;
+ if (idx === -1) {return -1; }
+ atWord = (lbl.charAt(idx - 1) === ' ');
+ if (strictly && !atWord) {return -1; }
+ return (atWord ? '1' : '2') + fillDigits(idx, 4, '0');
+ }
+
+ function primitive(selector) {
+ var newBlock = SpriteMorph.prototype.blockForSelector(selector, true);
+ newBlock.isTemplate = true;
+ return newBlock;
+ }
+
+ // custom blocks
+ [this.customBlocks, stage.globalBlocks].forEach(function (blocksList) {
+ blocksList.forEach(function (definition) {
+ var spec = localize(definition.blockSpec()).toLowerCase(),
+ rel = relevance(labelOf(spec), search);
+ if (rel !== -1) {
+ blocks.push([definition.templateInstance(), rel + '1']);
+ }
+ });
+ });
+ // primitives
+ blocksDict = SpriteMorph.prototype.blocks;
+ Object.keys(blocksDict).forEach(function (selector) {
+ if (!StageMorph.prototype.hiddenPrimitives[selector]) {
+ var block = blocksDict[selector],
+ spec = localize(block.spec).toLowerCase(),
+ rel = relevance(labelOf(spec), search);
+ if (
+ (rel !== -1) &&
+ (!block.dev) &&
+ (!block.only || (block.only === myself.constructor))
+ ) {
+ blocks.push([primitive(selector), rel + '2']);
+ }
+ }
+ });
+ blocks.sort(function (x, y) {return x[1] < y[1] ? -1 : 1; });
+ return blocks.map(function (each) {return each[0]; });
+};
+
+SpriteMorph.prototype.searchBlocks = function () {
+ var myself = this,
+ unit = SyntaxElementMorph.prototype.fontSize,
+ ide = this.parentThatIsA(IDE_Morph),
+ oldSearch = '',
+ searchBar = new InputFieldMorph(''),
+ searchPane = ide.createPalette('forSearch');
+
+ function show(blocks) {
+ var oldFlag = Morph.prototype.trackChanges,
+ x = searchPane.contents.left() + 5,
+ y = (searchBar.bottom() + unit);
+ Morph.prototype.trackChanges = false;
+ searchPane.contents.children = [searchPane.contents.children[0]];
+ blocks.forEach(function (block) {
+ block.setPosition(new Point(x, y));
+ searchPane.addContents(block);
+ y += block.height();
+ y += unit * 0.3;
+ });
+ Morph.prototype.trackChanges = oldFlag;
+ searchPane.changed();
+ }
+
+ searchPane.owner = this;
+ searchPane.padding = unit / 2;
+ searchPane.color = myself.paletteColor;
+ searchPane.contents.color = myself.paletteColor;
+ searchPane.growth = new Point(0, MorphicPreferences.scrollBarSize);
+ searchPane.addContents(searchBar);
+ searchBar.drawNew();
+ searchBar.setWidth(ide.logo.width() - 20);
+ searchBar.contrast = 90;
+ searchBar.setPosition(
+ searchPane.contents.topLeft().add(new Point(10, 10))
+ );
+ searchBar.drawNew();
+
+ searchPane.accept = function () {
+ var search = searchBar.getValue();
+ if (search.length > 0) {
+ show(myself.blocksMatching(search));
+ }
+ };
+
+ searchPane.reactToKeystroke = function () {
+ var search = searchBar.getValue();
+ if (search !== oldSearch) {
+ oldSearch = search;
+ show(myself.blocksMatching(search, search.length < 2));
+ }
+ };
+
+ searchBar.cancel = function () {
+ ide.refreshPalette();
+ ide.palette.adjustScrollBars();
+ };
+
+ ide.fixLayout('refreshPalette');
+ searchBar.edit();
+};
+
// SpriteMorph variable management
SpriteMorph.prototype.addVariable = function (name, isGlobal) {
@@ -4210,6 +4396,9 @@ StageMorph.prototype.processKeyEvent = function (event, action) {
break;
default:
keyName = String.fromCharCode(event.keyCode || event.charCode);
+ if (event.ctrlKey || event.metaKey) {
+ keyName = 'ctrl ' + keyName;
+ }
}
action.call(this, keyName);
};
@@ -4224,6 +4413,15 @@ StageMorph.prototype.fireKeyEvent = function (key) {
if (evt === 'ctrl enter') {
return this.fireGreenFlagEvent();
}
+ if (evt === 'ctrl f') {
+ return this.parentThatIsA(IDE_Morph).currentSprite.searchBlocks();
+ }
+ if (evt === 'ctrl o') {
+ return this.parentThatIsA(IDE_Morph).openProjectsBrowser();
+ }
+ if (evt === 'ctrl s') {
+ return this.parentThatIsA(IDE_Morph).save();
+ }
if (evt === 'esc') {
return this.fireStopAllEvent();
}
@@ -4847,6 +5045,8 @@ StageMorph.prototype.paletteColor = SpriteMorph.prototype.paletteColor;
StageMorph.prototype.setName = SpriteMorph.prototype.setName;
StageMorph.prototype.palette = SpriteMorph.prototype.palette;
StageMorph.prototype.freshPalette = SpriteMorph.prototype.freshPalette;
+StageMorph.prototype.blocksMatching = SpriteMorph.prototype.blocksMatching;
+StageMorph.prototype.searchBlocks = SpriteMorph.prototype.searchBlocks;
StageMorph.prototype.showingWatcher = SpriteMorph.prototype.showingWatcher;
StageMorph.prototype.addVariable = SpriteMorph.prototype.addVariable;
StageMorph.prototype.deleteVariable = SpriteMorph.prototype.deleteVariable;
diff --git a/snap.html b/snap.html
index 66604c5..904aba8 100755
--- a/snap.html
+++ b/snap.html
@@ -22,6 +22,7 @@
var world;
window.onload = function () {
world = new WorldMorph(document.getElementById('world'));
+ world.worldCanvas.focus();
new IDE_Morph().openIn(world);
setInterval(loop, 1);
};
diff --git a/threads.js b/threads.js
index b82a8c5..21147a3 100644
--- a/threads.js
+++ b/threads.js
@@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/
// Global stuff ////////////////////////////////////////////////////////
-modules.threads = '2014-May-02';
+modules.threads = '2014-May-20';
var ThreadManager;
var Process;
@@ -3110,6 +3110,20 @@ VariableFrame.prototype.allNames = function () {
return answer;
};
+// Variable /////////////////////////////////////////////////////////////////
+
+function Variable(value) {
+ this.value = value;
+}
+
+Variable.prototype.toString = function () {
+ return 'a Variable [' + this.value + ']';
+};
+
+Variable.prototype.copy = function () {
+ return new Variable(this.value);
+};
+
// UpvarReference ///////////////////////////////////////////////////////////
// ... quasi-inherits some features from VariableFrame