static void
pluma_prefs_manager_auto_save_changed (GSettings *settings,
                                       gchar       *key,
                                       gpointer     user_data)
{
    GList *docs;
    GList *l;

    pluma_debug (DEBUG_PREFS);

    if (strcmp (key, GPM_AUTO_SAVE) == 0)
    {
        gboolean auto_save;

        auto_save = g_settings_get_boolean (settings, key);

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

        while (l != NULL)
        {
            PlumaDocument *doc = PLUMA_DOCUMENT (l->data);
            PlumaTab *tab = pluma_tab_get_from_document (doc);

            pluma_tab_set_auto_save_enabled (tab, auto_save);

            l = l->next;
        }

        g_list_free (docs);
    }
    else if (strcmp (key,  GPM_AUTO_SAVE_INTERVAL) == 0)
    {
        gint auto_save_interval;

        auto_save_interval = g_settings_get_int (settings, key);

        if (auto_save_interval <= 0)
            auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL;

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

        while (l != NULL)
        {
            PlumaDocument *doc = PLUMA_DOCUMENT (l->data);
            PlumaTab *tab = pluma_tab_get_from_document (doc);

            pluma_tab_set_auto_save_interval (tab, auto_save_interval);

            l = l->next;
        }

        g_list_free (docs);
    }
}
static void
pluma_prefs_manager_search_hl_enable_changed (GSettings *settings,
        gchar       *key,
        gpointer     user_data)
{
    pluma_debug (DEBUG_PREFS);

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

        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 (PLUMA_IS_DOCUMENT (l->data));

            pluma_document_set_enable_search_highlighting  (PLUMA_DOCUMENT (l->data),
                    enable);

            l = l->next;
        }

        g_list_free (docs);
    }
}
static void
do_find (PlumaSearchDialog *dialog,
	 PlumaWindow       *window)
{
	PlumaView *active_view;
	PlumaDocument *doc;
	gchar *search_text;
	const gchar *entry_text;
	gboolean match_case;
	gboolean entire_word;
	gboolean wrap_around;
	gboolean search_backwards;
	guint flags = 0;
	guint old_flags = 0;
	gboolean found;

	/* TODO: make the dialog insensitive when all the tabs are closed
	 * and assert here that the view is not NULL */
	active_view = pluma_window_get_active_view (window);
	if (active_view == NULL)
		return;

	doc = PLUMA_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));

	entry_text = pluma_search_dialog_get_search_text (dialog);

	match_case = pluma_search_dialog_get_match_case (dialog);
	entire_word = pluma_search_dialog_get_entire_word (dialog);
	search_backwards = pluma_search_dialog_get_backwards (dialog);
	wrap_around = pluma_search_dialog_get_wrap_around (dialog);

	PLUMA_SEARCH_SET_CASE_SENSITIVE (flags, match_case);
	PLUMA_SEARCH_SET_ENTIRE_WORD (flags, entire_word);

	search_text = pluma_document_get_search_text (doc, &old_flags);

	if ((search_text == NULL) ||
	    (strcmp (search_text, entry_text) != 0) ||
	    (flags != old_flags))
	{
		pluma_document_set_search_text (doc, entry_text, flags);
	}

	g_free (search_text);
	
	found = run_search (active_view,
			    wrap_around,
			    search_backwards);

	if (found)
		text_found (window, 0);
	else
		text_not_found (window, entry_text);

	gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
					   PLUMA_SEARCH_DIALOG_REPLACE_RESPONSE,
					   found);
}
Exemple #4
0
static void
change_all_cb (PlumaSpellCheckerDialog *dlg,
	       const gchar             *word,
	       const gchar             *change,
	       PlumaView               *view)
{
	PlumaDocument *doc;
	CheckRange *range;
	gchar *w = NULL;
	GtkTextIter start, end;
	gint flags = 0;

	pluma_debug (DEBUG_PLUGINS);

	g_return_if_fail (view != NULL);
	g_return_if_fail (word != NULL);
	g_return_if_fail (change != NULL);

	doc = PLUMA_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
	g_return_if_fail (doc != NULL);

	range = get_check_range (doc);
	g_return_if_fail (range != NULL);

	gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &start, range->mw_start);
	if (range->mw_end < 0)
		gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &end);
	else
		gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &end, range->mw_end);

	w = gtk_text_buffer_get_slice (GTK_TEXT_BUFFER (doc), &start, &end, TRUE);
	g_return_if_fail (w != NULL);

	if (strcmp (w, word) != 0)
	{
		g_free (w);
		return;
	}

	g_free (w);

	PLUMA_SEARCH_SET_CASE_SENSITIVE (flags, TRUE);
	PLUMA_SEARCH_SET_ENTIRE_WORD (flags, TRUE);

	/* CHECK: currently this function does escaping etc */
	pluma_document_replace_all (doc, word, change, flags);

	update_current (doc, range->mw_start + g_utf8_strlen (change, -1));

	/* go to next misspelled word */
	ignore_cb (dlg, word, view);
}
Exemple #5
0
static void
change_cb (PlumaSpellCheckerDialog *dlg,
	   const gchar             *word,
	   const gchar             *change,
	   PlumaView               *view)
{
	PlumaDocument *doc;
	CheckRange *range;
	gchar *w = NULL;
	GtkTextIter start, end;

	pluma_debug (DEBUG_PLUGINS);

	g_return_if_fail (view != NULL);
	g_return_if_fail (word != NULL);
	g_return_if_fail (change != NULL);

	doc = PLUMA_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
	g_return_if_fail (doc != NULL);

	range = get_check_range (doc);
	g_return_if_fail (range != NULL);

	gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &start, range->mw_start);
	if (range->mw_end < 0)
		gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &end);
	else
		gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &end, range->mw_end);

	w = gtk_text_buffer_get_slice (GTK_TEXT_BUFFER (doc), &start, &end, TRUE);
	g_return_if_fail (w != NULL);

	if (strcmp (w, word) != 0)
	{
		g_free (w);
		return;
	}

	g_free (w);

	gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER(doc));

	gtk_text_buffer_delete (GTK_TEXT_BUFFER (doc), &start, &end);
	gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &start, change, -1);

	gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER(doc));

	update_current (doc, range->mw_start + g_utf8_strlen (change, -1));

	/* go to next misspelled word */
	ignore_cb (dlg, word, view);
}
void
_pluma_cmd_search_clear_highlight (GtkAction   *action,
				   PlumaWindow *window)
{
	PlumaDocument *doc;

	pluma_debug (DEBUG_COMMANDS);

	doc = pluma_window_get_active_document (window);
	pluma_document_set_search_text (PLUMA_DOCUMENT (doc),
					"",
					PLUMA_SEARCH_DONT_SET_FLAGS);
}
static void
do_replace_all (PlumaSearchDialog *dialog,
		PlumaWindow       *window)
{
	PlumaView *active_view;
	PlumaDocument *doc;
	const gchar *search_entry_text;
	const gchar *replace_entry_text;
	gboolean match_case;
	gboolean entire_word;
	guint flags = 0;
	gint count;

	active_view = pluma_window_get_active_view (window);
	if (active_view == NULL)
		return;

	doc = PLUMA_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));

	search_entry_text = pluma_search_dialog_get_search_text (dialog);
	g_return_if_fail ((search_entry_text) != NULL);
	g_return_if_fail ((*search_entry_text) != '\0');

	/* replace text may be "", we just delete all occurrencies */
	replace_entry_text = pluma_search_dialog_get_replace_text (dialog);
	g_return_if_fail ((replace_entry_text) != NULL);

	match_case = pluma_search_dialog_get_match_case (dialog);
	entire_word = pluma_search_dialog_get_entire_word (dialog);

	PLUMA_SEARCH_SET_CASE_SENSITIVE (flags, match_case);
	PLUMA_SEARCH_SET_ENTIRE_WORD (flags, entire_word);

	count = pluma_document_replace_all (doc, 
					    search_entry_text,
					    replace_entry_text,
					    flags);

	if (count > 0)
	{
		text_found (window, count);
	}
	else
	{
		text_not_found (window, search_entry_text);
	}

	gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
					   PLUMA_SEARCH_DIALOG_REPLACE_RESPONSE,
					   FALSE);
}
static void
save_bookmark_metadata (PlumaView *view)
{
	GtkTextIter iter;
	GtkTextBuffer *buf;
	GString *string;
	gchar *val = NULL;
	gboolean first = TRUE;

	buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));

	gtk_text_buffer_get_start_iter (buf, &iter);

	string = g_string_new (NULL);

	while (gtk_source_buffer_forward_iter_to_source_mark (GTK_SOURCE_BUFFER (buf),
							      &iter,
							      BOOKMARK_CATEGORY))
	{
		gint line;

		line = gtk_text_iter_get_line (&iter);

		if (!first)
		{
			g_string_append_printf (string, ",%d", line);
		}
		else
		{
			g_string_append_printf (string, "%d", line);
			first = FALSE;
		}
	}

	if (string->len == 0)
	{
		val = g_string_free (string, TRUE);
		val = NULL;
	}
	else
		val = g_string_free (string, FALSE);

	pluma_document_set_metadata (PLUMA_DOCUMENT (buf), METADATA_ATTR,
				     val, NULL);

	g_free (val);
}
static void
load_bookmark_metadata (PlumaView *view)
{
	PlumaDocument *doc;
	gchar *bookmarks_attr;

	doc = PLUMA_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
	bookmarks_attr = pluma_document_get_metadata (doc, METADATA_ATTR);

	if (bookmarks_attr != NULL)
	{
		gchar **bookmarks;

		bookmarks = g_strsplit (bookmarks_attr, ",", -1);
		g_free (bookmarks_attr);

		load_bookmarks (view, bookmarks);

		g_strfreev (bookmarks);
	}
}
static gboolean
run_search (PlumaView   *view,
	    gboolean     wrap_around,
	    gboolean     search_backwards)
{
	PlumaDocument *doc;
	GtkTextIter start_iter;
	GtkTextIter match_start;
	GtkTextIter match_end;
	gboolean found = FALSE;

	doc = PLUMA_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));

	if (!search_backwards)
	{
		gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),
						      NULL,
						      &start_iter);

		found = pluma_document_search_forward (doc,
						       &start_iter,
						       NULL,
						       &match_start,
						       &match_end);
	}
	else
	{
		gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),
						      &start_iter,
						      NULL);

		found = pluma_document_search_backward (doc,
						        NULL,
						        &start_iter,
						        &match_start,
						        &match_end);
	}

	if (!found && wrap_around)
	{
		if (!search_backwards)
			found = pluma_document_search_forward (doc,
							       NULL,
							       NULL, /* FIXME: set the end_inter */
							       &match_start,
							       &match_end);
		else
			found = pluma_document_search_backward (doc,
							        NULL, /* FIXME: set the start_inter */
							        NULL, 
							        &match_start,
							        &match_end);
	}
	
	if (found)
	{
		gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc),
					      &match_start);

		gtk_text_buffer_move_mark_by_name (GTK_TEXT_BUFFER (doc),
						   "selection_bound",
						   &match_end);

		pluma_view_scroll_to_cursor (view);
	}
	else
	{
		gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc),
					      &start_iter);
	}

	return found;
}
Exemple #11
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);
}
Exemple #12
0
static gchar *
get_next_misspelled_word (PlumaView *view)
{
	PlumaDocument *doc;
	CheckRange *range;
	gint start, end;
	gchar *word;
	PlumaSpellChecker *spell;

	g_return_val_if_fail (view != NULL, NULL);

	doc = PLUMA_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
	g_return_val_if_fail (doc != NULL, NULL);

	range = get_check_range (doc);
	g_return_val_if_fail (range != NULL, NULL);

	spell = get_spell_checker_from_document (doc);
	g_return_val_if_fail (spell != NULL, NULL);

	word = get_current_word (doc, &start, &end);
	if (word == NULL)
		return NULL;

	pluma_debug_message (DEBUG_PLUGINS, "Word to check: %s", word);

	while (pluma_spell_checker_check_word (spell, word, -1))
	{
		g_free (word);

		if (!goto_next_word (doc))
			return NULL;

		/* may return null if we reached the end of the selection */
		word = get_current_word (doc, &start, &end);
		if (word == NULL)
			return NULL;

		pluma_debug_message (DEBUG_PLUGINS, "Word to check: %s", word);
	}

	if (!goto_next_word (doc))
		update_current (doc, gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)));

	if (word != NULL)
	{
		GtkTextIter s, e;

		range->mw_start = start;
		range->mw_end = end;

		pluma_debug_message (DEBUG_PLUGINS, "Select [%d, %d]", start, end);

		gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &s, start);
		gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &e, end);

		gtk_text_buffer_select_range (GTK_TEXT_BUFFER (doc), &s, &e);

		pluma_view_scroll_to_cursor (view);
	}
	else
	{
		range->mw_start = -1;
		range->mw_end = -1;
	}

	return word;
}
Exemple #13
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);
}