33 коровы – Eclipse Monkey и редакторы Flex Builder - RIA разработка, Flex, Action Script, AIR, Eclipse, Monkey script

Eclipse Monkey и редакторы Flex Builder

April 16, 2009 – 5:39 am

Работа с mxml и css редактором отличается от работы с обычным редактором который нам предоставляет Eclipse Monkey. Чтобы получить доступ к любому редактору я использую такой метод

loadBundle("com.adobe.flexbuilder.editors.common");
/**
 * @return current text editor or null
 * @see org.eclipse.ui.editors.text.TextEditor  
 */
this.getCurrentTextEditor = function()
{
	var editor = window.getActivePage().getActiveEditor();
	if (editor)
	{ 
		if (editor.getClass().getName() == "com.adobe.flexbuilder.editors.mxml.MXMLEditor"
			|| editor.getClass().getName() == "com.adobe.flexbuilder.editors.css.CSSEditor")
		{
			editor = editor.getCodeEditor();
		}
		/*
		//TODO add others editors that 
		else if (){}
 
		*/
	}
	return editor;
}

Данный метод отдает ссылку на инстанс класса наследованого от org.eclipse.ui.editors.text.TextEditor, вернее даже на инстанс, который реализует
org.eclipse.ui.editors.ITextEditor

дальше работаем обычными для эклипса методами:

this.TextSelection = Packages.org.eclipse.jface.text.TextSelection;
 
this.insertToCursor = function(editor, text, moveCursor)
{
	if (editor)
	{
		var documentProvider = editor.getDocumentProvider();
		var doc = documentProvider.getDocument(editor.getEditorInput());
		var offset = editor.getSelectionProvider().getSelection().getOffset();
 
		doc.replace(offset, 0,  text);
 
		if (moveCursor)
		{
			var selection = new TextSelection(doc, offset+text.length, 0);
			editor.getSelectionProvider().setSelection(selection);	
		}
	}
}

Метод вставляет текст в позицию курсора и если выставлен флаг, перемещает курсор в конец вставленного текста.

  1. 2 Responses to “Eclipse Monkey и редакторы Flex Builder”

  2. Илюха!!! За колорпикер тебе огромное спасибо 😉 !!! Его во флексе не хватало.. так оперативно!

    By bimawa on Apr 21, 2009

  3. Потрясающе !!! Это именно то что было нужно. Работает на ура.

    Кудос автору !!!

    By mike on Sep 17, 2009

Sorry, comments for this entry are closed at this time.



]]> rss о RIA от 33 Коровы
Забадать RSS!
]]>
~~~~~~