aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremias Stotter <jeremias@stotter.eu>2024-03-24 16:33:39 +0100
committerJeremias Stotter <jeremias@stotter.eu>2024-03-24 16:36:10 +0100
commit4371c1f460fbe2e6bb99101166a1c6bf6abd80cf (patch)
tree59d128feb3a0652e28aeb9ef03374f6fb3db68d1
parent682f4c115b788979ecca895f5cccba95ae0d9e48 (diff)
downloadnetwork-simulator-4371c1f460fbe2e6bb99101166a1c6bf6abd80cf.tar.gz
network-simulator-4371c1f460fbe2e6bb99101166a1c6bf6abd80cf.tar.bz2
network-simulator-4371c1f460fbe2e6bb99101166a1c6bf6abd80cf.zip
When creating a connection, the removal of old connections is now pushed on the undo stack
-rw-r--r--gui.c21
-rw-r--r--undo-redo.c3
-rw-r--r--undo-redo.h1
3 files changed, 17 insertions, 8 deletions
diff --git a/gui.c b/gui.c
index 09bca3a..9328126 100644
--- a/gui.c
+++ b/gui.c
@@ -682,19 +682,30 @@ void selection_clicked(GtkButton* self, gpointer user_data) {
connection_interface1 = (struct interface*)user_data;
} else {
// Delete any old connection
- // @todo this isn't pushed to the undo redo stack!
+ struct undo_entry* undo_new_del = NULL;
+ if(connection_interface1->connection) {
+ struct undo_del_con_data* undo_del_con_new = NULL;
+ NEW_UNDO_STRUCT(undo_del_con, undo_del_con_data, undo_new_del, undo_del_con_new);
+ undo_del_con_new->int1 = connection_interface1;
+ undo_del_con_new->int2 = (connection_interface1->connection->interface1 == connection_interface1 ? connection_interface1->connection->interface2 : connection_interface1->connection->interface1);
+ undo_del_con_new->template = connection_interface1->connection->template;
+ }
+
delete_connection(connection_interface1->connection);
delete_connection(((struct interface*)user_data)->connection);
// Create the connection
new_connection(connection_interface1, (struct interface*)user_data, selected_connection_template);
- struct undo_entry* undo_new = NULL;
+ struct undo_entry* undo_new_add = NULL;
struct undo_add_con_data* undo_add_con_new = NULL;
- NEW_UNDO_STRUCT(undo_add_con, undo_add_con_data, undo_new, undo_add_con_new);
- undo_add_con_new->con = connection_interface1->connection;
+ NEW_UNDO_STRUCT(undo_add_con, undo_add_con_data, undo_new_add, undo_add_con_new);
+ if(undo_new_del) {
+ undo_new_del->prev_sibling = undo_new_add;
+ undo_new_add->next_sibling = undo_new_del;
+ }
undo_add_con_new->int1 = connection_interface1;
undo_add_con_new->int2 = (struct interface*)user_data;
undo_add_con_new->template = selected_connection_template;
- undo_add_entry(undo_new);
+ undo_add_entry(undo_new_add);
connection_interface1 = NULL;
}
diff --git a/undo-redo.c b/undo-redo.c
index ba0444a..ece1886 100644
--- a/undo-redo.c
+++ b/undo-redo.c
@@ -162,7 +162,7 @@ int undo() {
case undo_add_con:
{
struct undo_add_con_data* add_con_data = uentry->undo_data;
- delete_connection(add_con_data->con);
+ delete_connection(add_con_data->int1->connection);
}
break;
case undo_del_con:
@@ -246,7 +246,6 @@ int redo() {
{
struct undo_add_con_data* add_con_data = rentry->undo_data;
new_connection(add_con_data->int1, add_con_data->int2, add_con_data->template);
- add_con_data->con = add_con_data->int1->connection;
}
break;
case undo_del_con:
diff --git a/undo-redo.h b/undo-redo.h
index 5c42fdb..6b11ed9 100644
--- a/undo-redo.h
+++ b/undo-redo.h
@@ -75,7 +75,6 @@ struct undo_del_dev_data {
};
struct undo_add_con_data {
- struct connection* con;
struct interface* int1;
struct interface* int2;
struct connection_template* template;
Jeremias Stotters git repositories generated by CGIT