Add a 'close' button to LSP console
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 463 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
@@ -40,4 +40,14 @@
|
||||
class="org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolesPrefsInitializer">
|
||||
</initializer>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.console.consolePageParticipants">
|
||||
<consolePageParticipant
|
||||
class="org.springframework.tooling.ls.eclipse.commons.console.LanguageServerConsolePageParticipant"
|
||||
id="org.springframework.tooling.ls.eclipse.commons.console.LanguageServerConsolePageParticipant">
|
||||
<enablement>
|
||||
<instanceof value="org.springframework.tooling.ls.eclipse.commons.console.LanguageServerIOConsole"/>
|
||||
</enablement>
|
||||
</consolePageParticipant>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
||||
@@ -10,13 +10,22 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.ls.eclipse.commons;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
public class LanguageServerCommonsActivator extends AbstractUIPlugin {
|
||||
|
||||
public static final String PLUGIN_ID = "org.springframework.tooling.ls.eclipse.commons";
|
||||
|
||||
private static LanguageServerCommonsActivator instance;
|
||||
|
||||
public LanguageServerCommonsActivator() {
|
||||
@@ -28,6 +37,19 @@ public class LanguageServerCommonsActivator extends AbstractUIPlugin {
|
||||
super.start(context);
|
||||
}
|
||||
|
||||
public final static ImageDescriptor getImageDescriptor(String path) {
|
||||
ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
|
||||
Bundle bundle = Platform.getBundle(PLUGIN_ID);
|
||||
URL url = null;
|
||||
if (bundle != null) {
|
||||
url = FileLocator.find(bundle, new Path(path), null);
|
||||
if (url != null) {
|
||||
desc = ImageDescriptor.createFromURL(url);
|
||||
}
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
|
||||
public static LanguageServerCommonsActivator getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.ls.eclipse.commons.console;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.console.ConsolePlugin;
|
||||
import org.eclipse.ui.console.IConsole;
|
||||
import org.springframework.tooling.ls.eclipse.commons.LanguageServerCommonsActivator;
|
||||
|
||||
public class CloseConsoleAction extends Action {
|
||||
|
||||
private LanguageServerIOConsole fConsole;
|
||||
|
||||
public CloseConsoleAction(IWorkbenchWindow workbenchWindow, LanguageServerIOConsole fConsole) {
|
||||
super("Close Console", LanguageServerCommonsActivator.getImageDescriptor("icons/rem_co.png"));
|
||||
this.fConsole = fConsole;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
//TODO: anything to clean up?
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new IConsole[]{fConsole});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import org.eclipse.ui.console.IOConsoleOutputStream;
|
||||
*/
|
||||
@SuppressWarnings("restriction")
|
||||
public class ConsoleUtil {
|
||||
|
||||
|
||||
public static class Console {
|
||||
public final InputStream in;
|
||||
public final OutputStream out;
|
||||
@@ -67,15 +67,15 @@ public class ConsoleUtil {
|
||||
public static Color getOutputColor() {
|
||||
return DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_SYS_OUT_COLOR);
|
||||
}
|
||||
|
||||
|
||||
public static Color getErrorColor() {
|
||||
return DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_SYS_ERR_COLOR);
|
||||
}
|
||||
|
||||
|
||||
public static Color getInputColor() {
|
||||
return DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_SYS_IN_COLOR);
|
||||
}
|
||||
|
||||
|
||||
private LinkedList<IOConsole> history = new LinkedList<IOConsole>();
|
||||
|
||||
private void add(IOConsole console) {
|
||||
@@ -96,18 +96,18 @@ public class ConsoleUtil {
|
||||
private static void close(IOConsole console) {
|
||||
ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new IConsole[] {console});
|
||||
}
|
||||
|
||||
|
||||
public Console getConsole(String title) {
|
||||
|
||||
final IOConsole console = new IOConsole(title, null);
|
||||
|
||||
final IOConsole console = new LanguageServerIOConsole(title);
|
||||
final IOConsoleInputStream in = console.getInputStream();
|
||||
final IOConsoleOutputStream out = console.newOutputStream();
|
||||
final IOConsoleOutputStream err = console.newOutputStream();
|
||||
|
||||
|
||||
in.setColor(getInputColor());
|
||||
out.setColor(getOutputColor());
|
||||
err.setColor(getErrorColor());
|
||||
|
||||
|
||||
add(console);
|
||||
return new Console(in, out, err);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2009, 2017 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Kris De Volder - copied from org.eclipse.debug.internal.ui.views.console.ProcessConsolePageParticipant
|
||||
* - modified to create similar functionality for GrailsIOConsole
|
||||
* Kris De Volder - copied and modified to support lsp console close action
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.ls.eclipse.commons.console;
|
||||
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.console.IConsole;
|
||||
import org.eclipse.ui.console.IConsoleConstants;
|
||||
import org.eclipse.ui.console.IConsolePageParticipant;
|
||||
import org.eclipse.ui.console.IConsoleView;
|
||||
import org.eclipse.ui.part.IPageBookViewPage;
|
||||
|
||||
public class LanguageServerConsolePageParticipant implements IConsolePageParticipant {
|
||||
|
||||
// actions
|
||||
private CloseConsoleAction fClose;
|
||||
|
||||
private IPageBookViewPage fPage;
|
||||
|
||||
private IConsoleView fView;
|
||||
|
||||
private LanguageServerIOConsole fConsole;
|
||||
|
||||
@Override
|
||||
public void init(IPageBookViewPage page, IConsole console) {
|
||||
fPage = page;
|
||||
fConsole = (LanguageServerIOConsole) console;
|
||||
|
||||
fClose = new CloseConsoleAction(page.getSite().getWorkbenchWindow(), fConsole);
|
||||
|
||||
fView = (IConsoleView) fPage.getSite().getPage().findView(IConsoleConstants.ID_CONSOLE_VIEW);
|
||||
|
||||
// contribute to toolbar
|
||||
IActionBars actionBars = fPage.getSite().getActionBars();
|
||||
configureToolBar(actionBars.getToolBarManager());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getAdapter(Class<T> arg0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (fClose != null) {
|
||||
fClose.dispose();
|
||||
fClose = null;
|
||||
}
|
||||
// if (fStdOut != null) {
|
||||
// fStdOut.dispose();
|
||||
// fStdOut = null;
|
||||
// }
|
||||
// if (fStdErr != null) {
|
||||
// fStdErr.dispose();
|
||||
// fStdErr = null;
|
||||
// }
|
||||
fConsole = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Contribute actions to the toolbar
|
||||
*/
|
||||
protected void configureToolBar(IToolBarManager mgr) {
|
||||
mgr.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fClose);
|
||||
|
||||
// mgr.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fRemoveTerminated);
|
||||
// mgr.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fRemoveAllTerminated);
|
||||
// mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fStdOut);
|
||||
// mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fStdErr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activated() {
|
||||
// add EOF submissions
|
||||
// IPageSite site = fPage.getSite();
|
||||
// IHandlerService handlerService = (IHandlerService)site.getService(IHandlerService.class);
|
||||
// IContextService contextService = (IContextService)site.getService(IContextService.class);
|
||||
// fActivatedContext = contextService.activateContext(fContextId);
|
||||
// fActivatedHandler = handlerService.activateHandler("org.eclipse.debug.ui.commands.eof", fEOFHandler); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.ui.console.IConsolePageParticipant#deactivated()
|
||||
*/
|
||||
@Override
|
||||
public void deactivated() {
|
||||
// remove EOF submissions
|
||||
// IPageSite site = fPage.getSite();
|
||||
// IHandlerService handlerService = (IHandlerService)site.getService(IHandlerService.class);
|
||||
// IContextService contextService = (IContextService)site.getService(IContextService.class);
|
||||
// handlerService.deactivateHandler(fActivatedHandler);
|
||||
// contextService.deactivateContext(fActivatedContext);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.ls.eclipse.commons.console;
|
||||
|
||||
import org.eclipse.ui.console.IOConsole;
|
||||
|
||||
public class LanguageServerIOConsole extends IOConsole {
|
||||
|
||||
private static final String CONSOLE_TYPE = LanguageServerIOConsole.class.getName();
|
||||
|
||||
public LanguageServerIOConsole(final String title) {
|
||||
super(title, CONSOLE_TYPE, null);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user