Suggestion [Code] FileTreeComponent - showFileExtension

Because I’m using the FileTreeComponent as a comfortable preset-browser (which reflects the preset-structure on disc), i would like to have the option to hide file-extensions.

All you need is to insert in juce_FileTreeComponent.h

   void setShowFileExtension(bool showExtension)
	{
		if (showFileExtension!=showExtension)
		{
			showFileExtension=showExtension;
			repaint();
		}
	}

	bool getShowFileExtension()
	{
		return showFileExtension;
	}
......
private:
......
	bool showFileExtension;

change these three lines in juce_FileTreeComponent.h


  //FileListTreeItem::paintItem 
  void paintItem (Graphics& g, int width, int height)
    {
        if (file != File::nonexistent)
        {
            updateIcon (true);
            if (icon.isNull())
                thread.addTimeSliceClient (this);
        }
			
		String filename(owner.getShowFileExtension() ? file.getFileName() : file.getFileNameWithoutExtension());		// New ############

      owner.getLookAndFeel().drawFileBrowserRow (g, width, height,
                                                   filename,														   // Changed  ###########
                                                   &icon, fileSize, modTime,						
                                                   isDirectory, isSelected(),
                                                   indexInContentsList, owner);
    }
....
FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
    : DirectoryContentsDisplayComponent (listToShow)
	, showFileExtension(true)                                                                             // New ###############

jules, could you please add these few lines…

I don’t really want to get into “feature creep” with that class, and keep adding little methods. It might be smarter to add a virtual method to format the file name, so you could override it and do whatever’s necessary?

Yes! thats OK too ! :slight_smile: And btw a option to hide the Icon/the tree structrure, would be also fine…) thanks…

You know… I think a better approach might just be to override LookAndFeel::drawFileBrowserRow().

ehhmm yes!