Skip to content

Commit d00c1cb

Browse files
committed
[IMP] : improvment of device view. add the device name displayed only
1 parent bb6809a commit d00c1cb

2 files changed

Lines changed: 53 additions & 30 deletions

File tree

ImGuiFileDialog.cpp

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,9 @@ class FileSystemStd : public IGFD::IFileSystem {
467467
}
468468
return res;
469469
}
470-
std::vector<std::string> GetDrivesList() override {
471-
std::vector<std::string> res;
470+
471+
std::vector<std::pair<std::string, std::string> > GetDevicesList() override {
472+
std::vector<std::pair<std::string, std::string> > res;
472473
#ifdef _IGFD_WIN_
473474
const DWORD mydrives = 2048;
474475
char lpBuffer[2048];
@@ -478,7 +479,18 @@ class FileSystemStd : public IGFD::IFileSystem {
478479
if (countChars > 0U && countChars < 2049U) {
479480
std::string var = std::string(lpBuffer, (size_t)countChars);
480481
IGFD::Utils::ReplaceString(var, "\\", "");
481-
res = IGFD::Utils::SplitStringToVector(var, '\0', false);
482+
auto arr = IGFD::Utils::SplitStringToVector(var, '\0', false);
483+
wchar_t szVolumeName[2048];
484+
std::pair<std::string, std::string> path_name;
485+
for (auto& a : arr) {
486+
path_name.first = a;
487+
path_name.second.clear();
488+
std::wstring wpath = IGFD::Utils::UTF8Decode(a);
489+
if (GetVolumeInformationW(wpath.c_str(), szVolumeName, 2048, NULL, NULL, NULL, NULL, 0)) {
490+
path_name.second = IGFD::Utils::UTF8Encode(szVolumeName);
491+
}
492+
res.push_back(path_name);
493+
}
482494
}
483495
#endif // _IGFD_WIN_
484496
return res;
@@ -623,8 +635,8 @@ class FileSystemDirent : public IGFD::IFileSystem {
623635
return res;
624636
}
625637

626-
std::vector<std::string> GetDrivesList() override {
627-
std::vector<std::string> res;
638+
std::vector<std::pair<std::string, std::string>> GetDevicesList() override {
639+
std::vector<std::pair<std::string, std::string>> res;
628640
#ifdef _IGFD_WIN_
629641
const DWORD mydrives = 2048;
630642
char lpBuffer[2048];
@@ -634,7 +646,18 @@ class FileSystemDirent : public IGFD::IFileSystem {
634646
if (countChars > 0U && countChars < 2049U) {
635647
std::string var = std::string(lpBuffer, (size_t)countChars);
636648
IGFD::Utils::ReplaceString(var, "\\", "");
637-
res = IGFD::Utils::SplitStringToVector(var, '\0', false);
649+
auto arr = IGFD::Utils::SplitStringToVector(var, '\0', false);
650+
wchar_t szVolumeName[2048];
651+
std::pair<std::string, std::string> path_name;
652+
for (auto& a : arr) {
653+
path_name.first = a;
654+
path_name.second.clear();
655+
std::wstring wpath = IGFD::Utils::UTF8Decode(a);
656+
if (GetVolumeInformationW(wpath.c_str(), szVolumeName, 2048, NULL, NULL, NULL, NULL, 0)) {
657+
path_name.second = IGFD::Utils::UTF8Encode(szVolumeName);
658+
}
659+
res.push_back(path_name);
660+
}
638661
}
639662
#endif // _IGFD_WIN_
640663
return res;
@@ -1971,15 +1994,16 @@ void IGFD::FileManager::m_OpenPathPopup(const FileDialogInternal& vFileDialogInt
19711994
}
19721995

19731996
bool IGFD::FileManager::GetDrives() {
1974-
auto drives = m_FileSystemPtr->GetDrivesList();
1997+
auto drives = m_FileSystemPtr->GetDevicesList();
19751998
if (!drives.empty()) {
19761999
m_CurrentPath.clear();
19772000
m_CurrentPathDecomposition.clear();
19782001
ClearFileLists();
19792002
for (auto& drive : drives) {
19802003
auto info = std::make_shared<FileInfos>();
1981-
info->fileNameExt = drive;
1982-
info->fileNameExt_optimized = Utils::LowerCaseString(drive);
2004+
info->fileNameExt = drive.first;
2005+
info->fileNameExt_optimized = Utils::LowerCaseString(drive.first);
2006+
info->deviceInfos = drive.second;
19832007
info->fileType.SetContent(FileType::ContentType::Directory);
19842008

19852009
if (!info->fileNameExt.empty()) {
@@ -4085,27 +4109,26 @@ void IGFD::FileDialog::m_DrawFileListView(ImVec2 vSize) {
40854109
ImGui::TableNextRow();
40864110

40874111
column_id = 0;
4088-
if (ImGui::TableNextColumn()) // file name
4089-
{
4112+
if (ImGui::TableNextColumn()) { // file name
4113+
if (!infos->deviceInfos.empty()) {
4114+
_str += " " + infos->deviceInfos;
4115+
}
40904116
m_SelectableItem(i, infos, selected, _str.c_str());
40914117
m_DisplayFileInfosTooltip(i, column_id++, infos);
40924118
}
4093-
if (ImGui::TableNextColumn()) // file type
4094-
{
4119+
if (ImGui::TableNextColumn()) { // file type
40954120
ImGui::Text("%s", infos->fileExtLevels[0].c_str());
40964121
m_DisplayFileInfosTooltip(i, column_id++, infos);
40974122
}
4098-
if (ImGui::TableNextColumn()) // file size
4099-
{
4123+
if (ImGui::TableNextColumn()) { // file size
41004124
if (!infos->fileType.isDir()) {
41014125
ImGui::Text("%s ", infos->formatedFileSize.c_str());
41024126
} else {
41034127
ImGui::TextUnformatted("");
41044128
}
41054129
m_DisplayFileInfosTooltip(i, column_id++, infos);
41064130
}
4107-
if (ImGui::TableNextColumn()) // file date + time
4108-
{
4131+
if (ImGui::TableNextColumn()) { // file date + time
41094132
ImGui::Text("%s", infos->fileModifDate.c_str());
41104133
m_DisplayFileInfosTooltip(i, column_id++, infos);
41114134
}
@@ -4273,32 +4296,31 @@ void IGFD::FileDialog::m_DrawThumbnailsListView(ImVec2 vSize) {
42734296
ImGui::TableNextRow();
42744297

42754298
column_id = 0;
4276-
if (ImGui::TableNextColumn()) // file name
4277-
{
4299+
if (ImGui::TableNextColumn()) { // file name
4300+
if (!infos->deviceInfos.empty()) {
4301+
_str += " " + infos->deviceInfos;
4302+
}
42784303
m_SelectableItem(i, infos, selected, _str.c_str());
42794304
m_DisplayFileInfosTooltip(i, column_id++, infos);
42804305
}
4281-
if (ImGui::TableNextColumn()) // file type
4282-
{
4306+
if (ImGui::TableNextColumn())
4307+
{ // file type
42834308
ImGui::Text("%s", infos->fileExtLevels[0].c_str());
42844309
m_DisplayFileInfosTooltip(i, column_id++, infos);
42854310
}
4286-
if (ImGui::TableNextColumn()) // file size
4287-
{
4311+
if (ImGui::TableNextColumn()) { // file size
42884312
if (!infos->fileType.isDir()) {
42894313
ImGui::Text("%s ", infos->formatedFileSize.c_str());
42904314
} else {
42914315
ImGui::TextUnformatted("");
42924316
}
42934317
m_DisplayFileInfosTooltip(i, column_id++, infos);
42944318
}
4295-
if (ImGui::TableNextColumn()) // file date + time
4296-
{
4319+
if (ImGui::TableNextColumn()) { // file date + time
42974320
ImGui::Text("%s", infos->fileModifDate.c_str());
42984321
m_DisplayFileInfosTooltip(i, column_id++, infos);
42994322
}
4300-
if (ImGui::TableNextColumn()) // file thumbnails
4301-
{
4323+
if (ImGui::TableNextColumn()) { // file thumbnails
43024324
auto th = &infos->thumbnailInfo;
43034325

43044326
if (!th->isLoadingOrLoaded) {

ImGuiFileDialog.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,7 @@ class IGFD_API FileInfos {
16951695
std::string fileName; // file name only
16961696
std::string fileNameExt; // filename of the file (file name + extention) (but no path)
16971697
std::string fileNameExt_optimized; // optimized for search => insensitivecase
1698+
std::string deviceInfos; // quick infos to display after name for devices
16981699
std::string tooltipMessage; // message to display on the tooltip, is not empty
16991700
int32_t tooltipColumn = -1; // the tooltip will appears only when the mouse is over the tooltipColumn if > -1
17001701
size_t fileSize = 0U; // for sorting operations
@@ -1731,14 +1732,14 @@ class IFileSystem {
17311732
virtual bool IsFileExist(const std::string& vName) = 0;
17321733
// say if a directory was created, return false if vName is invalid or alreayd exist
17331734
virtual bool CreateDirectoryIfNotExist(const std::string& vName) = 0;
1734-
// extract the component of a file apth name, like path, name, ext
1735+
// extract the component of a file path name, like path, name, ext
17351736
virtual IGFD::Utils::PathStruct ParsePathFileName(const std::string& vPathFileName) = 0;
17361737
// will return a list of files inside a path
17371738
virtual std::vector<IGFD::FileInfos> ScanDirectory(const std::string& vPath) = 0;
17381739
// say if the path is well a directory
17391740
virtual bool IsDirectory(const std::string& vFilePathName) = 0;
1740-
// return a drive list on windows, bu can be used on android or linux for give to the suer a list of root dir
1741-
virtual std::vector<std::string> GetDrivesList() = 0;
1741+
// return a device list (<path, device name>) on windows, but can be used on other platforms for give to the user a list of devices paths.
1742+
virtual std::vector<std::pair<std::string, std::string>> GetDevicesList() = 0;
17421743
};
17431744

17441745
#pragma endregion

0 commit comments

Comments
 (0)