Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2016-08-08 14:05:20 +0000
committerAndrey Loskutov2016-08-13 05:14:23 +0000
commit26384f5e34988d15d91a7e1d40fa6f7f7d267f96 (patch)
treee0ef6f626ebf3ea0b14aff045e225b911eded60a
parent3b94b08bd36e82fffd41893c775cbf0b820960b9 (diff)
downloadeclipse.platform.ui-26384f5e34988d15d91a7e1d40fa6f7f7d267f96.tar.gz
eclipse.platform.ui-26384f5e34988d15d91a7e1d40fa6f7f7d267f96.tar.xz
eclipse.platform.ui-26384f5e34988d15d91a7e1d40fa6f7f7d267f96.zip
Bug 499363 - [IDE] Remove "Copy of" when copying a project
Code is inspired by the org.eclipse.ui.actions.CopyFilesAndFoldersOperation.getAutoNewNameFor(IPath, IWorkspace). Change-Id: I9942958670e5a687b9774d3d8119f097b7cad6ca Signed-off-by: Andrey Loskutov <loskutov@gmx.de> (cherry picked from commit f9d16aa400693529e34bfa73f06cf0a666d29dd1)
-rw-r--r--bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/ProjectLocationSelectionDialog.java31
1 files changed, 17 insertions, 14 deletions
diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/ProjectLocationSelectionDialog.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/ProjectLocationSelectionDialog.java
index cced04ea010..0d4fcacf9c4 100644
--- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/ProjectLocationSelectionDialog.java
+++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/ProjectLocationSelectionDialog.java
@@ -18,6 +18,8 @@
package org.eclipse.ui.dialogs;
import java.util.ArrayList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -231,24 +233,25 @@ public class ProjectLocationSelectionDialog extends SelectionStatusDialog {
return projectName;
}
- int counter = 1;
+ String newName = computeNewName(projectName);
while (true) {
- String nameSegment;
- if (counter > 1) {
- nameSegment = NLS.bind(IDEWorkbenchMessages.CopyProjectAction_copyNameTwoArgs, counter, projectName);
- } else {
- nameSegment = NLS.bind(
- IDEWorkbenchMessages.CopyProjectAction_copyNameOneArg,
- projectName);
+ if (!workspace.getRoot().getProject(newName).exists()) {
+ return newName;
}
-
- if (!workspace.getRoot().getProject(nameSegment).exists()) {
- return nameSegment;
- }
-
- counter++;
+ newName = computeNewName(newName);
}
+ }
+ private static String computeNewName(String str) {
+ String fileNameNoExtension = str;
+ Pattern p = Pattern.compile("[0-9]+$"); //$NON-NLS-1$
+ Matcher m = p.matcher(fileNameNoExtension);
+ if (m.find()) {
+ // String ends with a number: increment it by 1
+ int newNumber = Integer.parseInt(m.group()) + 1;
+ return m.replaceFirst(Integer.toString(newNumber));
+ }
+ return fileNameNoExtension + "2"; //$NON-NLS-1$
}
/**

Back to the top