Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2016-08-08 14:05:20 +0000
committerAndrey Loskutov2016-08-08 16:13:32 +0000
commitf9d16aa400693529e34bfa73f06cf0a666d29dd1 (patch)
tree324607a5fc55edc9b8a5ea8977f131b108dc3a2a
parentc3c018cd1a122e1ea58850f08780488485933a0b (diff)
downloadeclipse.platform.ui-f9d16aa400693529e34bfa73f06cf0a666d29dd1.tar.gz
eclipse.platform.ui-f9d16aa400693529e34bfa73f06cf0a666d29dd1.tar.xz
eclipse.platform.ui-f9d16aa400693529e34bfa73f06cf0a666d29dd1.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>
-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