How to set the Caret of the IOConsole

做~自己de王妃 提交于 2019-12-01 09:32:01

To gain access to the caret position, you will need to implement a console viewer.

This is the setup I have for my custom console,

public class MyConsole extends IOConsole
{
   ....
        @Override
    public IPageBookViewPage createPage(IConsoleView view) {
        return new MyConsolePage(this, view);
    }
}

public class MyConsolePage extends TextConsolePage
{
   ....
       @Override
    protected TextConsoleViewer createViewer(Composite parent) {
        return new MyConsoleViewer(parent, (MyConsole) this.getConsole());
    }
}

public class MyConsoleViewer extends TextConsoleViewer
{
    //This class gives you access to setting the caret position
    //by getting the styled text widget and then using setCaretOffset
}

There are multiple ways of getting the styled text widget depending on which method you are overriding. I also created my own Console history class which kept track of the caret offset since I needed additional functionality of using the up and down arrow keys to navigate through previously entered commands.

The best way to implement the MyConsoleViewer is to use Eclipse's vast source code that sets a perfect example. I practically reused all of this class org.eclipse.ui.internal.console.IOConsoleViewer. It even shows examples of setting the caret.

Hope this still helps as your question was a while ago.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!