Issue with FilenameComponent


#1

I’m noticing something strange with FilenameComponent. When I browse for a file everything works Ok. My listener method is triggered and I can retrieve the name of the file. But whenever I remove all text from the FilenameComponent, and hit return, FIlenameComponent::getCurrentFileText() return the previous file’s parent directory, minus the last file name. My FilenameComponent is a child of a PropertyComponent in case that makes any difference. Anyone got any ideas?

Here’s two simple files that you can drop into a jucer project that illustrate the problem.
MainComponent.cpp (1.0 KB)
MainComponent.h (1.8 KB)


#2

Should I change this from ‘issue’ to ‘bug’?


#3

Sorry to bump, but as usual, I only wish to know if this is expected behaviour. If so I’ll look for a workaround. If not I’ll wait for a fix.


#4

Hmmm… not really sure if this is intended or a bug. If you press backspace and then type in a name, it changes the subpath of the last parent path which does seem useful. It could be that some apps rely on this behaviour. Jules?


#5

I get that getCurrentFile() should always returns a file, but the docs state that getCurrentFileText() “Returns the raw text that the user has entered.” So I’m kind of confused again.


#6

Well for me it always returns the text that is in the combo box text field. The FilenameComponent will immediately modify what ever the user enters - so I think the behaviour is expected. Maybe the documentation should say “Returns the raw text of the combo box text field” or similar…


#7

For me it doesn’t always return what is in the combobox. If I remove all the text from the combobox getCurrentFileText() still returns some text. In the following screencast I browse for a file. Then I remove all text and hit return. As you can see from the Logger output in the terminal, although the combobox is now empty, I still get text returned. This doesn’t happen when you try it?


#8

I’m also seeing some odd behaviour here…

In my ctor I initialize it as:

m_PathComp ("PathComp", String(), false, true, true, String(), String(), String())

in my init list.

I then add the recent paths to the FilenameComponent:

String szLastPath = getAppProperties().getUserSettings()->getValue ("SaveOptionsRecentFile1", String());

m_PathComp.setCurrentFile (szLastPath, false, NotificationType::dontSendNotification);

for (int i = 1; i < 6; ++i)
    {
    String keyName = "SaveOptionsRecentFile" + String (i + 1);
    
    String szPath = getAppProperties().getUserSettings()->getValue (keyName, String());
    
    if (szPath.isNotEmpty())
        m_PathComp.addRecentlyUsedFile (File (szPath));
    }

but when filenameBox is cleared it triggers an AsynchUpdate which in turn triggers

void FilenameComponent::comboBoxChanged (ComboBox*)
{
    setCurrentFile (getCurrentFile(), true);
}

to be called which adds the current working directory to the comboBox (which isn’t desired).

Thanks,

Rail


#9

Okay…

Changing my second param to true fixes it…

m_PathComp.setCurrentFile (szLastPath, true, NotificationType::dontSendNotification);

Rail