Skip to content

Commit 5a59959

Browse files
authored
IEP-1521 Update build folder after project renaming (#1212)
* feat: rename build folder after the project's renaming * fix: remove useless line in code * fix: provide correct absolute path to the update build dir
1 parent 8b266c4 commit 5a59959

File tree

3 files changed

+79
-12
lines changed

3 files changed

+79
-12
lines changed

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class Messages extends NLS
2828
public static String MissingDebugConfigurationTitle;
2929
public static String DebugConfigurationNotFoundMsg;
3030

31+
public static String RenameIdfProjectParticipant_RenameBuildFolderPathChangeName;
3132
public static String RunActionHandler_NoProjectQuestionText;
3233
public static String RunActionHandler_NoProjectQuestionTitle;
3334

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/RenameIdfProjectParticipant.java

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.espressif.idf.ui.handlers;
22

3+
import org.eclipse.core.resources.IFolder;
4+
import org.eclipse.core.resources.IProject;
5+
import org.eclipse.core.resources.ResourcesPlugin;
36
import org.eclipse.core.runtime.CoreException;
47
import org.eclipse.core.runtime.IProgressMonitor;
58
import org.eclipse.core.runtime.OperationCanceledException;
9+
import org.eclipse.core.runtime.Status;
610
import org.eclipse.launchbar.core.ILaunchBarManager;
711
import org.eclipse.launchbar.core.target.ILaunchTarget;
812
import org.eclipse.ltk.core.refactoring.Change;
@@ -11,15 +15,75 @@
1115
import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
1216
import org.eclipse.swt.widgets.Display;
1317

18+
import com.espressif.idf.core.IDFConstants;
1419
import com.espressif.idf.core.IDFCorePlugin;
1520
import com.espressif.idf.core.logging.Logger;
21+
import com.espressif.idf.core.util.IDFUtil;
1622
import com.espressif.idf.ui.LaunchBarListener;
1723

1824
public class RenameIdfProjectParticipant extends RenameParticipant
1925
{
2026

27+
private IProject project;
28+
29+
class UpdateBuildFolderChange extends Change
30+
{
31+
32+
private String oldBuildFolderPath;
33+
private String newBuildPath;
34+
private IProject newProject;
35+
private IFolder newBuildFolder;
36+
37+
@Override
38+
public String getName()
39+
{
40+
return String.format(Messages.RenameIdfProjectParticipant_RenameBuildFolderPathChangeName,
41+
oldBuildFolderPath, newBuildPath);
42+
}
43+
44+
@Override
45+
public RefactoringStatus isValid(IProgressMonitor pm)
46+
{
47+
return RefactoringStatus.create(Status.OK_STATUS);
48+
}
49+
50+
@Override
51+
public void initializeValidationData(IProgressMonitor pm)
52+
{
53+
try
54+
{
55+
oldBuildFolderPath = IDFUtil.getBuildDir(project);
56+
String newProjectName = getArguments().getNewName();
57+
newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(newProjectName);
58+
newBuildFolder = newProject.getFolder(IDFConstants.BUILD_FOLDER);
59+
newBuildPath = newBuildFolder.getFullPath().toOSString();
60+
}
61+
catch (CoreException e)
62+
{
63+
Logger.log(e);
64+
}
65+
}
66+
67+
@Override
68+
public Change perform(IProgressMonitor pm) throws CoreException
69+
{
70+
IDFUtil.setBuildDir(newProject, newBuildFolder.getLocation().toOSString());
71+
return null;
72+
}
73+
74+
@Override
75+
public Object getModifiedElement()
76+
{
77+
return project;
78+
}
79+
}
80+
2181
protected boolean initialize(Object element)
2282
{
83+
if (element instanceof IProject projectElement)
84+
{
85+
this.project = projectElement;
86+
}
2387
return true;
2488
}
2589

@@ -40,19 +104,20 @@ public Change createChange(IProgressMonitor pm) throws CoreException, OperationC
40104
ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class);
41105
ILaunchTarget activeLaunchTarget = launchBarManager.getActiveLaunchTarget();
42106
LaunchBarListener.setIgnoreTargetChange(true);
43-
Display.getDefault().syncExec(() ->
44-
Display.getDefault().getActiveShell().addDisposeListener(disposeEvent -> {
45-
try
46-
{
47-
LaunchBarListener.setIgnoreTargetChange(false);
48-
launchBarManager.setActiveLaunchTarget(activeLaunchTarget);
49-
}
50-
catch (CoreException e)
51-
{
52-
Logger.log(e);
53-
}
107+
Display.getDefault().syncExec(() -> Display.getDefault().getActiveShell().addDisposeListener(disposeEvent -> {
108+
try
109+
{
110+
LaunchBarListener.setIgnoreTargetChange(false);
111+
launchBarManager.setActiveLaunchTarget(activeLaunchTarget);
112+
}
113+
catch (CoreException e)
114+
{
115+
Logger.log(e);
116+
}
117+
54118
}));
55-
return null;
119+
120+
return new UpdateBuildFolderChange();
56121
}
57122

58123
}

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ UpdateEspIdfCommand_InstallToolsJobMsg=Installing tools...
2020
UpdateEspIdfCommand_SuggestToOpenInstallToolsWizard = A new set of tools might be required to install. Do you want to open the Install Tools dialog?
2121
MissingDebugConfigurationTitle=Missing debug configuration
2222
DebugConfigurationNotFoundMsg=No matching debug configuration was found for the selected project. Do you want to create it?
23+
RenameIdfProjectParticipant_RenameBuildFolderPathChangeName=Update build folder path from "%s" to "%s"
2324
RunActionHandler_NoProjectQuestionText=The selected configuration does not include a project. Would you like to edit the active launch configuration and specify the project?
2425
RunActionHandler_NoProjectQuestionTitle=Edit Active Configuration?

0 commit comments

Comments
 (0)