question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IDE Creates Multiple Folders as File Path is Being Typed

See original GitHub issue

Apache NetBeans version

Apache NetBeans 13

What happened

While trying to create a new PHP class, I was typing the location where the class will be created. As I was typing, The IDE created multiple folders that I Don’t need.

Expected to happen

Only the folders that hold the class should be created.

How to reproduce

  • Created new PHP Application
  • Created new folder with name src
  • Right-clicked on the folder and selected New > PHP Class...
  • Entered File as class name, typed src/webfiori/framework as Folder and, webfiori\framework as namespace
  • As typing the folder name, the IDE will start by creating folders.

Did this work correctly in an earlier version?

Not Sure

Operating System

Windows 10 version 10.0 running on amd64; Cp1252; en_US (nb)

JDK

Java: 15.0.2; OpenJDK 64-Bit Server VM 15.0.2+7-27

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

Here is an image that shows the created folders.

image

Are you willing to submit a pull request?

No

Code of Conduct

Yes

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
junichi11commented, May 11, 2022

@tmysik My idea is the following. It’s ugly hack… What do you think?

diff --git a/php/php.project/src/org/netbeans/modules/php/project/ui/wizards/NewFileWizardIterator.java b/php/php.project/src/org/netbeans/modules/php/project/ui/wizards/NewFileWizardIterator.java
index 28a83c1aaf..77a9044a54 100644
--- a/php/php.project/src/org/netbeans/modules/php/project/ui/wizards/NewFileWizardIterator.java
+++ b/php/php.project/src/org/netbeans/modules/php/project/ui/wizards/NewFileWizardIterator.java
@@ -20,6 +20,7 @@ package org.netbeans.modules.php.project.ui.wizards;
 
 import java.awt.Component;
 import java.awt.EventQueue;
+import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
@@ -31,6 +32,8 @@ import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.swing.JComponent;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 import org.netbeans.api.annotations.common.CheckForNull;
@@ -53,7 +56,6 @@ import org.openide.WizardDescriptor.Panel;
 import org.openide.filesystems.FileObject;
 import org.openide.loaders.DataFolder;
 import org.openide.loaders.DataObject;
-import org.openide.util.RequestProcessor;
 
 public final class NewFileWizardIterator implements WizardDescriptor.AsynchronousInstantiatingIterator<WizardDescriptor> {
 
@@ -61,47 +63,14 @@ public final class NewFileWizardIterator implements WizardDescriptor.Asynchronou
 
     private static final Logger LOGGER = Logger.getLogger(NewFileWizardIterator.class.getName());
 
-    private static final RequestProcessor RP = new RequestProcessor(NewFileWizardIterator.class);
-
     private final BottomPanel bottomPanel;
-    final RequestProcessor.Task setTargetFolderTask;
-
     private WizardDescriptor wizard;
     private PhpProject phpProject;
     private WizardDescriptor.Panel<WizardDescriptor>[] wizardPanels;
     private int index;
-    // @GuardedBy("EDT")
-    WizardDescriptor.Panel<WizardDescriptor> simpleTargetChooserPanel;
-
 
     private NewFileWizardIterator(BottomPanel bottomPanel) {
         this.bottomPanel = bottomPanel;
-        if (bottomPanel != null) {
-            setTargetFolderTask = RP.create(new Runnable() {
-                @Override
-                public void run() {
-                    EventQueue.invokeLater(new Runnable() {
-                        @Override
-                        public void run() {
-                            assert EventQueue.isDispatchThread();
-                            final WizardDescriptor.Panel<WizardDescriptor> simpleTargetChooserPanelRef = simpleTargetChooserPanel;
-                            if (simpleTargetChooserPanelRef == null) {
-                                // #241005 - already uninitialized
-                                return;
-                            }
-                            WizardDescriptor descriptor = new DummyWizardDescriptor();
-                            assert simpleTargetChooserPanelRef != null;
-                            simpleTargetChooserPanelRef.storeSettings(descriptor);
-                            BottomPanel bottomPanelForPhpProject = getBottomPanelForPhpProject();
-                            assert bottomPanelForPhpProject != null;
-                            bottomPanelForPhpProject.targetFolderChanged(Templates.getTargetFolder(descriptor));
-                        }
-                    });
-                }
-            });
-        } else {
-            setTargetFolderTask = null;
-        }
     }
 
     public static NewFileWizardIterator simple() {
@@ -215,7 +184,6 @@ public final class NewFileWizardIterator implements WizardDescriptor.Asynchronou
     @Override
     public void uninitialize(WizardDescriptor wizard) {
         wizardPanels = null;
-        simpleTargetChooserPanel = null;
     }
 
     @Override
@@ -332,16 +300,39 @@ public final class NewFileWizardIterator implements WizardDescriptor.Asynchronou
             targetChooserBuilder
                     .bottomPanel(bottomPanelForPhpProject);
         }
-        simpleTargetChooserPanel = targetChooserBuilder
+        final WizardDescriptor.Panel<WizardDescriptor> simpleTargetChooserPanel = targetChooserBuilder
                 .freeFileExtension()
                 .create();
         if (bottomPanelForPhpProject != null) {
-            // #240917 hack - it is not possible to listen on panel (name and location)
             simpleTargetChooserPanel.addChangeListener(new ChangeListener() {
                 @Override
                 public void stateChanged(ChangeEvent e) {
-                    assert setTargetFolderTask != null;
-                    setTargetFolderTask.schedule(300);
+                    // #240917 hack - it is not possible to listen on panel (name and location)
+                    // GH #4099 ugly hack
+                    Component component = simpleTargetChooserPanel.getComponent();
+                    if (component instanceof JPanel) {
+                        // SimpleTargetChooserPanelGUI
+                        JPanel panel = (JPanel) component;
+                        for (Component c : panel.getComponents()) {
+                            if (c instanceof JTextField) {
+                                JTextField textField = (JTextField) c;
+                                if (!textField.isEditable()) {
+                                    String text = textField.getText();
+                                    if (text != null && text.endsWith(".php")) { // NOI18N
+                                        File file = new File(text);
+                                        File parent = file.getParentFile();
+                                        if (parent == null || !parent.exists()) {
+                                            return;
+                                        }
+                                        break;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    WizardDescriptor descriptor = new DummyWizardDescriptor();
+                    simpleTargetChooserPanel.storeSettings(descriptor);
+                    bottomPanelForPhpProject.targetFolderChanged(Templates.getTargetFolder(descriptor));
                 }
             });
         }

Get the “Created File” text field: nb-php-gh4099

1reaction
junichi11commented, May 12, 2022

@tmysik Sure 😃 Will create it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

File type associations | IntelliJ IDEA Documentation - JetBrains
Configure the IDE to recognize different file types and open files of certain types in IntelliJ IDEA by default.
Read more >
Working with the IDE file browser | Looker - Google Cloud
The Looker IDE supports folders for your project files. Folders are shown in the left navigation pane of the IDE. If your Looker...
Read more >
3 Ways to Create Multiple Folders at Once in Windows 10 & 11
1. Use Command Prompt to Create Multiple Folders at Once · Type Command Prompt in Windows search and click on Run as administrator....
Read more >
Multi-root Workspaces in Visual Studio Code
Opening multiple folders with your platform's native file open dialog will create a multi-root workspace. command line --add. Add a folder or multiple...
Read more >
c# - Create files in multiple folders - Stack Overflow
This code finds the current user's desktop path, and then uses System.IO.Path.Combine to ensure that paths are correctly concatenated together.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found