Skip to content

Commit

Permalink
[UPD] : update for the last ImGuiFileDialog and the new places system
Browse files Browse the repository at this point in the history
  • Loading branch information
aiekick committed Feb 21, 2024
1 parent e911033 commit 62f75b1
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 40 deletions.
146 changes: 125 additions & 21 deletions src/Gui/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@

#include <Res/CustomFont.h>

#if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) || defined(__WIN64__) || defined(WIN64) || defined(_WIN64) || defined(_MSC_VER)
#include <ShlObj.h> // for quick acces places
#else
#endif

using namespace std::placeholders;

///////////////////////////////////////////////////////
//// STATIC ///////////////////////////////////////////
///////////////////////////////////////////////////////
Expand Down Expand Up @@ -131,6 +138,8 @@ bool MainFrame::Init() {
HelpManager::Instance()->Init("NOODLESPLATE");
UrlLibrarySystem::Instance()->Init();

m_CreateDialogPlaces();

LoadConfigFile("config.xml");

PathSystem::Instance()->Save(); // apply paths who was loaded before in LoadConfigFile
Expand Down Expand Up @@ -300,6 +309,86 @@ void MainFrame::ShowAboutDialog() {
puShowAboutDialog = true;
}

void MainFrame::m_CreateDialogPlaces() {
const char* system_group_name = ICON_NDP_STAR " System";
ImGuiFileDialog::Instance()->AddPlacesGroup(system_group_name, 1, false);
auto system_places_ptr = ImGuiFileDialog::Instance()->GetPlacesGroupPtr(system_group_name);
if (system_places_ptr != nullptr) {
#if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) || defined(__WIN64__) || defined(WIN64) || defined(_WIN64) || defined(_MSC_VER)

//////////////////////////////////////////////////
//// SYSTEM QUICK ACCESS /////////////////////////
//////////////////////////////////////////////////

#define addKnownFolderAsPlace(knownFolder, folderLabel, folderIcon) \
{ \
PWSTR path = NULL; \
HRESULT hr = SHGetKnownFolderPath(knownFolder, 0, NULL, &path); \
if (SUCCEEDED(hr)) { \
IGFD::FileStyle style; \
style.icon = folderIcon; \
auto place_path = IGFD::Utils::UTF8Encode(path); \
system_places_ptr->AddPlace(folderLabel, place_path, false, style); \
} \
CoTaskMemFree(path); \
}
addKnownFolderAsPlace(FOLDERID_Desktop, "Desktop", ICON_NDP2_DESKTOP_MAC);
addKnownFolderAsPlace(FOLDERID_Startup, "Startup", ICON_NDP2_HOME);
addKnownFolderAsPlace(FOLDERID_Downloads, "Downloads", ICON_NDP2_DOWNLOADS);
addKnownFolderAsPlace(FOLDERID_Pictures, "Pictures", ICON_NDP_PICTURE_O);
addKnownFolderAsPlace(FOLDERID_Music, "Music", ICON_NDP_MUSIC);
addKnownFolderAsPlace(FOLDERID_Videos, "Videos", ICON_NDP_VIDEO);
#undef addKnownFolderAsPlace

//////////////////////////////////////////////////
//// SYSTEM DEVICES //////////////////////////////
//////////////////////////////////////////////////

const DWORD mydrives = 2048;
char lpBuffer[2048];
#define mini(a, b) (((a) < (b)) ? (a) : (b))
const DWORD countChars = mini(GetLogicalDriveStringsA(mydrives, lpBuffer), 2047);
#undef mini
if (countChars > 0U && countChars < 2049U) {
std::string var = std::string(lpBuffer, (size_t)countChars);
IGFD::Utils::ReplaceString(var, "\\", "");
auto arr = IGFD::Utils::SplitStringToVector(var, '\0', false);
wchar_t szVolumeName[2048];
std::string path;
std::string name;
for (auto& a : arr) {
path = a;
name.clear();
std::wstring wpath = IGFD::Utils::UTF8Decode(a);
if (GetVolumeInformationW(wpath.c_str(), szVolumeName, 2048, NULL, NULL, NULL, NULL, 0)) {
name = IGFD::Utils::UTF8Encode(szVolumeName);
}
IGFD::FileStyle style;
style.icon = ICON_NDP_DRIVES;
system_places_ptr->AddPlace(path + " " + name, path + IGFD::Utils::GetPathSeparator(), false, style);
}
}
#else
#endif
system_places_ptr = nullptr;
}

const char* local_group_name = "Local";
ImGuiFileDialog::Instance()->AddPlacesGroup(local_group_name, 2, false);
auto local_places_ptr = ImGuiFileDialog::Instance()->GetPlacesGroupPtr(local_group_name);
if (local_places_ptr != nullptr) {
IGFD::FileStyle style;
style.icon = ICON_NDP_PICTURE_O;
local_places_ptr->AddPlace("Assets", "assets", false, style);
style.icon = ICON_NDP_FILE_TEXT_O;
local_places_ptr->AddPlace("Scripts", "scripts", false, style);
local_places_ptr = nullptr;
}

const char* recent_group_name = "Recent";
ImGuiFileDialog::Instance()->AddPlacesGroup(recent_group_name, 3, false);
}

void MainFrame::DrawSettingsMenu_Global() {
if (ImGui::MenuItem("Settings Dialog", "")) {
SettingsDlg::Instance()->OpenDialog();
Expand Down Expand Up @@ -765,8 +854,12 @@ void MainFrame::DrawMainMenuBar() {
}

if (ImGui::MenuItem(ICON_NDP2_FOLDER " Open")) {
ImGuiFileDialog::Instance()->OpenDialog("OpenFileDialog", "Open File", ".glsl", puOpenFileDialog.filePath, puOpenFileDialog.filePathName,
1, nullptr, ImGuiFileDialogFlags_DisableThumbnailMode | ImGuiFileDialogFlags_Modal);
IGFD::FileDialogConfig config;
config.path = puOpenFileDialog.filePath;
config.filePathName = puOpenFileDialog.filePathName;
config.countSelectionMax = 1;
config.flags = ImGuiFileDialogFlags_DisableThumbnailMode | ImGuiFileDialogFlags_Modal;
ImGuiFileDialog::Instance()->OpenDialog("OpenFileDialog", "Open File", ".glsl", config);
}

if (MainBackend::Instance()->IsLoaded()) {
Expand Down Expand Up @@ -796,9 +889,12 @@ void MainFrame::DrawMainMenuBar() {
if (ImGui::BeginMenu(ICON_NDP2_IMPORT " Import")) {
if (ImGui::BeginMenu("From File Type")) {
if (ImGui::MenuItem(".json (ShaderToy Backup File)")) {
ImGuiFileDialog::Instance()->OpenDialog("OpenShaderToyBackupJsonFile", "Open ShaderToy Backup File", ".json",
puOpenFileDialog.filePath, puOpenFileDialog.filePathName, 1, nullptr,
ImGuiFileDialogFlags_DisableThumbnailMode | ImGuiFileDialogFlags_Modal);
IGFD::FileDialogConfig config;
config.path = puOpenFileDialog.filePath;
config.filePathName = puOpenFileDialog.filePathName;
config.countSelectionMax = 1;
config.flags = ImGuiFileDialogFlags_DisableThumbnailMode | ImGuiFileDialogFlags_Modal;
ImGuiFileDialog::Instance()->OpenDialog("OpenShaderToyBackupJsonFile", "Open ShaderToy Backup File", ".json", config);
}

if (ImGui::MenuItem(".xsha (wxShade)")) {
Expand Down Expand Up @@ -826,12 +922,14 @@ void MainFrame::DrawMainMenuBar() {
if (ImGui::BeginMenu(ICON_NDP2_UPLOAD " Export")) {
if (ImGui::BeginMenu("Buffer")) {
if (ImGui::MenuItem("To Picture File")) {
ImGuiFileDialog::Instance()->OpenDialogWithPane(
"SavePictureDialog", "Save Current Buffer to Picture File", ".png,.tga,.bmp,.hdr", puSavePictureDialog.filePath,
puSavePictureDialog.filePathName,
std::bind(&PictureExportSystem::ExportPictureDialogOptions, PictureExportSystem::Instance(), std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3),
ImGuiFileDialogFlags_Modal);
IGFD::FileDialogConfig config;
config.path = puSavePictureDialog.filePath;
config.filePathName = puSavePictureDialog.filePathName;
config.countSelectionMax = 1;
config.sidePane = std::bind(&PictureExportSystem::ExportPictureDialogOptions, PictureExportSystem::Instance(), _1, _2, _3);
config.flags = ImGuiFileDialogFlags_Modal;
ImGuiFileDialog::Instance()->OpenDialog(
"SavePictureDialog", "Save Current Buffer to Picture File", ".png,.tga,.bmp,.hdr", config);
}

if (ImGui::BeginMenu("After Each Modif of Code")) {
Expand Down Expand Up @@ -899,10 +997,13 @@ void MainFrame::DrawMainMenuBar() {
auto displayShaderPtr = MainBackend::Instance()->puDisplay_RenderPack.lock();
if (displayShaderPtr && displayShaderPtr->GetShaderKey()) {
if (ImGui::MenuItem(ICON_NDP_FLOPPY_O " Save As Template")) {
ImGuiFileDialog::Instance()->OpenDialogWithPane(
"NewFileDialog", "Save As Template", ".glsl", ImGuiFileDialog::Instance()->GetCurrentPath(),
displayShaderPtr->GetShaderKey()->puKey, nullptr, 0, 1, IGFDUserDatas("saveastemplate"),
ImGuiFileDialogFlags_DisableThumbnailMode | ImGuiFileDialogFlags_Modal);
IGFD::FileDialogConfig config;
config.path = ImGuiFileDialog::Instance()->GetCurrentPath();
config.filePathName = displayShaderPtr->GetShaderKey()->puKey;
config.countSelectionMax = 1;
config.userDatas = IGFDUserDatas("saveastemplate");
config.flags = ImGuiFileDialogFlags_DisableThumbnailMode | ImGuiFileDialogFlags_Modal;
ImGuiFileDialog::Instance()->OpenDialog("NewFileDialog", "Save As Template", ".glsl", config);
}

ImGui::Separator();
Expand Down Expand Up @@ -1059,11 +1160,14 @@ void MainFrame::DrawMainMenuBar() {

void MainFrame::CreateNewShader(std::string vType, const std::string& vFilePathName) {
const auto filePathName = FileHelper::Instance()->CorrectSlashTypeForFilePathName(vFilePathName);

puNewFileDialog.tgt_ext = vType;
puNewFileDialog.filePathName = filePathName;
ImGuiFileDialog::Instance()->OpenDialog("NewFileDialog", "New File", ".glsl", puNewFileDialog.filePath, puNewFileDialog.filePathName, 1, nullptr,
ImGuiFileDialogFlags_DisableThumbnailMode | ImGuiFileDialogFlags_Modal);
IGFD::FileDialogConfig config;
config.path = puNewFileDialog.filePath;
config.filePathName = puNewFileDialog.filePathName;
config.countSelectionMax = 1;
config.flags = ImGuiFileDialogFlags_DisableThumbnailMode | ImGuiFileDialogFlags_Modal;
ImGuiFileDialog::Instance()->OpenDialog("NewFileDialog", "New File", ".glsl", config);
}

///////////////////////////////////////////////////////
Expand All @@ -1085,7 +1189,7 @@ std::string MainFrame::getXml(const std::string& vOffset, const std::string& vUs
str += puForkFileDialog.getXml(vOffset, vUserDatas);
str += vOffset + "<debug>" + ct::toStr(puShowDebug ? "true" : "false") + "</debug>\n";
str += vOffset + "<consoleguivisibility>" + ct::toStr(puConsoleGuiVisiblity ? "true" : "false") + "</consoleguivisibility>\n";
str += vOffset + "<igfd_bookmarks>" + ImGuiFileDialog::Instance()->SerializeBookmarks() + "</igfd_bookmarks>\n";
str += vOffset + "<igfd_places>" + ImGuiFileDialog::Instance()->SerializePlaces() + "</igfd_places>\n";
str += vOffset + "<consoleverbose>" + ct::toStr(Logger::Instance()->ConsoleVerbose ? "true" : "false") + "</consoleverbose>\n";
str += vOffset + "<ShaderFile>" + MainBackend::sCurrentFileLoaded + "</ShaderFile>\n";

Expand Down Expand Up @@ -1142,8 +1246,8 @@ bool MainFrame::setFromXml(tinyxml2::XMLElement* vElem, tinyxml2::XMLElement* vP
puFileToLoad = ct::fvariant(strValue).GetS();
if (strName == "debug")
puShowDebug = ct::ivariant(strValue).GetB();
if (strName == "igfd_bookmarks")
ImGuiFileDialog::Instance()->DeserializeBookmarks(strValue);
if (strName == "igfd_places")
ImGuiFileDialog::Instance()->DeserializePlaces(strValue);
}

LayoutManager::Instance()->setFromXml(vElem, vParent, vUserDatas);
Expand Down
1 change: 1 addition & 0 deletions src/Gui/MainFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class MainFrame : public conf::ConfigAbstract
void OpenImportBar(std::string vUrl = "");

private: // imgui
void m_CreateDialogPlaces();
void DrawSettingsMenu_Global(); // Settings menu Global
bool DrawImportBar();
bool DrawErrorDialog();
Expand Down
26 changes: 18 additions & 8 deletions src/Headers/CustomImGuiFileDialogConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#define DisplayMode_ThumbailsGrid_ButtonString ICON_NDP_FILE_GRID_THUMBNAILS
//#define DisplayMode_ThumbailsGrid_ButtonHelp "Thumbnails Grid"

#define USE_EXPLORATION_BY_KEYS
//#define USE_EXPLORATION_BY_KEYS
// this mapping by default is for GLFW but you can use another
// Up key for explore to the top
#define IGFD_KEY_UP ImGuiKey_UpArrow//GLFW_KEY_UP
Expand Down Expand Up @@ -121,10 +121,20 @@
#define tableHeaderFileSizeString " Size"
#define tableHeaderFileDateTimeString " Date"

#define USE_BOOKMARK
//#define bookmarkPaneWith 150.0f
//#define IMGUI_TOGGLE_BUTTON ToggleButton
#define bookmarksButtonString ICON_NDP_BOOKMARK
//#define bookmarksButtonHelpString "bookmark"
#define addBookmarkButtonString ICON_NDP_ADD
#define removeBookmarkButtonString ICON_NDP_REMOVE
#define USE_PLACES_FEATURE
// #define placesPaneWith 150.0f
// #define IMGUI_TOGGLE_BUTTON ToggleButton
#define placesButtonString ICON_NDP_BOOKMARK
// #define placesButtonHelpString "Places"
#define addPlaceButtonString ICON_NDP_ADD
#define removePlaceButtonString ICON_NDP_REMOVE

// a group for bookmarks will be added by default, but you can also create it yourself and many more
#define USE_PLACES_BOOKMARKS
// #define PLACE_BOOKMARKS_NAME "Bookmarks"
// #define PLACE_BOOKMARKS_DISPLAY_ORDER 0 // to the first

// a group for system devices (returned by IFileSystem), but you can also add yours
// #define USE_PLACES_DEVICES
// #define PLACE_DEVICES_NAME "Devices"
// #define PLACE_DEVICES_DISPLAY_ORDER 10 // to the end
4 changes: 2 additions & 2 deletions src/Headers/NoodlesPlateBuild.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#define NoodlesPlate_Prefix "NoodlesPlate"
#define NoodlesPlate_BuildNumber 696
#define NoodlesPlate_BuildNumber 708
#define NoodlesPlate_MinorNumber 7
#define NoodlesPlate_MajorNumber 0
#define NoodlesPlate_BuildId "0.7.696"
#define NoodlesPlate_BuildId "0.7.708"
9 changes: 6 additions & 3 deletions src/Systems/PathSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ std::string PathField::GetPath()

void PathField::Draw(const char* vButtonLabel)
{
if (ImGui::ContrastedButton(vButtonLabel, nullptr, nullptr, 250.0f))
{
ImGuiFileDialog::Instance()->OpenDialog(vButtonLabel, "Select path", nullptr, m_Original_Path, 1, nullptr, ImGuiFileDialogFlags_Modal);
if (ImGui::ContrastedButton(vButtonLabel, nullptr, nullptr, 250.0f)) {
IGFD::FileDialogConfig config;
config.path = m_Original_Path;
config.countSelectionMax = 1;
config.flags = ImGuiFileDialogFlags_Modal;
ImGuiFileDialog::Instance()->OpenDialog(vButtonLabel, "Select path", nullptr, config);
}

ImGui::SameLine();
Expand Down
17 changes: 12 additions & 5 deletions src/Systems/TemplateSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <SoGLSL/src/Renderer/RenderPack.h>
#include <SoGLSL/src/Uniforms/UniformVariant.h>

using namespace std::placeholders;

////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
Expand Down Expand Up @@ -253,11 +255,16 @@ bool TemplateSystem::DrawMenu()

void TemplateSystem::CopyFromTemplate(TemplateFile vTemplateFile)
{
puSelectedFileToCopy = vTemplateFile;
ImGuiFileDialog::Instance()->OpenDialogWithPane("NewFileDialog", "New File from template", ".glsl",
ImGuiFileDialog::Instance()->GetCurrentPath(), puSelectedFileToCopy.main,
std::bind(&TemplateSystem::SetNameOfBuffers, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3),
350, 1, IGFDUserDatas("createfromtemplate"), ImGuiFileDialogFlags_DisableThumbnailMode | ImGuiFileDialogFlags_Modal);
puSelectedFileToCopy = vTemplateFile;
IGFD::FileDialogConfig config;
config.path = ImGuiFileDialog::Instance()->GetCurrentPath();
config.filePathName = puSelectedFileToCopy.main;
config.countSelectionMax = 1;
config.sidePane = std::bind(&TemplateSystem::SetNameOfBuffers, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
config.sidePaneWidth = 350.0f;
config.userDatas = IGFDUserDatas("createfromtemplate");
config.flags = ImGuiFileDialogFlags_DisableThumbnailMode | ImGuiFileDialogFlags_Modal;
ImGuiFileDialog::Instance()->OpenDialog("NewFileDialog", "New File from template", ".glsl", config);
}

void TemplateSystem::SetNameOfBuffers(const char * /*vFilter*/, IGFDUserDatas /*vUserDatas*/, bool *vCantContinue)
Expand Down

0 comments on commit 62f75b1

Please sign in to comment.