Rename readonly to editable

This commit is contained in:
Paulb23 2021-07-09 14:05:52 +01:00
parent b799e5583a
commit 7dbb0f3233
6 changed files with 83 additions and 82 deletions

View File

@ -688,6 +688,9 @@
<member name="draw_tabs" type="bool" setter="set_draw_tabs" getter="is_drawing_tabs" default="false">
If [code]true[/code], the "tab" character will have a visible representation.
</member>
<member name="editable" type="bool" setter="set_editable" getter="is_editable" default="true">
If [code]false[/code], existing text cannot be modified and new text cannot be added.
</member>
<member name="focus_mode" type="int" setter="set_focus_mode" getter="get_focus_mode" override="true" enum="Control.FocusMode" default="2" />
<member name="highlight_all_occurrences" type="bool" setter="set_highlight_all_occurrences" getter="is_highlight_all_occurrences_enabled" default="false">
If [code]true[/code], all occurrences of the selected text will be highlighted.
@ -708,9 +711,6 @@
<member name="override_selected_font_color" type="bool" setter="set_override_selected_font_color" getter="is_overriding_selected_font_color" default="false">
If [code]true[/code], custom [code]font_selected_color[/code] will be used for selected text.
</member>
<member name="readonly" type="bool" setter="set_readonly" getter="is_readonly" default="false">
If [code]true[/code], read-only mode is enabled. Existing text cannot be modified and new text cannot be added.
</member>
<member name="scroll_horizontal" type="int" setter="set_h_scroll" getter="get_h_scroll" default="0">
If there is a horizontal scrollbar, this determines the current horizontal scroll value in pixels.
</member>

View File

@ -51,7 +51,7 @@ void EditorNativeShaderSourceVisualizer::_inspect_shader(RID p_shader) {
versions->add_child(vtab);
for (int j = 0; j < nsc.versions[i].stages.size(); j++) {
TextEdit *vtext = memnew(TextEdit);
vtext->set_readonly(true);
vtext->set_editable(false);
vtext->set_name(nsc.versions[i].stages[j].name);
vtext->set_text(nsc.versions[i].stages[j].code);
vtext->set_v_size_flags(Control::SIZE_EXPAND_FILL);

View File

@ -3968,7 +3968,7 @@ VisualShaderEditor::VisualShaderEditor() {
preview_text->set_v_size_flags(Control::SIZE_EXPAND_FILL);
preview_text->set_syntax_highlighter(syntax_highlighter);
preview_text->set_draw_line_numbers(true);
preview_text->set_readonly(true);
preview_text->set_editable(false);
error_panel = memnew(PanelContainer);
preview_vbox->add_child(error_panel);

View File

@ -523,7 +523,7 @@ Control::CursorShape CodeEdit::get_cursor_shape(const Point2 &p_pos) const {
return CURSOR_POINTING_HAND;
}
if ((code_completion_active && code_completion_rect.has_point(p_pos)) || (is_readonly() && (!is_selecting_enabled() || get_line_count() == 0))) {
if ((code_completion_active && code_completion_rect.has_point(p_pos)) || (!is_editable() && (!is_selecting_enabled() || get_line_count() == 0))) {
return CURSOR_ARROW;
}
@ -600,7 +600,7 @@ void CodeEdit::_handle_unicode_input(const uint32_t p_unicode) {
}
void CodeEdit::_backspace() {
if (is_readonly()) {
if (!is_editable()) {
return;
}
@ -714,7 +714,7 @@ TypedArray<String> CodeEdit::get_auto_indent_prefixes() const {
}
void CodeEdit::do_indent() {
if (is_readonly()) {
if (!is_editable()) {
return;
}
@ -735,7 +735,7 @@ void CodeEdit::do_indent() {
}
void CodeEdit::indent_lines() {
if (is_readonly()) {
if (!is_editable()) {
return;
}
@ -786,7 +786,7 @@ void CodeEdit::indent_lines() {
}
void CodeEdit::do_unindent() {
if (is_readonly()) {
if (!is_editable()) {
return;
}
@ -824,7 +824,7 @@ void CodeEdit::do_unindent() {
}
void CodeEdit::unindent_lines() {
if (is_readonly()) {
if (!is_editable()) {
return;
}
@ -911,7 +911,7 @@ int CodeEdit::_calculate_spaces_till_next_right_indent(int p_column) const {
}
void CodeEdit::_new_line(bool p_split_current_line, bool p_above) {
if (is_readonly()) {
if (!is_editable()) {
return;
}
@ -1839,7 +1839,7 @@ void CodeEdit::set_code_completion_selected_index(int p_index) {
}
void CodeEdit::confirm_code_completion(bool p_replace) {
if (is_readonly() || !code_completion_active) {
if (!is_editable() || !code_completion_active) {
return;
}

View File

@ -464,7 +464,7 @@ void TextEdit::_notification(int p_what) {
int xmargin_end = size.width - cache.style_normal->get_margin(SIDE_RIGHT) - cache.minimap_width;
// Let's do it easy for now.
cache.style_normal->draw(ci, Rect2(Point2(), size));
if (readonly) {
if (!editable) {
cache.style_readonly->draw(ci, Rect2(Point2(), size));
draw_caret = false;
}
@ -474,7 +474,7 @@ void TextEdit::_notification(int p_what) {
int visible_rows = get_visible_rows() + 1;
Color color = readonly ? cache.font_readonly_color : cache.font_color;
Color color = !editable ? cache.font_readonly_color : cache.font_color;
if (cache.background_color.a > 0.01) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(), get_size()), cache.background_color);
@ -687,7 +687,7 @@ void TextEdit::_notification(int p_what) {
Color line_background_color = text.get_line_background_color(minimap_line);
line_background_color.a *= 0.6;
Color current_color = cache.font_color;
if (readonly) {
if (!editable) {
current_color = cache.font_readonly_color;
}
@ -734,7 +734,7 @@ void TextEdit::_notification(int p_what) {
for (int j = 0; j < str.length(); j++) {
if (color_map.has(last_wrap_column + j)) {
current_color = color_map[last_wrap_column + j].get("color");
if (readonly) {
if (!editable) {
current_color.a = cache.font_readonly_color.a;
}
}
@ -796,7 +796,7 @@ void TextEdit::_notification(int p_what) {
int top_limit_y = 0;
int bottom_limit_y = get_size().height;
if (readonly) {
if (!editable) {
top_limit_y += cache.style_readonly->get_margin(SIDE_TOP);
bottom_limit_y -= cache.style_readonly->get_margin(SIDE_BOTTOM);
} else {
@ -829,7 +829,7 @@ void TextEdit::_notification(int p_what) {
Dictionary color_map = _get_line_syntax_highlighting(line);
// Ensure we at least use the font color.
Color current_color = readonly ? cache.font_readonly_color : cache.font_color;
Color current_color = !editable ? cache.font_readonly_color : cache.font_color;
const Ref<TextParagraph> ldata = text.get_line_data(line);
@ -849,7 +849,7 @@ void TextEdit::_notification(int p_what) {
int ofs_x = 0;
int ofs_y = 0;
if (readonly) {
if (!editable) {
ofs_x = cache.style_readonly->get_offset().x / 2;
ofs_x -= cache.style_normal->get_offset().x / 2;
ofs_y = cache.style_readonly->get_offset().y / 2;
@ -1113,7 +1113,7 @@ void TextEdit::_notification(int p_what) {
for (int j = 0; j < gl_size; j++) {
if (color_map.has(glyphs[j].start)) {
current_color = color_map[glyphs[j].start].get("color");
if (readonly && current_color.a > cache.font_readonly_color.a) {
if (!editable && current_color.a > cache.font_readonly_color.a) {
current_color.a = cache.font_readonly_color.a;
}
}
@ -1399,7 +1399,7 @@ void TextEdit::_swap_current_input_direction() {
}
void TextEdit::_new_line(bool p_split_current_line, bool p_above) {
if (readonly) {
if (!editable) {
return;
}
@ -1676,7 +1676,7 @@ void TextEdit::_move_caret_page_down(bool p_select) {
}
void TextEdit::_do_backspace(bool p_word, bool p_all_to_left) {
if (readonly) {
if (!editable) {
return;
}
@ -1713,7 +1713,7 @@ void TextEdit::_do_backspace(bool p_word, bool p_all_to_left) {
}
void TextEdit::_delete(bool p_word, bool p_all_to_right) {
if (readonly) {
if (!editable) {
return;
}
@ -2375,7 +2375,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
// Handle Unicode (if no modifiers active).
if (allow_unicode_handling && !readonly && k->get_unicode() >= 32) {
if (allow_unicode_handling && editable && k->get_unicode() >= 32) {
handle_unicode_input(k->get_unicode());
accept_event();
return;
@ -3185,20 +3185,6 @@ void TextEdit::clear() {
setting_text = false;
};
void TextEdit::set_readonly(bool p_readonly) {
if (readonly == p_readonly) {
return;
}
readonly = p_readonly;
update();
}
bool TextEdit::is_readonly() const {
return readonly;
}
void TextEdit::_update_caches() {
/* Internal API for CodeEdit. */
code_folding_color = get_theme_color(SNAME("code_folding_color"), SNAME("CodeEdit"));
@ -3254,6 +3240,21 @@ void TextEdit::_update_caches() {
}
/* Text manipulation */
// User control
void TextEdit::set_editable(const bool p_editable) {
if (editable == p_editable) {
return;
}
editable = p_editable;
update();
}
bool TextEdit::is_editable() const {
return editable;
}
void TextEdit::set_overtype_mode_enabled(const bool p_enabled) {
overtype_mode = p_enabled;
update();
@ -4361,7 +4362,7 @@ void TextEdit::_clear_redo() {
}
void TextEdit::undo() {
if (readonly) {
if (!editable) {
return;
}
@ -4414,7 +4415,7 @@ void TextEdit::undo() {
}
void TextEdit::redo() {
if (readonly) {
if (!editable) {
return;
}
_push_current_op();
@ -4787,20 +4788,16 @@ bool TextEdit::is_text_field() const {
void TextEdit::menu_option(int p_option) {
switch (p_option) {
case MENU_CUT: {
if (!readonly) {
cut();
}
cut();
} break;
case MENU_COPY: {
copy();
} break;
case MENU_PASTE: {
if (!readonly) {
paste();
}
paste();
} break;
case MENU_CLEAR: {
if (!readonly) {
if (editable) {
clear();
}
} break;
@ -4829,82 +4826,82 @@ void TextEdit::menu_option(int p_option) {
set_draw_control_chars(!get_draw_control_chars());
} break;
case MENU_INSERT_LRM: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x200E));
}
} break;
case MENU_INSERT_RLM: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x200F));
}
} break;
case MENU_INSERT_LRE: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x202A));
}
} break;
case MENU_INSERT_RLE: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x202B));
}
} break;
case MENU_INSERT_LRO: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x202D));
}
} break;
case MENU_INSERT_RLO: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x202E));
}
} break;
case MENU_INSERT_PDF: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x202C));
}
} break;
case MENU_INSERT_ALM: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x061C));
}
} break;
case MENU_INSERT_LRI: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x2066));
}
} break;
case MENU_INSERT_RLI: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x2067));
}
} break;
case MENU_INSERT_FSI: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x2068));
}
} break;
case MENU_INSERT_PDI: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x2069));
}
} break;
case MENU_INSERT_ZWJ: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x200D));
}
} break;
case MENU_INSERT_ZWNJ: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x200C));
}
} break;
case MENU_INSERT_WJ: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x2060));
}
} break;
case MENU_INSERT_SHY: {
if (!readonly) {
if (editable) {
insert_text_at_caret(String::chr(0x00AD));
}
}
@ -5036,9 +5033,6 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("center_viewport_to_caret"), &TextEdit::center_viewport_to_caret);
ClassDB::bind_method(D_METHOD("set_readonly", "enable"), &TextEdit::set_readonly);
ClassDB::bind_method(D_METHOD("is_readonly"), &TextEdit::is_readonly);
ClassDB::bind_method(D_METHOD("set_context_menu_enabled", "enable"), &TextEdit::set_context_menu_enabled);
ClassDB::bind_method(D_METHOD("is_context_menu_enabled"), &TextEdit::is_context_menu_enabled);
ClassDB::bind_method(D_METHOD("set_shortcut_keys_enabled", "enable"), &TextEdit::set_shortcut_keys_enabled);
@ -5067,6 +5061,10 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_overriding_selected_font_color"), &TextEdit::is_overriding_selected_font_color);
/* Text manipulation */
// User control
ClassDB::bind_method(D_METHOD("set_editable", "enable"), &TextEdit::set_editable);
ClassDB::bind_method(D_METHOD("is_editable"), &TextEdit::is_editable);
ClassDB::bind_method(D_METHOD("set_overtype_mode_enabled", "enabled"), &TextEdit::set_overtype_mode_enabled);
ClassDB::bind_method(D_METHOD("is_overtype_mode_enabled"), &TextEdit::is_overtype_mode_enabled);
@ -5234,7 +5232,7 @@ void TextEdit::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "language"), "set_language", "get_language");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_control_chars"), "set_draw_control_chars", "get_draw_control_chars");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "readonly"), "set_readonly", "is_readonly");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_current_line"), "set_highlight_current_line", "is_highlight_current_line_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_tabs"), "set_draw_tabs", "is_drawing_tabs");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_spaces"), "set_draw_spaces", "is_drawing_spaces");
@ -5355,18 +5353,18 @@ void TextEdit::_ensure_menu() {
// Reorganize context menu.
menu->clear();
if (!readonly) {
if (editable) {
menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_cut") : 0);
}
menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_copy") : 0);
if (!readonly) {
if (editable) {
menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_paste") : 0);
}
menu->add_separator();
if (is_selecting_enabled()) {
menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_text_select_all") : 0);
}
if (!readonly) {
if (editable) {
menu->add_item(RTR("Clear"), MENU_CLEAR);
menu->add_separator();
menu->add_item(RTR("Undo"), MENU_UNDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_undo") : 0);
@ -5377,7 +5375,7 @@ void TextEdit::_ensure_menu() {
menu->add_separator();
menu->add_check_item(RTR("Display control characters"), MENU_DISPLAY_UCC);
menu->set_item_checked(menu->get_item_index(MENU_DISPLAY_UCC), draw_control_chars);
if (!readonly) {
if (editable) {
menu->add_submenu_item(RTR("Insert control character"), "CTLMenu");
}
menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), text_direction == TEXT_DIRECTION_INHERITED);
@ -5431,7 +5429,7 @@ void TextEdit::_set_symbol_lookup_word(const String &p_symbol) {
// Overridable actions
void TextEdit::_handle_unicode_input(const uint32_t p_unicode) {
if (readonly) {
if (!editable) {
return;
}
@ -5462,7 +5460,7 @@ void TextEdit::_handle_unicode_input(const uint32_t p_unicode) {
}
void TextEdit::_backspace() {
if (readonly) {
if (!editable) {
return;
}
@ -5493,7 +5491,7 @@ void TextEdit::_backspace() {
}
void TextEdit::_cut() {
if (readonly) {
if (!editable) {
return;
}
@ -5538,7 +5536,7 @@ void TextEdit::_copy() {
}
void TextEdit::_paste() {
if (readonly) {
if (!editable) {
return;
}
@ -5792,7 +5790,7 @@ TextEdit::TextEdit() {
undo_stack_max_size = GLOBAL_GET("gui/common/text_edit_undo_stack_max_size");
set_readonly(false);
set_editable(true);
}
TextEdit::~TextEdit() {

View File

@ -188,6 +188,10 @@ private:
};
/* Text manipulation */
// User control.
/* Initialise to opposite first, so we get past the early-out in set_editable. */
bool editable = false;
bool overtype_mode = false;
String cut_copy_line = "";
@ -332,8 +336,6 @@ private:
uint32_t version = 0;
uint32_t saved_version = 0;
bool readonly = true; // Initialise to opposite first, so we get past the early-out in set_readonly.
bool window_has_focus = true;
bool first_draw = true;
@ -525,6 +527,10 @@ protected:
public:
/* Text manipulation */
// User control
void set_editable(const bool p_editable);
bool is_editable() const;
void set_overtype_mode_enabled(const bool p_enabled);
bool is_overtype_mode_enabled() const;
@ -751,9 +757,6 @@ public:
void adjust_viewport_to_caret();
void center_viewport_to_caret();
void set_readonly(bool p_readonly);
bool is_readonly() const;
void clear();
void swap_lines(int line1, int line2);