LookAndFeel::drawFileBrowserRow request


#1

I need the file when drawing the file-browser row, to provide some extra information.
(Actually its some kind of selection state, but not that one which is done via the mouse)

Any i idea how to get it? If not i would request an extra parameter, just a reference or pointer to the file-object in drawFileBrowserRow().
The file-object already exists when the routine is called, so there is no overhead.

Alternatively it would be okay, if there is some virtual method in FileTreeComponent which could be overridden to draw the file browser row (which has access to the file object)


#2

Any idea how to get the current File() inside LookAndFeel::drawFileBrowserRow? (bump :wink: )


#3

Can’t you get it from the index and the DirectoryContentsDisplayComponent object?


#4

no, the index, is relative to the parent folder and always begins with 0. The DirectoryContentsDisplayComponent only provides a function to get the current selected file, but i need the File() which is currently repainted, regardless if its selected.

Basically instead the filename-parameter, pass the File reference, this would be also future proof, for whatever file-property somebody needs.

BTW:
I see the LookAndFeel_V4::drawFileBrowserRow uses some tricks (dynamic_cast) to access other values as well, but i can’t think if there is a way to get the current File(), but this maybe a good opportunity to change the implementation so that dynamic_cast isn’t required anymore.


#5

I would like to access the File() object inside LookAndFeel::drawFileBrowserRow :wink: (bump no.2)


#6

I really need that.


#7

I’ve made this public:
DirectoryContentsDisplayComponent::directoryContentsList

so you should be able to use that to find out everything about the file at that index


#8

Thank you very much for your effort, but i still have a problem.

The index which is provided is the index of the parents-content-list, and the DirectoryContentList provided by the LookFeelClass is the FileTreeComponent, so i can’t get the nested files from this information.

	void drawFileBrowserRow(Graphics& g, int width, int height,
		const String& filename, Image* icon,
		const String& fileSizeDescription,
		const String& fileTimeDescription,
		const bool isDirectory, const bool isItemSelected,
		const int itemIndex, DirectoryContentsDisplayComponent& dcc) override
	{
		
		
		LookAndFeel_V2::drawFileBrowserRow(g, width, height, String(itemIndex) + ":" + dcc.directoryContentsList.getFile(itemIndex).getFileName(), icon,
			fileSizeDescription, fileTimeDescription,
			isDirectory, isItemSelected, itemIndex, dcc);
	}


#9

Any idea how this can be solved?


#10

If you want to get the files nested under the file returned by DirectoryContentsList::getFile() can’t you just call File::findChildFiles() on it?


#11

No,

Actually my request is very simple

I need access to that one File() Object which will drawn with this method

void drawFileBrowserRow(Graphics& g, int width, int height,
	const String& filename, Image* icon,
	const String& fileSizeDescription,
	const String& fileTimeDescription,
	const bool isDirectory, const bool isItemSelected,
	const int itemIndex, DirectoryContentsDisplayComponent& dcc) override

The itemIndex refers to the parent Directory, the DirectoryContentsDisplayComponent refers to the root FileTreeComponent.
So with this information it is impossible to get the current File() Object which will be redrawn.

This is the routine in FileListTreeItem, which calls the method

    void paintItem (Graphics& g, int width, int height) override
{
    if (file != File())
    {
        updateIcon (true);

        if (icon.isNull())
            thread.addTimeSliceClient (this);
    }

    owner.getLookAndFeel().drawFileBrowserRow (g, width, height,
                                               file.getFileName(),
                                               &icon, fileSize, modTime,
                                               isDirectory, isSelected(),
                                               indexInContentsList, owner);
}

#12

The problem is that the directoryContentsList only refers to the root directory, but in a FileTreeComponent there are sub-contents lists too. (see screenshots above)

The straightforward solution is just add the File() parameter to the LookAndFeel method.

Or alternative the sub-contents list as a parameter.


#13

Bump


#14

I’m still hoping that access to the File() Object will be implemented in the LookAndFeel Method.
I think there a lot of use-cases for it, for example somebody wants to show special file-attributes etc.


#15

Alright, alright! Will be on develop shortly! :slight_smile: