From 07eb43b8361a920c045351d4ca11f1b68ba20ce9 Mon Sep 17 00:00:00 2001 From: don-tnowe <67479453+don-tnowe@users.noreply.github.com> Date: Thu, 22 Sep 2022 22:27:09 +0300 Subject: [PATCH] Change Inspector edits to be undoable --- .../resources_speadsheet_view/editor_view.gd | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/addons/resources_speadsheet_view/editor_view.gd b/addons/resources_speadsheet_view/editor_view.gd index d82b5bf..0276e38 100644 --- a/addons/resources_speadsheet_view/editor_view.gd +++ b/addons/resources_speadsheet_view/editor_view.gd @@ -292,9 +292,7 @@ func deselect_cell(cell : Control): func select_cell(cell : Control): var column_index := _get_cell_column(cell) if _can_select_cell(cell): - column_editors[column_index].set_selected(cell, true) - edited_cells.append(cell) - edit_cursor_positions.append(column_editors[column_index].get_text_length(cell)) + _add_cell_to_selection(cell) _try_open_docks(cell) inspector_resource = rows[_get_cell_row(cell)].duplicate() editor_plugin.get_editor_interface().edit_resource(inspector_resource) @@ -321,6 +319,12 @@ func select_cell(cell : Control): edit_cursor_positions.append(column_editors[column_index].get_text_length(cur_cell)) +func _add_cell_to_selection(cell : Control): + column_editors[_get_cell_column(cell)].set_selected(cell, true) + edited_cells.append(cell) + edit_cursor_positions.append(column_editors[_get_cell_column(cell)].get_text_length(cell)) + + func _try_open_docks(cell : Control): var column_index = _get_cell_column(cell) for x in get_node(path_property_editors).get_children(): @@ -613,9 +617,20 @@ func _on_inspector_property_edited(property : String): if inspector_resource == null: return var value = inspector_resource.get(property) - for x in edited_cells: - rows[_get_cell_row(x)].set(property, value) - _update_row(_get_cell_row(x)) + var values = [] + values.resize(edited_cells.size()) + for i in edited_cells.size(): + values[i] = value - # Resources could stop being null, sooooo... + var previously_edited = edited_cells + if columns[_get_cell_column(edited_cells[0])] != property: + previously_edited = previously_edited.duplicate() + var new_column := columns.find(property) + deselect_all_cells() + var index := 0 + for i in previously_edited.size(): + index = (_get_cell_row(previously_edited[i]) + 1) * columns.size() + new_column + _add_cell_to_selection(get_node(path_table_root).get_child(index)) + + set_edited_cells_values(values) _try_open_docks(edited_cells[0])