Skip to content
Merged
Show file tree
Hide file tree
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 @@ -8,8 +8,10 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.launchbar.core.ILaunchDescriptor;
import org.eclipse.launchbar.core.target.ILaunchTarget;

Expand All @@ -22,25 +24,16 @@ public class IDFCoreLaunchConfigProvider extends CoreBuildGenericLaunchConfigPro
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target)
throws CoreException
{

ILaunchConfiguration configuration = null;
IProject project = descriptor.getAdapter(IProject.class);
if (project != null)
{

String targetConfig = descriptor.getName();
configuration = configs.computeIfAbsent(project, key -> new HashMap<>()).get(targetConfig);
if (configuration == null)
{
// do we already have one with the descriptor?
configuration = descriptor.getAdapter(ILaunchConfiguration.class);
if (configuration == null)
{
configuration = createLaunchConfiguration(descriptor, target);
}
configs.get(project).put(configuration.getName(), configuration);
}
}
if (project == null)
return null;

String targetConfig = descriptor.getName();
Map<String, ILaunchConfiguration> projectConfigs = configs.computeIfAbsent(project, key -> new HashMap<>());
ILaunchConfiguration configuration = projectConfigs.get(targetConfig);
configuration = configuration == null ? findExistingLaunchConfiguration(project, descriptor) : configuration;
configuration = configuration == null ? createLaunchConfiguration(descriptor, target) : configuration;
projectConfigs.put(configuration.getName(), configuration);
return configuration;
}

Expand Down Expand Up @@ -106,4 +99,20 @@ public void launchTargetRemoved(ILaunchTarget target) throws CoreException
// Nothing to do
}

private ILaunchConfiguration findExistingLaunchConfiguration(IProject project, ILaunchDescriptor descriptor)
throws CoreException
{
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
for (ILaunchConfiguration config : launchManager.getLaunchConfigurations())
{
IResource[] mappedResource = config.getMappedResources();
if (mappedResource != null && mappedResource.length > 0 && mappedResource[0].getProject().equals(project)
&& config.getName().equals(descriptor.getName()))
{
return config;
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@

import org.eclipse.cdt.debug.internal.core.InternalDebugCoreMessages;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.PageChangingEvent;
import org.eclipse.jface.viewers.ISelectionProvider;
Expand All @@ -28,8 +31,6 @@
import org.eclipse.launchbar.ui.NewLaunchConfigWizard;
import org.eclipse.launchbar.ui.NewLaunchConfigWizardDialog;
import org.eclipse.launchbar.ui.internal.dialogs.NewLaunchConfigEditPage;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.tools.templates.core.IGenerator;
Expand Down Expand Up @@ -114,30 +115,44 @@ public boolean performFinish()
}

final String target = projectCreationWizardPage.getSelectedTarget();
this.getShell().addDisposeListener(new DisposeListener()
{
@Override
public void widgetDisposed(DisposeEvent event)
this.getShell().addDisposeListener(event -> {
ILaunchBarManager launchBarManager = UIPlugin.getService(ILaunchBarManager.class);
TargetSwitchJob targetSwtichJob = new TargetSwitchJob(target);
targetSwtichJob.schedule();
try
{
ILaunchBarManager launchBarManager = UIPlugin.getService(ILaunchBarManager.class);
TargetSwitchJob targetSwtichJob = new TargetSwitchJob(target);
targetSwtichJob.schedule();
try
ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor();
if (findAppropriateDebugConfig(desc) == null)
{
ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor();
createDefaultDebugConfig();
launchBarManager.setActiveLaunchDescriptor(desc);
}
catch (CoreException e)
{
Logger.log(e);
}

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

private ILaunchConfiguration findAppropriateDebugConfig(ILaunchDescriptor descriptor) throws CoreException
{
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
IProject project = descriptor.getAdapter(IProject.class);
for (ILaunchConfiguration config : launchManager.getLaunchConfigurations())
{
IResource[] mappedResource = config.getMappedResources();
if (mappedResource != null && mappedResource.length > 0 && mappedResource[0].getProject().equals(project)
&& config.getType().getIdentifier().contentEquals(IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE))
{
return config;
}
}
return null;

}

Comment thread
alirana01 marked this conversation as resolved.
Outdated
private void createDefaultDebugConfig()
{
Shell activeShell = Display.getDefault().getActiveShell();
Expand Down