static void set_auto_spell (GeditWindow *window, GeditDocument *doc, gboolean active) { GeditAutomaticSpellChecker *autospell; GeditSpellChecker *spell; spell = get_spell_checker_from_document (doc); g_return_if_fail (spell != NULL); autospell = gedit_automatic_spell_checker_get_from_document (doc); if (active) { if (autospell == NULL) { GeditView *active_view; active_view = gedit_window_get_active_view (window); g_return_if_fail (active_view != NULL); autospell = gedit_automatic_spell_checker_new (doc, spell); gedit_automatic_spell_checker_attach_view (autospell, active_view); gedit_automatic_spell_checker_recheck_all (autospell); } } else { if (autospell != NULL) gedit_automatic_spell_checker_free (autospell); } }
static void message_get_view_iter (GeditWindow *window, GeditMessage *message, GtkSourceView **view, GtkTextIter *iter) { if (gedit_message_has_key (message, "view")) { gedit_message_get (message, "view", view, NULL); } else { *view = GTK_SOURCE_VIEW (gedit_window_get_active_view (window)); } if (!*view) { return; } if (gedit_message_has_key (message, "iter")) { gedit_message_get (message, "iter", iter, NULL); } else { GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (*view)); gtk_text_buffer_get_iter_at_mark (buffer, iter, gtk_text_buffer_get_insert (buffer)); } }
static void auto_spell_cb (GSimpleAction *action, GVariant *state, gpointer data) { GeditSpellPlugin *plugin = GEDIT_SPELL_PLUGIN (data); GeditSpellPluginPrivate *priv = plugin->priv; GeditView *view; gboolean active; gedit_debug (DEBUG_PLUGINS); active = g_variant_get_boolean (state); gedit_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated"); view = gedit_window_get_active_view (priv->window); if (view != NULL) { GeditDocument *doc; doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); gedit_document_set_metadata (doc, GEDIT_METADATA_ATTRIBUTE_SPELL_ENABLED, active ? "1" : NULL, NULL); set_auto_spell (priv->window, view, active); g_simple_action_set_state (action, g_variant_new_boolean (active)); } }
static void update_ui (GeditSpellPlugin *plugin) { GeditSpellPluginPrivate *priv; GeditView *view; GAction *check_spell_action; GAction *config_spell_action; GAction *auto_spell_action; gedit_debug (DEBUG_PLUGINS); priv = plugin->priv; view = gedit_window_get_active_view (priv->window); check_spell_action = g_action_map_lookup_action (G_ACTION_MAP (priv->window), "check-spell"); g_simple_action_set_enabled (G_SIMPLE_ACTION (check_spell_action), (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); config_spell_action = g_action_map_lookup_action (G_ACTION_MAP (priv->window), "config-spell"); g_simple_action_set_enabled (G_SIMPLE_ACTION (config_spell_action), (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); auto_spell_action = g_action_map_lookup_action (G_ACTION_MAP (priv->window), "auto-spell"); g_simple_action_set_enabled (G_SIMPLE_ACTION (auto_spell_action), (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); if (view != NULL) { GeditDocument *doc; GeditTab *tab; GeditTabState state; gboolean autospell; doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); tab = gedit_window_get_active_tab (priv->window); state = gedit_tab_get_state (tab); autospell = (doc != NULL && gedit_automatic_spell_checker_get_from_document (doc) != NULL); /* If the document is loading we can't get the metadata so we endup with an useless speller */ if (state == GEDIT_TAB_STATE_NORMAL) { g_action_change_state (auto_spell_action, g_variant_new_boolean (autospell)); } g_simple_action_set_enabled (G_SIMPLE_ACTION (check_spell_action), gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)) > 0); } }
void _gedit_cmd_edit_cut (GtkAction *action, GeditWindow *window) { GeditView *active_view; gedit_debug (DEBUG_COMMANDS); active_view = gedit_window_get_active_view (window); g_return_if_fail (active_view); gedit_view_cut_clipboard (active_view); gtk_widget_grab_focus (GTK_WIDGET (active_view)); }
static void update_ui_real (GeditWindow *window, WindowData *data) { GeditDocument *doc; GeditView *view; gboolean autospell; GtkAction *action; gedit_debug (DEBUG_PLUGINS); doc = gedit_window_get_active_document (window); view = gedit_window_get_active_view (window); autospell = (doc != NULL && gedit_automatic_spell_checker_get_from_document (doc) != NULL); if (doc != NULL) { GeditTab *tab; GeditTabState state; tab = gedit_window_get_active_tab (window); state = gedit_tab_get_state (tab); /* If the document is loading we can't get the metadata so we endup with an useless speller */ if (state == GEDIT_TAB_STATE_NORMAL) { action = gtk_action_group_get_action (data->action_group, "AutoSpell"); g_signal_handlers_block_by_func (action, auto_spell_cb, window); set_auto_spell (window, doc, autospell); gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), autospell); g_signal_handlers_unblock_by_func (action, auto_spell_cb, window); } } gtk_action_group_set_sensitive (data->action_group, (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); }
void _gedit_cmd_edit_cut (GSimpleAction *action, GVariant *parameter, gpointer user_data) { GeditWindow *window = GEDIT_WINDOW (user_data); GeditView *active_view; gedit_debug (DEBUG_COMMANDS); active_view = gedit_window_get_active_view (window); g_return_if_fail (active_view); gedit_view_cut_clipboard (active_view); gtk_widget_grab_focus (GTK_WIDGET (active_view)); }
void _gedit_cmd_edit_overwrite_mode (GSimpleAction *action, GVariant *state, gpointer user_data) { GeditWindow *window = GEDIT_WINDOW (user_data); GeditView *active_view; gboolean overwrite; gedit_debug (DEBUG_COMMANDS); active_view = gedit_window_get_active_view (window); g_return_if_fail (active_view); overwrite = g_variant_get_boolean (state); g_simple_action_set_state (action, state); gtk_text_view_set_overwrite (GTK_TEXT_VIEW (active_view), overwrite); gtk_widget_grab_focus (GTK_WIDGET (active_view)); }
void _gedit_cmd_edit_redo (GtkAction *action, GeditWindow *window) { GeditView *active_view; GtkSourceBuffer *active_document; gedit_debug (DEBUG_COMMANDS); active_view = gedit_window_get_active_view (window); g_return_if_fail (active_view); active_document = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view))); gtk_source_buffer_redo (active_document); gedit_view_scroll_to_cursor (active_view); gtk_widget_grab_focus (GTK_WIDGET (active_view)); }
void _gedit_cmd_edit_redo (GSimpleAction *action, GVariant *parameter, gpointer user_data) { GeditWindow *window = GEDIT_WINDOW (user_data); GeditView *active_view; GtkSourceBuffer *active_document; gedit_debug (DEBUG_COMMANDS); active_view = gedit_window_get_active_view (window); g_return_if_fail (active_view); active_document = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view))); gtk_source_buffer_redo (active_document); gedit_view_scroll_to_cursor (active_view); gtk_widget_grab_focus (GTK_WIDGET (active_view)); }
static void spell_cb (GtkAction *action, ActionData *action_data) { GeditView *view; GeditDocument *doc; GeditSpellChecker *spell; GtkWidget *dlg; GtkTextIter start, end; gchar *word; gchar *data_dir; gedit_debug (DEBUG_PLUGINS); view = gedit_window_get_active_view (action_data->window); g_return_if_fail (view != NULL); doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); g_return_if_fail (doc != NULL); spell = get_spell_checker_from_document (doc); g_return_if_fail (spell != NULL); if (gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)) <= 0) { WindowData *data; GtkWidget *statusbar; data = (WindowData *) g_object_get_data (G_OBJECT (action_data->window), WINDOW_DATA_KEY); g_return_if_fail (data != NULL); statusbar = gedit_window_get_statusbar (action_data->window); gedit_statusbar_flash_message (GEDIT_STATUSBAR (statusbar), data->message_cid, _("The document is empty.")); return; } if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &start, &end)) { /* no selection, get the whole doc */ gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &start, &end); } set_check_range (doc, &start, &end); word = get_next_misspelled_word (view); if (word == NULL) { WindowData *data; GtkWidget *statusbar; data = (WindowData *) g_object_get_data (G_OBJECT (action_data->window), WINDOW_DATA_KEY); g_return_if_fail (data != NULL); statusbar = gedit_window_get_statusbar (action_data->window); gedit_statusbar_flash_message (GEDIT_STATUSBAR (statusbar), data->message_cid, _("No misspelled words")); return; } data_dir = gedit_plugin_get_data_dir (action_data->plugin); dlg = gedit_spell_checker_dialog_new_from_spell_checker (spell, data_dir); g_free (data_dir); gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (action_data->window)); g_signal_connect (dlg, "ignore", G_CALLBACK (ignore_cb), view); g_signal_connect (dlg, "ignore_all", G_CALLBACK (ignore_cb), view); g_signal_connect (dlg, "change", G_CALLBACK (change_cb), view); g_signal_connect (dlg, "change_all", G_CALLBACK (change_all_cb), view); g_signal_connect (dlg, "add_word_to_personal", G_CALLBACK (add_word_cb), view); gedit_spell_checker_dialog_set_misspelled_word (GEDIT_SPELL_CHECKER_DIALOG (dlg), word, -1); g_free (word); gtk_widget_show (dlg); }
static void goto_bookmark (GeditWindow *window, GtkSourceView *view, GtkTextIter *iter, IterSearchFunc func, CycleFunc cycle_func) { GtkTextBuffer *buffer; GtkTextIter at; GtkTextMark *insert; GtkTextIter end; if (view == NULL) { view = GTK_SOURCE_VIEW (gedit_window_get_active_view (window)); } if (view == NULL) { return; } buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); if (iter == NULL) { gtk_text_buffer_get_iter_at_mark (buffer, &at, gtk_text_buffer_get_insert (buffer)); } else { at = *iter; } /* Move the iter to the beginning of the line, where the bookmarks are */ gtk_text_iter_set_line_offset (&at, 0); /* Try to find the next bookmark */ if (!func (GTK_SOURCE_BUFFER (buffer), &at, BOOKMARK_CATEGORY)) { GSList *marks; /* cycle through */ cycle_func (buffer, &at); gtk_text_iter_set_line_offset (&at, 0); marks = gtk_source_buffer_get_source_marks_at_iter (GTK_SOURCE_BUFFER (buffer), &at, BOOKMARK_CATEGORY); if (!marks && !func (GTK_SOURCE_BUFFER (buffer), &at, BOOKMARK_CATEGORY)) { return; } g_slist_free (marks); } end = at; if (!gtk_text_iter_forward_visible_line (&end)) { gtk_text_buffer_get_end_iter (buffer, &end); } else { gtk_text_iter_backward_char (&end); } gtk_text_buffer_select_range (buffer, &at, &end); gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (view), &at, 0.3, FALSE, 0, 0); }
static void spell_cb (GSimpleAction *action, GVariant *parameter, gpointer data) { GeditSpellPlugin *plugin = GEDIT_SPELL_PLUGIN (data); GeditSpellPluginPrivate *priv; GeditView *view; GeditDocument *doc; GeditSpellChecker *spell; GtkWidget *dlg; GtkTextIter start, end; gchar *word; gchar *data_dir; gedit_debug (DEBUG_PLUGINS); priv = plugin->priv; view = gedit_window_get_active_view (priv->window); g_return_if_fail (view != NULL); doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); g_return_if_fail (doc != NULL); spell = get_spell_checker_from_document (doc); g_return_if_fail (spell != NULL); if (gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)) <= 0) { GtkWidget *statusbar; statusbar = gedit_window_get_statusbar (priv->window); gedit_statusbar_flash_message (GEDIT_STATUSBAR (statusbar), priv->message_cid, _("The document is empty.")); return; } if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &start, &end)) { /* no selection, get the whole doc */ gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &start, &end); } set_check_range (doc, &start, &end); word = get_next_misspelled_word (view); if (word == NULL) { GtkWidget *statusbar; statusbar = gedit_window_get_statusbar (priv->window); gedit_statusbar_flash_message (GEDIT_STATUSBAR (statusbar), priv->message_cid, _("No misspelled words")); return; } data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); dlg = gedit_spell_checker_dialog_new_from_spell_checker (spell, data_dir); g_free (data_dir); gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (priv->window)); g_signal_connect (dlg, "ignore", G_CALLBACK (ignore_cb), view); g_signal_connect (dlg, "ignore_all", G_CALLBACK (ignore_cb), view); g_signal_connect (dlg, "change", G_CALLBACK (change_cb), view); g_signal_connect (dlg, "change_all", G_CALLBACK (change_all_cb), view); g_signal_connect (dlg, "add_word_to_personal", G_CALLBACK (add_word_cb), view); gedit_spell_checker_dialog_set_misspelled_word (GEDIT_SPELL_CHECKER_DIALOG (dlg), word, -1); g_free (word); gtk_widget_show (dlg); }