簡體   English   中英

XML Eclipse插件。 如何使用“ Tab”鍵作為快捷方式

[英]XML Eclipse Plugin. How to use the 'tab' key as a shortcut

我目前正在開發Eclipse XML編輯器插件。 我目前正在努力實現快捷功能。 我希望能夠使用Tab鍵在下面的代碼片段中的引號之間跳轉。 我的意思是,鍵入查詢名稱,按“ tab”,然后跳過類型引號。

<query name="" type="" />

我對應該使用plugin.xml中的哪個擴展名以及通常如何實現此擴展名感到困惑。 提前謝謝了。

假設您的編輯器是從TextEditor派生的,則已經有一個帶有定義動作的Tab處理程序。 您應該能夠通過覆蓋createActions方法來覆蓋此方法:

protected void createActions()
{
  super.createActions();

  IAction action = ..... your IAction to do the tabbing

  // Replace tab handler
  setAction(ITextEditorActionConstants.SHIFT_RIGHT_TAB, action);
}

您的IAction應該擴展TextEditorAction 這使您可以訪問編輯器。 run方法可能是:

public void run()
{
  ITextEditor ed = getTextEditor();
  if (!(ed instanceof AbstractTextEditor))
    return;

  if (!validateEditorInputState())
    return;

  AbstractTextEditor editor = (AbstractTextEditor)ed;
  ISourceViewer sv = editor.getSourceViewer();
  if (sv == null)
    return;

  IDocument document = sv.getDocument();
  if (document == null)
    return;

  StyledText st = sv.getTextWidget();
  if (st == null || st.isDisposed())
    return;

  int caret = st.getCaretOffset();

  // Offset in document of the caret

  int offset = AbstractTextEditor.widgetOffset2ModelOffset(sv, caret);

  int newOffset  = ... your code to change the position

  // Set caret from new document offset

  int widgetCaret = AbstractTextEditor.modelOffset2WidgetOffset(sv, newOffset);

  st.setSelectionRange(widgetCaret, 0);

(部分改編自InsertLineAction )。

暫無
暫無

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

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