* 文件拖入响应

This commit is contained in:
2024-02-23 11:01:06 +08:00
parent 55c65cccdb
commit f44af0badf
4 changed files with 58 additions and 4 deletions
+17 -4
View File
@@ -233,11 +233,10 @@ void Erase(C& container, const V& v)
++iter;
}
}
/**
* @brief 移除容器所有元素都等于某值
* @param[in] c 操作的容器
* @param[in] v 要比较的值
* @brief 移除容器所有元素都等于某值
* @param[in] c 操作的容器
* @param[in] v 要比较的值
*/
template<typename C, typename V>
[[nodiscard]]
@@ -290,6 +289,20 @@ void Replace(C& c, const V& v, const V& v_new)
iter = v_new;
}
}
/**
* @brief 替换容器所有元素都等于某值
* @param[in] c 操作的容器
* @param[in] v 要替换的值
* @param[in] v_new 新值
*/
template<typename C, typename V>
[[nodiscard]]
C Replace(const C& c, const V& v, const V& v_new)
{
C ret = c;
Replace(ret, v, v_new);
return ret;
}
/**
* @brief 对容器每个元素进行delete操作
+9
View File
@@ -387,6 +387,15 @@ inline void CvtPathSeparator(std::string& path)
{
Every::Replace(path, '\\', '/');
}
/**
* @brief 路径斜杠统一为/
* @param[in] path 路径
*/
[[nodiscard]]
inline std::string CvtPathSeparator(std::string_view path)
{
return Every::Replace(std::string{ path }, '\\', '/');
}
/**
* @brief 换行符统一为\n
+8
View File
@@ -108,6 +108,11 @@ static void CallbackScroll(GLFWwindow* window, double dx, double dy)
//log_test("滚动操作:{}, {}", dx, -dy);
}
void CallbackDrop(GLFWwindow* window, int count, const char** paths)
{
for (int i = 0; i < count; ++i)
g_system->_add_drop_file(String::CvtPathSeparator(paths[i]));
}
System::System() :
_funcInit{ nullptr },
@@ -159,6 +164,9 @@ void System::Start(const ParamWindow& param)
glfwSetMouseButtonCallback(_imp->_window, CallbackMouseButton);
// 设置滚动回调
glfwSetScrollCallback(_imp->_window, CallbackScroll);
// 拖入文件回调
glfwSetDropCallback(_imp->_window, CallbackDrop);
#elif DL_PLATFORM == DL_PLATFORM_ANDROID
_imp->_window = new GLFWwindow;
_imp->_monitor = new GLFWmonitor;
+24
View File
@@ -13,6 +13,7 @@
#ifndef DL_DISABLE_RENDER
#include <string_view>
#include <vector>
#include "dl_type.h"
#include "base/dl_type_user.h"
@@ -123,6 +124,27 @@ public:
*/
std::string GetClipboardString();
/**
* @brief 清空拖入文件列表
*/
void ClearDropFile()
{
_vecDropFile.clear();
}
/**
* @brief 返回拖入文件列表
*/
const std::vector<std::string>& GetDropFile()
{
return _vecDropFile;
}
//! 内部调用
void _add_drop_file(std::string_view str)
{
_vecDropFile.push_back(std::string{ str });
}
SystemImp* GetImp() { return _imp; }
private:
SystemImp* _imp;
@@ -131,6 +153,8 @@ private:
CursorMode _cursorMode;
bool _bCursorModeChange;
std::vector<std::string> _vecDropFile;
};
extern System* g_system;
}