Skip to content

Commit

Permalink
IEP-1262 Changing the configuration should also change the mode (#993)
Browse files Browse the repository at this point in the history
* feat: change the mode when changing conf
  • Loading branch information
sigmaaa authored Jul 10, 2024
1 parent c69061c commit bbc1b6c
Show file tree
Hide file tree
Showing 3 changed files with 299 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import java.io.File;
import java.text.MessageFormat;
import java.util.Optional;
import java.util.stream.Stream;

import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.core.resources.IProject;
Expand All @@ -17,6 +19,8 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.launchbar.core.ILaunchBarListener;
import org.eclipse.launchbar.core.ILaunchBarManager;
Expand Down Expand Up @@ -49,6 +53,40 @@ public static void setIgnoreTargetChange(boolean status)
targetChangeIgnored = status;
}

@Override
public void activeLaunchDescriptorChanged(ILaunchDescriptor descriptor)
{
ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class);

try
{
ILaunchConfiguration activeLaunchConfiguration = launchBarManager.getActiveLaunchConfiguration();

if (activeLaunchConfiguration != null && activeLaunchConfiguration.getType() != null)
{
String configTypeIdentifier = activeLaunchConfiguration.getType().getIdentifier();
if (IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier))
{
// Set debug mode first to ensure a mode change, triggering listeners.
setMode(launchBarManager, ILaunchManager.DEBUG_MODE);
setMode(launchBarManager, ILaunchManager.RUN_MODE);
}
else if (IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier))
{
// Set run mode first to ensure a mode change, triggering listeners.
setMode(launchBarManager, ILaunchManager.RUN_MODE);
setMode(launchBarManager, ILaunchManager.DEBUG_MODE);
}
}
}
catch (CoreException e)
{
Logger.log(e);
}

ILaunchBarListener.super.activeLaunchDescriptorChanged(descriptor);
}

@Override
public void activeLaunchTargetChanged(ILaunchTarget target)
{
Expand Down Expand Up @@ -218,4 +256,22 @@ private void cleanSdkConfig(IResource project)
}
}

private void setMode(ILaunchBarManager launchBarManager, String mode)
{
try
{
Optional<ILaunchMode> runMode = Stream.of(launchBarManager.getLaunchModes())
.filter(m -> m.getIdentifier().equals(mode)).findFirst();
if (runMode.isPresent())
{
launchBarManager.setActiveLaunchMode(runMode.get());
}

}
catch (CoreException e)
{
Logger.log(e);
}
}

}
Loading

0 comments on commit bbc1b6c

Please sign in to comment.