📄 main.js
字号:
] }) ] }) ] }) ] }); }, _apply: function(e) { DemoApp.pref.windowStyleName = this._windowStyleNameSelect.get("selectedId") == "None" ? null : this._windowStyleNameSelect.get("selectedId"); DemoApp.pref.transitionsEnabled = this._transitionsEnabled.get("selected"); DemoApp.pref.sourceViewerBackground = this._sourceViewerBackground.color; DemoApp.pref.sourceViewerForeground = this._sourceViewerForeground.color; this.parent.remove(this); }, _close: function(e) { this.parent.remove(this); }});DemoApp.SourcePane = Core.extend(EchoApp.ContentPane, { _msg: null, $construct: function(data) { this._msg = DemoApp.Messages.get(null); EchoApp.ContentPane.call(this, data); var url = this.render("url"); if (url) { var conn = new WebCore.HttpConnection(url, "GET"); conn.addResponseListener(Core.method(this, this._responseListener)); try { conn.connect(); } catch (ex) { this.add(new EchoApp.Label({ text: this._msg["SourcePane.XHRError"] })); } } }, _responseListener: function(e) { this.add(new DemoApp.SourceView({ code: e.source.getResponseText() })); }});/** * SourceView component. Displays formatted source code. * Optionally supports settings syntax colors for * C-style comments. */DemoApp.SourceView = Core.extend(EchoApp.Component, { componentType: "DemoApp.SourceView"});/** * SourceView synchronization peer. */DemoApp.SourceViewSync = Core.extend(EchoRender.ComponentSync, { $load: function() { EchoRender.registerPeer("DemoApp.SourceView", this); }, renderAdd: function(update, parentElement) { var code = this.component.render("code", ""); var lines = code.split("\n"); var inBlockComment = false; this._divElement = document.createElement("div"); this._divElement.style.padding = "2px 1ex 2px 9ex"; for (var i = 0; i < lines.length; ++i) { var line = lines[i]; var trimmedLine = DemoApp.Util.trim(line); if (DemoApp.Util._BLOCK_COMMENT_START.test(trimmedLine)) { inBlockComment = true; } if (DemoApp.Util.BLANK_LINE.test(line)) { var blankDiv = document.createElement("div"); blankDiv.style.height = "1em"; this._divElement.appendChild(blankDiv); continue; } var lineDiv = document.createElement("div"); if (DemoApp.Util._LINE_COMMENT.test(trimmedLine)) { EchoAppRender.Color.render(this.component.render("lineCommentColor"), lineDiv, "color"); } else if (inBlockComment) { EchoAppRender.Color.render(this.component.render("blockCommentColor"), lineDiv, "color"); } lineDiv.style.paddingLeft = DemoApp.Util.countLeadingSpaces(line) + "ex"; lineDiv.style.textIndent = "-8ex"; lineDiv.appendChild(document.createTextNode(trimmedLine)); this._divElement.appendChild(lineDiv); if (DemoApp.Util._BLOCK_COMMENT_END.test(trimmedLine)) { inBlockComment = false; } } parentElement.appendChild(this._divElement); }, renderDispose: function(update) { this._divElement = null; }, renderUpdate: function(update) { var element = this._divElement; var containerElement = element.parentNode; this.renderDispose(update); containerElement.removeChild(element); this.renderAdd(update, containerElement); return false; // Child elements not supported: safe to return false. }});/** * Source code viewing window. * Retrieves arbitrary source code from URL. */DemoApp.SourceWindow = Core.extend(EchoApp.WindowPane, { _msg: null, $construct: function(screen) { this._msg = DemoApp.Messages.get(null); var title, icon, url; if (screen instanceof DemoApp.Workspace.ScreenData) { title = screen.title; icon = screen.icon16; url = screen.sourceUrl; } else { title = screen; icon = null; url = screen; } EchoApp.WindowPane.call(this, { icon: icon, iconInsets: "6px 10px", title: this._msg["SourceWindow.TitlePrompt"] + " \"" + title + "\"", styleName: DemoApp.pref.windowStyleName, width: 600, height: 500, events: { close: function(e) { e.source.parent.remove(e.source); } }, children: [ new DemoApp.SourcePane({ background: DemoApp.pref.sourceViewerBackground, foreground: DemoApp.pref.sourceViewerForeground, font: { typeface: ["Courier New", "courier", "monospace"] }, url: url }) ] }); }});/** * Utility methods. */DemoApp.Util = { _LEADING_SPACES: /^(\s*)/, _TRAILING_SPACES: /(\s*)$/, _BLOCK_COMMENT_START: /^\/\*/, _BLOCK_COMMENT_END: /\*\//, _LINE_COMMENT: /^\/\//, BLANK_LINE: /^\s*$/, /** * Determiens the number of leading spaces in a string. * * @param s the string to evaluate * @return the number of leading spaces * @type Number */ countLeadingSpaces: function(s) { return this._LEADING_SPACES.exec(s)[1].length; }, /** * Determiens the number of trailing spaces in a string. * * @param s the string to evaluate * @return the number of trailing spaces * @type Number */ countTrailingSpaces: function(s) { return this._TRAILING_SPACES.exec(s)[1].length; }, /** * Returns a random item from an array. * * @param array the array to evaluate * @return a random item */ randomItem: function(array) { return array[Math.floor(Math.random() * array.length)]; }, /** * Trims leading and trailing spaces from a string. * * @param s the string to evaluate * @return the string with no leading/trailing spaces */ trim: function(s) { var leading = this._LEADING_SPACES.exec(s)[1].length; var trailing = this._TRAILING_SPACES.exec(s)[1].length; return s.substring(leading); }};/** * Workspace component: the primary user interface of the demo application. */ DemoApp.Workspace = Core.extend(EchoApp.ContentPane, { $static: { /** * Data object representing a section (collection of demo screens). */ SectionData: Core.extend({ $construct: function(title, screens) { this.title = title; this.screens = screens; } }), /** * Data object representing a launchable demo screen. */ ScreenData: Core.extend({ $construct: function(title, icon16, icon64, launchFunction, sourceUrl) { this.id = EchoApp.generateUid(); this.title = title; this.icon16 = icon16; this.icon64 = icon64; this.launchFunction = launchFunction; this.sourceUrl = sourceUrl; } }) }, _launchPanel: null, _contentArea: null, _menu: null, _screenMap: null, _activeScreen: null, _sections: null, _activeScreenLaunchButton: null, _stopWindow: null, fpsLabel: null, $construct: function(sections) { this._sections = sections; this._msg = DemoApp.Messages.get(null); EchoApp.ContentPane.call(this, { children: [ new EchoApp.SplitPane({ separatorWidth: 6, separatorPosition: 170, resizable: true, separatorHorizontalImage: "image/MainSeparator.png", children: [ new EchoApp.SplitPane({ orientation: EchoApp.SplitPane.ORIENTATION_VERTICAL_TOP_BOTTOM, separatorPosition: 52, layoutData: { minimumSize: 150, maximumSize: 300 }, children: [ new EchoApp.Label({ icon: "image/Logo.png", layoutData: { overflow: EchoApp.SplitPane.OVERFLOW_HIDDEN, alignment: "center", backgroundImage: { url: "image/LogoBackground.png", repeat: "repeat-x" } } }), this._launchPanel = new ExtrasApp.AccordionPane({ styleName: "Default", background: "#313131", foreground: "#ffffff", defaultContentInsets: "5px 10px" }) ] }), new EchoApp.SplitPane({ orientation: EchoApp.SplitPane.ORIENTATION_VERTICAL_TOP_BOTTOM, separatorPosition: 26, separatorHeight: 1, separatorColor: "#000000", children: [ this._menu = new ExtrasApp.MenuBarPane({ styleName: "Default", events: { action: Core.method(this, this._processMenuAction) }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -