📄 sdk_explorer_logic.js
字号:
_storedLeft:windowPos.left, _storedTop:windowPos.top, title:node.title, visibility:"hidden", headerIconProperties:{src:node.windowIconSrc || node.iconSrc}, items:iconRows, icons:iconRows // so we can hide icons and show an alternate presentation (eg tree) }); isc.SimpleWindowManager.addWindow(newWindow, node.predraw); // see below return newWindow;} // end makeWindowsFromTree()//===================================================================// PROCESS RESOURCE TREE// When running in clientOnly mode, set enabled:false on nodes that// needServer. The TreeGrid and Menu views of this tree will disable// the nodes (appearance and interactivity) accordingly.// Also set the icon property for use in these views.//===================================================================// assumes we start with a root node that cannot be disabledfunction processResourceTree (tree, node) { var children = tree.getChildren(node), numChildren = children.length; for (var i=0; i<numChildren; i++) { var childNode = children[i]; if (childNode.needServer && isc.clientOnly) childNode.enabled = false; if (!isc.hasOptionalModules(childNode.requiresModules)) childNode.enabled = false; childNode.icon = childNode.windowIconSrc || childNode.iconSrc; if (tree.isFolder(childNode)) processResourceTree(tree,childNode); }}//===================================================================// WINDOW STATE GETTER/SETTER//===================================================================isc.ClassFactory.defineClass("SDKWindow", Window);isc.SDKWindow.addMethods({ getSaveState : function () { var visible = this.isDrawn() && this.isVisible(); return { ID:this.getID(), v:visible, // save off stored coordinates instead if hidden, since hidden windows are moved to // 0,0 l:visible ? this.getLeft() : this._storedLeft || 0, t:visible ? this.getTop() : this._storedTop || 0, z:this.getZIndex(), m:this.minimized } }, setSaveState : function (saveState) { // mark window with stored coordinates to use when it is opened this._storedLeft = saveState.l; this._storedTop = saveState.t; if (saveState.v) { // visible this.moveTo(saveState.l,saveState.t); this.showingDelayed = true; this.delayCall("show"); } else { this.hide(); } if (saveState.m) { // minimized if (this.isDrawn() && !this.minimized) this.minimize(); } else { if (this.isDrawn() && this.minimized==true) this.restore(); } }});//===================================================================// SIMPLE WINDOW MANAGER//===================================================================// Define a simple window manager that keeps track of all windows in this application// and allows us to easily:// - open/close all windows// - save/restore all window states// Exercises for the curious reader:// - arrange, tile, cascade// - open just one window// - close all but one window// - lazy creation of windows, with save & restore supportisc.ClassFactory.defineClass("SimpleWindowManager");isc.SimpleWindowManager.addClassProperties({ allWindows:[], predrawWinList:[], predrawWinNum:0});isc.SimpleWindowManager.addClassMethods({ addWindow : function (windowRef, predraw) { this.allWindows[this.allWindows.length] = windowRef; if (predraw) { this.predrawWinList[this.predrawWinList.length] = windowRef; } }, predrawWindows : function () { var predrawCount = this.predrawWinList.length; if (predrawCount == 0) return; this.predrawWinNum = predrawCount - 1; this.queuePredraws(); }, queuePredraws : function () { if (!this.showingDelayed) this.delayCall("predrawWindow"); }, predrawWindow : function () { // don't start a predraw in the middle of an animation if (isc.Animation.isActive()) return this.queuePredraws(); var win = this.predrawWinList[this.predrawWinNum]; if (!win.isDrawn()) win.draw(); if (this.predrawWinNum > 0) { this.predrawWinNum--; this.queuePredraws(); } }, openAllWindows : function () { for (var i=0; i < this.allWindows.length; i++) this.allWindows[i].show(); }, closeAllWindows : function () { for (var i=0; i < this.allWindows.length; i++) this.allWindows[i].hide(); }, // TODO: breadth-first traversal of source tree to get the best cascade order // (currently mixed up due to depth-first recursive generation of windows) cascadeAllWindows : function () { var nextLeft = 50, nextTop = 70; // first cascade and layer all visible windows (reverse due to generator recursion) for (var i=this.allWindows.length; i > 0; i--) { var currWindow = this.allWindows[i-1]; if (currWindow.isVisible()) { currWindow.moveTo(nextLeft, nextTop); currWindow.bringToFront(); nextLeft += 30; nextTop += 45; } } // then cascade all hidden windows for (var i=this.allWindows.length; i > 0; i--) { var currWindow = this.allWindows[i-1]; if (!currWindow.isVisible()) { currWindow.moveTo(nextLeft, nextTop); nextLeft += 30; nextTop += 45; } } }, getAllWindowStates : function () { var saveStates = []; for (var i=0; i < this.allWindows.length; i++) { saveStates[i] = this.allWindows[i].getSaveState(); } // sort by layer now, so windows will be recreated in this order saveStates.sortByProperty("z", Array.ASCENDING); return isc.Comm.serialize(saveStates); }, setAllWindowStates : function (stateString) { if (!stateString) return null; var fn = new Function("return " + stateString); var savedStates = fn(); for (var i=0; i < savedStates.length; i++) { var thisWin = window[savedStates[i].ID]; if (thisWin) thisWin.setSaveState(savedStates[i]); } }});//===================================================================// WINDOW CONTROL EXTENSIONS//===================================================================// Repurpose the maximize button to switch between tree and window views.// This button is enabled only on the topmost window.isc.SDKWindow.changeDefaults("restoreButtonDefaults", { src:"[SKIN]/Window/maximize.png"})isc.SDKWindow.addProperties({ maximizeButtonDefaults:{ width:18, height:18, layoutAlign:"center", showRollOver:true, src:"[SKIN]/Window/tree.png", click:"this.creator.showTreeView();return false" }, windowViewButtonDefaults:{ width:18, height:18, showRollOver:true, src:"[SKIN]/Window/restore.png", click:"this.creator.showWindowView();return false" }, showTreeView: function () { this.maximizeButton.addProperties(this.windowViewButtonDefaults); this.maximizeButton.redraw(); viewInTree(); }, showWindowView: function () { this.maximizeButton.addProperties(this.maximizeButtonDefaults); this.maximizeButton.redraw(); viewInWindows(); }})//===================================================================// WINDOW ANIMATION//===================================================================isc.Wireframe = isc.Canvas.create({ ID:"isc_wireframe", border:"2px solid #8289A6", autoDraw:false})isc.SDKWindow.addProperties({ animateOpenDuration:300, animateClosedDuration:200, animateMinimize:true, animateMinimizeTime:1000})isc.SDKWindow.addMethods({ // Window.js FIXME - was overriding hide here, but window calls hide twice // (will still want to override closeClick, since hide is called when restoring window states) closeClick : function () { this.hide(); var fromRect = this.getPageRect(); // store coordinates, and keep windows at 0,0 until re-opened this._storedLeft = this.getLeft(); this._storedTop = this.getTop(); this.moveTo(0,0); this.animateClosed(this.openFromIcon._iconImage.getPageRect(), fromRect); }, animateClosed: function (toRect, fromRect, duration) { // initialize the wireframe to the current window rect isc.Wireframe.setRect(fromRect); isc.Wireframe.show(); isc.Wireframe.bringToFront(); // animate the wireframe to the specified rect isc.Wireframe.animateRect( toRect[0], toRect[1], toRect[2], toRect[3], // TODO move this to a function that also calls an animateClosedDone handler // (which is where the icon setSrc should go) "isc.Wireframe.hide();" + this.openFromIcon._iconImage.getID() + ".setSrc('"+this.openFromIcon.iconSrc+"');", duration || this.animateClosedDuration ); }, animateOpen: function (fromRect, toRect, duration) { var win = this, toLeft, toTop, toWidth, toHeight; if (toRect) { // destination rect was passed to this function toLeft = toRect[0]; toTop = toRect[1]; toWidth = toRect[2]; toHeight = toRect[3]; } else { // destination rect is the rect of the window // grab stored coordinates if any toLeft = this._storedLeft || this.getLeft(); toTop = this._storedTop || this.getTop(); if (!this.isDrawn()) { // draw offscreen to determine width and height this.moveTo(-10000,-10000); this.show(); } toWidth = this.getVisibleWidth(); toHeight = this.getVisibleHeight(); } // initialize the wireframe at fromRect isc.Wireframe.setRect(fromRect); isc.Wireframe.show(); isc.Wireframe.bringToFront(); // animate the wireframe to the final position/size of the window isc.Wireframe.animateRect( toLeft, toTop, toWidth, toHeight, // then hide wireframe and show window // TODO move this code to a function that also calls an animateOpenDone handler function () { isc.Wireframe.hide(); win.moveTo(toLeft,toTop); win.delayCall("show"); }, duration || this.animateOpenDuration ); }})
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -