PageRenderTime 38ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/!src/com/luaye/console/view/MainPanel.as

https://github.com/tluczyns/tluczyns-as3-base
ActionScript | 766 lines | 689 code | 20 blank | 57 comment | 136 complexity | 8dd8ef9c7f1116be294b0e38755249e0 MD5 | raw file
  1. /*
  2. *
  3. * Copyright (c) 2008-2009 Lu Aye Oo
  4. *
  5. * @author Lu Aye Oo
  6. *
  7. * http://code.google.com/p/flash-console/
  8. *
  9. *
  10. * This software is provided 'as-is', without any express or implied
  11. * warranty. In no event will the authors be held liable for any damages
  12. * arising from the use of this software.
  13. * Permission is granted to anyone to use this software for any purpose,
  14. * including commercial applications, and to alter it and redistribute it
  15. * freely, subject to the following restrictions:
  16. * 1. The origin of this software must not be misrepresented; you must not
  17. * claim that you wrote the original software. If you use this software
  18. * in a product, an acknowledgment in the product documentation would be
  19. * appreciated but is not required.
  20. * 2. Altered source versions must be plainly marked as such, and must not be
  21. * misrepresented as being the original software.
  22. * 3. This notice may not be removed or altered from any source distribution.
  23. *
  24. */
  25. package com.luaye.console.view {
  26. import flash.text.TextFormat;
  27. import flash.system.System;
  28. import com.luaye.console.Console;
  29. import com.luaye.console.core.CommandLine;
  30. import com.luaye.console.core.Log;
  31. import com.luaye.console.core.Logs;
  32. import flash.display.Shape;
  33. import flash.display.Sprite;
  34. import flash.events.Event;
  35. import flash.events.KeyboardEvent;
  36. import flash.events.MouseEvent;
  37. import flash.events.TextEvent;
  38. import flash.geom.ColorTransform;
  39. import flash.geom.Rectangle;
  40. import flash.system.Capabilities;
  41. import flash.system.Security;
  42. import flash.system.SecurityPanel;
  43. import flash.text.TextField;
  44. import flash.text.TextFieldAutoSize;
  45. import flash.text.TextFieldType;
  46. import flash.ui.Keyboard;
  47. public class MainPanel extends AbstractPanel {
  48. private static const CHANNELS_IN_MENU:int = 7;
  49. public static const TOOLTIPS:Object = {
  50. fps:"Frames Per Second",
  51. mm:"Memory Monitor",
  52. roller:"Display Roller::Map the display list under your mouse",
  53. ruler:"Screen Ruler::Measure the distance and angle between two points on screen.",
  54. command:"Command Line",
  55. copy:"Copy to clipboard",
  56. clear:"Clear log",
  57. trace:"Trace",
  58. pause:"Pause updates",
  59. resume:"Resume updates",
  60. priority:"Priority filter",
  61. channels:"Expand channels",
  62. close:"Close",
  63. closemain:"Close::Type password to show again",
  64. viewall:"View all channels",
  65. defaultch:"Default channel::Logs with no channel",
  66. consolech:"Console's channel::Logs generated from Console",
  67. filterch:"Filtering channel",
  68. channel:"Change channel::Hold shift to select multiple channels",
  69. scrollUp:"Scroll up",
  70. scrollDown:"Scroll down",
  71. scope:"Current scope::(CommandLine)"
  72. };
  73. // these are used for adding extended functionality such as from RemoteAIR
  74. private var _extraMenuKeys:Array = [];
  75. public var topMenuClick:Function;
  76. public var topMenuRollOver:Function;
  77. private var _traceField:TextField;
  78. private var _menuField:TextField;
  79. private var _commandPrefx:TextField;
  80. private var _commandField:TextField;
  81. private var _commandBackground:Shape;
  82. private var _bottomLine:Shape;
  83. private var _isMinimised:Boolean;
  84. private var _shift:Boolean;
  85. private var _canUseTrace:Boolean;
  86. private var _scrollbar:Sprite;
  87. private var _scroller:Sprite;
  88. private var _scrolldelay:uint;
  89. private var _scrolldir:int;
  90. private var _channels:Array;
  91. private var _viewingChannels:Array;
  92. private var _lines:Logs;
  93. private var _commandsHistory:Array = [];
  94. private var _commandsInd:int = -1;
  95. private var _needUpdateMenu:Boolean;
  96. private var _needUpdateTrace:Boolean;
  97. private var _lockScrollUpdate:Boolean;
  98. private var _atBottom:Boolean = true;
  99. private var _enteringLogin:Boolean;
  100. public function MainPanel(m:Console, lines:Logs, channels:Array, chanviews:Array) {
  101. super(m);
  102. _canUseTrace = (Capabilities.playerType=="External"||Capabilities.isDebugger);
  103. var fsize:int = m.style.menuFontSize;
  104. _channels = channels;
  105. _viewingChannels = chanviews;
  106. _lines = lines;
  107. _commandsHistory = m.ud.commandLineHistory;
  108. name = Console.PANEL_MAIN;
  109. minimumWidth = 50;
  110. minimumHeight = 18;
  111. _traceField = new TextField();
  112. _traceField.name = "traceField";
  113. _traceField.wordWrap = true;
  114. _traceField.background = false;
  115. _traceField.multiline = true;
  116. _traceField.styleSheet = m.css;
  117. _traceField.y = fsize;
  118. _traceField.addEventListener(Event.SCROLL, onTraceScroll, false, 0, true);
  119. addChild(_traceField);
  120. //
  121. _menuField = new TextField();
  122. _menuField.name = "menuField";
  123. _menuField.styleSheet = m.css;
  124. _menuField.height = fsize+6;
  125. _menuField.y = -2;
  126. registerRollOverTextField(_menuField);
  127. _menuField.addEventListener(AbstractPanel.TEXT_LINK, onMenuRollOver, false, 0, true);
  128. addChild(_menuField);
  129. //
  130. _commandBackground = new Shape();
  131. _commandBackground.name = "commandBackground";
  132. _commandBackground.graphics.beginFill(style.commandLineColor, 0.1);
  133. _commandBackground.graphics.drawRoundRect(0, 0, 100, 18,fsize,fsize);
  134. _commandBackground.scale9Grid = new Rectangle(9, 9, 80, 1);
  135. addChild(_commandBackground);
  136. //
  137. var tf:TextFormat = new TextFormat(style.menuFont, style.menuFontSize, style.highColor);
  138. _commandField = new TextField();
  139. _commandField.name = "commandField";
  140. _commandField.type = TextFieldType.INPUT;
  141. _commandField.x = 40;
  142. _commandField.height = fsize+6;
  143. _commandField.addEventListener(KeyboardEvent.KEY_DOWN, commandKeyDown, false, 0, true);
  144. _commandField.addEventListener(KeyboardEvent.KEY_UP, commandKeyUp, false, 0, true);
  145. _commandField.defaultTextFormat = tf;
  146. addChild(_commandField);
  147. tf.color = style.commandLineColor;
  148. _commandPrefx = new TextField();
  149. _commandPrefx.name = "commandPrefx";
  150. _commandPrefx.type = TextFieldType.DYNAMIC;
  151. _commandPrefx.x = 2;
  152. _commandPrefx.height = fsize+6;
  153. _commandPrefx.selectable = false;
  154. _commandPrefx.defaultTextFormat = tf;
  155. _commandPrefx.text = " ";
  156. _commandPrefx.addEventListener(MouseEvent.MOUSE_DOWN, onCmdPrefMouseDown, false, 0, true);
  157. _commandPrefx.addEventListener(MouseEvent.MOUSE_MOVE, onCmdPrefRollOverOut, false, 0, true);
  158. _commandPrefx.addEventListener(MouseEvent.ROLL_OUT, onCmdPrefRollOverOut, false, 0, true);
  159. addChild(_commandPrefx);
  160. //
  161. _bottomLine = new Shape();
  162. _bottomLine.name = "blinkLine";
  163. _bottomLine.alpha = 0.2;
  164. addChild(_bottomLine);
  165. //
  166. _scrollbar = new Sprite();
  167. _scrollbar.name = "scrollbar";
  168. _scrollbar.buttonMode = true;
  169. _scrollbar.addEventListener(MouseEvent.MOUSE_DOWN, onScrollbarDown, false, 0, true);
  170. _scrollbar.y = fsize+4;
  171. addChild(_scrollbar);
  172. //
  173. _scroller = new Sprite();
  174. _scroller.name = "scroller";
  175. _scroller.graphics.beginFill(style.controlColor, 1);
  176. _scroller.graphics.drawRect(-5, 0, 5, 30);
  177. _scroller.graphics.beginFill(0, 0);
  178. _scroller.graphics.drawRect(-10, 0, 10, 30);
  179. _scroller.graphics.endFill();
  180. _scroller.buttonMode = true;
  181. _scroller.addEventListener(MouseEvent.MOUSE_DOWN, onScrollerDown, false, 0, true);
  182. addChild(_scroller);
  183. //
  184. _commandField.visible = false;
  185. _commandPrefx.visible = false;
  186. _commandBackground.visible = false;
  187. //
  188. init(420,100,true);
  189. registerDragger(_menuField);
  190. //
  191. addEventListener(TextEvent.LINK, linkHandler, false, 0, true);
  192. addEventListener(Event.ADDED_TO_STAGE, stageAddedHandle, false, 0, true);
  193. addEventListener(Event.REMOVED_FROM_STAGE, stageRemovedHandle, false, 0, true);
  194. master.cl.addEventListener(CommandLine.CHANGED_SCOPE, onUpdateCommandLineScope, false, 0, true);
  195. }
  196. public function addMenuKey(key:String):void{
  197. _extraMenuKeys.push(key);
  198. _needUpdateMenu = true;
  199. }
  200. private function stageAddedHandle(e:Event=null):void{
  201. stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler, false, 0, true);
  202. stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, false, 0, true);
  203. }
  204. private function stageRemovedHandle(e:Event=null):void{
  205. stage.removeEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
  206. stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
  207. }
  208. private function onCmdPrefRollOverOut(e : MouseEvent) : void {
  209. master.panels.tooltip(e.type==MouseEvent.MOUSE_MOVE?TOOLTIPS["scope"]:"", this);
  210. }
  211. private function onCmdPrefMouseDown(e : MouseEvent) : void {
  212. stage.focus = _commandField;
  213. _commandField.setSelection(_commandField.text.length, _commandField.text.length);
  214. }
  215. private function keyDownHandler(e:KeyboardEvent):void{
  216. if(e.keyCode == Keyboard.SHIFT){
  217. _shift = true;
  218. }
  219. }
  220. private function keyUpHandler(e:KeyboardEvent):void{
  221. if(e.keyCode == Keyboard.SHIFT){
  222. _shift = false;
  223. }
  224. }
  225. public function requestLogin(on:Boolean = true):void{
  226. var ct:ColorTransform = new ColorTransform();
  227. if(on){
  228. master.commandLine = true;
  229. master.report("//", -2);
  230. master.report("// <b>Enter remoting password</b> in CommandLine below...", -2);
  231. updateCLScope("Password");
  232. ct.color = style.controlColor;
  233. _commandBackground.transform.colorTransform = ct;
  234. _traceField.transform.colorTransform = new ColorTransform(0.7,0.7,0.7);
  235. }else{
  236. updateCLScope("?");
  237. _commandBackground.transform.colorTransform = ct;
  238. _traceField.transform.colorTransform = ct;
  239. }
  240. _commandField.displayAsPassword = on;
  241. _enteringLogin = on;
  242. }
  243. public function update(changed:Boolean):void{
  244. if(_bottomLine.alpha>0){
  245. _bottomLine.alpha -= 0.25;
  246. }
  247. if(changed){
  248. _bottomLine.alpha = 1;
  249. _needUpdateMenu = true;
  250. _needUpdateTrace = true;
  251. }
  252. if(_needUpdateTrace){
  253. _needUpdateTrace = false;
  254. _updateTraces(true);
  255. }
  256. if(_needUpdateMenu){
  257. _needUpdateMenu = false;
  258. _updateMenu();
  259. }
  260. }
  261. public function updateToBottom():void{
  262. _atBottom = true;
  263. _needUpdateTrace = true;
  264. }
  265. public function updateTraces(instant:Boolean = false):void{
  266. if(instant){
  267. _updateTraces();
  268. }else{
  269. _needUpdateTrace = true;
  270. }
  271. }
  272. private function _updateTraces(onlyBottom:Boolean = false):void{
  273. // TODO: onlyBottom: when you are scrolled up, it doesnt update for new lines, because
  274. // you won't see them while scrolled up anyway... (it increase performace a lot on long logs)
  275. // BUT scroll up, add lots of new lines, scroll back down,
  276. // you'll see it jumps to the bottom of log which can be annoying in rare cases
  277. //
  278. if(_atBottom) {
  279. updateBottom();
  280. }else if(!onlyBottom){
  281. updateFull();
  282. }
  283. }
  284. private function updateFull():void{
  285. var str:String = "";
  286. var line:Log = _lines.first;
  287. while(line){
  288. if(master.lineShouldShow(line)){
  289. str += makeLine(line);
  290. }
  291. line = line.next;
  292. }
  293. _lockScrollUpdate = true;
  294. _traceField.htmlText = str;
  295. _lockScrollUpdate = false;
  296. updateScroller();
  297. }
  298. public function setPaused(b:Boolean):void{
  299. if(b && _atBottom){
  300. _atBottom = false;
  301. updateTraces(true);
  302. _traceField.scrollV = _traceField.maxScrollV;
  303. }else if(!b){
  304. _atBottom = true;
  305. updateBottom();
  306. }
  307. updateMenu();
  308. }
  309. private function updateBottom():void{
  310. var lines:Array = new Array();
  311. var linesLeft:int = Math.round(_traceField.height/master.style.traceFontSize);
  312. var line:Log = _lines.last;
  313. while(line){
  314. if(master.lineShouldShow(line)){
  315. linesLeft--;
  316. lines.push(makeLine(line));
  317. if(linesLeft<=0){
  318. break;
  319. }
  320. }
  321. line = line.prev;
  322. }
  323. _lockScrollUpdate = true;
  324. _traceField.htmlText = lines.reverse().join("");
  325. _traceField.scrollV = _traceField.maxScrollV;
  326. _lockScrollUpdate = false;
  327. updateScroller();
  328. }
  329. private function makeLine(line:Log):String{
  330. var str:String = "";
  331. var txt:String = line.text;
  332. if(master.prefixChannelNames && (_viewingChannels.indexOf(Console.GLOBAL_CHANNEL)>=0 || _viewingChannels.length>1) && line.c != Console.DEFAULT_CHANNEL){
  333. txt = "[<a href=\"event:channel_"+line.c+"\">"+line.c+"</a>] "+txt;
  334. }
  335. var ptag:String = "p"+line.p;
  336. str += "<p><"+ptag+">" + txt + "</"+ptag+"></p>";
  337. return str;
  338. }
  339. private function onTraceScroll(e:Event = null):void{
  340. if(_lockScrollUpdate) return;
  341. var atbottom:Boolean = _traceField.scrollV >= _traceField.maxScrollV-1;
  342. if(!master.paused && _atBottom !=atbottom){
  343. var diff:int = _traceField.maxScrollV-_traceField.scrollV;
  344. _atBottom = atbottom;
  345. _updateTraces();
  346. _traceField.scrollV = _traceField.maxScrollV-diff;
  347. }
  348. updateScroller();
  349. }
  350. private function updateScroller():void{
  351. if(_traceField.maxScrollV<=1 || scrollerMaxY<22){
  352. _scroller.visible = false;
  353. _scrollbar.visible = false;
  354. }else{
  355. _scrollbar.visible = true;
  356. _scroller.visible = true;
  357. /* // scroller resize... works but waste of resouse I think
  358. var h:Number = (height*20)/_lines.length;
  359. var mh:Number = _bottomLine.y-40;
  360. _scroller.height = h<16?16:(h>mh?mh:h);
  361. */
  362. if(_atBottom) {
  363. _scroller.y = scrollerMaxY;
  364. }else{
  365. var per:Number = (_traceField.scrollV-1)/(_traceField.maxScrollV-1);
  366. _scroller.y = 21+((scrollerMaxY-21)*per);
  367. }
  368. }
  369. }
  370. private function onScrollerDown(e:MouseEvent):void{
  371. if(!master.paused){
  372. _atBottom = false;
  373. var Y:int = _scroller.y;
  374. _updateTraces();
  375. _scroller.y = Y;
  376. }
  377. var bound:Number = master.style.menuFontSize+8;
  378. _scroller.startDrag(false, new Rectangle(_scroller.x,bound, 0, (scrollerMaxY-bound)));
  379. stage.addEventListener(MouseEvent.MOUSE_MOVE, onScrollerMove, false, 0, true);
  380. stage.addEventListener(MouseEvent.MOUSE_UP, onScrollerUp, false, 0, true);
  381. }
  382. private function onScrollerMove(e:MouseEvent):void{
  383. var minY:Number = master.style.menuFontSize+8;
  384. var per:Number = (_scroller.y-minY)/(scrollerMaxY-minY);
  385. _lockScrollUpdate = true;
  386. _traceField.scrollV = Math.round((per*(_traceField.maxScrollV-1))+1);
  387. _lockScrollUpdate = false;
  388. }
  389. private function get scrollerMaxY():Number{
  390. return _bottomLine.y-_scroller.height-(_commandField.visible?5:(master.style.menuFontSize+5));
  391. }
  392. private function onScrollerUp(e:MouseEvent):void{
  393. _scroller.stopDrag();
  394. stage.removeEventListener(MouseEvent.MOUSE_MOVE, onScrollerMove);
  395. stage.removeEventListener(MouseEvent.MOUSE_UP, onScrollerUp);
  396. onTraceScroll();
  397. }
  398. private function onScrollbarDown(e:MouseEvent):void{
  399. if(_scroller.mouseY>0) {
  400. _traceField.scrollV += 3;
  401. _scrolldir = 3;
  402. }
  403. else {
  404. _traceField.scrollV -= 3;
  405. _scrolldir = -3;
  406. }
  407. _scrolldelay = 0;
  408. _scrollbar.addEventListener(Event.ENTER_FRAME, onScrollBarFrame, false, 0, true);
  409. stage.addEventListener(MouseEvent.MOUSE_UP, onScrollBarUp, false, 0, true);
  410. }
  411. private function onScrollBarFrame(e:Event):void{
  412. _scrolldelay++;
  413. if(_scrolldelay>10){
  414. _scrolldelay = 9;
  415. if((_scrolldir<0 && _scroller.y>mouseY)||(_scrolldir>0 && _scroller.y+_scroller.height<mouseY)){
  416. _traceField.scrollV += _scrolldir;
  417. }
  418. }
  419. }
  420. private function onScrollBarUp(e:Event):void{
  421. _scrollbar.removeEventListener(Event.ENTER_FRAME, onScrollBarFrame);
  422. stage.removeEventListener(MouseEvent.MOUSE_UP, onScrollBarUp);
  423. }
  424. override public function set width(n:Number):void{
  425. _lockScrollUpdate = true;
  426. super.width = n;
  427. _traceField.width = n-4;
  428. _menuField.width = n;
  429. _commandField.width = width-15-_commandField.x;
  430. _commandBackground.width = n;
  431. _bottomLine.graphics.clear();
  432. _bottomLine.graphics.lineStyle(1, style.controlColor);
  433. _bottomLine.graphics.moveTo(10, -1);
  434. _bottomLine.graphics.lineTo(n-10, -1);
  435. _scroller.x = n;
  436. _scrollbar.x = n;
  437. onUpdateCommandLineScope();
  438. _atBottom = true;
  439. _needUpdateMenu = true;
  440. _needUpdateTrace = true;
  441. _lockScrollUpdate = false;
  442. }
  443. override public function set height(n:Number):void{
  444. _lockScrollUpdate = true;
  445. super.height = n;
  446. var minimize:Boolean = false;
  447. if(n<(_commandField.visible?42:24)){
  448. minimize = true;
  449. }
  450. if(_isMinimised != minimize){
  451. registerDragger(_menuField, minimize);
  452. registerDragger(_traceField, !minimize);
  453. _isMinimised = minimize;
  454. }
  455. var fsize:int = master.style.menuFontSize;
  456. _menuField.visible = !minimize;
  457. _traceField.y = minimize?0:fsize;
  458. _traceField.height = n-(_commandField.visible?(fsize+4):0)-(minimize?0:fsize);
  459. var cmdy:Number = n-(fsize+6);
  460. _commandField.y = cmdy;
  461. _commandPrefx.y = cmdy;
  462. _commandBackground.y = cmdy;
  463. _bottomLine.y = _commandField.visible?cmdy:n;
  464. //
  465. var sbh:Number = (_bottomLine.y-(_commandField.visible?0:10))-_scrollbar.y;
  466. _scrollbar.graphics.clear();
  467. _scrollbar.graphics.beginFill(style.controlColor, 0.7);
  468. _scrollbar.graphics.drawRect(-5, 0, 5, 5);
  469. _scrollbar.graphics.drawRect(-5, sbh-5, 5, 5);
  470. _scrollbar.graphics.beginFill(style.controlColor, 0.25);
  471. _scrollbar.graphics.drawRect(-5, 5, 5, sbh-10);
  472. _scrollbar.graphics.endFill();
  473. //
  474. _atBottom = true;
  475. _needUpdateTrace = true;
  476. _lockScrollUpdate = false;
  477. }
  478. //
  479. //
  480. //
  481. public function updateMenu(instant:Boolean = false):void{
  482. if(instant){
  483. _updateMenu();
  484. }else{
  485. _needUpdateMenu = true;
  486. }
  487. }
  488. private function _updateMenu():void{
  489. var str:String = "<r><w>";
  490. if(!master.panels.channelsPanel){
  491. str += getChannelsLink(true);
  492. }
  493. str += "<menu>[ <b>";
  494. str += doActive("<a href=\"event:fps\">F</a>", master.fpsMonitor>0);
  495. str += doActive(" <a href=\"event:mm\">M</a>", master.memoryMonitor>0);
  496. if(master.commandLineAllowed){
  497. str += doActive(" <a href=\"event:command\">CL</a>", commandLine);
  498. }
  499. if(!master.remote){
  500. str += doActive(" <a href=\"event:roller\">Ro</a>", master.displayRoller);
  501. str += doActive(" <a href=\"event:ruler\">RL</a>", master.panels.rulerActive);
  502. }
  503. str += " ¦</b>";
  504. for each(var link:String in _extraMenuKeys){
  505. str += " <a href=\"event:"+link+"\">"+link+"</a>";
  506. }
  507. if(_canUseTrace){
  508. str += doActive(" <a href=\"event:trace\">T</a>", master.tracing);
  509. }
  510. str += " <a href=\"event:copy\">Cc</a>";
  511. str += " <a href=\"event:priority\">P"+master.priority+"</a>";
  512. str += doActive(" <a href=\"event:pause\">P</a>", master.paused);
  513. str += " <a href=\"event:clear\">C</a> <a href=\"event:close\">X</a>";
  514. str += " ]</menu> </w></r>";
  515. _menuField.htmlText = str;
  516. _menuField.scrollH = _menuField.maxScrollH;
  517. }
  518. public function getChannelsLink(limited:Boolean = false):String{
  519. var str:String = "<chs>";
  520. var len:int = _channels.length;
  521. if(limited && len>CHANNELS_IN_MENU) len = CHANNELS_IN_MENU;
  522. for(var ci:int = 0; ci<len; ci++){
  523. var channel:String = _channels[ci];
  524. var channelTxt:String = (_viewingChannels.indexOf(channel)>=0) ? "<ch><b>"+channel+"</b></ch>" : channel;
  525. str += "<a href=\"event:channel_"+channel+"\">["+channelTxt+"]</a> ";
  526. }
  527. if(limited){
  528. str += "<ch><a href=\"event:channels\"><b>"+(_channels.length>len?"...":"")+"</b>^^ </a></ch>";
  529. }
  530. str += "</chs> ";
  531. return str;
  532. }
  533. private function doActive(str:String, b:Boolean):String{
  534. if(b) return "<hi>"+str+"</hi>";
  535. return str;
  536. }
  537. public function onMenuRollOver(e:TextEvent, src:AbstractPanel = null):void{
  538. if(src==null) src = this;
  539. var txt:String = e.text?e.text.replace("event:",""):"";
  540. if(topMenuRollOver!=null) {
  541. var t:String = topMenuRollOver(txt);
  542. if(t) {
  543. master.panels.tooltip(t, src);
  544. return;
  545. }
  546. }
  547. if(txt == "channel_"+Console.GLOBAL_CHANNEL){
  548. txt = TOOLTIPS["viewall"];
  549. }else if(txt == "channel_"+Console.DEFAULT_CHANNEL) {
  550. txt = TOOLTIPS["defaultch"];
  551. }else if(txt == "channel_"+ Console.CONSOLE_CHANNEL) {
  552. txt = TOOLTIPS["consolech"];
  553. }else if(txt == "channel_"+ Console.FILTERED_CHANNEL) {
  554. txt = TOOLTIPS["filterch"]+"::*"+master.filterText+"*";
  555. }else if(txt.indexOf("channel_")==0) {
  556. txt = TOOLTIPS["channel"];
  557. }else if(txt == "pause"){
  558. if(master.paused)
  559. txt = TOOLTIPS["resume"];
  560. else
  561. txt = TOOLTIPS["pause"];
  562. }else if(txt == "copy"){
  563. txt = TOOLTIPS["copy"];
  564. }else if(txt == "close" && src == this){
  565. txt = TOOLTIPS["closemain"];
  566. }else{
  567. txt = TOOLTIPS[txt];
  568. }
  569. master.panels.tooltip(txt, src);
  570. }
  571. private function linkHandler(e:TextEvent):void{
  572. _menuField.setSelection(0, 0);
  573. stopDrag();
  574. if(topMenuClick!=null && topMenuClick(e.text)) return;
  575. if(e.text == "pause"){
  576. if(master.paused){
  577. master.paused = false;
  578. master.panels.tooltip(TOOLTIPS["pause"], this);
  579. }else{
  580. master.paused = true;
  581. master.panels.tooltip(TOOLTIPS["resume"], this);
  582. }
  583. }else if(e.text == "trace"){
  584. master.tracing = !master.tracing;
  585. if(master.tracing){
  586. master.report("Tracing turned [<b>On</b>]",-1);
  587. }else{
  588. master.report("Tracing turned [<b>Off</b>]",-1);
  589. }
  590. }else if(e.text == "close"){
  591. master.panels.tooltip();
  592. visible = false;
  593. //dispatchEvent(new Event(AbstractPanel.CLOSED));
  594. }else if(e.text == "channels"){
  595. master.panels.channelsPanel = !master.panels.channelsPanel;
  596. }else if(e.text == "fps"){
  597. master.fpsMonitor = !master.fpsMonitor;
  598. }else if(e.text == "priority"){
  599. if(master.priority<10){
  600. master.priority++;
  601. }else{
  602. master.priority = 0;
  603. }
  604. }else if(e.text == "mm"){
  605. master.memoryMonitor = !master.memoryMonitor;
  606. }else if(e.text == "roller"){
  607. master.displayRoller = !master.displayRoller;
  608. }else if(e.text == "ruler"){
  609. master.panels.tooltip();
  610. master.panels.startRuler();
  611. }else if(e.text == "command"){
  612. commandLine = !commandLine;
  613. }else if(e.text == "copy") {
  614. System.setClipboard(master.getAllLog());
  615. master.report("Copied log to clipboard.", -1);
  616. }else if(e.text == "clear"){
  617. master.clear();
  618. }else if(e.text == "settings"){
  619. master.report("A new window should open in browser. If not, try searching for 'Flash Player Global Security Settings panel' online :)", -1);
  620. Security.showSettings(SecurityPanel.SETTINGS_MANAGER);
  621. }else if(e.text.substring(0,8) == "channel_"){
  622. onChannelPressed(e.text.substring(8));
  623. }else if(e.text.substring(0,5) == "clip_"){
  624. var str:String = "/remap "+e.text.substring(5);
  625. master.runCommand(str);
  626. }else if(e.text.substring(0,6) == "sclip_"){
  627. //var str:String = "/remap 0|"+e.text.substring(6);
  628. master.runCommand("/remap 0"+Console.MAPPING_SPLITTER+e.text.substring(6));
  629. //master.cl.reMap(e.text.substring(6), stage);
  630. }
  631. _menuField.setSelection(0, 0);
  632. e.stopPropagation();
  633. }
  634. public function onChannelPressed(chn:String):void{
  635. var current:Array = _viewingChannels.concat();
  636. if(_shift && _viewingChannels[0] != Console.GLOBAL_CHANNEL && chn != Console.GLOBAL_CHANNEL){
  637. var ind:int = current.indexOf(chn);
  638. if(ind>=0){
  639. current.splice(ind,1);
  640. if(current.length == 0){
  641. current.push(Console.GLOBAL_CHANNEL);
  642. }
  643. }else{
  644. current.push(chn);
  645. }
  646. master.viewingChannels = current;
  647. }else{
  648. master.viewingChannels = [chn];
  649. }
  650. }
  651. //
  652. // COMMAND LINE
  653. //
  654. private function commandKeyDown(e:KeyboardEvent):void{
  655. e.stopPropagation();
  656. }
  657. private function commandKeyUp(e:KeyboardEvent):void{
  658. if( e.keyCode == Keyboard.ENTER){
  659. if(_enteringLogin){
  660. dispatchEvent(new Event(Event.CONNECT));
  661. _commandField.text = "";
  662. requestLogin(false);
  663. }else{
  664. var txt:String = _commandField.text;
  665. master.runCommand(txt);
  666. var i:int = _commandsHistory.indexOf(txt);
  667. while(i>=0){
  668. _commandsHistory.splice(i,1);
  669. i = _commandsHistory.indexOf(txt);
  670. }
  671. _commandsHistory.unshift(txt);
  672. _commandsInd = -1;
  673. _commandField.text = "";
  674. // maximum 20 commands history
  675. if(_commandsHistory.length>20){
  676. _commandsHistory.splice(20);
  677. }
  678. master.ud.commandLineHistoryChanged();
  679. }
  680. }if( e.keyCode == Keyboard.ESCAPE){
  681. if(stage) stage.focus = null;
  682. }else if( e.keyCode == Keyboard.UP){
  683. // if its back key for first time, store the current key
  684. if(_commandField.text && _commandsInd<0){
  685. _commandsHistory.unshift(_commandField.text);
  686. _commandsInd++;
  687. }
  688. if(_commandsInd<(_commandsHistory.length-1)){
  689. _commandsInd++;
  690. _commandField.text = _commandsHistory[_commandsInd];
  691. _commandField.setSelection(_commandField.text.length, _commandField.text.length);
  692. }else{
  693. _commandsInd = _commandsHistory.length;
  694. _commandField.text = "";
  695. }
  696. }else if( e.keyCode == Keyboard.DOWN){
  697. if(_commandsInd>0){
  698. _commandsInd--;
  699. _commandField.text = _commandsHistory[_commandsInd];
  700. _commandField.setSelection(_commandField.text.length, _commandField.text.length);
  701. }else{
  702. _commandsInd = -1;
  703. _commandField.text = "";
  704. }
  705. }
  706. e.stopPropagation();
  707. }
  708. private function onUpdateCommandLineScope(e:Event=null):void{
  709. if(!master.remote) updateCLScope(master.cl.scopeString);
  710. }
  711. public function get commandLineText():String{
  712. return _commandField.text;
  713. }
  714. public function updateCLScope(str:String):void{
  715. if(_enteringLogin) {
  716. _enteringLogin = false;
  717. requestLogin(false);
  718. }
  719. _commandPrefx.autoSize = TextFieldAutoSize.LEFT;
  720. _commandPrefx.text = str;
  721. var w:Number = width-48;
  722. if(_commandPrefx.width > 120 || _commandPrefx.width > w){
  723. _commandPrefx.autoSize = TextFieldAutoSize.NONE;
  724. _commandPrefx.width = w>120?120:w;
  725. _commandPrefx.scrollH = _commandPrefx.maxScrollH;
  726. }
  727. _commandField.x = _commandPrefx.width+2;
  728. _commandField.width = width-15-_commandField.x;
  729. }
  730. public function set commandLine (b:Boolean):void{
  731. if(b && master.commandLineAllowed>0){
  732. _commandField.visible = true;
  733. _commandPrefx.visible = true;
  734. _commandBackground.visible = true;
  735. }else{
  736. _commandField.visible = false;
  737. _commandPrefx.visible = false;
  738. _commandBackground.visible = false;
  739. }
  740. this.height = height;
  741. }
  742. public function get commandLine ():Boolean{
  743. return _commandField.visible;
  744. }
  745. }
  746. }