From 4020dbcc54379ec163d9a2b6304f54ef220419c2 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 26 Sep 2017 19:14:15 -0400 Subject: MqTabBody: Define macros to preserve/restore menu items --- (limited to 'src') diff --git a/src/tab-body.c b/src/tab-body.c index 5010c5d..b2276f8 100644 --- a/src/tab-body.c +++ b/src/tab-body.c @@ -102,6 +102,13 @@ menu_open_image_win_activate_cb(GtkAction __attribute__((unused)) *action, webkit_context_menu_append(context_menu, \ webkit_context_menu_item_new_separator()); \ } while (0) +#define RESTORE_ITEMS(ITEMS) \ + do { \ + for (; ITEMS; ITEMS = ITEMS->next) { \ + webkit_context_menu_append(context_menu, ITEMS->data); \ + g_object_unref(ITEMS->data); \ + } \ + } while (0) static void context_menu_link_cb(WebKitContextMenu *context_menu, MqTabBody *body) @@ -134,17 +141,19 @@ context_menu_document_cb(WebKitContextMenu *context_menu, GList *nav_items, { ITEM_DECLS_NO_CUSTOM - /* Back, Forward, Stop, Reload */ - for (; nav_items; nav_items = nav_items->next) { - webkit_context_menu_append(context_menu, nav_items->data); - g_object_unref(nav_items->data); - } + RESTORE_ITEMS(nav_items); /* Back, Forward, Stop, Reload */ NEW_SEPARATOR_ITEM(); /* --- */ NEW_STOCK_ITEM(SELECT_ALL); /* Select All */ NEW_SEPARATOR_ITEM(); /* --- */ /* View Page Source */ } +#define PRESERVE_ITEM(ITEMS) \ + do { \ + g_object_ref(items->data); \ + ITEMS = g_list_prepend(ITEMS, items->data); \ + } while (0) + static gboolean context_menu_cb(WebKitWebView __attribute__((unused)) *web_view, WebKitContextMenu *context_menu, @@ -181,25 +190,21 @@ context_menu_cb(WebKitWebView __attribute__((unused)) *web_view, case WKCMA(GO_FORWARD): case WKCMA(STOP): case WKCMA(RELOAD): - g_object_ref(items->data); - nav_items = g_list_prepend(nav_items, - items->data); + PRESERVE_ITEM(nav_items); break; case WKCMA(COPY): is_selection = TRUE; break; case WKCMA(INPUT_METHODS): case WKCMA(UNICODE): - input_items = g_list_prepend(input_items, - items->data); + PRESERVE_ITEM(input_items); break; case WKCMA(SPELLING_GUESS): case WKCMA(NO_GUESSES_FOUND): case WKCMA(IGNORE_SPELLING): case WKCMA(LEARN_SPELLING): case WKCMA(IGNORE_GRAMMAR): - spell_items = g_list_prepend(spell_items, - items->data); + PRESERVE_ITEM(spell_items); break; case WKCMA(OPEN_VIDEO_IN_NEW_WINDOW): case WKCMA(COPY_VIDEO_LINK_TO_CLIPBOARD): -- cgit v0.9.1