diff options
Diffstat (limited to 'morphic.js')
| -rw-r--r-- | morphic.js | 115 |
1 files changed, 84 insertions, 31 deletions
@@ -1035,7 +1035,7 @@ /*global window, HTMLCanvasElement, getMinimumFontHeight, FileReader, Audio, FileList, getBlurredShadowSupport*/ -var morphicVersion = '2014-May-20'; +var morphicVersion = '2014-July-11'; var modules = {}; // keep track of additional loaded modules var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug @@ -4495,9 +4495,9 @@ CursorMorph.prototype.processKeyPress = function (event) { } if (event.keyCode) { // Opera doesn't support charCode if (event.ctrlKey) { - this.ctrl(event.keyCode); + this.ctrl(event.keyCode, event.shiftKey); } else if (event.metaKey) { - this.cmd(event.keyCode); + this.cmd(event.keyCode, event.shiftKey); } else { this.insert( String.fromCharCode(event.keyCode), @@ -4506,9 +4506,9 @@ CursorMorph.prototype.processKeyPress = function (event) { } } else if (event.charCode) { // all other browsers if (event.ctrlKey) { - this.ctrl(event.charCode); + this.ctrl(event.charCode, event.shiftKey); } else if (event.metaKey) { - this.cmd(event.keyCode); + this.cmd(event.charCode, event.shiftKey); } else { this.insert( String.fromCharCode(event.charCode), @@ -4525,13 +4525,13 @@ CursorMorph.prototype.processKeyDown = function (event) { var shift = event.shiftKey; this.keyDownEventUsed = false; if (event.ctrlKey) { - this.ctrl(event.keyCode); + this.ctrl(event.keyCode, event.shiftKey); // notify target's parent of key event this.target.escalateEvent('reactToKeystroke', event); return; } if (event.metaKey) { - this.cmd(event.keyCode); + this.cmd(event.keyCode, event.shiftKey); // notify target's parent of key event this.target.escalateEvent('reactToKeystroke', event); return; @@ -4746,8 +4746,10 @@ CursorMorph.prototype.insert = function (aChar, shiftKey) { } }; -CursorMorph.prototype.ctrl = function (aChar) { - if ((aChar === 97) || (aChar === 65)) { +CursorMorph.prototype.ctrl = function (aChar, shiftKey) { + if (aChar === 64 || (aChar === 65 && shiftKey)) { + this.insert('@'); + } else if (aChar === 65) { this.target.selectAll(); } else if (aChar === 90) { this.undo(); @@ -4759,17 +4761,34 @@ CursorMorph.prototype.ctrl = function (aChar) { this.insert('['); } else if (aChar === 93) { this.insert(']'); - } else if (aChar === 64) { - this.insert('@'); + } else if (!isNil(this.target.receiver)) { + if (aChar === 68) { + this.target.doIt(); + } else if (aChar === 73) { + this.target.inspectIt(); + } else if (aChar === 80) { + this.target.showIt(); + } } + }; -CursorMorph.prototype.cmd = function (aChar) { - if (aChar === 65) { +CursorMorph.prototype.cmd = function (aChar, shiftKey) { + if (aChar === 64 || (aChar === 65 && shiftKey)) { + this.insert('@'); + } else if (aChar === 65) { this.target.selectAll(); } else if (aChar === 90) { this.undo(); + } else if (!isNil(this.target.receiver)) { + if (aChar === 68) { + this.target.doIt(); + } else if (aChar === 73) { + this.target.inspectIt(); + } else if (aChar === 80) { + this.target.showIt(); + } } }; @@ -6141,6 +6160,7 @@ InspectorMorph.prototype.init = function (target) { this.currentProperty = null; this.showing = 'attributes'; this.markOwnProperties = false; + this.hasUserEditedDetails = false; // initialize inherited properties: InspectorMorph.uber.init.call(this); @@ -6157,6 +6177,7 @@ InspectorMorph.prototype.init = function (target) { this.edge = MorphicPreferences.isFlat ? 1 : 5; this.color = new Color(60, 60, 60); this.borderColor = new Color(95, 95, 95); + this.fps = 25; this.drawNew(); // panes: @@ -6181,6 +6202,36 @@ InspectorMorph.prototype.setTarget = function (target) { this.buildPanes(); }; +InspectorMorph.prototype.updateCurrentSelection = function () { + var val, txt, cnts, + sel = this.list.selected, + currentTxt = this.detail.contents.children[0], + root = this.root(); + + if (root && + (root.keyboardReceiver instanceof CursorMorph) && + (root.keyboardReceiver.target === currentTxt)) { + this.hasUserEditedDetails = true; + return; + } + if (isNil(sel) || this.hasUserEditedDetails) {return; } + val = this.target[sel]; + this.currentProperty = val; + if (isNil(val)) { + txt = 'NULL'; + } else if (isString(val)) { + txt = val; + } else { + txt = val.toString(); + } + if (currentTxt.text === txt) {return; } + cnts = new TextMorph(txt); + cnts.isEditable = true; + cnts.enableSelecting(); + cnts.setReceiver(this.target); + this.detail.setContents(cnts); +}; + InspectorMorph.prototype.buildPanes = function () { var attribs = [], property, myself = this, ctrl, ev, doubleClickAction; @@ -6248,23 +6299,9 @@ InspectorMorph.prototype.buildPanes = function () { doubleClickAction ); - this.list.action = function (selected) { - var val, txt, cnts; - if (selected === undefined) {return; } - val = myself.target[selected]; - myself.currentProperty = val; - if (val === null) { - txt = 'NULL'; - } else if (isString(val)) { - txt = val; - } else { - txt = val.toString(); - } - cnts = new TextMorph(txt); - cnts.isEditable = true; - cnts.enableSelecting(); - cnts.setReceiver(myself.target); - myself.detail.setContents(cnts); + this.list.action = function () { + myself.hasUserEditedDetails = false; + myself.updateCurrentSelection(); }; this.list.hBar.alpha = 0.6; @@ -6512,6 +6549,7 @@ InspectorMorph.prototype.save = function () { try { // this.target[prop] = evaluate(txt); this.target.evaluateString('this.' + prop + ' = ' + txt); + this.hasUserEditedDetails = false; if (this.target.drawNew) { this.target.changed(); this.target.drawNew(); @@ -6582,6 +6620,17 @@ InspectorMorph.prototype.removeProperty = function () { } }; +// InspectorMorph stepping + +InspectorMorph.prototype.step = function () { + this.updateCurrentSelection(); + var lbl = this.target.toString(); + if (this.label.text === lbl) {return; } + this.label.text = lbl; + this.label.drawNew(); + this.fixLayout(); +}; + // MenuMorph /////////////////////////////////////////////////////////// // MenuMorph: referenced constructors @@ -6844,6 +6893,9 @@ MenuMorph.prototype.popup = function (world, pos) { if (world.activeMenu) { world.activeMenu.destroy(); } + if (this.items.length < 1 && !this.title) { // don't show empty menus + return; + } world.add(this); world.activeMenu = this; this.fullChanged(); @@ -7924,7 +7976,7 @@ TextMorph.prototype.inspectIt = function () { var result = this.receiver.evaluateString(this.selection()), world = this.world(), inspector; - if (result !== null) { + if (isObject(result)) { inspector = new InspectorMorph(result); inspector.setPosition(world.hand.position()); inspector.keepWithin(world); @@ -9046,6 +9098,7 @@ ListMorph.prototype.buildListContents = function () { }; ListMorph.prototype.select = function (item, trigger) { + if (isNil(item)) {return; } this.selected = item; this.active = trigger; if (this.action) { |
