Skip to content

Commit

Permalink
Merge pull request #5164 from matthiasblaesing/ordering_languages_opt…
Browse files Browse the repository at this point in the history
…ions

Add displayname for maven POM language and order languages in options dialog
  • Loading branch information
matthiasblaesing authored Dec 30, 2022
2 parents 84068cd + 5b87b53 commit 7f4b816
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,9 @@ jobs:
- name: ide/o.openidex.util
run: ant $OPTS -f ide/o.openidex.util test

- name: ide/options.editor
run: ant $OPTS -f ide/options.editor test

# - name: ide/parsing.api
# run: ant $OPTS -f ide/parsing.api test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
Expand All @@ -35,6 +37,7 @@
import org.netbeans.api.options.OptionsDisplayer;
import org.netbeans.modules.editor.settings.storage.api.EditorSettings;
import org.netbeans.modules.options.editor.spi.OptionsFilter;
import org.netbeans.modules.options.util.LanguagesComparator;
import org.netbeans.spi.options.OptionsPanelController;
import org.openide.util.HelpCtx;
import org.openide.util.Lookup;
Expand Down Expand Up @@ -239,8 +242,13 @@ protected void setCurrentSubcategory(String subpath) {
Logger.getLogger(FolderBasedController.class.getName()).log(Level.WARNING, "setCurrentSubcategory: cannot open: {0}", subpath);
}

Iterable<String> getMimeTypes() {
return getMimeType2delegates ().keySet();
/**
* @return Copy of the list of mime types sorted by display name
*/
List<String> getMimeTypes() {
List<String> mimeTypes = new ArrayList<>(getMimeType2delegates().keySet());
mimeTypes.sort(LanguagesComparator.INSTANCE);
return mimeTypes;
}

OptionsPanelController getController(String mimeType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.netbeans.api.options.OptionsDisplayer;
import org.netbeans.modules.editor.settings.storage.api.EditorSettings;
import org.netbeans.modules.options.editor.spi.PreferencesCustomizer;
import org.netbeans.modules.options.util.LanguagesComparator;
import org.netbeans.spi.options.OptionsPanelController;
import org.openide.util.WeakListeners;

Expand Down Expand Up @@ -82,7 +83,7 @@ public void setSelector(CodeCompletionOptionsSelector selector) {
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
ArrayList<String> mimeTypes = new ArrayList<String>();
mimeTypes.addAll(selector.getMimeTypes());
Collections.sort(mimeTypes, new LanguagesComparator());
Collections.sort(mimeTypes, LanguagesComparator.INSTANCE);

for (String mimeType : mimeTypes) {
model.addElement(mimeType);
Expand Down Expand Up @@ -169,17 +170,4 @@ private void languageChanged(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_
private javax.swing.JPanel panel;
// End of variables declaration//GEN-END:variables

private static final class LanguagesComparator implements Comparator<String> {
public int compare(String mimeType1, String mimeType2) {
if (mimeType1.length() == 0)
return mimeType2.length() == 0 ? 0 : -1;
if (mimeType2.length() == 0)
return 1;

String langName1 = EditorSettings.getDefault().getLanguageName(mimeType1);
String langName2 = EditorSettings.getDefault().getLanguageName(mimeType2);

return langName1.compareTo(langName2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Container class="javax.swing.JSplitPane" name="jSplitPane1">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="null"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="-1" gridY="-1" gridWidth="0" gridHeight="0" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="1.0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListCellRenderer;
Expand All @@ -43,6 +42,7 @@
import org.netbeans.modules.editor.settings.storage.api.EditorSettings;
import org.netbeans.modules.options.editor.spi.PreferencesCustomizer;
import org.netbeans.modules.options.editor.spi.PreviewProvider;
import org.netbeans.modules.options.util.LanguagesComparator;
import org.netbeans.spi.options.OptionsPanelController;
import org.openide.util.NbBundle;
import org.openide.util.WeakListeners;
Expand Down Expand Up @@ -111,7 +111,7 @@ public void setSelector(CustomizerSelector selector) {
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
ArrayList<String> mimeTypes = new ArrayList<String>();
mimeTypes.addAll(selector.getMimeTypes());
Collections.sort(mimeTypes, new LanguagesComparator());
Collections.sort(mimeTypes, LanguagesComparator.INSTANCE);

String preSelectMimeType = null;
for (String mimeType : mimeTypes) {
Expand Down Expand Up @@ -366,17 +366,4 @@ private void categoryChanged(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_
private CustomizerSelector selector;
private PropertyChangeListener weakListener;

private static final class LanguagesComparator implements Comparator<String> {
public int compare(String mimeType1, String mimeType2) {
if (mimeType1.length() == 0)
return mimeType2.length() == 0 ? 0 : -1;
if (mimeType2.length() == 0)
return 1;

String langName1 = EditorSettings.getDefault().getLanguageName(mimeType1);
String langName2 = EditorSettings.getDefault().getLanguageName(mimeType2);

return langName1.compareTo(langName2);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.netbeans.modules.options.util;

import java.util.Comparator;
import org.netbeans.modules.editor.settings.storage.api.EditorSettings;

/**
* Comparator sorting a list of mime types by their language display name
*/
public final class LanguagesComparator implements Comparator<String> {

public static final LanguagesComparator INSTANCE = new LanguagesComparator();

private LanguagesComparator() {}

@Override
public int compare(String mimeType1, String mimeType2) {
if (mimeType1.length() == 0) {
return mimeType2.length() == 0 ? 0 : -1;
}
if (mimeType2.length() == 0) {
return 1;
}
String langName1 = EditorSettings.getDefault().getLanguageName(mimeType1);
String langName2 = EditorSettings.getDefault().getLanguageName(mimeType2);
return langName1.compareTo(langName2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class EditorOptionsTest extends NbTestCase {

EditorTestLookup.setLookup(
new URL[] {
getClass().getClassLoader().getResource("org/netbeans/core/resources/mf-layer.xml"),
getClass().getClassLoader().getResource("org/netbeans/core/ui/resources/layer.xml"),
getClass().getClassLoader().getResource("org/netbeans/modules/options/editor/mf-layer.xml"),
getClass().getClassLoader().getResource("org/netbeans/modules/options/keymap/mf-layer.xml"),
getClass().getClassLoader().getResource("org/netbeans/modules/options/editor/test-layer.xml"),
Expand All @@ -67,15 +69,14 @@ public EditorOptionsTest (String testName) {

public void testPanelsRegistration () {
// there are two panels registered from this module - Editor, Fonts & Colors
// and one panel from core/options/keymap
assertEquals (3, getCategories ().size ());
// and two panels from core/options/keymap (General, Keymaps)
assertEquals (4, getCategories ().size ());
}

public void testOptionsCategories () {
for(OptionsCategory oc : getCategories()) {
assertNotNull (oc.getCategoryName ());
assertNotNull (oc.getIcon());
assertNotNull (oc.getTitle ());
assertNotNull (oc + " no category name", oc.getCategoryName ());
assertNotNull (oc + " no icon", oc.getIcon());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ ShowEffPomDiffPanel.rbConfiguration.text=By Configuration
ShowEffPomDiffPanel.rbCustom.text=By Profiles and Properties
ShowEffPomDiffPanel.lblProfiles.text=Profiles:
ShowEffPomDiffPanel.lblProperties.text=Properties:
Editors/text/x-maven-pom+xml=Maven POM
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@
</folder>
</folder>
<folder name="x-maven-pom+xml">
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.maven.grammar.Bundle"/>

<attr name="displayName" bundlevalue="org.netbeans.modules.maven.grammar.Bundle#Editors/text/x-maven-pom+xml"/>
<folder name="CodeTemplates">
<folder name="Defaults">
<file name="org-netbeans-modules-maven-grammar-CodeTemplates.xml" url="POM-abbreviations.xml"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ final Set<String> getKeywordsByCategory() {
return Collections.emptySet();
}
}

@Override
public String toString() {
return "OptionsCategoryImpl{" + "title=" + title + ", categoryName=" + categoryName + ", iconBase=" + iconBase + ", icon=" + icon + ", controller=" + controller + ", keywords=" + keywords + ", keywordsCategory=" + keywordsCategory + ", advancedOptionsFolder=" + advancedOptionsFolder + '}';
}
}

0 comments on commit 7f4b816

Please sign in to comment.