diff --git a/src/gui/commandPalette.cpp b/src/gui/commandPalette.cpp index fcea3e3a6..e182f2bdf 100644 --- a/src/gui/commandPalette.cpp +++ b/src/gui/commandPalette.cpp @@ -28,11 +28,14 @@ enum CommandPaletteType { CMDPAL_TYPE_MAIN = 0, CMDPAL_TYPE_RECENT, - // TODO + // TODO: are there more? + + CMDPAL_TYPE_MAX, }; enum CommandPaletteExtraAction { CMDPAL_EXTRA_RECENT = 0, + CMDPAL_EXTRA_MAX, }; @@ -63,6 +66,12 @@ static inline bool matchFuzzy(const char* haystack,const char* needle) { } void FurnaceGUI::drawPalette() { + auto resetPalette = [](FurnaceGUI* g){ + g->paletteFirstFrame=true; + g->paletteQuery=""; + g->curPaletteChoice=0; + }; + bool accepted=false; if (paletteFirstFrame) @@ -164,9 +173,7 @@ void FurnaceGUI::drawPalette() { } else { switch (i-GUI_ACTION_MAX) { case CMDPAL_EXTRA_RECENT: - paletteFirstFrame=true; - paletteQuery=""; - curPaletteChoice=0; + resetPalette(this); curPaletteType=CMDPAL_TYPE_RECENT; break; default: @@ -177,17 +184,7 @@ void FurnaceGUI::drawPalette() { break; case CMDPAL_TYPE_RECENT: - if (modified) { - nextFile=recentFile[i]; - showWarning("Unsaved changes! Save changes before opening file?",GUI_WARN_OPEN_DROP); - } else { - String item=recentFile[i]; - recentFile.erase(recentFile.begin()+i); - i--; - if (load(item)>0) { - showError(fmt::sprintf("Error while loading file! (%s)",lastError)); - } - } + openRecentFile(recentFile[i]); ImGui::CloseCurrentPopup(); break; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index bf15f50ae..175a5fb80 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -2151,6 +2151,17 @@ int FurnaceGUI::load(String path) { return 0; } +void FurnaceGUI::openRecentFile(String path) { + if (modified) { + nextFile=path; + showWarning("Unsaved changes! Save changes before opening file?",GUI_WARN_OPEN_DROP); + } else { + if (load(path)>0) { + showError(fmt::sprintf("Error while loading file! (%s)",lastError)); + } + } +} + void FurnaceGUI::pushRecentFile(String path) { if (path.empty()) return; if (path.find(backupPath)==0) return; @@ -3802,17 +3813,13 @@ bool FurnaceGUI::loop() { exitDisabledTimer=1; for (int i=0; i<(int)recentFile.size(); i++) { String item=recentFile[i]; - if (ImGui::MenuItem(item.c_str())) { - if (modified) { - nextFile=item; - showWarning("Unsaved changes! Save changes before opening file?",GUI_WARN_OPEN_DROP); - } else { + if (ImGui::MenuItem(recentFile[i].c_str())) { + String item=recentFile[i]; + if (!modified) { recentFile.erase(recentFile.begin()+i); i--; - if (load(item)>0) { - showError(fmt::sprintf("Error while loading file! (%s)",lastError)); - } } + openRecentFile(item); } } if (recentFile.empty()) { diff --git a/src/gui/gui.h b/src/gui/gui.h index 3bac297f3..60be63611 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -2240,6 +2240,7 @@ class FurnaceGUI { int save(String path, int dmfVersion); int load(String path); int loadStream(String path); + void openRecentFile(String path); void pushRecentFile(String path); void exportAudio(String path, DivAudioExportModes mode); void delFirstBackup(String name);