mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
FIXED - bug 195604: Source folder becomes common folder after rename
https://bugs.eclipse.org/bugs/show_bug.cgi?id=195604
This commit is contained in:
parent
5304735fdb
commit
24ce8e3659
5 changed files with 228 additions and 1 deletions
|
@ -539,4 +539,5 @@ preferenceKeywords.markoccurrences=editor occurrence mark highlight
|
|||
preferenceKeywords.smarttyping=editor typing type close comment tabs indentation indent imports wrap escape semicolons braces brackets parenthesis parentheses strings literals paste pasting tabulator automatically
|
||||
historyAction.label = History...
|
||||
createScriptAction.label = Create Script...
|
||||
applyScriptAction.label = Apply Script...
|
||||
applyScriptAction.label = Apply Script...
|
||||
renameParticipant.name = Source Folder Rename
|
|
@ -3209,4 +3209,27 @@
|
|||
id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring">
|
||||
</contribution>
|
||||
</extension>
|
||||
<extension point="org.eclipse.ltk.core.refactoring.renameParticipants">
|
||||
<renameParticipant id="org.eclipse.jdt.junit.renameTypeParticipant"
|
||||
name="%renameParticipant.name"
|
||||
class="org.eclipse.cdt.internal.ui.refactoring.rename.RenameSourceFolder">
|
||||
<enablement>
|
||||
<or>
|
||||
<with variable="affectedNatures">
|
||||
<iterate operator="or">
|
||||
<equals value="org.eclipse.cdt.core.ccnature" />
|
||||
</iterate>
|
||||
</with>
|
||||
<with variable="affectedNatures">
|
||||
<iterate operator="or">
|
||||
<equals value="org.eclipse.cdt.core.cnature" />
|
||||
</iterate>
|
||||
</with>
|
||||
</or>
|
||||
<with variable="element">
|
||||
<instanceof value="org.eclipse.core.resources.IFolder" />
|
||||
</with>
|
||||
</enablement>
|
||||
</renameParticipant>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software (IFS)- initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.settings.model.CSourceEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
|
||||
import org.eclipse.cdt.core.settings.model.WriteAccessException;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf IFS
|
||||
*
|
||||
*/
|
||||
public class RenameCSourceFolderChange extends Change {
|
||||
|
||||
private IPath oldName;
|
||||
private IPath newName;
|
||||
private IProject project;
|
||||
private IFolder folder;
|
||||
|
||||
|
||||
|
||||
public RenameCSourceFolderChange(IPath oldFolderPath, IPath newFolderPath, IProject project, IFolder oldFolder) {
|
||||
super();
|
||||
this.oldName = oldFolderPath;
|
||||
this.newName = newFolderPath;
|
||||
this.project = project;
|
||||
folder = oldFolder;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getModifiedElement() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return MessageFormat.format(Messages.getString("RenameCSourceFolderChange.Name0"), oldName.lastSegment(), newName.lastSegment()); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeValidationData(IProgressMonitor pm) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||
if(folder.exists()) {
|
||||
return RefactoringStatus.create(Status.OK_STATUS);
|
||||
}else {
|
||||
return RefactoringStatus.create(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, MessageFormat.format(Messages.getString("RenameCSourceFolderChange.ErroMsg"), folder.getName()))); //$NON-NLS-1$
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Change perform(IProgressMonitor pm) throws CoreException {
|
||||
|
||||
changeEntryInAllCfgs(CCorePlugin.getDefault().getProjectDescription(project, true));
|
||||
IFolder folder2 = project.getFolder(newName.lastSegment());
|
||||
return new RenameCSourceFolderChange(newName, oldName, project, folder2);
|
||||
}
|
||||
|
||||
private void changeEntryInAllCfgs(ICProjectDescription des) throws WriteAccessException, CoreException{
|
||||
ICConfigurationDescription cfgs[] = des.getConfigurations();
|
||||
for(ICConfigurationDescription cfg : cfgs){
|
||||
ICSourceEntry[] entries = cfg.getSourceEntries();
|
||||
entries = renameEntry(entries);
|
||||
cfg.setSourceEntries(entries);
|
||||
}
|
||||
CCorePlugin.getDefault().setProjectDescription(project, des, false, new NullProgressMonitor());//TODO Add PM
|
||||
}
|
||||
|
||||
private ICSourceEntry[] renameEntry(ICSourceEntry[] entries){
|
||||
Set<ICSourceEntry> set = new HashSet<ICSourceEntry>();
|
||||
for(ICSourceEntry se : entries){
|
||||
String seLocation = se.getName();
|
||||
if(seLocation.equals(oldName.toPortableString())) {
|
||||
ICSourceEntry newSE = new CSourceEntry(newName, se.getExclusionPatterns(), se.getFlags());
|
||||
set.add(newSE);
|
||||
}else {
|
||||
Set<IPath> exPatters = new HashSet<IPath>();
|
||||
for (IPath filter : se.getExclusionPatterns()) {
|
||||
IPath oldSegments = oldName.removeFirstSegments(oldName.segmentCount() -1);
|
||||
if(filter.equals(oldSegments)) {
|
||||
exPatters.add(newName.removeFirstSegments(newName.segmentCount() -1));
|
||||
}else {
|
||||
exPatters.add(filter);
|
||||
}
|
||||
}
|
||||
|
||||
set.add(new CSourceEntry(se.getValue(), exPatters.toArray(new IPath[exPatters.size()]), se.getFlags()));
|
||||
}
|
||||
}
|
||||
return set.toArray(new ICSourceEntry[set.size()]);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software (IFS)- initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
|
||||
import org.eclipse.ltk.core.refactoring.participants.RenameArguments;
|
||||
import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf IFS
|
||||
*
|
||||
*/
|
||||
public class RenameSourceFolder extends RenameParticipant {
|
||||
|
||||
private IFolder oldFolder;
|
||||
private String newName;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public RenameSourceFolder() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context)
|
||||
throws OperationCanceledException {
|
||||
|
||||
RenameArguments arg = getArguments();
|
||||
newName = arg.getNewName();
|
||||
return RefactoringStatus.create(Status.OK_STATUS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||
IPath oldFolderPath = oldFolder.getFullPath();
|
||||
IPath newFolderPath = oldFolder.getFullPath().uptoSegment(oldFolder.getFullPath().segmentCount()-1).append(newName);
|
||||
|
||||
return new RenameCSourceFolderChange(oldFolderPath, newFolderPath, oldFolder.getProject(), oldFolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return Messages.getString("RenameSourceFolder.0"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean initialize(Object element) {
|
||||
if (element instanceof IFolder) {
|
||||
oldFolder = (IFolder) element;
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -95,3 +95,6 @@ ASTManager.warning.parsingError.detailed=Parsing error - {0} -
|
|||
ASTManager.warning.parsingError.withFile={0} in file ''{1}''
|
||||
ASTManager.warning.parsingError.withFileAndLine={0} in file ''{1}'' at line ''{2}''
|
||||
ASTManager.error.macro.name.conflict=''{0}'' conflicts with the name of an existing macro!
|
||||
RenameCSourceFolderChange.ErroMsg=Folder {0} does not exist
|
||||
RenameCSourceFolderChange.Name0=Rename source Folder {0} to {1}
|
||||
RenameSourceFolder.0=Rename CDT Source Folder
|
||||
|
|
Loading…
Add table
Reference in a new issue