2016-06-09 96 views
0

我正在研究一個插件,並試圖在點擊我的自定義標記時觸發的quickfix菜單添加一些附加信息。Eclipse插件:在quickfix旁邊打開對話框

我在MarkerResolutionGenerator.getResolutions()中添加一個方法調用來繪製新的對話框窗口,但是我很難讓它與quickfix對話框一致。我可以在同一時間繪製它,但是我無法控制位置,並且它在背景中還繪製了一個額外的空白對話框。

有什麼想法?下面的相關代碼。前兩個方法來自我的MarkerResolutionGenerator,而我的自定義類就在那之下。 (我只是從一個例子複製它,我更擔心得到它的行爲之前,我的工作內容。)

@Override 
public IMarkerResolution[] getResolutions(IMarker marker) 
{ 
    IMarker problem = marker; 

    makeStuff(); 
    ... 
} 

private void makeStuff() 
{ 
    Display display = Activator.getDefault().getWorkbench().getDisplay(); 
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() 
      .getSite().getWorkbenchWindow().getShell(); 

    Shell myShell = new Shell(shell, SWT.NO_TRIM); 

    MyDialog md = new MyDialog(myShell); 
    md.open(); 
} 


public class MyDialog extends Dialog 
{ 
    public MyDialog(Shell parentShell) 
    { 
     super(parentShell); 
     setShellStyle(SWT.CLOSE | SWT.MODELESS | SWT.BORDER | SWT.TITLE); 
     setBlockOnOpen(false); 
    } 

    @Override 
    protected Control createDialogArea(Composite parent) 
    { 
     Composite container = (Composite) super.createDialogArea(parent); 
     Button button = new Button(container, SWT.PUSH); 
     button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); 
     button.setText("Press me"); 
     button.addSelectionListener(new SelectionAdapter() { 
      @Override 
      public void widgetSelected(SelectionEvent e) { 
       System.out.println("Pressed"); 
      } 
     }); 

     return container; 
    } 
    ... 
} 
+0

'Dialog'創建自己的殼所以不需要你的'myShell'。 –

回答

0

你真的需要創建另一個Shell?爲什麼不僅僅使用你已經作爲你的對話的父母呢?這可能是「在後臺額外空白對話框」的原因。

你應該能夠設定初始位置在自定義對話框覆蓋getInitialLocation

@Override 
protected Point getInitialLocation(Point initialSize) { 
    return new Point(10, 10); // x and y coordinates of the initial position 
} 
+0

這讓我非常接近,但之所以我認爲我需要額外的外殼是因爲如果使用活動外殼,quickfix對話框不會保持可見。它快速閃爍,然後消失並離開自定義對話框。 – fang273

+0

如果你用'myShell.open()'打開myShell,你將會有額外的空白對話框,所以確保你沒有這樣做。如果您仍然遇到問題,請嘗試創建[MCVE](http://stackoverflow.com/help/mcve),以便我們可以重現問題 –

+0

感謝您的評論,我已經取消了myShell,但現在我遇到了問題我上面描述過。我可以嘗試製作一個MCVE,但是我必須獲得我正在合作發佈代碼的某人的許可。希望我發佈的代碼很有意義,因爲直接調用者是一個內部類。 – fang273