简体   繁体   中英

Eclipse Plugin: Opening dialogs alongside quickfix

I'm working on a plugin and am trying to add some additional information around the quickfix menu that is triggered by clicking on my custom markers.

I'm adding a method call in MarkerResolutionGenerator.getResolutions() to draw the new dialog window, but I'm having trouble getting it to agree with the quickfix dialog. I can get it to draw at the same time, but I can't control the position and it also draws an extra blank dialog in the background.

Any thoughts? Relevant code below. The first two methods are from my MarkerResolutionGenerator, and my custom class is below that. (I just copied it from an example, I'm more worried about getting it to behave before I work on the content.)

@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;
    }
    ...
}

Do you really need to create another Shell ? Why not just use the one you already have as parent for your dialog? It might be the reason for the "extra blank dialog in the background".

You should be able to set the initial position overriding getInitialLocation in your custom dialog:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM