簡體   English   中英

Eclipse RCP:自定義控制台

[英]Eclipse RCP: Custom console

我正在嘗試創建一個控制台,作為自定義編程語言的shell。 它與pydev交互式控制台非常相似。

目前,我的RCP使用基本的TextConsole並通過管道連接到shell,因此它只顯示shell顯示的內容,如果用戶在RCP控制台中輸入任何內容,則會在shell中寫入相同內容。

我希望能夠做更多的事情,例如移動插入位置,添加向上和向下箭頭鍵等事件。我相信這樣做我需要將一個StyledText小部件添加到控制台,這是通過ConsoleViewer完成的。

所以我的問題是,有沒有辦法讓我覆蓋TextConsole的ConsoleViewer,或者如果我要擴展TextConsole並創建我自己的,那么我如何將它與啟動配置(通過管道連接shell的那個)鏈接起來?

另外,要獲取當前的默認控制台,我使用DebugUITools.getConsole(process)

如果我沒有提供所需的所有信息,我很抱歉; 這有點難以解釋。 我很樂意添加更多信息。

一個想法......根據我的理解,我可以使用createPage(ConsoleView) TextConsolePageTextConsole創建一個TextConsolePage 有了頁面后,我可以通過setViewer(viewer)設置查看setViewer(viewer) 在這里,我想如果我創建自己的查看器(它將具有適當的樣式組件),那么這可能是一個領先者。 唯一的問題是觀眾需要一個復合材料,我似乎無法弄清楚從哪里得到它。

所以我想我會自己回答,因為我終於能夠完成控制台了。 它仍然是一個工作原型,但我想,隨着你不斷添加東西,你可以越來越多地清理代碼。 對於我目前的目的,這是它的工作方式。

如果你想要短版本,那么我基本上模仿了Eclipse提供的ProcessConsole ,因為這就是我所需要的:一個控制台,我可以在其中連接一個進程,但由於ProcessConsole是內部的,我想避免擴展這些類。

以下是我用來與我的控制台進行交互的類的概述。 我不會以MyConsole創建位置為借口。 基本上,我使用自己的myProcess.getConsole()方法而不是使用DebugUITools.getConsole(myProcess) MyProcess擴展了RuntimeProcess

class MyConsole extends IOConsole {
 private IOConsoleInputStream fInput;
 private IOConsoleOutputStream fOutput;
 private IStreamsProxy fStreamsProxy;
 private ConsoleHistory history;
 //This is to remember the caret position after the prompt 
 private int caretAtPrompt;
     /* in the console so when you need to replace the command on up and down 
      * arrow keys you have the position. 
      * I just did a caretAtPrompt += String.Length wherever string was 
      * appended to the console. Mainly in the streamlistener and 
      * InputJob unless you specifically output something to the output 
      * stream.
      */
 //In the constructor you assign all the above fields. Below are some 
 //to point out.
 //fInput = getInputStream();
 // fStreamsProxy = process.getStreamsProxy();
 // fOutput = newOutputStream();

 //We must override the following method to get access to the caret
 @Override
 public IPageBookViewPage createPage(IConsoleView view) {
    return new MyConsolePage(this, view);
    }
 //After this I followed the ProcessConsole and added the 
 //InputJob and StreamListener
 //defined in there. 
 }

class MyConsolePage extends TextConsolePage {
 //Not much in this class, just override the createViewer
 // to return MyConsoleViewer
 }

class MyConsoleViewer extends TextConsoleViewer {
 //This is the most important class and most of the work is done here
 //Again I basically copied everything from IOConsoleViewer and then
 //updated whatever I needed
 //I added a VerifyKeyListener for the up and down arrow 
 //keys for the console history

 MyConsoleViewer (Composite parent, MyConsole console) {
  //I have omitted a lot of code as it was too much to put up, 
  //just highlighted a few
  getTextWidget().addVerifyKeyListener(new MyKeyChecker());
  }

 class MyKeyChecker implements VerifyKeyListener {...}

 }

ProcessConsole的代碼。 IOConsoleViewer的代碼。

我創建的ConsoleHistory類只有一個雙向鏈接的字符串列表,用於保存用戶輸入的所有命令。 相當簡單的一個類來創建。

一旦你看了Eclipse類( ProcessConsoleIOConsoleViewer ),它實際上都是非常自我解釋的。 我沒有在這里輸入太多代碼,因為有很多。 但希望這會給我一些方向,因為當我開始時我完全失去了。

我很樂意回答問題,如果有人問,請添加更具體的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM