Fixes around ScriptEditor script list

- Fixed "Previous Script" shortcut not working (CTRL+SHIFT+<)
- Fixed crash (integer division by zero) when using previous/next script shortcut with no script open
- Fixed error when dropping a script file with no script open
ERROR: ItemList::get_item_metadata: Index p_idx=-1 out of size (items.size()=0)
   At: scene\gui\item_list.cpp:257
This commit is contained in:
PouleyKetchoupp 2019-11-25 17:16:29 +01:00
parent 5d7c13dcbb
commit 3ab5b33a47

View file

@ -2497,7 +2497,10 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node); ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node);
EditorHelp *eh = Object::cast_to<EditorHelp>(node); EditorHelp *eh = Object::cast_to<EditorHelp>(node);
if (se || eh) { if (se || eh) {
int new_index = script_list->get_item_metadata(script_list->get_item_at_position(p_point)); int new_index = 0;
if (script_list->get_item_count() > 0) {
new_index = script_list->get_item_metadata(script_list->get_item_at_position(p_point));
}
tab_container->move_child(node, new_index); tab_container->move_child(node, new_index);
tab_container->set_current_tab(new_index); tab_container->set_current_tab(new_index);
_update_script_names(); _update_script_names();
@ -2514,7 +2517,10 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node); ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node);
EditorHelp *eh = Object::cast_to<EditorHelp>(node); EditorHelp *eh = Object::cast_to<EditorHelp>(node);
if (se || eh) { if (se || eh) {
int new_index = script_list->get_item_metadata(script_list->get_item_at_position(p_point)); int new_index = 0;
if (script_list->get_item_count() > 0) {
new_index = script_list->get_item_metadata(script_list->get_item_at_position(p_point));
}
tab_container->move_child(node, new_index); tab_container->move_child(node, new_index);
tab_container->set_current_tab(new_index); tab_container->set_current_tab(new_index);
_update_script_names(); _update_script_names();
@ -2525,7 +2531,10 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co
Vector<String> files = d["files"]; Vector<String> files = d["files"];
int new_index = script_list->get_item_metadata(script_list->get_item_at_position(p_point)); int new_index = 0;
if (script_list->get_item_count() > 0) {
new_index = script_list->get_item_metadata(script_list->get_item_at_position(p_point));
}
int num_tabs_before = tab_container->get_child_count(); int num_tabs_before = tab_container->get_child_count();
for (int i = 0; i < files.size(); i++) { for (int i = 0; i < files.size(); i++) {
String file = files[i]; String file = files[i];
@ -2551,16 +2560,20 @@ void ScriptEditor::_unhandled_input(const Ref<InputEvent> &p_event) {
if (!is_visible_in_tree() || !p_event->is_pressed() || p_event->is_echo()) if (!is_visible_in_tree() || !p_event->is_pressed() || p_event->is_echo())
return; return;
if (ED_IS_SHORTCUT("script_editor/next_script", p_event)) { if (ED_IS_SHORTCUT("script_editor/next_script", p_event)) {
int next_tab = script_list->get_current() + 1; if (script_list->get_item_count() > 1) {
next_tab %= script_list->get_item_count(); int next_tab = script_list->get_current() + 1;
_go_to_tab(script_list->get_item_metadata(next_tab)); next_tab %= script_list->get_item_count();
_update_script_names(); _go_to_tab(script_list->get_item_metadata(next_tab));
_update_script_names();
}
} }
if (ED_IS_SHORTCUT("script_editor/prev_script", p_event)) { if (ED_IS_SHORTCUT("script_editor/prev_script", p_event)) {
int next_tab = script_list->get_current() - 1; if (script_list->get_item_count() > 1) {
next_tab = next_tab >= 0 ? next_tab : script_list->get_item_count() - 1; int next_tab = script_list->get_current() - 1;
_go_to_tab(script_list->get_item_metadata(next_tab)); next_tab = next_tab >= 0 ? next_tab : script_list->get_item_count() - 1;
_update_script_names(); _go_to_tab(script_list->get_item_metadata(next_tab));
_update_script_names();
}
} }
if (ED_IS_SHORTCUT("script_editor/window_move_up", p_event)) { if (ED_IS_SHORTCUT("script_editor/window_move_up", p_event)) {
_menu_option(WINDOW_MOVE_UP); _menu_option(WINDOW_MOVE_UP);
@ -3238,7 +3251,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
ED_SHORTCUT("script_editor/window_move_up", TTR("Move Up"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_UP); ED_SHORTCUT("script_editor/window_move_up", TTR("Move Up"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_UP);
ED_SHORTCUT("script_editor/window_move_down", TTR("Move Down"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_DOWN); ED_SHORTCUT("script_editor/window_move_down", TTR("Move Down"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_DOWN);
ED_SHORTCUT("script_editor/next_script", TTR("Next script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); // these should be KEY_GREATER and KEY_LESS but those don't work ED_SHORTCUT("script_editor/next_script", TTR("Next script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); // these should be KEY_GREATER and KEY_LESS but those don't work
ED_SHORTCUT("script_editor/prev_script", TTR("Previous script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COLON); ED_SHORTCUT("script_editor/prev_script", TTR("Previous script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COMMA);
set_process_unhandled_input(true); set_process_unhandled_input(true);
file_menu = memnew(MenuButton); file_menu = memnew(MenuButton);