void
pluma_automatic_spell_checker_free (PlumaAutomaticSpellChecker *spell)
{
	g_return_if_fail (spell != NULL);
	g_return_if_fail (pluma_automatic_spell_checker_get_from_document (spell->doc) == spell);
	
	if (automatic_spell_checker_id == 0)
		return;

	g_object_set_qdata (G_OBJECT (spell->doc), automatic_spell_checker_id, NULL);	
}
Esempio n. 2
0
static void
update_ui (PlumaSpellPlugin *plugin)
{
	PlumaSpellPluginPrivate *data;
	PlumaWindow *window;
	PlumaDocument *doc;
	PlumaView *view;
	gboolean autospell;
	GtkAction *action;

	pluma_debug (DEBUG_PLUGINS);

	data = plugin->priv;
	window = PLUMA_WINDOW (data->window);
	doc = pluma_window_get_active_document (window);
	view = pluma_window_get_active_view (window);

	autospell = (doc != NULL &&
	             pluma_automatic_spell_checker_get_from_document (doc) != NULL);

	if (doc != NULL)
	{
		PlumaTab *tab;
		PlumaTabState state;

		tab = pluma_window_get_active_tab (window);
		state = pluma_tab_get_state (tab);

		/* If the document is loading we can't get the metadata so we
		   endup with an useless speller */
		if (state == PLUMA_TAB_STATE_NORMAL)
		{
			action = gtk_action_group_get_action (data->action_group,
							      "AutoSpell");
	
			g_signal_handlers_block_by_func (action, auto_spell_cb,
							 plugin);
			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,
							   plugin);
		}
	}

	gtk_action_group_set_sensitive (data->action_group,
					(view != NULL) &&
					gtk_text_view_get_editable (GTK_TEXT_VIEW (view)));
}
Esempio n. 3
0
static void
on_document_saved (PlumaDocument *doc,
		   const GError  *error,
		   PlumaSpellPlugin *plugin)
{
	PlumaAutomaticSpellChecker *autospell;
	PlumaSpellChecker *spell;
	const gchar *key;

	if (error != NULL)
	{
		return;
	}

	/* Make sure to save the metadata here too */
	autospell = pluma_automatic_spell_checker_get_from_document (doc);
	spell = PLUMA_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc), spell_checker_id));

	if (spell != NULL)
	{
		key = pluma_spell_checker_language_to_key (pluma_spell_checker_get_language (spell));
	}
	else
	{
		key = NULL;
	}

	if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT)
	{

		pluma_document_set_metadata (doc,
				PLUMA_METADATA_ATTRIBUTE_SPELL_ENABLED,
				autospell != NULL ? "1" : NULL,
				PLUMA_METADATA_ATTRIBUTE_SPELL_LANGUAGE,
				key,
				NULL);
	}
	else
	{
		pluma_document_set_metadata (doc,
				PLUMA_METADATA_ATTRIBUTE_SPELL_LANGUAGE,
				key,
				NULL);
	}
}
Esempio n. 4
0
static void
set_auto_spell (PlumaWindow   *window,
		PlumaDocument *doc,
		gboolean       active)
{
	PlumaAutomaticSpellChecker *autospell;
	PlumaSpellChecker *spell;

	spell = get_spell_checker_from_document (doc);
	g_return_if_fail (spell != NULL);

	autospell = pluma_automatic_spell_checker_get_from_document (doc);

	if (active)
	{
		if (autospell == NULL)
		{
			PlumaView *active_view;

			active_view = pluma_window_get_active_view (window);
			g_return_if_fail (active_view != NULL);

			autospell = pluma_automatic_spell_checker_new (doc, spell);

			if (doc == pluma_window_get_active_document (window))
			{
				pluma_automatic_spell_checker_attach_view (autospell, active_view);
			}

			pluma_automatic_spell_checker_recheck_all (autospell);
		}
	}
	else
	{
		if (autospell != NULL)
			pluma_automatic_spell_checker_free (autospell);
	}
}
PlumaAutomaticSpellChecker *
pluma_automatic_spell_checker_new (PlumaDocument     *doc,
				   PlumaSpellChecker *checker)
{
	PlumaAutomaticSpellChecker *spell;
	GtkTextTagTable *tag_table;
	GtkTextIter start, end;

	g_return_val_if_fail (PLUMA_IS_DOCUMENT (doc), NULL);
	g_return_val_if_fail (PLUMA_IS_SPELL_CHECKER (checker), NULL);
	g_return_val_if_fail ((spell = pluma_automatic_spell_checker_get_from_document (doc)) == NULL,
			      spell);
	
	/* attach to the widget */
	spell = g_new0 (PlumaAutomaticSpellChecker, 1);

	spell->doc = doc;
	spell->spell_checker = g_object_ref (checker);

	if (automatic_spell_checker_id == 0)
	{
		automatic_spell_checker_id = 
			g_quark_from_string ("PlumaAutomaticSpellCheckerID");
	}
	if (suggestion_id == 0)
	{
		suggestion_id = g_quark_from_string ("PlumaAutoSuggestionID");
	}

	g_object_set_qdata_full (G_OBJECT (doc), 
				 automatic_spell_checker_id, 
				 spell, 
				 (GDestroyNotify)pluma_automatic_spell_checker_free_internal);

	g_signal_connect (doc,
			  "insert-text",
			  G_CALLBACK (insert_text_before), 
			  spell);
	g_signal_connect_after (doc,
			  "insert-text",
			  G_CALLBACK (insert_text_after), 
			  spell);
	g_signal_connect_after (doc,
			  "delete-range",
			  G_CALLBACK (delete_range_after), 
			  spell);
	g_signal_connect (doc,
			  "mark-set",
			  G_CALLBACK (mark_set), 
			  spell);

	g_signal_connect (doc,
	                  "highlight-updated",
	                  G_CALLBACK (highlight_updated),
	                  spell);

	g_signal_connect (spell->spell_checker,
			  "add_word_to_session",
			  G_CALLBACK (add_word_signal_cb),
			  spell);
	g_signal_connect (spell->spell_checker,
			  "add_word_to_personal",
			  G_CALLBACK (add_word_signal_cb),
			  spell);
	g_signal_connect (spell->spell_checker,
			  "clear_session",
			  G_CALLBACK (clear_session_cb),
			  spell);
	g_signal_connect (spell->spell_checker,
			  "set_language",
			  G_CALLBACK (set_language_cb),
			  spell);

	spell->tag_highlight = gtk_text_buffer_create_tag (
				GTK_TEXT_BUFFER (doc),
				"gtkspell-misspelled",
				"underline", PANGO_UNDERLINE_ERROR,
				NULL);

	g_object_weak_ref (G_OBJECT (spell->tag_highlight),
	                   (GWeakNotify)spell_tag_destroyed,
	                   spell);

	tag_table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (doc));

	gtk_text_tag_set_priority (spell->tag_highlight, 
				   gtk_text_tag_table_get_size (tag_table) - 1);

	g_signal_connect (tag_table,
			  "tag-added",
			  G_CALLBACK (tag_added_or_removed),
			  spell);
	g_signal_connect (tag_table,
			  "tag-removed",
			  G_CALLBACK (tag_added_or_removed),
			  spell);
	g_signal_connect (tag_table,
			  "tag-changed",
			  G_CALLBACK (tag_changed),
			  spell);

	/* we create the mark here, but we don't use it until text is
	 * inserted, so we don't really care where iter points.  */
	gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &start, &end);
	
	spell->mark_insert_start = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc),
					"pluma-automatic-spell-checker-insert-start");

	if (spell->mark_insert_start == NULL)
	{
		spell->mark_insert_start = 
			gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc),
						     "pluma-automatic-spell-checker-insert-start",
						     &start, 
						     TRUE);
	}
	else
	{
		gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc),
					   spell->mark_insert_start,
					   &start);
	}

	spell->mark_insert_end = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc),
					"pluma-automatic-spell-checker-insert-end");

	if (spell->mark_insert_end == NULL)
	{
		spell->mark_insert_end = 
			gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc),
						     "pluma-automatic-spell-checker-insert-end",
						     &start, 
						     TRUE);
	}
	else
	{
		gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc),
					   spell->mark_insert_end,
					   &start);
	}

	spell->mark_click = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc),
					"pluma-automatic-spell-checker-click");

	if (spell->mark_click == NULL)
	{
		spell->mark_click = 
			gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc),
						     "pluma-automatic-spell-checker-click",
						     &start, 
						     TRUE);
	}
	else
	{
		gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc),
					   spell->mark_click,
					   &start);
	}

	spell->deferred_check = FALSE;

	return spell;
}