You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2026-01-05 19:31:35 +00:00
Improve Undo/Redo menu items
* Make Undo/Redo menu items disabled when clicking it does nothing.
* Context menu of `TextEdit`
* Context menu of `LineEdit`
* Editor's Scene menu
* Script editor's Edit menu and context menu (for Script and Text)
* Make editor undo/redo log messages translatable.
* Mark `UndoRedo`'s `has_{un,re}do()` methods as `const`.
* Expose `TextEdit`'s `has_{un,re}do()` to scripts since `{un,re}do()` are already available.
This commit is contained in:
@@ -1406,6 +1406,7 @@ void ScriptTextEditor::_bind_methods() {
|
||||
ClassDB::bind_method("_show_warnings_panel", &ScriptTextEditor::_show_warnings_panel);
|
||||
ClassDB::bind_method("_warning_clicked", &ScriptTextEditor::_warning_clicked);
|
||||
ClassDB::bind_method("_color_changed", &ScriptTextEditor::_color_changed);
|
||||
ClassDB::bind_method("_prepare_edit_menu", &ScriptTextEditor::_prepare_edit_menu);
|
||||
|
||||
ClassDB::bind_method("get_drag_data_fw", &ScriptTextEditor::get_drag_data_fw);
|
||||
ClassDB::bind_method("can_drop_data_fw", &ScriptTextEditor::can_drop_data_fw);
|
||||
@@ -1687,6 +1688,13 @@ void ScriptTextEditor::_color_changed(const Color &p_color) {
|
||||
code_editor->get_text_edit()->update();
|
||||
}
|
||||
|
||||
void ScriptTextEditor::_prepare_edit_menu() {
|
||||
const TextEdit *tx = code_editor->get_text_edit();
|
||||
PopupMenu *popup = edit_menu->get_popup();
|
||||
popup->set_item_disabled(popup->get_item_index(EDIT_UNDO), !tx->has_undo());
|
||||
popup->set_item_disabled(popup->get_item_index(EDIT_REDO), !tx->has_redo());
|
||||
}
|
||||
|
||||
void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, Vector2 p_pos) {
|
||||
context_menu->clear();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
|
||||
@@ -1726,6 +1734,10 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p
|
||||
}
|
||||
}
|
||||
|
||||
const TextEdit *tx = code_editor->get_text_edit();
|
||||
context_menu->set_item_disabled(context_menu->get_item_index(EDIT_UNDO), !tx->has_undo());
|
||||
context_menu->set_item_disabled(context_menu->get_item_index(EDIT_REDO), !tx->has_redo());
|
||||
|
||||
context_menu->set_position(get_global_transform().xform(p_pos));
|
||||
context_menu->set_size(Vector2(1, 1));
|
||||
context_menu->popup();
|
||||
@@ -1794,6 +1806,7 @@ void ScriptTextEditor::_enable_code_editor() {
|
||||
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/contextual_help"), HELP_CONTEXTUAL);
|
||||
search_menu->get_popup()->connect("id_pressed", this, "_edit_option");
|
||||
edit_hb->add_child(edit_menu);
|
||||
edit_menu->connect("about_to_show", this, "_prepare_edit_menu");
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
|
||||
@@ -176,6 +176,7 @@ protected:
|
||||
void _make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, Vector2 p_pos);
|
||||
void _text_edit_gui_input(const Ref<InputEvent> &ev);
|
||||
void _color_changed(const Color &p_color);
|
||||
void _prepare_edit_menu();
|
||||
|
||||
void _goto_line(int p_line) { goto_line(p_line); }
|
||||
void _lookup_symbol(const String &p_symbol, int p_row, int p_column);
|
||||
|
||||
@@ -480,6 +480,7 @@ void TextEditor::_bind_methods() {
|
||||
ClassDB::bind_method("_edit_option", &TextEditor::_edit_option);
|
||||
ClassDB::bind_method("_change_syntax_highlighter", &TextEditor::_change_syntax_highlighter);
|
||||
ClassDB::bind_method("_text_edit_gui_input", &TextEditor::_text_edit_gui_input);
|
||||
ClassDB::bind_method("_prepare_edit_menu", &TextEditor::_prepare_edit_menu);
|
||||
}
|
||||
|
||||
static ScriptEditorBase *create_editor(const RES &p_resource) {
|
||||
@@ -539,6 +540,13 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditor::_prepare_edit_menu() {
|
||||
const TextEdit *tx = code_editor->get_text_edit();
|
||||
PopupMenu *popup = edit_menu->get_popup();
|
||||
popup->set_item_disabled(popup->get_item_index(EDIT_UNDO), !tx->has_undo());
|
||||
popup->set_item_disabled(popup->get_item_index(EDIT_REDO), !tx->has_redo());
|
||||
}
|
||||
|
||||
void TextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position) {
|
||||
context_menu->clear();
|
||||
if (p_selection) {
|
||||
@@ -565,6 +573,10 @@ void TextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
|
||||
}
|
||||
|
||||
const TextEdit *tx = code_editor->get_text_edit();
|
||||
context_menu->set_item_disabled(context_menu->get_item_index(EDIT_UNDO), !tx->has_undo());
|
||||
context_menu->set_item_disabled(context_menu->get_item_index(EDIT_REDO), !tx->has_redo());
|
||||
|
||||
context_menu->set_position(get_global_transform().xform(p_position));
|
||||
context_menu->set_size(Vector2(1, 1));
|
||||
context_menu->popup();
|
||||
@@ -609,6 +621,7 @@ TextEditor::TextEditor() {
|
||||
edit_hb->add_child(edit_menu);
|
||||
edit_menu->set_text(TTR("Edit"));
|
||||
edit_menu->set_switch_on_hover(true);
|
||||
edit_menu->connect("about_to_show", this, "_prepare_edit_menu");
|
||||
edit_menu->get_popup()->connect("id_pressed", this, "_edit_option");
|
||||
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
|
||||
|
||||
@@ -102,6 +102,7 @@ protected:
|
||||
void _edit_option(int p_op);
|
||||
void _make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position);
|
||||
void _text_edit_gui_input(const Ref<InputEvent> &ev);
|
||||
void _prepare_edit_menu();
|
||||
|
||||
Map<String, SyntaxHighlighter *> highlighters;
|
||||
void _change_syntax_highlighter(int p_idx);
|
||||
|
||||
Reference in New Issue
Block a user