From 34a68751e15ca67b8c802163baf4a4d4deeae68a Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 1 Feb 2022 03:09:53 -0500 Subject: [PATCH] GUI: add ability to open files by drag-and-drop --- src/gui/gui.cpp | 19 +++++++++++++++++++ src/gui/gui.h | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 5cea0c197..bab3b2a28 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -4663,6 +4663,19 @@ bool FurnaceGUI::loop() { } } break; + case SDL_DROPFILE: + if (ev.drop.file!=NULL) { + if (modified) { + nextFile=ev.drop.file; + showWarning("Unsaved changes! Are you sure?",GUI_WARN_OPEN_DROP); + } else { + if (load(ev.drop.file)>0) { + showError(fmt::sprintf("Error while loading file! (%s)",lastError)); + } + } + SDL_free(ev.drop.file); + } + break; case SDL_QUIT: if (modified) { showWarning("Unsaved changes! Are you sure you want to quit?",GUI_WARN_QUIT); @@ -5251,6 +5264,12 @@ bool FurnaceGUI::loop() { case GUI_WARN_OPEN: openFileDialog(GUI_FILE_OPEN); break; + case GUI_WARN_OPEN_DROP: + if (load(nextFile)>0) { + showError(fmt::sprintf("Error while loading file! (%s)",lastError)); + } + nextFile=""; + break; case GUI_WARN_GENERIC: break; } diff --git a/src/gui/gui.h b/src/gui/gui.h index 245f2f557..4e2c4aa98 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -107,6 +107,7 @@ enum FurnaceGUIWarnings { GUI_WARN_QUIT, GUI_WARN_NEW, GUI_WARN_OPEN, + GUI_WARN_OPEN_DROP, GUI_WARN_GENERIC }; @@ -166,7 +167,7 @@ class FurnaceGUI { SDL_Window* sdlWin; SDL_Renderer* sdlRend; - String workingDir, fileName, clipboard, warnString, errorString, lastError, curFileName; + String workingDir, fileName, clipboard, warnString, errorString, lastError, curFileName, nextFile; String mmlString[12]; String mmlStringW;