diff options
author | Davyd Madeley <davyd@madeley.id.au> | 2009-04-24 09:07:25 +0800 |
---|---|---|
committer | Davyd Madeley <davyd@madeley.id.au> | 2009-04-24 09:07:25 +0800 |
commit | b8a72ca6c86a001e6c7f8ff6fb761cfe8221b6b4 (patch) | |
tree | f6fd31036a541cd09f81154487926a1928e7490e /libempathy-gtk | |
parent | 055e2787d98e48a51eb4345c6e375776ec615072 (diff) | |
parent | e792e16499f942c6669ce12417118968a71a75c0 (diff) | |
download | gsoc2013-empathy-b8a72ca6c86a001e6c7f8ff6fb761cfe8221b6b4.tar gsoc2013-empathy-b8a72ca6c86a001e6c7f8ff6fb761cfe8221b6b4.tar.gz gsoc2013-empathy-b8a72ca6c86a001e6c7f8ff6fb761cfe8221b6b4.tar.bz2 gsoc2013-empathy-b8a72ca6c86a001e6c7f8ff6fb761cfe8221b6b4.tar.lz gsoc2013-empathy-b8a72ca6c86a001e6c7f8ff6fb761cfe8221b6b4.tar.xz gsoc2013-empathy-b8a72ca6c86a001e6c7f8ff6fb761cfe8221b6b4.tar.zst gsoc2013-empathy-b8a72ca6c86a001e6c7f8ff6fb761cfe8221b6b4.zip |
Merge branch 'spelling-578399'
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/Makefile.am | 3 | ||||
-rw-r--r-- | libempathy-gtk/empathy-chat.c | 61 | ||||
-rw-r--r-- | libempathy-gtk/empathy-spell-dialog.c | 264 | ||||
-rw-r--r-- | libempathy-gtk/empathy-spell-dialog.h | 39 | ||||
-rw-r--r-- | libempathy-gtk/empathy-spell-dialog.ui | 131 |
5 files changed, 45 insertions, 453 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 63bcf5ae3..2065589e3 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -49,7 +49,6 @@ libempathy_gtk_la_SOURCES = \ empathy-profile-chooser.c \ empathy-smiley-manager.c \ empathy-spell.c \ - empathy-spell-dialog.c \ empathy-status-preset-dialog.c \ empathy-theme-boxes.c \ empathy-theme-irc.c \ @@ -103,7 +102,6 @@ libempathy_gtk_headers = \ empathy-profile-chooser.h \ empathy-smiley-manager.h \ empathy-spell.h \ - empathy-spell-dialog.h \ empathy-status-preset-dialog.h \ empathy-theme-boxes.h \ empathy-theme-irc.h \ @@ -129,7 +127,6 @@ ui_DATA = \ empathy-account-widget-yahoo.ui \ empathy-account-widget-groupwise.ui \ empathy-account-widget-aim.ui \ - empathy-spell-dialog.ui \ empathy-status-preset-dialog.ui \ empathy-log-window.ui \ empathy-chat.ui \ diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index 985eaa4cf..425a1c555 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -45,7 +45,6 @@ #include "empathy-chat.h" #include "empathy-conf.h" #include "empathy-spell.h" -#include "empathy-spell-dialog.h" #include "empathy-contact-list-store.h" #include "empathy-contact-list-view.h" #include "empathy-contact-menu.h" @@ -595,7 +594,7 @@ chat_property_changed_cb (EmpathyTpChat *tp_chat, static void chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer, - EmpathyChat *chat) + EmpathyChat *chat) { EmpathyChatPriv *priv; GtkTextIter start, end; @@ -611,8 +610,8 @@ chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer, } empathy_conf_get_bool (empathy_conf_get (), - EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED, - &spell_checker); + EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED, + &spell_checker); gtk_text_buffer_get_start_iter (buffer, &start); @@ -931,13 +930,42 @@ chat_spell_free (EmpathyChatSpell *chat_spell) } static void -chat_text_check_word_spelling_cb (GtkMenuItem *menuitem, - EmpathyChatSpell *chat_spell) +chat_spelling_menu_activate_cb (GtkMenuItem *menu_item, + EmpathyChatSpell *chat_spell) { - empathy_spell_dialog_show (chat_spell->chat, - &chat_spell->start, - &chat_spell->end, - chat_spell->word); + empathy_chat_correct_word (chat_spell->chat, + &(chat_spell->start), + &(chat_spell->end), + gtk_menu_item_get_label (menu_item)); +} + +static GtkWidget* +chat_spelling_build_menu (EmpathyChatSpell *chat_spell) +{ + GtkWidget *menu, *menu_item; + GList *suggestions, *l; + + menu = gtk_menu_new (); + suggestions = empathy_spell_get_suggestions (chat_spell->word); + if (suggestions == NULL) { + menu_item = gtk_menu_item_new_with_label (_("(No Suggestions)")); + gtk_widget_set_sensitive (menu_item, FALSE); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + } else { + for (l = suggestions; l; l = l->next) { + menu_item = gtk_menu_item_new_with_label (l->data); + g_signal_connect (G_OBJECT (menu_item), + "activate", + G_CALLBACK (chat_spelling_menu_activate_cb), + chat_spell); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + } + } + empathy_spell_free_suggestions (suggestions); + + gtk_widget_show_all (menu); + + return menu; } static void @@ -960,7 +988,8 @@ chat_input_populate_popup_cb (GtkTextView *view, GtkTextIter iter, start, end; GtkWidget *item; gchar *str = NULL; - EmpathyChatSpell *chat_spell; + EmpathyChatSpell *chat_spell; + GtkWidget *spell_menu; EmpathySmileyManager *smiley_manager; GtkWidget *smiley_menu; GtkWidget *image; @@ -1025,14 +1054,14 @@ chat_input_populate_popup_cb (GtkTextView *view, gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); - item = gtk_image_menu_item_new_with_mnemonic (_("_Check Word Spelling...")); + item = gtk_image_menu_item_new_with_mnemonic (_("_Spelling Suggestions")); image = gtk_image_new_from_icon_name (GTK_STOCK_SPELL_CHECK, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); - g_signal_connect (item, - "activate", - G_CALLBACK (chat_text_check_word_spelling_cb), - chat_spell); + + spell_menu = chat_spelling_build_menu (chat_spell); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), spell_menu); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); } diff --git a/libempathy-gtk/empathy-spell-dialog.c b/libempathy-gtk/empathy-spell-dialog.c deleted file mode 100644 index 9ce80eebb..000000000 --- a/libempathy-gtk/empathy-spell-dialog.c +++ /dev/null @@ -1,264 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2004-2007 Imendio AB - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "config.h" - -#include <string.h> - -#include <glib/gi18n-lib.h> -#include <gtk/gtk.h> - -#include <libempathy/empathy-utils.h> - -#include "empathy-chat.h" -#include "empathy-spell.h" -#include "empathy-spell-dialog.h" -#include "empathy-ui-utils.h" - -typedef struct { - GtkWidget *window; - GtkWidget *button_replace; - GtkWidget *label_word; - GtkWidget *treeview_words; - - EmpathyChat *chat; - - gchar *word; - GtkTextIter start; - GtkTextIter end; -} EmpathySpellDialog; - -enum { - COL_SPELL_WORD, - COL_SPELL_COUNT -}; - -static void spell_dialog_model_populate_columns (EmpathySpellDialog *dialog); -static void spell_dialog_model_populate_suggestions (EmpathySpellDialog *dialog); -static void spell_dialog_model_row_activated_cb (GtkTreeView *tree_view, - GtkTreePath *path, - GtkTreeViewColumn *column, - EmpathySpellDialog *dialog); -static void spell_dialog_model_selection_changed_cb (GtkTreeSelection *treeselection, - EmpathySpellDialog *dialog); -static void spell_dialog_model_setup (EmpathySpellDialog *dialog); -static void spell_dialog_response_cb (GtkWidget *widget, - gint response, - EmpathySpellDialog *dialog); -static void spell_dialog_destroy_cb (GtkWidget *widget, - EmpathySpellDialog *dialog); - -static void -spell_dialog_model_populate_columns (EmpathySpellDialog *dialog) -{ - GtkTreeModel *model; - GtkTreeViewColumn *column; - GtkCellRenderer *renderer; - guint col_offset; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview_words)); - - renderer = gtk_cell_renderer_text_new (); - col_offset = gtk_tree_view_insert_column_with_attributes ( - GTK_TREE_VIEW (dialog->treeview_words), - -1, _("Word"), - renderer, - "text", COL_SPELL_WORD, - NULL); - - g_object_set_data (G_OBJECT (renderer), - "column", GINT_TO_POINTER (COL_SPELL_WORD)); - - column = gtk_tree_view_get_column (GTK_TREE_VIEW (dialog->treeview_words), col_offset - 1); - gtk_tree_view_column_set_sort_column_id (column, COL_SPELL_WORD); - gtk_tree_view_column_set_resizable (column, FALSE); - gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE); -} - -static void -spell_dialog_model_populate_suggestions (EmpathySpellDialog *dialog) -{ - GtkTreeModel *model; - GtkListStore *store; - GList *suggestions, *l; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview_words)); - store = GTK_LIST_STORE (model); - - suggestions = empathy_spell_get_suggestions (dialog->word); - for (l = suggestions; l; l=l->next) { - GtkTreeIter iter; - gchar *word; - - word = l->data; - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - COL_SPELL_WORD, word, - -1); - } - - empathy_spell_free_suggestions (suggestions); -} - -static void -spell_dialog_model_row_activated_cb (GtkTreeView *tree_view, - GtkTreePath *path, - GtkTreeViewColumn *column, - EmpathySpellDialog *dialog) -{ - spell_dialog_response_cb (dialog->window, GTK_RESPONSE_OK, dialog); -} - -static void -spell_dialog_model_selection_changed_cb (GtkTreeSelection *treeselection, - EmpathySpellDialog *dialog) -{ - gint count; - - count = gtk_tree_selection_count_selected_rows (treeselection); - gtk_widget_set_sensitive (dialog->button_replace, (count == 1)); -} - -static void -spell_dialog_model_setup (EmpathySpellDialog *dialog) -{ - GtkTreeView *view; - GtkListStore *store; - GtkTreeSelection *selection; - - view = GTK_TREE_VIEW (dialog->treeview_words); - - g_signal_connect (view, "row-activated", - G_CALLBACK (spell_dialog_model_row_activated_cb), - dialog); - - store = gtk_list_store_new (COL_SPELL_COUNT, - G_TYPE_STRING); /* word */ - - gtk_tree_view_set_model (view, GTK_TREE_MODEL (store)); - - selection = gtk_tree_view_get_selection (view); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); - - g_signal_connect (selection, "changed", - G_CALLBACK (spell_dialog_model_selection_changed_cb), - dialog); - - spell_dialog_model_populate_columns (dialog); - spell_dialog_model_populate_suggestions (dialog); - - g_object_unref (store); -} - -static void -spell_dialog_destroy_cb (GtkWidget *widget, - EmpathySpellDialog *dialog) -{ - g_object_unref (dialog->chat); - g_free (dialog->word); - - g_free (dialog); -} - -static void -spell_dialog_response_cb (GtkWidget *widget, - gint response, - EmpathySpellDialog *dialog) -{ - if (response == GTK_RESPONSE_OK) { - GtkTreeView *view; - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreeIter iter; - - gchar *new_word; - - view = GTK_TREE_VIEW (dialog->treeview_words); - selection = gtk_tree_view_get_selection (view); - - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { - return; - } - - gtk_tree_model_get (model, &iter, COL_SPELL_WORD, &new_word, -1); - - empathy_chat_correct_word (dialog->chat, - &dialog->start, - &dialog->end, - new_word); - - g_free (new_word); - } - - gtk_widget_destroy (dialog->window); -} - -void -empathy_spell_dialog_show (EmpathyChat *chat, - GtkTextIter *start, - GtkTextIter *end, - const gchar *word) -{ - EmpathySpellDialog *dialog; - GtkBuilder *gui; - gchar *str; - gchar *filename; - - g_return_if_fail (chat != NULL); - g_return_if_fail (word != NULL); - - dialog = g_new0 (EmpathySpellDialog, 1); - - dialog->chat = g_object_ref (chat); - - dialog->word = g_strdup (word); - - dialog->start = *start; - dialog->end = *end; - - filename = empathy_file_lookup ("empathy-spell-dialog.ui", - "libempathy-gtk"); - gui = empathy_builder_get_file (filename, - "spell_dialog", &dialog->window, - "button_replace", &dialog->button_replace, - "label_word", &dialog->label_word, - "treeview_words", &dialog->treeview_words, - NULL); - g_free (filename); - - empathy_builder_connect (gui, dialog, - "spell_dialog", "response", spell_dialog_response_cb, - "spell_dialog", "destroy", spell_dialog_destroy_cb, - NULL); - - g_object_unref (gui); - - str = g_markup_printf_escaped ("%s:\n<b>%s</b>", - _("Suggestions for the word"), - word); - - gtk_label_set_markup (GTK_LABEL (dialog->label_word), str); - g_free (str); - - spell_dialog_model_setup (dialog); - - gtk_widget_show (dialog->window); -} diff --git a/libempathy-gtk/empathy-spell-dialog.h b/libempathy-gtk/empathy-spell-dialog.h deleted file mode 100644 index ce0218812..000000000 --- a/libempathy-gtk/empathy-spell-dialog.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2004-2007 Imendio AB - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Authors: Martyn Russell <martyn@imendio.com> - * Richard Hult <richard@imendio.com> - */ - -#ifndef __EMPATHY_SPELL_DIALOG_H__ -#define __EMPATHY_SPELL_DIALOG_H__ - -#include <gtk/gtktextiter.h> -#include "empathy-chat.h" - -G_BEGIN_DECLS - -void empathy_spell_dialog_show (EmpathyChat *chat, - GtkTextIter *start, - GtkTextIter *end, - const gchar *word); - -G_END_DECLS - -#endif /* __EMPATHY_SPELL_DIALOG_H__ */ diff --git a/libempathy-gtk/empathy-spell-dialog.ui b/libempathy-gtk/empathy-spell-dialog.ui deleted file mode 100644 index 382346c1a..000000000 --- a/libempathy-gtk/empathy-spell-dialog.ui +++ /dev/null @@ -1,131 +0,0 @@ -<?xml version="1.0"?> -<!--*- mode: xml -*--> -<interface> - <object class="GtkDialog" id="spell_dialog"> - <property name="border_width">5</property> - <property name="title" translatable="yes">Spell Checker</property> - <property name="modal">True</property> - <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property> - <property name="default_width">275</property> - <property name="default_height">225</property> - <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property> - <property name="has_separator">False</property> - <child internal-child="vbox"> - <object class="GtkVBox" id="dialog-vbox7"> - <property name="visible">True</property> - <property name="spacing">2</property> - <child> - <object class="GtkVBox" id="vbox128"> - <property name="visible">True</property> - <property name="border_width">5</property> - <property name="spacing">6</property> - <child> - <object class="GtkLabel" id="label_word"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">Suggestions for the word:</property> - <property name="use_markup">True</property> - <property name="wrap">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - <child> - <object class="GtkScrolledWindow" id="scrolledwindow9"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="shadow_type">GTK_SHADOW_IN</property> - <child> - <object class="GtkTreeView" id="treeview_words"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="headers_visible">False</property> - </object> - </child> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> - <child internal-child="action_area"> - <object class="GtkHButtonBox" id="dialog-action_area7"> - <property name="visible">True</property> - <property name="layout_style">GTK_BUTTONBOX_END</property> - <child> - <object class="GtkButton" id="button_cancel"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="label">gtk-cancel</property> - <property name="use_stock">True</property> - </object> - </child> - <child> - <object class="GtkButton" id="button_replace"> - <property name="visible">True</property> - <property name="sensitive">False</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <child> - <object class="GtkAlignment" id="alignment6"> - <property name="visible">True</property> - <property name="xscale">0</property> - <property name="yscale">0</property> - <child> - <object class="GtkHBox" id="hbox135"> - <property name="visible">True</property> - <property name="spacing">2</property> - <child> - <object class="GtkImage" id="image245"> - <property name="visible">True</property> - <property name="stock">gtk-convert</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label594"> - <property name="visible">True</property> - <property name="label">_Replace</property> - <property name="use_underline">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - </object> - </child> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="pack_type">GTK_PACK_END</property> - </packing> - </child> - </object> - </child> - <action-widgets> - <action-widget response="-6">button_cancel</action-widget> - <action-widget response="-5">button_replace</action-widget> - </action-widgets> - </object> -</interface> |