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); } } } |
Метод вставляет текст в позицию курсора и если выставлен флаг, перемещает курсор в конец вставленного текста.
2 Responses to “Eclipse Monkey и редакторы Flex Builder”
Илюха!!! За колорпикер тебе огромное спасибо 😉 !!! Его во флексе не хватало.. так оперативно!
By bimawa on Apr 21, 2009
Потрясающе !!! Это именно то что было нужно. Работает на ура.
Кудос автору !!!
By mike on Sep 17, 2009