<i id='CqA3A'><tr id='CqA3A'><dt id='CqA3A'><q id='CqA3A'><span id='CqA3A'><b id='CqA3A'><form id='CqA3A'><ins id='CqA3A'></ins><ul id='CqA3A'></ul><sub id='CqA3A'></sub></form><legend id='CqA3A'></legend><bdo id='CqA3A'><pre id='CqA3A'><center id='CqA3A'></center></pre></bdo></b><th id='CqA3A'></th></span></q></dt></tr></i><div id='CqA3A'><tfoot id='CqA3A'></tfoot><dl id='CqA3A'><fieldset id='CqA3A'></fieldset></dl></div>
        <bdo id='CqA3A'></bdo><ul id='CqA3A'></ul>
    1. <small id='CqA3A'></small><noframes id='CqA3A'>

    2. <tfoot id='CqA3A'></tfoot>
        <legend id='CqA3A'><style id='CqA3A'><dir id='CqA3A'><q id='CqA3A'></q></dir></style></legend>
      1. 如何设置 IOConsole 的插入符号

        时间:2023-08-22
        <tfoot id='tsdRz'></tfoot>
        <legend id='tsdRz'><style id='tsdRz'><dir id='tsdRz'><q id='tsdRz'></q></dir></style></legend>

        <small id='tsdRz'></small><noframes id='tsdRz'>

          <tbody id='tsdRz'></tbody>

                <i id='tsdRz'><tr id='tsdRz'><dt id='tsdRz'><q id='tsdRz'><span id='tsdRz'><b id='tsdRz'><form id='tsdRz'><ins id='tsdRz'></ins><ul id='tsdRz'></ul><sub id='tsdRz'></sub></form><legend id='tsdRz'></legend><bdo id='tsdRz'><pre id='tsdRz'><center id='tsdRz'></center></pre></bdo></b><th id='tsdRz'></th></span></q></dt></tr></i><div id='tsdRz'><tfoot id='tsdRz'></tfoot><dl id='tsdRz'><fieldset id='tsdRz'></fieldset></dl></div>
                • <bdo id='tsdRz'></bdo><ul id='tsdRz'></ul>

                • 本文介绍了如何设置 IOConsole 的插入符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I'm writing an eclipse-plugin which creating a new Console. Please see my source code:

                  CliConsoleFactory.java

                  import java.io.IOException;
                  
                  import org.eclipse.jface.text.DocumentEvent;
                  import org.eclipse.jface.text.IDocument;
                  import org.eclipse.jface.text.IDocumentListener;
                  import org.eclipse.ui.IWorkbenchPage;
                  import org.eclipse.ui.PartInitException;
                  import org.eclipse.ui.PlatformUI;
                  import org.eclipse.ui.console.ConsolePlugin;
                  import org.eclipse.ui.console.IConsole;
                  import org.eclipse.ui.console.IConsoleConstants;
                  import org.eclipse.ui.console.IConsoleFactory;
                  import org.eclipse.ui.console.IConsoleView;
                  import org.eclipse.ui.console.IOConsoleOutputStream;
                  
                  public class CliConsoleFactory implements IConsoleFactory {
                  
                      private static final String ENTER_KEY = "
                  ";
                      private static final String CLI_PROMPT = "CLI> ";
                      private IConsoleView m_consoleView = null;
                  
                      @Override
                      public void openConsole() {
                  
                          IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                          try {
                              m_consoleView = (IConsoleView) page.showView(IConsoleConstants.ID_CONSOLE_VIEW);
                          } catch (PartInitException e1) {
                              e1.printStackTrace();
                          }
                          if (m_consoleView == null) {
                              return;
                          }
                  
                  
                          final MyIOConsole myConsole = new MyIOConsole("CLI", null);
                  
                          final IDocument document = myConsole.getDocument();
                          document.addDocumentListener(new IDocumentListener() {
                  
                              @Override
                              public void documentChanged(DocumentEvent event) {
                                  if (ENTER_KEY.equals(event.getText())) {
                                      // Print the Prompt
                                      writeToConsole(myConsole, CLI_PROMPT);
                                  }
                              }
                  
                              @Override
                              public void documentAboutToBeChanged(DocumentEvent event) {
                              }
                          });
                  
                          ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { myConsole });
                          m_consoleView.display(myConsole);
                          writeToConsole(myConsole, CLI_PROMPT);
                      }
                  
                      private void writeToConsole(final MyIOConsole myConsole, String msg) {
                          IOConsoleOutputStream stream = myConsole.newOutputStream();
                          stream.setActivateOnWrite(true);
                          try {
                              stream.write(msg);
                          } catch (IOException e) {
                              e.printStackTrace();
                          } finally {
                              if (stream != null) {
                                  try {
                                      stream.close();
                                  } catch (IOException e) {
                                      e.printStackTrace();
                                  }
                              }
                          }
                      }
                  }
                  

                  MyIOConsole.java

                  import org.eclipse.jface.resource.ImageDescriptor;
                  import org.eclipse.ui.console.IOConsole;
                  
                  public class MyIOConsole extends IOConsole {
                  
                      public MyIOConsole(String name, ImageDescriptor imageDescriptor) {
                          super(name, imageDescriptor);
                      }
                  
                  }
                  

                  It works great. When I enter to a new line, the Prompt is "CLI> ", but the Caret position is not okie, it is at the first position of the line instead of the last position. I want to make the Caret move to the last position. Who know please help me.!!!

                  解决方案

                  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.

                  这篇关于如何设置 IOConsole 的插入符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从任何 Java 应用程序调用自己的 Eclipse 插件方法 下一篇:eclipse插件 - 将非java扩展文件视为java文件

                  相关文章

                • <legend id='3fQbl'><style id='3fQbl'><dir id='3fQbl'><q id='3fQbl'></q></dir></style></legend>

                  1. <i id='3fQbl'><tr id='3fQbl'><dt id='3fQbl'><q id='3fQbl'><span id='3fQbl'><b id='3fQbl'><form id='3fQbl'><ins id='3fQbl'></ins><ul id='3fQbl'></ul><sub id='3fQbl'></sub></form><legend id='3fQbl'></legend><bdo id='3fQbl'><pre id='3fQbl'><center id='3fQbl'></center></pre></bdo></b><th id='3fQbl'></th></span></q></dt></tr></i><div id='3fQbl'><tfoot id='3fQbl'></tfoot><dl id='3fQbl'><fieldset id='3fQbl'></fieldset></dl></div>

                    <small id='3fQbl'></small><noframes id='3fQbl'>

                    • <bdo id='3fQbl'></bdo><ul id='3fQbl'></ul>

                      <tfoot id='3fQbl'></tfoot>