^1439975647467
@
sname
shell
stext
CodeEditor
sNO_TRIM
false
sCLOSE
true
sTITLE
true
sMIN
true
sMAX
true
sBORDER
false
sRESIZE
true
sON_TOP
false
sTOOL
false
sNO_FOCUS
false
swidth
640
sheight
480
scenterScreen
true
spack
false
smaximized
false
sfullScreen
false
sH_SCROLL
false
sV_SCROLL
false
sNO_BACKGROUND
false
sNO_MERGE_PAINTS
false
sNO_REDRAW_RESIZE
false
sNO_RADIO_GROUP
false
sEMBEDDED
false
sDOUBLE_BUFFERED
false
slabel
CodeEditor
scapture
false
senabled
true
sredraw
true
svisible
true
sxw_cl_global
false
sdescriptors
xworker.swt.widgets.Shell
sinheritDescription
false
sth_createIndex
false
sth_registMyChilds
false
sth_registDisabled
false
sth_mark
false
@/@shellFillLayout
sname
shellFillLayout
stype
SWT.HORIZONTAL
sxw_cl_global
false
sdescriptors
xworker.swt.Layouts/@FillLayout
sinheritDescription
false
sth_createIndex
false
sth_registMyChilds
false
sth_registDisabled
false
sth_mark
false
@/@group
sname
group
stext
CodeEditor
sstyle
SHADOW_ETCHED_IN
sBORDER
false
sH_SCROLL
false
sV_SCROLL
false
sNO_BACKGROUND
false
sNO_FOCUS
false
sNO_MERGE_PAINTS
false
sNO_REDRAW_RESIZE
false
sNO_RADIO_GROUP
false
sEMBEDDED
false
sDOUBLE_BUFFERED
false
slabel
CodeEditor
scapture
false
senabled
true
sredraw
true
svisible
true
sxw_cl_global
false
sdescriptors
xworker.swt.Widgets/@Group
sinheritDescription
false
sth_createIndex
false
sth_registMyChilds
false
sth_registDisabled
false
sth_mark
false
@/@group/@groupFillLayout
sname
groupFillLayout
stype
SWT.HORIZONTAL
sxw_cl_global
false
sdescriptors
xworker.swt.Layouts/@FillLayout
sinheritDescription
false
sth_createIndex
false
sth_registMyChilds
false
sth_registDisabled
false
sth_mark
false
@/@group/@codeEditor
sname
codeEditor
scodeName
java
scodeType
java
sWRAP
false
Scode
#$@text#$@
/*******************************************************************************
* Copyright 2007-2013 See AUTHORS file.
 * 
* 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.
******************************************************************************/
package xworker.swt.xworker;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import org.xmeta.World;

import xworker.swt.design.Designer;
import xworker.swt.events.SwtListener;
import xworker.swt.form.TextEditor;

public class CodeEditorCreator {
    public static Object create(ActionContext actionContext){
    	World world = World.getInstance();
    	Thing self = (Thing) actionContext.get("self");
    	Composite parent = (Composite) actionContext.get("parent");
    	
		ActionContext newContext = new ActionContext();
		newContext.put("parent", parent);
		newContext.put("codeName", self.getString("codeName"));
		newContext.put("codeType", self.getString("codeType"));
		newContext.put("parentContext", actionContext);
		
		Thing codeEditor = world.getThing("xworker.swt.xworker.CodeEditor/@editorViewForm");
		codeEditor.doAction("create", newContext);
		
		StyledText textEditor = (StyledText) newContext.get("editInput");
		if("true".equals(self.getString("WRAP"))){
		    textEditor.setWordWrap(true);
		}
		
		actionContext.getScope(0).put(self.getString("name"), textEditor);
		
		try{
			//代码着色
			Colorer.attach(textEditor, self.getString("codeName"), self.getString("codeType"));
		}catch(Throwable t){			
		}
		
		if(self.getStringBlankAsNull("code") != null){
			textEditor.setText(self.getString("code"));
		}
		//设置redoundo和其他
		TextEditor.attach(textEditor);
		textEditor.setData("lineLabel", newContext.get("editorLineLabel"));
		
		//创建子节点
		actionContext.peek().put("parent", newContext.get("editorViewForm"));
		for(Thing child : self.getAllChilds()){
		    child.doAction("create", actionContext);
		}
		actionContext.peek().remove("parent");
		//log.info("newContext.editorViewForm=" + newContext.editorViewForm.getLayoutData());
		
		Designer.attach(textEditor, self.getMetadata().getPath(), actionContext);
		
		return textEditor;        
	}

    public static void textKeyDown(ActionContext actionContext){
    	Event event = (Event) actionContext.get("event");
    	
    	StyledText text = (StyledText) event.widget;

    	int line =  text.getLineAtOffset(text.getCaretOffset()) + 1;
    	int carOffset = text.getCaretOffset();
    	int lineOffset = text.getOffsetAtLine(line - 1);

    	((Label) text.getData("lineLabel")).setText("" + line + ":" + (carOffset - lineOffset + 1));
    	((Label) text.getData("lineLabel")).update();

    	if(event.keyCode == 's' && event.stateMask == SWT.CTRL){
    		SwtListener okButtonSelection = (SwtListener) actionContext.get("okButtonSelection");
    	    if(okButtonSelection != null){
    	         okButtonSelection.handleEvent(null);
    	    }
    	}
    }
    
    public static void textMouseUp(ActionContext actionContext){
    	
    }
    
    public static void toolItemSelecitonScript(ActionContext actionContext){
    	World world = World.getInstance();
    	
        //取ViewForm数据对象的定义，要编辑的数据对象放置在ViewForm的数据对象中
    	StyledText textEditor = (StyledText) actionContext.get("editInput");

    	ActionContext newContext = new ActionContext();
    	newContext.put("parent", textEditor.getShell());
    	newContext.put("fileType", textEditor.getData("fileType"));
    	newContext.put("parentText", textEditor);
    	newContext.put("saveButtonSelection", actionContext.get("okButtonSelection"));

    	Thing shellObject = world.getThing("xworker.swt.xworker.CodeEditorPop/@shell");
    	shellObject.doAction("create", newContext);

    	StyledText newtextEditor = (StyledText) newContext.get("textEditor");
    	if(textEditor.getWordWrap()){
    		newtextEditor.setWordWrap(true);
    	}
    	newtextEditor.setText(textEditor.getText());
    	newtextEditor.setData("oldText", textEditor);

    	newtextEditor.setTopIndex(textEditor.getTopIndex());
    	newtextEditor.setCaretOffset(textEditor.getCaretOffset());

    	//CodeEditorSyncer.attach(textEditor, newContext.textEditor);
    	//CodeEditorSyncer.attach(newContext.textEditor, textEditor);

    	((Shell) newContext.get("shell")).open();
    }
    
    public static void contentTextKeyDown(ActionContext actionContext){
    	Event event = (Event) actionContext.get("event");

    	StyledText text = (StyledText) event.widget;

    	int line = text.getLineAtOffset(text.getCaretOffset()) + 1;
    	int carOffset = text.getCaretOffset();
    	int lineOffset = text.getOffsetAtLine(line - 1);

    	((Label) text.getData("lineLabel")).setText("" + line + ":" + (carOffset - lineOffset + 1));
    	((Label) text.getData("lineLabel")).update();

    	if(event.keyCode == 's' && event.stateMask == SWT.CTRL){
    		SwtListener okButtonSelection = (SwtListener) actionContext.get("okButtonSelection");
    	    if(okButtonSelection != null){
    	        okButtonSelection.handleEvent(null);
    	    }
    	}
    }
}
#$@text#$@
sxw_cl_global
false
sdescriptors
xworker.swt.Widgets/@CodeEditor
sinheritDescription
false
sth_createIndex
false
sth_registMyChilds
false
sth_registDisabled
false
sth_mark
false
