1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 14:55:41 +02:00

Bug 486033 - Add close button to CDT Build Console toolbar

This change adds a close action
(org.eclipse.ui.console.actions.CloseConsoleAction) to the CDT build
console.

CDT accessing a closed console via BuildConsoleManager will result in
re-adding the respective console page to the console view, if the
console page was closed.

Change-Id: Ifc4d4c6ed329f1c1c7e70f7903ed660ba85306c5
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
This commit is contained in:
Simeon Andreev 2020-11-19 14:51:43 +01:00 committed by Jonah Graham
parent a655f7b4a5
commit d4c6168964
4 changed files with 48 additions and 3 deletions

View file

@ -20,6 +20,7 @@ import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.internal.core.LocalProjectScope; import org.eclipse.cdt.internal.core.LocalProjectScope;
@ -55,6 +56,7 @@ import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException; import org.eclipse.ui.PartInitException;
import org.eclipse.ui.console.ConsolePlugin; import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsoleConstants; import org.eclipse.ui.console.IConsoleConstants;
import org.eclipse.ui.console.IConsoleListener;
import org.eclipse.ui.console.IConsoleView; import org.eclipse.ui.console.IConsoleView;
import org.osgi.service.prefs.Preferences; import org.osgi.service.prefs.Preferences;
@ -114,10 +116,14 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
private IProject fLastProject; private IProject fLastProject;
private IConsoleListener fConsoleListener;
private final AtomicBoolean fWasClosed;
/** /**
* Default constructor. * Default constructor.
*/ */
public BuildConsoleManager() { public BuildConsoleManager() {
fWasClosed = new AtomicBoolean(false);
} }
/** /**
@ -222,6 +228,7 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
problemInfoBackgroundColor.dispose(); problemInfoBackgroundColor.dispose();
problemHighlightedColor.dispose(); problemHighlightedColor.dispose();
} }
ConsolePlugin.getDefault().getConsoleManager().removeConsoleListener(fConsoleListener);
ConsolePlugin.getDefault().getConsoleManager() ConsolePlugin.getDefault().getConsoleManager()
.removeConsoles(new org.eclipse.ui.console.IConsole[] { fConsole }); .removeConsoles(new org.eclipse.ui.console.IConsole[] { fConsole });
CUIPlugin.getWorkspace().removeResourceChangeListener(this); CUIPlugin.getWorkspace().removeResourceChangeListener(this);
@ -276,12 +283,26 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
errorStream = new BuildConsoleStreamDecorator(); errorStream = new BuildConsoleStreamDecorator();
fName = name; fName = name;
fContextMenuId = contextId; fContextMenuId = contextId;
fConsoleListener = new IConsoleListener() {
@Override
public void consolesAdded(org.eclipse.ui.console.IConsole[] consoles) {
// don't care
}
@Override
public void consolesRemoved(org.eclipse.ui.console.IConsole[] consoles) {
for (org.eclipse.ui.console.IConsole console : consoles) {
if (console == fConsole) {
fWasClosed.set(true);
}
}
}
};
ConsolePlugin.getDefault().getConsoleManager().addConsoleListener(fConsoleListener);
runUI(() -> { runUI(() -> {
// add console to the Console view
fConsole = createBuildConsole(fName, fContextMenuId, iconUrl); fConsole = createBuildConsole(fName, fContextMenuId, iconUrl);
ConsolePlugin.getDefault().getConsoleManager() addConsole();
.addConsoles(new org.eclipse.ui.console.IConsole[] { fConsole });
infoStream.setConsole(fConsole); infoStream.setConsole(fConsole);
infoColor = createColor(CUIPlugin.getStandardDisplay(), infoColor = createColor(CUIPlugin.getStandardDisplay(),
@ -311,6 +332,20 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
} }
public void reinitaliazeIfNecessary() {
if (!(this instanceof GlobalBuildConsoleManager)) {
GlobalBuildConsoleManager.staticReinitaliazeIfNecessary();
}
if (fWasClosed.getAndSet(false)) {
addConsole();
}
}
private void addConsole() {
// add console to the Console view
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new org.eclipse.ui.console.IConsole[] { fConsole });
}
@Override @Override
public void propertyChange(PropertyChangeEvent event) { public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty(); String property = event.getProperty();

View file

@ -83,6 +83,7 @@ import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.console.IConsoleConstants; import org.eclipse.ui.console.IConsoleConstants;
import org.eclipse.ui.console.IConsoleView; import org.eclipse.ui.console.IConsoleView;
import org.eclipse.ui.console.actions.ClearOutputAction; import org.eclipse.ui.console.actions.ClearOutputAction;
import org.eclipse.ui.console.actions.CloseConsoleAction;
import org.eclipse.ui.console.actions.TextViewerAction; import org.eclipse.ui.console.actions.TextViewerAction;
import org.eclipse.ui.console.actions.TextViewerGotoLineAction; import org.eclipse.ui.console.actions.TextViewerGotoLineAction;
import org.eclipse.ui.ide.IDE; import org.eclipse.ui.ide.IDE;
@ -122,6 +123,7 @@ public class BuildConsolePage extends Page
private NextErrorAction fNextErrorAction; private NextErrorAction fNextErrorAction;
private PreviousErrorAction fPreviousErrorAction; private PreviousErrorAction fPreviousErrorAction;
private ShowErrorAction fShowErrorAction; private ShowErrorAction fShowErrorAction;
private CloseConsoleAction fCloseConsoleAction;
private WrapLinesAction fWrapAction; private WrapLinesAction fWrapAction;
private BringToTopOnBuild fBringToTopOnBuild; private BringToTopOnBuild fBringToTopOnBuild;
@ -276,6 +278,7 @@ public class BuildConsolePage extends Page
fPreviousErrorAction = new PreviousErrorAction(this); fPreviousErrorAction = new PreviousErrorAction(this);
fShowErrorAction = new ShowErrorAction(this); fShowErrorAction = new ShowErrorAction(this);
fBringToTopOnBuild = new BringToTopOnBuild(); fBringToTopOnBuild = new BringToTopOnBuild();
fCloseConsoleAction = new CloseConsoleAction(this.fConsole);
fSaveLogAction = new CopyBuildLogAction(this); fSaveLogAction = new CopyBuildLogAction(this);
getViewer().setAutoScroll(!fIsLocked); getViewer().setAutoScroll(!fIsLocked);
@ -337,6 +340,8 @@ public class BuildConsolePage extends Page
mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fWrapAction); mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fWrapAction);
mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fClearOutputAction); mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fClearOutputAction);
mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fBringToTopOnBuild); mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fBringToTopOnBuild);
mgr.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fCloseConsoleAction);
mgr.appendToGroup(IConsoleConstants.LAUNCH_GROUP, new Separator());
} }
protected BuildConsoleViewer getViewer() { protected BuildConsoleViewer getViewer() {

View file

@ -82,6 +82,10 @@ public class GlobalBuildConsoleManager extends BuildConsoleManager {
getInstance(); getInstance();
} }
static void staticReinitaliazeIfNecessary() {
getInstance().reinitaliazeIfNecessary();
}
/** /**
* Stop the console and deallocate resources allocated during {@link #startup()} * Stop the console and deallocate resources allocated during {@link #startup()}
*/ */

View file

@ -560,6 +560,7 @@ public class CUIPlugin extends AbstractUIPlugin {
fBuildConsoleManagers.put(contextId, manager); fBuildConsoleManagers.put(contextId, manager);
manager.startup(name, contextId, iconUrl); manager.startup(name, contextId, iconUrl);
} }
manager.reinitaliazeIfNecessary();
return manager; return manager;
} }