From 85609f6ae792a5797ee14bb36eda7a41c14d0a33 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sun, 24 Sep 2017 13:55:09 -0400 Subject: MqTab: Add tree manipulation functions --- (limited to 'src') diff --git a/src/tab.c b/src/tab.c index 47d048c..b633344 100644 --- a/src/tab.c +++ b/src/tab.c @@ -28,6 +28,67 @@ #include "tab-body.h" static void +update_positions(MqTab *node, step) +{ + if (node) { + node->position += step; + update_tab_label(node); + if (node->next) { + update_positions(node->next); + } else if (node->parent && node->parent->next) { + update_positions(node->parent->next); + } + } +} + +static void +update_tree_sizes(MqTab node, guint step) +{ + if (node) { + node->tree_size += step; + update_tree_sizes(node->parent, step); + } +} + +static void +append_child(MqTab *new_node, MqTab *parent) +{ + new_node->parent = parent; + new_node->next = NULL; + new_node->prev = parent->last_child; /* May be NULL */ + new_node->first_child = new_node->last_child = NULL; + new_node->position = parent->position; /* Will be updated */ + new_node->tree_size = 0; /* Will be updated */ + if (parent->last_child) { + parent->last_child->next = new_node; + } else { + parent->first_child = new_node; + } + parent->last_child = new_node; + update_positions(new_node, 1); + update_tree_sizes(new_node, 1); +} + +static void +append_sibling(MqTab *new_node, MqTab *prev_sibling) +{ + new_node->parent = prev_sibling->parent; + new_node->prev = prev_sibling; + new_node->next = prev_sibling->next; /* May be NULL */ + new_node->first_child = new_node->last_child = NULL; + new_node->position = prev_sibling->position; /* Will be updated */ + new_node->tree_size = 0; /* Will be updated */ + if (parent->last_child) { + parent->last_child->next = new_node; + } else { + parent->first_child = new_node; + } + parent->last_child = new_node; + update_positions(new_node, 1); + update_tree_sizes(new_node, 1); +} + +static void reload_tab_clicked_cb(GtkWidget __attribute__((unused)) *button, MqTab *tab) { webkit_web_view_reload(tab->web_view); -- cgit v0.9.1