You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by tm...@apache.org on 2021/03/28 05:49:40 UTC

[netbeans] branch master updated: [NETBEANS-5350] Improved Fix Uses dialog

This is an automated email from the ASF dual-hosted git repository.

tmysik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 06ce1cb  [NETBEANS-5350] Improved Fix Uses dialog
     new f285c4c  Merge pull request #2755 from KacerCZ/netbeans-5350-fix-uses-dialog
06ce1cb is described below

commit 06ce1cbde4fc9b3f9c8e8c99db9a8f7f7e031fba
Author: Tomas Prochazka <ka...@razdva.cz>
AuthorDate: Wed Feb 10 19:59:38 2021 +0100

    [NETBEANS-5350] Improved Fix Uses dialog
    
    https://issues.apache.org/jira/browse/NETBEANS-5350
    
    Added buttons "Clear Suggestions" and "Restore Defaults" to Fix Uses dialog.
---
 .../modules/php/editor/actions/Bundle.properties   | 12 ++---
 .../editor/actions/FixDuplicateImportStmts.java    | 61 ++++++++++++++++++++++
 .../modules/php/editor/actions/FixUsesAction.java  |  4 +-
 .../php/editor/actions/ImportDataCreator.java      |  2 +-
 .../testImportData_01.php.importData               | 10 ++--
 .../testImportData_02.php.importData               |  8 +--
 .../testImportData_03.php.importData               |  8 +--
 .../testImportData_04.php.importData               |  4 +-
 .../testImportData_05.php.importData               | 12 ++---
 .../testImportData_06.php.importData               | 10 ++--
 .../testImportData_07.php.importData               |  2 +-
 .../testImportData_issue227304.php.importData      |  4 +-
 .../testImportData_issue246537a.php.importData     |  2 +-
 .../testImportData_issue246537b.php.importData     |  2 +-
 14 files changed, 101 insertions(+), 40 deletions(-)

diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/actions/Bundle.properties b/php/php.editor/src/org/netbeans/modules/php/editor/actions/Bundle.properties
index dcbdbba..a5ffbf7 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/actions/Bundle.properties
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/actions/Bundle.properties
@@ -33,14 +33,14 @@ ImportChoices=Import choices:
 ToggleCommentAction_shortDescription=Toggle Comment
 toggle-comment=Toggle Comment
 
-FixDupImportStmts_Title=Fix Uses in Current Namespace
-FixDupImportStmts_IntroLbl=<html>Select the fully qualified name to use in the use statement.</html>
-FixDupImportStmts_Header=Use Statements:
+FixDupImportStmts_Title=Fix Imports in Current Namespace
+FixDupImportStmts_IntroLbl=<html>Select the fully qualified name to import.</html>
+FixDupImportStmts_Header=Import:
 FixDupImportStmts_Combo_ACSD=Choose appropriate fully qualified name
 FixDupImportStmts_Combo_Name_ACSD=Fully Qualified Names
-FixDupImportStmts_UnusedImports=&Remove unused uses
+FixDupImportStmts_UnusedImports=&Remove unused imports
 FixDupImportStmts_CannotResolve=<html><font color='#FF0000'>&lt;cannot be resolved&gt;
 FixDupImportStmts_NothingToFix=<nothing to fix>
-FixDupImportStmts_checkUnusedImports_a11y=Remove unused uses checkbox
+FixDupImportStmts_checkUnusedImports_a11y=Remove unused imports checkbox
 
-Actions/Source/org-netbeans-modules-php-editor-actions-FixUsesAction$GlobalAction.instance=Fix Uses...
\ No newline at end of file
+Actions/Source/org-netbeans-modules-php-editor-actions-FixUsesAction$GlobalAction.instance=Fix Imports...
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/actions/FixDuplicateImportStmts.java b/php/php.editor/src/org/netbeans/modules/php/editor/actions/FixDuplicateImportStmts.java
index ba772cc..5cf2abd 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/actions/FixDuplicateImportStmts.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/actions/FixDuplicateImportStmts.java
@@ -28,18 +28,22 @@ import java.awt.GridBagLayout;
 import java.awt.Insets;
 import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.FocusEvent;
 import java.awt.event.FocusListener;
 import java.awt.event.KeyEvent;
 import java.util.ArrayList;
 import java.util.List;
 import javax.swing.AbstractAction;
+import javax.swing.Box;
 import javax.swing.Icon;
 import javax.swing.InputMap;
+import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
 import javax.swing.JLabel;
 import javax.swing.JList;
+import javax.swing.JPanel;
 import javax.swing.KeyStroke;
 import javax.swing.ListCellRenderer;
 import javax.swing.UIManager;
@@ -57,6 +61,8 @@ import org.openide.util.NbBundle;
 public class FixDuplicateImportStmts extends javax.swing.JPanel {
     private JComboBox[] combos;
     private JCheckBox checkUnusedImports;
+    private ItemVariant[] defaultVariants;
+    private ItemVariant[] dontUseVariants;
 
     public FixDuplicateImportStmts() {
         initComponents();
@@ -64,6 +70,7 @@ public class FixDuplicateImportStmts extends javax.swing.JPanel {
 
     public void initPanel(ImportData importData, boolean removeUnusedImports) {
         initComponentsMore(importData, removeUnusedImports);
+        initButtons(importData);
         setAccessible();
     }
 
@@ -147,6 +154,60 @@ public class FixDuplicateImportStmts extends javax.swing.JPanel {
         return NbBundle.getMessage(FixDuplicateImportStmts.class, s);
     }
 
+    @NbBundle.Messages({
+        "ClearSuggestionsButton=&Clear Suggestions",
+        "RestoreDefaultsButton=Restore &Defaults"
+    })
+    private void initButtons(ImportData importData) {
+        int numberOfItems = importData.getItems().size();
+        defaultVariants = new ItemVariant[numberOfItems];
+        dontUseVariants = new ItemVariant[numberOfItems];
+        for (int i = 0; i < numberOfItems; i++) {
+            DataItem dataItem = importData.getItems().get(i);
+            defaultVariants[i] = dataItem.getDefaultVariant();
+            dontUseVariants[i] = dataItem.getDefaultVariant();
+            for (ItemVariant variant : dataItem.getVariants()) {
+                if (!variant.canBeUsed()) {
+                    dontUseVariants[i] = variant;
+                }
+            }
+        }
+
+        bottomPanel.add(Box.createHorizontalStrut(150));
+
+        JPanel buttonsPanel = new JPanel(new BorderLayout(5, 3));
+        bottomPanel.add(buttonsPanel, BorderLayout.LINE_END);
+
+        JButton changeNothingButton = new JButton();
+        Mnemonics.setLocalizedText(changeNothingButton, Bundle.ClearSuggestionsButton());
+        changeNothingButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent evt) {
+                deselectAllButtonActionPerformed(evt);
+            }
+        });
+        buttonsPanel.add(changeNothingButton, BorderLayout.LINE_START);
+
+        JButton restoreDefaultsButton = new JButton();
+        Mnemonics.setLocalizedText(restoreDefaultsButton, Bundle.RestoreDefaultsButton());
+        restoreDefaultsButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent evt) {
+                restoreDefaultsButtonActionPerformed(evt);
+            }
+        });
+        buttonsPanel.add(restoreDefaultsButton, BorderLayout.LINE_END);
+    }
+
+    private void deselectAllButtonActionPerformed(ActionEvent evt) {
+        for (int i = 0; i < combos.length; i++) {
+            combos[i].setSelectedItem(dontUseVariants[i]);
+        }
+    }
+
+    private void restoreDefaultsButtonActionPerformed(ActionEvent evt) {
+        for (int i = 0; i < combos.length; i++) {
+            combos[i].setSelectedItem(defaultVariants[i]);
+        }
+    }
 
     private void setAccessible() {
         getAccessibleContext().setAccessibleDescription(getBundleString("FixDupImportStmts_IntroLbl")); // NOI18N
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/actions/FixUsesAction.java b/php/php.editor/src/org/netbeans/modules/php/editor/actions/FixUsesAction.java
index 4dc31ed..076d077 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/actions/FixUsesAction.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/actions/FixUsesAction.java
@@ -64,8 +64,8 @@ import org.openide.util.RequestProcessor;
  * @author Ondrej Brejla <ob...@netbeans.org>
  */
 @Messages({
-    "FixUsesLabel=Fix Uses...",
-    "LongName=Fix Uses in Current Namespace"
+    "FixUsesLabel=Fix Imports...",
+    "LongName=Fix Imports in Current Namespace"
 })
 @EditorActionRegistration(
     name = FixUsesAction.ACTION_NAME,
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/actions/ImportDataCreator.java b/php/php.editor/src/org/netbeans/modules/php/editor/actions/ImportDataCreator.java
index bba0181..5096654 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/actions/ImportDataCreator.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/actions/ImportDataCreator.java
@@ -49,7 +49,7 @@ import org.openide.util.NbBundle;
  *
  * @author Ondrej Brejla <ob...@netbeans.org>
  */
-@NbBundle.Messages("DoNotUseType=Don't use type.")
+@NbBundle.Messages("DoNotUseType=Don't import.")
 public class ImportDataCreator {
     public static final String NS_SEPARATOR = "\\"; //NOI18N
     private final Map<String, List<UsedNamespaceName>> usedNames;
diff --git a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_01.php.importData b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_01.php.importData
index 9de13c7..e8e931f 100644
--- a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_01.php.importData
+++ b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_01.php.importData
@@ -16,18 +16,18 @@ Names:
 
 Variants:
  \Nette\Utils\Arrays
- Don't use type.
+ Don't import.
 
  \Nette\Utils\Html
- Don't use type.
+ Don't import.
 
  \Nette\Application\UI\Presenter
- Don't use type.
+ Don't import.
 
  \Nette\Application\Request
  \Nette\Http\Request
- Don't use type.
+ Don't import.
 
  \Nette\Utils\Strings
- Don't use type.
+ Don't import.
 
diff --git a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_02.php.importData b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_02.php.importData
index bfc577b..2805400 100644
--- a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_02.php.importData
+++ b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_02.php.importData
@@ -16,17 +16,17 @@ Names:
 
 Variants:
  \Nette\Utils\Arrays
- Don't use type.
+ Don't import.
 
  <html><font color='#FF0000'>&lt;cannot be resolved&gt;
 
  \Nette\Utils\Html
- Don't use type.
+ Don't import.
 
  \Nette\Application\Request
  \Nette\Http\Request
- Don't use type.
+ Don't import.
 
  \Nette\Utils\Strings
- Don't use type.
+ Don't import.
 
diff --git a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_03.php.importData b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_03.php.importData
index 5718fc8..4fd3ae7 100644
--- a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_03.php.importData
+++ b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_03.php.importData
@@ -14,15 +14,15 @@ Names:
 
 Variants:
  \Nette\Utils\Html
- Don't use type.
+ Don't import.
 
  \Nette\Application\UI\Presenter
- Don't use type.
+ Don't import.
 
  \Nette\Application\Request
  \Nette\Http\Request
- Don't use type.
+ Don't import.
 
  \Nette\Utils\Strings
- Don't use type.
+ Don't import.
 
diff --git a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_04.php.importData b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_04.php.importData
index ebfe634..cead90a 100644
--- a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_04.php.importData
+++ b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_04.php.importData
@@ -10,9 +10,9 @@ Names:
 
 Variants:
  \Nette\Application\UI\Presenter
- Don't use type.
+ Don't import.
 
  \Nette\Application\Request
  \Nette\Http\Request
- Don't use type.
+ Don't import.
 
diff --git a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_05.php.importData b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_05.php.importData
index defd088..0effac5 100644
--- a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_05.php.importData
+++ b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_05.php.importData
@@ -5,7 +5,7 @@ Defaults:
  \Nette\Application\UI\Presenter
  \Nette\Http\Request
  \Nette\Utils\Strings
- Don't use type.
+ Don't import.
 
 Names:
  Html
@@ -16,18 +16,18 @@ Names:
 
 Variants:
  \Nette\Utils\Html
- Don't use type.
+ Don't import.
 
  \Nette\Application\UI\Presenter
- Don't use type.
+ Don't import.
 
  \Nette\Application\Request
  \Nette\Http\Request
- Don't use type.
+ Don't import.
 
  \Nette\Utils\Strings
- Don't use type.
+ Don't import.
 
  \Nette\Utils\Arrays
- Don't use type.
+ Don't import.
 
diff --git a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_06.php.importData b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_06.php.importData
index 24b7a2a..f9359c4 100644
--- a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_06.php.importData
+++ b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_06.php.importData
@@ -16,18 +16,18 @@ Names:
 
 Variants:
  \Nette\Utils\Html
- Don't use type.
+ Don't import.
 
  \Nette\Application\UI\Presenter
- Don't use type.
+ Don't import.
 
  \Nette\Application\Request
  \Nette\Http\Request
- Don't use type.
+ Don't import.
 
  \Nette\Utils\Strings
- Don't use type.
+ Don't import.
 
  \Nette\Utils\Arrays
- Don't use type.
+ Don't import.
 
diff --git a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_07.php.importData b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_07.php.importData
index a6f478f..09c57c1 100644
--- a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_07.php.importData
+++ b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_07.php.importData
@@ -8,5 +8,5 @@ Names:
 
 Variants:
  \GlobalClass
- Don't use type.
+ Don't import.
 
diff --git a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_issue227304.php.importData b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_issue227304.php.importData
index a7dd0f5..39fc03d 100644
--- a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_issue227304.php.importData
+++ b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_issue227304.php.importData
@@ -1,7 +1,7 @@
 Caret position: 34
 Should show uses panel: true
 Defaults:
- Don't use type.
+ Don't import.
 
 Names:
  MyClass
@@ -9,5 +9,5 @@ Names:
 Variants:
  \Three\MyClass
  \Two\MyClass
- Don't use type.
+ Don't import.
 
diff --git a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_issue246537a.php.importData b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_issue246537a.php.importData
index fb11cd0..aab94ac 100644
--- a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_issue246537a.php.importData
+++ b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_issue246537a.php.importData
@@ -9,5 +9,5 @@ Names:
 Variants:
  \One\MyTrait
  \Two\MyTrait
- Don't use type.
+ Don't import.
 
diff --git a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_issue246537b.php.importData b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_issue246537b.php.importData
index 21f3b22..0c8f3ef 100644
--- a/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_issue246537b.php.importData
+++ b/php/php.editor/test/unit/data/testfiles/actions/testImportData/testImportData_issue246537b.php.importData
@@ -9,5 +9,5 @@ Names:
 Variants:
  \One\MyTrait
  \Two\MyTrait
- Don't use type.
+ Don't import.
 

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists