static void
on_toggle_bookmark_activate (GtkAction   *action,
			     PlumaWindow *window)
{
	GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (pluma_window_get_active_document (window));
	toggle_bookmark (buffer, NULL);
}
Exemplo n.º 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);
}
static void
do_replace (PlumaSearchDialog *dialog,
	    PlumaWindow       *window)
{
	PlumaDocument *doc;
	const gchar *search_entry_text;
	const gchar *replace_entry_text;
	gchar *unescaped_search_text;
	gchar *unescaped_replace_text;
	gchar *selected_text = NULL;
	gboolean match_case;

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

	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 */
	replace_entry_text = pluma_search_dialog_get_replace_text (dialog);
	g_return_if_fail ((replace_entry_text) != NULL);

	unescaped_search_text = pluma_utils_unescape_search_text (search_entry_text);

	get_selected_text (GTK_TEXT_BUFFER (doc), 
			   &selected_text, 
			   NULL);

	match_case = pluma_search_dialog_get_match_case (dialog);

	if ((selected_text == NULL) ||
	    (match_case && (strcmp (selected_text, unescaped_search_text) != 0)) || 
	    (!match_case && !g_utf8_caselessnmatch (selected_text,
						    unescaped_search_text, 
						    strlen (selected_text), 
						    strlen (unescaped_search_text)) != 0))
	{
		do_find (dialog, window);
		g_free (unescaped_search_text);
		g_free (selected_text);	

		return;
	}

	unescaped_replace_text = pluma_utils_unescape_search_text (replace_entry_text);	
	replace_selected_text (GTK_TEXT_BUFFER (doc), unescaped_replace_text);

	g_free (unescaped_search_text);
	g_free (selected_text);
	g_free (unescaped_replace_text);
	
	do_find (dialog, window);
}
void
_pluma_cmd_search_replace (GtkAction   *action,
			   PlumaWindow *window)
{
	gpointer data;
	GtkWidget *replace_dialog;
	PlumaDocument *doc;
	gboolean selection_exists;
	gchar *find_text = NULL;
	gint sel_len;

	pluma_debug (DEBUG_COMMANDS);

	data = g_object_get_data (G_OBJECT (window), PLUMA_SEARCH_DIALOG_KEY);

	if (data == NULL)
	{
		replace_dialog = create_dialog (window, TRUE);
	}
	else
	{
		g_return_if_fail (PLUMA_IS_SEARCH_DIALOG (data));
		
		replace_dialog = GTK_WIDGET (data);
		
		/* turn the dialog into a find dialog if needed */
		if (!pluma_search_dialog_get_show_replace (PLUMA_SEARCH_DIALOG (replace_dialog)))
			pluma_search_dialog_set_show_replace (PLUMA_SEARCH_DIALOG (replace_dialog),
							      TRUE);
	}

	doc = pluma_window_get_active_document (window);
	g_return_if_fail (doc != NULL);

	selection_exists = get_selected_text (GTK_TEXT_BUFFER (doc),
					      &find_text,
					      &sel_len);

	if (selection_exists && find_text != NULL && sel_len < 80)
	{
		pluma_search_dialog_set_search_text (PLUMA_SEARCH_DIALOG (replace_dialog),
						     find_text);
		g_free (find_text);
	}
	else
	{
		g_free (find_text);
	}

	gtk_widget_show (replace_dialog);
	last_search_data_restore_position (PLUMA_SEARCH_DIALOG (replace_dialog));
	pluma_search_dialog_present_with_time (PLUMA_SEARCH_DIALOG (replace_dialog),
					       GDK_CURRENT_TIME);
}
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);
}
Exemplo n.º 6
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)));
}
Exemplo n.º 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);
}
static void
docinfo_dialog_response_cb (GtkDialog	*widget,
			    gint	res_id,
			    PlumaWindow *window)
{
	WindowData *data;

	pluma_debug (DEBUG_PLUGINS);
	
	data = (WindowData *) g_object_get_data (G_OBJECT (window),
						 WINDOW_DATA_KEY);

	switch (res_id)
	{
		case GTK_RESPONSE_CLOSE:
		{
			pluma_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CLOSE");
			gtk_widget_destroy (data->dialog->dialog);

			break;
		}

		case GTK_RESPONSE_OK:
		{
			PlumaDocument *doc;
			
			pluma_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK");
			
			doc = pluma_window_get_active_document (window);
			g_return_if_fail (doc != NULL);
			
			docinfo_real (doc,
				      data->dialog);

			selectioninfo_real (doc,
					    data->dialog);
			
			break;
		}
	}
}
Exemplo n.º 9
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);
	}
}
static void
docinfo_cb (GtkAction	*action,
	    PlumaWindow *window)
{
	PlumaDocument *doc;
	WindowData *data;

	pluma_debug (DEBUG_PLUGINS);

	data = (WindowData *) g_object_get_data (G_OBJECT (window),
						 WINDOW_DATA_KEY);

	doc = pluma_window_get_active_document (window);
	g_return_if_fail (doc != NULL);

	if (data->dialog != NULL)
	{
		gtk_window_present (GTK_WINDOW (data->dialog->dialog));
		gtk_widget_grab_focus (GTK_WIDGET (data->dialog->dialog));
	}
	else
	{
		DocInfoDialog *dialog;

		dialog = get_docinfo_dialog (window, data);
		g_return_if_fail (dialog != NULL);
		
		data->dialog = dialog;

		gtk_widget_show (GTK_WIDGET (dialog->dialog));
	}
	
	docinfo_real (doc, 
		      data->dialog);	
	selectioninfo_real (doc, 
			    data->dialog);
}
Exemplo n.º 11
0
/* serverside */
static void
on_message_received (const char *message,
		     gpointer    data)
{
	const PlumaEncoding *encoding = NULL;
	gchar **commands;
	gchar **params;
	gint workspace;
	gint viewport_x;
	gint viewport_y;
	gchar *display_name;
	gint screen_number;
	gint i;
	PlumaApp *app;
	PlumaWindow *window;
	GdkDisplay *display;
	GdkScreen *screen;

	g_return_if_fail (message != NULL);

	pluma_debug_message (DEBUG_APP, "Received message:\n%s\n", message);

	commands = g_strsplit (message, "\v", -1);

	/* header */
	params = g_strsplit (commands[0], "\t", 6);
	startup_timestamp = atoi (params[0]);
	display_name = params[1];
	screen_number = atoi (params[2]);
	workspace = atoi (params[3]);
	viewport_x = atoi (params[4]);
	viewport_y = atoi (params[5]);

	display = display_open_if_needed (display_name);
	if (display == NULL)
	{
		g_warning ("Could not open display %s\n", display_name);
		g_strfreev (params);
		goto out;
	}

	screen = gdk_display_get_screen (display, screen_number);

	g_strfreev (params);

	/* body */
	for (i = 1; commands[i] != NULL; i++)
	{
		params = g_strsplit (commands[i], "\t", -1);

		if (strcmp (params[0], "NEW-WINDOW") == 0)
		{
			new_window_option = TRUE;
		}
		else if (strcmp (params[0], "NEW-DOCUMENT") == 0)
		{
			new_document_option = TRUE;
		}
		else if (strcmp (params[0], "OPEN-URIS") == 0)
		{
			gint n_uris, j;
			gchar **uris;

			line_position = atoi (params[1]);

			if (params[2] != '\0')
				encoding = pluma_encoding_get_from_charset (params[2]);

			n_uris = atoi (params[3]);
			uris = g_strsplit (params[4], " ", n_uris);

			for (j = 0; j < n_uris; j++)
			{
				GFile *file;

				file = g_file_new_for_uri (uris[j]);
				file_list = g_slist_prepend (file_list, file);
			}

			file_list = g_slist_reverse (file_list);

			/* the list takes ownerhip of the strings,
			 * only free the array */
			g_free (uris);
		}
		else
		{
			g_warning ("Unexpected bacon command");
		}

		g_strfreev (params);
	}

	/* execute the commands */

	app = pluma_app_get_default ();

	if (new_window_option)
	{
		window = pluma_app_create_window (app, screen);
	}
	else
	{
		/* get a window in the current workspace (if exists) and raise it */
		window = _pluma_app_get_window_in_viewport (app,
							    screen,
							    workspace,
							    viewport_x,
							    viewport_y);
	}

	if (file_list != NULL)
	{
		_pluma_cmd_load_files_from_prompt (window,
						   file_list,
						   encoding,
						   line_position);

		if (new_document_option)
			pluma_window_create_tab (window, TRUE);
	}
	else
	{
		PlumaDocument *doc;
		doc = pluma_window_get_active_document (window);

		if (doc == NULL ||
		    !pluma_document_is_untouched (doc) ||
		    new_document_option)
			pluma_window_create_tab (window, TRUE);
	}

	/* set the proper interaction time on the window.
	 * Fall back to roundtripping to the X server when we
	 * don't have the timestamp, e.g. when launched from
	 * terminal. We also need to make sure that the window
	 * has been realized otherwise it will not work. lame.
	 */
	if (!gtk_widget_get_realized (GTK_WIDGET (window)))
		gtk_widget_realize (GTK_WIDGET (window));

	if (startup_timestamp <= 0)
		startup_timestamp = gdk_x11_get_server_time (gtk_widget_get_window (GTK_WIDGET (window)));

	gdk_x11_window_set_user_time (gtk_widget_get_window (GTK_WIDGET (window)),
				      startup_timestamp);

	gtk_window_present (GTK_WINDOW (window));

 out:
	g_strfreev (commands);

	free_command_line_data ();
}
Exemplo n.º 12
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);
	}
}