Step 88: drag-and-drop open
This commit is contained in:
24
editor/src/DragDropHandler.h
Normal file
24
editor/src/DragDropHandler.h
Normal 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);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user