PDA

View Full Version : [OPEN] [CLOSED] [2.0 M2] HtmlEditor key events



Night Shadow
31 May 2009, 8:47 PM
Hi! I need to handle Enter and Ctrl+Enter events in HtmlEditor, but their not fire.



import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.KeyListener;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.form.HtmlEditor;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class Index implements EntryPoint {

/**
* This is the entry point method.
*/
public void onModuleLoad() {
RootPanel.get().add(getHtmlEditor());
}

private Widget getHtmlEditor(){
final HtmlEditor editor;

editor = new HtmlEditor();
editor.setEnableAlignments(false);
editor.setEnableLists(false);
editor.setSourceEditMode(false);
editor.setWidth("500px");
editor.setHeight("200px");

editor.addKeyListener(new KeyListener(){

@Override
public void handleEvent(ComponentEvent e) {
GWT.log("Key event", null);
}
});

return editor;
}
}

sven
1 Jun 2009, 12:49 AM
This is not supported in the HtmlEditor. The editor is really basic.

Night Shadow
1 Jun 2009, 1:14 AM
Ok. I found a workaround - extends HtmlEditor, add few methods and can handle keydown events. :-? Don't think it's a good way...

sven
1 Jun 2009, 1:17 AM
That is the way to go at the moment. The events are fired in the iframe.

Night Shadow
1 Jun 2009, 1:22 AM
Thanks. Will make my workaround more correct and use it.

itaarn
21 Sep 2009, 12:05 PM
Hi,
could you please explain the methods you added and how you succeded in disabling htmlEditor editing ?

Thanks in advance.

Night Shadow
21 Sep 2009, 9:42 PM
Hi! It was a long time and I do not remember exactly. I think I added some more functionality to htmleditor for my needs. It was something like


private KeyDownHandler keyDownHandler;

public void addKeyDownListener(KeyDownHandler keyDownHandler){
this.keyDownHandler = keyDownHandler;
}
...
protected class rte extends Component {
protected void onRender(Element target, int index) {
Element e = impl.getElement();
e.setPropertyInt("frameBorder", 0);
setElement(e, target, index);

addDomHandler(handler, ClickEvent.getType());
addDomHandler(handler, FocusEvent.getType());
addDomHandler(handler, BlurEvent.getType());
addDomHandler(handler, KeyUpEvent.getType());

if (keyDownHandler != null){
addDomHandler(keyDownHandler, KeyDownEvent.getType());
}
}


Here is full java class. (http://pastebin.org/20052)

bhomass
16 Jan 2010, 11:29 AM
This full java class link is broken.

could you post the code directly instead, or as a download?

I am really having trouble figuring out how you subclassed rte, which is an embedded class in HtmlEditor.

Night Shadow
16 Jan 2010, 12:06 PM
It's was not a subclass of HtmlEditor. It's a full copy-pasted code + necessary changes. :-? Yes, it's not good, but i can't find other way.

bhomass
16 Jan 2010, 12:34 PM
I managed to use the existing keyup event to detect the escape key


public class CanvasCellEditor extends HtmlEditor {
public CanvasCellEditor(){
handler = new CanvasEventHander();
}

protected class CanvasEventHander extends EventHandler {

@Override
public void onKeyUp(KeyUpEvent event) {
super.onKeyUp(event);
if (event.getNativeKeyCode()==KeyCodes.KEY_ESCAPE){
// do stuff
}
}
}
}

Arno.Nyhm
18 Jan 2010, 9:00 AM
It's was not a subclass of HtmlEditor. It's a full copy-pasted code + necessary changes. :-? Yes, it's not good, but i can't find other way.

the link to pastbin shows an empty class.

can you please repost the full class directly here in forum? thx.