WM: add WM_drag_get_string{_firstline} accessor functions
Add utility functions to access the drag string with an "_firstline()" to avoid having to in-line first line access.
This commit is contained in:
@@ -183,13 +183,11 @@ static bool console_drop_string_poll(bContext * /*C*/, wmDrag *drag, const wmEve
|
||||
|
||||
static void console_drop_string_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
|
||||
{
|
||||
const std::string *str = static_cast<const std::string *>(drag->poin);
|
||||
/* NOTE(@ideasman42): Only a single line is supported, multiple lines could be supported
|
||||
* but this implies executing all lines except for the last. While we could consider that,
|
||||
* there are some security implications for this, so just drop one line for now. */
|
||||
const size_t eol = str->find('\n');
|
||||
RNA_string_set(
|
||||
drop->ptr, "text", (eol == std::string::npos) ? str->c_str() : str->substr(0, eol).c_str());
|
||||
std::string str = WM_drag_get_string_firstline(drag);
|
||||
RNA_string_set(drop->ptr, "text", str.c_str());
|
||||
}
|
||||
|
||||
/* this region dropbox definition */
|
||||
|
||||
@@ -339,8 +339,8 @@ static bool text_drop_string_poll(bContext * /*C*/, wmDrag *drag, const wmEvent
|
||||
|
||||
static void text_drop_string_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
|
||||
{
|
||||
const std::string *str = static_cast<const std::string *>(drag->poin);
|
||||
RNA_string_set(drop->ptr, "text", str->c_str());
|
||||
const std::string &str = WM_drag_get_string(drag);
|
||||
RNA_string_set(drop->ptr, "text", str.c_str());
|
||||
}
|
||||
|
||||
/* this region dropbox definition */
|
||||
|
||||
@@ -1496,6 +1496,9 @@ bool WM_drag_has_path_file_type(const wmDrag *drag, int file_type);
|
||||
*/
|
||||
int /* #eFileSel_File_Types */ WM_drag_get_path_file_type(const wmDrag *drag);
|
||||
|
||||
const std::string &WM_drag_get_string(const wmDrag *drag);
|
||||
std::string WM_drag_get_string_firstline(const wmDrag *drag);
|
||||
|
||||
/* Set OpenGL viewport and scissor */
|
||||
void wmViewport(const rcti *winrct);
|
||||
void wmPartialViewport(rcti *drawrct, const rcti *winrct, const rcti *partialrct);
|
||||
|
||||
@@ -922,6 +922,24 @@ int WM_drag_get_path_file_type(const wmDrag *drag)
|
||||
return path_data->file_types[0];
|
||||
}
|
||||
|
||||
const std::string &WM_drag_get_string(const wmDrag *drag)
|
||||
{
|
||||
BLI_assert(drag->type == WM_DRAG_STRING);
|
||||
const std::string *str = static_cast<const std::string *>(drag->poin);
|
||||
return *str;
|
||||
}
|
||||
|
||||
std::string WM_drag_get_string_firstline(const wmDrag *drag)
|
||||
{
|
||||
BLI_assert(drag->type == WM_DRAG_STRING);
|
||||
const std::string *str = static_cast<const std::string *>(drag->poin);
|
||||
const size_t str_eol = str->find('\n');
|
||||
if (str_eol != std::string::npos) {
|
||||
return str->substr(0, str_eol);
|
||||
}
|
||||
return *str;
|
||||
}
|
||||
|
||||
/* ************** draw ***************** */
|
||||
|
||||
static void wm_drop_operator_draw(const blender::StringRef name, int x, int y)
|
||||
|
||||
Reference in New Issue
Block a user