mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup
This commit is contained in:
+35
-74
@@ -49,16 +49,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.net.URL;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.ide.fileTemplates.FileTemplateManager.*;
|
||||
|
||||
/*
|
||||
* @author: MYakovlev
|
||||
* Date: Jul 26, 2002
|
||||
@@ -86,7 +82,7 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
private JComponent myToolBar;
|
||||
private TabbedPaneWrapper myTabbedPane;
|
||||
private FileTemplateConfigurable myEditor;
|
||||
private boolean myModified = false;
|
||||
private boolean myModified;
|
||||
private JComponent myEditorComponent;
|
||||
private JPanel myLeftPanel;
|
||||
private FileTemplateTab[] myTabs;
|
||||
@@ -94,17 +90,16 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
private final Set<String> myInternalTemplateNames;
|
||||
|
||||
private FileTemplatesScheme myScheme;
|
||||
private final Map<FileTemplatesScheme, Map<String, FileTemplate[]>> myChangesCache =
|
||||
new HashMap<>();
|
||||
private final Map<FileTemplatesScheme, Map<String, FileTemplate[]>> myChangesCache = new HashMap<>();
|
||||
|
||||
private static final String CURRENT_TAB = "FileTemplates.CurrentTab";
|
||||
private static final String SELECTED_TEMPLATE = "FileTemplates.SelectedTemplate";
|
||||
|
||||
public AllFileTemplatesConfigurable(Project project) {
|
||||
myProject = project;
|
||||
myManager = getInstance(project);
|
||||
myManager = FileTemplateManager.getInstance(project);
|
||||
myScheme = myManager.getCurrentScheme();
|
||||
myInternalTemplateNames = ContainerUtil.map2Set(myManager.getInternalTemplates(), template -> template.getName());
|
||||
myInternalTemplateNames = ContainerUtil.map2Set(myManager.getInternalTemplates(), FileTemplate::getName);
|
||||
}
|
||||
|
||||
private void onRemove() {
|
||||
@@ -121,7 +116,8 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
createTemplate(IdeBundle.message("template.unnamed"), ext, "");
|
||||
}
|
||||
|
||||
private FileTemplate createTemplate(final @NotNull String prefName, final @NotNull String extension, final @NotNull String content) {
|
||||
@NotNull
|
||||
private FileTemplate createTemplate(@NotNull final String prefName, @NotNull final String extension, @NotNull final String content) {
|
||||
final FileTemplate[] templates = myCurrentTab.getTemplates();
|
||||
final FileTemplate newTemplate = FileTemplateUtil.createTemplate(prefName, extension, content, templates);
|
||||
myCurrentTab.addTemplate(newTemplate);
|
||||
@@ -149,7 +145,7 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
for (FileTemplate template : templates) {
|
||||
names.add(template.getName());
|
||||
}
|
||||
@SuppressWarnings({"UnresolvedPropertyKey"})
|
||||
@SuppressWarnings("UnresolvedPropertyKey")
|
||||
final String nameTemplate = IdeBundle.message("template.copy.N.of.T");
|
||||
String name = MessageFormat.format(nameTemplate, "", selected.getName());
|
||||
int i = 0;
|
||||
@@ -225,7 +221,7 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
@Override
|
||||
protected FileTemplateNode initModel() {
|
||||
SortedSet<FileTemplateGroupDescriptor> categories =
|
||||
new TreeSet<>((o1, o2) -> o1.getTitle().compareTo(o2.getTitle()));
|
||||
new TreeSet<>(Comparator.comparing(FileTemplateGroupDescriptor::getTitle));
|
||||
|
||||
|
||||
for (FileTemplateGroupDescriptorFactory templateGroupFactory : factories) {
|
||||
@@ -234,19 +230,14 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
|
||||
//noinspection HardCodedStringLiteral
|
||||
return new FileTemplateNode("ROOT", null,
|
||||
ContainerUtil.map2List(categories, s -> new FileTemplateNode(s)));
|
||||
ContainerUtil.map2List(categories, FileTemplateNode::new));
|
||||
}
|
||||
};
|
||||
allTabs.add(myOtherTemplatesList);
|
||||
}
|
||||
|
||||
myEditor = new FileTemplateConfigurable(myProject);
|
||||
myEditor.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
onEditorChanged();
|
||||
}
|
||||
});
|
||||
myEditor.addChangeListener(__ -> onEditorChanged());
|
||||
myEditorComponent = myEditor.createComponent();
|
||||
myEditorComponent.setBorder(JBUI.Borders.empty(10, 0, 10, 10));
|
||||
|
||||
@@ -261,12 +252,7 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
myTabbedPane.addTab(tab.getTitle(), fakePanel);
|
||||
}
|
||||
|
||||
myTabbedPane.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
onTabChanged();
|
||||
}
|
||||
});
|
||||
myTabbedPane.addChangeListener(__ -> onTabChanged());
|
||||
|
||||
DefaultActionGroup group = new DefaultActionGroup();
|
||||
AnAction removeAction = new AnAction(IdeBundle.message("action.remove.template"), null, AllIcons.General.Remove) {
|
||||
@@ -356,15 +342,7 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
|
||||
final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
|
||||
final String tabName = propertiesComponent.getValue(CURRENT_TAB);
|
||||
if (selectTab(tabName)) {
|
||||
//final String selectedTemplateName = propertiesComponent.getValue(SELECTED_TEMPLATE);
|
||||
//for (FileTemplate template : myCurrentTab.getTemplates()) {
|
||||
// if (Comparing.strEqual(template.getName(), selectedTemplateName)) {
|
||||
// myCurrentTab.selectTemplate(template);
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
selectTab(tabName);
|
||||
|
||||
return myMainPanel;
|
||||
}
|
||||
@@ -457,7 +435,7 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
}
|
||||
|
||||
// internal template could not be removed and should be rendered bold
|
||||
public static boolean isInternalTemplate(String templateName, String templateTabTitle) {
|
||||
static boolean isInternalTemplate(String templateName, String templateTabTitle) {
|
||||
if (templateName == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -471,7 +449,7 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
return true;
|
||||
}
|
||||
if (Comparing.strEqual(templateTabTitle, INCLUDES_TITLE)) {
|
||||
return Comparing.strEqual(templateName, FILE_HEADER_TEMPLATE_NAME);
|
||||
return Comparing.strEqual(templateName, FileTemplateManager.FILE_HEADER_TEMPLATE_NAME);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -488,11 +466,11 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
private void initLists() {
|
||||
FileTemplatesScheme scheme = myManager.getCurrentScheme();
|
||||
myManager.setCurrentScheme(myScheme);
|
||||
myTemplatesList.init(getTemplates(DEFAULT_TEMPLATES_CATEGORY));
|
||||
myIncludesList.init(getTemplates(INCLUDES_TEMPLATES_CATEGORY));
|
||||
myCodeTemplatesList.init(getTemplates(CODE_TEMPLATES_CATEGORY));
|
||||
myTemplatesList.init(getTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY));
|
||||
myIncludesList.init(getTemplates(FileTemplateManager.INCLUDES_TEMPLATES_CATEGORY));
|
||||
myCodeTemplatesList.init(getTemplates(FileTemplateManager.CODE_TEMPLATES_CATEGORY));
|
||||
if (myOtherTemplatesList != null) {
|
||||
myOtherTemplatesList.init(getTemplates(J2EE_TEMPLATES_CATEGORY));
|
||||
myOtherTemplatesList.init(getTemplates(FileTemplateManager.J2EE_TEMPLATES_CATEGORY));
|
||||
}
|
||||
myManager.setCurrentScheme(scheme);
|
||||
}
|
||||
@@ -502,9 +480,7 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
if (templates == null) {
|
||||
return myManager.getTemplates(category);
|
||||
}
|
||||
else {
|
||||
return templates.get(category);
|
||||
}
|
||||
return templates.get(category);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -520,11 +496,10 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
final FileTemplate[] templates = myCurrentTab.getTemplates();
|
||||
final List<String> allNames = new ArrayList<>();
|
||||
FileTemplate itemWithError = null;
|
||||
boolean errorInName = true;
|
||||
String errorString = null;
|
||||
for (FileTemplate template : templates) {
|
||||
final String currName = template.getName();
|
||||
if (currName.length() == 0) {
|
||||
if (currName.isEmpty()) {
|
||||
itemWithError = template;
|
||||
errorString = IdeBundle.message("error.please.specify.template.name");
|
||||
break;
|
||||
@@ -538,18 +513,10 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
}
|
||||
|
||||
if (itemWithError != null) {
|
||||
final boolean _errorInName = errorInName;
|
||||
myTabbedPane.setSelectedIndex(Arrays.asList(myTabs).indexOf(list));
|
||||
selectTemplate(itemWithError);
|
||||
list.selectTemplate(itemWithError);
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
if (_errorInName) {
|
||||
myEditor.focusToNameField();
|
||||
}
|
||||
else {
|
||||
myEditor.focusToExtensionField();
|
||||
}
|
||||
});
|
||||
ApplicationManager.getApplication().invokeLater(myEditor::focusToNameField);
|
||||
throw new ConfigurationException(errorString);
|
||||
}
|
||||
}
|
||||
@@ -576,11 +543,12 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
updateCache();
|
||||
for (Map.Entry<FileTemplatesScheme, Map<String, FileTemplate[]>> entry : myChangesCache.entrySet()) {
|
||||
myManager.setCurrentScheme(entry.getKey());
|
||||
myManager.setTemplates(DEFAULT_TEMPLATES_CATEGORY, Arrays.asList(entry.getValue().get(DEFAULT_TEMPLATES_CATEGORY)));
|
||||
myManager.setTemplates(INTERNAL_TEMPLATES_CATEGORY, Arrays.asList(entry.getValue().get(INTERNAL_TEMPLATES_CATEGORY)));
|
||||
myManager.setTemplates(INCLUDES_TEMPLATES_CATEGORY, Arrays.asList(entry.getValue().get(INCLUDES_TEMPLATES_CATEGORY)));
|
||||
myManager.setTemplates(CODE_TEMPLATES_CATEGORY, Arrays.asList(entry.getValue().get(CODE_TEMPLATES_CATEGORY)));
|
||||
myManager.setTemplates(J2EE_TEMPLATES_CATEGORY, Arrays.asList(entry.getValue().get(J2EE_TEMPLATES_CATEGORY)));
|
||||
Map<String, FileTemplate[]> templates = entry.getValue();
|
||||
myManager.setTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, Arrays.asList(templates.get(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY)));
|
||||
myManager.setTemplates(FileTemplateManager.INTERNAL_TEMPLATES_CATEGORY, Arrays.asList(templates.get(FileTemplateManager.INTERNAL_TEMPLATES_CATEGORY)));
|
||||
myManager.setTemplates(FileTemplateManager.INCLUDES_TEMPLATES_CATEGORY, Arrays.asList(templates.get(FileTemplateManager.INCLUDES_TEMPLATES_CATEGORY)));
|
||||
myManager.setTemplates(FileTemplateManager.CODE_TEMPLATES_CATEGORY, Arrays.asList(templates.get(FileTemplateManager.CODE_TEMPLATES_CATEGORY)));
|
||||
myManager.setTemplates(FileTemplateManager.J2EE_TEMPLATES_CATEGORY, Arrays.asList(templates.get(FileTemplateManager.J2EE_TEMPLATES_CATEGORY)));
|
||||
}
|
||||
myChangesCache.clear();
|
||||
|
||||
@@ -592,10 +560,6 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
}
|
||||
}
|
||||
|
||||
public void selectTemplatesTab() {
|
||||
selectTab(TEMPLATES_TITLE);
|
||||
}
|
||||
|
||||
private boolean selectTab(String tabName) {
|
||||
int idx = 0;
|
||||
for (FileTemplateTab tab : myTabs) {
|
||||
@@ -648,7 +612,8 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
myOtherTemplatesList = null;
|
||||
}
|
||||
|
||||
public FileTemplate createNewTemplate(@NotNull String preferredName, @NotNull String extension, @NotNull String text) {
|
||||
@NotNull
|
||||
FileTemplate createNewTemplate(@NotNull String preferredName, @NotNull String extension, @NotNull String text) {
|
||||
return createTemplate(preferredName, extension, text);
|
||||
}
|
||||
|
||||
@@ -672,7 +637,7 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
});
|
||||
}
|
||||
|
||||
public void changeScheme(FileTemplatesScheme scheme) {
|
||||
void changeScheme(FileTemplatesScheme scheme) {
|
||||
if (myEditor != null && myEditor.isModified()) {
|
||||
myModified = true;
|
||||
try {
|
||||
@@ -694,13 +659,13 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
if (!myChangesCache.containsKey(myScheme)) {
|
||||
Map<String, FileTemplate[]> templates = new HashMap<>();
|
||||
FileTemplate[] allTemplates = myTemplatesList.getTemplates();
|
||||
templates.put(DEFAULT_TEMPLATES_CATEGORY, ContainerUtil.filter(allTemplates,
|
||||
templates.put(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, ContainerUtil.filter(allTemplates,
|
||||
template -> !myInternalTemplateNames.contains(template.getName())).toArray(FileTemplate.EMPTY_ARRAY));
|
||||
templates.put(INTERNAL_TEMPLATES_CATEGORY, ContainerUtil.filter(allTemplates,
|
||||
templates.put(FileTemplateManager.INTERNAL_TEMPLATES_CATEGORY, ContainerUtil.filter(allTemplates,
|
||||
template -> myInternalTemplateNames.contains(template.getName())).toArray(FileTemplate.EMPTY_ARRAY));
|
||||
templates.put(INCLUDES_TEMPLATES_CATEGORY, myIncludesList.getTemplates());
|
||||
templates.put(CODE_TEMPLATES_CATEGORY, myCodeTemplatesList.getTemplates());
|
||||
templates.put(J2EE_TEMPLATES_CATEGORY, myOtherTemplatesList == null ? FileTemplate.EMPTY_ARRAY : myOtherTemplatesList.getTemplates());
|
||||
templates.put(FileTemplateManager.INCLUDES_TEMPLATES_CATEGORY, myIncludesList.getTemplates());
|
||||
templates.put(FileTemplateManager.CODE_TEMPLATES_CATEGORY, myCodeTemplatesList.getTemplates());
|
||||
templates.put(FileTemplateManager.J2EE_TEMPLATES_CATEGORY, myOtherTemplatesList == null ? FileTemplate.EMPTY_ARRAY : myOtherTemplatesList.getTemplates());
|
||||
myChangesCache.put(myScheme, templates);
|
||||
}
|
||||
}
|
||||
@@ -710,10 +675,6 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con
|
||||
return myManager;
|
||||
}
|
||||
|
||||
public FileTemplatesScheme getCurrentScheme() {
|
||||
return myScheme;
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
FileTemplateConfigurable getEditor() {
|
||||
return myEditor;
|
||||
|
||||
@@ -72,10 +72,7 @@ public final class BundledFileTemplate extends FileTemplateBase {
|
||||
@Override
|
||||
public boolean isDefault() {
|
||||
// todo: consider isReformat option here?
|
||||
if (!getText().equals(getDefaultText())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return getText().equals(getDefaultText());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ide.fileTemplates.impl;
|
||||
|
||||
import com.intellij.openapi.util.*;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class DeletedTemplatesManager implements JDOMExternalizable {
|
||||
public JDOMExternalizableStringList DELETED_DEFAULT_TEMPLATES = new JDOMExternalizableStringList();
|
||||
|
||||
public void addName(@NotNull @NonNls String nameWithExtension) {
|
||||
DELETED_DEFAULT_TEMPLATES.remove(nameWithExtension);
|
||||
DELETED_DEFAULT_TEMPLATES.add(nameWithExtension);
|
||||
}
|
||||
|
||||
public boolean contains(@NotNull @NonNls String nameWithExtension) {
|
||||
return DELETED_DEFAULT_TEMPLATES.contains(nameWithExtension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(Element element) throws InvalidDataException {
|
||||
DefaultJDOMExternalizer.readExternal(this, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) throws WriteExternalException {
|
||||
DefaultJDOMExternalizer.writeExternal(this, element);
|
||||
}
|
||||
}
|
||||
@@ -37,8 +37,8 @@ import java.util.*;
|
||||
*/
|
||||
class FTManager {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.fileTemplates.impl.FTManager");
|
||||
public static final String DEFAULT_TEMPLATE_EXTENSION = "ft";
|
||||
public static final String TEMPLATE_EXTENSION_SUFFIX = "." + DEFAULT_TEMPLATE_EXTENSION;
|
||||
private static final String DEFAULT_TEMPLATE_EXTENSION = "ft";
|
||||
static final String TEMPLATE_EXTENSION_SUFFIX = "." + DEFAULT_TEMPLATE_EXTENSION;
|
||||
private static final String ENCODED_NAME_EXT_DELIMITER = "\u0F0Fext\u0F0F.";
|
||||
|
||||
private final String myName;
|
||||
@@ -75,7 +75,7 @@ class FTManager {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<FileTemplateBase> getAllTemplates(boolean includeDisabled) {
|
||||
Collection<FileTemplateBase> getAllTemplates(boolean includeDisabled) {
|
||||
List<FileTemplateBase> sorted = mySortedTemplates;
|
||||
if (sorted == null) {
|
||||
sorted = new ArrayList<>(getTemplates().values());
|
||||
@@ -98,18 +98,15 @@ class FTManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param templateQname
|
||||
* @return template no matter enabled or disabled it is
|
||||
*/
|
||||
@Nullable
|
||||
public FileTemplateBase getTemplate(@NotNull String templateQname) {
|
||||
FileTemplateBase getTemplate(@NotNull String templateQname) {
|
||||
return getTemplates().get(templateQname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disabled templates are never returned
|
||||
* @param templateName
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
public FileTemplateBase findTemplateByName(@NotNull String templateName) {
|
||||
@@ -161,7 +158,7 @@ class FTManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTemplates(@NotNull Collection<FileTemplate> newTemplates) {
|
||||
void updateTemplates(@NotNull Collection<FileTemplate> newTemplates) {
|
||||
final Set<String> toDisable = new HashSet<>();
|
||||
for (DefaultTemplate template : myDefaultTemplates) {
|
||||
toDisable.add(template.getQualifiedName());
|
||||
@@ -190,7 +187,7 @@ class FTManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void addDefaultTemplate(DefaultTemplate template) {
|
||||
void addDefaultTemplate(DefaultTemplate template) {
|
||||
myDefaultTemplates.add(template);
|
||||
createAndStoreBundledTemplate(template);
|
||||
}
|
||||
@@ -245,7 +242,7 @@ class FTManager {
|
||||
Pair<String,String> nameExt = decodeFileName(fileName);
|
||||
final String extension = nameExt.second;
|
||||
final String templateQName = nameExt.first;
|
||||
if (templateQName.length() == 0) {
|
||||
if (templateQName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -356,7 +353,7 @@ class FTManager {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public File getConfigRoot(boolean create) {
|
||||
File getConfigRoot(boolean create) {
|
||||
if (create && !myTemplatesDir.mkdirs() && !myTemplatesDir.exists()) {
|
||||
LOG.info("Cannot create directory: " + myTemplatesDir.getAbsolutePath());
|
||||
}
|
||||
@@ -368,12 +365,13 @@ class FTManager {
|
||||
return myName + " file template manager";
|
||||
}
|
||||
|
||||
public static String encodeFileName(String templateName, String extension) {
|
||||
static String encodeFileName(String templateName, String extension) {
|
||||
String nameExtDelimiter = extension.contains(".") ? ENCODED_NAME_EXT_DELIMITER : ".";
|
||||
return templateName + nameExtDelimiter + extension;
|
||||
}
|
||||
|
||||
public static Pair<String,String> decodeFileName(String fileName) {
|
||||
@NotNull
|
||||
private static Pair<String,String> decodeFileName(@NotNull String fileName) {
|
||||
String name = fileName;
|
||||
String ext = "";
|
||||
String nameExtDelimiter = fileName.contains(ENCODED_NAME_EXT_DELIMITER) ? ENCODED_NAME_EXT_DELIMITER : ".";
|
||||
|
||||
@@ -34,8 +34,8 @@ import java.util.Properties;
|
||||
* Date: 4/6/11
|
||||
*/
|
||||
public abstract class FileTemplateBase implements FileTemplate {
|
||||
public static final boolean DEFAULT_REFORMAT_CODE_VALUE = true;
|
||||
public static final boolean DEFAULT_ENABLED_VALUE = true;
|
||||
static final boolean DEFAULT_REFORMAT_CODE_VALUE = true;
|
||||
static final boolean DEFAULT_ENABLED_VALUE = true;
|
||||
@Nullable
|
||||
private String myText;
|
||||
private boolean myShouldReformatCode = DEFAULT_REFORMAT_CODE_VALUE;
|
||||
|
||||
+13
-17
@@ -90,7 +90,7 @@ public class FileTemplateConfigurable implements Configurable, Configurable.NoSc
|
||||
private JCheckBox myLiveTemplateBox;
|
||||
private JPanel myTopPanel;
|
||||
private JEditorPane myDescriptionComponent;
|
||||
private boolean myModified = false;
|
||||
private boolean myModified;
|
||||
private URL myDefaultDescriptionUrl;
|
||||
private final Project myProject;
|
||||
|
||||
@@ -117,7 +117,7 @@ public class FileTemplateConfigurable implements Configurable, Configurable.NoSc
|
||||
}
|
||||
}
|
||||
|
||||
public void setShowInternalMessage(String message) {
|
||||
void setShowInternalMessage(String message) {
|
||||
myTopPanel.removeAll();
|
||||
if (message == null) {
|
||||
myTopPanel.add(new JLabel(IdeBundle.message("label.name")),
|
||||
@@ -138,7 +138,7 @@ public class FileTemplateConfigurable implements Configurable, Configurable.NoSc
|
||||
myTopPanel.repaint();
|
||||
}
|
||||
|
||||
public void setShowAdjustCheckBox(boolean show) {
|
||||
void setShowAdjustCheckBox(boolean show) {
|
||||
myAdjustBox.setEnabled(show);
|
||||
}
|
||||
|
||||
@@ -250,10 +250,6 @@ public class FileTemplateConfigurable implements Configurable, Configurable.NoSc
|
||||
myModified = true;
|
||||
}
|
||||
|
||||
public String getNameValue() {
|
||||
return myNameField.getText();
|
||||
}
|
||||
|
||||
private void onNameChanged() {
|
||||
ChangeEvent event = new ChangeEvent(this);
|
||||
for (ChangeListener changeListener : myChangeListeners) {
|
||||
@@ -261,7 +257,7 @@ public class FileTemplateConfigurable implements Configurable, Configurable.NoSc
|
||||
}
|
||||
}
|
||||
|
||||
public void addChangeListener(ChangeListener listener) {
|
||||
void addChangeListener(@NotNull ChangeListener listener) {
|
||||
if (!myChangeListeners.contains(listener)) {
|
||||
myChangeListeners.add(listener);
|
||||
}
|
||||
@@ -276,8 +272,8 @@ public class FileTemplateConfigurable implements Configurable, Configurable.NoSc
|
||||
if (myModified) {
|
||||
return true;
|
||||
}
|
||||
String name = (myTemplate == null) ? "" : myTemplate.getName();
|
||||
String extension = (myTemplate == null) ? "" : myTemplate.getExtension();
|
||||
String name = myTemplate == null ? "" : myTemplate.getName();
|
||||
String extension = myTemplate == null ? "" : myTemplate.getExtension();
|
||||
if (!Comparing.equal(name, myNameField.getText())) {
|
||||
return true;
|
||||
}
|
||||
@@ -325,12 +321,12 @@ public class FileTemplateConfigurable implements Configurable, Configurable.NoSc
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
final String text = (myTemplate == null) ? "" : myTemplate.getText();
|
||||
String name = (myTemplate == null) ? "" : myTemplate.getName();
|
||||
String extension = (myTemplate == null) ? "" : myTemplate.getExtension();
|
||||
String description = (myTemplate == null) ? "" : myTemplate.getDescription();
|
||||
final String text = myTemplate == null ? "" : myTemplate.getText();
|
||||
String name = myTemplate == null ? "" : myTemplate.getName();
|
||||
String extension = myTemplate == null ? "" : myTemplate.getExtension();
|
||||
String description = myTemplate == null ? "" : myTemplate.getDescription();
|
||||
|
||||
if ((description.length() == 0) && (myDefaultDescriptionUrl != null)) {
|
||||
if (description.isEmpty() && myDefaultDescriptionUrl != null) {
|
||||
try {
|
||||
description = UrlUtil.loadText(myDefaultDescriptionUrl);
|
||||
}
|
||||
@@ -361,8 +357,8 @@ public class FileTemplateConfigurable implements Configurable, Configurable.NoSc
|
||||
myDescriptionComponent.setText(description);
|
||||
myDescriptionComponent.setCaretPosition(0);
|
||||
|
||||
myNameField.setEditable((myTemplate != null) && (!myTemplate.isDefault()));
|
||||
myExtensionField.setEditable((myTemplate != null) && (!myTemplate.isDefault()));
|
||||
myNameField.setEditable(myTemplate != null && !myTemplate.isDefault());
|
||||
myExtensionField.setEditable(myTemplate != null && !myTemplate.isDefault());
|
||||
myModified = false;
|
||||
}
|
||||
|
||||
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.ide.fileTemplates.impl;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* author: lesya
|
||||
*/
|
||||
public class FileTemplateDescriptionImpl {
|
||||
private final String myTitle;
|
||||
private final Icon myIcon;
|
||||
|
||||
public FileTemplateDescriptionImpl(String title, Icon icon) {
|
||||
myTitle = title;
|
||||
myIcon = icon;
|
||||
}
|
||||
|
||||
protected FileTemplateTabAsTree.FileTemplateNode createTreeNode(){
|
||||
return new FileTemplateTabAsTree.FileTemplateNode(myIcon, myTitle);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -357,7 +357,7 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Pers
|
||||
|
||||
String message = "Default template not found: " + name;
|
||||
LOG.error(message);
|
||||
return null;
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -407,7 +407,7 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Pers
|
||||
return myDefaultSettings.getDefaultTemplateDescription();
|
||||
}
|
||||
|
||||
public URL getDefaultIncludeDescription() {
|
||||
URL getDefaultIncludeDescription() {
|
||||
return myDefaultSettings.getDefaultIncludeDescription();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ import java.util.Locale;
|
||||
storages = @Storage(FileTemplateSettings.EXPORTABLE_SETTINGS_FILE)
|
||||
)
|
||||
public class FileTemplateSettings extends FileTemplatesLoader implements PersistentStateComponent<Element> {
|
||||
public final static String EXPORTABLE_SETTINGS_FILE = "file.template.settings.xml";
|
||||
public static final String EXPORTABLE_SETTINGS_FILE = "file.template.settings.xml";
|
||||
|
||||
private static final String ELEMENT_TEMPLATE = "template";
|
||||
private static final String ATTRIBUTE_NAME = "name";
|
||||
|
||||
+6
-14
@@ -24,8 +24,6 @@ import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -34,19 +32,14 @@ import java.util.List;
|
||||
* @author Alexey Kudravtsev
|
||||
*/
|
||||
abstract class FileTemplateTabAsList extends FileTemplateTab {
|
||||
private final JList myList = new JBList();
|
||||
private final JList<FileTemplate> myList = new JBList<>();
|
||||
private MyListModel myModel;
|
||||
|
||||
FileTemplateTabAsList(String title) {
|
||||
super(title);
|
||||
myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
myList.setCellRenderer(new MyListCellRenderer());
|
||||
myList.addListSelectionListener(new ListSelectionListener() {
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
onTemplateSelected();
|
||||
}
|
||||
});
|
||||
myList.addListSelectionListener(__ -> onTemplateSelected());
|
||||
new ListSpeedSearch(myList, (Function<Object, String>)o -> {
|
||||
if (o instanceof FileTemplate) {
|
||||
return ((FileTemplate)o).getName();
|
||||
@@ -99,8 +92,8 @@ abstract class FileTemplateTabAsList extends FileTemplateTab {
|
||||
onTemplateSelected();
|
||||
}
|
||||
|
||||
private static class MyListModel extends DefaultListModel {
|
||||
public void fireListDataChanged() {
|
||||
private static class MyListModel extends DefaultListModel<FileTemplate> {
|
||||
void fireListDataChanged() {
|
||||
int size = getSize();
|
||||
if (size > 0) {
|
||||
fireContentsChanged(this, 0, size - 1);
|
||||
@@ -134,7 +127,7 @@ abstract class FileTemplateTabAsList extends FileTemplateTab {
|
||||
final int size = myModel.getSize();
|
||||
List<FileTemplate> templates = new ArrayList<>(size);
|
||||
for (int i =0; i<size; i++) {
|
||||
templates.add((FileTemplate) myModel.getElementAt(i));
|
||||
templates.add(myModel.getElementAt(i));
|
||||
}
|
||||
return templates.toArray(new FileTemplate[templates.size()]);
|
||||
}
|
||||
@@ -151,8 +144,7 @@ abstract class FileTemplateTabAsList extends FileTemplateTab {
|
||||
|
||||
@Override
|
||||
public FileTemplate getSelectedTemplate() {
|
||||
final Object value = myList.getSelectedValue();
|
||||
return value instanceof FileTemplate ? (FileTemplate) value : null;
|
||||
return myList.getSelectedValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.ide.fileTemplates.FileTemplate;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.io.URLUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
@@ -42,17 +43,15 @@ public class UrlUtil {
|
||||
private static final String FILE_PROTOCOL = URLUtil.FILE_PROTOCOL;
|
||||
private static final String FILE_PROTOCOL_PREFIX = FILE_PROTOCOL + ":";
|
||||
|
||||
public static String loadText(URL url) throws IOException {
|
||||
final InputStream stream = new BufferedInputStream(URLUtil.openStream(url));
|
||||
try {
|
||||
@NotNull
|
||||
public static String loadText(@NotNull URL url) throws IOException {
|
||||
try (InputStream stream = new BufferedInputStream(URLUtil.openStream(url))) {
|
||||
return new String(FileUtil.loadBytes(stream), FileTemplate.ourEncoding);
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getChildrenRelativePaths(URL root) throws IOException {
|
||||
@NotNull
|
||||
public static List<String> getChildrenRelativePaths(@NotNull URL root) throws IOException {
|
||||
final String protocol = root.getProtocol();
|
||||
if ("jar".equalsIgnoreCase(protocol)) {
|
||||
return getChildPathsFromJar(root);
|
||||
@@ -63,7 +62,8 @@ public class UrlUtil {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static List<String> getChildPathsFromFile(URL root) {
|
||||
@NotNull
|
||||
private static List<String> getChildPathsFromFile(@NotNull URL root) {
|
||||
final List<String> paths = new ArrayList<>();
|
||||
final File rootFile = new File(FileUtil.unquote(root.getPath()));
|
||||
new Object() {
|
||||
@@ -71,7 +71,7 @@ public class UrlUtil {
|
||||
final File[] list = fromFile.listFiles();
|
||||
if (list != null) {
|
||||
for (File file : list) {
|
||||
final String childRelativePath = prefix.length() == 0 ? file.getName() : prefix + URL_PATH_SEPARATOR + file.getName();
|
||||
final String childRelativePath = prefix.isEmpty() ? file.getName() : prefix + URL_PATH_SEPARATOR + file.getName();
|
||||
if (file.isDirectory()) {
|
||||
collectFiles(file, childRelativePath);
|
||||
}
|
||||
@@ -85,8 +85,8 @@ public class UrlUtil {
|
||||
return paths;
|
||||
}
|
||||
|
||||
private static List<String> getChildPathsFromJar(URL root) throws IOException {
|
||||
final List<String> paths = new ArrayList<>();
|
||||
@NotNull
|
||||
private static List<String> getChildPathsFromJar(@NotNull URL root) throws IOException {
|
||||
String file = root.getFile();
|
||||
file = StringUtil.trimStart(file, FILE_PROTOCOL_PREFIX);
|
||||
final int jarSeparatorIndex = file.indexOf(JAR_SEPARATOR);
|
||||
@@ -96,9 +96,9 @@ public class UrlUtil {
|
||||
if (!rootDirName.endsWith(URL_PATH_SEPARATOR)) {
|
||||
rootDirName += URL_PATH_SEPARATOR;
|
||||
}
|
||||
final ZipFile zipFile = new ZipFile(FileUtil.unquote(file.substring(0, jarSeparatorIndex)));
|
||||
try {
|
||||
try (ZipFile zipFile = new ZipFile(FileUtil.unquote(file.substring(0, jarSeparatorIndex)))) {
|
||||
final Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
final List<String> paths = new ArrayList<>();
|
||||
while (entries.hasMoreElements()) {
|
||||
final ZipEntry entry = entries.nextElement();
|
||||
if (!entry.isDirectory()) {
|
||||
@@ -110,8 +110,5 @@ public class UrlUtil {
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
finally {
|
||||
zipFile.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,6 @@ import javax.swing.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION;
|
||||
|
||||
public class ListSpeedSearch extends SpeedSearchBase<JList> {
|
||||
private final Convertor<Object, String> myToStringConvertor;
|
||||
|
||||
@@ -51,6 +49,7 @@ public class ListSpeedSearch extends SpeedSearchBase<JList> {
|
||||
new MySelectAllAction(list, this).registerCustomShortcutSet(list, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void selectElement(Object element, String selectedText) {
|
||||
if (element != null) {
|
||||
ScrollingUtil.selectItem(myComponent, element);
|
||||
@@ -60,10 +59,12 @@ public class ListSpeedSearch extends SpeedSearchBase<JList> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSelectedIndex() {
|
||||
return myComponent.getSelectedIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object[] getAllElements() {
|
||||
return getAllListElements(myComponent);
|
||||
}
|
||||
@@ -82,6 +83,7 @@ public class ListSpeedSearch extends SpeedSearchBase<JList> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getElementText(Object element) {
|
||||
if (myToStringConvertor != null) {
|
||||
return myToStringConvertor.convert(element);
|
||||
@@ -106,7 +108,7 @@ public class ListSpeedSearch extends SpeedSearchBase<JList> {
|
||||
@NotNull private final JList myList;
|
||||
@NotNull private final ListSpeedSearch mySearch;
|
||||
|
||||
public MySelectAllAction(@NotNull JList list, @NotNull ListSpeedSearch search) {
|
||||
MySelectAllAction(@NotNull JList list, @NotNull ListSpeedSearch search) {
|
||||
myList = list;
|
||||
mySearch = search;
|
||||
AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_SELECT_ALL);
|
||||
@@ -119,7 +121,7 @@ public class ListSpeedSearch extends SpeedSearchBase<JList> {
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
e.getPresentation().setEnabled(mySearch.isPopupActive() &&
|
||||
myList.getSelectionModel().getSelectionMode() == MULTIPLE_INTERVAL_SELECTION);
|
||||
myList.getSelectionModel().getSelectionMode() == ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user