Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

DEval preview.

  • Loading branch information...
commit 20a554895db621666a9339dc942ae5b6612de696 1 parent 2b097ba
tamt authored
View
19 demo/TestEval.as
@@ -0,0 +1,19 @@
+package
+{
+ import r1.deval.D;
+
+ import flash.display.DisplayObject;
+ import flash.display.Sprite;
+
+ /**
+ * @author tamt
+ */
+ public class TestEval extends Sprite
+ {
+ public function TestEval()
+ {
+ Object.prototype.prototype = null;
+ D.eval("trace(this);", null, this);
+ }
+ }
+}
View
BIN  demo/TestEval.swf
Binary file not shown
View
20 demo/tInspectorDemo.as
@@ -1,9 +1,9 @@
package
{
- import cn.itamt.utils.inspector.plugins.deval.DEval;
import cn.itamt.utils.Inspector;
- import cn.itamt.utils.inspector.core.liveinspect.LiveInspectView;
+ import cn.itamt.utils.inspector.core.structureview.StructureView;
import cn.itamt.utils.inspector.plugins.controlbar.ControlBar;
+ import cn.itamt.utils.inspector.plugins.deval.DEval;
import flash.display.Loader;
import flash.display.Sprite;
@@ -37,21 +37,29 @@ package
var bar:ControlBar=new ControlBar();
addChild(bar);
-
+
Inspector.getInstance().init(this);
// var liveInspect:LiveInspectView=new LiveInspectView();
// var property:PropertiesView = new PropertiesView();
- // var struct:StructureView = new StructureView();
+ var struct:StructureView=new StructureView();
+ var deval:DEval = new DEval();
+ Inspector.getInstance().pluginManager.registerPlugin(struct);
Inspector.getInstance().pluginManager.registerPlugin(bar);
- Inspector.getInstance().pluginManager.registerPlugin(new DEval());
+ Inspector.getInstance().pluginManager.registerPlugin(deval);
+
+
+ Inspector.getInstance().turnOn();
+
// Inspector.getInstance().pluginManager.registerPlugin(liveInspect);
// Inspector.getInstance().pluginManager.registerPlugin(property);
- // Inspector.getInstance().pluginManager.registerPlugin(struct);
// Inspector.getInstance().turnOn(liveInspect.getPluginId());
// this.stage.align = StageAlign.RIGHT;
+
+ Inspector.getInstance().pluginManager.activePlugin(struct.getPluginId());
+ Inspector.getInstance().pluginManager.activePlugin(deval.getPluginId());
}
}
}
View
BIN  demo/tInspectorDemo.swf
Binary file not shown
View
4 src/cn/itamt/utils/Debug.as
@@ -1,5 +1,5 @@
package cn.itamt.utils {
-// import com.hexagonstar.util.debug.Debug;
+ import com.hexagonstar.util.debug.Debug;
public class Debug {
public function Debug() {
}
@@ -9,7 +9,7 @@ package cn.itamt.utils {
}
public static function trace(str : String, level : int = 0) : void {
-// com.hexagonstar.util.debug.Debug.trace(str, level);
+ com.hexagonstar.util.debug.Debug.trace(str, level);
}
}
}
View
4 src/cn/itamt/utils/inspector/core/propertyview/accessors/BooleanPropertyEditor.as
@@ -1,5 +1,5 @@
-package cn.itamt.utils.inspector.core.propertyview.accessors {
- import cn.itamt.utils.Debug;
+package cn.itamt.utils.inspector.core.propertyview.accessors
+{
import cn.itamt.utils.inspector.events.PropertyEvent;
import cn.itamt.utils.inspector.ui.ToggleBooleanButton;
View
2  src/cn/itamt/utils/inspector/lang/CN.as
@@ -83,6 +83,8 @@ ShowMouse = 显示鼠标
FlashConsole = 控制台
DEval = as3 eval
runEval = 运行
+autoLinkThis = 自动链接this引用
+autoLinkThisTip = 自动链接this<br>代码中的this将引用当前查看对象.
]]>
</lang>;
}
View
2  src/cn/itamt/utils/inspector/lang/EN.as
@@ -83,6 +83,8 @@ ShowMouse = show mouse
FlashConsole = flash Console
DEval = as3 eval
runEval = run
+autoLinkThis = auto link "this" reference
+autoLinkThisTip = auto link "this"(in eval code) reference to current inspect target.
]]>
</lang>;
}
View
154 src/cn/itamt/utils/inspector/plugins/deval/DEval.as
@@ -1,10 +1,13 @@
package cn.itamt.utils.inspector.plugins.deval
{
- import r1.deval.D;
import cn.itamt.utils.inspector.core.BaseInspectorPlugin;
+ import cn.itamt.utils.inspector.core.InspectTarget;
import cn.itamt.utils.inspector.popup.InspectorPopupManager;
import cn.itamt.utils.inspector.popup.PopupAlignMode;
+ import r1.deval.D;
+
+ import flash.display.DisplayObject;
import flash.events.Event;
/**
@@ -14,56 +17,56 @@ package cn.itamt.utils.inspector.plugins.deval
*/
public class DEval extends BaseInspectorPlugin
{
- /**
- * 是否在插件使用时显示面板(用于输入代码)
- */
- protected var _isShowPanel:Boolean = true;
- //主要面板
- protected var panel:DEvalPanel;
-
+
public function DEval()
{
super();
//设定插件图标按钮
- _icon = new DEvalButton();
+ _icon=new DEvalButton();
}
-
+
+ //自动链接this,把eval中的this链接到当前查看的对象,这样代码中的this会引用当前查看的对象
+ protected var _autoThis:Boolean=true;
/**
- * 插件id,tInspector通过plugin id来管理各个插件。
+ * 是否在插件使用时显示面板(用于输入代码)
*/
- override public function getPluginId():String{
- return "DEval";
- }
-
+ protected var _isShowPanel:Boolean=true;
+ //主要面板
+ protected var panel:DEvalPanel;
+
/**
- * 插件被激活使用
- */
- override public function onActive() : void
+ * 自动链接this,把eval中的this链接到当前查看的对象,这样代码中的this会引用当前查看的对象
+ */
+ public function get autoThis():Boolean
{
- super.onActive();
-
- //根据默认值,显示面板
- this.isShowPanel = _isShowPanel;
+ return _autoThis;
}
-
+
/**
- * 插件被取消激活使用
+ * 自动链接this,把eval中的this链接到当前查看的对象,这样代码中的this会引用当前查看的对象
*/
- override public function onUnActive() : void
+ public function set autoThis(autoThis:Boolean):void
{
- super.onUnActive();
-
- if(isShowPanel){
- InspectorPopupManager.remove(panel);
- panel = null;
+ _autoThis=autoThis;
+ if (panel)
+ {
+ panel.autoLinkThis=_autoThis;
}
}
-
+
+ /**
+ * 插件id,tInspector通过plugin id来管理各个插件。
+ */
+ override public function getPluginId():String
+ {
+ return "DEval";
+ }
+
/**
* 是否在插件使用时显示面板(用于输入代码)
*/
- public function get isShowPanel() : Boolean
+ public function get isShowPanel():Boolean
{
return _isShowPanel;
}
@@ -71,41 +74,96 @@ package cn.itamt.utils.inspector.plugins.deval
/**
* 是否在插件使用时显示面板(用于输入、运行代码)
*/
- public function set isShowPanel(showPanel : Boolean) : void
+ public function set isShowPanel(showPanel:Boolean):void
{
- _isShowPanel = showPanel;
- if(_isShowPanel){
- if(panel == null){
- panel = new DEvalPanel();
+ _isShowPanel=showPanel;
+ if (_isShowPanel)
+ {
+ if (panel == null)
+ {
+ panel=new DEvalPanel();
panel.addEventListener(Event.CLOSE, closePanelHandler);
- panel.addEventListener("click run", clickRunHandler);
+ panel.addEventListener("click_run", clickRunHandler);
+ panel.autoLinkThis=autoThis;
+
+ //设置输出终端
+ D.setTextControlOutput(panel.outputControl);
}
InspectorPopupManager.popup(panel, PopupAlignMode.CENTER);
- }else{
- if(panel){
- if(panel.parent)panel.parent.removeChild(panel);
- panel = null;
+ }
+ else
+ {
+ if (panel)
+ {
+ if (panel.parent)
+ panel.parent.removeChild(panel);
+ panel.removeEventListener(Event.CLOSE, closePanelHandler);
+ panel.removeEventListener("click_run", clickRunHandler);
+ panel=null;
}
}
}
-
+
+ /**
+ * 插件被激活使用
+ */
+ override public function onActive():void
+ {
+ super.onActive();
+
+ //根据默认值,显示面板
+ this.isShowPanel=_isShowPanel;
+ if (panel)
+ panel.input='printf(this);';
+ }
+
+ /**
+ * 当Inspector查看某个目标显示对象时.
+ */
+ override public function onInspect(target:InspectTarget):void
+ {
+ this.target=target;
+ }
+
+ /**
+ * 插件被取消激活使用
+ */
+ override public function onUnActive():void
+ {
+ super.onUnActive();
+
+ if (isShowPanel)
+ {
+ InspectorPopupManager.remove(panel);
+ panel=null;
+ }
+ }
+
/**
* 单击面的“运行”按钮时
*/
- private function clickRunHandler(evt:Event) : void
+ private function clickRunHandler(evt:Event):void
{
- D.eval(panel.input);
+ if(_autoThis){
+ var _this:DisplayObject=target ? target.displayObject : null;
+ if (_this)
+ {
+ //D.eval内部直接访问对象的prototype属性,会导致运行出错。这个用于修正这个错误。
+ _this["constructor"].prototype.prototype=null;
+ }
+ D.eval(panel.input, null, _this);
+ }else{
+ D.eval(panel.input, null, null);
+ }
}
/**
* 单击面板的关闭按钮时
*/
- private function closePanelHandler(event : Event) : void
+ private function closePanelHandler(event:Event):void
{
//取消激活使用该插件
this._inspector.pluginManager.unactivePlugin(this.getPluginId());
}
-
-
}
}
View
114 src/cn/itamt/utils/inspector/plugins/deval/DEvalPanel.as
@@ -4,10 +4,14 @@ package cn.itamt.utils.inspector.plugins.deval
import cn.itamt.utils.inspector.ui.InspectorLabelButton;
import cn.itamt.utils.inspector.ui.InspectorTextField;
import cn.itamt.utils.inspector.ui.InspectorViewPanel;
+ import cn.itamt.utils.inspector.ui.ToggleBooleanButton;
+ import flash.events.ContextMenuEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextFieldType;
+ import flash.ui.ContextMenu;
+ import flash.ui.ContextMenuItem;
/**
* Deval面板,包含一个输入的文本框,和“执行”按钮
@@ -16,8 +20,11 @@ package cn.itamt.utils.inspector.plugins.deval
public class DEvalPanel extends InspectorViewPanel
{
//用户输入代码的文本框
- protected var cmd:InspectorTextField;
+ protected var _input:InspectorTextField;
+ protected var _output:InspectorTextField;
protected var btn:InspectorLabelButton;
+ protected var _autoLinkThis:ToggleBooleanButton;
+ protected var _autoLinkThisTip:InspectorTextField;
public function DEvalPanel(w : Number = 300, h : Number = 300, autoDisposeWhenRemove : Boolean = true, resizeable : Boolean = true, closeable : Boolean = true)
{
@@ -25,18 +32,48 @@ package cn.itamt.utils.inspector.plugins.deval
_title.mouseEnabled = _title.mouseWheelEnabled = _title.selectable = false;
- cmd = InspectorTextField.create("", 0xffffff, 12);
- cmd.type = TextFieldType.INPUT;
- cmd.multiline = true;
- cmd.border = true;
- cmd.borderColor = 0x666666;
- addChild(cmd);
+ _input = InspectorTextField.create("", 0xffffff, 12);
+ _input.type = TextFieldType.INPUT;
+ _input.multiline = true;
+ _input.border = true;
+ _input.borderColor = 0x666666;
+ addChild(_input);
+ _output = InspectorTextField.create("type code in the TextField below. and then click 'run'", 0xffffff, 12);
+ _output.multiline = true;
+ _output.border = true;
+ _output.wordWrap = true;
+ _output.borderColor = 0x999999;
+ var cm:ContextMenu = new ContextMenu();
+ var clearItem:ContextMenuItem = new ContextMenuItem(InspectorLanguageManager.getStr("Clear"));
+ cm.customItems.push(clearItem);
+ clearItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onMenuItemSelect);
+ _output.contextMenu = cm;
+ addChild(_output);
+
+ //运行
btn = new InspectorLabelButton(InspectorLanguageManager.getStr("runEval"));
btn.tip = null;
addChild(btn);
-
btn.addEventListener(MouseEvent.CLICK, clickRunHandler);
+
+ //把thisObj链接到当前查看的对象,这样代码中的this会引用当前查看的对象
+ _autoLinkThis = new ToggleBooleanButton(true);
+ _autoLinkThis.tip = InspectorLanguageManager.getStr("autoLinkThisTip");
+ addChild(_autoLinkThis);
+ _autoLinkThisTip = InspectorTextField.create(InspectorLanguageManager.getStr("autoLinkThis"), 0xcccccc, 12);
+ addChild(_autoLinkThisTip);
+ }
+
+ /**
+ * 点击了右键菜单项
+ */
+ private function onMenuItemSelect(event : ContextMenuEvent) : void
+ {
+ var menuItem:ContextMenuItem = event.target as ContextMenuItem;
+ if(menuItem.caption == InspectorLanguageManager.getStr("Clear")){
+ _output.text = "";
+ }
}
@@ -55,42 +92,79 @@ package cn.itamt.utils.inspector.plugins.deval
{
super.relayout();
- cmd.x = padding.left;
- cmd.y = padding.top;
- cmd.width = _width - padding.right - padding.left;
- cmd.height = _height - padding.top - padding.bottom - btn.height - 5;
+ _output.x = padding.left;
+ _output.y = padding.top;
+ _output.width = _width - padding.right - padding.left;
+ _output.height = _height - padding.top - padding.bottom - 70 - btn.height - 5;
+
+ _input.x = padding.left;
+ _input.y = _output.y + _output.height + 5;
+ _input.width = _width - padding.right - padding.left;
+ _input.height = 65;
btn.x = _width - padding.right - btn.width;
btn.y = _height - padding.bottom - btn.height;
+
+ _autoLinkThis.x = padding.left;
+ _autoLinkThis.y = _height - _autoLinkThis.height - padding.bottom;
+ _autoLinkThisTip.x = padding.left + _autoLinkThis.width;
+ _autoLinkThisTip.y = _height - _autoLinkThis.height - padding.bottom;
}
-
+
+ /**
+ * 展开面板时
+ */
override public function open() : void
{
super.open();
- this.btn.visible = true;
- this.cmd.visible = true;
+ this.btn.visible = this._input.visible = this._output.visible = this._autoLinkThis.visible = this._autoLinkThisTip.visible =true;
}
-
+ /**
+ * 最小化面板时
+ */
override public function hide() : void
{
super.hide();
- this.btn.visible = false;
- this.cmd.visible = false;
+ this.btn.visible = this._input.visible = this._output.visible = this._autoLinkThis.visible = this._autoLinkThisTip.visible =false;
}
/**
* 用户输入的代码
*/
public function get input():String{
- return cmd.text;
+ return _input.text;
}
/**
* 用户输入的代码
*/
public function set input(text:String):void{
- cmd.text = text;
+ _input.text = text;
+ }
+
+ /**
+ * 用于输出代码运行结果的文本框
+ */
+ public function get outputControl() : InspectorTextField
+ {
+ return _output;
+ }
+
+ /**
+ * 是否自动链接this引用
+ */
+ public function get autoLinkThis() : Boolean
+ {
+ return _autoLinkThis.value;
+ }
+
+ /**
+ * 是否自动链接this引用
+ */
+ public function set autoLinkThis(value:Boolean) : void
+ {
+ _autoLinkThis.value = value;
}
}
View
14 src/cn/itamt/utils/inspector/popup/InspectorTipsManager.as
@@ -47,21 +47,23 @@ package cn.itamt.utils.inspector.popup {
_tip.filters = [new GlowFilter(0x0, 1, 16, 16, 1)];
_tip.mouseEnabled = _tip.mouseChildren = false;
- var _tf : TextField = InspectorTextField.create(evt.tip, 0xffffff, 15, 5, 0, 'left');
+ var _tf : TextField = InspectorTextField.create("", 0xffffff, 15, 5, 0, 'left');
+ _tf.multiline = true;
+ _tf.htmlText = evt.tip;
_tf.name = "tf";
- _tf.y = 26 - _tf.height;
+ _tf.y = 6;//26 - _tf.height;
_tip.addChild(_tf);
var tipBg : Shape = new Shape();
tipBg.graphics.beginFill(0x000000);
- tipBg.graphics.drawRoundRect(0, 26 - _tf.height, _tf.width + 10, _tf.height, 10, 10);
+ tipBg.graphics.drawRoundRect(0, 6, _tf.width + 10, _tf.height, 10, 10);
tipBg.graphics.endFill();
// /*
tipBg.graphics.beginFill(0x000000);
- tipBg.graphics.moveTo(9, 26 - _tf.height);
- tipBg.graphics.lineTo(15, 26 - _tf.height);
+ tipBg.graphics.moveTo(9, 6);
+ tipBg.graphics.lineTo(15, 6);
tipBg.graphics.lineTo(12, 0);
- tipBg.graphics.lineTo(9, 26 - _tf.height);
+ tipBg.graphics.lineTo(9, 6);
tipBg.graphics.endFill();
// */
_tip.addChildAt(tipBg, 0);
View
4 src/cn/itamt/utils/inspector/ui/InspectorIconButton.as
@@ -61,6 +61,8 @@ package cn.itamt.utils.inspector.ui {
g.drawRect((_w - bmd.width) / 2, (_h - bmd.height) / 2, bmd.width, bmd.height);
g.endFill();
+ sp.filters = [new ColorMatrixFilter([0.3086, 0.6094, 0.0820, 0, 0, 0.3086, 0.6094, 0.0820, 0, 0, 0.3086, 0.6094, 0.0820, 0, 0, 0, 0, 0, 1, 0])];
+
return sp;
}
@@ -76,8 +78,6 @@ package cn.itamt.utils.inspector.ui {
g.drawRect((_w - bmd.width) / 2, (_h - bmd.height) / 2, bmd.width, bmd.height);
g.endFill();
- sp.filters = [new ColorMatrixFilter([0.3086, 0.6094, 0.0820, 0, 0, 0.3086, 0.6094, 0.0820, 0, 0, 0.3086, 0.6094, 0.0820, 0, 0, 0, 0, 0, 1, 0])];
-
return sp;
}
View
1  src/cn/itamt/utils/inspector/ui/InspectorTextField.as
@@ -18,6 +18,7 @@ package cn.itamt.utils.inspector.ui {
var tfm : TextFormat = new TextFormat();
tfm.size = size;
tfm.align = align;
+ tfm.color = color;
if(fontName == null) {
fontName = getNameOfFirstAvaliableFont(fonts);
View
2  src/cn/itamt/utils/inspector/ui/ToggleBooleanButton.as
@@ -7,7 +7,7 @@ package cn.itamt.utils.inspector.ui {
/**
* @author itamt@qq.com
*/
- public class ToggleBooleanButton extends SimpleButton {
+ public class ToggleBooleanButton extends InspectorButton {
private var _value : Boolean;
public function set value(v : Boolean) : void {
Please sign in to comment.
Something went wrong with that request. Please try again.