static void
pluma_plugins_engine_deactivate_plugin_real (PlumaPluginsEngine *engine,
					     PlumaPluginInfo *info)
{
	const GList *wins;
	PlumaPluginLoader *loader;

	if (!pluma_plugin_info_is_active (info) ||
	    !pluma_plugin_info_is_available (info))
		return;

	for (wins = pluma_app_get_windows (pluma_app_get_default ());
	     wins != NULL;
	     wins = wins->next)
	{
		call_plugin_deactivate (info->plugin, PLUMA_WINDOW (wins->data));
	}

	/* first unref the plugin (the loader still has one) */
	g_object_unref (info->plugin);

	/* find the loader and tell it to gc and unload the plugin */
	loader = get_plugin_loader (engine, info);

	pluma_plugin_loader_garbage_collect (loader);
	pluma_plugin_loader_unload (loader, info);

	info->plugin = NULL;
}
예제 #2
0
static void
auto_spell_cb (GtkAction   *action,
	       PlumaSpellPlugin *plugin)
{
	PlumaWindow *window;
	PlumaDocument *doc;
	gboolean active;

	pluma_debug (DEBUG_PLUGINS);

	window = PLUMA_WINDOW (plugin->priv->window);

	active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

	pluma_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated");

	doc = pluma_window_get_active_document (window);
	if (doc == NULL)
		return;

	if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT)
	{
		pluma_document_set_metadata (doc,
				     PLUMA_METADATA_ATTRIBUTE_SPELL_ENABLED,
				     active ? "1" : NULL, NULL);
	}

	set_auto_spell (window, doc, active);
}
예제 #3
0
static PlumaNotebook *
find_notebook_at_pointer (gint abs_x, gint abs_y)
{
	GdkWindow *win_at_pointer;
	GdkWindow *toplevel_win;
	gpointer toplevel = NULL;
	gint x, y;

	/* FIXME multi-head */
	win_at_pointer = gdk_window_at_pointer (&x, &y);
	if (win_at_pointer == NULL)
	{
		/* We are outside all windows of the same application */
		return NULL;
	}

	toplevel_win = gdk_window_get_toplevel (win_at_pointer);

	/* get the GtkWidget which owns the toplevel GdkWindow */
	gdk_window_get_user_data (toplevel_win, &toplevel);

	/* toplevel should be an PlumaWindow */
	if ((toplevel != NULL) && 
	    PLUMA_IS_WINDOW (toplevel))
	{
		return PLUMA_NOTEBOOK (_pluma_window_get_notebook
						(PLUMA_WINDOW (toplevel)));
	}

	/* We are outside all windows containing a notebook */
	return NULL;
}
예제 #4
0
static void
pluma_prefs_manager_syntax_hl_enable_changed (GSettings *settings,
        gchar       *key,
        gpointer     user_data)
{
    pluma_debug (DEBUG_PREFS);

    if (strcmp (key, GPM_SYNTAX_HL_ENABLE) == 0)
    {
        gboolean enable;
        GList *docs;
        GList *l;
        const GList *windows;

        enable = g_settings_get_boolean (settings, key);

        docs = pluma_app_get_documents (pluma_app_get_default ());
        l = docs;

        while (l != NULL)
        {
            g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data));

            gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (l->data),
                                                    enable);

            l = l->next;
        }

        g_list_free (docs);

        /* update the sensitivity of the Higlight Mode menu item */
        windows = pluma_app_get_windows (pluma_app_get_default ());
        while (windows != NULL)
        {
            GtkUIManager *ui;
            GtkAction *a;

            ui = pluma_window_get_ui_manager (PLUMA_WINDOW (windows->data));

            a = gtk_ui_manager_get_action (ui,
                                           "/MenuBar/ViewMenu/ViewHighlightModeMenu");

            gtk_action_set_sensitive (a, enable);

            windows = g_list_next (windows);
        }
    }
}
예제 #5
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)));
}
static void
pluma_plugins_engine_activate_plugin_real (PlumaPluginsEngine *engine,
					   PlumaPluginInfo *info)
{
	const GList *wins;

	if (!load_plugin (engine, info))
		return;

	for (wins = pluma_app_get_windows (pluma_app_get_default ());
	     wins != NULL;
	     wins = wins->next)
	{
		pluma_plugin_activate (info->plugin, PLUMA_WINDOW (wins->data));
	}
}
예제 #7
0
static void
set_language_cb (GtkAction   *action,
		 PlumaSpellPlugin *plugin)
{
	PlumaWindow *window;
	PlumaDocument *doc;
	PlumaSpellChecker *spell;
	const PlumaSpellCheckerLanguage *lang;
	GtkWidget *dlg;
	GtkWindowGroup *wg;
	gchar *data_dir;

	pluma_debug (DEBUG_PLUGINS);

	window = PLUMA_WINDOW (plugin->priv->window);
	doc = pluma_window_get_active_document (window);
	g_return_if_fail (doc != NULL);

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

	lang = pluma_spell_checker_get_language (spell);

	data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin));
	dlg = pluma_spell_language_dialog_new (GTK_WINDOW (window),
					       lang,
					       data_dir);
	g_free (data_dir);

	wg = pluma_window_get_group (window);

	gtk_window_group_add_window (wg, GTK_WINDOW (dlg));

	gtk_window_set_modal (GTK_WINDOW (dlg), TRUE);

	g_signal_connect (dlg,
			  "response",
			  G_CALLBACK (language_dialog_response),
			  spell);

	gtk_widget_show (dlg);
}
예제 #8
0
static void
pluma_spell_plugin_deactivate (PeasActivatable *activatable)
{
	PlumaSpellPluginPrivate *data;
	PlumaWindow *window;
	GtkUIManager *manager;

	pluma_debug (DEBUG_PLUGINS);

	data = PLUMA_SPELL_PLUGIN (activatable)->priv;
	window = PLUMA_WINDOW (data->window);

	manager = pluma_window_get_ui_manager (window);

	gtk_ui_manager_remove_ui (manager, data->ui_id);
	gtk_ui_manager_remove_action_group (manager, data->action_group);

	g_signal_handler_disconnect (window, data->tab_added_id);
	g_signal_handler_disconnect (window, data->tab_removed_id);
}
예제 #9
0
static void
spell_cb (GtkAction   *action,
	  PlumaSpellPlugin *plugin)
{
	PlumaSpellPluginPrivate *data;
	PlumaWindow *window;
	PlumaView *view;
	PlumaDocument *doc;
	PlumaSpellChecker *spell;
	GtkWidget *dlg;
	GtkTextIter start, end;
	gchar *word;
	gchar *data_dir;

	pluma_debug (DEBUG_PLUGINS);

	data = plugin->priv;
	window = PLUMA_WINDOW (data->window);
	view = pluma_window_get_active_view (window);
	g_return_if_fail (view != NULL);

	doc = PLUMA_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 = pluma_window_get_statusbar (window);
		pluma_statusbar_flash_message (PLUMA_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)
	{
		GtkWidget *statusbar;

		statusbar = pluma_window_get_statusbar (window);
		pluma_statusbar_flash_message (PLUMA_STATUSBAR (statusbar),
					       data->message_cid,
					       _("No misspelled words"));

		return;
	}

	data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin));
	dlg = pluma_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 (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);

	pluma_spell_checker_dialog_set_misspelled_word (PLUMA_SPELL_CHECKER_DIALOG (dlg),
							word,
							-1);

	g_free (word);

	gtk_widget_show (dlg);
}
예제 #10
0
static void
pluma_spell_plugin_activate (PeasActivatable *activatable)
{
	PlumaSpellPlugin *plugin;
	PlumaSpellPluginPrivate *data;
	PlumaWindow *window;
	GtkUIManager *manager;
	GList *docs, *l;

	pluma_debug (DEBUG_PLUGINS);

	plugin = PLUMA_SPELL_PLUGIN (activatable);
	data = plugin->priv;
	window = PLUMA_WINDOW (data->window);

	manager = pluma_window_get_ui_manager (window);

	data->action_group = gtk_action_group_new ("PlumaSpellPluginActions");
	gtk_action_group_set_translation_domain (data->action_group, 
						 GETTEXT_PACKAGE);
	gtk_action_group_add_actions (data->action_group,
					   action_entries,
					   G_N_ELEMENTS (action_entries),
					   plugin);
	gtk_action_group_add_toggle_actions (data->action_group, 
					     toggle_action_entries,
					     G_N_ELEMENTS (toggle_action_entries),
					     plugin);

	gtk_ui_manager_insert_action_group (manager, data->action_group, -1);

	data->ui_id = gtk_ui_manager_new_merge_id (manager);

	data->message_cid = gtk_statusbar_get_context_id
			(GTK_STATUSBAR (pluma_window_get_statusbar (window)), 
			 "spell_plugin_message");

	gtk_ui_manager_add_ui (manager,
			       data->ui_id,
			       MENU_PATH,
			       "CheckSpell",
			       "CheckSpell",
			       GTK_UI_MANAGER_MENUITEM, 
			       FALSE);

	gtk_ui_manager_add_ui (manager, 
			       data->ui_id, 
			       MENU_PATH,
			       "AutoSpell", 
			       "AutoSpell",
			       GTK_UI_MANAGER_MENUITEM, 
			       FALSE);

	gtk_ui_manager_add_ui (manager, 
			       data->ui_id, 
			       MENU_PATH,
			       "ConfigSpell", 
			       "ConfigSpell",
			       GTK_UI_MANAGER_MENUITEM, 
			       FALSE);

	update_ui (plugin);

	docs = pluma_window_get_documents (window);
	for (l = docs; l != NULL; l = g_list_next (l))
	{
		PlumaDocument *doc = PLUMA_DOCUMENT (l->data);

		set_auto_spell_from_metadata (plugin, doc,
					      data->action_group);

		g_signal_handlers_disconnect_by_func (doc,
		                                      on_document_loaded,
		                                      plugin);

		g_signal_handlers_disconnect_by_func (doc,
		                                      on_document_saved,
		                                      plugin);
	}

	data->tab_added_id =
		g_signal_connect (window, "tab-added",
				  G_CALLBACK (tab_added_cb), plugin);
	data->tab_removed_id =
		g_signal_connect (window, "tab-removed",
				  G_CALLBACK (tab_removed_cb), plugin);
}
예제 #11
0
static void
set_auto_spell_from_metadata (PlumaSpellPlugin *plugin,
			      PlumaDocument  *doc,
			      GtkActionGroup *action_group)
{
	gboolean active = FALSE;
	gchar *active_str = NULL;
	PlumaWindow *window;
	PlumaDocument *active_doc;
	PlumaSpellPluginAutocheckType autocheck_type;

	autocheck_type = get_autocheck_type (plugin);

	switch (autocheck_type)
	{
		case AUTOCHECK_ALWAYS:
		{
			active = TRUE;
			break;
		}
		case AUTOCHECK_DOCUMENT:
		{
			active_str = pluma_document_get_metadata (doc,
						  PLUMA_METADATA_ATTRIBUTE_SPELL_ENABLED);
			break;
		}
		case AUTOCHECK_NEVER:
		default:
			active = FALSE;
			break;
	}

	if (active_str)
	{
		active = *active_str == '1';
	
		g_free (active_str);
	}

	window = PLUMA_WINDOW (plugin->priv->window);

	set_auto_spell (window, doc, active);

	/* In case that the doc is the active one we mark the spell action */
	active_doc = pluma_window_get_active_document (window);

	if (active_doc == doc && action_group != NULL)
	{
		GtkAction *action;
		
		action = gtk_action_group_get_action (action_group,
						      "AutoSpell");

		g_signal_handlers_block_by_func (action, auto_spell_cb,
						 plugin);
		gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
					      active);
		g_signal_handlers_unblock_by_func (action, auto_spell_cb,
						   plugin);
	}
}