AirGuanZ / imgui-filebrowser

File browser implementation for dear-imgui. C++17 is required.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Double-click file selection

Getshi opened this issue · comments

commented

Hi, nice filebrowser!
For single file selection it would be nice to be able to double click a file to open it.

An incomplete solution is doing something like

if (IsItemClicked(0) && IsMouseDoubleClicked(0)) {
    if(rsc.isDir)
    {
        setNewPwd = true;
        newPwd = (rsc.name != "..") ? (pwd_ / rsc.name) :
                                    pwd_.parent_path();
    } else if (selected && !(flags_ & ImGuiFileBrowserFlags_SelectDirectory)) { // double click on file
        ok_ = true;
        CloseCurrentPopup();
    }
}

but that only works for double-clicking a non-selected file. Double-clicking an already selected file deselect and forgets the file with the first click.

Thanks for your suggestion!
I have added your solution to the newest version with a slight modification (to support already-selected file).

commented

Thanks, seems to work wonderfully!
FYI, I have to add #include <algorithm> such that the compiler does not complain about std::sort. If you want I can open a separate issue.

Fixed. Tks!