📄 workbench.js
字号:
/*
* Copyright 2001-2007 Hippo (www.hippo.nl)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Workbench class
*/
function Workbench() {
if(!Cfx.Class.IsDefined(Workbench)) {
Cfx.Class.New(Workbench, baseComponent);
if(Cfx.Class.IsInitializing(Workbench)) {
Workbench.Method(init);
Workbench.Method(initialized);
Workbench.Method(showMenu);//deprecated
Workbench.Method(setFocus);
Workbench.Method(loadInitialTab);
Workbench.Method(reloadActivePerspective);
Workbench.Method(reloadPerspectives);
//events
Workbench.Method(viewSource);
Workbench.Method(editDocument);
Workbench.Method(newImageSet);
Workbench.Method(editImageSet);
Workbench.Method(editDocumentForbidden);
Workbench.Method(previewSource);
Workbench.Method(assetviewResource);
Workbench.Method(selectSource);
Workbench.Method(assetselectSource);
Workbench.Method(doSelectSource);
Workbench.Method(refreshPerspective);
Workbench.Method(refreshActiveView);
Workbench.Method(imagesetnewDocument);
Workbench.Method(handleInputEvent);
Workbench.Method(doSearch);
Workbench.Method(showUserMessage);
Workbench.Method(showBreadcrumb);
Workbench.Method(closeDocument);
Workbench.Method(closeXopus);
return;
}
}
// Setup instance data.
this.InitInstance();
this.initialTabId = null;
// Return instance.
return this;
//////////////////////////////////////////////////////////////////////////
// Class methods definitions
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// init( )
//////////////////////////////////////////////////////////////////////////
function init() {
if(this.log.debugging()) {
this.log.debug("Initializing workbench");
}
try {
//listenen to events
this.sm.lookup("framework.eventmanager").addEventListener(this);
try{
this.perspectiveManager = this.sm.lookup("framework.componentFactory").createComponent(this.config.perspectives, this.log, this.context, this.sm);
}catch(ex) {
//let parent components handle error
throw new Error("workbench.init() -> creating child components. \n" + ex)
}
this.perspectiveManager.init();
this.globalKeyBoardHandler = new InputEventHandler(this);
} catch (ex) {
throw ex;
}
}
function handleInputEvent(event){
var code;
if (!event)
event = window.top.event;
if(event.keyCode)
code = event.keyCode;
else if(event.which)
code = event.which;
var pressedChar = String.fromCharCode(code);
var pm = this.perspectiveManager;
var isNumber = (new String(pressedChar).match(/[0-9]/)) != null;
if (event.altKey && isNumber && pressedChar <= pm.perspectives.length){
var ps = pm.perspectives[parseInt(pressedChar) - 1];
if (typeof ps != 'undefined')
this.showMenu(ps.getId());
Event.stop(event);
};
};
function initialized(){
var _res = this.perspectiveManager.initialized();
return _res;
}
function showMenu() {
var id = arguments[0];
var ps = this.perspectiveManager.perspectives;
for(var i = 0 ; i < ps.length; i++) {
var localId = ps[i].getId();
if (id == localId) {
if (this.log.debugging()) {
this.log.debug("showMenu: " + id + "==" + localId);
}
document.getElementById(localId).className = "selected_tab_td";
document.getElementById(localId + "_tab_top").className = "selected_tab_top";
if (this.log.debugging()) {
this.log.debug("showPerspective: " + localId);
}
this.perspectiveManager.showPerspective(localId);
this.showBreadcrumb();
}
else {
document.getElementById(localId).className = "";
document.getElementById(localId + "_tab_top").className = "tab_top_empty";
}
}
}
function editDocument(params)
{
if (params[0].val)
{
this.showMenu('editing');
}
}
function doSearch(params)
{
this.showMenu('searchEngine');
}
function newImageSet(params) {
this.showMenu('editing');
}
function editImageSet(params) {
this.showMenu('editing');
}
function imagesetnewDocument(params) {
this.showMenu('imageset');
}
function editDocumentForbidden(params) {
if (this.perspectiveManager.activePerspective != "search")
{
this.showMenu('search');
alert(params[1].val);
}
}
function selectSource(params) {
this.doSelectSource(params, "documents", "selectSource");
}
function assetselectSource(params) {
this.doSelectSource(params, "assets", "assetselectSource");
}
function doSelectSource(params, perspective, event)
{
var ps = this.perspectiveManager.perspectives;
var i = 0;
while (i < ps.length && ps[i].getId() != perspective)
{
this.log.debug(i + ": " + ps[i].getId());
i++;
}
var shown = true;
if (ps[i].getId() == perspective)
{
shown = ps[i].shown;
}
this.showMenu(perspective);
if (!shown)
{
var urlLocation;
for(ii=0; ii<params.length;ii++)
{
if(params[ii].key=='url')
{
urlLocation = ii;
}
}
if(params[urlLocation].key=='url')
{
var tmpPathArray = params[urlLocation].val.split("/");
var perspectivePath = '/' + tmpPathArray[1];
//alert(perspectivePath);
var p = "[{key:'url',val:'"+params[urlLocation].val+"'},{key:'refresh',val:'"+perspectivePath+"'}]";
window.setTimeout("window.top.window.frames['topframe'].workbench.perspectiveManager.perspectives["+i+"]."+event+"("+p+")", 2000);
}
}
}
function previewSource(params) {
var w = 800;
var h = 600;
var i;
var urlLocation = -1;
for(i=0; i<params.length;i++)
{
if(params[i].key=='previewUrl')
{
urlLocation = i;
}
}
if (urlLocation >= 0){
var url = params[urlLocation].val;
//var url = this.context.get("previewUrl") + params[2].val;
var name = 'previewWindow';
var options = 'scrollbars=yes,toolbar=yes,location=yes,resizable=yes';
var previewWin = window.open(url, name,'width='+w+',height='+h+','+options);
previewWin.focus();
}
}
function assetviewResource(params) {
var w = 800;
var h = 600;
var url = '/skins/images/empty.gif';
var name = 'previewWindow';
var options = 'scrollbars=yes,toolbar=yes,location=yes,resizable=yes';
var previewWin = window.open(url, name,'width='+w+',height='+h+','+options);
previewWin.focus();
previewWin.location.href='/assetspreview' + params[2].val;
}
function viewSource(params) {
this.showMenu('source');
}
function refreshPerspective() {
if(this.perspectiveManager.activePerspective) {
var ps = this.perspectiveManager.perspectives;
ps[this.perspectiveManager.activePerspective].refresh();
}
}
function refreshActiveView(params) {
if(this.perspectiveManager.activePerspective) {
var ps = this.perspectiveManager.perspectives;
ps[this.perspectiveManager.activePerspective].refreshView(params[0].val);
}
}
function showUserMessage(params){
if(params.length>0)
alert(params);
}
function showBreadcrumb(){
var ps = this.perspectiveManager.perspectives;
// fetch breadcrumb from active perspective / active view(s)
var arr=ps[this.perspectiveManager.activePerspective].getBreadcrumb();
var i;
var breadcrumbContainer = document.getElementById("top_breadcrumb");
breadcrumbContainer.innerHTML = '';
for (i=0; i<arr.length; i++)
breadcrumbContainer.innerHTML+=' > '+ arr[i];
}
function setFocus(params) {
if(this.initialized()) {
this.showMenu(params[0].val);
}
}
function loadInitialTab() {
if(!Cfx.Js.IsEmpty(this.initialTab)) {
this.setFocus({'val': this.initialTab});
} else {
this.setFocus([{'val': this.perspectiveManager.perspectives[0].getId()}]);
}
}
function reloadActivePerspective() {
this.perspectiveManager.getActivePerspective().refresh();
}
function reloadPerspectives(params) {
for(var i=0; i<params.length; i++) {
this.perspectiveManager.getPerspectiveById(params[i]).refresh();
}
}
function closeDocument(params)
{
window.top.removeCaptionFromWindowTitle();
}
function closeXopus(params)
{
window.top.removeCaptionFromWindowTitle();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -