Step 88: drag-and-drop open

This commit is contained in:
Bill
2026-02-09 09:38:57 -07:00
parent a1efe93ba3
commit 23e3758cca
5 changed files with 92 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
#pragma once
// Step 88: Drag-and-drop handler
#include <string>
#include <functional>
#include <filesystem>
class DragDropHandler {
public:
using FileCallback = std::function<void(const std::string&)>;
using FolderCallback = std::function<void(const std::string&)>;
static void handleDrop(const std::string& path,
const FileCallback& onFile,
const FolderCallback& onFolder) {
if (path.empty()) return;
std::filesystem::path p(path);
if (std::filesystem::is_directory(p)) {
if (onFolder) onFolder(path);
} else {
if (onFile) onFile(path);
}
}
};

View File

@@ -22,6 +22,7 @@
#include "FileDialog.h"
#include "FileTree.h"
#include "WelcomeScreen.h"
#include "DragDropHandler.h"
#include "ast/Generator.h"
#include <cstdio>
@@ -624,6 +625,18 @@ int main(int, char**) {
event.window.event == SDL_WINDOWEVENT_CLOSE &&
event.window.windowID == SDL_GetWindowID(window))
done = true;
if (event.type == SDL_DROPFILE) {
char* droppedFile = event.drop.file;
if (droppedFile) {
DragDropHandler::handleDrop(droppedFile,
[&](const std::string& p) { state.doOpen(p); },
[&](const std::string& p) {
state.workspaceRoot = p;
state.fileTreeDirty = true;
});
SDL_free(droppedFile);
}
}
// Handle keyboard shortcuts via KeybindingManager
if (event.type == SDL_KEYDOWN && !io.WantTextInput) {