From 68c67c5a1b35d5d55d82c4a14cd82212eb7e7177 Mon Sep 17 00:00:00 2001 From: Lidia Popescu Date: Sun, 11 Apr 2021 04:15:58 +0300 Subject: [PATCH] Bug 572755: Sorting for new custom templates The changes adds sorting for source templates in alphabetic order. Makes possible to bring to the top the new custom templates provided by extension points, as the most frequently used ones and to avoid the need for using the drop down list for the right option. Change-Id: I931bd2fc08f3e37178a64e4b7908db73af1fbc2c Signed-off-by: Lidia Popescu --- .../corext/codemanipulation/CdtTemplate.java | 72 +++++++++++++++++++ .../corext/codemanipulation/StubUtility.java | 17 ++++- 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/CdtTemplate.java diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/CdtTemplate.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/CdtTemplate.java new file mode 100644 index 00000000000..6728b1c96c8 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/CdtTemplate.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2021 Wind River Systems, Inc. and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Lidia Popescu (Wind River Systems) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.corext.codemanipulation; + +import java.util.Objects; + +import org.eclipse.jface.text.templates.Template; + +public class CdtTemplate implements Comparable { + + private String id; + private Template template; + private String key; + private String name; + + /** + * @param id - should be the id from TemplatePersistenceData + * @param template + */ + public CdtTemplate(String id, Template template) { + this.id = id; + this.template = template; + if (id == null) { + this.key = ""; //$NON-NLS-1$ + } else { + this.key = id; + } + if (template == null || template.getName() == null) { + this.name = ""; //$NON-NLS-1$ + } else { + this.name = template.getName(); + } + } + + public String getID() { + return id; + } + + public Template getTemplate() { + return template; + } + + public String getKey() { + return key; + } + + public String getName() { + return name; + } + + @Override + public int compareTo(CdtTemplate cdtTmp) { + int value = Objects.compare(key, cdtTmp.key, String::compareTo); + if (value == 0) { + return Objects.compare(name, cdtTmp.name, String.CASE_INSENSITIVE_ORDER); + } + return value; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java index d1aa1849f35..10593493114 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java @@ -18,6 +18,7 @@ package org.eclipse.cdt.internal.corext.codemanipulation; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -759,13 +760,27 @@ public class StubUtility { } templateDatas = projectStore.getTemplateData(); } + List