Permalink
Browse files

DEval preview.

  • Loading branch information...
1 parent 2b097ba commit 20a554895db621666a9339dc942ae5b6612de696 tamt committed May 14, 2011
View
@@ -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
Binary file not shown.
View
@@ -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
Binary file not shown.
@@ -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);
}
}
}
@@ -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;
@@ -83,6 +83,8 @@ ShowMouse = 显示鼠标
FlashConsole = 控制台
DEval = as3 eval
runEval = 运行
+autoLinkThis = 自动链接this引用
+autoLinkThisTip = 自动链接this<br>代码中的this将引用当前查看对象.
]]>
</lang>;
}
@@ -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>;
}
@@ -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,98 +17,153 @@ 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;
}
/**
* 是否在插件使用时显示面板(用于输入、运行代码)
*/
- 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());
}
-
-
}
}
Oops, something went wrong.

0 comments on commit 20a5548

Please sign in to comment.