static gboolean html_engine_get_table_start_end_cells (HTMLEngine *e, HTMLTableCell **start_cell, HTMLTableCell **end_cell) { if (!e->cursor->object->parent || !e->cursor->object->parent->parent || !HTML_IS_TABLE_CELL (e->cursor->object->parent->parent)) return FALSE; if (html_engine_is_selection_active (e)) { if (!e->mark->object->parent || !e->mark->object->parent->parent || !HTML_IS_TABLE_CELL (e->mark->object->parent->parent) || HTML_TABLE (e->mark->object->parent->parent->parent) != html_engine_get_table (e)) return FALSE; if (html_cursor_precedes (e->cursor, e->mark)) { *start_cell = HTML_TABLE_CELL (e->cursor->object->parent->parent); *end_cell = HTML_TABLE_CELL (e->mark->object->parent->parent); } else { *start_cell = HTML_TABLE_CELL (e->mark->object->parent->parent); *end_cell = HTML_TABLE_CELL (e->cursor->object->parent->parent); } } else { *start_cell = *end_cell = html_engine_get_table_cell (e); } return TRUE; }
void gtkhtml_editor_update_context (GtkhtmlEditor *editor) { GtkHTML *html; HTMLType type; HTMLObject *object; GtkUIManager *manager; GtkActionGroup *action_group; GList *list; gboolean visible; guint merge_id; html = gtkhtml_editor_get_html (editor); manager = gtkhtml_editor_get_ui_manager (editor); gtk_html_update_styles (html); /* Update context menu item visibility. */ object = html->engine->cursor->object; if (object != NULL) type = HTML_OBJECT_TYPE (object); else type = HTML_TYPE_NONE; visible = (type == HTML_TYPE_IMAGE); gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_IMAGE), visible); visible = (type == HTML_TYPE_LINKTEXT); gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_LINK), visible); visible = (type == HTML_TYPE_RULE); gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_RULE), visible); visible = (type == HTML_TYPE_TEXT); gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_TEXT), visible); visible = gtk_action_get_visible (ACTION (CONTEXT_PROPERTIES_IMAGE)) || gtk_action_get_visible (ACTION (CONTEXT_PROPERTIES_LINK)) || gtk_action_get_visible (ACTION (CONTEXT_PROPERTIES_TEXT)); gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_PARAGRAPH), visible); /* Set to visible if any of these are true: * - Selection is active and contains a link. * - Cursor is on a link. * - Cursor is on an image that has a URL or target. */ visible = (html_engine_is_selection_active (html->engine) && html_engine_selection_contains_link (html->engine)) || (type == HTML_TYPE_LINKTEXT) || (type == HTML_TYPE_IMAGE && (HTML_IMAGE (object)->url != NULL || HTML_IMAGE (object)->target != NULL)); gtk_action_set_visible (ACTION (CONTEXT_REMOVE_LINK), visible); /* Get the parent object. */ object = (object != NULL) ? object->parent : NULL; /* Get the grandparent object. */ object = (object != NULL) ? object->parent : NULL; if (object != NULL) type = HTML_OBJECT_TYPE (object); else type = HTML_TYPE_NONE; visible = (type == HTML_TYPE_TABLECELL); gtk_action_set_visible (ACTION (CONTEXT_DELETE_CELL), visible); gtk_action_set_visible (ACTION (CONTEXT_DELETE_COLUMN), visible); gtk_action_set_visible (ACTION (CONTEXT_DELETE_ROW), visible); gtk_action_set_visible (ACTION (CONTEXT_DELETE_TABLE), visible); gtk_action_set_visible (ACTION (CONTEXT_INSERT_COLUMN_AFTER), visible); gtk_action_set_visible (ACTION (CONTEXT_INSERT_COLUMN_BEFORE), visible); gtk_action_set_visible (ACTION (CONTEXT_INSERT_ROW_ABOVE), visible); gtk_action_set_visible (ACTION (CONTEXT_INSERT_ROW_BELOW), visible); gtk_action_set_visible (ACTION (CONTEXT_INSERT_TABLE), visible); gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_CELL), visible); /* Get the great grandparent object. */ object = (object != NULL) ? object->parent : NULL; if (object != NULL) type = HTML_OBJECT_TYPE (object); else type = HTML_TYPE_NONE; /* Note the |= (cursor must be in a table cell). */ visible |= (type == HTML_TYPE_TABLE); gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_TABLE), visible); /********************** Spell Check Suggestions **********************/ object = html->engine->cursor->object; action_group = editor->priv->suggestion_actions; /* Remove the old content from the context menu. */ merge_id = editor->priv->spell_suggestions_merge_id; if (merge_id > 0) { gtk_ui_manager_remove_ui (manager, merge_id); editor->priv->spell_suggestions_merge_id = 0; } /* Clear the action group for spelling suggestions. */ list = gtk_action_group_list_actions (action_group); while (list != NULL) { GtkAction *action = list->data; gtk_action_group_remove_action (action_group, action); list = g_list_delete_link (list, list); } /* Decide if we should show spell checking items. */ visible = !html_engine_is_selection_active (html->engine) && object != NULL && html_object_is_text (object) && !html_engine_spell_word_is_valid (html->engine); action_group = editor->priv->spell_check_actions; gtk_action_group_set_visible (action_group, visible); /* Exit early if spell checking items are invisible. */ if (!visible) return; list = editor->priv->active_spell_checkers; merge_id = gtk_ui_manager_new_merge_id (manager); editor->priv->spell_suggestions_merge_id = merge_id; /* Handle a single active language as a special case. */ if (g_list_length (list) == 1) { editor_inline_spelling_suggestions (editor, list->data); return; } /* Add actions and context menu content for active languages. */ g_list_foreach (list, (GFunc) editor_spell_checkers_foreach, editor); }