GUI: fix several file dialog bugs

damn it
This commit is contained in:
tildearrow 2022-02-01 02:52:36 -05:00
parent de931c1d2f
commit ba08d3515f
5 changed files with 70 additions and 29 deletions

View file

@ -1541,7 +1541,19 @@ namespace IGFD
case DT_DIR: case DT_DIR:
fileType = 'd'; break; fileType = 'd'; break;
case DT_LNK: case DT_LNK:
fileType = 'l'; break; std::string where = path+std::string("/")+std::string(ent->d_name);
DIR* dirTest = opendir(where.c_str());
if (dirTest==NULL) {
if (errno==ENOTDIR) {
fileType = 'f';
} else {
fileType = 'l';
}
} else {
fileType = 'd';
closedir(dirTest);
}
break;
} }
auto fileNameExt = ent->d_name; auto fileNameExt = ent->d_name;
@ -3661,8 +3673,9 @@ namespace IGFD
// draw dialog parts // draw dialog parts
prDrawHeader(); // bookmark, directory, path prDrawHeader(); // bookmark, directory, path
prDrawContent(); // bookmark, files view, side pane res = prDrawContent(); // bookmark, files view, side pane
res = prDrawFooter(); // file field, filter combobox, ok/cancel buttons bool res1 = prDrawFooter(); // file field, filter combobox, ok/cancel buttons
if (!res) res=res1;
EndFrame(); EndFrame();
@ -3734,8 +3747,9 @@ namespace IGFD
prFileDialogInternal.puSearchManager.DrawSearchBar(prFileDialogInternal); prFileDialogInternal.puSearchManager.DrawSearchBar(prFileDialogInternal);
} }
void IGFD::FileDialog::prDrawContent() bool IGFD::FileDialog::prDrawContent()
{ {
bool escape = false;
ImVec2 size = ImGui::GetContentRegionAvail() - ImVec2(0.0f, prFileDialogInternal.puFooterHeight); ImVec2 size = ImGui::GetContentRegionAvail() - ImVec2(0.0f, prFileDialogInternal.puFooterHeight);
#ifdef USE_BOOKMARK #ifdef USE_BOOKMARK
@ -3783,13 +3797,15 @@ namespace IGFD
} }
} }
#else #else
prDrawFileListView(size); escape = prDrawFileListView(size);
#endif // USE_THUMBNAILS #endif // USE_THUMBNAILS
if (prFileDialogInternal.puDLGoptionsPane) if (prFileDialogInternal.puDLGoptionsPane)
{ {
prDrawSidePane(size.y); prDrawSidePane(size.y);
} }
return escape;
} }
bool IGFD::FileDialog::prDrawFooter() bool IGFD::FileDialog::prDrawFooter()
@ -3845,10 +3861,11 @@ namespace IGFD
return res; return res;
} }
bool IGFD::FileDialog::prSelectableItem(int vidx, std::shared_ptr<FileInfos> vInfos, bool vSelected, const char* vFmt, ...) // returns 0 if not break loop, 1 if break loop, 2 if exit dialog
int IGFD::FileDialog::prSelectableItem(int vidx, std::shared_ptr<FileInfos> vInfos, bool vSelected, const char* vFmt, ...)
{ {
if (!vInfos.use_count()) if (!vInfos.use_count())
return false; return 0;
auto& fdi = prFileDialogInternal.puFileManager; auto& fdi = prFileDialogInternal.puFileManager;
@ -3880,6 +3897,7 @@ namespace IGFD
{ {
if (vInfos->fileType == 'd') if (vInfos->fileType == 'd')
{ {
bool isSelectingDir=false;
// nav system, selectebale cause open directory or select directory // nav system, selectebale cause open directory or select directory
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard)
{ {
@ -3890,12 +3908,14 @@ namespace IGFD
else else
{ {
fdi.puPathClicked = fdi.SelectDirectory(vInfos); fdi.puPathClicked = fdi.SelectDirectory(vInfos);
isSelectingDir=true;
} }
} }
else // no nav system => classic behavior else // no nav system => classic behavior
{ {
if (ImGui::IsMouseDoubleClicked(0)) // 0 -> left mouse button double click if (ImGui::IsMouseDoubleClicked(0)) // 0 -> left mouse button double click
{ {
isSelectingDir=true;
fdi.puPathClicked = fdi.SelectDirectory(vInfos); fdi.puPathClicked = fdi.SelectDirectory(vInfos);
} }
else if (fdi.puDLGDirectoryMode) // directory chooser else if (fdi.puDLGDirectoryMode) // directory chooser
@ -3904,15 +3924,21 @@ namespace IGFD
} }
} }
return true; // needToBreakTheloop return isSelectingDir; // needToBreakTheloop
} }
else else
{ {
if (ImGui::IsMouseDoubleClicked(0)) {
fdi.SelectFileName(prFileDialogInternal, vInfos);
prFileDialogInternal.puIsOk = true;
return 2;
} else {
fdi.SelectFileName(prFileDialogInternal, vInfos); fdi.SelectFileName(prFileDialogInternal, vInfos);
} }
} }
}
return false; return 0;
} }
void IGFD::FileDialog::prBeginFileColorIconStyle(std::shared_ptr<FileInfos> vFileInfos, bool& vOutShowColor, std::string& vOutStr, ImFont** vOutFont) void IGFD::FileDialog::prBeginFileColorIconStyle(std::shared_ptr<FileInfos> vFileInfos, bool& vOutShowColor, std::string& vOutStr, ImFont** vOutFont)
@ -3948,8 +3974,9 @@ namespace IGFD
ImGui::PopStyleColor(); ImGui::PopStyleColor();
} }
void IGFD::FileDialog::prDrawFileListView(ImVec2 vSize) bool IGFD::FileDialog::prDrawFileListView(ImVec2 vSize)
{ {
bool escape = false;
auto& fdi = prFileDialogInternal.puFileManager; auto& fdi = prFileDialogInternal.puFileManager;
ImGui::PushID(this); ImGui::PushID(this);
@ -4038,11 +4065,12 @@ namespace IGFD
ImGui::TableNextRow(); ImGui::TableNextRow();
bool needToBreakTheloop = false; int needToBreakTheloop = false;
if (ImGui::TableNextColumn()) // file name if (ImGui::TableNextColumn()) // file name
{ {
needToBreakTheloop = prSelectableItem(i, infos, selected, _str.c_str()); needToBreakTheloop = prSelectableItem(i, infos, selected, _str.c_str());
if (needToBreakTheloop==2) escape=true;
} }
if (ImGui::TableNextColumn()) // file type if (ImGui::TableNextColumn()) // file type
{ {
@ -4066,7 +4094,7 @@ namespace IGFD
prEndFileColorIconStyle(_showColor, _font); prEndFileColorIconStyle(_showColor, _font);
if (needToBreakTheloop) if (needToBreakTheloop==1)
break; break;
} }
} }
@ -4091,6 +4119,7 @@ namespace IGFD
} }
ImGui::PopID(); ImGui::PopID();
return escape;
} }
#ifdef USE_THUMBNAILS #ifdef USE_THUMBNAILS

View file

@ -1293,15 +1293,15 @@ namespace IGFD
public: public:
// dialog parts // dialog parts
virtual void prDrawHeader(); // draw header part of the dialog (bookmark btn, dir creation, path composer, search bar) virtual void prDrawHeader(); // draw header part of the dialog (bookmark btn, dir creation, path composer, search bar)
virtual void prDrawContent(); // draw content part of the dialog (bookmark pane, file list, side pane) virtual bool prDrawContent(); // draw content part of the dialog (bookmark pane, file list, side pane)
virtual bool prDrawFooter(); // draw footer part of the dialog (file field, fitler combobox, ok/cancel btn's) virtual bool prDrawFooter(); // draw footer part of the dialog (file field, fitler combobox, ok/cancel btn's)
// widgets components // widgets components
virtual void prDrawSidePane(float vHeight); // draw side pane virtual void prDrawSidePane(float vHeight); // draw side pane
virtual bool prSelectableItem(int vidx, virtual int prSelectableItem(int vidx,
std::shared_ptr<FileInfos> vInfos, std::shared_ptr<FileInfos> vInfos,
bool vSelected, const char* vFmt, ...); // draw a custom selectable behavior item bool vSelected, const char* vFmt, ...); // draw a custom selectable behavior item
virtual void prDrawFileListView(ImVec2 vSize); // draw file list view (default mode) virtual bool prDrawFileListView(ImVec2 vSize); // draw file list view (default mode)
#ifdef USE_THUMBNAILS #ifdef USE_THUMBNAILS
virtual void prDrawThumbnailsListView(ImVec2 vSize); // draw file list view with small thumbnails on the same line virtual void prDrawThumbnailsListView(ImVec2 vSize); // draw file list view with small thumbnails on the same line

View file

@ -4419,7 +4419,6 @@ bool DivEngine::addInstrumentFromFile(const char *path) {
} }
if (version>=11) { // 1.0 if (version>=11) { // 1.0
logI("version 10 or higher, so load\n");
try { try {
sys=reader.readC(); sys=reader.readC();

View file

@ -2610,8 +2610,9 @@ void FurnaceGUI::drawAbout() {
float r=0; float r=0;
float g=0; float g=0;
float b=0; float b=0;
ImGui::ColorConvertHSVtoRGB(aboutHue,1.0,0.5,r,g,b); float peakMix=settings.partyTime?((peak[0]+peak[1])*0.5):0.3;
aboutHue+=0.001; ImGui::ColorConvertHSVtoRGB(aboutHue,1.0,0.25+MIN(0.75f,peakMix*0.75f),r,g,b);
aboutHue+=0.001+peakMix*0.004;
dl->AddRectFilled(ImVec2(0,0),ImVec2(scrW*dpiScale,scrH*dpiScale),0xff000000); dl->AddRectFilled(ImVec2(0,0),ImVec2(scrW*dpiScale,scrH*dpiScale),0xff000000);
bool skip=false; bool skip=false;
bool skip2=false; bool skip2=false;
@ -2670,8 +2671,9 @@ void FurnaceGUI::drawAbout() {
0xffffffff,aboutLine[i]); 0xffffffff,aboutLine[i]);
} }
ImGui::PopFont(); ImGui::PopFont();
aboutScroll+=2; aboutScroll+=2+(peakMix>0.78)*3;
if (++aboutSin>=2400) aboutSin=0; aboutSin+=1+(peakMix>0.75)*2;
if (aboutSin>=2400) aboutSin-=2400;
if (aboutScroll>(42*56+scrH)) aboutScroll=-20; if (aboutScroll>(42*56+scrH)) aboutScroll=-20;
} }
ImGui::End(); ImGui::End();
@ -2883,6 +2885,11 @@ void FurnaceGUI::drawSettings() {
settings.overflowHighlight=overflowHighlightB; settings.overflowHighlight=overflowHighlightB;
} }
bool partyTimeB=settings.partyTime;
if (ImGui::Checkbox("About screen party time",&partyTimeB)) {
settings.partyTime=partyTimeB;
}
ImGui::Separator(); ImGui::Separator();
if (ImGui::TreeNode("Color scheme")) { if (ImGui::TreeNode("Color scheme")) {
@ -3011,6 +3018,7 @@ void FurnaceGUI::syncSettings() {
settings.chipNames=e->getConfInt("chipNames",0); settings.chipNames=e->getConfInt("chipNames",0);
settings.overflowHighlight=e->getConfInt("overflowHighlight",0); settings.overflowHighlight=e->getConfInt("overflowHighlight",0);
if (settings.fmNames<0 || settings.fmNames>2) settings.fmNames=0; if (settings.fmNames<0 || settings.fmNames>2) settings.fmNames=0;
settings.partyTime=e->getConfInt("partyTime",0);
} }
#define PUT_UI_COLOR(source) e->setConf(#source,(int)ImGui::GetColorU32(uiColors[source])); #define PUT_UI_COLOR(source) e->setConf(#source,(int)ImGui::GetColorU32(uiColors[source]));
@ -3039,6 +3047,7 @@ void FurnaceGUI::commitSettings() {
e->setConf("allowEditDocking",settings.allowEditDocking); e->setConf("allowEditDocking",settings.allowEditDocking);
e->setConf("chipNames",settings.chipNames); e->setConf("chipNames",settings.chipNames);
e->setConf("overflowHighlight",settings.overflowHighlight); e->setConf("overflowHighlight",settings.overflowHighlight);
e->setConf("partyTime",settings.partyTime);
PUT_UI_COLOR(GUI_COLOR_BACKGROUND); PUT_UI_COLOR(GUI_COLOR_BACKGROUND);
PUT_UI_COLOR(GUI_COLOR_FRAME_BACKGROUND); PUT_UI_COLOR(GUI_COLOR_FRAME_BACKGROUND);
@ -4256,43 +4265,44 @@ void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
ImGuiFileDialog::Instance()->OpenModal("FileDialog","Open File","compatible files{.fur,.dmf},.*",workingDir); ImGuiFileDialog::Instance()->OpenModal("FileDialog","Open File","compatible files{.fur,.dmf},.*",workingDir);
break; break;
case GUI_FILE_SAVE: case GUI_FILE_SAVE:
ImGuiFileDialog::Instance()->OpenModal("FileDialog","Save File","Furnace song{.fur},DefleMask module{.dmf}",workingDir); ImGuiFileDialog::Instance()->OpenModal("FileDialog","Save File","Furnace song{.fur},DefleMask module{.dmf}",workingDir,1,nullptr,ImGuiFileDialogFlags_ConfirmOverwrite);
break; break;
case GUI_FILE_INS_OPEN: case GUI_FILE_INS_OPEN:
ImGuiFileDialog::Instance()->OpenModal("FileDialog","Load Instrument","compatible files{.fui,.dmp},.*",workingDir); ImGuiFileDialog::Instance()->OpenModal("FileDialog","Load Instrument","compatible files{.fui,.dmp},.*",workingDir);
break; break;
case GUI_FILE_INS_SAVE: case GUI_FILE_INS_SAVE:
ImGuiFileDialog::Instance()->OpenModal("FileDialog","Save Instrument","Furnace instrument{.fui}",workingDir); ImGuiFileDialog::Instance()->OpenModal("FileDialog","Save Instrument","Furnace instrument{.fui}",workingDir,1,nullptr,ImGuiFileDialogFlags_ConfirmOverwrite);
break; break;
case GUI_FILE_WAVE_OPEN: case GUI_FILE_WAVE_OPEN:
ImGuiFileDialog::Instance()->OpenModal("FileDialog","Load Wavetable","compatible files{.fuw,.dmw},.*",workingDir); ImGuiFileDialog::Instance()->OpenModal("FileDialog","Load Wavetable","compatible files{.fuw,.dmw},.*",workingDir);
break; break;
case GUI_FILE_WAVE_SAVE: case GUI_FILE_WAVE_SAVE:
ImGuiFileDialog::Instance()->OpenModal("FileDialog","Save Wavetable","Furnace wavetable{.fuw}",workingDir); ImGuiFileDialog::Instance()->OpenModal("FileDialog","Save Wavetable","Furnace wavetable{.fuw}",workingDir,1,nullptr,ImGuiFileDialogFlags_ConfirmOverwrite);
break; break;
case GUI_FILE_SAMPLE_OPEN: case GUI_FILE_SAMPLE_OPEN:
ImGuiFileDialog::Instance()->OpenModal("FileDialog","Load Sample","Wave file{.wav},.*",workingDir); ImGuiFileDialog::Instance()->OpenModal("FileDialog","Load Sample","Wave file{.wav},.*",workingDir);
break; break;
case GUI_FILE_SAMPLE_SAVE: case GUI_FILE_SAMPLE_SAVE:
ImGuiFileDialog::Instance()->OpenModal("FileDialog","Save Sample","Wave file{.wav}",workingDir); ImGuiFileDialog::Instance()->OpenModal("FileDialog","Save Sample","Wave file{.wav}",workingDir,1,nullptr,ImGuiFileDialogFlags_ConfirmOverwrite);
break; break;
case GUI_FILE_EXPORT_AUDIO_ONE: case GUI_FILE_EXPORT_AUDIO_ONE:
ImGuiFileDialog::Instance()->OpenModal("FileDialog","Export Audio","Wave file{.wav}",workingDir); ImGuiFileDialog::Instance()->OpenModal("FileDialog","Export Audio","Wave file{.wav}",workingDir,1,nullptr,ImGuiFileDialogFlags_ConfirmOverwrite);
break; break;
case GUI_FILE_EXPORT_AUDIO_PER_SYS: case GUI_FILE_EXPORT_AUDIO_PER_SYS:
ImGuiFileDialog::Instance()->OpenModal("FileDialog","Export Audio","Wave file{.wav}",workingDir); ImGuiFileDialog::Instance()->OpenModal("FileDialog","Export Audio","Wave file{.wav}",workingDir,1,nullptr,ImGuiFileDialogFlags_ConfirmOverwrite);
break; break;
case GUI_FILE_EXPORT_AUDIO_PER_CHANNEL: case GUI_FILE_EXPORT_AUDIO_PER_CHANNEL:
ImGuiFileDialog::Instance()->OpenModal("FileDialog","Export Audio","Wave file{.wav}",workingDir); ImGuiFileDialog::Instance()->OpenModal("FileDialog","Export Audio","Wave file{.wav}",workingDir,1,nullptr,ImGuiFileDialogFlags_ConfirmOverwrite);
break; break;
case GUI_FILE_EXPORT_VGM: case GUI_FILE_EXPORT_VGM:
ImGuiFileDialog::Instance()->OpenModal("FileDialog","Export VGM",".vgm",workingDir); ImGuiFileDialog::Instance()->OpenModal("FileDialog","Export VGM",".vgm",workingDir,1,nullptr,ImGuiFileDialogFlags_ConfirmOverwrite);
break; break;
case GUI_FILE_EXPORT_ROM: case GUI_FILE_EXPORT_ROM:
showError("Coming soon!"); showError("Coming soon!");
break; break;
} }
curFileDialog=type; curFileDialog=type;
//ImGui::GetIO().ConfigFlags|=ImGuiConfigFlags_NavEnableKeyboard;
} }
#define FURNACE_ZLIB_COMPRESS #define FURNACE_ZLIB_COMPRESS
@ -5062,6 +5072,7 @@ bool FurnaceGUI::loop() {
drawDebug(); drawDebug();
if (ImGuiFileDialog::Instance()->Display("FileDialog",ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove,ImVec2(600.0f*dpiScale,400.0f*dpiScale),ImVec2(scrW*dpiScale,scrH*dpiScale))) { if (ImGuiFileDialog::Instance()->Display("FileDialog",ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove,ImVec2(600.0f*dpiScale,400.0f*dpiScale),ImVec2(scrW*dpiScale,scrH*dpiScale))) {
//ImGui::GetIO().ConfigFlags&=~ImGuiConfigFlags_NavEnableKeyboard;
if (ImGuiFileDialog::Instance()->IsOk()) { if (ImGuiFileDialog::Instance()->IsOk()) {
fileName=ImGuiFileDialog::Instance()->GetFilePathName(); fileName=ImGuiFileDialog::Instance()->GetFilePathName();
if (fileName!="") { if (fileName!="") {

View file

@ -210,6 +210,7 @@ class FurnaceGUI {
int allowEditDocking; int allowEditDocking;
int chipNames; int chipNames;
int overflowHighlight; int overflowHighlight;
int partyTime;
unsigned int maxUndoSteps; unsigned int maxUndoSteps;
String mainFontPath; String mainFontPath;
String patFontPath; String patFontPath;
@ -236,6 +237,7 @@ class FurnaceGUI {
allowEditDocking(0), allowEditDocking(0),
chipNames(0), chipNames(0),
overflowHighlight(0), overflowHighlight(0),
partyTime(0),
maxUndoSteps(100), maxUndoSteps(100),
mainFontPath(""), mainFontPath(""),
patFontPath("") {} patFontPath("") {}