GUI: add recent file list

This commit is contained in:
tildearrow 2022-09-10 18:53:27 -05:00
parent 7b19c8afa2
commit eb2c01097f
5 changed files with 81 additions and 1 deletions

View file

@ -239,6 +239,10 @@ void DivEngine::setConf(String key, double value) {
conf[key]=fmt::sprintf("%f",value); conf[key]=fmt::sprintf("%f",value);
} }
void DivEngine::setConf(String key, const char* value) {
conf[key]=String(value);
}
void DivEngine::setConf(String key, String value) { void DivEngine::setConf(String key, String value) {
conf[key]=value; conf[key]=value;
} }

View file

@ -544,6 +544,7 @@ class DivEngine {
void setConf(String key, int value); void setConf(String key, int value);
void setConf(String key, float value); void setConf(String key, float value);
void setConf(String key, double value); void setConf(String key, double value);
void setConf(String key, const char* value);
void setConf(String key, String value); void setConf(String key, String value);
// calculate base frequency/period // calculate base frequency/period

View file

@ -536,6 +536,7 @@ void FurnaceGUI::setFileName(String name) {
} }
#endif #endif
updateWindowTitle(); updateWindowTitle();
pushRecentFile(curFileName);
} }
void FurnaceGUI::updateWindowTitle() { void FurnaceGUI::updateWindowTitle() {
@ -1724,6 +1725,7 @@ int FurnaceGUI::save(String path, int dmfVersion) {
if (!e->getWarnings().empty()) { if (!e->getWarnings().empty()) {
showWarning(e->getWarnings(),GUI_WARN_GENERIC); showWarning(e->getWarnings(),GUI_WARN_GENERIC);
} }
pushRecentFile(path);
return 0; return 0;
} }
@ -1801,9 +1803,26 @@ int FurnaceGUI::load(String path) {
if (!e->getWarnings().empty()) { if (!e->getWarnings().empty()) {
showWarning(e->getWarnings(),GUI_WARN_GENERIC); showWarning(e->getWarnings(),GUI_WARN_GENERIC);
} }
pushRecentFile(path);
return 0; return 0;
} }
void FurnaceGUI::pushRecentFile(String path) {
if (path.empty()) return;
if (path==backupPath) return;
for (int i=0; i<(int)recentFile.size(); i++) {
if (recentFile[i]==path) {
recentFile.erase(recentFile.begin()+i);
i--;
}
}
recentFile.push_front(path);
while (!recentFile.empty() && (int)recentFile.size()>settings.maxRecentFile) {
recentFile.pop_back();
}
}
void FurnaceGUI::exportAudio(String path, DivAudioExportModes mode) { void FurnaceGUI::exportAudio(String path, DivAudioExportModes mode) {
e->saveAudio(path.c_str(),exportLoops+1,mode,exportFadeOut); e->saveAudio(path.c_str(),exportLoops+1,mode,exportFadeOut);
displayExporting=true; displayExporting=true;
@ -3045,6 +3064,27 @@ bool FurnaceGUI::loop() {
openFileDialog(GUI_FILE_OPEN); openFileDialog(GUI_FILE_OPEN);
} }
} }
if (ImGui::BeginMenu("open recent")) {
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 {
recentFile.erase(recentFile.begin()+i);
i--;
if (load(item)>0) {
showError(fmt::sprintf("Error while loading file! (%s)",lastError));
}
}
}
}
if (recentFile.empty()) {
ImGui::Text("nothing here yet");
}
ImGui::EndMenu();
}
ImGui::Separator(); ImGui::Separator();
if (ImGui::MenuItem("save",BIND_FOR(GUI_ACTION_SAVE))) { if (ImGui::MenuItem("save",BIND_FOR(GUI_ACTION_SAVE))) {
if (curFileName=="" || curFileName==backupPath || e->song.version>=0xff00) { if (curFileName=="" || curFileName==backupPath || e->song.version>=0xff00) {
@ -4628,6 +4668,13 @@ bool FurnaceGUI::init() {
syncSettings(); syncSettings();
for (int i=0; i<settings.maxRecentFile; i++) {
String r=e->getConfString(fmt::sprintf("recentFile%d",i),"");
if (!r.empty()) {
recentFile.push_back(r);
}
}
if (settings.dpiScale>=0.5f) { if (settings.dpiScale>=0.5f) {
dpiScale=settings.dpiScale; dpiScale=settings.dpiScale;
} }
@ -4900,6 +4947,16 @@ bool FurnaceGUI::finish() {
e->setConf("chanOscUseGrad",chanOscUseGrad); e->setConf("chanOscUseGrad",chanOscUseGrad);
e->setConf("chanOscGrad",chanOscGrad.toString()); e->setConf("chanOscGrad",chanOscGrad.toString());
// commit recent files
for (int i=0; i<30; i++) {
String key=fmt::sprintf("recentFile%d",i);
if (i>=settings.maxRecentFile || i>=(int)recentFile.size()) {
e->setConf(key,"");
} else {
e->setConf(key,recentFile[i]);
}
}
for (int i=0; i<DIV_MAX_CHANS; i++) { for (int i=0; i<DIV_MAX_CHANS; i++) {
delete oldPat[i]; delete oldPat[i];
} }

View file

@ -1000,6 +1000,7 @@ class FurnaceGUI {
std::vector<DivSystem> sysSearchResults; std::vector<DivSystem> sysSearchResults;
std::vector<FurnaceGUISysDef> newSongSearchResults; std::vector<FurnaceGUISysDef> newSongSearchResults;
std::deque<String> recentFile;
bool quit, warnQuit, willCommit, edit, modified, displayError, displayExporting, vgmExportLoop, vgmExportPatternHints; bool quit, warnQuit, willCommit, edit, modified, displayError, displayExporting, vgmExportLoop, vgmExportPatternHints;
bool portrait, mobileMenuOpen; bool portrait, mobileMenuOpen;
@ -1171,6 +1172,7 @@ class FurnaceGUI {
int channelStyle; int channelStyle;
int channelVolStyle; int channelVolStyle;
int channelFeedbackStyle; int channelFeedbackStyle;
int maxRecentFile;
unsigned int maxUndoSteps; unsigned int maxUndoSteps;
String mainFontPath; String mainFontPath;
String patFontPath; String patFontPath;
@ -1291,6 +1293,7 @@ class FurnaceGUI {
channelStyle(0), channelStyle(0),
channelVolStyle(0), channelVolStyle(0),
channelFeedbackStyle(1), channelFeedbackStyle(1),
maxRecentFile(10),
maxUndoSteps(100), maxUndoSteps(100),
mainFontPath(""), mainFontPath(""),
patFontPath(""), patFontPath(""),
@ -1728,6 +1731,7 @@ class FurnaceGUI {
void openFileDialog(FurnaceGUIFileDialogs type); void openFileDialog(FurnaceGUIFileDialogs type);
int save(String path, int dmfVersion); int save(String path, int dmfVersion);
int load(String path); int load(String path);
void pushRecentFile(String path);
void exportAudio(String path, DivAudioExportModes mode); void exportAudio(String path, DivAudioExportModes mode);
bool parseSysEx(unsigned char* data, size_t len); bool parseSysEx(unsigned char* data, size_t len);

View file

@ -1130,6 +1130,13 @@ void FurnaceGUI::drawSettings() {
ImGui::Separator(); ImGui::Separator();
if (ImGui::InputInt("Number of recent files",&settings.maxRecentFile)) {
if (settings.maxRecentFile<0) settings.maxRecentFile=0;
if (settings.maxRecentFile>30) settings.maxRecentFile=30;
}
ImGui::Separator();
ImGui::Text("Pattern view labels:"); ImGui::Text("Pattern view labels:");
ImGui::InputTextWithHint("Note off (3-char)","OFF",&settings.noteOffLabel); ImGui::InputTextWithHint("Note off (3-char)","OFF",&settings.noteOffLabel);
ImGui::InputTextWithHint("Note release (3-char)","===",&settings.noteRelLabel); ImGui::InputTextWithHint("Note release (3-char)","===",&settings.noteRelLabel);
@ -2273,6 +2280,7 @@ void FurnaceGUI::syncSettings() {
settings.channelStyle=e->getConfInt("channelStyle",0); settings.channelStyle=e->getConfInt("channelStyle",0);
settings.channelVolStyle=e->getConfInt("channelVolStyle",0); settings.channelVolStyle=e->getConfInt("channelVolStyle",0);
settings.channelFeedbackStyle=e->getConfInt("channelFeedbackStyle",1); settings.channelFeedbackStyle=e->getConfInt("channelFeedbackStyle",1);
settings.maxRecentFile=e->getConfInt("maxRecentFile",10);
clampSetting(settings.mainFontSize,2,96); clampSetting(settings.mainFontSize,2,96);
clampSetting(settings.patFontSize,2,96); clampSetting(settings.patFontSize,2,96);
@ -2371,6 +2379,7 @@ void FurnaceGUI::syncSettings() {
clampSetting(settings.channelStyle,0,5); clampSetting(settings.channelStyle,0,5);
clampSetting(settings.channelVolStyle,0,3); clampSetting(settings.channelVolStyle,0,3);
clampSetting(settings.channelFeedbackStyle,0,3); clampSetting(settings.channelFeedbackStyle,0,3);
clampSetting(settings.maxRecentFile,0,30);
settings.initialSys=e->decodeSysDesc(e->getConfString("initialSys","")); settings.initialSys=e->decodeSysDesc(e->getConfString("initialSys",""));
if (settings.initialSys.size()<4) { if (settings.initialSys.size()<4) {
@ -2525,6 +2534,7 @@ void FurnaceGUI::commitSettings() {
e->setConf("channelStyle",settings.channelStyle); e->setConf("channelStyle",settings.channelStyle);
e->setConf("channelVolStyle",settings.channelVolStyle); e->setConf("channelVolStyle",settings.channelVolStyle);
e->setConf("channelFeedbackStyle",settings.channelFeedbackStyle); e->setConf("channelFeedbackStyle",settings.channelFeedbackStyle);
e->setConf("maxRecentFile",settings.maxRecentFile);
// colors // colors
for (int i=0; i<GUI_COLOR_MAX; i++) { for (int i=0; i<GUI_COLOR_MAX; i++) {
@ -2546,6 +2556,10 @@ void FurnaceGUI::commitSettings() {
e->saveConf(); e->saveConf();
while (!recentFile.empty() && (int)recentFile.size()>settings.maxRecentFile) {
recentFile.pop_back();
}
if (sampleROMsChanged) { if (sampleROMsChanged) {
if (e->loadSampleROMs()) { if (e->loadSampleROMs()) {
showError(e->getLastError()); showError(e->getLastError());