Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IEP-1262 Changing the configuration should also change the mode #993

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,37 @@ public static void setIgnoreTargetChange(boolean status)
targetChangeIgnored = status;
}

@Override
public void activeLaunchDescriptorChanged(ILaunchDescriptor descriptor)
{
descriptor.getAdapter(ILaunchConfiguration.class);
sigmaaa marked this conversation as resolved.
Show resolved Hide resolved
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))
{
setMode(launchBarManager, ILaunchManager.RUN_MODE);
}
else if (IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier))
{
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 +253,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);
}
}
Comment on lines +259 to +275
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enhance Error Logging in setMode.

The error logging in the catch block can be improved to provide more context about the error.

- Logger.log(e);
+ Logger.log("Error setting launch mode", e);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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);
}
}
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("Error setting launch mode", e);
}
}


}
Loading