gtkhtml r9054 - trunk/components/editor
- From: mbarnes svn gnome org
- To: svn-commits-list gnome org
- Subject: gtkhtml r9054 - trunk/components/editor
- Date: Thu, 27 Nov 2008 14:55:40 +0000 (UTC)
Author: mbarnes
Date: Thu Nov 27 14:55:40 2008
New Revision: 9054
URL: http://svn.gnome.org/viewvc/gtkhtml?rev=9054&view=rev
Log:
2008-11-27 Matthew Barnes <mbarnes redhat com>
** Fixes bug #330452
* gtkhtml-editor-ui:
Move spell check items to the top of the context menu.
Add a "More Suggestions" menu after the "spell-suggest" placeholder.
* gtkhtml-editor-actions.c (spell_context_entries):
Define an action for the "More Suggestions" menu.
* gtkhtml-editor-private.c:
Display spelling suggestions in bold text.
When only a single language is selected, display spelling suggestions
directly in the context menu. If the list of suggestions grows too
long, put the rest under a "More Suggestions" menu. "Too long" is
defined by a constant: MAX_LEVEL1_SUGGESTIONS (currently 4).
Modified:
trunk/components/editor/ChangeLog
trunk/components/editor/gtkhtml-editor-actions.c
trunk/components/editor/gtkhtml-editor-private.c
trunk/components/editor/gtkhtml-editor.ui
Modified: trunk/components/editor/gtkhtml-editor-actions.c
==============================================================================
--- trunk/components/editor/gtkhtml-editor-actions.c (original)
+++ trunk/components/editor/gtkhtml-editor-actions.c Thu Nov 27 14:55:40 2008
@@ -2153,6 +2153,15 @@
N_("Add Word To"),
NULL,
NULL,
+ NULL },
+
+ /* Menus */
+
+ { "context-more-suggestions-menu",
+ NULL,
+ N_("More Suggestions"),
+ NULL,
+ NULL,
NULL }
};
Modified: trunk/components/editor/gtkhtml-editor-private.c
==============================================================================
--- trunk/components/editor/gtkhtml-editor-private.c (original)
+++ trunk/components/editor/gtkhtml-editor-private.c Thu Nov 27 14:55:40 2008
@@ -41,6 +41,26 @@
"\nSee http://www.freedesktop.org/Standards/basedir-spec for more\n" \
"information about standard base directories.\n\n"
+/* This controls how spelling suggestions are divided between the primary
+ * context menu and a secondary menu. The idea is to prevent the primary
+ * menu from growing too long.
+ *
+ * The constants below are used as follows:
+ *
+ * if TOTAL_SUGGESTIONS <= MAX_LEVEL1_SUGGETIONS:
+ * LEVEL1_SUGGESTIONS = TOTAL_SUGGESTIONS
+ * elif TOTAL_SUGGESTIONS - MAX_LEVEL1_SUGGESTIONS < MIN_LEVEL2_SUGGESTIONS:
+ * LEVEL1_SUGGESTIONS = TOTAL_SUGGESTIONS
+ * else
+ * LEVEL1_SUGGESTIONS = MAX_LEVEL1_SUGGETIONS
+ *
+ * LEVEL2_SUGGESTIONS = TOTAL_SUGGESTIONS - LEVEL1_SUGGESTIONS
+ *
+ * Note that MAX_LEVEL1_SUGGETIONS is not a hard maximum.
+ */
+#define MAX_LEVEL1_SUGGESTIONS 4
+#define MIN_LEVEL2_SUGGESTIONS 3
+
/************************ Begin Spell Dialog Callbacks ***********************/
static void
@@ -674,17 +694,103 @@
GtkhtmlEditor *editor)
{
GtkHTML *html;
- gchar *label;
+ const gchar *word;
+
+ html = gtkhtml_editor_get_html (editor);
+
+ word = g_object_get_data (G_OBJECT (action), "word");
+ g_return_if_fail (word != NULL);
+
+ html_engine_replace_spell_word_with (html->engine, word);
+}
+
+static void
+editor_inline_spelling_suggestions (GtkhtmlEditor *editor,
+ GtkhtmlSpellChecker *checker)
+{
+ GtkActionGroup *action_group;
+ GtkUIManager *manager;
+ GtkHTML *html;
+ GList *list;
+ const gchar *path;
+ gchar *word;
+ guint count = 0;
+ guint length;
+ guint merge_id;
+ guint threshold;
html = gtkhtml_editor_get_html (editor);
+ word = html_engine_get_spell_word (html->engine);
+ list = gtkhtml_spell_checker_get_suggestions (checker, word, -1);
+
+ path = "/context-menu/context-spell-suggest/";
+ manager = gtkhtml_editor_get_ui_manager (editor);
+ action_group = editor->priv->suggestion_actions;
+ merge_id = editor->priv->spell_suggestions_merge_id;
+
+ /* Calculate how many suggestions to put directly in the
+ * context menu. The rest will go in a secondary menu. */
+ length = g_list_length (list);
+ if (length <= MAX_LEVEL1_SUGGESTIONS)
+ threshold = length;
+ else if (length - MAX_LEVEL1_SUGGESTIONS < MIN_LEVEL2_SUGGESTIONS)
+ threshold = length;
+ else
+ threshold = MAX_LEVEL1_SUGGESTIONS;
+
+ while (list != NULL) {
+ gchar *suggestion = list->data;
+ gchar *action_name;
+ gchar *action_label;
+ GtkAction *action;
+ GtkWidget *child;
+ GSList *proxies;
+
+ /* Once we reach the threshold, put all subsequent
+ * spelling suggestions in a secondary menu. */
+ if (count == threshold)
+ path = "/context-menu/context-more-suggestions-menu/";
+
+ /* Action name just needs to be unique. */
+ action_name = g_strdup_printf ("suggest-%d", count++);
- /* The action's label is the replacement word. */
- g_object_get (action, "label", &label, NULL);
- g_return_if_fail (label != NULL);
+ action_label = g_markup_printf_escaped (
+ "<b>%s</b>", suggestion);
- html_engine_replace_spell_word_with (html->engine, label);
+ action = gtk_action_new (
+ action_name, action_label, NULL, NULL);
+
+ g_object_set_data_full (
+ G_OBJECT (action), "word",
+ g_strdup (suggestion), g_free);
+
+ g_signal_connect (
+ action, "activate", G_CALLBACK (
+ action_context_spell_suggest_cb), editor);
+
+ gtk_action_group_add_action (action_group, action);
+
+ gtk_ui_manager_add_ui (
+ manager, merge_id, path,
+ action_name, action_name,
+ GTK_UI_MANAGER_AUTO, FALSE);
+
+ /* XXX GtkAction offers no support for Pango markup,
+ * so we have to manually set "use-markup" on the
+ * child of the proxy widget. */
+ gtk_ui_manager_ensure_update (manager);
+ proxies = gtk_action_get_proxies (action);
+ child = gtk_bin_get_child (proxies->data);
+ g_object_set (child, "use-markup", TRUE, NULL);
- g_free (label);
+ g_free (suggestion);
+ g_free (action_name);
+ g_free (action_label);
+
+ list = g_list_delete_link (list, list);
+ }
+
+ g_free (word);
}
/* Helper for gtkhtml_editor_update_context() */
@@ -719,17 +825,27 @@
"context-spell-suggest-%s-menu", language_code);
while (list != NULL) {
- gchar *action_label = list->data;
+ gchar *suggestion = list->data;
gchar *action_name;
+ gchar *action_label;
GtkAction *action;
+ GtkWidget *child;
+ GSList *proxies;
/* Action name just needs to be unique. */
action_name = g_strdup_printf (
"suggest-%s-%d", language_code, count++);
+ action_label = g_markup_printf_escaped (
+ "<b>%s</b>", suggestion);
+
action = gtk_action_new (
action_name, action_label, NULL, NULL);
+ g_object_set_data_full (
+ G_OBJECT (action), "word",
+ g_strdup (suggestion), g_free);
+
g_signal_connect (
action, "activate", G_CALLBACK (
action_context_spell_suggest_cb), editor);
@@ -741,8 +857,17 @@
action_name, action_name,
GTK_UI_MANAGER_AUTO, FALSE);
- g_free (action_label);
+ /* XXX GtkAction offers no supports for Pango markup,
+ * so we have to manually set "use-markup" on the
+ * child of the proxy widget. */
+ gtk_ui_manager_ensure_update (manager);
+ proxies = gtk_action_get_proxies (action);
+ child = gtk_bin_get_child (proxies->data);
+ g_object_set (child, "use-markup", TRUE, NULL);
+
+ g_free (suggestion);
g_free (action_name);
+ g_free (action_label);
list = g_list_delete_link (list, list);
}
@@ -880,6 +1005,12 @@
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);
}
Modified: trunk/components/editor/gtkhtml-editor.ui
==============================================================================
--- trunk/components/editor/gtkhtml-editor.ui (original)
+++ trunk/components/editor/gtkhtml-editor.ui Thu Nov 27 14:55:40 2008
@@ -137,6 +137,13 @@
<toolitem action='insert-table'/>
</toolbar>
<popup name='context-menu'>
+ <placeholder name='context-spell-suggest'/>
+ <menu action='context-more-suggestions-menu'/>
+ <separator/>
+ <menuitem action='context-spell-ignore'/>
+ <menu action='context-spell-add-menu'/>
+ <menuitem action='context-spell-add'/>
+ <separator/>
<menuitem action='undo'/>
<menuitem action='redo'/>
<separator/>
@@ -175,12 +182,6 @@
<menuitem action='context-delete-cell'/>
</menu>
<separator/>
- <placeholder name='context-spell-suggest'/>
- <separator/>
- <menuitem action='context-spell-ignore'/>
- <menu action='context-spell-add-menu'/>
- <menuitem action='context-spell-add'/>
- <separator/>
<menu action='context-input-methods-menu'/>
</popup>
</ui>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]