[latexila] Apply GtkSourceView coding style to *.c files
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] Apply GtkSourceView coding style to *.c files
- Date: Fri, 16 Feb 2018 11:28:09 +0000 (UTC)
commit 9968a940c9215cf400f6ea7d1cd085d14c4e47dc
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Feb 16 12:11:19 2018 +0100
Apply GtkSourceView coding style to *.c files
The script apply-gsv-coding-style-no-backup.sh from GtkSourceView has
been run on all the *.c files in gnome-latex. The script uses
uncrustify. The uncrustify config file is maybe not perfect, if someone
sees a problem, the uncrustify config file can be improved and then
re-run on all the *.c files.
The *.h files have not been processed, because the script cannot
correctly format function prototypes. The headers will either be
manually adapted, or another script can be written.
src/liblatexila/latexila-build-job.c | 964 ++++----
src/liblatexila/latexila-build-tool.c | 1118 +++++-----
src/liblatexila/latexila-build-tools-default.c | 233 +-
src/liblatexila/latexila-build-tools-personal.c | 370 ++--
src/liblatexila/latexila-build-tools.c | 628 +++---
src/liblatexila/latexila-build-view.c | 1105 +++++-----
src/liblatexila/latexila-latex-commands.c | 938 ++++----
.../latexila-post-processor-all-output.c | 70 +-
src/liblatexila/latexila-post-processor-latex.c | 2492 ++++++++++----------
src/liblatexila/latexila-post-processor-latexmk.c | 945 ++++----
src/liblatexila/latexila-post-processor.c | 633 +++---
src/liblatexila/latexila-synctex.c | 782 +++---
src/liblatexila/latexila-templates-common.c | 148 +-
src/liblatexila/latexila-templates-default.c | 260 ++-
src/liblatexila/latexila-templates-dialogs.c | 546 +++---
src/liblatexila/latexila-templates-manage-dialog.c | 490 ++--
src/liblatexila/latexila-templates-personal.c | 810 ++++---
src/liblatexila/latexila-utils.c | 487 ++--
src/liblatexila/latexila-view.c | 52 +-
tests/test-build-tools.c | 296 ++--
tests/test-utils.c | 118 +-
21 files changed, 6891 insertions(+), 6594 deletions(-)
---
diff --git a/src/liblatexila/latexila-build-job.c b/src/liblatexila/latexila-build-job.c
index 7959395..e5cae70 100644
--- a/src/liblatexila/latexila-build-job.c
+++ b/src/liblatexila/latexila-build-job.c
@@ -37,35 +37,35 @@
struct _LatexilaBuildJobPrivate
{
- gchar *command;
- LatexilaPostProcessorType post_processor_type;
- guint running_tasks_count;
+ gchar *command;
+ LatexilaPostProcessorType post_processor_type;
+ guint running_tasks_count;
};
/* Used for running the build job. */
typedef struct _TaskData TaskData;
struct _TaskData
{
- GFile *file;
- LatexilaBuildView *build_view;
- GtkTreeIter job_title;
- LatexilaPostProcessor *post_processor;
-
- /* To finish the post-processor we must know if the subprocess has succeeded.
- * Since there are two different callbacks that can be called in any order, we
- * store the needed results to pass to
- * latexila_post_processor_process_finish().
- */
- GAsyncResult *post_processor_result;
- guint succeeded : 1;
- guint succeeded_set : 1;
+ GFile *file;
+ LatexilaBuildView *build_view;
+ GtkTreeIter job_title;
+ LatexilaPostProcessor *post_processor;
+
+ /* To finish the post-processor we must know if the subprocess has succeeded.
+ * Since there are two different callbacks that can be called in any order, we
+ * store the needed results to pass to
+ * latexila_post_processor_process_finish().
+ */
+ GAsyncResult *post_processor_result;
+ guint succeeded : 1;
+ guint succeeded_set : 1;
};
enum
{
- PROP_0,
- PROP_COMMAND,
- PROP_POST_PROCESSOR_TYPE
+ PROP_0,
+ PROP_COMMAND,
+ PROP_POST_PROCESSOR_TYPE
};
G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildJob, latexila_build_job, G_TYPE_OBJECT)
@@ -73,120 +73,120 @@ G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildJob, latexila_build_job, G_TYPE_OBJECT)
static TaskData *
task_data_new (void)
{
- return g_slice_new0 (TaskData);
+ return g_slice_new0 (TaskData);
}
static void
task_data_free (TaskData *data)
{
- if (data != NULL)
- {
- g_clear_object (&data->file);
- g_clear_object (&data->build_view);
- g_clear_object (&data->post_processor);
- g_clear_object (&data->post_processor_result);
-
- g_slice_free (TaskData, data);
- }
+ if (data != NULL)
+ {
+ g_clear_object (&data->file);
+ g_clear_object (&data->build_view);
+ g_clear_object (&data->post_processor);
+ g_clear_object (&data->post_processor_result);
+
+ g_slice_free (TaskData, data);
+ }
}
static void
latexila_build_job_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- LatexilaBuildJob *build_job = LATEXILA_BUILD_JOB (object);
-
- switch (prop_id)
- {
- case PROP_COMMAND:
- g_value_set_string (value, build_job->priv->command);
- break;
-
- case PROP_POST_PROCESSOR_TYPE:
- g_value_set_enum (value, build_job->priv->post_processor_type);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ LatexilaBuildJob *build_job = LATEXILA_BUILD_JOB (object);
+
+ switch (prop_id)
+ {
+ case PROP_COMMAND:
+ g_value_set_string (value, build_job->priv->command);
+ break;
+
+ case PROP_POST_PROCESSOR_TYPE:
+ g_value_set_enum (value, build_job->priv->post_processor_type);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
latexila_build_job_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- LatexilaBuildJob *build_job = LATEXILA_BUILD_JOB (object);
-
- /* The build job can not be modified when it is running. */
- g_return_if_fail (build_job->priv->running_tasks_count == 0);
-
- switch (prop_id)
- {
- case PROP_COMMAND:
- g_free (build_job->priv->command);
- build_job->priv->command = g_value_dup_string (value);
- break;
-
- case PROP_POST_PROCESSOR_TYPE:
- build_job->priv->post_processor_type = g_value_get_enum (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ LatexilaBuildJob *build_job = LATEXILA_BUILD_JOB (object);
+
+ /* The build job can not be modified when it is running. */
+ g_return_if_fail (build_job->priv->running_tasks_count == 0);
+
+ switch (prop_id)
+ {
+ case PROP_COMMAND:
+ g_free (build_job->priv->command);
+ build_job->priv->command = g_value_dup_string (value);
+ break;
+
+ case PROP_POST_PROCESSOR_TYPE:
+ build_job->priv->post_processor_type = g_value_get_enum (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
latexila_build_job_finalize (GObject *object)
{
- LatexilaBuildJob *build_job = LATEXILA_BUILD_JOB (object);
+ LatexilaBuildJob *build_job = LATEXILA_BUILD_JOB (object);
- g_free (build_job->priv->command);
+ g_free (build_job->priv->command);
- G_OBJECT_CLASS (latexila_build_job_parent_class)->finalize (object);
+ G_OBJECT_CLASS (latexila_build_job_parent_class)->finalize (object);
}
static void
latexila_build_job_class_init (LatexilaBuildJobClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = latexila_build_job_get_property;
- object_class->set_property = latexila_build_job_set_property;
- object_class->finalize = latexila_build_job_finalize;
-
- g_object_class_install_property (object_class,
- PROP_COMMAND,
- g_param_spec_string ("command",
- "Command",
- "",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class,
- PROP_POST_PROCESSOR_TYPE,
- g_param_spec_enum ("post-processor-type",
- "Post-processor type",
- "",
- LATEXILA_TYPE_POST_PROCESSOR_TYPE,
- LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = latexila_build_job_get_property;
+ object_class->set_property = latexila_build_job_set_property;
+ object_class->finalize = latexila_build_job_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_COMMAND,
+ g_param_spec_string ("command",
+ "Command",
+ "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_POST_PROCESSOR_TYPE,
+ g_param_spec_enum ("post-processor-type",
+ "Post-processor type",
+ "",
+ LATEXILA_TYPE_POST_PROCESSOR_TYPE,
+ LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
}
static void
latexila_build_job_init (LatexilaBuildJob *build_job)
{
- build_job->priv = latexila_build_job_get_instance_private (build_job);
+ build_job->priv = latexila_build_job_get_instance_private (build_job);
}
/**
@@ -197,7 +197,7 @@ latexila_build_job_init (LatexilaBuildJob *build_job)
LatexilaBuildJob *
latexila_build_job_new (void)
{
- return g_object_new (LATEXILA_TYPE_BUILD_JOB, NULL);
+ return g_object_new (LATEXILA_TYPE_BUILD_JOB, NULL);
}
/**
@@ -211,12 +211,12 @@ latexila_build_job_new (void)
LatexilaBuildJob *
latexila_build_job_clone (LatexilaBuildJob *build_job)
{
- g_return_val_if_fail (LATEXILA_IS_BUILD_JOB (build_job), NULL);
+ g_return_val_if_fail (LATEXILA_IS_BUILD_JOB (build_job), NULL);
- return g_object_new (LATEXILA_TYPE_BUILD_JOB,
- "command", build_job->priv->command,
- "post-processor-type", build_job->priv->post_processor_type,
- NULL);
+ return g_object_new (LATEXILA_TYPE_BUILD_JOB,
+ "command", build_job->priv->command,
+ "post-processor-type", build_job->priv->post_processor_type,
+ NULL);
}
/**
@@ -228,383 +228,401 @@ latexila_build_job_clone (LatexilaBuildJob *build_job)
gchar *
latexila_build_job_to_xml (LatexilaBuildJob *build_job)
{
- g_return_val_if_fail (LATEXILA_IS_BUILD_JOB (build_job), NULL);
+ g_return_val_if_fail (LATEXILA_IS_BUILD_JOB (build_job), NULL);
- return g_markup_printf_escaped (" <job postProcessor=\"%s\">%s</job>\n",
- latexila_post_processor_get_name_from_type
(build_job->priv->post_processor_type),
- build_job->priv->command != NULL ? build_job->priv->command : "");
+ return g_markup_printf_escaped (" <job postProcessor=\"%s\">%s</job>\n",
+ latexila_post_processor_get_name_from_type
(build_job->priv->post_processor_type),
+ build_job->priv->command != NULL ? build_job->priv->command : "");
}
static gchar **
get_command_argv (GTask *task,
- gboolean for_printing,
- GError **error)
+ gboolean for_printing,
+ GError **error)
{
- LatexilaBuildJob *build_job = g_task_get_source_object (task);
- TaskData *data = g_task_get_task_data (task);
- gchar **argv;
- gchar *base_filename;
- gchar *base_shortname;
- gint i;
-
- /* Separate arguments */
- if (!g_shell_parse_argv (build_job->priv->command, NULL, &argv, error) ||
- argv == NULL)
- return NULL;
-
- /* Re-add quotes if needed */
- if (for_printing)
- {
- for (i = 0; argv[i] != NULL; i++)
- {
- /* If the argument contains a space, add the quotes. */
- if (strchr (argv[i], ' ') != NULL)
- {
- gchar *new_arg = g_strdup_printf ("\"%s\"", argv[i]);
- g_free (argv[i]);
- argv[i] = new_arg;
- }
- }
- }
-
- /* Replace placeholders */
- base_filename = g_file_get_basename (data->file);
- base_shortname = latexila_utils_get_shortname (base_filename);
-
- for (i = 0; argv[i] != NULL; i++)
- {
- gchar *new_arg = NULL;
-
- if (strstr (argv[i], "$filename") != NULL)
- {
- new_arg = latexila_utils_str_replace (argv[i], "$filename", base_filename);
- }
- else if (strstr (argv[i], "$shortname"))
- {
- new_arg = latexila_utils_str_replace (argv[i], "$shortname", base_shortname);
- }
- else if (strstr (argv[i], "$view"))
- {
- g_warning ("Build job: the '$view' placeholder is deprecated.");
- new_arg = latexila_utils_str_replace (argv[i], "$view", "xdg-open");
- }
-
- if (new_arg != NULL)
- {
- g_free (argv[i]);
- argv[i] = new_arg;
- }
- }
-
- g_free (base_filename);
- g_free (base_shortname);
- return argv;
+ LatexilaBuildJob *build_job = g_task_get_source_object (task);
+ TaskData *data = g_task_get_task_data (task);
+ gchar **argv;
+ gchar *base_filename;
+ gchar *base_shortname;
+ gint i;
+
+ /* Separate arguments */
+ if (!g_shell_parse_argv (build_job->priv->command, NULL, &argv, error) ||
+ argv == NULL)
+ {
+ return NULL;
+ }
+
+ /* Re-add quotes if needed */
+ if (for_printing)
+ {
+ for (i = 0; argv[i] != NULL; i++)
+ {
+ /* If the argument contains a space, add the quotes. */
+ if (strchr (argv[i], ' ') != NULL)
+ {
+ gchar *new_arg = g_strdup_printf ("\"%s\"", argv[i]);
+ g_free (argv[i]);
+ argv[i] = new_arg;
+ }
+ }
+ }
+
+ /* Replace placeholders */
+ base_filename = g_file_get_basename (data->file);
+ base_shortname = latexila_utils_get_shortname (base_filename);
+
+ for (i = 0; argv[i] != NULL; i++)
+ {
+ gchar *new_arg = NULL;
+
+ if (strstr (argv[i], "$filename") != NULL)
+ {
+ new_arg = latexila_utils_str_replace (argv[i], "$filename", base_filename);
+ }
+ else if (strstr (argv[i], "$shortname"))
+ {
+ new_arg = latexila_utils_str_replace (argv[i], "$shortname", base_shortname);
+ }
+ else if (strstr (argv[i], "$view"))
+ {
+ g_warning ("Build job: the '$view' placeholder is deprecated.");
+ new_arg = latexila_utils_str_replace (argv[i], "$view", "xdg-open");
+ }
+
+ if (new_arg != NULL)
+ {
+ g_free (argv[i]);
+ argv[i] = new_arg;
+ }
+ }
+
+ g_free (base_filename);
+ g_free (base_shortname);
+ return argv;
}
static gchar *
get_command_name (GTask *task)
{
- gchar **argv;
- gchar *command_name;
-
- argv = get_command_argv (task, TRUE, NULL);
-
- if (argv == NULL || argv[0] == NULL || argv[0][0] == '\0')
- command_name = NULL;
- else
- command_name = g_strdup (argv[0]);
-
- g_strfreev (argv);
- return command_name;
+ gchar **argv;
+ gchar *command_name;
+
+ argv = get_command_argv (task, TRUE, NULL);
+
+ if (argv == NULL || argv[0] == NULL || argv[0][0] == '\0')
+ {
+ command_name = NULL;
+ }
+ else
+ {
+ command_name = g_strdup (argv[0]);
+ }
+
+ g_strfreev (argv);
+ return command_name;
}
static void
display_error (GTask *task,
- const gchar *message,
- GError *error)
+ const gchar *message,
+ GError *error)
{
- TaskData *data = g_task_get_task_data (task);
- LatexilaBuildMsg *build_msg;
-
- g_assert (error != NULL);
-
- latexila_build_view_set_title_state (data->build_view,
- &data->job_title,
- LATEXILA_BUILD_STATE_FAILED);
-
- build_msg = latexila_build_msg_new ();
- build_msg->text = (gchar *) message;
- build_msg->type = LATEXILA_BUILD_MSG_TYPE_ERROR;
- latexila_build_view_append_single_message (data->build_view,
- &data->job_title,
- build_msg);
-
- build_msg->text = g_strdup (error->message);
- build_msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
- latexila_build_view_append_single_message (data->build_view,
- &data->job_title,
- build_msg);
-
- /* If the command doesn't seem to be installed, display a more understandable
- * message.
- */
- if (error->domain == G_SPAWN_ERROR &&
- error->code == G_SPAWN_ERROR_NOENT)
- {
- gchar *command_name = get_command_name (task);
-
- if (command_name != NULL)
- {
- g_free (build_msg->text);
- build_msg->text = g_strdup_printf (_("%s doesn't seem to be installed."), command_name);
-
- latexila_build_view_append_single_message (data->build_view,
- &data->job_title,
- build_msg);
-
- g_free (command_name);
- }
- }
-
- g_error_free (error);
- latexila_build_msg_free (build_msg);
- g_task_return_boolean (task, FALSE);
- g_object_unref (task);
+ TaskData *data = g_task_get_task_data (task);
+ LatexilaBuildMsg *build_msg;
+
+ g_assert (error != NULL);
+
+ latexila_build_view_set_title_state (data->build_view,
+ &data->job_title,
+ LATEXILA_BUILD_STATE_FAILED);
+
+ build_msg = latexila_build_msg_new ();
+ build_msg->text = (gchar *) message;
+ build_msg->type = LATEXILA_BUILD_MSG_TYPE_ERROR;
+ latexila_build_view_append_single_message (data->build_view,
+ &data->job_title,
+ build_msg);
+
+ build_msg->text = g_strdup (error->message);
+ build_msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
+ latexila_build_view_append_single_message (data->build_view,
+ &data->job_title,
+ build_msg);
+
+ /* If the command doesn't seem to be installed, display a more understandable
+ * message.
+ */
+ if (error->domain == G_SPAWN_ERROR &&
+ error->code == G_SPAWN_ERROR_NOENT)
+ {
+ gchar *command_name = get_command_name (task);
+
+ if (command_name != NULL)
+ {
+ g_free (build_msg->text);
+ build_msg->text = g_strdup_printf (_ ("%s doesn't seem to be installed."),
command_name);
+
+ latexila_build_view_append_single_message (data->build_view,
+ &data->job_title,
+ build_msg);
+
+ g_free (command_name);
+ }
+ }
+
+ g_error_free (error);
+ latexila_build_msg_free (build_msg);
+ g_task_return_boolean (task, FALSE);
+ g_object_unref (task);
}
/* Returns TRUE on success. */
static gboolean
display_command_line (GTask *task)
{
- LatexilaBuildJob *build_job = g_task_get_source_object (task);
- TaskData *data = g_task_get_task_data (task);
- gchar **argv;
- gchar *command_line;
- GError *error = NULL;
+ LatexilaBuildJob *build_job = g_task_get_source_object (task);
+ TaskData *data = g_task_get_task_data (task);
+ gchar **argv;
+ gchar *command_line;
+ GError *error = NULL;
- argv = get_command_argv (task, TRUE, &error);
+ argv = get_command_argv (task, TRUE, &error);
- if (error != NULL)
- {
- data->job_title = latexila_build_view_add_job_title (data->build_view,
- build_job->priv->command,
- LATEXILA_BUILD_STATE_FAILED);
+ if (error != NULL)
+ {
+ data->job_title = latexila_build_view_add_job_title (data->build_view,
+ build_job->priv->command,
+ LATEXILA_BUILD_STATE_FAILED);
- display_error (task, "Failed to parse command line:", error);
- return FALSE;
- }
+ display_error (task, "Failed to parse command line:", error);
+ return FALSE;
+ }
- command_line = g_strjoinv (" ", argv);
+ command_line = g_strjoinv (" ", argv);
- data->job_title = latexila_build_view_add_job_title (data->build_view,
- command_line,
- LATEXILA_BUILD_STATE_RUNNING);
+ data->job_title = latexila_build_view_add_job_title (data->build_view,
+ command_line,
+ LATEXILA_BUILD_STATE_RUNNING);
- g_strfreev (argv);
- g_free (command_line);
- return TRUE;
+ g_strfreev (argv);
+ g_free (command_line);
+ return TRUE;
}
static void
show_details_notify_cb (LatexilaBuildView *build_view,
- GParamSpec *pspec,
- GTask *task)
+ GParamSpec *pspec,
+ GTask *task)
{
- TaskData *data = g_task_get_task_data (task);
- const GList *messages;
- gboolean show_details;
+ TaskData *data = g_task_get_task_data (task);
+ const GList *messages;
+ gboolean show_details;
- latexila_build_view_remove_children (build_view, &data->job_title);
+ latexila_build_view_remove_children (build_view, &data->job_title);
- g_object_get (build_view, "show-details", &show_details, NULL);
+ g_object_get (build_view, "show-details", &show_details, NULL);
- messages = latexila_post_processor_get_messages (data->post_processor,
- show_details);
+ messages = latexila_post_processor_get_messages (data->post_processor,
+ show_details);
- latexila_build_view_append_messages (build_view,
- &data->job_title,
- messages,
- TRUE);
+ latexila_build_view_append_messages (build_view,
+ &data->job_title,
+ messages,
+ TRUE);
}
static void
finish_post_processor (GTask *task)
{
- TaskData *data = g_task_get_task_data (task);
- gboolean has_details;
+ TaskData *data = g_task_get_task_data (task);
+ gboolean has_details;
- g_assert (data->succeeded_set);
- g_assert (data->post_processor_result != NULL);
+ g_assert (data->succeeded_set);
+ g_assert (data->post_processor_result != NULL);
- latexila_post_processor_process_finish (data->post_processor,
- data->post_processor_result,
- data->succeeded);
+ latexila_post_processor_process_finish (data->post_processor,
+ data->post_processor_result,
+ data->succeeded);
- g_clear_object (&data->post_processor_result);
+ g_clear_object (&data->post_processor_result);
- g_object_get (data->post_processor,
- "has-details", &has_details,
- NULL);
+ g_object_get (data->post_processor,
+ "has-details", &has_details,
+ NULL);
- if (has_details)
- g_object_set (data->build_view,
- "has-details", TRUE,
- NULL);
+ if (has_details)
+ {
+ g_object_set (data->build_view,
+ "has-details", TRUE,
+ NULL);
+ }
- g_signal_connect_object (data->build_view,
- "notify::show-details",
- G_CALLBACK (show_details_notify_cb),
- task,
- 0);
+ g_signal_connect_object (data->build_view,
+ "notify::show-details",
+ G_CALLBACK (show_details_notify_cb),
+ task,
+ 0);
- show_details_notify_cb (data->build_view, NULL, task);
+ show_details_notify_cb (data->build_view, NULL, task);
}
static void
post_processor_cb (LatexilaPostProcessor *pp,
- GAsyncResult *result,
- GTask *task)
+ GAsyncResult *result,
+ GTask *task)
{
- TaskData *data = g_task_get_task_data (task);
+ TaskData *data = g_task_get_task_data (task);
- if (data->post_processor_result != NULL)
- {
- g_warning ("BuildJob: got two post-processor results.");
- g_object_unref (data->post_processor_result);
- }
+ if (data->post_processor_result != NULL)
+ {
+ g_warning ("BuildJob: got two post-processor results.");
+ g_object_unref (data->post_processor_result);
+ }
- data->post_processor_result = g_object_ref (result);
+ data->post_processor_result = g_object_ref (result);
- if (data->succeeded_set)
- finish_post_processor (task);
+ if (data->succeeded_set)
+ {
+ finish_post_processor (task);
+ }
- g_object_unref (task);
+ g_object_unref (task);
}
static void
subprocess_wait_cb (GSubprocess *subprocess,
- GAsyncResult *result,
- GTask *task)
+ GAsyncResult *result,
+ GTask *task)
{
- TaskData *data = g_task_get_task_data (task);
- gboolean ret;
- LatexilaBuildState state;
-
- ret = g_subprocess_wait_finish (subprocess, result, NULL);
-
- if (data->succeeded_set)
- g_warning ("BuildJob: subprocess finished two times.");
-
- data->succeeded = g_subprocess_get_successful (subprocess);
- data->succeeded_set = TRUE;
-
- if (!ret)
- {
- state = LATEXILA_BUILD_STATE_ABORTED;
- g_subprocess_force_exit (subprocess);
- }
- else if (data->succeeded)
- {
- state = LATEXILA_BUILD_STATE_SUCCEEDED;
- }
- else
- {
- ret = FALSE;
- state = LATEXILA_BUILD_STATE_FAILED;
- }
-
- latexila_build_view_set_title_state (data->build_view,
- &data->job_title,
- state);
-
- g_task_return_boolean (task, ret);
-
- if (data->post_processor_result != NULL)
- finish_post_processor (task);
-
- g_object_unref (subprocess);
- g_object_unref (task);
+ TaskData *data = g_task_get_task_data (task);
+ gboolean ret;
+ LatexilaBuildState state;
+
+ ret = g_subprocess_wait_finish (subprocess, result, NULL);
+
+ if (data->succeeded_set)
+ {
+ g_warning ("BuildJob: subprocess finished two times.");
+ }
+
+ data->succeeded = g_subprocess_get_successful (subprocess);
+ data->succeeded_set = TRUE;
+
+ if (!ret)
+ {
+ state = LATEXILA_BUILD_STATE_ABORTED;
+ g_subprocess_force_exit (subprocess);
+ }
+ else if (data->succeeded)
+ {
+ state = LATEXILA_BUILD_STATE_SUCCEEDED;
+ }
+ else
+ {
+ ret = FALSE;
+ state = LATEXILA_BUILD_STATE_FAILED;
+ }
+
+ latexila_build_view_set_title_state (data->build_view,
+ &data->job_title,
+ state);
+
+ g_task_return_boolean (task, ret);
+
+ if (data->post_processor_result != NULL)
+ {
+ finish_post_processor (task);
+ }
+
+ g_object_unref (subprocess);
+ g_object_unref (task);
}
static void
launch_subprocess (GTask *task)
{
- LatexilaBuildJob *build_job = g_task_get_source_object (task);
- TaskData *data = g_task_get_task_data (task);
- GSubprocessLauncher *launcher;
- GSubprocess *subprocess;
- GFile *parent_dir;
- gchar *working_directory;
- gchar **argv;
- GError *error = NULL;
-
- if (build_job->priv->post_processor_type == LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT)
- launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_SILENCE |
- G_SUBPROCESS_FLAGS_STDERR_SILENCE);
- else
- launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE |
- G_SUBPROCESS_FLAGS_STDERR_MERGE);
-
- parent_dir = g_file_get_parent (data->file);
- working_directory = g_file_get_path (parent_dir);
- g_object_unref (parent_dir);
-
- g_subprocess_launcher_set_cwd (launcher, working_directory);
- g_free (working_directory);
-
- /* The error is already catched in display_command_line(). */
- argv = get_command_argv (task, FALSE, NULL);
-
- subprocess = g_subprocess_launcher_spawnv (launcher, (const gchar * const *) argv, &error);
- g_strfreev (argv);
- g_object_unref (launcher);
-
- if (error != NULL)
- {
- display_error (task, "Failed to launch command:", error);
- return;
- }
-
- g_clear_object (&data->post_processor);
-
- switch (build_job->priv->post_processor_type)
- {
- case LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT:
- break;
-
- case LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT:
- data->post_processor = latexila_post_processor_all_output_new ();
- break;
-
- case LATEXILA_POST_PROCESSOR_TYPE_LATEX:
- data->post_processor = latexila_post_processor_latex_new ();
- break;
-
- case LATEXILA_POST_PROCESSOR_TYPE_LATEXMK:
- data->post_processor = latexila_post_processor_latexmk_new ();
- break;
-
- case LATEXILA_POST_PROCESSOR_TYPE_NB_TYPES:
- default:
- g_return_if_reached ();
- }
-
- if (data->post_processor != NULL)
- {
- g_object_ref (task);
-
- latexila_post_processor_process_async (data->post_processor,
- data->file,
- g_subprocess_get_stdout_pipe (subprocess),
- g_task_get_cancellable (task),
- (GAsyncReadyCallback) post_processor_cb,
- task);
- }
-
- g_subprocess_wait_async (subprocess,
- g_task_get_cancellable (task),
- (GAsyncReadyCallback) subprocess_wait_cb,
- task);
+ LatexilaBuildJob *build_job = g_task_get_source_object (task);
+ TaskData *data = g_task_get_task_data (task);
+ GSubprocessLauncher *launcher;
+ GSubprocess *subprocess;
+ GFile *parent_dir;
+ gchar *working_directory;
+ gchar **argv;
+ GError *error = NULL;
+
+ if (build_job->priv->post_processor_type == LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT)
+ {
+ launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_SILENCE |
+ G_SUBPROCESS_FLAGS_STDERR_SILENCE);
+ }
+ else
+ {
+ launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE |
+ G_SUBPROCESS_FLAGS_STDERR_MERGE);
+ }
+
+ parent_dir = g_file_get_parent (data->file);
+ working_directory = g_file_get_path (parent_dir);
+ g_object_unref (parent_dir);
+
+ g_subprocess_launcher_set_cwd (launcher, working_directory);
+ g_free (working_directory);
+
+ /* The error is already catched in display_command_line(). */
+ argv = get_command_argv (task, FALSE, NULL);
+
+ subprocess = g_subprocess_launcher_spawnv (launcher, (const gchar * const *) argv, &error);
+ g_strfreev (argv);
+ g_object_unref (launcher);
+
+ if (error != NULL)
+ {
+ display_error (task, "Failed to launch command:", error);
+ return;
+ }
+
+ g_clear_object (&data->post_processor);
+
+ switch (build_job->priv->post_processor_type)
+ {
+ case LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT:
+ break;
+
+ case LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT:
+ data->post_processor = latexila_post_processor_all_output_new ();
+ break;
+
+ case LATEXILA_POST_PROCESSOR_TYPE_LATEX:
+ data->post_processor = latexila_post_processor_latex_new ();
+ break;
+
+ case LATEXILA_POST_PROCESSOR_TYPE_LATEXMK:
+ data->post_processor = latexila_post_processor_latexmk_new ();
+ break;
+
+ case LATEXILA_POST_PROCESSOR_TYPE_NB_TYPES:
+ default:
+ g_return_if_reached ();
+ }
+
+ if (data->post_processor != NULL)
+ {
+ g_object_ref (task);
+
+ latexila_post_processor_process_async (data->post_processor,
+ data->file,
+ g_subprocess_get_stdout_pipe (subprocess),
+ g_task_get_cancellable (task),
+ (GAsyncReadyCallback) post_processor_cb,
+ task);
+ }
+
+ g_subprocess_wait_async (subprocess,
+ g_task_get_cancellable (task),
+ (GAsyncReadyCallback) subprocess_wait_cb,
+ task);
}
/**
@@ -622,35 +640,41 @@ launch_subprocess (GTask *task)
*/
void
latexila_build_job_run_async (LatexilaBuildJob *build_job,
- GFile *file,
- LatexilaBuildView *build_view,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ GFile *file,
+ LatexilaBuildView *build_view,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- GTask *task;
- TaskData *data;
-
- g_return_if_fail (LATEXILA_IS_BUILD_JOB (build_job));
- g_return_if_fail (G_IS_FILE (file));
- g_return_if_fail (LATEXILA_IS_BUILD_VIEW (build_view));
-
- task = g_task_new (build_job, cancellable, callback, user_data);
- build_job->priv->running_tasks_count++;
-
- data = task_data_new ();
- g_task_set_task_data (task, data, (GDestroyNotify) task_data_free);
-
- data->file = g_object_ref (file);
- data->build_view = g_object_ref (build_view);
-
- if (!display_command_line (task))
- return;
-
- if (g_task_return_error_if_cancelled (task))
- g_object_unref (task);
- else
- launch_subprocess (task);
+ GTask *task;
+ TaskData *data;
+
+ g_return_if_fail (LATEXILA_IS_BUILD_JOB (build_job));
+ g_return_if_fail (G_IS_FILE (file));
+ g_return_if_fail (LATEXILA_IS_BUILD_VIEW (build_view));
+
+ task = g_task_new (build_job, cancellable, callback, user_data);
+ build_job->priv->running_tasks_count++;
+
+ data = task_data_new ();
+ g_task_set_task_data (task, data, (GDestroyNotify) task_data_free);
+
+ data->file = g_object_ref (file);
+ data->build_view = g_object_ref (build_view);
+
+ if (!display_command_line (task))
+ {
+ return;
+ }
+
+ if (g_task_return_error_if_cancelled (task))
+ {
+ g_object_unref (task);
+ }
+ else
+ {
+ launch_subprocess (task);
+ }
}
/**
@@ -667,31 +691,31 @@ latexila_build_job_run_async (LatexilaBuildJob *build_job,
*/
gboolean
latexila_build_job_run_finish (LatexilaBuildJob *build_job,
- GAsyncResult *result)
+ GAsyncResult *result)
{
- GTask *task;
- TaskData *data;
- GCancellable *cancellable;
- gboolean succeed;
-
- g_return_val_if_fail (g_task_is_valid (result, build_job), FALSE);
-
- task = G_TASK (result);
- data = g_task_get_task_data (task);
-
- cancellable = g_task_get_cancellable (task);
- if (g_cancellable_is_cancelled (cancellable))
- {
- latexila_build_view_set_title_state (data->build_view,
- &data->job_title,
- LATEXILA_BUILD_STATE_ABORTED);
- succeed = FALSE;
- }
- else
- {
- succeed = g_task_propagate_boolean (task, NULL);
- }
-
- build_job->priv->running_tasks_count--;
- return succeed;
+ GTask *task;
+ TaskData *data;
+ GCancellable *cancellable;
+ gboolean succeed;
+
+ g_return_val_if_fail (g_task_is_valid (result, build_job), FALSE);
+
+ task = G_TASK (result);
+ data = g_task_get_task_data (task);
+
+ cancellable = g_task_get_cancellable (task);
+ if (g_cancellable_is_cancelled (cancellable))
+ {
+ latexila_build_view_set_title_state (data->build_view,
+ &data->job_title,
+ LATEXILA_BUILD_STATE_ABORTED);
+ succeed = FALSE;
+ }
+ else
+ {
+ succeed = g_task_propagate_boolean (task, NULL);
+ }
+
+ build_job->priv->running_tasks_count--;
+ return succeed;
}
diff --git a/src/liblatexila/latexila-build-tool.c b/src/liblatexila/latexila-build-tool.c
index c760bb7..3c8c0af 100644
--- a/src/liblatexila/latexila-build-tool.c
+++ b/src/liblatexila/latexila-build-tool.c
@@ -37,51 +37,51 @@
struct _LatexilaBuildToolPrivate
{
- gchar *label;
- gchar *description;
- gchar *extensions;
- gchar *icon;
- gchar *files_to_open;
- gchar **files_to_open_split;
- gint id;
+ gchar *label;
+ gchar *description;
+ gchar *extensions;
+ gchar *icon;
+ gchar *files_to_open;
+ gchar **files_to_open_split;
+ gint id;
- /* A list of LatexilaBuildJob's. */
- GQueue *jobs;
+ /* A list of LatexilaBuildJob's. */
+ GQueue *jobs;
- guint running_tasks_count;
+ guint running_tasks_count;
- guint enabled : 1;
+ guint enabled : 1;
};
/* Used for running the build tool. */
typedef struct _TaskData TaskData;
struct _TaskData
{
- GFile *file;
- LatexilaBuildView *build_view;
- GtkTreeIter main_title;
+ GFile *file;
+ LatexilaBuildView *build_view;
+ GtkTreeIter main_title;
- /* Position in priv->jobs. */
- GList *current_job;
+ /* Position in priv->jobs. */
+ GList *current_job;
- /* Position in priv->files_to_open_split. */
- gchar **current_file_to_open;
+ /* Position in priv->files_to_open_split. */
+ gchar **current_file_to_open;
- GtkTreeIter open_file_job_title;
+ GtkTreeIter open_file_job_title;
- GSList *job_results;
+ GSList *job_results;
};
enum
{
- PROP_0,
- PROP_LABEL,
- PROP_DESCRIPTION,
- PROP_EXTENSIONS,
- PROP_ICON,
- PROP_FILES_TO_OPEN,
- PROP_ID,
- PROP_ENABLED
+ PROP_0,
+ PROP_LABEL,
+ PROP_DESCRIPTION,
+ PROP_EXTENSIONS,
+ PROP_ICON,
+ PROP_FILES_TO_OPEN,
+ PROP_ID,
+ PROP_ENABLED
};
G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildTool, latexila_build_tool, G_TYPE_OBJECT)
@@ -93,247 +93,249 @@ static void open_file (GTask *task);
static TaskData *
task_data_new (void)
{
- return g_slice_new0 (TaskData);
+ return g_slice_new0 (TaskData);
}
static void
task_data_free (TaskData *data)
{
- if (data != NULL)
- {
- g_clear_object (&data->file);
- g_clear_object (&data->build_view);
- g_slist_free_full (data->job_results, g_object_unref);
-
- g_slice_free (TaskData, data);
- }
+ if (data != NULL)
+ {
+ g_clear_object (&data->file);
+ g_clear_object (&data->build_view);
+ g_slist_free_full (data->job_results, g_object_unref);
+
+ g_slice_free (TaskData, data);
+ }
}
static void
latexila_build_tool_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- LatexilaBuildTool *build_tool = LATEXILA_BUILD_TOOL (object);
-
- switch (prop_id)
- {
- case PROP_LABEL:
- g_value_set_string (value, build_tool->priv->label);
- break;
-
- case PROP_DESCRIPTION:
- g_value_set_string (value, build_tool->priv->description);
- break;
-
- case PROP_EXTENSIONS:
- g_value_set_string (value, build_tool->priv->extensions);
- break;
-
- case PROP_ICON:
- g_value_set_string (value, build_tool->priv->icon);
- break;
-
- case PROP_FILES_TO_OPEN:
- g_value_set_string (value, build_tool->priv->files_to_open);
- break;
-
- case PROP_ID:
- g_value_set_int (value, build_tool->priv->id);
- break;
-
- case PROP_ENABLED:
- g_value_set_boolean (value, build_tool->priv->enabled);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ LatexilaBuildTool *build_tool = LATEXILA_BUILD_TOOL (object);
+
+ switch (prop_id)
+ {
+ case PROP_LABEL:
+ g_value_set_string (value, build_tool->priv->label);
+ break;
+
+ case PROP_DESCRIPTION:
+ g_value_set_string (value, build_tool->priv->description);
+ break;
+
+ case PROP_EXTENSIONS:
+ g_value_set_string (value, build_tool->priv->extensions);
+ break;
+
+ case PROP_ICON:
+ g_value_set_string (value, build_tool->priv->icon);
+ break;
+
+ case PROP_FILES_TO_OPEN:
+ g_value_set_string (value, build_tool->priv->files_to_open);
+ break;
+
+ case PROP_ID:
+ g_value_set_int (value, build_tool->priv->id);
+ break;
+
+ case PROP_ENABLED:
+ g_value_set_boolean (value, build_tool->priv->enabled);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
latexila_build_tool_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- LatexilaBuildTool *build_tool = LATEXILA_BUILD_TOOL (object);
-
- /* The build tool can not be modified when it is running. */
- g_return_if_fail (build_tool->priv->running_tasks_count == 0);
-
- switch (prop_id)
- {
- case PROP_LABEL:
- g_free (build_tool->priv->label);
- build_tool->priv->label = g_value_dup_string (value);
- break;
-
- case PROP_DESCRIPTION:
- g_free (build_tool->priv->description);
- build_tool->priv->description = g_value_dup_string (value);
- break;
-
- case PROP_EXTENSIONS:
- g_free (build_tool->priv->extensions);
- build_tool->priv->extensions = g_value_dup_string (value);
- break;
-
- case PROP_ICON:
- g_free (build_tool->priv->icon);
- build_tool->priv->icon = g_value_dup_string (value);
- break;
-
- case PROP_FILES_TO_OPEN:
- g_free (build_tool->priv->files_to_open);
- build_tool->priv->files_to_open = g_value_dup_string (value);
-
- g_strfreev (build_tool->priv->files_to_open_split);
- build_tool->priv->files_to_open_split = NULL;
- if (build_tool->priv->files_to_open != NULL)
- build_tool->priv->files_to_open_split = g_strsplit (build_tool->priv->files_to_open, " ", -1);
- break;
-
- case PROP_ID:
- build_tool->priv->id = g_value_get_int (value);
- break;
-
- case PROP_ENABLED:
- build_tool->priv->enabled = g_value_get_boolean (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ LatexilaBuildTool *build_tool = LATEXILA_BUILD_TOOL (object);
+
+ /* The build tool can not be modified when it is running. */
+ g_return_if_fail (build_tool->priv->running_tasks_count == 0);
+
+ switch (prop_id)
+ {
+ case PROP_LABEL:
+ g_free (build_tool->priv->label);
+ build_tool->priv->label = g_value_dup_string (value);
+ break;
+
+ case PROP_DESCRIPTION:
+ g_free (build_tool->priv->description);
+ build_tool->priv->description = g_value_dup_string (value);
+ break;
+
+ case PROP_EXTENSIONS:
+ g_free (build_tool->priv->extensions);
+ build_tool->priv->extensions = g_value_dup_string (value);
+ break;
+
+ case PROP_ICON:
+ g_free (build_tool->priv->icon);
+ build_tool->priv->icon = g_value_dup_string (value);
+ break;
+
+ case PROP_FILES_TO_OPEN:
+ g_free (build_tool->priv->files_to_open);
+ build_tool->priv->files_to_open = g_value_dup_string (value);
+
+ g_strfreev (build_tool->priv->files_to_open_split);
+ build_tool->priv->files_to_open_split = NULL;
+ if (build_tool->priv->files_to_open != NULL)
+ {
+ build_tool->priv->files_to_open_split = g_strsplit
(build_tool->priv->files_to_open, " ", -1);
+ }
+ break;
+
+ case PROP_ID:
+ build_tool->priv->id = g_value_get_int (value);
+ break;
+
+ case PROP_ENABLED:
+ build_tool->priv->enabled = g_value_get_boolean (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
latexila_build_tool_dispose (GObject *object)
{
- LatexilaBuildTool *build_tool = LATEXILA_BUILD_TOOL (object);
+ LatexilaBuildTool *build_tool = LATEXILA_BUILD_TOOL (object);
- if (build_tool->priv->jobs != NULL)
- {
- g_queue_free_full (build_tool->priv->jobs, g_object_unref);
- build_tool->priv->jobs = NULL;
- }
+ if (build_tool->priv->jobs != NULL)
+ {
+ g_queue_free_full (build_tool->priv->jobs, g_object_unref);
+ build_tool->priv->jobs = NULL;
+ }
- G_OBJECT_CLASS (latexila_build_tool_parent_class)->dispose (object);
+ G_OBJECT_CLASS (latexila_build_tool_parent_class)->dispose (object);
}
static void
latexila_build_tool_finalize (GObject *object)
{
- LatexilaBuildTool *build_tool = LATEXILA_BUILD_TOOL (object);
+ LatexilaBuildTool *build_tool = LATEXILA_BUILD_TOOL (object);
- g_free (build_tool->priv->label);
- g_free (build_tool->priv->description);
- g_free (build_tool->priv->extensions);
- g_free (build_tool->priv->icon);
- g_free (build_tool->priv->files_to_open);
- g_strfreev (build_tool->priv->files_to_open_split);
+ g_free (build_tool->priv->label);
+ g_free (build_tool->priv->description);
+ g_free (build_tool->priv->extensions);
+ g_free (build_tool->priv->icon);
+ g_free (build_tool->priv->files_to_open);
+ g_strfreev (build_tool->priv->files_to_open_split);
- G_OBJECT_CLASS (latexila_build_tool_parent_class)->finalize (object);
+ G_OBJECT_CLASS (latexila_build_tool_parent_class)->finalize (object);
}
static void
latexila_build_tool_class_init (LatexilaBuildToolClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = latexila_build_tool_get_property;
- object_class->set_property = latexila_build_tool_set_property;
- object_class->dispose = latexila_build_tool_dispose;
- object_class->finalize = latexila_build_tool_finalize;
-
- g_object_class_install_property (object_class,
- PROP_LABEL,
- g_param_spec_string ("label",
- "Label",
- "",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class,
- PROP_DESCRIPTION,
- g_param_spec_string ("description",
- "Description",
- "",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class,
- PROP_EXTENSIONS,
- g_param_spec_string ("extensions",
- "Extensions",
- "",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class,
- PROP_ICON,
- g_param_spec_string ("icon",
- "Icon",
- "",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class,
- PROP_FILES_TO_OPEN,
- g_param_spec_string ("files-to-open",
- "Files to open",
- "",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * LatexilaBuildTool:id:
- *
- * The build tool ID. It is used only by the default build tools, for saving
- * in #GSettings the lists of enabled/disabled build tools.
- */
- g_object_class_install_property (object_class,
- PROP_ID,
- g_param_spec_int ("id",
- "ID",
- "",
- 0,
- G_MAXINT,
- 0,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class,
- PROP_ENABLED,
- g_param_spec_boolean ("enabled",
- "Enabled",
- "",
- FALSE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = latexila_build_tool_get_property;
+ object_class->set_property = latexila_build_tool_set_property;
+ object_class->dispose = latexila_build_tool_dispose;
+ object_class->finalize = latexila_build_tool_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_LABEL,
+ g_param_spec_string ("label",
+ "Label",
+ "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_DESCRIPTION,
+ g_param_spec_string ("description",
+ "Description",
+ "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_EXTENSIONS,
+ g_param_spec_string ("extensions",
+ "Extensions",
+ "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_ICON,
+ g_param_spec_string ("icon",
+ "Icon",
+ "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_FILES_TO_OPEN,
+ g_param_spec_string ("files-to-open",
+ "Files to open",
+ "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * LatexilaBuildTool:id:
+ *
+ * The build tool ID. It is used only by the default build tools, for saving
+ * in #GSettings the lists of enabled/disabled build tools.
+ */
+ g_object_class_install_property (object_class,
+ PROP_ID,
+ g_param_spec_int ("id",
+ "ID",
+ "",
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_ENABLED,
+ g_param_spec_boolean ("enabled",
+ "Enabled",
+ "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
}
static void
latexila_build_tool_init (LatexilaBuildTool *self)
{
- self->priv = latexila_build_tool_get_instance_private (self);
+ self->priv = latexila_build_tool_get_instance_private (self);
- self->priv->jobs = g_queue_new ();
+ self->priv->jobs = g_queue_new ();
}
/**
@@ -344,7 +346,7 @@ latexila_build_tool_init (LatexilaBuildTool *self)
LatexilaBuildTool *
latexila_build_tool_new (void)
{
- return g_object_new (LATEXILA_TYPE_BUILD_TOOL, NULL);
+ return g_object_new (LATEXILA_TYPE_BUILD_TOOL, NULL);
}
/**
@@ -358,31 +360,31 @@ latexila_build_tool_new (void)
LatexilaBuildTool *
latexila_build_tool_clone (LatexilaBuildTool *build_tool)
{
- LatexilaBuildTool *new_build_tool;
- GList *l;
-
- g_return_val_if_fail (LATEXILA_IS_BUILD_TOOL (build_tool), NULL);
-
- new_build_tool = g_object_new (LATEXILA_TYPE_BUILD_TOOL,
- "label", build_tool->priv->label,
- "description", build_tool->priv->description,
- "extensions", build_tool->priv->extensions,
- "icon", build_tool->priv->icon,
- "files-to-open", build_tool->priv->files_to_open,
- "enabled", build_tool->priv->enabled,
- "id", build_tool->priv->id,
- NULL);
-
- for (l = build_tool->priv->jobs->head; l != NULL; l = l->next)
- {
- LatexilaBuildJob *build_job = l->data;
- LatexilaBuildJob *new_build_job = latexila_build_job_clone (build_job);
-
- latexila_build_tool_add_job (new_build_tool, new_build_job);
- g_object_unref (new_build_job);
- }
-
- return new_build_tool;
+ LatexilaBuildTool *new_build_tool;
+ GList *l;
+
+ g_return_val_if_fail (LATEXILA_IS_BUILD_TOOL (build_tool), NULL);
+
+ new_build_tool = g_object_new (LATEXILA_TYPE_BUILD_TOOL,
+ "label", build_tool->priv->label,
+ "description", build_tool->priv->description,
+ "extensions", build_tool->priv->extensions,
+ "icon", build_tool->priv->icon,
+ "files-to-open", build_tool->priv->files_to_open,
+ "enabled", build_tool->priv->enabled,
+ "id", build_tool->priv->id,
+ NULL);
+
+ for (l = build_tool->priv->jobs->head; l != NULL; l = l->next)
+ {
+ LatexilaBuildJob *build_job = l->data;
+ LatexilaBuildJob *new_build_job = latexila_build_job_clone (build_job);
+
+ latexila_build_tool_add_job (new_build_tool, new_build_job);
+ g_object_unref (new_build_job);
+ }
+
+ return new_build_tool;
}
/**
@@ -396,11 +398,13 @@ latexila_build_tool_clone (LatexilaBuildTool *build_tool)
const gchar *
latexila_build_tool_get_description (LatexilaBuildTool *build_tool)
{
- if (build_tool->priv->description == NULL ||
- build_tool->priv->description[0] == '\0')
- return build_tool->priv->label;
+ if (build_tool->priv->description == NULL ||
+ build_tool->priv->description[0] == '\0')
+ {
+ return build_tool->priv->label;
+ }
- return build_tool->priv->description;
+ return build_tool->priv->description;
}
/**
@@ -412,16 +416,16 @@ latexila_build_tool_get_description (LatexilaBuildTool *build_tool)
*/
void
latexila_build_tool_add_job (LatexilaBuildTool *build_tool,
- LatexilaBuildJob *build_job)
+ LatexilaBuildJob *build_job)
{
- g_return_if_fail (LATEXILA_IS_BUILD_TOOL (build_tool));
- g_return_if_fail (LATEXILA_IS_BUILD_JOB (build_job));
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOL (build_tool));
+ g_return_if_fail (LATEXILA_IS_BUILD_JOB (build_job));
- /* The build tool can not be modified when it is running. */
- g_return_if_fail (build_tool->priv->running_tasks_count == 0);
+ /* The build tool can not be modified when it is running. */
+ g_return_if_fail (build_tool->priv->running_tasks_count == 0);
- g_queue_push_tail (build_tool->priv->jobs, build_job);
- g_object_ref (build_job);
+ g_queue_push_tail (build_tool->priv->jobs, build_job);
+ g_object_ref (build_job);
}
/**
@@ -434,9 +438,9 @@ latexila_build_tool_add_job (LatexilaBuildTool *build_tool,
GList *
latexila_build_tool_get_jobs (LatexilaBuildTool *build_tool)
{
- g_return_val_if_fail (LATEXILA_IS_BUILD_TOOL (build_tool), NULL);
+ g_return_val_if_fail (LATEXILA_IS_BUILD_TOOL (build_tool), NULL);
- return build_tool->priv->jobs->head;
+ return build_tool->priv->jobs->head;
}
/**
@@ -448,317 +452,325 @@ latexila_build_tool_get_jobs (LatexilaBuildTool *build_tool)
gchar *
latexila_build_tool_to_xml (LatexilaBuildTool *tool)
{
- GString *contents;
- gchar *escaped_text;
- GList *l;
+ GString *contents;
+ gchar *escaped_text;
+ GList *l;
- g_return_val_if_fail (LATEXILA_IS_BUILD_TOOL (tool), NULL);
+ g_return_val_if_fail (LATEXILA_IS_BUILD_TOOL (tool), NULL);
- contents = g_string_new (NULL);
+ contents = g_string_new (NULL);
- g_string_append_printf (contents,
- "\n <tool enabled=\"%s\" extensions=\"%s\" icon=\"%s\">\n",
- tool->priv->enabled ? "true" : "false",
- tool->priv->extensions != NULL ? tool->priv->extensions : "",
- tool->priv->icon != NULL ? tool->priv->icon : "");
+ g_string_append_printf (contents,
+ "\n <tool enabled=\"%s\" extensions=\"%s\" icon=\"%s\">\n",
+ tool->priv->enabled ? "true" : "false",
+ tool->priv->extensions != NULL ? tool->priv->extensions : "",
+ tool->priv->icon != NULL ? tool->priv->icon : "");
- escaped_text = g_markup_printf_escaped (" <label>%s</label>\n"
- " <description>%s</description>\n",
- tool->priv->label != NULL ? tool->priv->label : "",
- tool->priv->description != NULL ? tool->priv->description : "");
+ escaped_text = g_markup_printf_escaped (" <label>%s</label>\n"
+ " <description>%s</description>\n",
+ tool->priv->label != NULL ? tool->priv->label : "",
+ tool->priv->description != NULL ? tool->priv->description :
"");
- g_string_append (contents, escaped_text);
- g_free (escaped_text);
+ g_string_append (contents, escaped_text);
+ g_free (escaped_text);
- for (l = tool->priv->jobs->head; l != NULL; l = l->next)
- {
- LatexilaBuildJob *job = l->data;
+ for (l = tool->priv->jobs->head; l != NULL; l = l->next)
+ {
+ LatexilaBuildJob *job = l->data;
- escaped_text = latexila_build_job_to_xml (job);
- g_string_append (contents, escaped_text);
- g_free (escaped_text);
- }
+ escaped_text = latexila_build_job_to_xml (job);
+ g_string_append (contents, escaped_text);
+ g_free (escaped_text);
+ }
- escaped_text = g_markup_printf_escaped (" <open>%s</open>\n",
- tool->priv->files_to_open != NULL ? tool->priv->files_to_open :
"");
- g_string_append (contents, escaped_text);
- g_free (escaped_text);
+ escaped_text = g_markup_printf_escaped (" <open>%s</open>\n",
+ tool->priv->files_to_open != NULL ? tool->priv->files_to_open
: "");
+ g_string_append (contents, escaped_text);
+ g_free (escaped_text);
- g_string_append (contents, " </tool>\n");
+ g_string_append (contents, " </tool>\n");
- return g_string_free (contents, FALSE);
+ return g_string_free (contents, FALSE);
}
static void
failed (GTask *task)
{
- TaskData *data = g_task_get_task_data (task);
- GCancellable *cancellable;
- LatexilaBuildState state;
-
- cancellable = g_task_get_cancellable (task);
- if (g_cancellable_is_cancelled (cancellable))
- state = LATEXILA_BUILD_STATE_ABORTED;
- else
- state = LATEXILA_BUILD_STATE_FAILED;
-
- latexila_build_view_set_title_state (data->build_view,
- &data->main_title,
- state);
-
- g_task_return_boolean (task, FALSE);
- g_object_unref (task);
+ TaskData *data = g_task_get_task_data (task);
+ GCancellable *cancellable;
+ LatexilaBuildState state;
+
+ cancellable = g_task_get_cancellable (task);
+ if (g_cancellable_is_cancelled (cancellable))
+ {
+ state = LATEXILA_BUILD_STATE_ABORTED;
+ }
+ else
+ {
+ state = LATEXILA_BUILD_STATE_FAILED;
+ }
+
+ latexila_build_view_set_title_state (data->build_view,
+ &data->main_title,
+ state);
+
+ g_task_return_boolean (task, FALSE);
+ g_object_unref (task);
}
static void
query_exists_cb (GFile *file,
- GAsyncResult *result,
- GTask *task)
+ GAsyncResult *result,
+ GTask *task)
{
- TaskData *data = g_task_get_task_data (task);
- gboolean file_exists;
- GCancellable *cancellable;
- gchar *uri = NULL;
- GError *error = NULL;
+ TaskData *data = g_task_get_task_data (task);
+ gboolean file_exists;
+ GCancellable *cancellable;
+ gchar *uri = NULL;
+ GError *error = NULL;
- file_exists = latexila_utils_file_query_exists_finish (file, result);
+ file_exists = latexila_utils_file_query_exists_finish (file, result);
- cancellable = g_task_get_cancellable (task);
- if (g_cancellable_is_cancelled (cancellable))
- {
- latexila_build_view_set_title_state (data->build_view,
- &data->open_file_job_title,
- LATEXILA_BUILD_STATE_ABORTED);
- failed (task);
- goto out;
- }
+ cancellable = g_task_get_cancellable (task);
+ if (g_cancellable_is_cancelled (cancellable))
+ {
+ latexila_build_view_set_title_state (data->build_view,
+ &data->open_file_job_title,
+ LATEXILA_BUILD_STATE_ABORTED);
+ failed (task);
+ goto out;
+ }
- uri = g_file_get_uri (file);
+ uri = g_file_get_uri (file);
- if (!file_exists)
- {
- LatexilaBuildMsg *msg;
+ if (!file_exists)
+ {
+ LatexilaBuildMsg *msg;
- latexila_build_view_set_title_state (data->build_view,
- &data->open_file_job_title,
- LATEXILA_BUILD_STATE_FAILED);
+ latexila_build_view_set_title_state (data->build_view,
+ &data->open_file_job_title,
+ LATEXILA_BUILD_STATE_FAILED);
- msg = latexila_build_msg_new ();
- msg->text = g_strdup_printf (_("The file '%s' doesn't exist."), uri);
- msg->type = LATEXILA_BUILD_MSG_TYPE_ERROR;
+ msg = latexila_build_msg_new ();
+ msg->text = g_strdup_printf (_ ("The file '%s' doesn't exist."), uri);
+ msg->type = LATEXILA_BUILD_MSG_TYPE_ERROR;
- latexila_build_view_append_single_message (data->build_view,
- &data->open_file_job_title,
- msg);
+ latexila_build_view_append_single_message (data->build_view,
+ &data->open_file_job_title,
+ msg);
- latexila_build_msg_free (msg);
- failed (task);
- goto out;
- }
+ latexila_build_msg_free (msg);
+ failed (task);
+ goto out;
+ }
- /* Show URI */
+ /* Show URI */
- latexila_utils_show_uri (GTK_WIDGET (data->build_view),
- uri,
- GDK_CURRENT_TIME,
- &error);
+ latexila_utils_show_uri (GTK_WIDGET (data->build_view),
+ uri,
+ GDK_CURRENT_TIME,
+ &error);
- if (error != NULL)
- {
- LatexilaBuildMsg *msg;
+ if (error != NULL)
+ {
+ LatexilaBuildMsg *msg;
- latexila_build_view_set_title_state (data->build_view,
- &data->open_file_job_title,
- LATEXILA_BUILD_STATE_FAILED);
+ latexila_build_view_set_title_state (data->build_view,
+ &data->open_file_job_title,
+ LATEXILA_BUILD_STATE_FAILED);
- msg = latexila_build_msg_new ();
- msg->text = g_strdup_printf (_("Failed to open '%s':"), uri);
- msg->type = LATEXILA_BUILD_MSG_TYPE_ERROR;
+ msg = latexila_build_msg_new ();
+ msg->text = g_strdup_printf (_ ("Failed to open '%s':"), uri);
+ msg->type = LATEXILA_BUILD_MSG_TYPE_ERROR;
- latexila_build_view_append_single_message (data->build_view,
- &data->open_file_job_title,
- msg);
+ latexila_build_view_append_single_message (data->build_view,
+ &data->open_file_job_title,
+ msg);
- g_free (msg->text);
- msg->text = g_strdup (error->message);
- msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
+ g_free (msg->text);
+ msg->text = g_strdup (error->message);
+ msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
- latexila_build_view_append_single_message (data->build_view,
- &data->open_file_job_title,
- msg);
+ latexila_build_view_append_single_message (data->build_view,
+ &data->open_file_job_title,
+ msg);
- latexila_build_msg_free (msg);
- g_error_free (error);
+ latexila_build_msg_free (msg);
+ g_error_free (error);
- failed (task);
- goto out;
- }
+ failed (task);
+ goto out;
+ }
- latexila_build_view_set_title_state (data->build_view,
- &data->open_file_job_title,
- LATEXILA_BUILD_STATE_SUCCEEDED);
+ latexila_build_view_set_title_state (data->build_view,
+ &data->open_file_job_title,
+ LATEXILA_BUILD_STATE_SUCCEEDED);
- data->current_file_to_open++;
- open_file (task);
+ data->current_file_to_open++;
+ open_file (task);
out:
- g_object_unref (file);
- g_free (uri);
+ g_object_unref (file);
+ g_free (uri);
}
static void
open_file (GTask *task)
{
- TaskData *data = g_task_get_task_data (task);
- const gchar *file_to_open;
- gchar *filename;
- gchar *filename_for_display;
- gchar *shortname;
- gchar *shortname_for_display;
- gchar *uri;
- gchar *uri_for_display;
- gchar *basename;
- gchar *message;
- GFile *file;
-
- while (TRUE)
- {
- if (data->current_file_to_open == NULL ||
- data->current_file_to_open[0] == NULL)
- {
- /* Finished */
- latexila_build_view_set_title_state (data->build_view,
- &data->main_title,
- LATEXILA_BUILD_STATE_SUCCEEDED);
-
- g_task_return_boolean (task, TRUE);
- g_object_unref (task);
- return;
- }
-
- /* Check if the file to open is an empty string. It happens if there are
- * two contiguous spaces in priv->files_to_open for example.
- */
- if (data->current_file_to_open[0][0] == '\0')
- data->current_file_to_open++;
- else
- break;
- }
-
- file_to_open = data->current_file_to_open[0];
-
- /* Replace placeholders */
-
- filename = g_file_get_uri (data->file);
- filename_for_display = g_file_get_parse_name (data->file);
-
- shortname = latexila_utils_get_shortname (filename);
- shortname_for_display = latexila_utils_get_shortname (filename_for_display);
-
- if (strstr (file_to_open, "$filename") != NULL)
- {
- uri = latexila_utils_str_replace (file_to_open, "$filename", filename);
- uri_for_display = latexila_utils_str_replace (file_to_open, "$filename", filename_for_display);
- }
- else if (strstr (file_to_open, "$shortname") != NULL)
- {
- uri = latexila_utils_str_replace (file_to_open, "$shortname", shortname);
- uri_for_display = latexila_utils_str_replace (file_to_open, "$shortname", shortname_for_display);
- }
- else
- {
- uri = g_strdup_printf ("file://%s", file_to_open);
- uri_for_display = g_strdup (file_to_open);
- }
-
- /* Add job title in the build view */
-
- basename = g_path_get_basename (uri_for_display);
- message = g_strdup_printf (_("Open %s"), basename);
-
- data->open_file_job_title = latexila_build_view_add_job_title (data->build_view,
- message,
- LATEXILA_BUILD_STATE_RUNNING);
-
- /* Check if the file exists */
-
- file = g_file_new_for_uri (uri);
-
- latexila_utils_file_query_exists_async (file,
- g_task_get_cancellable (task),
- (GAsyncReadyCallback) query_exists_cb,
- task);
-
- g_free (filename);
- g_free (filename_for_display);
- g_free (shortname);
- g_free (shortname_for_display);
- g_free (uri);
- g_free (uri_for_display);
- g_free (basename);
- g_free (message);
+ TaskData *data = g_task_get_task_data (task);
+ const gchar *file_to_open;
+ gchar *filename;
+ gchar *filename_for_display;
+ gchar *shortname;
+ gchar *shortname_for_display;
+ gchar *uri;
+ gchar *uri_for_display;
+ gchar *basename;
+ gchar *message;
+ GFile *file;
+
+ while (TRUE)
+ {
+ if (data->current_file_to_open == NULL ||
+ data->current_file_to_open[0] == NULL)
+ {
+ /* Finished */
+ latexila_build_view_set_title_state (data->build_view,
+ &data->main_title,
+ LATEXILA_BUILD_STATE_SUCCEEDED);
+
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
+ return;
+ }
+
+ /* Check if the file to open is an empty string. It happens if there are
+ * two contiguous spaces in priv->files_to_open for example.
+ */
+ if (data->current_file_to_open[0][0] == '\0')
+ {
+ data->current_file_to_open++;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ file_to_open = data->current_file_to_open[0];
+
+ /* Replace placeholders */
+
+ filename = g_file_get_uri (data->file);
+ filename_for_display = g_file_get_parse_name (data->file);
+
+ shortname = latexila_utils_get_shortname (filename);
+ shortname_for_display = latexila_utils_get_shortname (filename_for_display);
+
+ if (strstr (file_to_open, "$filename") != NULL)
+ {
+ uri = latexila_utils_str_replace (file_to_open, "$filename", filename);
+ uri_for_display = latexila_utils_str_replace (file_to_open, "$filename",
filename_for_display);
+ }
+ else if (strstr (file_to_open, "$shortname") != NULL)
+ {
+ uri = latexila_utils_str_replace (file_to_open, "$shortname", shortname);
+ uri_for_display = latexila_utils_str_replace (file_to_open, "$shortname",
shortname_for_display);
+ }
+ else
+ {
+ uri = g_strdup_printf ("file://%s", file_to_open);
+ uri_for_display = g_strdup (file_to_open);
+ }
+
+ /* Add job title in the build view */
+
+ basename = g_path_get_basename (uri_for_display);
+ message = g_strdup_printf (_ ("Open %s"), basename);
+
+ data->open_file_job_title = latexila_build_view_add_job_title (data->build_view,
+ message,
+ LATEXILA_BUILD_STATE_RUNNING);
+
+ /* Check if the file exists */
+
+ file = g_file_new_for_uri (uri);
+
+ latexila_utils_file_query_exists_async (file,
+ g_task_get_cancellable (task),
+ (GAsyncReadyCallback) query_exists_cb,
+ task);
+
+ g_free (filename);
+ g_free (filename_for_display);
+ g_free (shortname);
+ g_free (shortname_for_display);
+ g_free (uri);
+ g_free (uri_for_display);
+ g_free (basename);
+ g_free (message);
}
static void
open_files (GTask *task)
{
- TaskData *data = g_task_get_task_data (task);
- LatexilaBuildTool *build_tool = g_task_get_source_object (task);
+ TaskData *data = g_task_get_task_data (task);
+ LatexilaBuildTool *build_tool = g_task_get_source_object (task);
- data->current_file_to_open = build_tool->priv->files_to_open_split;
- open_file (task);
+ data->current_file_to_open = build_tool->priv->files_to_open_split;
+ open_file (task);
}
static void
run_job_cb (LatexilaBuildJob *build_job,
- GAsyncResult *result,
- GTask *task)
+ GAsyncResult *result,
+ GTask *task)
{
- TaskData *data = g_task_get_task_data (task);
- gboolean success;
-
- data->job_results = g_slist_prepend (data->job_results,
- g_object_ref (result));
-
- success = latexila_build_job_run_finish (build_job, result);
-
- if (success)
- {
- data->current_job = data->current_job->next;
- run_job (task);
- }
- else
- {
- failed (task);
- }
+ TaskData *data = g_task_get_task_data (task);
+ gboolean success;
+
+ data->job_results = g_slist_prepend (data->job_results,
+ g_object_ref (result));
+
+ success = latexila_build_job_run_finish (build_job, result);
+
+ if (success)
+ {
+ data->current_job = data->current_job->next;
+ run_job (task);
+ }
+ else
+ {
+ failed (task);
+ }
}
static void
run_job (GTask *task)
{
- TaskData *data = g_task_get_task_data (task);
- LatexilaBuildJob *build_job;
-
- if (g_task_return_error_if_cancelled (task))
- {
- g_object_unref (task);
- return;
- }
-
- if (data->current_job == NULL)
- {
- open_files (task);
- return;
- }
-
- build_job = data->current_job->data;
-
- latexila_build_job_run_async (build_job,
- data->file,
- data->build_view,
- g_task_get_cancellable (task),
- (GAsyncReadyCallback) run_job_cb,
- task);
+ TaskData *data = g_task_get_task_data (task);
+ LatexilaBuildJob *build_job;
+
+ if (g_task_return_error_if_cancelled (task))
+ {
+ g_object_unref (task);
+ return;
+ }
+
+ if (data->current_job == NULL)
+ {
+ open_files (task);
+ return;
+ }
+
+ build_job = data->current_job->data;
+
+ latexila_build_job_run_async (build_job,
+ data->file,
+ data->build_view,
+ g_task_get_cancellable (task),
+ (GAsyncReadyCallback) run_job_cb,
+ task);
}
/**
@@ -774,36 +786,36 @@ run_job (GTask *task)
*/
void
latexila_build_tool_run_async (LatexilaBuildTool *build_tool,
- GFile *file,
- LatexilaBuildView *build_view,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ GFile *file,
+ LatexilaBuildView *build_view,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- GTask *task;
- TaskData *data;
+ GTask *task;
+ TaskData *data;
- g_return_if_fail (LATEXILA_IS_BUILD_TOOL (build_tool));
- g_return_if_fail (G_IS_FILE (file));
- g_return_if_fail (LATEXILA_IS_BUILD_VIEW (build_view));
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOL (build_tool));
+ g_return_if_fail (G_IS_FILE (file));
+ g_return_if_fail (LATEXILA_IS_BUILD_VIEW (build_view));
- task = g_task_new (build_tool, cancellable, callback, user_data);
- build_tool->priv->running_tasks_count++;
+ task = g_task_new (build_tool, cancellable, callback, user_data);
+ build_tool->priv->running_tasks_count++;
- data = task_data_new ();
- g_task_set_task_data (task, data, (GDestroyNotify) task_data_free);
+ data = task_data_new ();
+ g_task_set_task_data (task, data, (GDestroyNotify) task_data_free);
- data->file = g_object_ref (file);
- data->build_view = g_object_ref (build_view);
+ data->file = g_object_ref (file);
+ data->build_view = g_object_ref (build_view);
- latexila_build_view_clear (build_view);
+ latexila_build_view_clear (build_view);
- data->main_title = latexila_build_view_add_main_title (build_view,
- build_tool->priv->label,
- LATEXILA_BUILD_STATE_RUNNING);
+ data->main_title = latexila_build_view_add_main_title (build_view,
+ build_tool->priv->label,
+ LATEXILA_BUILD_STATE_RUNNING);
- data->current_job = build_tool->priv->jobs->head;
- run_job (task);
+ data->current_job = build_tool->priv->jobs->head;
+ run_job (task);
}
/**
@@ -819,23 +831,25 @@ latexila_build_tool_run_async (LatexilaBuildTool *build_tool,
*/
void
latexila_build_tool_run_finish (LatexilaBuildTool *build_tool,
- GAsyncResult *result)
+ GAsyncResult *result)
{
- GTask *task;
- TaskData *data;
- GCancellable *cancellable;
+ GTask *task;
+ TaskData *data;
+ GCancellable *cancellable;
- g_return_if_fail (g_task_is_valid (result, build_tool));
+ g_return_if_fail (g_task_is_valid (result, build_tool));
- task = G_TASK (result);
- data = g_task_get_task_data (task);
+ task = G_TASK (result);
+ data = g_task_get_task_data (task);
- cancellable = g_task_get_cancellable (task);
- if (g_cancellable_is_cancelled (cancellable))
- latexila_build_view_set_title_state (data->build_view,
- &data->main_title,
- LATEXILA_BUILD_STATE_ABORTED);
+ cancellable = g_task_get_cancellable (task);
+ if (g_cancellable_is_cancelled (cancellable))
+ {
+ latexila_build_view_set_title_state (data->build_view,
+ &data->main_title,
+ LATEXILA_BUILD_STATE_ABORTED);
+ }
- g_task_propagate_boolean (task, NULL);
- build_tool->priv->running_tasks_count--;
+ g_task_propagate_boolean (task, NULL);
+ build_tool->priv->running_tasks_count--;
}
diff --git a/src/liblatexila/latexila-build-tools-default.c b/src/liblatexila/latexila-build-tools-default.c
index b67b69d..b07ff90 100644
--- a/src/liblatexila/latexila-build-tools-default.c
+++ b/src/liblatexila/latexila-build-tools-default.c
@@ -39,32 +39,32 @@
struct _LatexilaBuildToolsDefaultPrivate
{
- gint something; /* not used, but the struct can not be empty */
+ gint something; /* not used, but the struct can not be empty */
};
G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildToolsDefault, latexila_build_tools_default,
LATEXILA_TYPE_BUILD_TOOLS)
static void
set_enabled_by_id (LatexilaBuildToolsDefault *build_tools,
- gint build_tool_id,
- gboolean enabled)
+ gint build_tool_id,
+ gboolean enabled)
{
- LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
- GList *l;
-
- for (l = build_tools_parent->build_tools; l != NULL; l = l->next)
- {
- LatexilaBuildTool *build_tool = l->data;
- gint id;
-
- g_object_get (build_tool, "id", &id, NULL);
-
- if (id == build_tool_id)
- {
- g_object_set (build_tool, "enabled", enabled, NULL);
- return;
- }
- }
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ GList *l;
+
+ for (l = build_tools_parent->build_tools; l != NULL; l = l->next)
+ {
+ LatexilaBuildTool *build_tool = l->data;
+ gint id;
+
+ g_object_get (build_tool, "id", &id, NULL);
+
+ if (id == build_tool_id)
+ {
+ g_object_set (build_tool, "enabled", enabled, NULL);
+ return;
+ }
+ }
}
/* Enable or disable the build tools.
@@ -77,129 +77,138 @@ set_enabled_by_id (LatexilaBuildToolsDefault *build_tools,
static void
load_settings (LatexilaBuildToolsDefault *build_tools)
{
- GSettings *settings;
- GVariant *tools;
- GVariantIter *iter;
- gint tool_id;
+ GSettings *settings;
+ GVariant *tools;
+ GVariantIter *iter;
+ gint tool_id;
- settings = g_settings_new ("org.gnome.gnome-latex.preferences.latex");
+ settings = g_settings_new ("org.gnome.gnome-latex.preferences.latex");
- tools = g_settings_get_value (settings, "enabled-default-build-tools");
- g_variant_get (tools, "ai", &iter);
+ tools = g_settings_get_value (settings, "enabled-default-build-tools");
+ g_variant_get (tools, "ai", &iter);
- while (g_variant_iter_loop (iter, "i", &tool_id))
- set_enabled_by_id (build_tools, tool_id, TRUE);
+ while (g_variant_iter_loop (iter, "i", &tool_id))
+ {
+ set_enabled_by_id (build_tools, tool_id, TRUE);
+ }
- g_variant_iter_free (iter);
- g_variant_unref (tools);
+ g_variant_iter_free (iter);
+ g_variant_unref (tools);
- tools = g_settings_get_value (settings, "disabled-default-build-tools");
- g_variant_get (tools, "ai", &iter);
+ tools = g_settings_get_value (settings, "disabled-default-build-tools");
+ g_variant_get (tools, "ai", &iter);
- while (g_variant_iter_loop (iter, "i", &tool_id))
- set_enabled_by_id (build_tools, tool_id, FALSE);
+ while (g_variant_iter_loop (iter, "i", &tool_id))
+ {
+ set_enabled_by_id (build_tools, tool_id, FALSE);
+ }
- g_variant_iter_free (iter);
- g_variant_unref (tools);
- g_object_unref (settings);
+ g_variant_iter_free (iter);
+ g_variant_unref (tools);
+ g_object_unref (settings);
}
static void
save_settings (LatexilaBuildToolsDefault *build_tools)
{
- LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
- GVariantBuilder builder_enabled;
- GVariantBuilder builder_disabled;
- GVariant *enabled_tools;
- GVariant *disabled_tools;
- GSettings *settings;
- GList *l;
-
- g_variant_builder_init (&builder_enabled, G_VARIANT_TYPE_ARRAY);
- g_variant_builder_init (&builder_disabled, G_VARIANT_TYPE_ARRAY);
-
- for (l = build_tools_parent->build_tools; l != NULL; l = l->next)
- {
- LatexilaBuildTool *build_tool = l->data;
- gboolean enabled;
- gint id;
-
- g_object_get (build_tool,
- "enabled", &enabled,
- "id", &id,
- NULL);
-
- if (enabled)
- g_variant_builder_add (&builder_enabled, "i", id);
- else
- g_variant_builder_add (&builder_disabled, "i", id);
- }
-
- enabled_tools = g_variant_builder_end (&builder_enabled);
- disabled_tools = g_variant_builder_end (&builder_disabled);
-
- settings = g_settings_new ("org.gnome.gnome-latex.preferences.latex");
- g_settings_set_value (settings, "enabled-default-build-tools", enabled_tools);
- g_settings_set_value (settings, "disabled-default-build-tools", disabled_tools);
-
- g_object_unref (settings);
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ GVariantBuilder builder_enabled;
+ GVariantBuilder builder_disabled;
+ GVariant *enabled_tools;
+ GVariant *disabled_tools;
+ GSettings *settings;
+ GList *l;
+
+ g_variant_builder_init (&builder_enabled, G_VARIANT_TYPE_ARRAY);
+ g_variant_builder_init (&builder_disabled, G_VARIANT_TYPE_ARRAY);
+
+ for (l = build_tools_parent->build_tools; l != NULL; l = l->next)
+ {
+ LatexilaBuildTool *build_tool = l->data;
+ gboolean enabled;
+ gint id;
+
+ g_object_get (build_tool,
+ "enabled", &enabled,
+ "id", &id,
+ NULL);
+
+ if (enabled)
+ {
+ g_variant_builder_add (&builder_enabled, "i", id);
+ }
+ else
+ {
+ g_variant_builder_add (&builder_disabled, "i", id);
+ }
+ }
+
+ enabled_tools = g_variant_builder_end (&builder_enabled);
+ disabled_tools = g_variant_builder_end (&builder_disabled);
+
+ settings = g_settings_new ("org.gnome.gnome-latex.preferences.latex");
+ g_settings_set_value (settings, "enabled-default-build-tools", enabled_tools);
+ g_settings_set_value (settings, "disabled-default-build-tools", disabled_tools);
+
+ g_object_unref (settings);
}
static void
latexila_build_tools_default_handle_not_found_error (LatexilaBuildTools *build_tools,
- GFile *xml_file,
- GError *error)
+ GFile *xml_file,
+ GError *error)
{
- gchar *path = g_file_get_parse_name (xml_file);
- g_warning ("XML file not found for the default build tools: %s", path);
- g_free (path);
+ gchar *path = g_file_get_parse_name (xml_file);
+
+ g_warning ("XML file not found for the default build tools: %s", path);
+ g_free (path);
}
static void
latexila_build_tools_default_class_init (LatexilaBuildToolsDefaultClass *klass)
{
- LatexilaBuildToolsClass *build_tools_class = LATEXILA_BUILD_TOOLS_CLASS (klass);
+ LatexilaBuildToolsClass *build_tools_class = LATEXILA_BUILD_TOOLS_CLASS (klass);
- build_tools_class->handle_not_found_error = latexila_build_tools_default_handle_not_found_error;
+ build_tools_class->handle_not_found_error = latexila_build_tools_default_handle_not_found_error;
}
static GFile *
get_xml_file (void)
{
- gchar *path;
- GFile *file;
+ gchar *path;
+ GFile *file;
- path = g_build_filename (DATA_DIR, "build_tools.xml", NULL);
- file = g_file_new_for_path (path);
- g_free (path);
+ path = g_build_filename (DATA_DIR, "build_tools.xml", NULL);
+ file = g_file_new_for_path (path);
+ g_free (path);
- return file;
+ return file;
}
static void
latexila_build_tools_default_init (LatexilaBuildToolsDefault *build_tools)
{
- GFile *xml_file;
-
- build_tools->priv = latexila_build_tools_default_get_instance_private (build_tools);
-
- /* load_settings() will be called directly after the file is loaded. So if
- * external code connects to the "loaded" signal too, normally the settings
- * will be loaded too.
- */
- g_signal_connect (build_tools,
- "loaded",
- G_CALLBACK (load_settings),
- NULL);
-
- g_signal_connect (build_tools,
- "modified",
- G_CALLBACK (save_settings),
- NULL);
-
- xml_file = get_xml_file ();
- latexila_build_tools_load (LATEXILA_BUILD_TOOLS (build_tools), xml_file);
- g_object_unref (xml_file);
+ GFile *xml_file;
+
+ build_tools->priv = latexila_build_tools_default_get_instance_private (build_tools);
+
+ /* load_settings() will be called directly after the file is loaded. So if
+ * external code connects to the "loaded" signal too, normally the settings
+ * will be loaded too.
+ */
+ g_signal_connect (build_tools,
+ "loaded",
+ G_CALLBACK (load_settings),
+ NULL);
+
+ g_signal_connect (build_tools,
+ "modified",
+ G_CALLBACK (save_settings),
+ NULL);
+
+ xml_file = get_xml_file ();
+ latexila_build_tools_load (LATEXILA_BUILD_TOOLS (build_tools), xml_file);
+ g_object_unref (xml_file);
}
/**
@@ -212,10 +221,12 @@ latexila_build_tools_default_init (LatexilaBuildToolsDefault *build_tools)
LatexilaBuildToolsDefault *
latexila_build_tools_default_get_instance (void)
{
- static LatexilaBuildToolsDefault *instance = NULL;
+ static LatexilaBuildToolsDefault *instance = NULL;
- if (instance == NULL)
- instance = g_object_new (LATEXILA_TYPE_BUILD_TOOLS_DEFAULT, NULL);
+ if (instance == NULL)
+ {
+ instance = g_object_new (LATEXILA_TYPE_BUILD_TOOLS_DEFAULT, NULL);
+ }
- return instance;
+ return instance;
}
diff --git a/src/liblatexila/latexila-build-tools-personal.c b/src/liblatexila/latexila-build-tools-personal.c
index daef58a..fcc34fa 100644
--- a/src/liblatexila/latexila-build-tools-personal.c
+++ b/src/liblatexila/latexila-build-tools-personal.c
@@ -34,10 +34,10 @@
struct _LatexilaBuildToolsPersonalPrivate
{
- /* Used for saving */
- GString *xml_file_contents;
+ /* Used for saving */
+ GString *xml_file_contents;
- guint modified : 1;
+ guint modified : 1;
};
G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildToolsPersonal, latexila_build_tools_personal,
LATEXILA_TYPE_BUILD_TOOLS)
@@ -45,63 +45,63 @@ G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildToolsPersonal, latexila_build_tools_per
static void
latexila_build_tools_personal_finalize (GObject *object)
{
- LatexilaBuildToolsPersonal *build_tools = LATEXILA_BUILD_TOOLS_PERSONAL (object);
+ LatexilaBuildToolsPersonal *build_tools = LATEXILA_BUILD_TOOLS_PERSONAL (object);
- if (build_tools->priv->xml_file_contents != NULL)
- {
- g_string_free (build_tools->priv->xml_file_contents, TRUE);
- build_tools->priv->xml_file_contents = NULL;
- }
+ if (build_tools->priv->xml_file_contents != NULL)
+ {
+ g_string_free (build_tools->priv->xml_file_contents, TRUE);
+ build_tools->priv->xml_file_contents = NULL;
+ }
- G_OBJECT_CLASS (latexila_build_tools_personal_parent_class)->finalize (object);
+ G_OBJECT_CLASS (latexila_build_tools_personal_parent_class)->finalize (object);
}
static void
latexila_build_tools_personal_class_init (LatexilaBuildToolsPersonalClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = latexila_build_tools_personal_finalize;
+ object_class->finalize = latexila_build_tools_personal_finalize;
}
static GFile *
get_xml_file (void)
{
- gchar *path;
- GFile *file;
+ gchar *path;
+ GFile *file;
- path = g_build_filename (g_get_user_config_dir (),
- "latexila",
- "build_tools.xml",
- NULL);
+ path = g_build_filename (g_get_user_config_dir (),
+ "latexila",
+ "build_tools.xml",
+ NULL);
- file = g_file_new_for_path (path);
- g_free (path);
+ file = g_file_new_for_path (path);
+ g_free (path);
- return file;
+ return file;
}
static void
modified_cb (LatexilaBuildToolsPersonal *build_tools)
{
- build_tools->priv->modified = TRUE;
+ build_tools->priv->modified = TRUE;
}
static void
latexila_build_tools_personal_init (LatexilaBuildToolsPersonal *build_tools)
{
- GFile *xml_file;
+ GFile *xml_file;
- build_tools->priv = latexila_build_tools_personal_get_instance_private (build_tools);
+ build_tools->priv = latexila_build_tools_personal_get_instance_private (build_tools);
- g_signal_connect (build_tools,
- "modified",
- G_CALLBACK (modified_cb),
- NULL);
+ g_signal_connect (build_tools,
+ "modified",
+ G_CALLBACK (modified_cb),
+ NULL);
- xml_file = get_xml_file ();
- latexila_build_tools_load (LATEXILA_BUILD_TOOLS (build_tools), xml_file);
- g_object_unref (xml_file);
+ xml_file = get_xml_file ();
+ latexila_build_tools_load (LATEXILA_BUILD_TOOLS (build_tools), xml_file);
+ g_object_unref (xml_file);
}
/**
@@ -114,39 +114,41 @@ latexila_build_tools_personal_init (LatexilaBuildToolsPersonal *build_tools)
LatexilaBuildToolsPersonal *
latexila_build_tools_personal_get_instance (void)
{
- static LatexilaBuildToolsPersonal *instance = NULL;
+ static LatexilaBuildToolsPersonal *instance = NULL;
- if (instance == NULL)
- instance = g_object_new (LATEXILA_TYPE_BUILD_TOOLS_PERSONAL, NULL);
+ if (instance == NULL)
+ {
+ instance = g_object_new (LATEXILA_TYPE_BUILD_TOOLS_PERSONAL, NULL);
+ }
- return instance;
+ return instance;
}
static void
save_cb (GFile *xml_file,
- GAsyncResult *result,
- LatexilaBuildToolsPersonal *build_tools)
+ GAsyncResult *result,
+ LatexilaBuildToolsPersonal *build_tools)
{
- GError *error = NULL;
-
- g_file_replace_contents_finish (xml_file, result, NULL, &error);
-
- if (error != NULL)
- {
- g_warning ("Error while saving the personal build tools: %s",
- error->message);
- g_error_free (error);
- }
- else
- {
- build_tools->priv->modified = FALSE;
- }
-
- g_string_free (build_tools->priv->xml_file_contents, TRUE);
- build_tools->priv->xml_file_contents = NULL;
-
- g_object_unref (build_tools);
- g_application_release (g_application_get_default ());
+ GError *error = NULL;
+
+ g_file_replace_contents_finish (xml_file, result, NULL, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Error while saving the personal build tools: %s",
+ error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ build_tools->priv->modified = FALSE;
+ }
+
+ g_string_free (build_tools->priv->xml_file_contents, TRUE);
+ build_tools->priv->xml_file_contents = NULL;
+
+ g_object_unref (build_tools);
+ g_application_release (g_application_get_default ());
}
/**
@@ -158,64 +160,66 @@ save_cb (GFile *xml_file,
void
latexila_build_tools_personal_save (LatexilaBuildToolsPersonal *build_tools)
{
- LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
- GString *contents;
- GList *cur_build_tool;
- GFile *xml_file;
- GError *error = NULL;
-
- g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
-
- if (!build_tools->priv->modified ||
- build_tools->priv->xml_file_contents != NULL)
- return;
-
- contents = g_string_new ("<tools>");
- build_tools->priv->xml_file_contents = contents;
-
- for (cur_build_tool = build_tools_parent->build_tools;
- cur_build_tool != NULL;
- cur_build_tool = cur_build_tool->next)
- {
- LatexilaBuildTool *build_tool = cur_build_tool->data;
- gchar *build_tool_xml = latexila_build_tool_to_xml (build_tool);
-
- g_string_append (contents, build_tool_xml);
- g_free (build_tool_xml);
- }
-
- g_string_append (contents, "</tools>\n");
-
- xml_file = get_xml_file ();
-
- latexila_utils_create_parent_directories (xml_file, &error);
-
- if (error == NULL)
- {
- /* Avoid finalization of build_tools during the async operation. And keep the
- * application running.
- */
- g_object_ref (build_tools);
- g_application_hold (g_application_get_default ());
-
- g_file_replace_contents_async (xml_file,
- contents->str,
- contents->len,
- NULL,
- TRUE, /* make a backup */
- G_FILE_CREATE_NONE,
- NULL,
- (GAsyncReadyCallback) save_cb,
- build_tools);
- }
- else
- {
- g_warning ("Error while saving the personal build tools: %s",
- error->message);
- g_error_free (error);
- }
-
- g_object_unref (xml_file);
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ GString *contents;
+ GList *cur_build_tool;
+ GFile *xml_file;
+ GError *error = NULL;
+
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
+
+ if (!build_tools->priv->modified ||
+ build_tools->priv->xml_file_contents != NULL)
+ {
+ return;
+ }
+
+ contents = g_string_new ("<tools>");
+ build_tools->priv->xml_file_contents = contents;
+
+ for (cur_build_tool = build_tools_parent->build_tools;
+ cur_build_tool != NULL;
+ cur_build_tool = cur_build_tool->next)
+ {
+ LatexilaBuildTool *build_tool = cur_build_tool->data;
+ gchar *build_tool_xml = latexila_build_tool_to_xml (build_tool);
+
+ g_string_append (contents, build_tool_xml);
+ g_free (build_tool_xml);
+ }
+
+ g_string_append (contents, "</tools>\n");
+
+ xml_file = get_xml_file ();
+
+ latexila_utils_create_parent_directories (xml_file, &error);
+
+ if (error == NULL)
+ {
+ /* Avoid finalization of build_tools during the async operation. And keep the
+ * application running.
+ */
+ g_object_ref (build_tools);
+ g_application_hold (g_application_get_default ());
+
+ g_file_replace_contents_async (xml_file,
+ contents->str,
+ contents->len,
+ NULL,
+ TRUE, /* make a backup */
+ G_FILE_CREATE_NONE,
+ NULL,
+ (GAsyncReadyCallback) save_cb,
+ build_tools);
+ }
+ else
+ {
+ g_warning ("Error while saving the personal build tools: %s",
+ error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (xml_file);
}
/**
@@ -227,29 +231,29 @@ latexila_build_tools_personal_save (LatexilaBuildToolsPersonal *build_tools)
*/
void
latexila_build_tools_personal_move_up (LatexilaBuildToolsPersonal *build_tools,
- guint tool_num)
+ guint tool_num)
{
- LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
- GList *node;
- GList *prev_node;
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ GList *node;
+ GList *prev_node;
- g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
- node = g_list_nth (build_tools_parent->build_tools, tool_num);
- g_return_if_fail (node != NULL);
+ node = g_list_nth (build_tools_parent->build_tools, tool_num);
+ g_return_if_fail (node != NULL);
- prev_node = node->prev;
- g_return_if_fail (prev_node != NULL);
+ prev_node = node->prev;
+ g_return_if_fail (prev_node != NULL);
- build_tools_parent->build_tools = g_list_remove_link (build_tools_parent->build_tools, node);
+ build_tools_parent->build_tools = g_list_remove_link (build_tools_parent->build_tools, node);
- build_tools_parent->build_tools = g_list_insert_before (build_tools_parent->build_tools,
- prev_node,
- node->data);
+ build_tools_parent->build_tools = g_list_insert_before (build_tools_parent->build_tools,
+ prev_node,
+ node->data);
- g_list_free (node);
+ g_list_free (node);
- g_signal_emit_by_name (build_tools, "modified");
+ g_signal_emit_by_name (build_tools, "modified");
}
/**
@@ -261,29 +265,29 @@ latexila_build_tools_personal_move_up (LatexilaBuildToolsPersonal *build_tools,
*/
void
latexila_build_tools_personal_move_down (LatexilaBuildToolsPersonal *build_tools,
- guint tool_num)
+ guint tool_num)
{
- LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
- GList *node;
- GList *next_node;
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ GList *node;
+ GList *next_node;
- g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
- node = g_list_nth (build_tools_parent->build_tools, tool_num);
- g_return_if_fail (node != NULL);
+ node = g_list_nth (build_tools_parent->build_tools, tool_num);
+ g_return_if_fail (node != NULL);
- next_node = node->next;
- g_return_if_fail (next_node != NULL);
+ next_node = node->next;
+ g_return_if_fail (next_node != NULL);
- build_tools_parent->build_tools = g_list_remove_link (build_tools_parent->build_tools, node);
+ build_tools_parent->build_tools = g_list_remove_link (build_tools_parent->build_tools, node);
- build_tools_parent->build_tools = g_list_insert_before (build_tools_parent->build_tools,
- next_node->next,
- node->data);
+ build_tools_parent->build_tools = g_list_insert_before (build_tools_parent->build_tools,
+ next_node->next,
+ node->data);
- g_list_free (node);
+ g_list_free (node);
- g_signal_emit_by_name (build_tools, "modified");
+ g_signal_emit_by_name (build_tools, "modified");
}
/**
@@ -295,21 +299,21 @@ latexila_build_tools_personal_move_down (LatexilaBuildToolsPersonal *build_tools
*/
void
latexila_build_tools_personal_delete (LatexilaBuildToolsPersonal *build_tools,
- guint tool_num)
+ guint tool_num)
{
- LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
- GList *node;
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ GList *node;
- g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
- node = g_list_nth (build_tools_parent->build_tools, tool_num);
- g_return_if_fail (node != NULL);
+ node = g_list_nth (build_tools_parent->build_tools, tool_num);
+ g_return_if_fail (node != NULL);
- build_tools_parent->build_tools = g_list_remove_link (build_tools_parent->build_tools, node);
+ build_tools_parent->build_tools = g_list_remove_link (build_tools_parent->build_tools, node);
- g_list_free_full (node, g_object_unref);
+ g_list_free_full (node, g_object_unref);
- g_signal_emit_by_name (build_tools, "modified");
+ g_signal_emit_by_name (build_tools, "modified");
}
/**
@@ -321,18 +325,18 @@ latexila_build_tools_personal_delete (LatexilaBuildToolsPersonal *build_tools,
*/
void
latexila_build_tools_personal_add (LatexilaBuildToolsPersonal *build_tools,
- LatexilaBuildTool *new_build_tool)
+ LatexilaBuildTool *new_build_tool)
{
- LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
- g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
- build_tools_parent->build_tools = g_list_append (build_tools_parent->build_tools,
- new_build_tool);
+ build_tools_parent->build_tools = g_list_append (build_tools_parent->build_tools,
+ new_build_tool);
- g_object_ref (new_build_tool);
+ g_object_ref (new_build_tool);
- g_signal_emit_by_name (build_tools, "modified");
+ g_signal_emit_by_name (build_tools, "modified");
}
/**
@@ -345,20 +349,20 @@ latexila_build_tools_personal_add (LatexilaBuildToolsPersonal *build_tools,
*/
void
latexila_build_tools_personal_insert (LatexilaBuildToolsPersonal *build_tools,
- LatexilaBuildTool *new_build_tool,
- guint position)
+ LatexilaBuildTool *new_build_tool,
+ guint position)
{
- LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
- g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
- build_tools_parent->build_tools = g_list_insert (build_tools_parent->build_tools,
- new_build_tool,
- position);
+ build_tools_parent->build_tools = g_list_insert (build_tools_parent->build_tools,
+ new_build_tool,
+ position);
- g_object_ref (new_build_tool);
+ g_object_ref (new_build_tool);
- g_signal_emit_by_name (build_tools, "modified");
+ g_signal_emit_by_name (build_tools, "modified");
}
/**
@@ -372,22 +376,22 @@ latexila_build_tools_personal_insert (LatexilaBuildToolsPersonal *build_tools,
*/
void
latexila_build_tools_personal_replace (LatexilaBuildToolsPersonal *build_tools,
- LatexilaBuildTool *new_build_tool,
- guint position)
+ LatexilaBuildTool *new_build_tool,
+ guint position)
{
- LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
- GList *node;
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ GList *node;
- g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
- node = g_list_nth (build_tools_parent->build_tools, position);
- g_return_if_fail (node != NULL);
+ node = g_list_nth (build_tools_parent->build_tools, position);
+ g_return_if_fail (node != NULL);
- if (node->data != new_build_tool)
- {
- g_object_unref (node->data);
- node->data = g_object_ref (new_build_tool);
+ if (node->data != new_build_tool)
+ {
+ g_object_unref (node->data);
+ node->data = g_object_ref (new_build_tool);
- g_signal_emit_by_name (build_tools, "modified");
- }
+ g_signal_emit_by_name (build_tools, "modified");
+ }
}
diff --git a/src/liblatexila/latexila-build-tools.c b/src/liblatexila/latexila-build-tools.c
index 1e70030..2a0e42f 100644
--- a/src/liblatexila/latexila-build-tools.c
+++ b/src/liblatexila/latexila-build-tools.c
@@ -40,16 +40,16 @@
struct _LatexilaBuildToolsPrivate
{
- /* Used during the XML file parsing to load the build tools. */
- LatexilaBuildTool *cur_tool;
- LatexilaBuildJob *cur_job;
+ /* Used during the XML file parsing to load the build tools. */
+ LatexilaBuildTool *cur_tool;
+ LatexilaBuildJob *cur_job;
};
enum
{
- SIGNAL_LOADED,
- SIGNAL_MODIFIED,
- LAST_SIGNAL
+ SIGNAL_LOADED,
+ SIGNAL_MODIFIED,
+ LAST_SIGNAL
};
G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildTools, latexila_build_tools, G_TYPE_OBJECT)
@@ -58,332 +58,350 @@ static guint signals[LAST_SIGNAL];
static void
latexila_build_tools_handle_not_found_error_default (LatexilaBuildTools *build_tools,
- GFile *xml_file,
- GError *error)
+ GFile *xml_file,
+ GError *error)
{
- /* Do nothing. If it is an error that the XML file doesn't exist, override
- * this vfunc to display an error message.
- * Another way would have been to add a property xml_file_must_exist or
- * something like that.
- * A class should not be aware of its subclasses, so explicit case analysis on
- * the type of the object is not a solution.
- */
+ /* Do nothing. If it is an error that the XML file doesn't exist, override
+ * this vfunc to display an error message.
+ * Another way would have been to add a property xml_file_must_exist or
+ * something like that.
+ * A class should not be aware of its subclasses, so explicit case analysis on
+ * the type of the object is not a solution.
+ */
}
static void
latexila_build_tools_dispose (GObject *object)
{
- LatexilaBuildTools *build_tools = LATEXILA_BUILD_TOOLS (object);
+ LatexilaBuildTools *build_tools = LATEXILA_BUILD_TOOLS (object);
- g_list_free_full (build_tools->build_tools, g_object_unref);
- build_tools->build_tools = NULL;
+ g_list_free_full (build_tools->build_tools, g_object_unref);
+ build_tools->build_tools = NULL;
- g_clear_object (&build_tools->priv->cur_tool);
- g_clear_object (&build_tools->priv->cur_job);
+ g_clear_object (&build_tools->priv->cur_tool);
+ g_clear_object (&build_tools->priv->cur_job);
- G_OBJECT_CLASS (latexila_build_tools_parent_class)->dispose (object);
+ G_OBJECT_CLASS (latexila_build_tools_parent_class)->dispose (object);
}
static void
latexila_build_tools_class_init (LatexilaBuildToolsClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = latexila_build_tools_dispose;
-
- klass->handle_not_found_error = latexila_build_tools_handle_not_found_error_default;
-
- /**
- * LatexilaBuildTools::loaded:
- * @build_tools: a #LatexilaBuildTools object.
- *
- * The ::loaded signal is emitted when the build tools are fully loaded.
- */
- signals[SIGNAL_LOADED] = g_signal_new ("loaded",
- LATEXILA_TYPE_BUILD_TOOLS,
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE, 0);
- /**
- * LatexilaBuildTools::modified:
- * @build_tools: a #LatexilaBuildTools object.
- *
- * The ::modified signal is emitted when a build tool is modified.
- */
- signals[SIGNAL_MODIFIED] = g_signal_new ("modified",
- LATEXILA_TYPE_BUILD_TOOLS,
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE, 0);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = latexila_build_tools_dispose;
+
+ klass->handle_not_found_error = latexila_build_tools_handle_not_found_error_default;
+
+ /**
+ * LatexilaBuildTools::loaded:
+ * @build_tools: a #LatexilaBuildTools object.
+ *
+ * The ::loaded signal is emitted when the build tools are fully loaded.
+ */
+ signals[SIGNAL_LOADED] = g_signal_new ("loaded",
+ LATEXILA_TYPE_BUILD_TOOLS,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
+ /**
+ * LatexilaBuildTools::modified:
+ * @build_tools: a #LatexilaBuildTools object.
+ *
+ * The ::modified signal is emitted when a build tool is modified.
+ */
+ signals[SIGNAL_MODIFIED] = g_signal_new ("modified",
+ LATEXILA_TYPE_BUILD_TOOLS,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
}
static void
latexila_build_tools_init (LatexilaBuildTools *build_tools)
{
- build_tools->priv = latexila_build_tools_get_instance_private (build_tools);
+ build_tools->priv = latexila_build_tools_get_instance_private (build_tools);
}
static void
parser_start_element (GMarkupParseContext *context,
- const gchar *element_name,
- const gchar **attribute_names,
- const gchar **attribute_values,
- gpointer user_data,
- GError **error)
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer user_data,
+ GError **error)
{
- LatexilaBuildTools *build_tools = user_data;
-
- if (g_str_equal (element_name, "tools") ||
- g_str_equal (element_name, "label") ||
- g_str_equal (element_name, "description") ||
- g_str_equal (element_name, "open"))
- {
- /* do nothing */
- }
-
- else if (g_str_equal (element_name, "tool"))
- {
- LatexilaBuildTool *cur_tool;
- gint i;
-
- g_clear_object (&build_tools->priv->cur_tool);
- cur_tool = latexila_build_tool_new ();
- build_tools->priv->cur_tool = cur_tool;
-
- for (i = 0; attribute_names[i] != NULL; i++)
- {
- if (g_str_equal (attribute_names[i], "id"))
- {
- gint id = g_strtod (attribute_values[i], NULL);
- g_object_set (cur_tool, "id", id, NULL);
- }
- /* "show" was the previous name of "enabled" */
- else if (g_str_equal (attribute_names[i], "show") ||
- g_str_equal (attribute_names[i], "enabled"))
- {
- gboolean enabled = g_str_equal (attribute_values[i], "true");
- g_object_set (cur_tool, "enabled", enabled, NULL);
- }
- else if (g_str_equal (attribute_names[i], "extensions"))
- {
- g_object_set (cur_tool, "extensions", attribute_values[i], NULL);
- }
- else if (g_str_equal (attribute_names[i], "icon"))
- {
- /* Migrate from GtkStock to icon-names. */
- if (g_str_equal (attribute_values[i], "gtk-execute"))
- g_object_set (cur_tool, "icon", "system-run", NULL);
- else if (g_str_equal (attribute_values[i], "gtk-file"))
- g_object_set (cur_tool, "icon", "text-x-generic", NULL);
-
- /* Migrate from old icon names specific to latexila. */
- else if (g_str_equal (attribute_values[i], "view_dvi"))
- g_object_set (cur_tool, "icon", "latexila-dvi", NULL);
- else if (g_str_equal (attribute_values[i], "view_pdf"))
- g_object_set (cur_tool, "icon", "latexila-pdf", NULL);
- else if (g_str_equal (attribute_values[i], "view_ps"))
- g_object_set (cur_tool, "icon", "latexila-ps", NULL);
-
- else
- g_object_set (cur_tool, "icon", attribute_values[i], NULL);
- }
- else if (error != NULL)
- {
- *error = g_error_new (G_MARKUP_ERROR,
- G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
- "unknown attribute \"%s\"",
- attribute_names[i]);
- }
- }
- }
-
- else if (g_str_equal (element_name, "job"))
- {
- LatexilaBuildJob *cur_job;
- gint i;
-
- g_clear_object (&build_tools->priv->cur_job);
- cur_job = latexila_build_job_new ();
- build_tools->priv->cur_job = cur_job;
-
- for (i = 0; attribute_names[i] != NULL; i++)
- {
- if (g_str_equal (attribute_names[i], "postProcessor"))
- {
- LatexilaPostProcessorType type;
-
- if (latexila_post_processor_get_type_from_name (attribute_values[i], &type))
- g_object_set (cur_job, "post-processor-type", type, NULL);
- else if (error != NULL)
- *error = g_error_new (G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- "unknown post processor \"%s\"",
- attribute_values[i]);
- }
-
- /* For compatibility (no longer used) */
- else if (g_str_equal (attribute_names[i], "mustSucceed"))
- {
- }
-
- else if (error != NULL)
- {
- *error = g_error_new (G_MARKUP_ERROR,
- G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
- "unknown attribute \"%s\"",
- attribute_names[i]);
- }
- }
- }
-
- else if (error != NULL)
- {
- *error = g_error_new (G_MARKUP_ERROR,
- G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "unknown element \"%s\"",
- element_name);
- }
+ LatexilaBuildTools *build_tools = user_data;
+
+ if (g_str_equal (element_name, "tools") ||
+ g_str_equal (element_name, "label") ||
+ g_str_equal (element_name, "description") ||
+ g_str_equal (element_name, "open"))
+ {
+ /* do nothing */
+ }
+ else if (g_str_equal (element_name, "tool"))
+ {
+ LatexilaBuildTool *cur_tool;
+ gint i;
+
+ g_clear_object (&build_tools->priv->cur_tool);
+ cur_tool = latexila_build_tool_new ();
+ build_tools->priv->cur_tool = cur_tool;
+
+ for (i = 0; attribute_names[i] != NULL; i++)
+ {
+ if (g_str_equal (attribute_names[i], "id"))
+ {
+ gint id = g_strtod (attribute_values[i], NULL);
+ g_object_set (cur_tool, "id", id, NULL);
+ }
+ /* "show" was the previous name of "enabled" */
+ else if (g_str_equal (attribute_names[i], "show") ||
+ g_str_equal (attribute_names[i], "enabled"))
+ {
+ gboolean enabled = g_str_equal (attribute_values[i], "true");
+ g_object_set (cur_tool, "enabled", enabled, NULL);
+ }
+ else if (g_str_equal (attribute_names[i], "extensions"))
+ {
+ g_object_set (cur_tool, "extensions", attribute_values[i], NULL);
+ }
+ else if (g_str_equal (attribute_names[i], "icon"))
+ {
+ /* Migrate from GtkStock to icon-names. */
+ if (g_str_equal (attribute_values[i], "gtk-execute"))
+ {
+ g_object_set (cur_tool, "icon", "system-run", NULL);
+ }
+ else if (g_str_equal (attribute_values[i], "gtk-file"))
+ {
+ g_object_set (cur_tool, "icon", "text-x-generic", NULL);
+ }
+ /* Migrate from old icon names specific to latexila. */
+ else if (g_str_equal (attribute_values[i], "view_dvi"))
+ {
+ g_object_set (cur_tool, "icon", "latexila-dvi", NULL);
+ }
+ else if (g_str_equal (attribute_values[i], "view_pdf"))
+ {
+ g_object_set (cur_tool, "icon", "latexila-pdf", NULL);
+ }
+ else if (g_str_equal (attribute_values[i], "view_ps"))
+ {
+ g_object_set (cur_tool, "icon", "latexila-ps", NULL);
+ }
+ else
+ {
+ g_object_set (cur_tool, "icon", attribute_values[i], NULL);
+ }
+ }
+ else if (error != NULL)
+ {
+ *error = g_error_new (G_MARKUP_ERROR,
+ G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
+ "unknown attribute \"%s\"",
+ attribute_names[i]);
+ }
+ }
+ }
+ else if (g_str_equal (element_name, "job"))
+ {
+ LatexilaBuildJob *cur_job;
+ gint i;
+
+ g_clear_object (&build_tools->priv->cur_job);
+ cur_job = latexila_build_job_new ();
+ build_tools->priv->cur_job = cur_job;
+
+ for (i = 0; attribute_names[i] != NULL; i++)
+ {
+ if (g_str_equal (attribute_names[i], "postProcessor"))
+ {
+ LatexilaPostProcessorType type;
+
+ if (latexila_post_processor_get_type_from_name (attribute_values[i], &type))
+ {
+ g_object_set (cur_job, "post-processor-type", type, NULL);
+ }
+ else if (error != NULL)
+ {
+ *error = g_error_new (G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ "unknown post processor \"%s\"",
+ attribute_values[i]);
+ }
+ }
+ /* For compatibility (no longer used) */
+ else if (g_str_equal (attribute_names[i], "mustSucceed"))
+ {
+ }
+ else if (error != NULL)
+ {
+ *error = g_error_new (G_MARKUP_ERROR,
+ G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
+ "unknown attribute \"%s\"",
+ attribute_names[i]);
+ }
+ }
+ }
+ else if (error != NULL)
+ {
+ *error = g_error_new (G_MARKUP_ERROR,
+ G_MARKUP_ERROR_UNKNOWN_ELEMENT,
+ "unknown element \"%s\"",
+ element_name);
+ }
}
static void
parser_end_element (GMarkupParseContext *context,
- const gchar *element_name,
- gpointer user_data,
- GError **error)
+ const gchar *element_name,
+ gpointer user_data,
+ GError **error)
{
- LatexilaBuildTools *build_tools = user_data;
-
- if (g_str_equal (element_name, "tools") ||
- g_str_equal (element_name, "label") ||
- g_str_equal (element_name, "description") ||
- g_str_equal (element_name, "open"))
- {
- /* do nothing */
- }
-
- else if (g_str_equal (element_name, "tool"))
- {
- build_tools->build_tools = g_list_prepend (build_tools->build_tools,
- build_tools->priv->cur_tool);
- build_tools->priv->cur_tool = NULL;
- }
-
- else if (g_str_equal (element_name, "job"))
- {
- latexila_build_tool_add_job (build_tools->priv->cur_tool,
- build_tools->priv->cur_job);
- build_tools->priv->cur_job = NULL;
- }
-
- else if (error != NULL)
- {
- *error = g_error_new (G_MARKUP_ERROR,
- G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "unknown element \"%s\"",
- element_name);
- }
+ LatexilaBuildTools *build_tools = user_data;
+
+ if (g_str_equal (element_name, "tools") ||
+ g_str_equal (element_name, "label") ||
+ g_str_equal (element_name, "description") ||
+ g_str_equal (element_name, "open"))
+ {
+ /* do nothing */
+ }
+ else if (g_str_equal (element_name, "tool"))
+ {
+ build_tools->build_tools = g_list_prepend (build_tools->build_tools,
+ build_tools->priv->cur_tool);
+ build_tools->priv->cur_tool = NULL;
+ }
+ else if (g_str_equal (element_name, "job"))
+ {
+ latexila_build_tool_add_job (build_tools->priv->cur_tool,
+ build_tools->priv->cur_job);
+ build_tools->priv->cur_job = NULL;
+ }
+ else if (error != NULL)
+ {
+ *error = g_error_new (G_MARKUP_ERROR,
+ G_MARKUP_ERROR_UNKNOWN_ELEMENT,
+ "unknown element \"%s\"",
+ element_name);
+ }
}
static void
parser_text (GMarkupParseContext *context,
- const gchar *text,
- gsize text_len,
- gpointer user_data,
- GError **error)
+ const gchar *text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error)
{
- LatexilaBuildTools *build_tools = user_data;
- const gchar *element_name = g_markup_parse_context_get_element (context);
- gchar *stripped_text = g_strndup (text, text_len);
- stripped_text = g_strstrip (stripped_text);
-
- if (g_str_equal (element_name, "job"))
- g_object_set (build_tools->priv->cur_job, "command", stripped_text, NULL);
-
- else if (g_str_equal (element_name, "label"))
- g_object_set (build_tools->priv->cur_tool, "label", _(stripped_text), NULL);
-
- else if (g_str_equal (element_name, "description"))
- g_object_set (build_tools->priv->cur_tool, "description", _(stripped_text), NULL);
-
- else if (g_str_equal (element_name, "open"))
- g_object_set (build_tools->priv->cur_tool, "files-to-open", stripped_text, NULL);
-
- g_free (stripped_text);
+ LatexilaBuildTools *build_tools = user_data;
+ const gchar *element_name = g_markup_parse_context_get_element (context);
+ gchar *stripped_text = g_strndup (text, text_len);
+
+ stripped_text = g_strstrip (stripped_text);
+
+ if (g_str_equal (element_name, "job"))
+ {
+ g_object_set (build_tools->priv->cur_job, "command", stripped_text, NULL);
+ }
+ else if (g_str_equal (element_name, "label"))
+ {
+ g_object_set (build_tools->priv->cur_tool, "label", _ (stripped_text), NULL);
+ }
+ else if (g_str_equal (element_name, "description"))
+ {
+ g_object_set (build_tools->priv->cur_tool, "description", _ (stripped_text), NULL);
+ }
+ else if (g_str_equal (element_name, "open"))
+ {
+ g_object_set (build_tools->priv->cur_tool, "files-to-open", stripped_text, NULL);
+ }
+
+ g_free (stripped_text);
}
static void
parse_contents (LatexilaBuildTools *build_tools,
- gchar *contents)
+ gchar *contents)
{
- GMarkupParser parser;
- GMarkupParseContext *context;
- GError *error = NULL;
-
- parser.start_element = parser_start_element;
- parser.end_element = parser_end_element;
- parser.text = parser_text;
- parser.passthrough = NULL;
- parser.error = NULL;
-
- context = g_markup_parse_context_new (&parser, 0, build_tools, NULL);
-
- g_markup_parse_context_parse (context, contents, -1, &error);
-
- if (error != NULL)
- {
- g_warning ("Error while parsing build tools: %s", error->message);
- g_error_free (error);
- error = NULL;
- goto out;
- }
-
- g_markup_parse_context_end_parse (context, &error);
-
- if (error != NULL)
- {
- g_warning ("Error while ending build tools parser: %s", error->message);
- g_error_free (error);
- error = NULL;
- goto out;
- }
+ GMarkupParser parser;
+ GMarkupParseContext *context;
+ GError *error = NULL;
+
+ parser.start_element = parser_start_element;
+ parser.end_element = parser_end_element;
+ parser.text = parser_text;
+ parser.passthrough = NULL;
+ parser.error = NULL;
+
+ context = g_markup_parse_context_new (&parser, 0, build_tools, NULL);
+
+ g_markup_parse_context_parse (context, contents, -1, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Error while parsing build tools: %s", error->message);
+ g_error_free (error);
+ error = NULL;
+ goto out;
+ }
+
+ g_markup_parse_context_end_parse (context, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Error while ending build tools parser: %s", error->message);
+ g_error_free (error);
+ error = NULL;
+ goto out;
+ }
out:
- build_tools->build_tools = g_list_reverse (build_tools->build_tools);
+ build_tools->build_tools = g_list_reverse (build_tools->build_tools);
- g_markup_parse_context_free (context);
- g_free (contents);
+ g_markup_parse_context_free (context);
+ g_free (contents);
- g_signal_emit (build_tools, signals[SIGNAL_LOADED], 0);
+ g_signal_emit (build_tools, signals[SIGNAL_LOADED], 0);
}
static void
load_contents_cb (GFile *xml_file,
- GAsyncResult *result,
- LatexilaBuildTools *build_tools)
+ GAsyncResult *result,
+ LatexilaBuildTools *build_tools)
{
- gchar *contents = NULL;
- GError *error = NULL;
-
- g_file_load_contents_finish (xml_file, result, &contents, NULL, NULL, &error);
-
- if (error != NULL)
- {
- if (error->domain == G_IO_ERROR &&
- error->code == G_IO_ERROR_NOT_FOUND)
- LATEXILA_BUILD_TOOLS_GET_CLASS (build_tools)->handle_not_found_error (build_tools,
- xml_file,
- error);
- else
- g_warning ("Error while loading the contents of the build tools XML file: %s",
- error->message);
-
- g_error_free (error);
- }
-
- if (contents != NULL)
- parse_contents (build_tools, contents);
-
- g_object_unref (build_tools);
+ gchar *contents = NULL;
+ GError *error = NULL;
+
+ g_file_load_contents_finish (xml_file, result, &contents, NULL, NULL, &error);
+
+ if (error != NULL)
+ {
+ if (error->domain == G_IO_ERROR &&
+ error->code == G_IO_ERROR_NOT_FOUND)
+ {
+ LATEXILA_BUILD_TOOLS_GET_CLASS (build_tools)->handle_not_found_error (build_tools,
+ xml_file,
+ error);
+ }
+ else
+ {
+ g_warning ("Error while loading the contents of the build tools XML file: %s",
+ error->message);
+ }
+
+ g_error_free (error);
+ }
+
+ if (contents != NULL)
+ {
+ parse_contents (build_tools, contents);
+ }
+
+ g_object_unref (build_tools);
}
/**
@@ -398,18 +416,18 @@ load_contents_cb (GFile *xml_file,
*/
void
latexila_build_tools_load (LatexilaBuildTools *build_tools,
- GFile *xml_file)
+ GFile *xml_file)
{
- g_return_if_fail (LATEXILA_IS_BUILD_TOOLS (build_tools));
- g_return_if_fail (G_IS_FILE (xml_file));
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS (build_tools));
+ g_return_if_fail (G_IS_FILE (xml_file));
- /* Avoid finalization of build_tools during the async operation. */
- g_object_ref (build_tools);
+ /* Avoid finalization of build_tools during the async operation. */
+ g_object_ref (build_tools);
- g_file_load_contents_async (xml_file,
- NULL,
- (GAsyncReadyCallback) load_contents_cb,
- build_tools);
+ g_file_load_contents_async (xml_file,
+ NULL,
+ (GAsyncReadyCallback) load_contents_cb,
+ build_tools);
}
/**
@@ -421,16 +439,16 @@ latexila_build_tools_load (LatexilaBuildTools *build_tools,
*/
LatexilaBuildTool *
latexila_build_tools_nth (LatexilaBuildTools *build_tools,
- guint tool_num)
+ guint tool_num)
{
- LatexilaBuildTool *build_tool;
+ LatexilaBuildTool *build_tool;
- g_return_val_if_fail (LATEXILA_IS_BUILD_TOOLS (build_tools), NULL);
+ g_return_val_if_fail (LATEXILA_IS_BUILD_TOOLS (build_tools), NULL);
- build_tool = g_list_nth_data (build_tools->build_tools, tool_num);
- g_return_val_if_fail (build_tool != NULL, NULL);
+ build_tool = g_list_nth_data (build_tools->build_tools, tool_num);
+ g_return_val_if_fail (build_tool != NULL, NULL);
- return build_tool;
+ return build_tool;
}
/**
@@ -441,13 +459,13 @@ latexila_build_tools_nth (LatexilaBuildTools *build_tools,
*/
void
latexila_build_tools_set_enabled (LatexilaBuildTools *build_tools,
- guint tool_num,
- gboolean enabled)
+ guint tool_num,
+ gboolean enabled)
{
- LatexilaBuildTool *build_tool = g_list_nth_data (build_tools->build_tools, tool_num);
+ LatexilaBuildTool *build_tool = g_list_nth_data (build_tools->build_tools, tool_num);
- g_return_if_fail (build_tool != NULL);
+ g_return_if_fail (build_tool != NULL);
- g_object_set (build_tool, "enabled", enabled, NULL);
- g_signal_emit (build_tools, signals[SIGNAL_MODIFIED], 0);
+ g_object_set (build_tool, "enabled", enabled, NULL);
+ g_signal_emit (build_tools, signals[SIGNAL_MODIFIED], 0);
}
diff --git a/src/liblatexila/latexila-build-view.c b/src/liblatexila/latexila-build-view.c
index 55e93e4..4e10b45 100644
--- a/src/liblatexila/latexila-build-view.c
+++ b/src/liblatexila/latexila-build-view.c
@@ -33,44 +33,44 @@
struct _LatexilaBuildViewPrivate
{
- GtkTreeStore *store;
- GtkTreeModelFilter *filtered_model;
+ GtkTreeStore *store;
+ GtkTreeModelFilter *filtered_model;
- guint show_warnings : 1;
- guint show_badboxes : 1;
- guint show_details : 1;
- guint has_details : 1;
+ guint show_warnings : 1;
+ guint show_badboxes : 1;
+ guint show_details : 1;
+ guint has_details : 1;
};
enum
{
- PROP_0,
- PROP_SHOW_WARNINGS,
- PROP_SHOW_BADBOXES,
- PROP_SHOW_DETAILS,
- PROP_HAS_DETAILS
+ PROP_0,
+ PROP_SHOW_WARNINGS,
+ PROP_SHOW_BADBOXES,
+ PROP_SHOW_DETAILS,
+ PROP_HAS_DETAILS
};
/* Columns for the GtkTreeView */
enum
{
- COLUMN_ICON,
- COLUMN_MESSAGE,
- COLUMN_MESSAGE_TYPE,
- COLUMN_WEIGHT,
- COLUMN_BASENAME,
- COLUMN_PATH,
- COLUMN_FILE,
- COLUMN_START_LINE,
- COLUMN_END_LINE,
- COLUMN_LINE_STR,
- NB_COLUMNS
+ COLUMN_ICON,
+ COLUMN_MESSAGE,
+ COLUMN_MESSAGE_TYPE,
+ COLUMN_WEIGHT,
+ COLUMN_BASENAME,
+ COLUMN_PATH,
+ COLUMN_FILE,
+ COLUMN_START_LINE,
+ COLUMN_END_LINE,
+ COLUMN_LINE_STR,
+ NB_COLUMNS
};
enum
{
- SIGNAL_JUMP_TO_FILE,
- LAST_SIGNAL
+ SIGNAL_JUMP_TO_FILE,
+ LAST_SIGNAL
};
G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildView, latexila_build_view, GTK_TYPE_TREE_VIEW)
@@ -86,16 +86,16 @@ static guint signals[LAST_SIGNAL];
void
latexila_build_msg_reinit (LatexilaBuildMsg *build_msg)
{
- g_assert (build_msg != NULL);
+ g_assert (build_msg != NULL);
- g_free (build_msg->text);
- g_free (build_msg->filename);
+ g_free (build_msg->text);
+ g_free (build_msg->filename);
- memset (build_msg, 0, sizeof (LatexilaBuildMsg));
+ memset (build_msg, 0, sizeof (LatexilaBuildMsg));
- build_msg->start_line = -1;
- build_msg->end_line = -1;
- build_msg->expand = TRUE;
+ build_msg->start_line = -1;
+ build_msg->end_line = -1;
+ build_msg->expand = TRUE;
}
/**
@@ -108,15 +108,15 @@ latexila_build_msg_reinit (LatexilaBuildMsg *build_msg)
LatexilaBuildMsg *
latexila_build_msg_new (void)
{
- LatexilaBuildMsg *build_msg;
+ LatexilaBuildMsg *build_msg;
- build_msg = g_slice_new0 (LatexilaBuildMsg);
+ build_msg = g_slice_new0 (LatexilaBuildMsg);
- build_msg->start_line = -1;
- build_msg->end_line = -1;
- build_msg->expand = TRUE;
+ build_msg->start_line = -1;
+ build_msg->end_line = -1;
+ build_msg->expand = TRUE;
- return build_msg;
+ return build_msg;
}
/**
@@ -128,16 +128,18 @@ latexila_build_msg_new (void)
void
latexila_build_msg_free (LatexilaBuildMsg *build_msg)
{
- if (build_msg != NULL)
- {
- g_free (build_msg->text);
- g_free (build_msg->filename);
-
- if (build_msg->children != NULL)
- g_queue_free_full (build_msg->children, (GDestroyNotify) latexila_build_msg_free);
-
- g_slice_free (LatexilaBuildMsg, build_msg);
- }
+ if (build_msg != NULL)
+ {
+ g_free (build_msg->text);
+ g_free (build_msg->filename);
+
+ if (build_msg->children != NULL)
+ {
+ g_queue_free_full (build_msg->children, (GDestroyNotify) latexila_build_msg_free);
+ }
+
+ g_slice_free (LatexilaBuildMsg, build_msg);
+ }
}
/**
@@ -149,436 +151,450 @@ latexila_build_msg_free (LatexilaBuildMsg *build_msg)
void
latexila_build_msg_print (LatexilaBuildMsg *build_msg)
{
- GEnumClass *enum_class;
- GEnumValue *enum_value;
-
- enum_class = g_type_class_ref (LATEXILA_TYPE_BUILD_MSG_TYPE);
- enum_value = g_enum_get_value (enum_class, build_msg->type);
-
- g_print ("Build message:\n");
- g_print ("\ttype: %s\n", enum_value->value_nick);
- g_print ("\ttext: %s\n", build_msg->text);
- g_print ("\tfilename: %s\n", build_msg->filename);
- g_print ("\tstart line: %d\n", build_msg->start_line);
- g_print ("\tend line: %d\n", build_msg->end_line);
- g_print ("\texpand: %d\n", build_msg->expand);
- g_print ("\n");
-
- g_type_class_unref (enum_class);
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+
+ enum_class = g_type_class_ref (LATEXILA_TYPE_BUILD_MSG_TYPE);
+ enum_value = g_enum_get_value (enum_class, build_msg->type);
+
+ g_print ("Build message:\n");
+ g_print ("\ttype: %s\n", enum_value->value_nick);
+ g_print ("\ttext: %s\n", build_msg->text);
+ g_print ("\tfilename: %s\n", build_msg->filename);
+ g_print ("\tstart line: %d\n", build_msg->start_line);
+ g_print ("\tend line: %d\n", build_msg->end_line);
+ g_print ("\texpand: %d\n", build_msg->expand);
+ g_print ("\n");
+
+ g_type_class_unref (enum_class);
}
static const gchar *
get_icon_name_from_state (LatexilaBuildState state)
{
- switch (state)
- {
- case LATEXILA_BUILD_STATE_RUNNING:
- return "system-run";
-
- case LATEXILA_BUILD_STATE_SUCCEEDED:
- /* This stock item doesn't have an icon name replacement, but the stock-id
- * works fine. For GTK+ 4 it will probably be removed, so we can copy the
- * icon in the latexila sources.
- */
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- return GTK_STOCK_APPLY;
- G_GNUC_END_IGNORE_DEPRECATIONS
-
- case LATEXILA_BUILD_STATE_FAILED:
- return "dialog-error";
-
- case LATEXILA_BUILD_STATE_ABORTED:
- return "process-stop";
-
- default:
- g_return_val_if_reached (NULL);
- }
+ switch (state)
+ {
+ case LATEXILA_BUILD_STATE_RUNNING:
+ return "system-run";
+
+ case LATEXILA_BUILD_STATE_SUCCEEDED:
+ /* This stock item doesn't have an icon name replacement, but the stock-id
+ * works fine. For GTK+ 4 it will probably be removed, so we can copy the
+ * icon in the latexila sources.
+ */
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+ return GTK_STOCK_APPLY;
+ G_GNUC_END_IGNORE_DEPRECATIONS
+
+ case LATEXILA_BUILD_STATE_FAILED:
+ return "dialog-error";
+
+ case LATEXILA_BUILD_STATE_ABORTED:
+ return "process-stop";
+
+ default:
+ g_return_val_if_reached (NULL);
+ }
}
static const gchar *
get_icon_name_from_msg_type (LatexilaBuildMsgType type)
{
- switch (type)
- {
- case LATEXILA_BUILD_MSG_TYPE_JOB_SUB_COMMAND:
- return "gray-square";
-
- case LATEXILA_BUILD_MSG_TYPE_ERROR:
- return "dialog-error";
-
- case LATEXILA_BUILD_MSG_TYPE_WARNING:
- return "dialog-warning";
-
- case LATEXILA_BUILD_MSG_TYPE_BADBOX:
- return "badbox";
-
- case LATEXILA_BUILD_MSG_TYPE_MAIN_TITLE:
- case LATEXILA_BUILD_MSG_TYPE_JOB_TITLE:
- case LATEXILA_BUILD_MSG_TYPE_INFO:
- default:
- return NULL;
- }
+ switch (type)
+ {
+ case LATEXILA_BUILD_MSG_TYPE_JOB_SUB_COMMAND:
+ return "gray-square";
+
+ case LATEXILA_BUILD_MSG_TYPE_ERROR:
+ return "dialog-error";
+
+ case LATEXILA_BUILD_MSG_TYPE_WARNING:
+ return "dialog-warning";
+
+ case LATEXILA_BUILD_MSG_TYPE_BADBOX:
+ return "badbox";
+
+ case LATEXILA_BUILD_MSG_TYPE_MAIN_TITLE:
+ case LATEXILA_BUILD_MSG_TYPE_JOB_TITLE:
+ case LATEXILA_BUILD_MSG_TYPE_INFO:
+ default:
+ return NULL;
+ }
}
static void
latexila_build_view_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- LatexilaBuildView *build_view = LATEXILA_BUILD_VIEW (object);
-
- switch (prop_id)
- {
- case PROP_SHOW_WARNINGS:
- g_value_set_boolean (value, build_view->priv->show_warnings);
- break;
-
- case PROP_SHOW_BADBOXES:
- g_value_set_boolean (value, build_view->priv->show_badboxes);
- break;
-
- case PROP_SHOW_DETAILS:
- g_value_set_boolean (value, build_view->priv->show_details);
- break;
-
- case PROP_HAS_DETAILS:
- g_value_set_boolean (value, build_view->priv->has_details);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ LatexilaBuildView *build_view = LATEXILA_BUILD_VIEW (object);
+
+ switch (prop_id)
+ {
+ case PROP_SHOW_WARNINGS:
+ g_value_set_boolean (value, build_view->priv->show_warnings);
+ break;
+
+ case PROP_SHOW_BADBOXES:
+ g_value_set_boolean (value, build_view->priv->show_badboxes);
+ break;
+
+ case PROP_SHOW_DETAILS:
+ g_value_set_boolean (value, build_view->priv->show_details);
+ break;
+
+ case PROP_HAS_DETAILS:
+ g_value_set_boolean (value, build_view->priv->has_details);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
latexila_build_view_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- LatexilaBuildView *build_view = LATEXILA_BUILD_VIEW (object);
-
- switch (prop_id)
- {
- case PROP_SHOW_WARNINGS:
- build_view->priv->show_warnings = g_value_get_boolean (value);
-
- if (build_view->priv->filtered_model != NULL)
- gtk_tree_model_filter_refilter (build_view->priv->filtered_model);
- break;
-
- case PROP_SHOW_BADBOXES:
- build_view->priv->show_badboxes = g_value_get_boolean (value);
-
- if (build_view->priv->filtered_model != NULL)
- gtk_tree_model_filter_refilter (build_view->priv->filtered_model);
- break;
-
- case PROP_SHOW_DETAILS:
- build_view->priv->show_details = g_value_get_boolean (value);
- break;
-
- case PROP_HAS_DETAILS:
- build_view->priv->has_details = g_value_get_boolean (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ LatexilaBuildView *build_view = LATEXILA_BUILD_VIEW (object);
+
+ switch (prop_id)
+ {
+ case PROP_SHOW_WARNINGS:
+ build_view->priv->show_warnings = g_value_get_boolean (value);
+
+ if (build_view->priv->filtered_model != NULL)
+ {
+ gtk_tree_model_filter_refilter (build_view->priv->filtered_model);
+ }
+ break;
+
+ case PROP_SHOW_BADBOXES:
+ build_view->priv->show_badboxes = g_value_get_boolean (value);
+
+ if (build_view->priv->filtered_model != NULL)
+ {
+ gtk_tree_model_filter_refilter (build_view->priv->filtered_model);
+ }
+ break;
+
+ case PROP_SHOW_DETAILS:
+ build_view->priv->show_details = g_value_get_boolean (value);
+ break;
+
+ case PROP_HAS_DETAILS:
+ build_view->priv->has_details = g_value_get_boolean (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
latexila_build_view_dispose (GObject *object)
{
- LatexilaBuildView *build_view = LATEXILA_BUILD_VIEW (object);
+ LatexilaBuildView *build_view = LATEXILA_BUILD_VIEW (object);
- g_clear_object (&build_view->priv->store);
- g_clear_object (&build_view->priv->filtered_model);
+ g_clear_object (&build_view->priv->store);
+ g_clear_object (&build_view->priv->filtered_model);
- G_OBJECT_CLASS (latexila_build_view_parent_class)->dispose (object);
+ G_OBJECT_CLASS (latexila_build_view_parent_class)->dispose (object);
}
static void
latexila_build_view_class_init (LatexilaBuildViewClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = latexila_build_view_get_property;
- object_class->set_property = latexila_build_view_set_property;
- object_class->dispose = latexila_build_view_dispose;
-
- g_object_class_install_property (object_class,
- PROP_SHOW_WARNINGS,
- g_param_spec_boolean ("show-warnings",
- "Show warnings",
- "",
- TRUE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class,
- PROP_SHOW_BADBOXES,
- g_param_spec_boolean ("show-badboxes",
- "Show badboxes",
- "",
- TRUE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class,
- PROP_SHOW_DETAILS,
- g_param_spec_boolean ("show-details",
- "Show details",
- "",
- FALSE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class,
- PROP_HAS_DETAILS,
- g_param_spec_boolean ("has-details",
- "Has details",
- "",
- FALSE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * LatexilaBuildView::jump-to-file:
- * @build_view: a #LatexilaBuildView.
- * @file: the file to open.
- * @start_line: the start of the selection, counting from 0. Or -1 if unset.
- * @end_line: the end of the selection, counting from 0. Or -1 if unset.
- *
- * The ::jump-to-file signal is emitted when a row in the build view is
- * selected. The row must contain a file, otherwise the signal is not emitted.
- * The file should be opened and presented to the user. If @start_line and
- * @end_line are not -1, jump to the @start_line and select those lines. If
- * @start_line is provided, @end_line is also provided (different than -1).
- *
- * The selection should stop at the end of @end_line (not at the start of
- * @end_line).
- */
- signals[SIGNAL_JUMP_TO_FILE] = g_signal_new ("jump-to-file",
- LATEXILA_TYPE_BUILD_VIEW,
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE,
- 3,
- G_TYPE_FILE,
- G_TYPE_INT,
- G_TYPE_INT);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = latexila_build_view_get_property;
+ object_class->set_property = latexila_build_view_set_property;
+ object_class->dispose = latexila_build_view_dispose;
+
+ g_object_class_install_property (object_class,
+ PROP_SHOW_WARNINGS,
+ g_param_spec_boolean ("show-warnings",
+ "Show warnings",
+ "",
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_SHOW_BADBOXES,
+ g_param_spec_boolean ("show-badboxes",
+ "Show badboxes",
+ "",
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_SHOW_DETAILS,
+ g_param_spec_boolean ("show-details",
+ "Show details",
+ "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_HAS_DETAILS,
+ g_param_spec_boolean ("has-details",
+ "Has details",
+ "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * LatexilaBuildView::jump-to-file:
+ * @build_view: a #LatexilaBuildView.
+ * @file: the file to open.
+ * @start_line: the start of the selection, counting from 0. Or -1 if unset.
+ * @end_line: the end of the selection, counting from 0. Or -1 if unset.
+ *
+ * The ::jump-to-file signal is emitted when a row in the build view is
+ * selected. The row must contain a file, otherwise the signal is not emitted.
+ * The file should be opened and presented to the user. If @start_line and
+ * @end_line are not -1, jump to the @start_line and select those lines. If
+ * @start_line is provided, @end_line is also provided (different than -1).
+ *
+ * The selection should stop at the end of @end_line (not at the start of
+ * @end_line).
+ */
+ signals[SIGNAL_JUMP_TO_FILE] = g_signal_new ("jump-to-file",
+ LATEXILA_TYPE_BUILD_VIEW,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE,
+ 3,
+ G_TYPE_FILE,
+ G_TYPE_INT,
+ G_TYPE_INT);
}
static gboolean
visible_func (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data)
+ GtkTreeIter *iter,
+ gpointer user_data)
{
- LatexilaBuildMsgType msg_type;
- LatexilaBuildView *build_view = user_data;
-
- gtk_tree_model_get (model, iter,
- COLUMN_MESSAGE_TYPE, &msg_type,
- -1);
-
- switch (msg_type)
- {
- case LATEXILA_BUILD_MSG_TYPE_WARNING:
- return build_view->priv->show_warnings;
-
- case LATEXILA_BUILD_MSG_TYPE_BADBOX:
- return build_view->priv->show_badboxes;
-
- case LATEXILA_BUILD_MSG_TYPE_MAIN_TITLE:
- case LATEXILA_BUILD_MSG_TYPE_JOB_TITLE:
- case LATEXILA_BUILD_MSG_TYPE_JOB_SUB_COMMAND:
- case LATEXILA_BUILD_MSG_TYPE_ERROR:
- case LATEXILA_BUILD_MSG_TYPE_INFO:
- default:
- return TRUE;
- }
+ LatexilaBuildMsgType msg_type;
+ LatexilaBuildView *build_view = user_data;
+
+ gtk_tree_model_get (model, iter,
+ COLUMN_MESSAGE_TYPE, &msg_type,
+ -1);
+
+ switch (msg_type)
+ {
+ case LATEXILA_BUILD_MSG_TYPE_WARNING:
+ return build_view->priv->show_warnings;
+
+ case LATEXILA_BUILD_MSG_TYPE_BADBOX:
+ return build_view->priv->show_badboxes;
+
+ case LATEXILA_BUILD_MSG_TYPE_MAIN_TITLE:
+ case LATEXILA_BUILD_MSG_TYPE_JOB_TITLE:
+ case LATEXILA_BUILD_MSG_TYPE_JOB_SUB_COMMAND:
+ case LATEXILA_BUILD_MSG_TYPE_ERROR:
+ case LATEXILA_BUILD_MSG_TYPE_INFO:
+ default:
+ return TRUE;
+ }
}
static void
init_tree_models (LatexilaBuildView *build_view)
{
- g_assert (build_view->priv->store == NULL);
-
- build_view->priv->store = gtk_tree_store_new (NB_COLUMNS,
- G_TYPE_STRING, /* icon name */
- G_TYPE_STRING, /* message */
- LATEXILA_TYPE_BUILD_MSG_TYPE,
- G_TYPE_INT, /* weight (normal or bold) */
- G_TYPE_STRING, /* basename */
- G_TYPE_STRING, /* path */
- G_TYPE_FILE,
- G_TYPE_INT, /* start line */
- G_TYPE_INT, /* end line */
- G_TYPE_STRING); /* line (same as start line but for
display) */
-
- build_view->priv->filtered_model = GTK_TREE_MODEL_FILTER (
- gtk_tree_model_filter_new (GTK_TREE_MODEL (build_view->priv->store), NULL));
-
- gtk_tree_model_filter_set_visible_func (build_view->priv->filtered_model,
- visible_func,
- build_view,
- NULL);
+ g_assert (build_view->priv->store == NULL);
+
+ build_view->priv->store = gtk_tree_store_new (NB_COLUMNS,
+ G_TYPE_STRING, /* icon name */
+ G_TYPE_STRING, /* message */
+ LATEXILA_TYPE_BUILD_MSG_TYPE,
+ G_TYPE_INT, /* weight (normal or bold) */
+ G_TYPE_STRING, /* basename */
+ G_TYPE_STRING, /* path */
+ G_TYPE_FILE,
+ G_TYPE_INT, /* start line */
+ G_TYPE_INT, /* end line */
+ G_TYPE_STRING); /* line (same as start line but for
display) */
+
+ build_view->priv->filtered_model = GTK_TREE_MODEL_FILTER (
+ gtk_tree_model_filter_new (GTK_TREE_MODEL (build_view->priv->store), NULL));
+
+ gtk_tree_model_filter_set_visible_func (build_view->priv->filtered_model,
+ visible_func,
+ build_view,
+ NULL);
}
/* Returns TRUE to select the row. */
static gboolean
select_row (LatexilaBuildView *build_view,
- GtkTreeModel *model,
- GtkTreePath *path)
+ GtkTreeModel *model,
+ GtkTreePath *path)
{
- GtkTreeView *tree_view = GTK_TREE_VIEW (build_view);
- GtkTreeIter iter;
- GFile *file;
- gint start_line;
- gint end_line;
-
- if (!gtk_tree_model_get_iter (model, &iter, path))
- return FALSE;
-
- if (gtk_tree_model_iter_has_child (model, &iter))
- {
- if (gtk_tree_view_row_expanded (tree_view, path))
- gtk_tree_view_collapse_row (tree_view, path);
- else
- gtk_tree_view_expand_to_path (tree_view, path);
-
- return FALSE;
- }
-
- gtk_tree_model_get (model, &iter,
- COLUMN_FILE, &file,
- COLUMN_START_LINE, &start_line,
- COLUMN_END_LINE, &end_line,
- -1);
-
- /* For the signal, we count from 0. */
- if (start_line > 0)
- start_line--;
-
- if (end_line > 0)
- end_line--;
-
- if (file != NULL)
- {
- g_signal_emit (build_view,
- signals[SIGNAL_JUMP_TO_FILE],
- 0,
- file,
- start_line,
- end_line);
-
- g_object_unref (file);
- }
-
- /* Select the row, so the user can copy/paste its contents. */
- return TRUE;
+ GtkTreeView *tree_view = GTK_TREE_VIEW (build_view);
+ GtkTreeIter iter;
+ GFile *file;
+ gint start_line;
+ gint end_line;
+
+ if (!gtk_tree_model_get_iter (model, &iter, path))
+ {
+ return FALSE;
+ }
+
+ if (gtk_tree_model_iter_has_child (model, &iter))
+ {
+ if (gtk_tree_view_row_expanded (tree_view, path))
+ {
+ gtk_tree_view_collapse_row (tree_view, path);
+ }
+ else
+ {
+ gtk_tree_view_expand_to_path (tree_view, path);
+ }
+
+ return FALSE;
+ }
+
+ gtk_tree_model_get (model, &iter,
+ COLUMN_FILE, &file,
+ COLUMN_START_LINE, &start_line,
+ COLUMN_END_LINE, &end_line,
+ -1);
+
+ /* For the signal, we count from 0. */
+ if (start_line > 0)
+ {
+ start_line--;
+ }
+
+ if (end_line > 0)
+ {
+ end_line--;
+ }
+
+ if (file != NULL)
+ {
+ g_signal_emit (build_view,
+ signals[SIGNAL_JUMP_TO_FILE],
+ 0,
+ file,
+ start_line,
+ end_line);
+
+ g_object_unref (file);
+ }
+
+ /* Select the row, so the user can copy/paste its contents. */
+ return TRUE;
}
static gboolean
select_func (GtkTreeSelection *selection,
- GtkTreeModel *model,
- GtkTreePath *path,
- gboolean path_currently_selected,
- gpointer user_data)
+ GtkTreeModel *model,
+ GtkTreePath *path,
+ gboolean path_currently_selected,
+ gpointer user_data)
{
- LatexilaBuildView *build_view = user_data;
+ LatexilaBuildView *build_view = user_data;
- if (path_currently_selected)
- {
- /* Always allow deselect */
- return TRUE;
- }
+ if (path_currently_selected)
+ {
+ /* Always allow deselect */
+ return TRUE;
+ }
- return select_row (build_view, model, path);
+ return select_row (build_view, model, path);
}
static void
row_activated_cb (LatexilaBuildView *build_view,
- GtkTreePath *path)
+ GtkTreePath *path)
{
- select_row (build_view,
- GTK_TREE_MODEL (build_view->priv->filtered_model),
- path);
+ select_row (build_view,
+ GTK_TREE_MODEL (build_view->priv->filtered_model),
+ path);
}
static void
init_tree_view (LatexilaBuildView *build_view)
{
- GtkTreeView *tree_view = GTK_TREE_VIEW (build_view);
- GtkTreeViewColumn *column;
- GtkCellRenderer *renderer;
- GtkTreeSelection *selection;
+ GtkTreeView *tree_view = GTK_TREE_VIEW (build_view);
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *renderer;
+ GtkTreeSelection *selection;
- gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (build_view->priv->filtered_model));
- gtk_tree_view_set_headers_visible (tree_view, FALSE);
+ gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (build_view->priv->filtered_model));
+ gtk_tree_view_set_headers_visible (tree_view, FALSE);
- /* Columns, cell renderers */
+ /* Columns, cell renderers */
- column = gtk_tree_view_column_new ();
+ column = gtk_tree_view_column_new ();
- renderer = gtk_cell_renderer_pixbuf_new ();
- gtk_tree_view_column_pack_start (column, renderer, FALSE);
- gtk_tree_view_column_add_attribute (column, renderer, "icon-name", COLUMN_ICON);
+ renderer = gtk_cell_renderer_pixbuf_new ();
+ gtk_tree_view_column_pack_start (column, renderer, FALSE);
+ gtk_tree_view_column_add_attribute (column, renderer, "icon-name", COLUMN_ICON);
- renderer = gtk_cell_renderer_text_new ();
- g_object_set (renderer,
- "weight-set", TRUE,
- "editable", TRUE,
- "editable-set", TRUE,
- NULL);
+ renderer = gtk_cell_renderer_text_new ();
+ g_object_set (renderer,
+ "weight-set", TRUE,
+ "editable", TRUE,
+ "editable-set", TRUE,
+ NULL);
- gtk_tree_view_column_pack_start (column, renderer, TRUE);
- gtk_tree_view_column_add_attribute (column, renderer, "text", COLUMN_MESSAGE);
- gtk_tree_view_column_add_attribute (column, renderer, "weight", COLUMN_WEIGHT);
+ gtk_tree_view_column_pack_start (column, renderer, TRUE);
+ gtk_tree_view_column_add_attribute (column, renderer, "text", COLUMN_MESSAGE);
+ gtk_tree_view_column_add_attribute (column, renderer, "weight", COLUMN_WEIGHT);
- gtk_tree_view_append_column (tree_view, column);
+ gtk_tree_view_append_column (tree_view, column);
- gtk_tree_view_insert_column_with_attributes (tree_view, -1, NULL,
- gtk_cell_renderer_text_new (),
- "text", COLUMN_BASENAME,
- NULL);
+ gtk_tree_view_insert_column_with_attributes (tree_view, -1, NULL,
+ gtk_cell_renderer_text_new (),
+ "text", COLUMN_BASENAME,
+ NULL);
- gtk_tree_view_insert_column_with_attributes (tree_view, -1, NULL,
- gtk_cell_renderer_text_new (),
- "text", COLUMN_LINE_STR,
- NULL);
+ gtk_tree_view_insert_column_with_attributes (tree_view, -1, NULL,
+ gtk_cell_renderer_text_new (),
+ "text", COLUMN_LINE_STR,
+ NULL);
- gtk_tree_view_set_tooltip_column (tree_view, COLUMN_PATH);
+ gtk_tree_view_set_tooltip_column (tree_view, COLUMN_PATH);
- /* Selection */
+ /* Selection */
- selection = gtk_tree_view_get_selection (tree_view);
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
- gtk_tree_selection_set_select_function (selection, select_func, build_view, NULL);
+ selection = gtk_tree_view_get_selection (tree_view);
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
+ gtk_tree_selection_set_select_function (selection, select_func, build_view, NULL);
- /* Double-click */
+ /* Double-click */
- g_signal_connect (build_view,
- "row-activated",
- G_CALLBACK (row_activated_cb),
- NULL);
+ g_signal_connect (build_view,
+ "row-activated",
+ G_CALLBACK (row_activated_cb),
+ NULL);
}
static void
latexila_build_view_init (LatexilaBuildView *build_view)
{
- build_view->priv = latexila_build_view_get_instance_private (build_view);
+ build_view->priv = latexila_build_view_get_instance_private (build_view);
- init_tree_models (build_view);
- init_tree_view (build_view);
+ init_tree_models (build_view);
+ init_tree_view (build_view);
}
/**
@@ -589,7 +605,7 @@ latexila_build_view_init (LatexilaBuildView *build_view)
LatexilaBuildView *
latexila_build_view_new (void)
{
- return g_object_new (LATEXILA_TYPE_BUILD_VIEW, NULL);
+ return g_object_new (LATEXILA_TYPE_BUILD_VIEW, NULL);
}
/**
@@ -601,50 +617,50 @@ latexila_build_view_new (void)
void
latexila_build_view_clear (LatexilaBuildView *build_view)
{
- GtkTreeSelection *selection;
+ GtkTreeSelection *selection;
- g_return_if_fail (LATEXILA_IS_BUILD_VIEW (build_view));
+ g_return_if_fail (LATEXILA_IS_BUILD_VIEW (build_view));
- /* No selection allowed when clearing the GtkTreeStore. Else, all the rows are
- * selected one by one, and if there are warnings or errors, the program jumps
- * to all warnings/errors one by one.
- * Another means would have been to remove and re-add the select function, but
- * I prefer this hack, shorter :)
- */
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (build_view));
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE);
- gtk_tree_store_clear (build_view->priv->store);
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
+ /* No selection allowed when clearing the GtkTreeStore. Else, all the rows are
+ * selected one by one, and if there are warnings or errors, the program jumps
+ * to all warnings/errors one by one.
+ * Another means would have been to remove and re-add the select function, but
+ * I prefer this hack, shorter :)
+ */
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (build_view));
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE);
+ gtk_tree_store_clear (build_view->priv->store);
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
- gtk_tree_view_columns_autosize (GTK_TREE_VIEW (build_view));
+ gtk_tree_view_columns_autosize (GTK_TREE_VIEW (build_view));
- build_view->priv->has_details = FALSE;
- g_object_notify (G_OBJECT (build_view), "has-details");
+ build_view->priv->has_details = FALSE;
+ g_object_notify (G_OBJECT (build_view), "has-details");
}
static GtkTreeIter
add_title (LatexilaBuildView *build_view,
- const gchar *message,
- LatexilaBuildState state,
- LatexilaBuildMsgType type)
+ const gchar *message,
+ LatexilaBuildState state,
+ LatexilaBuildMsgType type)
{
- gboolean bold = type == LATEXILA_BUILD_MSG_TYPE_MAIN_TITLE;
- GtkTreeIter iter;
- GtkTreePath *path;
-
- gtk_tree_store_append (build_view->priv->store, &iter, NULL);
- gtk_tree_store_set (build_view->priv->store, &iter,
- COLUMN_ICON, get_icon_name_from_state (state),
- COLUMN_MESSAGE, message,
- COLUMN_MESSAGE_TYPE, type,
- COLUMN_WEIGHT, bold ? 800 : 400,
- -1);
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (build_view->priv->store), &iter);
- gtk_tree_view_expand_to_path (GTK_TREE_VIEW (build_view), path);
- gtk_tree_path_free (path);
-
- return iter;
+ gboolean bold = type == LATEXILA_BUILD_MSG_TYPE_MAIN_TITLE;
+ GtkTreeIter iter;
+ GtkTreePath *path;
+
+ gtk_tree_store_append (build_view->priv->store, &iter, NULL);
+ gtk_tree_store_set (build_view->priv->store, &iter,
+ COLUMN_ICON, get_icon_name_from_state (state),
+ COLUMN_MESSAGE, message,
+ COLUMN_MESSAGE_TYPE, type,
+ COLUMN_WEIGHT, bold ? 800 : 400,
+ -1);
+
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (build_view->priv->store), &iter);
+ gtk_tree_view_expand_to_path (GTK_TREE_VIEW (build_view), path);
+ gtk_tree_path_free (path);
+
+ return iter;
}
/**
@@ -659,10 +675,10 @@ add_title (LatexilaBuildView *build_view,
*/
GtkTreeIter
latexila_build_view_add_main_title (LatexilaBuildView *build_view,
- const gchar *main_title,
- LatexilaBuildState state)
+ const gchar *main_title,
+ LatexilaBuildState state)
{
- return add_title (build_view, main_title, state, LATEXILA_BUILD_MSG_TYPE_MAIN_TITLE);
+ return add_title (build_view, main_title, state, LATEXILA_BUILD_MSG_TYPE_MAIN_TITLE);
}
/**
@@ -677,10 +693,10 @@ latexila_build_view_add_main_title (LatexilaBuildView *build_view,
*/
GtkTreeIter
latexila_build_view_add_job_title (LatexilaBuildView *build_view,
- const gchar *job_title,
- LatexilaBuildState state)
+ const gchar *job_title,
+ LatexilaBuildState state)
{
- return add_title (build_view, job_title, state, LATEXILA_BUILD_MSG_TYPE_JOB_TITLE);
+ return add_title (build_view, job_title, state, LATEXILA_BUILD_MSG_TYPE_JOB_TITLE);
}
/**
@@ -695,15 +711,15 @@ latexila_build_view_add_job_title (LatexilaBuildView *build_view,
*/
void
latexila_build_view_set_title_state (LatexilaBuildView *build_view,
- GtkTreeIter *title_id,
- LatexilaBuildState state)
+ GtkTreeIter *title_id,
+ LatexilaBuildState state)
{
- g_return_if_fail (LATEXILA_IS_BUILD_VIEW (build_view));
- g_return_if_fail (title_id != NULL);
+ g_return_if_fail (LATEXILA_IS_BUILD_VIEW (build_view));
+ g_return_if_fail (title_id != NULL);
- gtk_tree_store_set (build_view->priv->store, title_id,
- COLUMN_ICON, get_icon_name_from_state (state),
- -1);
+ gtk_tree_store_set (build_view->priv->store, title_id,
+ COLUMN_ICON, get_icon_name_from_state (state),
+ -1);
}
/**
@@ -718,58 +734,64 @@ latexila_build_view_set_title_state (LatexilaBuildView *build_view,
*/
GtkTreeIter
latexila_build_view_append_single_message (LatexilaBuildView *build_view,
- GtkTreeIter *parent,
- LatexilaBuildMsg *message)
+ GtkTreeIter *parent,
+ LatexilaBuildMsg *message)
{
- GFile *file = NULL;
- gchar *path = NULL;
- gchar *basename = NULL;
- gchar *line_str = NULL;
- gint end_line;
- GtkTreeIter iter;
-
- if (message->filename != NULL)
- {
- gchar *filename_with_tilde;
-
- file = g_file_new_for_path (message->filename);
-
- filename_with_tilde = latexila_utils_replace_home_dir_with_tilde (message->filename);
- path = g_markup_escape_text (filename_with_tilde, -1);
- g_free (filename_with_tilde);
-
- basename = g_file_get_basename (file);
- }
-
- if (message->start_line != -1)
- line_str = g_strdup_printf ("%d", message->start_line);
-
- end_line = message->end_line;
- if (message->start_line != -1 && end_line == -1)
- end_line = message->start_line;
-
- gtk_tree_store_append (build_view->priv->store, &iter, parent);
- gtk_tree_store_set (build_view->priv->store, &iter,
- COLUMN_ICON, get_icon_name_from_msg_type (message->type),
- COLUMN_MESSAGE, message->text,
- COLUMN_MESSAGE_TYPE, message->type,
- COLUMN_WEIGHT, 400,
- COLUMN_BASENAME, basename,
- COLUMN_FILE, file,
- COLUMN_PATH, path,
- COLUMN_START_LINE, message->start_line,
- COLUMN_END_LINE, end_line,
- COLUMN_LINE_STR, line_str,
- -1);
-
- if (file != NULL)
- g_object_unref (file);
-
- g_free (path);
- g_free (basename);
- g_free (line_str);
-
- return iter;
+ GFile *file = NULL;
+ gchar *path = NULL;
+ gchar *basename = NULL;
+ gchar *line_str = NULL;
+ gint end_line;
+ GtkTreeIter iter;
+
+ if (message->filename != NULL)
+ {
+ gchar *filename_with_tilde;
+
+ file = g_file_new_for_path (message->filename);
+
+ filename_with_tilde = latexila_utils_replace_home_dir_with_tilde (message->filename);
+ path = g_markup_escape_text (filename_with_tilde, -1);
+ g_free (filename_with_tilde);
+
+ basename = g_file_get_basename (file);
+ }
+
+ if (message->start_line != -1)
+ {
+ line_str = g_strdup_printf ("%d", message->start_line);
+ }
+
+ end_line = message->end_line;
+ if (message->start_line != -1 && end_line == -1)
+ {
+ end_line = message->start_line;
+ }
+
+ gtk_tree_store_append (build_view->priv->store, &iter, parent);
+ gtk_tree_store_set (build_view->priv->store, &iter,
+ COLUMN_ICON, get_icon_name_from_msg_type (message->type),
+ COLUMN_MESSAGE, message->text,
+ COLUMN_MESSAGE_TYPE, message->type,
+ COLUMN_WEIGHT, 400,
+ COLUMN_BASENAME, basename,
+ COLUMN_FILE, file,
+ COLUMN_PATH, path,
+ COLUMN_START_LINE, message->start_line,
+ COLUMN_END_LINE, end_line,
+ COLUMN_LINE_STR, line_str,
+ -1);
+
+ if (file != NULL)
+ {
+ g_object_unref (file);
+ }
+
+ g_free (path);
+ g_free (basename);
+ g_free (line_str);
+
+ return iter;
}
/**
@@ -784,35 +806,37 @@ latexila_build_view_append_single_message (LatexilaBuildView *build_view,
*/
void
latexila_build_view_append_messages (LatexilaBuildView *build_view,
- GtkTreeIter *parent,
- const GList *messages,
- gboolean expand)
+ GtkTreeIter *parent,
+ const GList *messages,
+ gboolean expand)
{
- const GList *l;
-
- for (l = messages; l != NULL; l = l->next)
- {
- GtkTreeIter child;
- LatexilaBuildMsg *build_msg = l->data;
-
- g_assert (build_msg != NULL);
-
- child = latexila_build_view_append_single_message (build_view, parent, build_msg);
-
- if (build_msg->children != NULL)
- latexila_build_view_append_messages (build_view,
- &child,
- build_msg->children->head,
- build_msg->expand);
- }
-
- if (expand)
- {
- GtkTreePath *path;
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (build_view->priv->store), parent);
- gtk_tree_view_expand_to_path (GTK_TREE_VIEW (build_view), path);
- gtk_tree_path_free (path);
- }
+ const GList *l;
+
+ for (l = messages; l != NULL; l = l->next)
+ {
+ GtkTreeIter child;
+ LatexilaBuildMsg *build_msg = l->data;
+
+ g_assert (build_msg != NULL);
+
+ child = latexila_build_view_append_single_message (build_view, parent, build_msg);
+
+ if (build_msg->children != NULL)
+ {
+ latexila_build_view_append_messages (build_view,
+ &child,
+ build_msg->children->head,
+ build_msg->expand);
+ }
+ }
+
+ if (expand)
+ {
+ GtkTreePath *path;
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (build_view->priv->store), parent);
+ gtk_tree_view_expand_to_path (GTK_TREE_VIEW (build_view), path);
+ gtk_tree_path_free (path);
+ }
}
/**
@@ -824,23 +848,28 @@ latexila_build_view_append_messages (LatexilaBuildView *build_view,
*/
void
latexila_build_view_remove_children (LatexilaBuildView *build_view,
- GtkTreeIter *parent)
+ GtkTreeIter *parent)
{
- GtkTreeIter child;
- GtkTreeModel *model;
- GtkTreeSelection *selection;
-
- g_return_if_fail (LATEXILA_IS_BUILD_VIEW (build_view));
-
- model = GTK_TREE_MODEL (build_view->priv->store);
- if (!gtk_tree_model_iter_children (model, &child, parent))
- return;
-
- /* Do the same hack as in latexila_build_view_clear(). */
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (build_view));
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE);
- while (gtk_tree_store_remove (build_view->priv->store, &child));
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
-
- gtk_tree_view_columns_autosize (GTK_TREE_VIEW (build_view));
+ GtkTreeIter child;
+ GtkTreeModel *model;
+ GtkTreeSelection *selection;
+
+ g_return_if_fail (LATEXILA_IS_BUILD_VIEW (build_view));
+
+ model = GTK_TREE_MODEL (build_view->priv->store);
+ if (!gtk_tree_model_iter_children (model, &child, parent))
+ {
+ return;
+ }
+
+ /* Do the same hack as in latexila_build_view_clear(). */
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (build_view));
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE);
+ while (gtk_tree_store_remove (build_view->priv->store, &child))
+ {
+ ;
+ }
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
+
+ gtk_tree_view_columns_autosize (GTK_TREE_VIEW (build_view));
}
diff --git a/src/liblatexila/latexila-latex-commands.c b/src/liblatexila/latexila-latex-commands.c
index 11e44a1..84e87eb 100644
--- a/src/liblatexila/latexila-latex-commands.c
+++ b/src/liblatexila/latexila-latex-commands.c
@@ -40,26 +40,26 @@
void
latexila_latex_commands_add_action_infos (GtkApplication *gtk_app)
{
- TeplApplication *tepl_app;
- AmtkActionInfoStore *store;
+ TeplApplication *tepl_app;
+ AmtkActionInfoStore *store;
- const AmtkActionInfoEntry entries[] =
- {
- /* action, icon, label, accel, tooltip */
+ const AmtkActionInfoEntry entries[] =
+ {
+ /* action, icon, label, accel, tooltip */
- { "win.latex-command-env-figure", "image-x-generic", "\\begin{_figure}", NULL,
- N_("Figure - \\begin{figure}") },
- };
+ { "win.latex-command-env-figure", "image-x-generic", "\\begin{_figure}", NULL,
+ N_ ("Figure - \\begin{figure}") },
+ };
- g_return_if_fail (GTK_IS_APPLICATION (gtk_app));
+ g_return_if_fail (GTK_IS_APPLICATION (gtk_app));
- tepl_app = tepl_application_get_from_gtk_application (gtk_app);
- store = tepl_application_get_app_action_info_store (tepl_app);
+ tepl_app = tepl_application_get_from_gtk_application (gtk_app);
+ store = tepl_application_get_app_action_info_store (tepl_app);
- amtk_action_info_store_add_entries (store,
- entries,
- G_N_ELEMENTS (entries),
- GETTEXT_PACKAGE);
+ amtk_action_info_store_add_entries (store,
+ entries,
+ G_N_ELEMENTS (entries),
+ GETTEXT_PACKAGE);
}
/* Util functions */
@@ -69,108 +69,108 @@ latexila_latex_commands_add_action_infos (GtkApplication *gtk_app)
*/
void
latexila_latex_commands_insert_text (TeplApplicationWindow *tepl_window,
- const gchar *text_before,
- const gchar *text_after,
- const gchar *text_if_no_selection)
+ const gchar *text_before,
+ const gchar *text_after,
+ const gchar *text_if_no_selection)
{
- TeplView *view;
- GtkTextBuffer *buffer;
- GtkTextIter selection_start;
- GtkTextIter selection_end;
- gboolean has_selection;
- gchar *text_before_with_indent;
- gchar *text_after_with_indent;
+ TeplView *view;
+ GtkTextBuffer *buffer;
+ GtkTextIter selection_start;
+ GtkTextIter selection_end;
+ gboolean has_selection;
+ gchar *text_before_with_indent;
+ gchar *text_after_with_indent;
- g_return_if_fail (TEPL_IS_APPLICATION_WINDOW (tepl_window));
- g_return_if_fail (text_before != NULL);
- g_return_if_fail (text_after != NULL);
+ g_return_if_fail (TEPL_IS_APPLICATION_WINDOW (tepl_window));
+ g_return_if_fail (text_before != NULL);
+ g_return_if_fail (text_after != NULL);
- view = tepl_tab_group_get_active_view (TEPL_TAB_GROUP (tepl_window));
- g_return_if_fail (view != NULL);
+ view = tepl_tab_group_get_active_view (TEPL_TAB_GROUP (tepl_window));
+ g_return_if_fail (view != NULL);
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- has_selection = gtk_text_buffer_get_selection_bounds (buffer,
- &selection_start,
- &selection_end);
+ has_selection = gtk_text_buffer_get_selection_bounds (buffer,
+ &selection_start,
+ &selection_end);
- /* Take into account the current indentation. */
- {
- gchar *current_indent;
- gchar *newline_replacement;
+ /* Take into account the current indentation. */
+ {
+ gchar *current_indent;
+ gchar *newline_replacement;
- current_indent = tepl_iter_get_line_indentation (&selection_start);
- newline_replacement = g_strdup_printf ("\n%s", current_indent);
+ current_indent = tepl_iter_get_line_indentation (&selection_start);
+ newline_replacement = g_strdup_printf ("\n%s", current_indent);
- text_before_with_indent = latexila_utils_str_replace (text_before, "\n", newline_replacement);
- text_after_with_indent = latexila_utils_str_replace (text_after, "\n", newline_replacement);
+ text_before_with_indent = latexila_utils_str_replace (text_before, "\n", newline_replacement);
+ text_after_with_indent = latexila_utils_str_replace (text_after, "\n", newline_replacement);
- g_free (current_indent);
- g_free (newline_replacement);
- }
+ g_free (current_indent);
+ g_free (newline_replacement);
+ }
- gtk_text_buffer_begin_user_action (buffer);
+ gtk_text_buffer_begin_user_action (buffer);
- /* Insert around the selected text.
- * Move the cursor to the end.
- */
- if (has_selection)
- {
- GtkTextMark *end_mark;
- GtkTextIter end_iter;
+ /* Insert around the selected text.
+ * Move the cursor to the end.
+ */
+ if (has_selection)
+ {
+ GtkTextMark *end_mark;
+ GtkTextIter end_iter;
- end_mark = gtk_text_buffer_create_mark (buffer, NULL, &selection_end, FALSE);
+ end_mark = gtk_text_buffer_create_mark (buffer, NULL, &selection_end, FALSE);
- gtk_text_buffer_insert (buffer, &selection_start, text_before_with_indent, -1);
+ gtk_text_buffer_insert (buffer, &selection_start, text_before_with_indent, -1);
- gtk_text_buffer_get_iter_at_mark (buffer, &end_iter, end_mark);
- gtk_text_buffer_delete_mark (buffer, end_mark);
+ gtk_text_buffer_get_iter_at_mark (buffer, &end_iter, end_mark);
+ gtk_text_buffer_delete_mark (buffer, end_mark);
- gtk_text_buffer_insert (buffer, &end_iter, text_after_with_indent, -1);
- gtk_text_buffer_place_cursor (buffer, &end_iter);
- }
- /* No selection */
- else if (text_if_no_selection != NULL)
- {
- gtk_text_buffer_insert_at_cursor (buffer, text_if_no_selection, -1);
- }
- /* No selection, move the cursor between the two inserted chunks. */
- else
- {
- GtkTextIter between_iter;
- GtkTextMark *between_mark;
+ gtk_text_buffer_insert (buffer, &end_iter, text_after_with_indent, -1);
+ gtk_text_buffer_place_cursor (buffer, &end_iter);
+ }
+ /* No selection */
+ else if (text_if_no_selection != NULL)
+ {
+ gtk_text_buffer_insert_at_cursor (buffer, text_if_no_selection, -1);
+ }
+ /* No selection, move the cursor between the two inserted chunks. */
+ else
+ {
+ GtkTextIter between_iter;
+ GtkTextMark *between_mark;
- gtk_text_buffer_insert_at_cursor (buffer, text_before_with_indent, -1);
+ gtk_text_buffer_insert_at_cursor (buffer, text_before_with_indent, -1);
- gtk_text_buffer_get_iter_at_mark (buffer,
- &between_iter,
- gtk_text_buffer_get_insert (buffer));
- between_mark = gtk_text_buffer_create_mark (buffer, NULL, &between_iter, TRUE);
+ gtk_text_buffer_get_iter_at_mark (buffer,
+ &between_iter,
+ gtk_text_buffer_get_insert (buffer));
+ between_mark = gtk_text_buffer_create_mark (buffer, NULL, &between_iter, TRUE);
- gtk_text_buffer_insert_at_cursor (buffer, text_after_with_indent, -1);
+ gtk_text_buffer_insert_at_cursor (buffer, text_after_with_indent, -1);
- gtk_text_buffer_get_iter_at_mark (buffer, &between_iter, between_mark);
- gtk_text_buffer_delete_mark (buffer, between_mark);
- gtk_text_buffer_place_cursor (buffer, &between_iter);
- }
+ gtk_text_buffer_get_iter_at_mark (buffer, &between_iter, between_mark);
+ gtk_text_buffer_delete_mark (buffer, between_mark);
+ gtk_text_buffer_place_cursor (buffer, &between_iter);
+ }
- gtk_text_buffer_end_user_action (buffer);
+ gtk_text_buffer_end_user_action (buffer);
- gtk_widget_grab_focus (GTK_WIDGET (view));
+ gtk_widget_grab_focus (GTK_WIDGET (view));
- g_free (text_before_with_indent);
- g_free (text_after_with_indent);
+ g_free (text_before_with_indent);
+ g_free (text_after_with_indent);
}
static gchar *
get_indentation (TeplApplicationWindow *tepl_window)
{
- TeplView *view;
+ TeplView *view;
- view = tepl_tab_group_get_active_view (TEPL_TAB_GROUP (tepl_window));
- g_return_val_if_fail (view != NULL, NULL);
+ view = tepl_tab_group_get_active_view (TEPL_TAB_GROUP (tepl_window));
+ g_return_val_if_fail (view != NULL, NULL);
- return latexila_view_get_indentation_style (GTK_SOURCE_VIEW (view));
+ return latexila_view_get_indentation_style (GTK_SOURCE_VIEW (view));
}
/* When it doesn't make sense to have the selected text between @text_before and
@@ -180,524 +180,524 @@ get_indentation (TeplApplicationWindow *tepl_window)
static void
deselect_text (TeplApplicationWindow *tepl_window)
{
- TeplBuffer *tepl_buffer;
- GtkTextBuffer *gtk_buffer;
- GtkTextIter selection_start;
- GtkTextIter selection_end;
+ TeplBuffer *tepl_buffer;
+ GtkTextBuffer *gtk_buffer;
+ GtkTextIter selection_start;
+ GtkTextIter selection_end;
- tepl_buffer = tepl_tab_group_get_active_buffer (TEPL_TAB_GROUP (tepl_window));
- g_return_if_fail (tepl_buffer != NULL);
+ tepl_buffer = tepl_tab_group_get_active_buffer (TEPL_TAB_GROUP (tepl_window));
+ g_return_if_fail (tepl_buffer != NULL);
- gtk_buffer = GTK_TEXT_BUFFER (tepl_buffer);
+ gtk_buffer = GTK_TEXT_BUFFER (tepl_buffer);
- gtk_text_buffer_get_selection_bounds (gtk_buffer,
- &selection_start,
- &selection_end);
+ gtk_text_buffer_get_selection_bounds (gtk_buffer,
+ &selection_start,
+ &selection_end);
- /* Always place cursor at beginning of selection, to have more predictable
- * results, instead of placing the cursor at the insert mark.
- */
- gtk_text_buffer_place_cursor (gtk_buffer, &selection_start);
+ /* Always place cursor at beginning of selection, to have more predictable
+ * results, instead of placing the cursor at the insert mark.
+ */
+ gtk_text_buffer_place_cursor (gtk_buffer, &selection_start);
}
/* GActions implementation */
static void
latex_command_simple_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- const gchar *command;
- gchar *text_before;
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ const gchar *command;
+ gchar *text_before;
- command = g_variant_get_string (parameter, NULL);
- text_before = g_strdup_printf ("\\%s", command);
+ command = g_variant_get_string (parameter, NULL);
+ text_before = g_strdup_printf ("\\%s", command);
- latexila_latex_commands_insert_text (tepl_window, text_before, "", NULL);
+ latexila_latex_commands_insert_text (tepl_window, text_before, "", NULL);
- g_free (text_before);
+ g_free (text_before);
}
static void
latex_command_with_braces_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- const gchar *command;
- gchar *text_before;
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ const gchar *command;
+ gchar *text_before;
- command = g_variant_get_string (parameter, NULL);
- text_before = g_strdup_printf ("\\%s{", command);
+ command = g_variant_get_string (parameter, NULL);
+ text_before = g_strdup_printf ("\\%s{", command);
- latexila_latex_commands_insert_text (tepl_window, text_before, "}", NULL);
+ latexila_latex_commands_insert_text (tepl_window, text_before, "}", NULL);
- g_free (text_before);
+ g_free (text_before);
}
static void
latex_command_with_space_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- const gchar *command;
- gchar *text_before;
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ const gchar *command;
+ gchar *text_before;
- command = g_variant_get_string (parameter, NULL);
- text_before = g_strdup_printf ("\\%s ", command);
+ command = g_variant_get_string (parameter, NULL);
+ text_before = g_strdup_printf ("\\%s ", command);
- latexila_latex_commands_insert_text (tepl_window, text_before, "", NULL);
+ latexila_latex_commands_insert_text (tepl_window, text_before, "", NULL);
- g_free (text_before);
+ g_free (text_before);
}
static void
latex_command_with_newline_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- const gchar *command;
- gchar *text_before;
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ const gchar *command;
+ gchar *text_before;
- command = g_variant_get_string (parameter, NULL);
- text_before = g_strdup_printf ("\\%s\n", command);
+ command = g_variant_get_string (parameter, NULL);
+ text_before = g_strdup_printf ("\\%s\n", command);
- latexila_latex_commands_insert_text (tepl_window, text_before, "", NULL);
+ latexila_latex_commands_insert_text (tepl_window, text_before, "", NULL);
- g_free (text_before);
+ g_free (text_before);
}
static void
latex_command_env_simple_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- const gchar *environment;
- gchar *text_before;
- gchar *text_after;
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ const gchar *environment;
+ gchar *text_before;
+ gchar *text_after;
- environment = g_variant_get_string (parameter, NULL);
- text_before = g_strdup_printf ("\\begin{%s}\n", environment);
- text_after = g_strdup_printf ("\n\\end{%s}", environment);
+ environment = g_variant_get_string (parameter, NULL);
+ text_before = g_strdup_printf ("\\begin{%s}\n", environment);
+ text_after = g_strdup_printf ("\n\\end{%s}", environment);
- latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
+ latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
- g_free (text_before);
- g_free (text_after);
+ g_free (text_before);
+ g_free (text_after);
}
static void
latex_command_env_figure_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- gchar *indent;
- gchar *text_before;
- gchar *text_after;
-
- indent = get_indentation (tepl_window);
-
- text_before = g_strdup_printf ("\\begin{figure}\n"
- "%s\\begin{center}\n"
- "%s%s\\includegraphics{",
- indent,
- indent, indent);
-
- text_after = g_strdup_printf ("}\n"
- "%s%s\\caption{}\n"
- "%s%s\\label{fig:}\n"
- "%s\\end{center}\n"
- "\\end{figure}",
- indent, indent,
- indent, indent,
- indent);
-
- deselect_text (tepl_window);
- latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
-
- g_free (indent);
- g_free (text_before);
- g_free (text_after);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ gchar *indent;
+ gchar *text_before;
+ gchar *text_after;
+
+ indent = get_indentation (tepl_window);
+
+ text_before = g_strdup_printf ("\\begin{figure}\n"
+ "%s\\begin{center}\n"
+ "%s%s\\includegraphics{",
+ indent,
+ indent, indent);
+
+ text_after = g_strdup_printf ("}\n"
+ "%s%s\\caption{}\n"
+ "%s%s\\label{fig:}\n"
+ "%s\\end{center}\n"
+ "\\end{figure}",
+ indent, indent,
+ indent, indent,
+ indent);
+
+ deselect_text (tepl_window);
+ latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
+
+ g_free (indent);
+ g_free (text_before);
+ g_free (text_after);
}
static void
latex_command_env_table_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- gchar *indent;
- gchar *text_before;
- gchar *text_after;
-
- indent = get_indentation (tepl_window);
-
- text_before = g_strdup_printf ("\\begin{table}\n"
- "%s\\caption{",
- indent);
-
- text_after = g_strdup_printf ("}\n"
- "%s\\label{tab:}\n"
- "\n"
- "%s\\begin{center}\n"
- "%s%s\\begin{tabular}{cc}\n"
- "%s%s%s a & b \\\\\n"
- "%s%s%s c & d \\\\\n"
- "%s%s\\end{tabular}\n"
- "%s\\end{center}\n"
- "\\end{table}",
- indent,
- indent,
- indent, indent,
- indent, indent, indent,
- indent, indent, indent,
- indent, indent,
- indent);
-
- deselect_text (tepl_window);
- latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
-
- g_free (indent);
- g_free (text_before);
- g_free (text_after);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ gchar *indent;
+ gchar *text_before;
+ gchar *text_after;
+
+ indent = get_indentation (tepl_window);
+
+ text_before = g_strdup_printf ("\\begin{table}\n"
+ "%s\\caption{",
+ indent);
+
+ text_after = g_strdup_printf ("}\n"
+ "%s\\label{tab:}\n"
+ "\n"
+ "%s\\begin{center}\n"
+ "%s%s\\begin{tabular}{cc}\n"
+ "%s%s%s a & b \\\\\n"
+ "%s%s%s c & d \\\\\n"
+ "%s%s\\end{tabular}\n"
+ "%s\\end{center}\n"
+ "\\end{table}",
+ indent,
+ indent,
+ indent, indent,
+ indent, indent, indent,
+ indent, indent, indent,
+ indent, indent,
+ indent);
+
+ deselect_text (tepl_window);
+ latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
+
+ g_free (indent);
+ g_free (text_before);
+ g_free (text_after);
}
static void
latex_command_list_env_simple_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- const gchar *list_env;
- gchar *indent;
- gchar *text_before;
- gchar *text_after;
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ const gchar *list_env;
+ gchar *indent;
+ gchar *text_before;
+ gchar *text_after;
- list_env = g_variant_get_string (parameter, NULL);
+ list_env = g_variant_get_string (parameter, NULL);
- indent = get_indentation (tepl_window);
+ indent = get_indentation (tepl_window);
- text_before = g_strdup_printf ("\\begin{%s}\n"
- "%s\\item ",
- list_env,
- indent);
+ text_before = g_strdup_printf ("\\begin{%s}\n"
+ "%s\\item ",
+ list_env,
+ indent);
- text_after = g_strdup_printf ("\n\\end{%s}", list_env);
+ text_after = g_strdup_printf ("\n\\end{%s}", list_env);
- deselect_text (tepl_window);
- latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
+ deselect_text (tepl_window);
+ latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
- g_free (indent);
- g_free (text_before);
- g_free (text_after);
+ g_free (indent);
+ g_free (text_before);
+ g_free (text_after);
}
static void
latex_command_list_env_description_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- gchar *indent;
- gchar *text_before;
- gchar *text_after;
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ gchar *indent;
+ gchar *text_before;
+ gchar *text_after;
- indent = get_indentation (tepl_window);
+ indent = get_indentation (tepl_window);
- text_before = g_strdup_printf ("\\begin{description}\n"
- "%s\\item[",
- indent);
+ text_before = g_strdup_printf ("\\begin{description}\n"
+ "%s\\item[",
+ indent);
- text_after = g_strdup_printf ("] \n\\end{description}");
+ text_after = g_strdup_printf ("] \n\\end{description}");
- deselect_text (tepl_window);
- latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
+ deselect_text (tepl_window);
+ latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
- g_free (indent);
- g_free (text_before);
- g_free (text_after);
+ g_free (indent);
+ g_free (text_before);
+ g_free (text_after);
}
static void
latex_command_list_env_list_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- gchar *indent;
- gchar *text_after;
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ gchar *indent;
+ gchar *text_after;
- indent = get_indentation (tepl_window);
- text_after = g_strdup_printf ("}{}\n%s\\item \n\\end{list}", indent);
+ indent = get_indentation (tepl_window);
+ text_after = g_strdup_printf ("}{}\n%s\\item \n\\end{list}", indent);
- deselect_text (tepl_window);
- latexila_latex_commands_insert_text (tepl_window, "\\begin{list}{", text_after, NULL);
+ deselect_text (tepl_window);
+ latexila_latex_commands_insert_text (tepl_window, "\\begin{list}{", text_after, NULL);
- g_free (indent);
- g_free (text_after);
+ g_free (indent);
+ g_free (text_after);
}
static void
latex_command_char_style_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- const gchar *style;
- TeplBuffer *buffer;
- TeplSelectionType selection_type;
- gchar *text_before;
- gchar *text_after;
- gchar *text_if_no_selection;
-
- style = g_variant_get_string (parameter, NULL);
-
- buffer = tepl_tab_group_get_active_buffer (TEPL_TAB_GROUP (tepl_window));
- g_return_if_fail (buffer != NULL);
-
- selection_type = tepl_buffer_get_selection_type (buffer);
-
- if (selection_type == TEPL_SELECTION_TYPE_MULTIPLE_LINES)
- {
- text_before = g_strdup_printf ("\\begin{%s}\n", style);
- text_after = g_strdup_printf ("\n\\end{%s}", style);
- text_if_no_selection = NULL;
- }
- else
- {
- text_before = g_strdup_printf ("{\\%s ", style);
- text_after = g_strdup_printf ("}");
- text_if_no_selection = g_strdup_printf ("\\%s ", style);
- }
-
- latexila_latex_commands_insert_text (tepl_window,
- text_before,
- text_after,
- text_if_no_selection);
-
- g_free (text_before);
- g_free (text_after);
- g_free (text_if_no_selection);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ const gchar *style;
+ TeplBuffer *buffer;
+ TeplSelectionType selection_type;
+ gchar *text_before;
+ gchar *text_after;
+ gchar *text_if_no_selection;
+
+ style = g_variant_get_string (parameter, NULL);
+
+ buffer = tepl_tab_group_get_active_buffer (TEPL_TAB_GROUP (tepl_window));
+ g_return_if_fail (buffer != NULL);
+
+ selection_type = tepl_buffer_get_selection_type (buffer);
+
+ if (selection_type == TEPL_SELECTION_TYPE_MULTIPLE_LINES)
+ {
+ text_before = g_strdup_printf ("\\begin{%s}\n", style);
+ text_after = g_strdup_printf ("\n\\end{%s}", style);
+ text_if_no_selection = NULL;
+ }
+ else
+ {
+ text_before = g_strdup_printf ("{\\%s ", style);
+ text_after = g_strdup_printf ("}");
+ text_if_no_selection = g_strdup_printf ("\\%s ", style);
+ }
+
+ latexila_latex_commands_insert_text (tepl_window,
+ text_before,
+ text_after,
+ text_if_no_selection);
+
+ g_free (text_before);
+ g_free (text_after);
+ g_free (text_if_no_selection);
}
static void
latex_command_tabular_tabular_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- gchar *indent;
- gchar *text_after;
-
- indent = get_indentation (tepl_window);
- text_after = g_strdup_printf ("}\n"
- "%s a & b \\\\\n"
- "%s c & d \\\\\n"
- "\\end{tabular}",
- indent,
- indent);
-
- deselect_text (tepl_window);
- latexila_latex_commands_insert_text (tepl_window,
- "\\begin{tabular}{cc",
- text_after,
- NULL);
-
- g_free (indent);
- g_free (text_after);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ gchar *indent;
+ gchar *text_after;
+
+ indent = get_indentation (tepl_window);
+ text_after = g_strdup_printf ("}\n"
+ "%s a & b \\\\\n"
+ "%s c & d \\\\\n"
+ "\\end{tabular}",
+ indent,
+ indent);
+
+ deselect_text (tepl_window);
+ latexila_latex_commands_insert_text (tepl_window,
+ "\\begin{tabular}{cc",
+ text_after,
+ NULL);
+
+ g_free (indent);
+ g_free (text_after);
}
static void
latex_command_tabular_multicolumn_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- latexila_latex_commands_insert_text (tepl_window, "\\multicolumn{}{}{", "}", NULL);
+ latexila_latex_commands_insert_text (tepl_window, "\\multicolumn{}{}{", "}", NULL);
}
static void
latex_command_tabular_cline_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- latexila_latex_commands_insert_text (tepl_window, "\\cline{", "-}", NULL);
+ latexila_latex_commands_insert_text (tepl_window, "\\cline{", "-}", NULL);
}
static void
latex_command_presentation_frame_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- gchar *indent;
- gchar *text_before;
-
- indent = get_indentation (tepl_window);
- text_before = g_strdup_printf ("\\begin{frame}\n"
- "%s\\frametitle{}\n"
- "%s\\framesubtitle{}\n",
- indent,
- indent);
-
- latexila_latex_commands_insert_text (tepl_window,
- text_before,
- "\n\\end{frame}",
- NULL);
-
- g_free (indent);
- g_free (text_before);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ gchar *indent;
+ gchar *text_before;
+
+ indent = get_indentation (tepl_window);
+ text_before = g_strdup_printf ("\\begin{frame}\n"
+ "%s\\frametitle{}\n"
+ "%s\\framesubtitle{}\n",
+ indent,
+ indent);
+
+ latexila_latex_commands_insert_text (tepl_window,
+ text_before,
+ "\n\\end{frame}",
+ NULL);
+
+ g_free (indent);
+ g_free (text_before);
}
static void
latex_command_presentation_block_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- latexila_latex_commands_insert_text (tepl_window,
- "\\begin{block}{}\n",
- "\n\\end{block}",
- NULL);
+ latexila_latex_commands_insert_text (tepl_window,
+ "\\begin{block}{}\n",
+ "\n\\end{block}",
+ NULL);
}
static void
latex_command_presentation_columns_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- gchar *indent;
- gchar *text_before;
- gchar *text_after;
-
- indent = get_indentation (tepl_window);
-
- text_before = g_strdup_printf ("\\begin{columns}\n"
- "%s\\begin{column}{.5\\textwidth}\n",
- indent);
-
- text_after = g_strdup_printf ("\n"
- "%s\\end{column}\n"
- "%s\\begin{column}{.5\\textwidth}\n\n"
- "%s\\end{column}\n"
- "\\end{columns}",
- indent,
- indent,
- indent);
-
- latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
-
- g_free (indent);
- g_free (text_before);
- g_free (text_after);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ gchar *indent;
+ gchar *text_before;
+ gchar *text_after;
+
+ indent = get_indentation (tepl_window);
+
+ text_before = g_strdup_printf ("\\begin{columns}\n"
+ "%s\\begin{column}{.5\\textwidth}\n",
+ indent);
+
+ text_after = g_strdup_printf ("\n"
+ "%s\\end{column}\n"
+ "%s\\begin{column}{.5\\textwidth}\n\n"
+ "%s\\end{column}\n"
+ "\\end{columns}",
+ indent,
+ indent,
+ indent);
+
+ latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
+
+ g_free (indent);
+ g_free (text_before);
+ g_free (text_after);
}
static void
latex_command_spacing_new_line_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- latexila_latex_commands_insert_text (tepl_window, "\\\\\n", "", NULL);
+ latexila_latex_commands_insert_text (tepl_window, "\\\\\n", "", NULL);
}
static void
latex_command_ams_packages_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
-
- latexila_latex_commands_insert_text (tepl_window,
- "\\usepackage{amsmath}\n"
- "\\usepackage{amsfonts}\n"
- "\\usepackage{amssymb}",
- "",
- NULL);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+
+ latexila_latex_commands_insert_text (tepl_window,
+ "\\usepackage{amsmath}\n"
+ "\\usepackage{amsfonts}\n"
+ "\\usepackage{amssymb}",
+ "",
+ NULL);
}
static void
math_command_env_normal_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- latexila_latex_commands_insert_text (tepl_window, "$ ", " $", NULL);
+ latexila_latex_commands_insert_text (tepl_window, "$ ", " $", NULL);
}
static void
math_command_env_centered_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- latexila_latex_commands_insert_text (tepl_window, "\\[ ", " \\]", NULL);
+ latexila_latex_commands_insert_text (tepl_window, "\\[ ", " \\]", NULL);
}
static void
math_command_env_array_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- latexila_latex_commands_insert_text (tepl_window,
- "\\begin{align*}\n",
- "\n\\end{align*}",
- NULL);
+ latexila_latex_commands_insert_text (tepl_window,
+ "\\begin{align*}\n",
+ "\n\\end{align*}",
+ NULL);
}
static void
math_command_misc_superscript_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- latexila_latex_commands_insert_text (tepl_window, "^{", "}", NULL);
+ latexila_latex_commands_insert_text (tepl_window, "^{", "}", NULL);
}
static void
math_command_misc_subscript_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- latexila_latex_commands_insert_text (tepl_window, "_{", "}", NULL);
+ latexila_latex_commands_insert_text (tepl_window, "_{", "}", NULL);
}
static void
math_command_misc_frac_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- latexila_latex_commands_insert_text (tepl_window, "\\frac{", "}{}", NULL);
+ latexila_latex_commands_insert_text (tepl_window, "\\frac{", "}{}", NULL);
}
static void
math_command_misc_nth_root_cb (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
- latexila_latex_commands_insert_text (tepl_window, "\\sqrt[]{", "}", NULL);
+ latexila_latex_commands_insert_text (tepl_window, "\\sqrt[]{", "}", NULL);
}
/**
@@ -710,43 +710,43 @@ math_command_misc_nth_root_cb (GSimpleAction *action,
void
latexila_latex_commands_add_actions (GtkApplicationWindow *gtk_window)
{
- TeplApplicationWindow *tepl_window;
-
- const GActionEntry entries[] = {
- { "latex-command-simple", latex_command_simple_cb, "s" },
- { "latex-command-with-braces", latex_command_with_braces_cb, "s" },
- { "latex-command-with-space", latex_command_with_space_cb, "s" },
- { "latex-command-with-newline", latex_command_with_newline_cb, "s" },
- { "latex-command-env-simple", latex_command_env_simple_cb, "s" },
- { "latex-command-env-figure", latex_command_env_figure_cb },
- { "latex-command-env-table", latex_command_env_table_cb },
- { "latex-command-list-env-simple", latex_command_list_env_simple_cb, "s" },
- { "latex-command-list-env-description", latex_command_list_env_description_cb },
- { "latex-command-list-env-list", latex_command_list_env_list_cb },
- { "latex-command-char-style", latex_command_char_style_cb, "s" },
- { "latex-command-tabular-tabular", latex_command_tabular_tabular_cb },
- { "latex-command-tabular-multicolumn", latex_command_tabular_multicolumn_cb },
- { "latex-command-tabular-cline", latex_command_tabular_cline_cb },
- { "latex-command-presentation-frame", latex_command_presentation_frame_cb },
- { "latex-command-presentation-block", latex_command_presentation_block_cb },
- { "latex-command-presentation-columns", latex_command_presentation_columns_cb },
- { "latex-command-spacing-new-line", latex_command_spacing_new_line_cb },
- { "latex-command-ams-packages", latex_command_ams_packages_cb },
- { "math-command-env-normal", math_command_env_normal_cb },
- { "math-command-env-centered", math_command_env_centered_cb },
- { "math-command-env-array", math_command_env_array_cb },
- { "math-command-misc-superscript", math_command_misc_superscript_cb },
- { "math-command-misc-subscript", math_command_misc_subscript_cb },
- { "math-command-misc-frac", math_command_misc_frac_cb },
- { "math-command-misc-nth-root", math_command_misc_nth_root_cb },
- };
-
- g_return_if_fail (GTK_IS_APPLICATION_WINDOW (gtk_window));
-
- tepl_window = tepl_application_window_get_from_gtk_application_window (gtk_window);
-
- amtk_action_map_add_action_entries_check_dups (G_ACTION_MAP (gtk_window),
- entries,
- G_N_ELEMENTS (entries),
- tepl_window);
+ TeplApplicationWindow *tepl_window;
+
+ const GActionEntry entries[] = {
+ { "latex-command-simple", latex_command_simple_cb, "s" },
+ { "latex-command-with-braces", latex_command_with_braces_cb, "s" },
+ { "latex-command-with-space", latex_command_with_space_cb, "s" },
+ { "latex-command-with-newline", latex_command_with_newline_cb, "s" },
+ { "latex-command-env-simple", latex_command_env_simple_cb, "s" },
+ { "latex-command-env-figure", latex_command_env_figure_cb },
+ { "latex-command-env-table", latex_command_env_table_cb },
+ { "latex-command-list-env-simple", latex_command_list_env_simple_cb, "s" },
+ { "latex-command-list-env-description", latex_command_list_env_description_cb },
+ { "latex-command-list-env-list", latex_command_list_env_list_cb },
+ { "latex-command-char-style", latex_command_char_style_cb, "s" },
+ { "latex-command-tabular-tabular", latex_command_tabular_tabular_cb },
+ { "latex-command-tabular-multicolumn", latex_command_tabular_multicolumn_cb },
+ { "latex-command-tabular-cline", latex_command_tabular_cline_cb },
+ { "latex-command-presentation-frame", latex_command_presentation_frame_cb },
+ { "latex-command-presentation-block", latex_command_presentation_block_cb },
+ { "latex-command-presentation-columns", latex_command_presentation_columns_cb },
+ { "latex-command-spacing-new-line", latex_command_spacing_new_line_cb },
+ { "latex-command-ams-packages", latex_command_ams_packages_cb },
+ { "math-command-env-normal", math_command_env_normal_cb },
+ { "math-command-env-centered", math_command_env_centered_cb },
+ { "math-command-env-array", math_command_env_array_cb },
+ { "math-command-misc-superscript", math_command_misc_superscript_cb },
+ { "math-command-misc-subscript", math_command_misc_subscript_cb },
+ { "math-command-misc-frac", math_command_misc_frac_cb },
+ { "math-command-misc-nth-root", math_command_misc_nth_root_cb },
+ };
+
+ g_return_if_fail (GTK_IS_APPLICATION_WINDOW (gtk_window));
+
+ tepl_window = tepl_application_window_get_from_gtk_application_window (gtk_window);
+
+ amtk_action_map_add_action_entries_check_dups (G_ACTION_MAP (gtk_window),
+ entries,
+ G_N_ELEMENTS (entries),
+ tepl_window);
}
diff --git a/src/liblatexila/latexila-post-processor-all-output.c
b/src/liblatexila/latexila-post-processor-all-output.c
index 3f6c908..c1af7bd 100644
--- a/src/liblatexila/latexila-post-processor-all-output.c
+++ b/src/liblatexila/latexila-post-processor-all-output.c
@@ -30,82 +30,84 @@
struct _LatexilaPostProcessorAllOutputPrivate
{
- GQueue *messages;
+ GQueue *messages;
};
G_DEFINE_TYPE_WITH_PRIVATE (LatexilaPostProcessorAllOutput,
- latexila_post_processor_all_output,
- LATEXILA_TYPE_POST_PROCESSOR)
+ latexila_post_processor_all_output,
+ LATEXILA_TYPE_POST_PROCESSOR)
static void
latexila_post_processor_all_output_process_line (LatexilaPostProcessor *post_processor,
- gchar *line)
+ gchar *line)
{
- LatexilaPostProcessorAllOutput *pp = LATEXILA_POST_PROCESSOR_ALL_OUTPUT (post_processor);
+ LatexilaPostProcessorAllOutput *pp = LATEXILA_POST_PROCESSOR_ALL_OUTPUT (post_processor);
- if (line != NULL)
- {
- LatexilaBuildMsg *msg;
+ if (line != NULL)
+ {
+ LatexilaBuildMsg *msg;
- msg = latexila_build_msg_new ();
- msg->text = line;
- msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
+ msg = latexila_build_msg_new ();
+ msg->text = line;
+ msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
- g_queue_push_tail (pp->priv->messages, msg);
- }
+ g_queue_push_tail (pp->priv->messages, msg);
+ }
}
static const GList *
latexila_post_processor_all_output_get_messages (LatexilaPostProcessor *post_processor,
- gboolean show_details)
+ gboolean show_details)
{
- LatexilaPostProcessorAllOutput *pp = LATEXILA_POST_PROCESSOR_ALL_OUTPUT (post_processor);
+ LatexilaPostProcessorAllOutput *pp = LATEXILA_POST_PROCESSOR_ALL_OUTPUT (post_processor);
- return pp->priv->messages != NULL ? pp->priv->messages->head : NULL;
+ return pp->priv->messages != NULL ? pp->priv->messages->head : NULL;
}
static GQueue *
latexila_post_processor_all_output_take_messages (LatexilaPostProcessor *post_processor)
{
- LatexilaPostProcessorAllOutput *pp = LATEXILA_POST_PROCESSOR_ALL_OUTPUT (post_processor);
- GQueue *ret;
+ LatexilaPostProcessorAllOutput *pp = LATEXILA_POST_PROCESSOR_ALL_OUTPUT (post_processor);
+ GQueue *ret;
- ret = pp->priv->messages;
- pp->priv->messages = NULL;
+ ret = pp->priv->messages;
+ pp->priv->messages = NULL;
- return ret;
+ return ret;
}
static void
latexila_post_processor_all_output_finalize (GObject *object)
{
- LatexilaPostProcessorAllOutput *pp = LATEXILA_POST_PROCESSOR_ALL_OUTPUT (object);
+ LatexilaPostProcessorAllOutput *pp = LATEXILA_POST_PROCESSOR_ALL_OUTPUT (object);
- if (pp->priv->messages != NULL)
- g_queue_free_full (pp->priv->messages, (GDestroyNotify) latexila_build_msg_free);
+ if (pp->priv->messages != NULL)
+ {
+ g_queue_free_full (pp->priv->messages, (GDestroyNotify) latexila_build_msg_free);
+ }
- G_OBJECT_CLASS (latexila_post_processor_all_output_parent_class)->finalize (object);
+ G_OBJECT_CLASS (latexila_post_processor_all_output_parent_class)->finalize (object);
}
static void
latexila_post_processor_all_output_class_init (LatexilaPostProcessorAllOutputClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- LatexilaPostProcessorClass *post_processor_class = LATEXILA_POST_PROCESSOR_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ LatexilaPostProcessorClass *post_processor_class = LATEXILA_POST_PROCESSOR_CLASS (klass);
- object_class->finalize = latexila_post_processor_all_output_finalize;
+ object_class->finalize = latexila_post_processor_all_output_finalize;
- post_processor_class->process_line = latexila_post_processor_all_output_process_line;
- post_processor_class->get_messages = latexila_post_processor_all_output_get_messages;
- post_processor_class->take_messages = latexila_post_processor_all_output_take_messages;
+ post_processor_class->process_line = latexila_post_processor_all_output_process_line;
+ post_processor_class->get_messages = latexila_post_processor_all_output_get_messages;
+ post_processor_class->take_messages = latexila_post_processor_all_output_take_messages;
}
static void
latexila_post_processor_all_output_init (LatexilaPostProcessorAllOutput *pp)
{
- pp->priv = latexila_post_processor_all_output_get_instance_private (pp);
+ pp->priv = latexila_post_processor_all_output_get_instance_private (pp);
- pp->priv->messages = g_queue_new ();
+ pp->priv->messages = g_queue_new ();
}
/**
@@ -116,5 +118,5 @@ latexila_post_processor_all_output_init (LatexilaPostProcessorAllOutput *pp)
LatexilaPostProcessor *
latexila_post_processor_all_output_new (void)
{
- return g_object_new (LATEXILA_TYPE_POST_PROCESSOR_ALL_OUTPUT, NULL);
+ return g_object_new (LATEXILA_TYPE_POST_PROCESSOR_ALL_OUTPUT, NULL);
}
diff --git a/src/liblatexila/latexila-post-processor-latex.c b/src/liblatexila/latexila-post-processor-latex.c
index 992d0dc..0edb9ca 100644
--- a/src/liblatexila/latexila-post-processor-latex.c
+++ b/src/liblatexila/latexila-post-processor-latex.c
@@ -40,13 +40,13 @@
*/
typedef enum
{
- STATE_START,
- STATE_BADBOX,
- STATE_WARNING,
- STATE_ERROR,
- STATE_ERROR_SEARCH_LINE,
- STATE_FILENAME,
- STATE_FILENAME_HEURISTIC
+ STATE_START,
+ STATE_BADBOX,
+ STATE_WARNING,
+ STATE_ERROR,
+ STATE_ERROR_SEARCH_LINE,
+ STATE_FILENAME,
+ STATE_FILENAME_HEURISTIC
} State;
/* File opened by TeX. It is used to know on which file an error or warning
@@ -55,952 +55,965 @@ typedef enum
typedef struct _File File;
struct _File
{
- gchar *filename;
-
- /* There are basically two ways to detect the current file TeX is processing:
- * 1) Use \Input (srctex or srcltx package) and \include exclusively. This will
- * cause (La)TeX to print the line ":<+ filename" in the log file when opening
- * a file, ":<-" when closing a file. Filenames pushed on the stack in this mode
- * are marked as reliable.
- *
- * 2) Since people will probably also use the \input command, we also have to
- * detect the old-fashioned way. TeX prints '(filename' when opening a file
- * and a ')' when closing one. It is impossible to detect this with 100%
- * certainty (TeX prints many messages and even text (a context) from the
- * TeX source file, there could be unbalanced parentheses), so we use an
- * heuristic algorithm. In heuristic mode a ')' will only be considered as
- * a signal that TeX is closing a file if the top of the stack is not
- * marked as "reliable".
- *
- * The method used here is almost the same as in Kile.
- */
- guint reliable : 1;
-
- /* Non-existent files are also pushed on the stack, because the corresponding
- * ')' will pop them. If we don't push them, wrong files are popped.
- * When a new message is added, the last _existing_ file is taken.
- */
- guint exists : 1;
+ gchar *filename;
+
+ /* There are basically two ways to detect the current file TeX is processing:
+ * 1) Use \Input (srctex or srcltx package) and \include exclusively. This will
+ * cause (La)TeX to print the line ":<+ filename" in the log file when opening
+ * a file, ":<-" when closing a file. Filenames pushed on the stack in this mode
+ * are marked as reliable.
+ *
+ * 2) Since people will probably also use the \input command, we also have to
+ * detect the old-fashioned way. TeX prints '(filename' when opening a file
+ * and a ')' when closing one. It is impossible to detect this with 100%
+ * certainty (TeX prints many messages and even text (a context) from the
+ * TeX source file, there could be unbalanced parentheses), so we use an
+ * heuristic algorithm. In heuristic mode a ')' will only be considered as
+ * a signal that TeX is closing a file if the top of the stack is not
+ * marked as "reliable".
+ *
+ * The method used here is almost the same as in Kile.
+ */
+ guint reliable : 1;
+
+ /* Non-existent files are also pushed on the stack, because the corresponding
+ * ')' will pop them. If we don't push them, wrong files are popped.
+ * When a new message is added, the last _existing_ file is taken.
+ */
+ guint exists : 1;
};
struct _LatexilaPostProcessorLatexPrivate
{
- GQueue *messages;
+ GQueue *messages;
- /* Current message. */
- LatexilaBuildMsg *cur_msg;
+ /* Current message. */
+ LatexilaBuildMsg *cur_msg;
- State state;
+ State state;
- /* If a message is split into several lines, the lines are concatenated in
- * line_buffer.
- */
- GString *line_buffer;
+ /* If a message is split into several lines, the lines are concatenated in
+ * line_buffer.
+ */
+ GString *line_buffer;
- /* Number of lines in @line_buffer. */
- gint lines_count;
+ /* Number of lines in @line_buffer. */
+ gint lines_count;
- /* If a filename is split into several lines. */
- GString *filename_buffer;
+ /* If a filename is split into several lines. */
+ GString *filename_buffer;
- /* The stack containing the files that TeX is processing. The top of the stack
- * is the beginning of the list.
- * Elements type: pointer to File
- */
- GSList *stack_files;
+ /* The stack containing the files that TeX is processing. The top of the stack
+ * is the beginning of the list.
+ * Elements type: pointer to File
+ */
+ GSList *stack_files;
- /* The directory where the document is compiled. */
- /* FIXME why not storing the GFile? */
- gchar *directory_path;
+ /* The directory where the document is compiled. */
+ /* FIXME why not storing the GFile? */
+ gchar *directory_path;
- /* For statistics. */
- gint badboxes_count;
- gint warnings_count;
- gint errors_count;
+ /* For statistics. */
+ gint badboxes_count;
+ gint warnings_count;
+ gint errors_count;
};
G_DEFINE_TYPE_WITH_PRIVATE (LatexilaPostProcessorLatex,
- latexila_post_processor_latex,
- LATEXILA_TYPE_POST_PROCESSOR)
+ latexila_post_processor_latex,
+ LATEXILA_TYPE_POST_PROCESSOR)
static File *
file_new (void)
{
- return g_slice_new0 (File);
+ return g_slice_new0 (File);
}
static void
file_free (File *file)
{
- if (file != NULL)
- {
- g_free (file->filename);
- g_slice_free (File, file);
- }
+ if (file != NULL)
+ {
+ g_free (file->filename);
+ g_slice_free (File, file);
+ }
}
static void
set_line_buffer (LatexilaPostProcessorLatex *pp,
- const gchar *line)
+ const gchar *line)
{
- if (pp->priv->line_buffer != NULL)
- g_string_free (pp->priv->line_buffer, TRUE);
+ if (pp->priv->line_buffer != NULL)
+ {
+ g_string_free (pp->priv->line_buffer, TRUE);
+ }
- pp->priv->line_buffer = g_string_new (line);
- pp->priv->lines_count = 1;
+ pp->priv->line_buffer = g_string_new (line);
+ pp->priv->lines_count = 1;
}
static void
append_to_line_buffer (LatexilaPostProcessorLatex *pp,
- const gchar *line)
+ const gchar *line)
{
- if (pp->priv->line_buffer == NULL)
- {
- set_line_buffer (pp, line);
- }
- else
- {
- g_string_append (pp->priv->line_buffer, line);
- pp->priv->lines_count++;
- }
+ if (pp->priv->line_buffer == NULL)
+ {
+ set_line_buffer (pp, line);
+ }
+ else
+ {
+ g_string_append (pp->priv->line_buffer, line);
+ pp->priv->lines_count++;
+ }
}
static void
set_filename_buffer (LatexilaPostProcessorLatex *pp,
- const gchar *content)
+ const gchar *content)
{
- if (pp->priv->filename_buffer != NULL)
- g_string_free (pp->priv->filename_buffer, TRUE);
+ if (pp->priv->filename_buffer != NULL)
+ {
+ g_string_free (pp->priv->filename_buffer, TRUE);
+ }
- pp->priv->filename_buffer = g_string_new (content);
+ pp->priv->filename_buffer = g_string_new (content);
}
static void
append_to_filename_buffer (LatexilaPostProcessorLatex *pp,
- const gchar *content)
+ const gchar *content)
{
- if (pp->priv->filename_buffer == NULL)
- set_filename_buffer (pp, content);
- else
- g_string_append (pp->priv->filename_buffer, content);
+ if (pp->priv->filename_buffer == NULL)
+ {
+ set_filename_buffer (pp, content);
+ }
+ else
+ {
+ g_string_append (pp->priv->filename_buffer, content);
+ }
}
static gchar *
get_current_filename (LatexilaPostProcessorLatex *pp)
{
- GSList *l;
+ GSList *l;
- for (l = pp->priv->stack_files; l != NULL; l = l->next)
- {
- File *file = l->data;
+ for (l = pp->priv->stack_files; l != NULL; l = l->next)
+ {
+ File *file = l->data;
- /* TODO check lazily if the file exists */
- if (file->exists)
- return g_strdup (file->filename);
- }
+ /* TODO check lazily if the file exists */
+ if (file->exists)
+ {
+ return g_strdup (file->filename);
+ }
+ }
- return NULL;
+ return NULL;
}
static void
add_message (LatexilaPostProcessorLatex *pp,
- gboolean set_filename)
+ gboolean set_filename)
{
- static GRegex *regex_spaces = NULL;
- LatexilaBuildMsg *cur_msg;
- GError *error = NULL;
-
- cur_msg = pp->priv->cur_msg;
- g_return_if_fail (cur_msg != NULL);
-
- /* Exclude some useless messages. */
- if (cur_msg->type == LATEXILA_BUILD_MSG_TYPE_WARNING &&
- g_strcmp0 (cur_msg->text, "There were undefined references.") == 0)
- {
- latexila_build_msg_reinit (cur_msg);
- goto end;
- }
-
- if (set_filename)
- {
- g_free (cur_msg->filename);
- cur_msg->filename = get_current_filename (pp);
- }
-
- if (G_UNLIKELY (regex_spaces == NULL))
- {
- regex_spaces = g_regex_new ("\\s{2,}", G_REGEX_OPTIMIZE, 0, &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- error = NULL;
- }
- }
-
- if (G_LIKELY (regex_spaces != NULL))
- {
- gchar *new_text;
-
- /* A message on several lines is sometimes indented, so when the lines are
- * concatenated there are a lot of spaces. So multiple spaces are replaced
- * by one space.
- */
- new_text = g_regex_replace (regex_spaces,
- cur_msg->text,
- -1, 0, " ", 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- error = NULL;
- }
-
- if (new_text != NULL)
- {
- g_free (cur_msg->text);
- cur_msg->text = new_text;
- }
- }
-
- switch (cur_msg->type)
- {
- case LATEXILA_BUILD_MSG_TYPE_BADBOX:
- pp->priv->badboxes_count++;
- break;
-
- case LATEXILA_BUILD_MSG_TYPE_WARNING:
- pp->priv->warnings_count++;
- break;
-
- case LATEXILA_BUILD_MSG_TYPE_ERROR:
- pp->priv->errors_count++;
- break;
-
- case LATEXILA_BUILD_MSG_TYPE_MAIN_TITLE:
- case LATEXILA_BUILD_MSG_TYPE_JOB_TITLE:
- case LATEXILA_BUILD_MSG_TYPE_JOB_SUB_COMMAND:
- case LATEXILA_BUILD_MSG_TYPE_INFO:
- default:
- break;
- }
-
- g_queue_push_tail (pp->priv->messages, cur_msg);
-
- pp->priv->cur_msg = latexila_build_msg_new ();
+ static GRegex *regex_spaces = NULL;
+ LatexilaBuildMsg *cur_msg;
+ GError *error = NULL;
+
+ cur_msg = pp->priv->cur_msg;
+ g_return_if_fail (cur_msg != NULL);
+
+ /* Exclude some useless messages. */
+ if (cur_msg->type == LATEXILA_BUILD_MSG_TYPE_WARNING &&
+ g_strcmp0 (cur_msg->text, "There were undefined references.") == 0)
+ {
+ latexila_build_msg_reinit (cur_msg);
+ goto end;
+ }
+
+ if (set_filename)
+ {
+ g_free (cur_msg->filename);
+ cur_msg->filename = get_current_filename (pp);
+ }
+
+ if (G_UNLIKELY (regex_spaces == NULL))
+ {
+ regex_spaces = g_regex_new ("\\s{2,}", G_REGEX_OPTIMIZE, 0, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ }
+
+ if (G_LIKELY (regex_spaces != NULL))
+ {
+ gchar *new_text;
+
+ /* A message on several lines is sometimes indented, so when the lines are
+ * concatenated there are a lot of spaces. So multiple spaces are replaced
+ * by one space.
+ */
+ new_text = g_regex_replace (regex_spaces,
+ cur_msg->text,
+ -1, 0, " ", 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+
+ if (new_text != NULL)
+ {
+ g_free (cur_msg->text);
+ cur_msg->text = new_text;
+ }
+ }
+
+ switch (cur_msg->type)
+ {
+ case LATEXILA_BUILD_MSG_TYPE_BADBOX:
+ pp->priv->badboxes_count++;
+ break;
+
+ case LATEXILA_BUILD_MSG_TYPE_WARNING:
+ pp->priv->warnings_count++;
+ break;
+
+ case LATEXILA_BUILD_MSG_TYPE_ERROR:
+ pp->priv->errors_count++;
+ break;
+
+ case LATEXILA_BUILD_MSG_TYPE_MAIN_TITLE:
+ case LATEXILA_BUILD_MSG_TYPE_JOB_TITLE:
+ case LATEXILA_BUILD_MSG_TYPE_JOB_SUB_COMMAND:
+ case LATEXILA_BUILD_MSG_TYPE_INFO:
+ default:
+ break;
+ }
+
+ g_queue_push_tail (pp->priv->messages, cur_msg);
+
+ pp->priv->cur_msg = latexila_build_msg_new ();
end:
- pp->priv->state = STATE_START;
+ pp->priv->state = STATE_START;
- if (pp->priv->line_buffer != NULL)
- {
- g_string_free (pp->priv->line_buffer, TRUE);
- pp->priv->line_buffer = NULL;
- }
+ if (pp->priv->line_buffer != NULL)
+ {
+ g_string_free (pp->priv->line_buffer, TRUE);
+ pp->priv->line_buffer = NULL;
+ }
- pp->priv->lines_count = 0;
+ pp->priv->lines_count = 0;
}
static void
latexila_post_processor_latex_start (LatexilaPostProcessor *post_processor,
- GFile *file)
+ GFile *file)
{
- LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (post_processor);
- GFile *parent;
+ LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (post_processor);
+ GFile *parent;
- parent = g_file_get_parent (file);
+ parent = g_file_get_parent (file);
- g_free (pp->priv->directory_path);
- pp->priv->directory_path = g_file_get_parse_name (parent);
+ g_free (pp->priv->directory_path);
+ pp->priv->directory_path = g_file_get_parse_name (parent);
- g_object_unref (parent);
+ g_object_unref (parent);
}
static void
latexila_post_processor_latex_end (LatexilaPostProcessor *post_processor,
- gboolean succeeded)
+ gboolean succeeded)
{
- LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (post_processor);
- LatexilaBuildMsg *cur_msg = pp->priv->cur_msg;
-
- latexila_build_msg_reinit (cur_msg);
-
- /* Statistics. Since all the messages printed by TeX are in English, the
- * string is not translated.
- */
- cur_msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
- cur_msg->text = g_strdup_printf ("%d %s, %d %s, %d %s",
- pp->priv->errors_count,
- pp->priv->errors_count == 1 ? "error" : "errors",
- pp->priv->warnings_count,
- pp->priv->warnings_count == 1 ? "warning" : "warnings",
- pp->priv->badboxes_count,
- pp->priv->badboxes_count == 1 ? "badbox" : "badboxes");
-
- add_message (pp, FALSE);
+ LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (post_processor);
+ LatexilaBuildMsg *cur_msg = pp->priv->cur_msg;
+
+ latexila_build_msg_reinit (cur_msg);
+
+ /* Statistics. Since all the messages printed by TeX are in English, the
+ * string is not translated.
+ */
+ cur_msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
+ cur_msg->text = g_strdup_printf ("%d %s, %d %s, %d %s",
+ pp->priv->errors_count,
+ pp->priv->errors_count == 1 ? "error" : "errors",
+ pp->priv->warnings_count,
+ pp->priv->warnings_count == 1 ? "warning" : "warnings",
+ pp->priv->badboxes_count,
+ pp->priv->badboxes_count == 1 ? "badbox" : "badboxes");
+
+ add_message (pp, FALSE);
}
static void
detect_badbox_line (LatexilaPostProcessorLatex *pp,
- const gchar *badbox_line,
- gboolean current_line_is_empty)
+ const gchar *badbox_line,
+ gboolean current_line_is_empty)
{
- static GRegex *regex_badbox_lines = NULL;
- static GRegex *regex_badbox_line = NULL;
- static GRegex *regex_badbox_output = NULL;
- LatexilaBuildMsg *cur_msg = pp->priv->cur_msg;
- GError *error = NULL;
-
- if (G_UNLIKELY (regex_badbox_lines == NULL))
- {
- regex_badbox_lines = g_regex_new ("(.*) at lines (\\d+)--(\\d+)",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- return;
- }
- }
-
- if (G_UNLIKELY (regex_badbox_line == NULL))
- {
- regex_badbox_line = g_regex_new ("(.*) at line (\\d+)",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- return;
- }
- }
-
- if (G_UNLIKELY (regex_badbox_output == NULL))
- {
- regex_badbox_output = g_regex_new ("(.*)has occurred while \\\\output is active",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- return;
- }
- }
-
- if (g_regex_match (regex_badbox_lines, badbox_line, 0, NULL))
- {
- gchar **strings;
- gint n1;
- gint n2;
-
- /* TODO use g_match_info_fetch_named() */
- strings = g_regex_split (regex_badbox_lines, badbox_line, 0);
-
- g_free (cur_msg->text);
- cur_msg->text = g_strdup (strings[1]);
-
- n1 = atoi (strings[2]);
- n2 = atoi (strings[3]);
-
- if (n1 <= n2)
- {
- cur_msg->start_line = n1;
- cur_msg->end_line = n2;
- }
- else
- {
- cur_msg->start_line = n2;
- cur_msg->end_line = n1;
- }
-
- add_message (pp, TRUE);
-
- g_strfreev (strings);
- return;
- }
-
- if (g_regex_match (regex_badbox_line, badbox_line, 0, NULL))
- {
- gchar **strings;
-
- strings = g_regex_split (regex_badbox_line, badbox_line, 0);
-
- g_free (cur_msg->text);
- cur_msg->text = g_strdup (strings[1]);
-
- cur_msg->start_line = atoi (strings[2]);
-
- add_message (pp, TRUE);
-
- g_strfreev (strings);
- return;
- }
-
- if (g_regex_match (regex_badbox_output, badbox_line, 0, NULL))
- {
- gchar **strings;
-
- strings = g_regex_split (regex_badbox_output, badbox_line, 0);
-
- g_free (cur_msg->text);
- cur_msg->text = g_strdup (strings[1]);
- cur_msg->start_line = NO_LINE;
-
- add_message (pp, TRUE);
-
- g_strfreev (strings);
- return;
- }
-
- if (pp->priv->lines_count > 4 || current_line_is_empty)
- {
- g_free (cur_msg->text);
- cur_msg->text = g_strdup (badbox_line);
-
- cur_msg->start_line = NO_LINE;
-
- add_message (pp, TRUE);
- return;
- }
-
- if (pp->priv->state == STATE_START)
- {
- pp->priv->state = STATE_BADBOX;
- set_line_buffer (pp, badbox_line);
- }
+ static GRegex *regex_badbox_lines = NULL;
+ static GRegex *regex_badbox_line = NULL;
+ static GRegex *regex_badbox_output = NULL;
+ LatexilaBuildMsg *cur_msg = pp->priv->cur_msg;
+ GError *error = NULL;
+
+ if (G_UNLIKELY (regex_badbox_lines == NULL))
+ {
+ regex_badbox_lines = g_regex_new ("(.*) at lines (\\d+)--(\\d+)",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+ }
+
+ if (G_UNLIKELY (regex_badbox_line == NULL))
+ {
+ regex_badbox_line = g_regex_new ("(.*) at line (\\d+)",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+ }
+
+ if (G_UNLIKELY (regex_badbox_output == NULL))
+ {
+ regex_badbox_output = g_regex_new ("(.*)has occurred while \\\\output is active",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+ }
+
+ if (g_regex_match (regex_badbox_lines, badbox_line, 0, NULL))
+ {
+ gchar **strings;
+ gint n1;
+ gint n2;
+
+ /* TODO use g_match_info_fetch_named() */
+ strings = g_regex_split (regex_badbox_lines, badbox_line, 0);
+
+ g_free (cur_msg->text);
+ cur_msg->text = g_strdup (strings[1]);
+
+ n1 = atoi (strings[2]);
+ n2 = atoi (strings[3]);
+
+ if (n1 <= n2)
+ {
+ cur_msg->start_line = n1;
+ cur_msg->end_line = n2;
+ }
+ else
+ {
+ cur_msg->start_line = n2;
+ cur_msg->end_line = n1;
+ }
+
+ add_message (pp, TRUE);
+
+ g_strfreev (strings);
+ return;
+ }
+
+ if (g_regex_match (regex_badbox_line, badbox_line, 0, NULL))
+ {
+ gchar **strings;
+
+ strings = g_regex_split (regex_badbox_line, badbox_line, 0);
+
+ g_free (cur_msg->text);
+ cur_msg->text = g_strdup (strings[1]);
+
+ cur_msg->start_line = atoi (strings[2]);
+
+ add_message (pp, TRUE);
+
+ g_strfreev (strings);
+ return;
+ }
+
+ if (g_regex_match (regex_badbox_output, badbox_line, 0, NULL))
+ {
+ gchar **strings;
+
+ strings = g_regex_split (regex_badbox_output, badbox_line, 0);
+
+ g_free (cur_msg->text);
+ cur_msg->text = g_strdup (strings[1]);
+ cur_msg->start_line = NO_LINE;
+
+ add_message (pp, TRUE);
+
+ g_strfreev (strings);
+ return;
+ }
+
+ if (pp->priv->lines_count > 4 || current_line_is_empty)
+ {
+ g_free (cur_msg->text);
+ cur_msg->text = g_strdup (badbox_line);
+
+ cur_msg->start_line = NO_LINE;
+
+ add_message (pp, TRUE);
+ return;
+ }
+
+ if (pp->priv->state == STATE_START)
+ {
+ pp->priv->state = STATE_BADBOX;
+ set_line_buffer (pp, badbox_line);
+ }
}
static gboolean
detect_badbox (LatexilaPostProcessorLatex *pp,
- const gchar *line)
+ const gchar *line)
{
- static GRegex *regex_badbox = NULL;
- GError *error = NULL;
-
- if (G_UNLIKELY (regex_badbox == NULL))
- {
- regex_badbox = g_regex_new ("^(Over|Under)full \\\\[hv]box",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
- }
-
- switch (pp->priv->state)
- {
- case STATE_START:
- if (!g_regex_match (regex_badbox, line, 0, NULL))
- return FALSE;
-
- pp->priv->cur_msg->type = LATEXILA_BUILD_MSG_TYPE_BADBOX;
- detect_badbox_line (pp, line, FALSE);
- return TRUE;
-
- case STATE_BADBOX:
- detect_badbox_line (pp,
- pp->priv->line_buffer->str,
- line[0] == '\0');
-
- /* The return value is not important here. */
- return TRUE;
-
- case STATE_WARNING:
- case STATE_ERROR:
- case STATE_ERROR_SEARCH_LINE:
- case STATE_FILENAME:
- case STATE_FILENAME_HEURISTIC:
- default:
- g_return_val_if_reached (FALSE);
- }
+ static GRegex *regex_badbox = NULL;
+ GError *error = NULL;
+
+ if (G_UNLIKELY (regex_badbox == NULL))
+ {
+ regex_badbox = g_regex_new ("^(Over|Under)full \\\\[hv]box",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+ }
+
+ switch (pp->priv->state)
+ {
+ case STATE_START:
+ if (!g_regex_match (regex_badbox, line, 0, NULL))
+ {
+ return FALSE;
+ }
+
+ pp->priv->cur_msg->type = LATEXILA_BUILD_MSG_TYPE_BADBOX;
+ detect_badbox_line (pp, line, FALSE);
+ return TRUE;
+
+ case STATE_BADBOX:
+ detect_badbox_line (pp,
+ pp->priv->line_buffer->str,
+ line[0] == '\0');
+
+ /* The return value is not important here. */
+ return TRUE;
+
+ case STATE_WARNING:
+ case STATE_ERROR:
+ case STATE_ERROR_SEARCH_LINE:
+ case STATE_FILENAME:
+ case STATE_FILENAME_HEURISTIC:
+ default:
+ g_return_val_if_reached (FALSE);
+ }
}
static void
detect_warning_line (LatexilaPostProcessorLatex *pp,
- const gchar *warning,
- gboolean current_line_is_empty)
+ const gchar *warning,
+ gboolean current_line_is_empty)
{
- static GRegex *regex_warning_line = NULL;
- static GRegex *regex_warning_international_line = NULL;
- LatexilaBuildMsg *cur_msg = pp->priv->cur_msg;
- gint len;
- GError *error = NULL;
-
- if (G_UNLIKELY (regex_warning_line == NULL))
- {
- regex_warning_line = g_regex_new ("(.*) on input line (\\d+)\\.$",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- return;
- }
- }
-
- if (G_UNLIKELY (regex_warning_international_line == NULL))
- {
- regex_warning_international_line = g_regex_new ("(.*)(\\d+)\\.$",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- return;
- }
- }
-
- if (g_regex_match (regex_warning_line, warning, 0, NULL))
- {
- gchar **strings;
-
- strings = g_regex_split (regex_warning_line, warning, 0);
-
- g_free (cur_msg->text);
- cur_msg->text = g_strdup (strings[1]);
-
- cur_msg->start_line = atoi (strings[2]);
-
- add_message (pp, TRUE);
-
- g_strfreev (strings);
- return;
- }
-
- if (g_regex_match (regex_warning_international_line, warning, 0, NULL))
- {
- gchar **strings;
-
- strings = g_regex_split (regex_warning_international_line, warning, 0);
-
- g_free (cur_msg->text);
- cur_msg->text = g_strdup (strings[1]);
-
- cur_msg->start_line = atoi (strings[2]);
-
- add_message (pp, TRUE);
-
- g_strfreev (strings);
- return;
- }
-
- len = strlen (warning);
- if (warning[len-1] == '.' || pp->priv->lines_count > 5 || current_line_is_empty)
- {
- g_free (cur_msg->text);
- cur_msg->text = g_strdup (warning);
-
- cur_msg->start_line = NO_LINE;
-
- add_message (pp, TRUE);
- return;
- }
-
- if (pp->priv->state == STATE_START)
- {
- pp->priv->state = STATE_WARNING;
- set_line_buffer (pp, warning);
- }
+ static GRegex *regex_warning_line = NULL;
+ static GRegex *regex_warning_international_line = NULL;
+ LatexilaBuildMsg *cur_msg = pp->priv->cur_msg;
+ gint len;
+ GError *error = NULL;
+
+ if (G_UNLIKELY (regex_warning_line == NULL))
+ {
+ regex_warning_line = g_regex_new ("(.*) on input line (\\d+)\\.$",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+ }
+
+ if (G_UNLIKELY (regex_warning_international_line == NULL))
+ {
+ regex_warning_international_line = g_regex_new ("(.*)(\\d+)\\.$",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+ }
+
+ if (g_regex_match (regex_warning_line, warning, 0, NULL))
+ {
+ gchar **strings;
+
+ strings = g_regex_split (regex_warning_line, warning, 0);
+
+ g_free (cur_msg->text);
+ cur_msg->text = g_strdup (strings[1]);
+
+ cur_msg->start_line = atoi (strings[2]);
+
+ add_message (pp, TRUE);
+
+ g_strfreev (strings);
+ return;
+ }
+
+ if (g_regex_match (regex_warning_international_line, warning, 0, NULL))
+ {
+ gchar **strings;
+
+ strings = g_regex_split (regex_warning_international_line, warning, 0);
+
+ g_free (cur_msg->text);
+ cur_msg->text = g_strdup (strings[1]);
+
+ cur_msg->start_line = atoi (strings[2]);
+
+ add_message (pp, TRUE);
+
+ g_strfreev (strings);
+ return;
+ }
+
+ len = strlen (warning);
+ if (warning[len-1] == '.' || pp->priv->lines_count > 5 || current_line_is_empty)
+ {
+ g_free (cur_msg->text);
+ cur_msg->text = g_strdup (warning);
+
+ cur_msg->start_line = NO_LINE;
+
+ add_message (pp, TRUE);
+ return;
+ }
+
+ if (pp->priv->state == STATE_START)
+ {
+ pp->priv->state = STATE_WARNING;
+ set_line_buffer (pp, warning);
+ }
}
static gboolean
detect_warning (LatexilaPostProcessorLatex *pp,
- const gchar *line)
+ const gchar *line)
{
- static GRegex *regex_warning = NULL;
- static GRegex *regex_warning_no_file = NULL;
- LatexilaBuildMsg *cur_msg = pp->priv->cur_msg;
- GMatchInfo *match_info;
- GError *error = NULL;
-
- if (G_UNLIKELY (regex_warning == NULL))
- {
- regex_warning = g_regex_new ("^(((! )?(La|pdf)TeX)|Package|Class)"
- "(?P<name>.*) Warning[^:]*:\\s*(?P<contents>.*)",
- G_REGEX_OPTIMIZE | G_REGEX_CASELESS,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
- }
-
- if (G_UNLIKELY (regex_warning_no_file == NULL))
- {
- regex_warning_no_file = g_regex_new ("(No file .*)",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
- }
-
- switch (pp->priv->state)
- {
- case STATE_START:
- g_regex_match (regex_warning, line, 0, &match_info);
- if (g_match_info_matches (match_info))
- {
- gchar *contents;
- gchar *name;
-
- cur_msg->type = LATEXILA_BUILD_MSG_TYPE_WARNING;
-
- contents = g_match_info_fetch_named (match_info, "contents");
- name = g_match_info_fetch_named (match_info, "name");
- name = g_strstrip (name);
-
- if (name[0] != '\0')
- {
- gchar *new_contents = g_strdup_printf ("%s: %s", name, contents);
- g_free (contents);
- contents = new_contents;
- }
-
- detect_warning_line (pp, contents, FALSE);
-
- g_free (contents);
- g_free (name);
- g_match_info_free (match_info);
- return TRUE;
- }
-
- g_match_info_free (match_info);
- match_info = NULL;
-
- if (g_regex_match (regex_warning_no_file, line, 0, NULL))
- {
- gchar **strings;
-
- cur_msg->type = LATEXILA_BUILD_MSG_TYPE_WARNING;
-
- strings = g_regex_split (regex_warning_no_file, line, 0);
-
- g_free (cur_msg->text);
- cur_msg->text = g_strdup (strings[1]);
-
- cur_msg->start_line = NO_LINE;
-
- add_message (pp, TRUE);
-
- g_strfreev (strings);
- return TRUE;
- }
-
- return FALSE;
-
- case STATE_WARNING:
- detect_warning_line (pp,
- pp->priv->line_buffer->str,
- line[0] == '\0');
-
- /* The return value is not important here. */
- return TRUE;
-
- case STATE_BADBOX:
- case STATE_ERROR:
- case STATE_ERROR_SEARCH_LINE:
- case STATE_FILENAME:
- case STATE_FILENAME_HEURISTIC:
- default:
- g_return_val_if_reached (FALSE);
- }
+ static GRegex *regex_warning = NULL;
+ static GRegex *regex_warning_no_file = NULL;
+ LatexilaBuildMsg *cur_msg = pp->priv->cur_msg;
+ GMatchInfo *match_info;
+ GError *error = NULL;
+
+ if (G_UNLIKELY (regex_warning == NULL))
+ {
+ regex_warning = g_regex_new ("^(((! )?(La|pdf)TeX)|Package|Class)"
+ "(?P<name>.*) Warning[^:]*:\\s*(?P<contents>.*)",
+ G_REGEX_OPTIMIZE | G_REGEX_CASELESS,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+ }
+
+ if (G_UNLIKELY (regex_warning_no_file == NULL))
+ {
+ regex_warning_no_file = g_regex_new ("(No file .*)",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+ }
+
+ switch (pp->priv->state)
+ {
+ case STATE_START:
+ g_regex_match (regex_warning, line, 0, &match_info);
+ if (g_match_info_matches (match_info))
+ {
+ gchar *contents;
+ gchar *name;
+
+ cur_msg->type = LATEXILA_BUILD_MSG_TYPE_WARNING;
+
+ contents = g_match_info_fetch_named (match_info, "contents");
+ name = g_match_info_fetch_named (match_info, "name");
+ name = g_strstrip (name);
+
+ if (name[0] != '\0')
+ {
+ gchar *new_contents = g_strdup_printf ("%s: %s", name, contents);
+ g_free (contents);
+ contents = new_contents;
+ }
+
+ detect_warning_line (pp, contents, FALSE);
+
+ g_free (contents);
+ g_free (name);
+ g_match_info_free (match_info);
+ return TRUE;
+ }
+
+ g_match_info_free (match_info);
+ match_info = NULL;
+
+ if (g_regex_match (regex_warning_no_file, line, 0, NULL))
+ {
+ gchar **strings;
+
+ cur_msg->type = LATEXILA_BUILD_MSG_TYPE_WARNING;
+
+ strings = g_regex_split (regex_warning_no_file, line, 0);
+
+ g_free (cur_msg->text);
+ cur_msg->text = g_strdup (strings[1]);
+
+ cur_msg->start_line = NO_LINE;
+
+ add_message (pp, TRUE);
+
+ g_strfreev (strings);
+ return TRUE;
+ }
+
+ return FALSE;
+
+ case STATE_WARNING:
+ detect_warning_line (pp,
+ pp->priv->line_buffer->str,
+ line[0] == '\0');
+
+ /* The return value is not important here. */
+ return TRUE;
+
+ case STATE_BADBOX:
+ case STATE_ERROR:
+ case STATE_ERROR_SEARCH_LINE:
+ case STATE_FILENAME:
+ case STATE_FILENAME_HEURISTIC:
+ default:
+ g_return_val_if_reached (FALSE);
+ }
}
static gboolean
detect_error (LatexilaPostProcessorLatex *pp,
- const gchar *line)
+ const gchar *line)
{
- static GRegex *regex_latex_error = NULL;
- static GRegex *regex_pdflatex_error = NULL;
- static GRegex *regex_tex_error = NULL;
- static GRegex *regex_error_line = NULL;
- gboolean found;
- gchar *msg;
- gint len;
- LatexilaBuildMsg *cur_msg = pp->priv->cur_msg;
- GError *error = NULL;
-
- if (G_UNLIKELY (regex_latex_error == NULL))
- {
- regex_latex_error = g_regex_new ("^! LaTeX Error: (.*)$",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
- }
-
- if (G_UNLIKELY (regex_pdflatex_error == NULL))
- {
- regex_pdflatex_error = g_regex_new ("^Error: pdflatex (.*)$",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
- }
-
- if (G_UNLIKELY (regex_tex_error == NULL))
- {
- regex_tex_error = g_regex_new ("^! (.*)\\.$",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
- }
-
- if (G_UNLIKELY (regex_error_line == NULL))
- {
- regex_error_line = g_regex_new ("^l\\.(\\d+)(.*)",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
- }
-
- switch (pp->priv->state)
- {
- case STATE_START:
- found = FALSE;
- msg = NULL;
-
- if (g_regex_match (regex_latex_error, line, 0, NULL))
- {
- gchar **strings = g_regex_split (regex_latex_error, line, 0);
- msg = g_strdup (strings[1]);
- found = TRUE;
- g_strfreev (strings);
- }
- else if (g_regex_match (regex_pdflatex_error, line, 0, NULL))
- {
- gchar **strings = g_regex_split (regex_pdflatex_error, line, 0);
- msg = g_strdup (strings[1]);
- found = TRUE;
- g_strfreev (strings);
- }
- else if (g_regex_match (regex_tex_error, line, 0, NULL))
- {
- gchar **strings = g_regex_split (regex_tex_error, line, 0);
- msg = g_strdup (strings[1]);
- found = TRUE;
- g_strfreev (strings);
- }
-
- if (found)
- {
- pp->priv->lines_count++;
- cur_msg->type = LATEXILA_BUILD_MSG_TYPE_ERROR;
-
- len = strlen (line);
-
- /* The message is complete. */
- if (line[len-1] == '.')
- {
- g_free (cur_msg->text);
- cur_msg->text = msg;
-
- pp->priv->state = STATE_ERROR_SEARCH_LINE;
- }
-
- /* The message is split into several lines. */
- else
- {
- set_line_buffer (pp, msg);
- pp->priv->state = STATE_ERROR;
- g_free (msg);
- }
-
- return TRUE;
- }
-
- return FALSE;
-
- case STATE_ERROR:
- len = strlen (line);
-
- if (line[len-1] == '.')
- {
- g_free (cur_msg->text);
- cur_msg->text = g_string_free (pp->priv->line_buffer, FALSE);
- pp->priv->line_buffer = NULL;
-
- /* FIXME set lines_count to 0? */
-
- pp->priv->state = STATE_ERROR_SEARCH_LINE;
- }
- else if (pp->priv->lines_count > 4)
- {
- g_free (cur_msg->text);
- cur_msg->text = g_string_free (pp->priv->line_buffer, FALSE);
- pp->priv->line_buffer = NULL;
-
- cur_msg->start_line = NO_LINE;
-
- add_message (pp, TRUE);
- }
-
- /* The return value is not important here. */
- return TRUE;
-
- case STATE_ERROR_SEARCH_LINE:
- if (g_regex_match (regex_error_line, line, 0, NULL))
- {
- gchar **strings = g_regex_split (regex_error_line, line, 0);
- cur_msg->start_line = atoi (strings[1]);
-
- add_message (pp, TRUE);
-
- g_strfreev (strings);
- return TRUE;
- }
- else if (pp->priv->lines_count > 11)
- {
- cur_msg->start_line = NO_LINE;
- add_message (pp, TRUE);
- return TRUE;
- }
-
- return FALSE;
-
- case STATE_BADBOX:
- case STATE_WARNING:
- case STATE_FILENAME:
- case STATE_FILENAME_HEURISTIC:
- default:
- g_return_val_if_reached (FALSE);
- }
+ static GRegex *regex_latex_error = NULL;
+ static GRegex *regex_pdflatex_error = NULL;
+ static GRegex *regex_tex_error = NULL;
+ static GRegex *regex_error_line = NULL;
+ gboolean found;
+ gchar *msg;
+ gint len;
+ LatexilaBuildMsg *cur_msg = pp->priv->cur_msg;
+ GError *error = NULL;
+
+ if (G_UNLIKELY (regex_latex_error == NULL))
+ {
+ regex_latex_error = g_regex_new ("^! LaTeX Error: (.*)$",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+ }
+
+ if (G_UNLIKELY (regex_pdflatex_error == NULL))
+ {
+ regex_pdflatex_error = g_regex_new ("^Error: pdflatex (.*)$",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+ }
+
+ if (G_UNLIKELY (regex_tex_error == NULL))
+ {
+ regex_tex_error = g_regex_new ("^! (.*)\\.$",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+ }
+
+ if (G_UNLIKELY (regex_error_line == NULL))
+ {
+ regex_error_line = g_regex_new ("^l\\.(\\d+)(.*)",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+ }
+
+ switch (pp->priv->state)
+ {
+ case STATE_START:
+ found = FALSE;
+ msg = NULL;
+
+ if (g_regex_match (regex_latex_error, line, 0, NULL))
+ {
+ gchar **strings = g_regex_split (regex_latex_error, line, 0);
+ msg = g_strdup (strings[1]);
+ found = TRUE;
+ g_strfreev (strings);
+ }
+ else if (g_regex_match (regex_pdflatex_error, line, 0, NULL))
+ {
+ gchar **strings = g_regex_split (regex_pdflatex_error, line, 0);
+ msg = g_strdup (strings[1]);
+ found = TRUE;
+ g_strfreev (strings);
+ }
+ else if (g_regex_match (regex_tex_error, line, 0, NULL))
+ {
+ gchar **strings = g_regex_split (regex_tex_error, line, 0);
+ msg = g_strdup (strings[1]);
+ found = TRUE;
+ g_strfreev (strings);
+ }
+
+ if (found)
+ {
+ pp->priv->lines_count++;
+ cur_msg->type = LATEXILA_BUILD_MSG_TYPE_ERROR;
+
+ len = strlen (line);
+
+ /* The message is complete. */
+ if (line[len-1] == '.')
+ {
+ g_free (cur_msg->text);
+ cur_msg->text = msg;
+
+ pp->priv->state = STATE_ERROR_SEARCH_LINE;
+ }
+ /* The message is split into several lines. */
+ else
+ {
+ set_line_buffer (pp, msg);
+ pp->priv->state = STATE_ERROR;
+ g_free (msg);
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+
+ case STATE_ERROR:
+ len = strlen (line);
+
+ if (line[len-1] == '.')
+ {
+ g_free (cur_msg->text);
+ cur_msg->text = g_string_free (pp->priv->line_buffer, FALSE);
+ pp->priv->line_buffer = NULL;
+
+ /* FIXME set lines_count to 0? */
+
+ pp->priv->state = STATE_ERROR_SEARCH_LINE;
+ }
+ else if (pp->priv->lines_count > 4)
+ {
+ g_free (cur_msg->text);
+ cur_msg->text = g_string_free (pp->priv->line_buffer, FALSE);
+ pp->priv->line_buffer = NULL;
+
+ cur_msg->start_line = NO_LINE;
+
+ add_message (pp, TRUE);
+ }
+
+ /* The return value is not important here. */
+ return TRUE;
+
+ case STATE_ERROR_SEARCH_LINE:
+ if (g_regex_match (regex_error_line, line, 0, NULL))
+ {
+ gchar **strings = g_regex_split (regex_error_line, line, 0);
+ cur_msg->start_line = atoi (strings[1]);
+
+ add_message (pp, TRUE);
+
+ g_strfreev (strings);
+ return TRUE;
+ }
+ else if (pp->priv->lines_count > 11)
+ {
+ cur_msg->start_line = NO_LINE;
+ add_message (pp, TRUE);
+ return TRUE;
+ }
+
+ return FALSE;
+
+ case STATE_BADBOX:
+ case STATE_WARNING:
+ case STATE_FILENAME:
+ case STATE_FILENAME_HEURISTIC:
+ default:
+ g_return_val_if_reached (FALSE);
+ }
}
static gboolean
detect_other (LatexilaPostProcessorLatex *pp,
- const gchar *line)
+ const gchar *line)
{
- static GRegex *regex_other_bytes = NULL;
- LatexilaBuildMsg *cur_msg = pp->priv->cur_msg;
- GMatchInfo *match_info;
- GError *error = NULL;
-
- if (G_UNLIKELY (regex_other_bytes == NULL))
- {
- regex_other_bytes = g_regex_new ("(?P<nb>\\d+) bytes",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
- }
-
- if (strstr (line, "Output written on") == NULL)
- return FALSE;
-
- cur_msg->start_line = NO_LINE;
- cur_msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
-
- g_regex_match (regex_other_bytes, line, 0, &match_info);
-
- if (g_match_info_matches (match_info))
- {
- gchar *nb_bytes_str;
- glong nb_bytes;
- gchar *human_size;
- gchar *new_line;
-
- nb_bytes_str = g_match_info_fetch_named (match_info, "nb");
- g_return_val_if_fail (nb_bytes_str != NULL, FALSE);
-
- nb_bytes = atol (nb_bytes_str);
- human_size = g_format_size (nb_bytes);
-
- new_line = g_regex_replace_literal (regex_other_bytes, line, -1, 0, human_size, 0, &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- error = NULL;
-
- g_free (cur_msg->text);
- cur_msg->text = g_strdup (line);
- }
- else
- {
- g_free (cur_msg->text);
- cur_msg->text = new_line;
- }
-
- g_free (nb_bytes_str);
- g_free (human_size);
- }
- else
- {
- g_free (cur_msg->text);
- cur_msg->text = g_strdup (line);
- }
-
- add_message (pp, FALSE);
-
- g_match_info_free (match_info);
- return TRUE;
+ static GRegex *regex_other_bytes = NULL;
+ LatexilaBuildMsg *cur_msg = pp->priv->cur_msg;
+ GMatchInfo *match_info;
+ GError *error = NULL;
+
+ if (G_UNLIKELY (regex_other_bytes == NULL))
+ {
+ regex_other_bytes = g_regex_new ("(?P<nb>\\d+) bytes",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+ }
+
+ if (strstr (line, "Output written on") == NULL)
+ {
+ return FALSE;
+ }
+
+ cur_msg->start_line = NO_LINE;
+ cur_msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
+
+ g_regex_match (regex_other_bytes, line, 0, &match_info);
+
+ if (g_match_info_matches (match_info))
+ {
+ gchar *nb_bytes_str;
+ glong nb_bytes;
+ gchar *human_size;
+ gchar *new_line;
+
+ nb_bytes_str = g_match_info_fetch_named (match_info, "nb");
+ g_return_val_if_fail (nb_bytes_str != NULL, FALSE);
+
+ nb_bytes = atol (nb_bytes_str);
+ human_size = g_format_size (nb_bytes);
+
+ new_line = g_regex_replace_literal (regex_other_bytes, line, -1, 0, human_size, 0, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ g_free (cur_msg->text);
+ cur_msg->text = g_strdup (line);
+ }
+ else
+ {
+ g_free (cur_msg->text);
+ cur_msg->text = new_line;
+ }
+
+ g_free (nb_bytes_str);
+ g_free (human_size);
+ }
+ else
+ {
+ g_free (cur_msg->text);
+ cur_msg->text = g_strdup (line);
+ }
+
+ add_message (pp, FALSE);
+
+ g_match_info_free (match_info);
+ return TRUE;
}
/* Returns NULL if the filename does not exist.
@@ -1008,452 +1021,481 @@ detect_other (LatexilaPostProcessorLatex *pp,
*/
static gchar *
get_path_if_file_exists (LatexilaPostProcessorLatex *pp,
- const gchar *filename)
+ const gchar *filename)
{
- gchar *full_path;
- const gchar *extensions[] = {".tex", ".ltx", ".latex", ".dtx", ".ins", NULL};
- gint i;
-
- if (g_path_is_absolute (filename))
- {
- if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
- return g_strdup (filename);
- else
- return NULL;
- }
-
- if (g_str_has_prefix (filename, "./"))
- full_path = g_build_filename (pp->priv->directory_path,
- filename + 2,
- NULL);
- else
- full_path = g_build_filename (pp->priv->directory_path,
- filename,
- NULL);
-
- if (g_file_test (full_path, G_FILE_TEST_IS_REGULAR))
- return full_path;
-
- for (i = 0; extensions[i] != NULL; i++)
- {
- gchar *path_with_ext = g_strdup_printf ("%s%s", full_path, extensions[i]);
-
- if (g_file_test (path_with_ext, G_FILE_TEST_IS_REGULAR))
- {
- g_free (full_path);
- return path_with_ext;
- }
-
- g_free (path_with_ext);
- }
-
- g_free (full_path);
- return NULL;
+ gchar *full_path;
+ const gchar *extensions[] = {".tex", ".ltx", ".latex", ".dtx", ".ins", NULL};
+ gint i;
+
+ if (g_path_is_absolute (filename))
+ {
+ if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
+ {
+ return g_strdup (filename);
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+
+ if (g_str_has_prefix (filename, "./"))
+ {
+ full_path = g_build_filename (pp->priv->directory_path,
+ filename + 2,
+ NULL);
+ }
+ else
+ {
+ full_path = g_build_filename (pp->priv->directory_path,
+ filename,
+ NULL);
+ }
+
+ if (g_file_test (full_path, G_FILE_TEST_IS_REGULAR))
+ {
+ return full_path;
+ }
+
+ for (i = 0; extensions[i] != NULL; i++)
+ {
+ gchar *path_with_ext = g_strdup_printf ("%s%s", full_path, extensions[i]);
+
+ if (g_file_test (path_with_ext, G_FILE_TEST_IS_REGULAR))
+ {
+ g_free (full_path);
+ return path_with_ext;
+ }
+
+ g_free (path_with_ext);
+ }
+
+ g_free (full_path);
+ return NULL;
}
static void
push_file_on_stack (LatexilaPostProcessorLatex *pp,
- gboolean reliable)
+ gboolean reliable)
{
- File *file;
- const gchar *bad_suffix = "pdfTeX";
- gchar *path;
-
- file = file_new ();
- file->reliable = reliable;
- file->filename = g_string_free (pp->priv->filename_buffer, FALSE);
- pp->priv->filename_buffer = NULL;
-
- /* Handle special case when a warning message is collapsed. */
- if (g_str_has_suffix (file->filename, bad_suffix))
- {
- gint pos = strlen (file->filename) - strlen (bad_suffix);
- file->filename[pos] = '\0';
- }
-
- path = get_path_if_file_exists (pp, file->filename);
-
- if (path != NULL)
- {
- g_free (file->filename);
- file->filename = path;
- file->exists = TRUE;
- }
- else
- {
- file->exists = FALSE;
- }
-
- pp->priv->stack_files = g_slist_prepend (pp->priv->stack_files, file);
+ File *file;
+ const gchar *bad_suffix = "pdfTeX";
+ gchar *path;
+
+ file = file_new ();
+ file->reliable = reliable;
+ file->filename = g_string_free (pp->priv->filename_buffer, FALSE);
+ pp->priv->filename_buffer = NULL;
+
+ /* Handle special case when a warning message is collapsed. */
+ if (g_str_has_suffix (file->filename, bad_suffix))
+ {
+ gint pos = strlen (file->filename) - strlen (bad_suffix);
+ file->filename[pos] = '\0';
+ }
+
+ path = get_path_if_file_exists (pp, file->filename);
+
+ if (path != NULL)
+ {
+ g_free (file->filename);
+ file->filename = path;
+ file->exists = TRUE;
+ }
+ else
+ {
+ file->exists = FALSE;
+ }
+
+ pp->priv->stack_files = g_slist_prepend (pp->priv->stack_files, file);
}
static void
pop_file_from_stack (LatexilaPostProcessorLatex *pp)
{
- if (pp->priv->stack_files != NULL)
- {
- File *file = pp->priv->stack_files->data;
- file_free (file);
- }
-
- pp->priv->stack_files = g_slist_remove_link (pp->priv->stack_files,
- pp->priv->stack_files);
+ if (pp->priv->stack_files != NULL)
+ {
+ File *file = pp->priv->stack_files->data;
+ file_free (file);
+ }
+
+ pp->priv->stack_files = g_slist_remove_link (pp->priv->stack_files,
+ pp->priv->stack_files);
}
static gboolean
file_exists (LatexilaPostProcessorLatex *pp,
- const gchar *filename)
+ const gchar *filename)
{
- gchar *path;
- gboolean ret;
+ gchar *path;
+ gboolean ret;
- path = get_path_if_file_exists (pp, filename);
- ret = path != NULL;
+ path = get_path_if_file_exists (pp, filename);
+ ret = path != NULL;
- g_free (path);
- return ret;
+ g_free (path);
+ return ret;
}
static void
update_stack_file_heuristic (LatexilaPostProcessorLatex *pp,
- const gchar *line)
+ const gchar *line)
{
- gboolean expect_filename;
- const gchar *line_pos;
- const gchar *line_pos_next;
-
- /* This is where the filename is supposed to start. */
- const gchar *start_filename = line;
-
- expect_filename = pp->priv->state == STATE_FILENAME_HEURISTIC;
-
- /* Handle special case. */
- if (expect_filename && line[0] == ')')
- {
- push_file_on_stack (pp, FALSE);
- expect_filename = FALSE;
- pp->priv->state = STATE_START;
- }
-
- for (line_pos = line; line_pos[0] != '\0'; line_pos = line_pos_next)
- {
- gboolean is_last_char = FALSE;
- gboolean next_is_terminator = FALSE;
- gunichar cur_char = g_utf8_get_char (line_pos);
-
- line_pos_next = g_utf8_next_char (line_pos);
-
- /* We're expecting a filename. If a filename really ends at this position,
- * one of the following must be true:
- * 1) Next character is a space, indicating the end of a filename
- * (yes, the path can't have spaces, this is a TeX limitation).
- * 2) We're at the end of the line, the filename is probably
- * continued on the next line.
- * 3) The file was closed already, signalled by the ')'.
- */
-
- if (expect_filename)
- {
- is_last_char = line_pos_next[0] == '\0';
-
- if (is_last_char)
- {
- next_is_terminator = FALSE;
- }
- else
- {
- gunichar next_char = g_utf8_get_char (line_pos_next);
- next_is_terminator = (g_unichar_isspace (next_char) || next_char == ')');
- }
- }
-
- if (is_last_char || next_is_terminator)
- {
- gint pos;
-
- if (pp->priv->filename_buffer == NULL)
- set_filename_buffer (pp, "");
-
- g_string_append_len (pp->priv->filename_buffer,
- start_filename,
- line_pos_next - start_filename);
-
- if (pp->priv->filename_buffer->len == 0)
- continue;
-
- pos = line_pos - line;
-
- /* By default, an output line is 79 characters max. */
- if ((is_last_char && pos < 78) ||
- next_is_terminator ||
- file_exists (pp, pp->priv->filename_buffer->str))
- {
- push_file_on_stack (pp, FALSE);
- expect_filename = FALSE;
- pp->priv->state = STATE_START;
- }
-
- /* Guess the filename is continued on the next line, only if the
- * current filename does not exist.
- */
- else
- {
- g_assert (is_last_char);
-
- if (file_exists (pp, pp->priv->filename_buffer->str))
- {
- push_file_on_stack (pp, FALSE);
- expect_filename = FALSE;
- pp->priv->state = STATE_START;
- }
- else
- {
- pp->priv->state = STATE_FILENAME_HEURISTIC;
- }
- }
- }
-
- /* TeX is opening a file. */
- else if (cur_char == '(')
- {
- pp->priv->state = STATE_START;
- set_filename_buffer (pp, "");
-
- /* We need to extract the filename. */
- expect_filename = TRUE;
- start_filename = line_pos_next;
- }
-
- /* TeX is closing a file.
- * If this filename was pushed on the stack by the reliable ":<+-"
- * method, don't pop, a ":<-" will follow. This helps in preventing
- * unbalanced ')' from popping filenames from the stack too soon.
- */
- else if (cur_char == ')' && pp->priv->stack_files != NULL)
- {
- File *file = pp->priv->stack_files->data;
-
- if (!file->reliable)
- pop_file_from_stack (pp);
- }
- }
+ gboolean expect_filename;
+ const gchar *line_pos;
+ const gchar *line_pos_next;
+
+ /* This is where the filename is supposed to start. */
+ const gchar *start_filename = line;
+
+ expect_filename = pp->priv->state == STATE_FILENAME_HEURISTIC;
+
+ /* Handle special case. */
+ if (expect_filename && line[0] == ')')
+ {
+ push_file_on_stack (pp, FALSE);
+ expect_filename = FALSE;
+ pp->priv->state = STATE_START;
+ }
+
+ for (line_pos = line; line_pos[0] != '\0'; line_pos = line_pos_next)
+ {
+ gboolean is_last_char = FALSE;
+ gboolean next_is_terminator = FALSE;
+ gunichar cur_char = g_utf8_get_char (line_pos);
+
+ line_pos_next = g_utf8_next_char (line_pos);
+
+ /* We're expecting a filename. If a filename really ends at this position,
+ * one of the following must be true:
+ * 1) Next character is a space, indicating the end of a filename
+ * (yes, the path can't have spaces, this is a TeX limitation).
+ * 2) We're at the end of the line, the filename is probably
+ * continued on the next line.
+ * 3) The file was closed already, signalled by the ')'.
+ */
+
+ if (expect_filename)
+ {
+ is_last_char = line_pos_next[0] == '\0';
+
+ if (is_last_char)
+ {
+ next_is_terminator = FALSE;
+ }
+ else
+ {
+ gunichar next_char = g_utf8_get_char (line_pos_next);
+ next_is_terminator = (g_unichar_isspace (next_char) || next_char == ')');
+ }
+ }
+
+ if (is_last_char || next_is_terminator)
+ {
+ gint pos;
+
+ if (pp->priv->filename_buffer == NULL)
+ {
+ set_filename_buffer (pp, "");
+ }
+
+ g_string_append_len (pp->priv->filename_buffer,
+ start_filename,
+ line_pos_next - start_filename);
+
+ if (pp->priv->filename_buffer->len == 0)
+ {
+ continue;
+ }
+
+ pos = line_pos - line;
+
+ /* By default, an output line is 79 characters max. */
+ if ((is_last_char && pos < 78) ||
+ next_is_terminator ||
+ file_exists (pp, pp->priv->filename_buffer->str))
+ {
+ push_file_on_stack (pp, FALSE);
+ expect_filename = FALSE;
+ pp->priv->state = STATE_START;
+ }
+ /* Guess the filename is continued on the next line, only if the
+ * current filename does not exist.
+ */
+ else
+ {
+ g_assert (is_last_char);
+
+ if (file_exists (pp, pp->priv->filename_buffer->str))
+ {
+ push_file_on_stack (pp, FALSE);
+ expect_filename = FALSE;
+ pp->priv->state = STATE_START;
+ }
+ else
+ {
+ pp->priv->state = STATE_FILENAME_HEURISTIC;
+ }
+ }
+ }
+ /* TeX is opening a file. */
+ else if (cur_char == '(')
+ {
+ pp->priv->state = STATE_START;
+ set_filename_buffer (pp, "");
+
+ /* We need to extract the filename. */
+ expect_filename = TRUE;
+ start_filename = line_pos_next;
+ }
+ /* TeX is closing a file.
+ * If this filename was pushed on the stack by the reliable ":<+-"
+ * method, don't pop, a ":<-" will follow. This helps in preventing
+ * unbalanced ')' from popping filenames from the stack too soon.
+ */
+ else if (cur_char == ')' && pp->priv->stack_files != NULL)
+ {
+ File *file = pp->priv->stack_files->data;
+
+ if (!file->reliable)
+ {
+ pop_file_from_stack (pp);
+ }
+ }
+ }
}
static void
update_stack_file (LatexilaPostProcessorLatex *pp,
- const gchar *line)
+ const gchar *line)
{
- static GRegex *regex_file_pop = NULL;
- GError *error = NULL;
-
- if (G_UNLIKELY (regex_file_pop == NULL))
- {
- regex_file_pop = g_regex_new ("(\\) )?:<-$",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatex: %s", error->message);
- g_error_free (error);
- return;
- }
- }
-
- switch (pp->priv->state)
- {
- case STATE_START:
- case STATE_FILENAME_HEURISTIC:
- /* TeX is opening a file. */
- if (g_str_has_prefix (line, ":<+ "))
- {
- gchar *filename;
-
- filename = g_strdup (line + 4);
- g_strstrip (filename);
-
- set_filename_buffer (pp, filename);
- g_free (filename);
-
- pp->priv->state = STATE_FILENAME;
- }
-
- /* TeX closed a file. */
- else if (g_regex_match (regex_file_pop, line, 0, NULL) ||
- g_str_has_prefix (line, ":<-"))
- pop_file_from_stack (pp);
-
- /* Fallback to the heuristic detection of filenames. */
- else
- update_stack_file_heuristic (pp, line);
- break;
-
- case STATE_FILENAME:
- /* The partial filename was followed by '(', this means that TeX is
- * signalling it is opening the file. We are sure the filename is
- * complete now. Don't call update_stack_file_heuristic()
- * since we don't want the filename on the stack twice.
- */
- if (line[0] == '(' ||
- g_str_has_prefix (line, "\\openout"))
- {
- push_file_on_stack (pp, TRUE);
- pp->priv->state = STATE_START;
- }
-
- /* The partial filename was followed by a TeX error, meaning the
- * file doesn't exist. Don't push it on the stack, instead try to
- * detect the error.
- */
- else if (line[0] == '!')
- {
- pp->priv->state = STATE_START;
- detect_error (pp, line);
- }
- else if (g_str_has_prefix (line, "No file"))
- {
- pp->priv->state = STATE_START;
- detect_warning (pp, line);
- }
-
- /* The filename is not complete. */
- else
- {
- gchar *line_stripped = g_strdup (line);
- g_strstrip (line_stripped);
- append_to_filename_buffer (pp, line_stripped);
- g_free (line_stripped);
- }
- break;
-
- case STATE_BADBOX:
- case STATE_WARNING:
- case STATE_ERROR:
- case STATE_ERROR_SEARCH_LINE:
- default:
- g_return_if_reached ();
- }
+ static GRegex *regex_file_pop = NULL;
+ GError *error = NULL;
+
+ if (G_UNLIKELY (regex_file_pop == NULL))
+ {
+ regex_file_pop = g_regex_new ("(\\) )?:<-$",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatex: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+ }
+
+ switch (pp->priv->state)
+ {
+ case STATE_START:
+ case STATE_FILENAME_HEURISTIC:
+ /* TeX is opening a file. */
+ if (g_str_has_prefix (line, ":<+ "))
+ {
+ gchar *filename;
+
+ filename = g_strdup (line + 4);
+ g_strstrip (filename);
+
+ set_filename_buffer (pp, filename);
+ g_free (filename);
+
+ pp->priv->state = STATE_FILENAME;
+ }
+ /* TeX closed a file. */
+ else if (g_regex_match (regex_file_pop, line, 0, NULL) ||
+ g_str_has_prefix (line, ":<-"))
+ {
+ pop_file_from_stack (pp);
+ }
+ /* Fallback to the heuristic detection of filenames. */
+ else
+ {
+ update_stack_file_heuristic (pp, line);
+ }
+ break;
+
+ case STATE_FILENAME:
+ /* The partial filename was followed by '(', this means that TeX is
+ * signalling it is opening the file. We are sure the filename is
+ * complete now. Don't call update_stack_file_heuristic()
+ * since we don't want the filename on the stack twice.
+ */
+ if (line[0] == '(' ||
+ g_str_has_prefix (line, "\\openout"))
+ {
+ push_file_on_stack (pp, TRUE);
+ pp->priv->state = STATE_START;
+ }
+ /* The partial filename was followed by a TeX error, meaning the
+ * file doesn't exist. Don't push it on the stack, instead try to
+ * detect the error.
+ */
+ else if (line[0] == '!')
+ {
+ pp->priv->state = STATE_START;
+ detect_error (pp, line);
+ }
+ else if (g_str_has_prefix (line, "No file"))
+ {
+ pp->priv->state = STATE_START;
+ detect_warning (pp, line);
+ }
+ /* The filename is not complete. */
+ else
+ {
+ gchar *line_stripped = g_strdup (line);
+ g_strstrip (line_stripped);
+ append_to_filename_buffer (pp, line_stripped);
+ g_free (line_stripped);
+ }
+ break;
+
+ case STATE_BADBOX:
+ case STATE_WARNING:
+ case STATE_ERROR:
+ case STATE_ERROR_SEARCH_LINE:
+ default:
+ g_return_if_reached ();
+ }
}
static void
latexila_post_processor_latex_process_line (LatexilaPostProcessor *post_processor,
- gchar *line)
+ gchar *line)
{
- LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (post_processor);
-
- if (line == NULL)
- return;
-
- if (pp->priv->state != STATE_START)
- append_to_line_buffer (pp, line);
-
- switch (pp->priv->state)
- {
- case STATE_START:
- if (line[0] == '\0')
- break;
-
- if (!(detect_badbox (pp, line) ||
- detect_warning (pp, line) ||
- detect_error (pp, line) ||
- detect_other (pp, line)))
- update_stack_file (pp, line);
- break;
-
- case STATE_BADBOX:
- detect_badbox (pp, line);
- break;
-
- case STATE_WARNING:
- detect_warning (pp, line);
- break;
-
- case STATE_ERROR:
- case STATE_ERROR_SEARCH_LINE:
- detect_error (pp, line);
- break;
-
- case STATE_FILENAME:
- case STATE_FILENAME_HEURISTIC:
- update_stack_file (pp, line);
- break;
-
- default:
- g_return_if_reached ();
- }
-
- g_free (line);
+ LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (post_processor);
+
+ if (line == NULL)
+ {
+ return;
+ }
+
+ if (pp->priv->state != STATE_START)
+ {
+ append_to_line_buffer (pp, line);
+ }
+
+ switch (pp->priv->state)
+ {
+ case STATE_START:
+ if (line[0] == '\0')
+ {
+ break;
+ }
+
+ if (!(detect_badbox (pp, line) ||
+ detect_warning (pp, line) ||
+ detect_error (pp, line) ||
+ detect_other (pp, line)))
+ {
+ update_stack_file (pp, line);
+ }
+ break;
+
+ case STATE_BADBOX:
+ detect_badbox (pp, line);
+ break;
+
+ case STATE_WARNING:
+ detect_warning (pp, line);
+ break;
+
+ case STATE_ERROR:
+ case STATE_ERROR_SEARCH_LINE:
+ detect_error (pp, line);
+ break;
+
+ case STATE_FILENAME:
+ case STATE_FILENAME_HEURISTIC:
+ update_stack_file (pp, line);
+ break;
+
+ default:
+ g_return_if_reached ();
+ }
+
+ g_free (line);
}
static const GList *
latexila_post_processor_latex_get_messages (LatexilaPostProcessor *post_processor,
- gboolean show_details)
+ gboolean show_details)
{
- LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (post_processor);
+ LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (post_processor);
- return pp->priv->messages != NULL ? pp->priv->messages->head : NULL;
+ return pp->priv->messages != NULL ? pp->priv->messages->head : NULL;
}
static GQueue *
latexila_post_processor_latex_take_messages (LatexilaPostProcessor *post_processor)
{
- LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (post_processor);
- GQueue *ret;
+ LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (post_processor);
+ GQueue *ret;
- ret = pp->priv->messages;
- pp->priv->messages = NULL;
+ ret = pp->priv->messages;
+ pp->priv->messages = NULL;
- return ret;
+ return ret;
}
static void
latexila_post_processor_latex_finalize (GObject *object)
{
- LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (object);
+ LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (object);
- if (pp->priv->messages != NULL)
- g_queue_free_full (pp->priv->messages, (GDestroyNotify) latexila_build_msg_free);
+ if (pp->priv->messages != NULL)
+ {
+ g_queue_free_full (pp->priv->messages, (GDestroyNotify) latexila_build_msg_free);
+ }
- if (pp->priv->cur_msg != NULL)
- latexila_build_msg_free (pp->priv->cur_msg);
+ if (pp->priv->cur_msg != NULL)
+ {
+ latexila_build_msg_free (pp->priv->cur_msg);
+ }
- if (pp->priv->line_buffer != NULL)
- g_string_free (pp->priv->line_buffer, TRUE);
+ if (pp->priv->line_buffer != NULL)
+ {
+ g_string_free (pp->priv->line_buffer, TRUE);
+ }
- if (pp->priv->filename_buffer != NULL)
- g_string_free (pp->priv->filename_buffer, TRUE);
+ if (pp->priv->filename_buffer != NULL)
+ {
+ g_string_free (pp->priv->filename_buffer, TRUE);
+ }
- g_slist_free_full (pp->priv->stack_files, (GDestroyNotify) file_free);
+ g_slist_free_full (pp->priv->stack_files, (GDestroyNotify) file_free);
- g_free (pp->priv->directory_path);
+ g_free (pp->priv->directory_path);
- G_OBJECT_CLASS (latexila_post_processor_latex_parent_class)->finalize (object);
+ G_OBJECT_CLASS (latexila_post_processor_latex_parent_class)->finalize (object);
}
static void
latexila_post_processor_latex_class_init (LatexilaPostProcessorLatexClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- LatexilaPostProcessorClass *pp_class = LATEXILA_POST_PROCESSOR_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ LatexilaPostProcessorClass *pp_class = LATEXILA_POST_PROCESSOR_CLASS (klass);
- object_class->finalize = latexila_post_processor_latex_finalize;
+ object_class->finalize = latexila_post_processor_latex_finalize;
- pp_class->start = latexila_post_processor_latex_start;
- pp_class->end = latexila_post_processor_latex_end;
- pp_class->process_line = latexila_post_processor_latex_process_line;
- pp_class->get_messages = latexila_post_processor_latex_get_messages;
- pp_class->take_messages = latexila_post_processor_latex_take_messages;
+ pp_class->start = latexila_post_processor_latex_start;
+ pp_class->end = latexila_post_processor_latex_end;
+ pp_class->process_line = latexila_post_processor_latex_process_line;
+ pp_class->get_messages = latexila_post_processor_latex_get_messages;
+ pp_class->take_messages = latexila_post_processor_latex_take_messages;
}
static void
latexila_post_processor_latex_init (LatexilaPostProcessorLatex *pp)
{
- pp->priv = latexila_post_processor_latex_get_instance_private (pp);
+ pp->priv = latexila_post_processor_latex_get_instance_private (pp);
- pp->priv->messages = g_queue_new ();
- pp->priv->cur_msg = latexila_build_msg_new ();
- pp->priv->state = STATE_START;
+ pp->priv->messages = g_queue_new ();
+ pp->priv->cur_msg = latexila_build_msg_new ();
+ pp->priv->state = STATE_START;
}
/**
@@ -1464,7 +1506,7 @@ latexila_post_processor_latex_init (LatexilaPostProcessorLatex *pp)
LatexilaPostProcessor *
latexila_post_processor_latex_new (void)
{
- return g_object_new (LATEXILA_TYPE_POST_PROCESSOR_LATEX, NULL);
+ return g_object_new (LATEXILA_TYPE_POST_PROCESSOR_LATEX, NULL);
}
/**
@@ -1476,7 +1518,7 @@ latexila_post_processor_latex_new (void)
gint
latexila_post_processor_latex_get_errors_count (LatexilaPostProcessorLatex *pp)
{
- g_return_val_if_fail (LATEXILA_IS_POST_PROCESSOR_LATEX (pp), 0);
+ g_return_val_if_fail (LATEXILA_IS_POST_PROCESSOR_LATEX (pp), 0);
- return pp->priv->errors_count;
+ return pp->priv->errors_count;
}
diff --git a/src/liblatexila/latexila-post-processor-latexmk.c
b/src/liblatexila/latexila-post-processor-latexmk.c
index 5218e87..cae1b86 100644
--- a/src/liblatexila/latexila-post-processor-latexmk.c
+++ b/src/liblatexila/latexila-post-processor-latexmk.c
@@ -32,681 +32,716 @@
typedef enum
{
- /* Try to find something like:
- * ------------
- * Run number 1 of rule 'pdflatex'
- * ------------
- */
- STATE_SUB_TITLE_START,
- STATE_SUB_TITLE_END,
-
- /* Try to find something like:
- * ------------
- * Running 'pdflatex -synctex=1 -recorder "test.tex"'
- * ------------
- */
- STATE_SUB_COMMAND_START,
- STATE_SUB_COMMAND_END,
-
- /* Fetch the sub-command output. */
- STATE_SUB_COMMAND_OUTPUT_START,
- STATE_SUB_COMMAND_OUTPUT_IN,
-
- /* Fetch the Latexmk messages after a command output. */
- STATE_LATEXMK_MESSAGES,
-
- /* If no sub-titles have been found, display almost all output. */
- STATE_FALLBACK_START,
- STATE_FALLBACK_IN
+ /* Try to find something like:
+ * ------------
+ * Run number 1 of rule 'pdflatex'
+ * ------------
+ */
+ STATE_SUB_TITLE_START,
+ STATE_SUB_TITLE_END,
+
+ /* Try to find something like:
+ * ------------
+ * Running 'pdflatex -synctex=1 -recorder "test.tex"'
+ * ------------
+ */
+ STATE_SUB_COMMAND_START,
+ STATE_SUB_COMMAND_END,
+
+ /* Fetch the sub-command output. */
+ STATE_SUB_COMMAND_OUTPUT_START,
+ STATE_SUB_COMMAND_OUTPUT_IN,
+
+ /* Fetch the Latexmk messages after a command output. */
+ STATE_LATEXMK_MESSAGES,
+
+ /* If no sub-titles have been found, display almost all output. */
+ STATE_FALLBACK_START,
+ STATE_FALLBACK_IN
} State;
struct _LatexilaPostProcessorLatexmkPrivate
{
- /* The tree of all messages. */
- GQueue *messages;
+ /* The tree of all messages. */
+ GQueue *messages;
- State state;
+ State state;
- /* Number of separators encountered for the current state. */
- gint separator_count;
+ /* Number of separators encountered for the current state. */
+ gint separator_count;
- /* We run the 'latex' post-processor only on the last latex or pdflatex rule.
- * The first latex rules most probably have warnings that are fixed in the
- * last latex rule.
- * @last_latex_sub_command and @last_latex_messages are simple pointers inside
- * @messages, so don't free them.
- */
- LatexilaBuildMsg *last_latex_sub_command;
- GQueue *last_latex_lines;
- GList *last_latex_messages;
+ /* We run the 'latex' post-processor only on the last latex or pdflatex rule.
+ * The first latex rules most probably have warnings that are fixed in the
+ * last latex rule.
+ * @last_latex_sub_command and @last_latex_messages are simple pointers inside
+ * @messages, so don't free them.
+ */
+ LatexilaBuildMsg *last_latex_sub_command;
+ GQueue *last_latex_lines;
+ GList *last_latex_messages;
- GFile *file;
+ GFile *file;
- GQueue *all_lines;
+ GQueue *all_lines;
- guint last_rule_is_latex_rule : 1;
- guint store_all_lines : 1;
+ guint last_rule_is_latex_rule : 1;
+ guint store_all_lines : 1;
};
G_DEFINE_TYPE_WITH_PRIVATE (LatexilaPostProcessorLatexmk,
- latexila_post_processor_latexmk,
- LATEXILA_TYPE_POST_PROCESSOR)
+ latexila_post_processor_latexmk,
+ LATEXILA_TYPE_POST_PROCESSOR)
static void
latexila_post_processor_latexmk_start (LatexilaPostProcessor *post_processor,
- GFile *file)
+ GFile *file)
{
- LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (post_processor);
+ LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (post_processor);
- g_clear_object (&pp->priv->file);
- pp->priv->file = g_object_ref (file);
+ g_clear_object (&pp->priv->file);
+ pp->priv->file = g_object_ref (file);
}
static void
add_top_level_message (LatexilaPostProcessorLatexmk *pp,
- LatexilaBuildMsg *msg)
+ LatexilaBuildMsg *msg)
{
- g_assert (msg != NULL);
+ g_assert (msg != NULL);
- msg->type = LATEXILA_BUILD_MSG_TYPE_JOB_SUB_COMMAND;
+ msg->type = LATEXILA_BUILD_MSG_TYPE_JOB_SUB_COMMAND;
- /* Do not expand the row, so the user has first a global view of what have
- * been executed.
- */
- msg->expand = FALSE;
+ /* Do not expand the row, so the user has first a global view of what have
+ * been executed.
+ */
+ msg->expand = FALSE;
- g_queue_push_tail (pp->priv->messages, msg);
+ g_queue_push_tail (pp->priv->messages, msg);
- pp->priv->store_all_lines = FALSE;
+ pp->priv->store_all_lines = FALSE;
}
static void
add_sub_message (LatexilaPostProcessorLatexmk *pp,
- LatexilaBuildMsg *sub_msg)
+ LatexilaBuildMsg *sub_msg)
{
- LatexilaBuildMsg *last_toplevel_msg;
+ LatexilaBuildMsg *last_toplevel_msg;
- g_assert (sub_msg != NULL);
+ g_assert (sub_msg != NULL);
- last_toplevel_msg = g_queue_peek_tail (pp->priv->messages);
+ last_toplevel_msg = g_queue_peek_tail (pp->priv->messages);
- if (last_toplevel_msg == NULL)
- {
- g_warning ("PostProcessorLatexmk: try to add a sub-message without a top-level message.");
- latexila_build_msg_free (sub_msg);
- return;
- }
+ if (last_toplevel_msg == NULL)
+ {
+ g_warning ("PostProcessorLatexmk: try to add a sub-message without a top-level message.");
+ latexila_build_msg_free (sub_msg);
+ return;
+ }
- sub_msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
+ sub_msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
- if (last_toplevel_msg->children == NULL)
- last_toplevel_msg->children = g_queue_new ();
+ if (last_toplevel_msg->children == NULL)
+ {
+ last_toplevel_msg->children = g_queue_new ();
+ }
- g_queue_push_tail (last_toplevel_msg->children, sub_msg);
+ g_queue_push_tail (last_toplevel_msg->children, sub_msg);
}
static void
set_last_latex_sub_command (LatexilaPostProcessorLatexmk *pp,
- LatexilaBuildMsg *msg)
+ LatexilaBuildMsg *msg)
{
- if (pp->priv->last_latex_lines != NULL)
- g_queue_free_full (pp->priv->last_latex_lines, g_free);
+ if (pp->priv->last_latex_lines != NULL)
+ {
+ g_queue_free_full (pp->priv->last_latex_lines, g_free);
+ }
- pp->priv->last_latex_lines = g_queue_new ();
- pp->priv->last_latex_sub_command = msg;
+ pp->priv->last_latex_lines = g_queue_new ();
+ pp->priv->last_latex_sub_command = msg;
}
static gboolean
is_separator (const gchar *line)
{
- return g_str_has_prefix (line, "------------");
+ return g_str_has_prefix (line, "------------");
}
static void
fetch_sub_title (LatexilaPostProcessorLatexmk *pp,
- gchar *line)
+ gchar *line)
{
- static GRegex *regex_sub_title = NULL;
- GMatchInfo *match_info;
+ static GRegex *regex_sub_title = NULL;
+ GMatchInfo *match_info;
- g_assert (pp->priv->state == STATE_SUB_TITLE_START ||
- pp->priv->state == STATE_SUB_TITLE_END);
+ g_assert (pp->priv->state == STATE_SUB_TITLE_START ||
+ pp->priv->state == STATE_SUB_TITLE_END);
- if (G_UNLIKELY (regex_sub_title == NULL))
- {
- GError *error = NULL;
+ if (G_UNLIKELY (regex_sub_title == NULL))
+ {
+ GError *error = NULL;
- regex_sub_title = g_regex_new ("Run number \\d+ of rule '(?P<rule>.*)'",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
+ regex_sub_title = g_regex_new ("Run number \\d+ of rule '(?P<rule>.*)'",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
- if (error != NULL)
- {
- g_warning ("PostProcessorLatexmk: %s", error->message);
- g_error_free (error);
- return;
- }
- }
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatexmk: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+ }
- if (pp->priv->state == STATE_SUB_TITLE_END)
- {
- g_assert (pp->priv->separator_count == 1);
+ if (pp->priv->state == STATE_SUB_TITLE_END)
+ {
+ g_assert (pp->priv->separator_count == 1);
- if (is_separator (line))
- {
- pp->priv->separator_count = 0;
- pp->priv->state = STATE_SUB_COMMAND_START;
- }
+ if (is_separator (line))
+ {
+ pp->priv->separator_count = 0;
+ pp->priv->state = STATE_SUB_COMMAND_START;
+ }
- goto end;
- }
+ goto end;
+ }
- if (is_separator (line))
- {
- pp->priv->separator_count++;
+ if (is_separator (line))
+ {
+ pp->priv->separator_count++;
- if (pp->priv->separator_count == 2)
- {
- pp->priv->separator_count = 0;
- g_warning ("PostProcessorLatexmk: fetch sub-title failed, try again.");
- }
+ if (pp->priv->separator_count == 2)
+ {
+ pp->priv->separator_count = 0;
+ g_warning ("PostProcessorLatexmk: fetch sub-title failed, try again.");
+ }
- goto end;
- }
+ goto end;
+ }
- if (pp->priv->separator_count != 1)
- goto end;
+ if (pp->priv->separator_count != 1)
+ {
+ goto end;
+ }
- g_regex_match (regex_sub_title, line, 0, &match_info);
+ g_regex_match (regex_sub_title, line, 0, &match_info);
- if (g_match_info_matches (match_info))
- {
- LatexilaBuildMsg *msg;
- gchar *rule;
+ if (g_match_info_matches (match_info))
+ {
+ LatexilaBuildMsg *msg;
+ gchar *rule;
- msg = latexila_build_msg_new ();
- msg->text = line;
- line = NULL;
+ msg = latexila_build_msg_new ();
+ msg->text = line;
+ line = NULL;
- add_top_level_message (pp, msg);
- pp->priv->state = STATE_SUB_TITLE_END;
+ add_top_level_message (pp, msg);
+ pp->priv->state = STATE_SUB_TITLE_END;
- rule = g_match_info_fetch_named (match_info, "rule");
+ rule = g_match_info_fetch_named (match_info, "rule");
- pp->priv->last_rule_is_latex_rule = (g_strcmp0 (rule, "latex") == 0 ||
- g_strcmp0 (rule, "pdflatex") == 0);
+ pp->priv->last_rule_is_latex_rule = (g_strcmp0 (rule, "latex") == 0 ||
+ g_strcmp0 (rule, "pdflatex") == 0);
- if (pp->priv->last_rule_is_latex_rule)
- set_last_latex_sub_command (pp, msg);
+ if (pp->priv->last_rule_is_latex_rule)
+ {
+ set_last_latex_sub_command (pp, msg);
+ }
- g_free (rule);
- }
+ g_free (rule);
+ }
- g_match_info_free (match_info);
+ g_match_info_free (match_info);
end:
- if (pp->priv->store_all_lines)
- {
- if (pp->priv->all_lines == NULL)
- pp->priv->all_lines = g_queue_new ();
-
- g_queue_push_tail (pp->priv->all_lines, line);
- }
- else
- {
- g_free (line);
- }
+ if (pp->priv->store_all_lines)
+ {
+ if (pp->priv->all_lines == NULL)
+ {
+ pp->priv->all_lines = g_queue_new ();
+ }
+
+ g_queue_push_tail (pp->priv->all_lines, line);
+ }
+ else
+ {
+ g_free (line);
+ }
}
static void
fetch_sub_command (LatexilaPostProcessorLatexmk *pp,
- gchar *line)
+ gchar *line)
{
- static GRegex *regex_sub_command = NULL;
- GMatchInfo *match_info;
+ static GRegex *regex_sub_command = NULL;
+ GMatchInfo *match_info;
- g_assert (pp->priv->state == STATE_SUB_COMMAND_START ||
- pp->priv->state == STATE_SUB_COMMAND_END);
+ g_assert (pp->priv->state == STATE_SUB_COMMAND_START ||
+ pp->priv->state == STATE_SUB_COMMAND_END);
- if (G_UNLIKELY (regex_sub_command == NULL))
- {
- GError *error = NULL;
+ if (G_UNLIKELY (regex_sub_command == NULL))
+ {
+ GError *error = NULL;
- regex_sub_command = g_regex_new ("Running '(?P<command>.*)'",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
+ regex_sub_command = g_regex_new ("Running '(?P<command>.*)'",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
- if (error != NULL)
- {
- g_warning ("PostProcessorLatexmk: %s", error->message);
- g_error_free (error);
- return;
- }
- }
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatexmk: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+ }
- if (pp->priv->state == STATE_SUB_COMMAND_END)
- {
- g_assert (pp->priv->separator_count == 1);
+ if (pp->priv->state == STATE_SUB_COMMAND_END)
+ {
+ g_assert (pp->priv->separator_count == 1);
- if (is_separator (line))
- {
- pp->priv->separator_count = 0;
- pp->priv->state = STATE_SUB_COMMAND_OUTPUT_START;
- }
+ if (is_separator (line))
+ {
+ pp->priv->separator_count = 0;
+ pp->priv->state = STATE_SUB_COMMAND_OUTPUT_START;
+ }
- goto end;
- }
+ goto end;
+ }
- if (is_separator (line))
- {
- pp->priv->separator_count++;
+ if (is_separator (line))
+ {
+ pp->priv->separator_count++;
- if (pp->priv->separator_count == 2)
- {
- pp->priv->separator_count = 0;
- g_warning ("PostProcessorLatexmk: fetch sub-command failed, try again.");
- }
+ if (pp->priv->separator_count == 2)
+ {
+ pp->priv->separator_count = 0;
+ g_warning ("PostProcessorLatexmk: fetch sub-command failed, try again.");
+ }
- goto end;
- }
+ goto end;
+ }
- if (pp->priv->separator_count != 1)
- goto end;
+ if (pp->priv->separator_count != 1)
+ {
+ goto end;
+ }
- g_regex_match (regex_sub_command, line, 0, &match_info);
+ g_regex_match (regex_sub_command, line, 0, &match_info);
- if (g_match_info_matches (match_info))
- {
- LatexilaBuildMsg *msg;
- gchar *command;
+ if (g_match_info_matches (match_info))
+ {
+ LatexilaBuildMsg *msg;
+ gchar *command;
- msg = latexila_build_msg_new ();
+ msg = latexila_build_msg_new ();
- command = g_match_info_fetch_named (match_info, "command");
- msg->text = g_strdup_printf ("$ %s", command);
- g_free (command);
+ command = g_match_info_fetch_named (match_info, "command");
+ msg->text = g_strdup_printf ("$ %s", command);
+ g_free (command);
- add_sub_message (pp, msg);
- pp->priv->state = STATE_SUB_COMMAND_END;
- }
+ add_sub_message (pp, msg);
+ pp->priv->state = STATE_SUB_COMMAND_END;
+ }
- g_match_info_free (match_info);
+ g_match_info_free (match_info);
end:
- g_free (line);
+ g_free (line);
}
static void
fetch_latexmk_messages (LatexilaPostProcessorLatexmk *pp,
- gchar *line)
+ gchar *line)
{
- LatexilaBuildMsg *msg;
+ LatexilaBuildMsg *msg;
- g_assert (pp->priv->state == STATE_LATEXMK_MESSAGES);
+ g_assert (pp->priv->state == STATE_LATEXMK_MESSAGES);
- if (is_separator (line))
- {
- pp->priv->state = STATE_SUB_TITLE_START;
- fetch_sub_title (pp, line);
- return;
- }
+ if (is_separator (line))
+ {
+ pp->priv->state = STATE_SUB_TITLE_START;
+ fetch_sub_title (pp, line);
+ return;
+ }
- msg = latexila_build_msg_new ();
- msg->text = line;
- add_sub_message (pp, msg);
+ msg = latexila_build_msg_new ();
+ msg->text = line;
+ add_sub_message (pp, msg);
}
static gboolean
sub_command_output_matches_start_latexmk_message (const gchar *line)
{
- static GRegex *regex_for_rule = NULL;
-
- if (G_UNLIKELY (regex_for_rule == NULL))
- {
- GError *error = NULL;
-
- regex_for_rule = g_regex_new ("^For rule '.*', running",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatexmk: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
- }
-
- return (g_str_has_prefix (line, "Latexmk: applying rule") ||
- g_regex_match (regex_for_rule, line, 0, NULL));
+ static GRegex *regex_for_rule = NULL;
+
+ if (G_UNLIKELY (regex_for_rule == NULL))
+ {
+ GError *error = NULL;
+
+ regex_for_rule = g_regex_new ("^For rule '.*', running",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatexmk: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+ }
+
+ return (g_str_has_prefix (line, "Latexmk: applying rule") ||
+ g_regex_match (regex_for_rule, line, 0, NULL));
}
static void
fetch_sub_command_output (LatexilaPostProcessorLatexmk *pp,
- gchar *line)
+ gchar *line)
{
- static GRegex *regex_rule = NULL;
-
- g_assert (pp->priv->state == STATE_SUB_COMMAND_OUTPUT_START ||
- pp->priv->state == STATE_SUB_COMMAND_OUTPUT_IN);
-
- if (G_UNLIKELY (regex_rule == NULL))
- {
- GError *error = NULL;
-
- regex_rule = g_regex_new ("^Rule '.*':",
- G_REGEX_OPTIMIZE,
- 0,
- &error);
-
- if (error != NULL)
- {
- g_warning ("PostProcessorLatexmk: %s", error->message);
- g_error_free (error);
- return;
- }
- }
-
- if (pp->priv->state == STATE_SUB_COMMAND_OUTPUT_START)
- {
- if (sub_command_output_matches_start_latexmk_message (line))
- goto end;
-
- pp->priv->state = STATE_SUB_COMMAND_OUTPUT_IN;
- }
-
- if (!sub_command_output_matches_start_latexmk_message (line) &&
- (g_str_has_prefix (line, "Latexmk:") ||
- g_regex_match (regex_rule, line, 0, NULL)))
- {
- LatexilaBuildMsg *msg;
-
- pp->priv->state = STATE_LATEXMK_MESSAGES;
-
- msg = latexila_build_msg_new ();
- /* The latex command output is in English, so for consistency no need to
- * translate this.
- */
- msg->text = g_strdup ("Latexmk messages");
- add_top_level_message (pp, msg);
-
- fetch_latexmk_messages (pp, line);
- return;
- }
-
- /* If the rule is latex or pdflatex, we store the output. */
- if (pp->priv->last_rule_is_latex_rule)
- {
- g_queue_push_tail (pp->priv->last_latex_lines, line);
- line = NULL;
- }
-
- /* If it's another rule (bibtex, makeindex, etc), we show all output. */
- else
- {
- LatexilaBuildMsg *msg;
-
- msg = latexila_build_msg_new ();
- msg->text = line;
- line = NULL;
-
- add_sub_message (pp, msg);
- }
+ static GRegex *regex_rule = NULL;
+
+ g_assert (pp->priv->state == STATE_SUB_COMMAND_OUTPUT_START ||
+ pp->priv->state == STATE_SUB_COMMAND_OUTPUT_IN);
+
+ if (G_UNLIKELY (regex_rule == NULL))
+ {
+ GError *error = NULL;
+
+ regex_rule = g_regex_new ("^Rule '.*':",
+ G_REGEX_OPTIMIZE,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("PostProcessorLatexmk: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+ }
+
+ if (pp->priv->state == STATE_SUB_COMMAND_OUTPUT_START)
+ {
+ if (sub_command_output_matches_start_latexmk_message (line))
+ {
+ goto end;
+ }
+
+ pp->priv->state = STATE_SUB_COMMAND_OUTPUT_IN;
+ }
+
+ if (!sub_command_output_matches_start_latexmk_message (line) &&
+ (g_str_has_prefix (line, "Latexmk:") ||
+ g_regex_match (regex_rule, line, 0, NULL)))
+ {
+ LatexilaBuildMsg *msg;
+
+ pp->priv->state = STATE_LATEXMK_MESSAGES;
+
+ msg = latexila_build_msg_new ();
+ /* The latex command output is in English, so for consistency no need to
+ * translate this.
+ */
+ msg->text = g_strdup ("Latexmk messages");
+ add_top_level_message (pp, msg);
+
+ fetch_latexmk_messages (pp, line);
+ return;
+ }
+
+ /* If the rule is latex or pdflatex, we store the output. */
+ if (pp->priv->last_rule_is_latex_rule)
+ {
+ g_queue_push_tail (pp->priv->last_latex_lines, line);
+ line = NULL;
+ }
+ /* If it's another rule (bibtex, makeindex, etc), we show all output. */
+ else
+ {
+ LatexilaBuildMsg *msg;
+
+ msg = latexila_build_msg_new ();
+ msg->text = line;
+ line = NULL;
+
+ add_sub_message (pp, msg);
+ }
end:
- g_free (line);
+ g_free (line);
}
static void
process_line_fallback (LatexilaPostProcessorLatexmk *pp,
- gchar *line)
+ gchar *line)
{
- g_assert (pp->priv->state == STATE_FALLBACK_START ||
- pp->priv->state == STATE_FALLBACK_IN);
+ g_assert (pp->priv->state == STATE_FALLBACK_START ||
+ pp->priv->state == STATE_FALLBACK_IN);
- if (pp->priv->state == STATE_FALLBACK_START &&
- !g_str_has_prefix (line, "Latexmk: This is Latexmk") &&
- !g_str_has_prefix (line, "**** Report bugs"))
- pp->priv->state = STATE_FALLBACK_IN;
+ if (pp->priv->state == STATE_FALLBACK_START &&
+ !g_str_has_prefix (line, "Latexmk: This is Latexmk") &&
+ !g_str_has_prefix (line, "**** Report bugs"))
+ {
+ pp->priv->state = STATE_FALLBACK_IN;
+ }
- if (pp->priv->state == STATE_FALLBACK_IN)
- {
- LatexilaBuildMsg *msg;
+ if (pp->priv->state == STATE_FALLBACK_IN)
+ {
+ LatexilaBuildMsg *msg;
- msg = latexila_build_msg_new ();
- msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
- msg->text = line;
- line = NULL;
+ msg = latexila_build_msg_new ();
+ msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
+ msg->text = line;
+ line = NULL;
- g_queue_push_tail (pp->priv->messages, msg);
- }
+ g_queue_push_tail (pp->priv->messages, msg);
+ }
- g_free (line);
+ g_free (line);
}
static void
latexila_post_processor_latexmk_process_line (LatexilaPostProcessor *post_processor,
- gchar *line)
+ gchar *line)
{
- LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (post_processor);
-
- switch (pp->priv->state)
- {
- case STATE_SUB_TITLE_START:
- case STATE_SUB_TITLE_END:
- fetch_sub_title (pp, line);
- break;
-
- case STATE_SUB_COMMAND_START:
- case STATE_SUB_COMMAND_END:
- fetch_sub_command (pp, line);
- break;
-
- case STATE_SUB_COMMAND_OUTPUT_START:
- case STATE_SUB_COMMAND_OUTPUT_IN:
- fetch_sub_command_output (pp, line);
- break;
-
- case STATE_LATEXMK_MESSAGES:
- fetch_latexmk_messages (pp, line);
- break;
-
- case STATE_FALLBACK_START:
- case STATE_FALLBACK_IN:
- process_line_fallback (pp, line);
- break;
-
- default:
- g_return_if_reached ();
- }
+ LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (post_processor);
+
+ switch (pp->priv->state)
+ {
+ case STATE_SUB_TITLE_START:
+ case STATE_SUB_TITLE_END:
+ fetch_sub_title (pp, line);
+ break;
+
+ case STATE_SUB_COMMAND_START:
+ case STATE_SUB_COMMAND_END:
+ fetch_sub_command (pp, line);
+ break;
+
+ case STATE_SUB_COMMAND_OUTPUT_START:
+ case STATE_SUB_COMMAND_OUTPUT_IN:
+ fetch_sub_command_output (pp, line);
+ break;
+
+ case STATE_LATEXMK_MESSAGES:
+ fetch_latexmk_messages (pp, line);
+ break;
+
+ case STATE_FALLBACK_START:
+ case STATE_FALLBACK_IN:
+ process_line_fallback (pp, line);
+ break;
+
+ default:
+ g_return_if_reached ();
+ }
}
static void
run_latex_post_processor (LatexilaPostProcessorLatexmk *pp,
- gboolean succeeded)
+ gboolean succeeded)
{
- LatexilaPostProcessor *pp_latex;
- LatexilaBuildMsg *msg;
- GQueue *initial_children;
- GList *l;
- gboolean has_details;
- gint latex_errors_count;
+ LatexilaPostProcessor *pp_latex;
+ LatexilaBuildMsg *msg;
+ GQueue *initial_children;
+ GList *l;
+ gboolean has_details;
+ gint latex_errors_count;
- g_assert (pp->priv->last_latex_sub_command != NULL);
- g_assert (pp->priv->last_latex_lines != NULL);
+ g_assert (pp->priv->last_latex_sub_command != NULL);
+ g_assert (pp->priv->last_latex_lines != NULL);
- pp_latex = latexila_post_processor_latex_new ();
+ pp_latex = latexila_post_processor_latex_new ();
- latexila_post_processor_start (pp_latex, pp->priv->file);
+ latexila_post_processor_start (pp_latex, pp->priv->file);
- for (l = pp->priv->last_latex_lines->head; l != NULL; l = l->next)
- latexila_post_processor_process_line (pp_latex, l->data);
+ for (l = pp->priv->last_latex_lines->head; l != NULL; l = l->next)
+ {
+ latexila_post_processor_process_line (pp_latex, l->data);
+ }
- g_queue_free (pp->priv->last_latex_lines);
- pp->priv->last_latex_lines = NULL;
+ g_queue_free (pp->priv->last_latex_lines);
+ pp->priv->last_latex_lines = NULL;
- latexila_post_processor_end (pp_latex, succeeded);
+ latexila_post_processor_end (pp_latex, succeeded);
- msg = pp->priv->last_latex_sub_command;
+ msg = pp->priv->last_latex_sub_command;
- /* The initial children contain the command, for example. */
- initial_children = msg->children;
+ /* The initial children contain the command, for example. */
+ initial_children = msg->children;
- msg->children = latexila_post_processor_take_messages (pp_latex);
+ msg->children = latexila_post_processor_take_messages (pp_latex);
- pp->priv->last_latex_messages = msg->children->head;
+ pp->priv->last_latex_messages = msg->children->head;
- if (initial_children != NULL)
- {
- for (l = initial_children->tail; l != NULL; l = l->prev)
- g_queue_push_head (msg->children, l->data);
+ if (initial_children != NULL)
+ {
+ for (l = initial_children->tail; l != NULL; l = l->prev)
+ {
+ g_queue_push_head (msg->children, l->data);
+ }
- g_queue_free (initial_children);
- }
+ g_queue_free (initial_children);
+ }
- /* Expand only the last latex command. */
- msg->expand = TRUE;
+ /* Expand only the last latex command. */
+ msg->expand = TRUE;
- /* Set has-details.
- * Almost all the time, the user wants to see only the latex output.
- */
+ /* Set has-details.
+ * Almost all the time, the user wants to see only the latex output.
+ */
- /* Another solution is to know if the last rule was a latex rule, but it
- * doesn't work well. For example if a BibTeX error occurs, Latexmk run the
- * latex command a second time, so the last command is latex, but the latex
- * output has no errors, the error is only in BibTeX.
- * So it's probably better to check the number of latex errors, as is done
- * below.
- */
+ /* Another solution is to know if the last rule was a latex rule, but it
+ * doesn't work well. For example if a BibTeX error occurs, Latexmk run the
+ * latex command a second time, so the last command is latex, but the latex
+ * output has no errors, the error is only in BibTeX.
+ * So it's probably better to check the number of latex errors, as is done
+ * below.
+ */
- latex_errors_count = latexila_post_processor_latex_get_errors_count (LATEXILA_POST_PROCESSOR_LATEX
(pp_latex));
+ latex_errors_count = latexila_post_processor_latex_get_errors_count (LATEXILA_POST_PROCESSOR_LATEX
(pp_latex));
- has_details = succeeded || latex_errors_count > 0;
- g_object_set (pp, "has-details", has_details, NULL);
+ has_details = succeeded || latex_errors_count > 0;
+ g_object_set (pp, "has-details", has_details, NULL);
- g_object_unref (pp_latex);
+ g_object_unref (pp_latex);
}
static void
process_all_output (LatexilaPostProcessorLatexmk *pp)
{
- LatexilaPostProcessor *post_processor = LATEXILA_POST_PROCESSOR (pp);
- GList *l;
+ LatexilaPostProcessor *post_processor = LATEXILA_POST_PROCESSOR (pp);
+ GList *l;
- g_assert (pp->priv->messages->length == 0);
- g_assert (pp->priv->store_all_lines);
+ g_assert (pp->priv->messages->length == 0);
+ g_assert (pp->priv->store_all_lines);
- if (pp->priv->all_lines == NULL)
- return;
+ if (pp->priv->all_lines == NULL)
+ {
+ return;
+ }
- pp->priv->state = STATE_FALLBACK_START;
- pp->priv->store_all_lines = FALSE;
+ pp->priv->state = STATE_FALLBACK_START;
+ pp->priv->store_all_lines = FALSE;
- for (l = pp->priv->all_lines->head; l != NULL; l = l->next)
- latexila_post_processor_latexmk_process_line (post_processor, l->data);
+ for (l = pp->priv->all_lines->head; l != NULL; l = l->next)
+ {
+ latexila_post_processor_latexmk_process_line (post_processor, l->data);
+ }
- g_queue_free (pp->priv->all_lines);
- pp->priv->all_lines = NULL;
+ g_queue_free (pp->priv->all_lines);
+ pp->priv->all_lines = NULL;
}
static void
latexila_post_processor_latexmk_end (LatexilaPostProcessor *post_processor,
- gboolean succeeded)
+ gboolean succeeded)
{
- LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (post_processor);
+ LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (post_processor);
- if (pp->priv->last_latex_sub_command != NULL)
- run_latex_post_processor (pp, succeeded);
+ if (pp->priv->last_latex_sub_command != NULL)
+ {
+ run_latex_post_processor (pp, succeeded);
+ }
- if (pp->priv->messages->length == 0)
- process_all_output (pp);
+ if (pp->priv->messages->length == 0)
+ {
+ process_all_output (pp);
+ }
}
static const GList *
latexila_post_processor_latexmk_get_messages (LatexilaPostProcessor *post_processor,
- gboolean show_details)
+ gboolean show_details)
{
- LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (post_processor);
- gboolean has_details;
+ LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (post_processor);
+ gboolean has_details;
- g_object_get (pp, "has-details", &has_details, NULL);
+ g_object_get (pp, "has-details", &has_details, NULL);
- if (has_details && !show_details)
- return pp->priv->last_latex_messages;
+ if (has_details && !show_details)
+ {
+ return pp->priv->last_latex_messages;
+ }
- return pp->priv->messages != NULL ? pp->priv->messages->head : NULL;
+ return pp->priv->messages != NULL ? pp->priv->messages->head : NULL;
}
static GQueue *
latexila_post_processor_latexmk_take_messages (LatexilaPostProcessor *post_processor)
{
- LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (post_processor);
- GQueue *ret;
+ LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (post_processor);
+ GQueue *ret;
- ret = pp->priv->messages;
+ ret = pp->priv->messages;
- pp->priv->messages = NULL;
- pp->priv->last_latex_messages = NULL;
- pp->priv->last_latex_sub_command = NULL;
+ pp->priv->messages = NULL;
+ pp->priv->last_latex_messages = NULL;
+ pp->priv->last_latex_sub_command = NULL;
- return ret;
+ return ret;
}
static void
latexila_post_processor_latexmk_dispose (GObject *object)
{
- LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (object);
+ LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (object);
- g_clear_object (&pp->priv->file);
+ g_clear_object (&pp->priv->file);
- G_OBJECT_CLASS (latexila_post_processor_latexmk_parent_class)->dispose (object);
+ G_OBJECT_CLASS (latexila_post_processor_latexmk_parent_class)->dispose (object);
}
static void
latexila_post_processor_latexmk_finalize (GObject *object)
{
- LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (object);
+ LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (object);
- if (pp->priv->messages != NULL)
- g_queue_free_full (pp->priv->messages, (GDestroyNotify) latexila_build_msg_free);
+ if (pp->priv->messages != NULL)
+ {
+ g_queue_free_full (pp->priv->messages, (GDestroyNotify) latexila_build_msg_free);
+ }
- if (pp->priv->last_latex_lines != NULL)
- g_queue_free_full (pp->priv->last_latex_lines, g_free);
+ if (pp->priv->last_latex_lines != NULL)
+ {
+ g_queue_free_full (pp->priv->last_latex_lines, g_free);
+ }
- if (pp->priv->all_lines != NULL)
- g_queue_free_full (pp->priv->all_lines, g_free);
+ if (pp->priv->all_lines != NULL)
+ {
+ g_queue_free_full (pp->priv->all_lines, g_free);
+ }
- G_OBJECT_CLASS (latexila_post_processor_latexmk_parent_class)->finalize (object);
+ G_OBJECT_CLASS (latexila_post_processor_latexmk_parent_class)->finalize (object);
}
static void
latexila_post_processor_latexmk_class_init (LatexilaPostProcessorLatexmkClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- LatexilaPostProcessorClass *pp_class = LATEXILA_POST_PROCESSOR_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ LatexilaPostProcessorClass *pp_class = LATEXILA_POST_PROCESSOR_CLASS (klass);
- object_class->dispose = latexila_post_processor_latexmk_dispose;
- object_class->finalize = latexila_post_processor_latexmk_finalize;
+ object_class->dispose = latexila_post_processor_latexmk_dispose;
+ object_class->finalize = latexila_post_processor_latexmk_finalize;
- pp_class->start = latexila_post_processor_latexmk_start;
- pp_class->process_line = latexila_post_processor_latexmk_process_line;
- pp_class->end = latexila_post_processor_latexmk_end;
- pp_class->get_messages = latexila_post_processor_latexmk_get_messages;
- pp_class->take_messages = latexila_post_processor_latexmk_take_messages;
+ pp_class->start = latexila_post_processor_latexmk_start;
+ pp_class->process_line = latexila_post_processor_latexmk_process_line;
+ pp_class->end = latexila_post_processor_latexmk_end;
+ pp_class->get_messages = latexila_post_processor_latexmk_get_messages;
+ pp_class->take_messages = latexila_post_processor_latexmk_take_messages;
}
static void
latexila_post_processor_latexmk_init (LatexilaPostProcessorLatexmk *pp)
{
- pp->priv = latexila_post_processor_latexmk_get_instance_private (pp);
+ pp->priv = latexila_post_processor_latexmk_get_instance_private (pp);
- pp->priv->messages = g_queue_new ();
- pp->priv->state = STATE_SUB_TITLE_START;
- pp->priv->store_all_lines = TRUE;
+ pp->priv->messages = g_queue_new ();
+ pp->priv->state = STATE_SUB_TITLE_START;
+ pp->priv->store_all_lines = TRUE;
}
/**
@@ -717,5 +752,5 @@ latexila_post_processor_latexmk_init (LatexilaPostProcessorLatexmk *pp)
LatexilaPostProcessor *
latexila_post_processor_latexmk_new (void)
{
- return g_object_new (LATEXILA_TYPE_POST_PROCESSOR_LATEXMK, NULL);
+ return g_object_new (LATEXILA_TYPE_POST_PROCESSOR_LATEXMK, NULL);
}
diff --git a/src/liblatexila/latexila-post-processor.c b/src/liblatexila/latexila-post-processor.c
index 830a1f1..5da2561 100644
--- a/src/liblatexila/latexila-post-processor.c
+++ b/src/liblatexila/latexila-post-processor.c
@@ -42,26 +42,26 @@
struct _LatexilaPostProcessorPrivate
{
- GTask *task;
- GInputStream *stream;
+ GTask *task;
+ GInputStream *stream;
- /* "+1" so we can nul-terminate the buffer. */
- gchar buffer[BUFFER_SIZE + 1];
+ /* "+1" so we can nul-terminate the buffer. */
+ gchar buffer[BUFFER_SIZE + 1];
- /* The @buffer is split by lines. But since the stream is read with a fixed
- * size (BUFFER_SIZE), the last string returned by g_strsplit() is stored in
- * @line_buffer. When the next block is read, the first line returned is
- * appended to @line_buffer to have the whole line.
- */
- GString *line_buffer;
+ /* The @buffer is split by lines. But since the stream is read with a fixed
+ * size (BUFFER_SIZE), the last string returned by g_strsplit() is stored in
+ * @line_buffer. When the next block is read, the first line returned is
+ * appended to @line_buffer to have the whole line.
+ */
+ GString *line_buffer;
- guint has_details : 1;
+ guint has_details : 1;
};
enum
{
- PROP_0,
- PROP_HAS_DETAILS
+ PROP_0,
+ PROP_HAS_DETAILS
};
G_DEFINE_TYPE_WITH_PRIVATE (LatexilaPostProcessor, latexila_post_processor, G_TYPE_OBJECT)
@@ -78,35 +78,35 @@ static void read_stream (LatexilaPostProcessor *pp);
*/
gboolean
latexila_post_processor_get_type_from_name (const gchar *name,
- LatexilaPostProcessorType *type)
+ LatexilaPostProcessorType *type)
{
- g_assert (type != NULL);
-
- if (g_str_equal (name, "latexmk"))
- {
- *type = LATEXILA_POST_PROCESSOR_TYPE_LATEXMK;
- return TRUE;
- }
-
- if (g_str_equal (name, "latex"))
- {
- *type = LATEXILA_POST_PROCESSOR_TYPE_LATEX;
- return TRUE;
- }
-
- if (g_str_equal (name, "all-output"))
- {
- *type = LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT;
- return TRUE;
- }
-
- if (g_str_equal (name, "no-output"))
- {
- *type = LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT;
- return TRUE;
- }
-
- return FALSE;
+ g_assert (type != NULL);
+
+ if (g_str_equal (name, "latexmk"))
+ {
+ *type = LATEXILA_POST_PROCESSOR_TYPE_LATEXMK;
+ return TRUE;
+ }
+
+ if (g_str_equal (name, "latex"))
+ {
+ *type = LATEXILA_POST_PROCESSOR_TYPE_LATEX;
+ return TRUE;
+ }
+
+ if (g_str_equal (name, "all-output"))
+ {
+ *type = LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT;
+ return TRUE;
+ }
+
+ if (g_str_equal (name, "no-output"))
+ {
+ *type = LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT;
+ return TRUE;
+ }
+
+ return FALSE;
}
/**
@@ -118,156 +118,156 @@ latexila_post_processor_get_type_from_name (const gchar *name,
const gchar *
latexila_post_processor_get_name_from_type (LatexilaPostProcessorType type)
{
- switch (type)
- {
- case LATEXILA_POST_PROCESSOR_TYPE_LATEXMK:
- return "latexmk";
+ switch (type)
+ {
+ case LATEXILA_POST_PROCESSOR_TYPE_LATEXMK:
+ return "latexmk";
- case LATEXILA_POST_PROCESSOR_TYPE_LATEX:
- return "latex";
+ case LATEXILA_POST_PROCESSOR_TYPE_LATEX:
+ return "latex";
- case LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT:
- return "all-output";
+ case LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT:
+ return "all-output";
- case LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT:
- return "no-output";
+ case LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT:
+ return "no-output";
- case LATEXILA_POST_PROCESSOR_TYPE_NB_TYPES:
- default:
- g_return_val_if_reached (NULL);
- }
+ case LATEXILA_POST_PROCESSOR_TYPE_NB_TYPES:
+ default:
+ g_return_val_if_reached (NULL);
+ }
}
static void
latexila_post_processor_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- LatexilaPostProcessor *pp = LATEXILA_POST_PROCESSOR (object);
-
- switch (prop_id)
- {
- case PROP_HAS_DETAILS:
- g_value_set_boolean (value, pp->priv->has_details);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ LatexilaPostProcessor *pp = LATEXILA_POST_PROCESSOR (object);
+
+ switch (prop_id)
+ {
+ case PROP_HAS_DETAILS:
+ g_value_set_boolean (value, pp->priv->has_details);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
latexila_post_processor_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- LatexilaPostProcessor *pp = LATEXILA_POST_PROCESSOR (object);
-
- switch (prop_id)
- {
- case PROP_HAS_DETAILS:
- pp->priv->has_details = g_value_get_boolean (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ LatexilaPostProcessor *pp = LATEXILA_POST_PROCESSOR (object);
+
+ switch (prop_id)
+ {
+ case PROP_HAS_DETAILS:
+ pp->priv->has_details = g_value_get_boolean (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
latexila_post_processor_dispose (GObject *object)
{
- LatexilaPostProcessor *pp = LATEXILA_POST_PROCESSOR (object);
+ LatexilaPostProcessor *pp = LATEXILA_POST_PROCESSOR (object);
- g_clear_object (&pp->priv->task);
- g_clear_object (&pp->priv->stream);
+ g_clear_object (&pp->priv->task);
+ g_clear_object (&pp->priv->stream);
- G_OBJECT_CLASS (latexila_post_processor_parent_class)->dispose (object);
+ G_OBJECT_CLASS (latexila_post_processor_parent_class)->dispose (object);
}
static void
latexila_post_processor_finalize (GObject *object)
{
- LatexilaPostProcessor *pp = LATEXILA_POST_PROCESSOR (object);
+ LatexilaPostProcessor *pp = LATEXILA_POST_PROCESSOR (object);
- if (pp->priv->line_buffer != NULL)
- {
- g_string_free (pp->priv->line_buffer, TRUE);
- pp->priv->line_buffer = NULL;
- }
+ if (pp->priv->line_buffer != NULL)
+ {
+ g_string_free (pp->priv->line_buffer, TRUE);
+ pp->priv->line_buffer = NULL;
+ }
- G_OBJECT_CLASS (latexila_post_processor_parent_class)->finalize (object);
+ G_OBJECT_CLASS (latexila_post_processor_parent_class)->finalize (object);
}
static void
latexila_post_processor_start_default (LatexilaPostProcessor *pp,
- GFile *file)
+ GFile *file)
{
- /* Do nothing. */
+ /* Do nothing. */
}
static void
latexila_post_processor_process_line_default (LatexilaPostProcessor *pp,
- gchar *line)
+ gchar *line)
{
- g_free (line);
+ g_free (line);
}
static void
latexila_post_processor_end_default (LatexilaPostProcessor *pp,
- gboolean succeeded)
+ gboolean succeeded)
{
- /* Do nothing. */
+ /* Do nothing. */
}
static const GList *
latexila_post_processor_get_messages_default (LatexilaPostProcessor *pp,
- gboolean show_details)
+ gboolean show_details)
{
- return NULL;
+ return NULL;
}
static GQueue *
latexila_post_processor_take_messages_default (LatexilaPostProcessor *pp)
{
- return NULL;
+ return NULL;
}
static void
latexila_post_processor_class_init (LatexilaPostProcessorClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = latexila_post_processor_get_property;
- object_class->set_property = latexila_post_processor_set_property;
- object_class->dispose = latexila_post_processor_dispose;
- object_class->finalize = latexila_post_processor_finalize;
-
- klass->start = latexila_post_processor_start_default;
- klass->process_line = latexila_post_processor_process_line_default;
- klass->end = latexila_post_processor_end_default;
- klass->get_messages = latexila_post_processor_get_messages_default;
- klass->take_messages = latexila_post_processor_take_messages_default;
-
- g_object_class_install_property (object_class,
- PROP_HAS_DETAILS,
- g_param_spec_boolean ("has-details",
- "Has details",
- "",
- FALSE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = latexila_post_processor_get_property;
+ object_class->set_property = latexila_post_processor_set_property;
+ object_class->dispose = latexila_post_processor_dispose;
+ object_class->finalize = latexila_post_processor_finalize;
+
+ klass->start = latexila_post_processor_start_default;
+ klass->process_line = latexila_post_processor_process_line_default;
+ klass->end = latexila_post_processor_end_default;
+ klass->get_messages = latexila_post_processor_get_messages_default;
+ klass->take_messages = latexila_post_processor_take_messages_default;
+
+ g_object_class_install_property (object_class,
+ PROP_HAS_DETAILS,
+ g_param_spec_boolean ("has-details",
+ "Has details",
+ "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
}
static void
latexila_post_processor_init (LatexilaPostProcessor *pp)
{
- pp->priv = latexila_post_processor_get_instance_private (pp);
+ pp->priv = latexila_post_processor_get_instance_private (pp);
}
/* Use this function to process a line for the first time, it will convert the
@@ -275,151 +275,166 @@ latexila_post_processor_init (LatexilaPostProcessor *pp)
*/
static void
process_line (LatexilaPostProcessor *pp,
- gchar *line)
+ gchar *line)
{
- gchar *utf8_line = NULL;
-
- /* locale is not UTF-8 */
- if (!g_get_charset (NULL))
- {
- utf8_line = g_locale_to_utf8 (line, -1, NULL, NULL, NULL);
- }
- else if (g_utf8_validate (line, -1, NULL))
- {
- utf8_line = line;
- line = NULL;
- }
-
- /* The LaTeX output can be in ISO-8859-1, with accents in a filename for
- * instance.
- */
- if (utf8_line == NULL)
- utf8_line = g_convert (line, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
-
- if (utf8_line != NULL)
- latexila_post_processor_process_line (pp, utf8_line);
- else
- g_warning ("Failed to convert subprocess output to UTF-8: %s", line);
-
- g_free (line);
+ gchar *utf8_line = NULL;
+
+ /* locale is not UTF-8 */
+ if (!g_get_charset (NULL))
+ {
+ utf8_line = g_locale_to_utf8 (line, -1, NULL, NULL, NULL);
+ }
+ else if (g_utf8_validate (line, -1, NULL))
+ {
+ utf8_line = line;
+ line = NULL;
+ }
+
+ /* The LaTeX output can be in ISO-8859-1, with accents in a filename for
+ * instance.
+ */
+ if (utf8_line == NULL)
+ {
+ utf8_line = g_convert (line, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
+ }
+
+ if (utf8_line != NULL)
+ {
+ latexila_post_processor_process_line (pp, utf8_line);
+ }
+ else
+ {
+ g_warning ("Failed to convert subprocess output to UTF-8: %s", line);
+ }
+
+ g_free (line);
}
static void
read_stream_cb (GInputStream *stream,
- GAsyncResult *result,
- LatexilaPostProcessor *pp)
+ GAsyncResult *result,
+ LatexilaPostProcessor *pp)
{
- gssize bytes_read;
- GCancellable *cancellable;
- gchar **lines;
- GError *error = NULL;
-
- bytes_read = g_input_stream_read_finish (stream, result, &error);
-
- cancellable = g_task_get_cancellable (pp->priv->task);
- if (g_cancellable_is_cancelled (cancellable))
- {
- if (error != NULL)
- g_error_free (error);
-
- g_task_return_boolean (pp->priv->task, FALSE);
- return;
- }
-
- if (error != NULL)
- {
- g_warning ("Error while reading the post-processor stream: %s", error->message);
- g_error_free (error);
- g_task_return_boolean (pp->priv->task, FALSE);
- return;
- }
-
- /* End of stream reached, process line_buffer. */
- if (bytes_read == 0)
- {
- /* Generally a single \n is present at the end of the stream, so an empty
- * line is present in line_buffer. But we don't want to display it in the
- * build view.
- */
- if (pp->priv->line_buffer != NULL &&
- pp->priv->line_buffer->str != NULL &&
- pp->priv->line_buffer->str[0] != '\0')
- {
- gchar *line;
-
- line = g_string_free (pp->priv->line_buffer, FALSE);
- pp->priv->line_buffer = NULL;
-
- process_line (pp, line);
- }
-
- /* finished! */
- g_task_return_boolean (pp->priv->task, TRUE);
- return;
- }
-
- pp->priv->buffer[bytes_read] = '\0';
-
- lines = g_strsplit (pp->priv->buffer, "\n", 0);
- g_assert (lines != NULL);
- g_assert (lines[0] != NULL);
-
- if (pp->priv->line_buffer != NULL)
- {
- /* Merge line_buffer and the first line */
- g_string_append (pp->priv->line_buffer, lines[0]);
- }
-
- /* If a second line exists, we can call process_line().
- * The first line must be replaced by the contents of line_buffer.
- * And the last line must go to line_buffer.
- */
- if (lines[1] != NULL)
- {
- gint last_line;
- gint i;
-
- if (pp->priv->line_buffer != NULL)
- {
- g_free (lines[0]);
- lines[0] = g_string_free (pp->priv->line_buffer, FALSE);
- pp->priv->line_buffer = NULL;
- }
-
- for (last_line = 1; lines[last_line+1] != NULL; last_line++);
-
- pp->priv->line_buffer = g_string_new (lines[last_line]);
- g_free (lines[last_line]);
- lines[last_line] = NULL;
-
- for (i = 0; lines[i] != NULL; i++)
- process_line (pp, lines[i]);
-
- g_free (lines);
- }
- else
- {
- /* If not already done above, put the first line to line_buffer. */
- if (pp->priv->line_buffer == NULL)
- pp->priv->line_buffer = g_string_new (lines[0]);
-
- g_strfreev (lines);
- }
-
- /* Unfortunately for the computer, it is not finished. */
- read_stream (pp);
+ gssize bytes_read;
+ GCancellable *cancellable;
+ gchar **lines;
+ GError *error = NULL;
+
+ bytes_read = g_input_stream_read_finish (stream, result, &error);
+
+ cancellable = g_task_get_cancellable (pp->priv->task);
+ if (g_cancellable_is_cancelled (cancellable))
+ {
+ if (error != NULL)
+ {
+ g_error_free (error);
+ }
+
+ g_task_return_boolean (pp->priv->task, FALSE);
+ return;
+ }
+
+ if (error != NULL)
+ {
+ g_warning ("Error while reading the post-processor stream: %s", error->message);
+ g_error_free (error);
+ g_task_return_boolean (pp->priv->task, FALSE);
+ return;
+ }
+
+ /* End of stream reached, process line_buffer. */
+ if (bytes_read == 0)
+ {
+ /* Generally a single \n is present at the end of the stream, so an empty
+ * line is present in line_buffer. But we don't want to display it in the
+ * build view.
+ */
+ if (pp->priv->line_buffer != NULL &&
+ pp->priv->line_buffer->str != NULL &&
+ pp->priv->line_buffer->str[0] != '\0')
+ {
+ gchar *line;
+
+ line = g_string_free (pp->priv->line_buffer, FALSE);
+ pp->priv->line_buffer = NULL;
+
+ process_line (pp, line);
+ }
+
+ /* finished! */
+ g_task_return_boolean (pp->priv->task, TRUE);
+ return;
+ }
+
+ pp->priv->buffer[bytes_read] = '\0';
+
+ lines = g_strsplit (pp->priv->buffer, "\n", 0);
+ g_assert (lines != NULL);
+ g_assert (lines[0] != NULL);
+
+ if (pp->priv->line_buffer != NULL)
+ {
+ /* Merge line_buffer and the first line */
+ g_string_append (pp->priv->line_buffer, lines[0]);
+ }
+
+ /* If a second line exists, we can call process_line().
+ * The first line must be replaced by the contents of line_buffer.
+ * And the last line must go to line_buffer.
+ */
+ if (lines[1] != NULL)
+ {
+ gint last_line;
+ gint i;
+
+ if (pp->priv->line_buffer != NULL)
+ {
+ g_free (lines[0]);
+ lines[0] = g_string_free (pp->priv->line_buffer, FALSE);
+ pp->priv->line_buffer = NULL;
+ }
+
+ for (last_line = 1; lines[last_line+1] != NULL; last_line++)
+ {
+ ;
+ }
+
+ pp->priv->line_buffer = g_string_new (lines[last_line]);
+ g_free (lines[last_line]);
+ lines[last_line] = NULL;
+
+ for (i = 0; lines[i] != NULL; i++)
+ {
+ process_line (pp, lines[i]);
+ }
+
+ g_free (lines);
+ }
+ else
+ {
+ /* If not already done above, put the first line to line_buffer. */
+ if (pp->priv->line_buffer == NULL)
+ {
+ pp->priv->line_buffer = g_string_new (lines[0]);
+ }
+
+ g_strfreev (lines);
+ }
+
+ /* Unfortunately for the computer, it is not finished. */
+ read_stream (pp);
}
static void
read_stream (LatexilaPostProcessor *pp)
{
- g_input_stream_read_async (pp->priv->stream,
- &pp->priv->buffer,
- BUFFER_SIZE,
- G_PRIORITY_DEFAULT,
- g_task_get_cancellable (pp->priv->task),
- (GAsyncReadyCallback) read_stream_cb,
- pp);
+ g_input_stream_read_async (pp->priv->stream,
+ &pp->priv->buffer,
+ BUFFER_SIZE,
+ G_PRIORITY_DEFAULT,
+ g_task_get_cancellable (pp->priv->task),
+ (GAsyncReadyCallback) read_stream_cb,
+ pp);
}
/**
@@ -440,30 +455,30 @@ read_stream (LatexilaPostProcessor *pp)
*/
void
latexila_post_processor_process_async (LatexilaPostProcessor *pp,
- GFile *file,
- GInputStream *stream,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ GFile *file,
+ GInputStream *stream,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- g_return_if_fail (LATEXILA_IS_POST_PROCESSOR (pp));
- g_return_if_fail (G_IS_FILE (file));
- g_return_if_fail (G_IS_INPUT_STREAM (stream));
- g_return_if_fail (G_IS_CANCELLABLE (cancellable));
- g_return_if_fail (pp->priv->task == NULL);
+ g_return_if_fail (LATEXILA_IS_POST_PROCESSOR (pp));
+ g_return_if_fail (G_IS_FILE (file));
+ g_return_if_fail (G_IS_INPUT_STREAM (stream));
+ g_return_if_fail (G_IS_CANCELLABLE (cancellable));
+ g_return_if_fail (pp->priv->task == NULL);
- pp->priv->task = g_task_new (pp, cancellable, callback, user_data);
- pp->priv->stream = g_object_ref (stream);
+ pp->priv->task = g_task_new (pp, cancellable, callback, user_data);
+ pp->priv->stream = g_object_ref (stream);
- latexila_post_processor_start (pp, file);
+ latexila_post_processor_start (pp, file);
- if (pp->priv->line_buffer != NULL)
- {
- g_string_free (pp->priv->line_buffer, TRUE);
- pp->priv->line_buffer = NULL;
- }
+ if (pp->priv->line_buffer != NULL)
+ {
+ g_string_free (pp->priv->line_buffer, TRUE);
+ pp->priv->line_buffer = NULL;
+ }
- read_stream (pp);
+ read_stream (pp);
}
/**
@@ -478,23 +493,23 @@ latexila_post_processor_process_async (LatexilaPostProcessor *pp,
*/
void
latexila_post_processor_process_finish (LatexilaPostProcessor *pp,
- GAsyncResult *result,
- gboolean succeeded)
+ GAsyncResult *result,
+ gboolean succeeded)
{
- g_return_if_fail (g_task_is_valid (result, pp));
+ g_return_if_fail (g_task_is_valid (result, pp));
- g_task_propagate_boolean (G_TASK (result), NULL);
+ g_task_propagate_boolean (G_TASK (result), NULL);
- latexila_post_processor_end (pp, succeeded);
+ latexila_post_processor_end (pp, succeeded);
- g_clear_object (&pp->priv->task);
- g_clear_object (&pp->priv->stream);
+ g_clear_object (&pp->priv->task);
+ g_clear_object (&pp->priv->stream);
- if (pp->priv->line_buffer != NULL)
- {
- g_string_free (pp->priv->line_buffer, TRUE);
- pp->priv->line_buffer = NULL;
- }
+ if (pp->priv->line_buffer != NULL)
+ {
+ g_string_free (pp->priv->line_buffer, TRUE);
+ pp->priv->line_buffer = NULL;
+ }
}
/**
@@ -508,11 +523,11 @@ latexila_post_processor_process_finish (LatexilaPostProcessor *pp,
*/
void
latexila_post_processor_start (LatexilaPostProcessor *pp,
- GFile *file)
+ GFile *file)
{
- g_return_if_fail (LATEXILA_IS_POST_PROCESSOR (pp));
+ g_return_if_fail (LATEXILA_IS_POST_PROCESSOR (pp));
- return LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->start (pp, file);
+ return LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->start (pp, file);
}
/**
@@ -527,11 +542,11 @@ latexila_post_processor_start (LatexilaPostProcessor *pp,
*/
void
latexila_post_processor_process_line (LatexilaPostProcessor *pp,
- gchar *line)
+ gchar *line)
{
- g_return_if_fail (LATEXILA_IS_POST_PROCESSOR (pp));
+ g_return_if_fail (LATEXILA_IS_POST_PROCESSOR (pp));
- return LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->process_line (pp, line);
+ return LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->process_line (pp, line);
}
/**
@@ -545,13 +560,13 @@ latexila_post_processor_process_line (LatexilaPostProcessor *pp,
*/
void
latexila_post_processor_end (LatexilaPostProcessor *pp,
- gboolean succeeded)
+ gboolean succeeded)
{
- g_return_if_fail (LATEXILA_IS_POST_PROCESSOR (pp));
+ g_return_if_fail (LATEXILA_IS_POST_PROCESSOR (pp));
- succeeded = succeeded != FALSE;
+ succeeded = succeeded != FALSE;
- return LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->end (pp, succeeded);
+ return LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->end (pp, succeeded);
}
/**
@@ -587,13 +602,13 @@ latexila_post_processor_end (LatexilaPostProcessor *pp,
*/
const GList *
latexila_post_processor_get_messages (LatexilaPostProcessor *pp,
- gboolean show_details)
+ gboolean show_details)
{
- g_return_val_if_fail (LATEXILA_IS_POST_PROCESSOR (pp), NULL);
+ g_return_val_if_fail (LATEXILA_IS_POST_PROCESSOR (pp), NULL);
- show_details = show_details != FALSE;
+ show_details = show_details != FALSE;
- return LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->get_messages (pp, show_details);
+ return LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->get_messages (pp, show_details);
}
/**
@@ -609,7 +624,7 @@ latexila_post_processor_get_messages (LatexilaPostProcessor *pp,
GQueue *
latexila_post_processor_take_messages (LatexilaPostProcessor *pp)
{
- g_return_val_if_fail (LATEXILA_IS_POST_PROCESSOR (pp), NULL);
+ g_return_val_if_fail (LATEXILA_IS_POST_PROCESSOR (pp), NULL);
- return LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->take_messages (pp);
+ return LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->take_messages (pp);
}
diff --git a/src/liblatexila/latexila-synctex.c b/src/liblatexila/latexila-synctex.c
index 39d4d07..43dcef8 100644
--- a/src/liblatexila/latexila-synctex.c
+++ b/src/liblatexila/latexila-synctex.c
@@ -45,28 +45,28 @@
struct _LatexilaSynctexPrivate
{
- /* PDF URI -> EvinceWindow object */
- GHashTable *evince_windows;
+ /* PDF URI -> EvinceWindow object */
+ GHashTable *evince_windows;
};
typedef struct
{
- GtkTextBuffer *buffer;
- GFile *buffer_location;
- gchar *pdf_uri;
- guint timestamp;
+ GtkTextBuffer *buffer;
+ GFile *buffer_location;
+ gchar *pdf_uri;
+ guint timestamp;
} ForwardSearchData;
typedef struct
{
- gchar *pdf_uri;
- gchar *owner;
+ gchar *pdf_uri;
+ gchar *owner;
} ConnectEvinceWindowData;
enum
{
- SIGNAL_BACKWARD_SEARCH,
- LAST_SIGNAL
+ SIGNAL_BACKWARD_SEARCH,
+ LAST_SIGNAL
};
G_DEFINE_TYPE_WITH_PRIVATE (LatexilaSynctex, latexila_synctex, G_TYPE_OBJECT)
@@ -77,88 +77,88 @@ static guint signals[LAST_SIGNAL];
static ForwardSearchData *
forward_search_data_new (void)
{
- return g_slice_new0 (ForwardSearchData);
+ return g_slice_new0 (ForwardSearchData);
}
static void
forward_search_data_free (ForwardSearchData *data)
{
- if (data != NULL)
- {
- g_clear_object (&data->buffer);
- g_clear_object (&data->buffer_location);
- g_free (data->pdf_uri);
- g_slice_free (ForwardSearchData, data);
- }
+ if (data != NULL)
+ {
+ g_clear_object (&data->buffer);
+ g_clear_object (&data->buffer_location);
+ g_free (data->pdf_uri);
+ g_slice_free (ForwardSearchData, data);
+ }
}
static ConnectEvinceWindowData *
connect_evince_window_data_new (void)
{
- return g_slice_new0 (ConnectEvinceWindowData);
+ return g_slice_new0 (ConnectEvinceWindowData);
}
static void
connect_evince_window_data_free (ConnectEvinceWindowData *data)
{
- if (data != NULL)
- {
- g_free (data->pdf_uri);
- g_free (data->owner);
- g_slice_free (ConnectEvinceWindowData, data);
- }
+ if (data != NULL)
+ {
+ g_free (data->pdf_uri);
+ g_free (data->owner);
+ g_slice_free (ConnectEvinceWindowData, data);
+ }
}
static void
latexila_synctex_dispose (GObject *object)
{
- LatexilaSynctex *synctex = LATEXILA_SYNCTEX (object);
+ LatexilaSynctex *synctex = LATEXILA_SYNCTEX (object);
- if (synctex->priv->evince_windows != NULL)
- {
- g_hash_table_unref (synctex->priv->evince_windows);
- synctex->priv->evince_windows = NULL;
- }
+ if (synctex->priv->evince_windows != NULL)
+ {
+ g_hash_table_unref (synctex->priv->evince_windows);
+ synctex->priv->evince_windows = NULL;
+ }
- G_OBJECT_CLASS (latexila_synctex_parent_class)->dispose (object);
+ G_OBJECT_CLASS (latexila_synctex_parent_class)->dispose (object);
}
static void
latexila_synctex_class_init (LatexilaSynctexClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = latexila_synctex_dispose;
-
- /**
- * LatexilaSynctex::backward-search:
- * @synctex: the #LatexilaSynctex instance.
- * @tex_uri: the *.tex file URI.
- * @line: the line to jump to.
- * @timestamp: timestamp of the event.
- *
- * The ::backward-search signal is emitted to perform a backward search, i.e.
- * switching from the PDF to the source *.tex file.
- */
- signals[SIGNAL_BACKWARD_SEARCH] = g_signal_new ("backward-search",
- LATEXILA_TYPE_SYNCTEX,
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE, 3,
- G_TYPE_STRING,
- G_TYPE_INT,
- G_TYPE_UINT);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = latexila_synctex_dispose;
+
+ /**
+ * LatexilaSynctex::backward-search:
+ * @synctex: the #LatexilaSynctex instance.
+ * @tex_uri: the *.tex file URI.
+ * @line: the line to jump to.
+ * @timestamp: timestamp of the event.
+ *
+ * The ::backward-search signal is emitted to perform a backward search, i.e.
+ * switching from the PDF to the source *.tex file.
+ */
+ signals[SIGNAL_BACKWARD_SEARCH] = g_signal_new ("backward-search",
+ LATEXILA_TYPE_SYNCTEX,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 3,
+ G_TYPE_STRING,
+ G_TYPE_INT,
+ G_TYPE_UINT);
}
static void
latexila_synctex_init (LatexilaSynctex *synctex)
{
- synctex->priv = latexila_synctex_get_instance_private (synctex);
+ synctex->priv = latexila_synctex_get_instance_private (synctex);
- synctex->priv->evince_windows = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- g_object_unref);
+ synctex->priv->evince_windows = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_object_unref);
}
/**
@@ -169,309 +169,311 @@ latexila_synctex_init (LatexilaSynctex *synctex)
LatexilaSynctex *
latexila_synctex_get_instance (void)
{
- if (instance == NULL)
- instance = g_object_new (LATEXILA_TYPE_SYNCTEX, NULL);
+ if (instance == NULL)
+ {
+ instance = g_object_new (LATEXILA_TYPE_SYNCTEX, NULL);
+ }
- return instance;
+ return instance;
}
static void
show_warning (const gchar *message)
{
- GtkApplication *app;
- GtkWindow *parent;
- GtkWidget *dialog;
+ GtkApplication *app;
+ GtkWindow *parent;
+ GtkWidget *dialog;
- app = GTK_APPLICATION (g_application_get_default ());
- parent = gtk_application_get_active_window (app);
+ app = GTK_APPLICATION (g_application_get_default ());
+ parent = gtk_application_get_active_window (app);
- dialog = gtk_message_dialog_new (parent,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- "%s", _("Impossible to do the forward search."));
+ dialog = gtk_message_dialog_new (parent,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ "%s", _ ("Impossible to do the forward search."));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s", message);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", message);
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
}
static gchar *
get_pdf_uri (GFile *main_tex_file)
{
- gchar *tex_uri;
- gchar *short_uri;
- gchar *pdf_uri;
+ gchar *tex_uri;
+ gchar *short_uri;
+ gchar *pdf_uri;
- tex_uri = g_file_get_uri (main_tex_file);
- short_uri = latexila_utils_get_shortname (tex_uri);
- pdf_uri = g_strdup_printf ("%s.pdf", short_uri);
+ tex_uri = g_file_get_uri (main_tex_file);
+ short_uri = latexila_utils_get_shortname (tex_uri);
+ pdf_uri = g_strdup_printf ("%s.pdf", short_uri);
- g_free (tex_uri);
- g_free (short_uri);
- return pdf_uri;
+ g_free (tex_uri);
+ g_free (short_uri);
+ return pdf_uri;
}
static GVariant *
get_buffer_position (GtkTextBuffer *buffer)
{
- GtkTextIter iter;
- gint line;
- gint column;
+ GtkTextIter iter;
+ gint line;
+ gint column;
- gtk_text_buffer_get_iter_at_mark (buffer,
- &iter,
- gtk_text_buffer_get_insert (buffer));
+ gtk_text_buffer_get_iter_at_mark (buffer,
+ &iter,
+ gtk_text_buffer_get_insert (buffer));
- line = gtk_text_iter_get_line (&iter) + 1;
+ line = gtk_text_iter_get_line (&iter) + 1;
- /* Ignore the column, it gives a better result. */
- column = -1;
+ /* Ignore the column, it gives a better result. */
+ column = -1;
- return g_variant_new ("(ii)", line, column);
+ return g_variant_new ("(ii)", line, column);
}
static void
window_closed_cb (EvinceWindow *window,
- const gchar *pdf_uri)
+ const gchar *pdf_uri)
{
- g_hash_table_remove (instance->priv->evince_windows, pdf_uri);
+ g_hash_table_remove (instance->priv->evince_windows, pdf_uri);
}
static void
sync_source_cb (EvinceWindow *window,
- const gchar *tex_uri,
- GVariant *pos,
- guint timestamp,
- LatexilaSynctex *synctex)
+ const gchar *tex_uri,
+ GVariant *pos,
+ guint timestamp,
+ LatexilaSynctex *synctex)
{
- gint line;
- gint column; /* not used */
+ gint line;
+ gint column; /* not used */
- g_variant_get (pos, "(ii)", &line, &column);
+ g_variant_get (pos, "(ii)", &line, &column);
- g_signal_emit (synctex,
- signals[SIGNAL_BACKWARD_SEARCH], 0,
- tex_uri,
- line - 1,
- timestamp);
+ g_signal_emit (synctex,
+ signals[SIGNAL_BACKWARD_SEARCH], 0,
+ tex_uri,
+ line - 1,
+ timestamp);
}
static void
window_proxy_cb (GObject *object,
- GAsyncResult *result,
- GTask *task)
+ GAsyncResult *result,
+ GTask *task)
{
- EvinceWindow *window;
- ConnectEvinceWindowData *data;
- GError *error = NULL;
+ EvinceWindow *window;
+ ConnectEvinceWindowData *data;
+ GError *error = NULL;
- window = evince_window_proxy_new_for_bus_finish (result, &error);
+ window = evince_window_proxy_new_for_bus_finish (result, &error);
- if (error != NULL)
- {
- g_warning ("SyncTeX: can not connect to evince window: %s", error->message);
- g_task_return_boolean (task, FALSE);
- g_object_unref (task);
- g_error_free (error);
- return;
- }
+ if (error != NULL)
+ {
+ g_warning ("SyncTeX: can not connect to evince window: %s", error->message);
+ g_task_return_boolean (task, FALSE);
+ g_object_unref (task);
+ g_error_free (error);
+ return;
+ }
- data = g_task_get_task_data (task);
+ data = g_task_get_task_data (task);
- g_hash_table_insert (instance->priv->evince_windows, data->pdf_uri, window);
+ g_hash_table_insert (instance->priv->evince_windows, data->pdf_uri, window);
- g_signal_connect (window,
- "closed",
- G_CALLBACK (window_closed_cb),
- data->pdf_uri);
+ g_signal_connect (window,
+ "closed",
+ G_CALLBACK (window_closed_cb),
+ data->pdf_uri);
- g_signal_connect (window,
- "sync-source",
- G_CALLBACK (sync_source_cb),
- instance);
+ g_signal_connect (window,
+ "sync-source",
+ G_CALLBACK (sync_source_cb),
+ instance);
- data->pdf_uri = NULL;
+ data->pdf_uri = NULL;
- /* connect_evince_window_async() is finally finished! */
- g_task_return_boolean (task, TRUE);
- g_object_unref (task);
+ /* connect_evince_window_async() is finally finished! */
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
}
static void
get_window_list_cb (EvinceApplication *app,
- GAsyncResult *result,
- GTask *task)
+ GAsyncResult *result,
+ GTask *task)
{
- ConnectEvinceWindowData *data;
- gchar **window_list;
- gchar *window_path;
- GError *error = NULL;
-
- evince_application_call_get_window_list_finish (app, &window_list, result, &error);
- g_object_unref (app);
-
- if (error != NULL)
- {
- g_warning ("SyncTeX: can not get window list: %s", error->message);
- g_task_return_boolean (task, FALSE);
- g_object_unref (task);
- g_error_free (error);
- return;
- }
-
- if (window_list == NULL || window_list[0] == NULL)
- {
- g_warning ("SyncTeX: the window list is empty.");
- g_task_return_boolean (task, FALSE);
- g_object_unref (task);
- g_strfreev (window_list);
- return;
- }
-
- data = g_task_get_task_data (task);
-
- /* There is normally only one window. */
- window_path = window_list[0];
-
- evince_window_proxy_new_for_bus (G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_NONE,
- data->owner,
- window_path,
- NULL,
- (GAsyncReadyCallback) window_proxy_cb,
- task);
-
- g_strfreev (window_list);
+ ConnectEvinceWindowData *data;
+ gchar **window_list;
+ gchar *window_path;
+ GError *error = NULL;
+
+ evince_application_call_get_window_list_finish (app, &window_list, result, &error);
+ g_object_unref (app);
+
+ if (error != NULL)
+ {
+ g_warning ("SyncTeX: can not get window list: %s", error->message);
+ g_task_return_boolean (task, FALSE);
+ g_object_unref (task);
+ g_error_free (error);
+ return;
+ }
+
+ if (window_list == NULL || window_list[0] == NULL)
+ {
+ g_warning ("SyncTeX: the window list is empty.");
+ g_task_return_boolean (task, FALSE);
+ g_object_unref (task);
+ g_strfreev (window_list);
+ return;
+ }
+
+ data = g_task_get_task_data (task);
+
+ /* There is normally only one window. */
+ window_path = window_list[0];
+
+ evince_window_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ data->owner,
+ window_path,
+ NULL,
+ (GAsyncReadyCallback) window_proxy_cb,
+ task);
+
+ g_strfreev (window_list);
}
static void
application_proxy_cb (GObject *object,
- GAsyncResult *result,
- GTask *task)
+ GAsyncResult *result,
+ GTask *task)
{
- EvinceApplication *app;
- GError *error = NULL;
-
- app = evince_application_proxy_new_for_bus_finish (result, &error);
-
- if (error != NULL)
- {
- g_warning ("SyncTeX: can not connect to evince application: %s", error->message);
- g_task_return_boolean (task, FALSE);
- g_object_unref (task);
- g_error_free (error);
- return;
- }
-
- evince_application_call_get_window_list (app,
- NULL,
- (GAsyncReadyCallback) get_window_list_cb,
- task);
+ EvinceApplication *app;
+ GError *error = NULL;
+
+ app = evince_application_proxy_new_for_bus_finish (result, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("SyncTeX: can not connect to evince application: %s", error->message);
+ g_task_return_boolean (task, FALSE);
+ g_object_unref (task);
+ g_error_free (error);
+ return;
+ }
+
+ evince_application_call_get_window_list (app,
+ NULL,
+ (GAsyncReadyCallback) get_window_list_cb,
+ task);
}
static void
find_document_cb (EvinceDaemon *daemon,
- GAsyncResult *result,
- GTask *task)
+ GAsyncResult *result,
+ GTask *task)
{
- ConnectEvinceWindowData *data;
- GError *error = NULL;
-
- data = g_task_get_task_data (task);
-
- evince_daemon_call_find_document_finish (daemon, &data->owner, result, &error);
- g_object_unref (daemon);
-
- if (error != NULL)
- {
- g_warning ("SyncTeX: find document: %s", error->message);
- g_task_return_boolean (task, FALSE);
- g_object_unref (task);
- g_error_free (error);
- return;
- }
-
- evince_application_proxy_new_for_bus (G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_NONE,
- data->owner,
- "/org/gnome/evince/Evince",
- NULL,
- (GAsyncReadyCallback) application_proxy_cb,
- task);
+ ConnectEvinceWindowData *data;
+ GError *error = NULL;
+
+ data = g_task_get_task_data (task);
+
+ evince_daemon_call_find_document_finish (daemon, &data->owner, result, &error);
+ g_object_unref (daemon);
+
+ if (error != NULL)
+ {
+ g_warning ("SyncTeX: find document: %s", error->message);
+ g_task_return_boolean (task, FALSE);
+ g_object_unref (task);
+ g_error_free (error);
+ return;
+ }
+
+ evince_application_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ data->owner,
+ "/org/gnome/evince/Evince",
+ NULL,
+ (GAsyncReadyCallback) application_proxy_cb,
+ task);
}
static void
daemon_proxy_cb (GObject *object,
- GAsyncResult *result,
- GTask *task)
+ GAsyncResult *result,
+ GTask *task)
{
- EvinceDaemon *daemon;
- GError *error = NULL;
- ConnectEvinceWindowData *data;
-
- daemon = evince_daemon_proxy_new_for_bus_finish (result, &error);
-
- if (error != NULL)
- {
- g_warning ("SyncTeX: can not connect to the evince daemon: %s", error->message);
- g_task_return_boolean (task, FALSE);
- g_object_unref (task);
- g_error_free (error);
- return;
- }
-
- data = g_task_get_task_data (task);
-
- evince_daemon_call_find_document (daemon, data->pdf_uri, TRUE, NULL,
- (GAsyncReadyCallback) find_document_cb,
- task);
+ EvinceDaemon *daemon;
+ GError *error = NULL;
+ ConnectEvinceWindowData *data;
+
+ daemon = evince_daemon_proxy_new_for_bus_finish (result, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("SyncTeX: can not connect to the evince daemon: %s", error->message);
+ g_task_return_boolean (task, FALSE);
+ g_object_unref (task);
+ g_error_free (error);
+ return;
+ }
+
+ data = g_task_get_task_data (task);
+
+ evince_daemon_call_find_document (daemon, data->pdf_uri, TRUE, NULL,
+ (GAsyncReadyCallback) find_document_cb,
+ task);
}
static void
connect_evince_window_async (LatexilaSynctex *synctex,
- const gchar *pdf_uri,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ const gchar *pdf_uri,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- GTask *task;
- ConnectEvinceWindowData *data;
+ GTask *task;
+ ConnectEvinceWindowData *data;
- g_return_if_fail (LATEXILA_IS_SYNCTEX (synctex));
- g_return_if_fail (pdf_uri != NULL);
+ g_return_if_fail (LATEXILA_IS_SYNCTEX (synctex));
+ g_return_if_fail (pdf_uri != NULL);
- task = g_task_new (synctex, NULL, callback, user_data);
+ task = g_task_new (synctex, NULL, callback, user_data);
- if (g_hash_table_contains (synctex->priv->evince_windows, pdf_uri))
- {
- g_task_return_boolean (task, TRUE);
- g_object_unref (task);
- return;
- }
+ if (g_hash_table_contains (synctex->priv->evince_windows, pdf_uri))
+ {
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
+ return;
+ }
- data = connect_evince_window_data_new ();
- data->pdf_uri = g_strdup (pdf_uri);
+ data = connect_evince_window_data_new ();
+ data->pdf_uri = g_strdup (pdf_uri);
- g_task_set_task_data (task, data, (GDestroyNotify) connect_evince_window_data_free);
+ g_task_set_task_data (task, data, (GDestroyNotify) connect_evince_window_data_free);
- evince_daemon_proxy_new_for_bus (G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.gnome.evince.Daemon",
- "/org/gnome/evince/Daemon",
- NULL,
- (GAsyncReadyCallback) daemon_proxy_cb,
- task);
+ evince_daemon_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.gnome.evince.Daemon",
+ "/org/gnome/evince/Daemon",
+ NULL,
+ (GAsyncReadyCallback) daemon_proxy_cb,
+ task);
}
static void
connect_evince_window_finish (LatexilaSynctex *synctex,
- GAsyncResult *result)
+ GAsyncResult *result)
{
- g_return_if_fail (g_task_is_valid (result, synctex));
+ g_return_if_fail (g_task_is_valid (result, synctex));
- g_task_propagate_boolean (G_TASK (result), NULL);
+ g_task_propagate_boolean (G_TASK (result), NULL);
}
/**
@@ -485,126 +487,126 @@ connect_evince_window_finish (LatexilaSynctex *synctex,
*/
void
latexila_synctex_connect_evince_window (LatexilaSynctex *synctex,
- const gchar *pdf_uri)
+ const gchar *pdf_uri)
{
- connect_evince_window_async (synctex,
- pdf_uri,
- (GAsyncReadyCallback) connect_evince_window_finish,
- NULL);
+ connect_evince_window_async (synctex,
+ pdf_uri,
+ (GAsyncReadyCallback) connect_evince_window_finish,
+ NULL);
}
static void
sync_view_cb (EvinceWindow *evince_window,
- GAsyncResult *result,
- ForwardSearchData *data)
+ GAsyncResult *result,
+ ForwardSearchData *data)
{
- GError *error = NULL;
+ GError *error = NULL;
- evince_window_call_sync_view_finish (evince_window, result, &error);
+ evince_window_call_sync_view_finish (evince_window, result, &error);
- if (error != NULL)
- {
- g_warning ("SyncTeX: can not sync view: %s", error->message);
- g_error_free (error);
- }
+ if (error != NULL)
+ {
+ g_warning ("SyncTeX: can not sync view: %s", error->message);
+ g_error_free (error);
+ }
- /* latexila_synctex_forward_search() finished! */
- forward_search_data_free (data);
+ /* latexila_synctex_forward_search() finished! */
+ forward_search_data_free (data);
}
static void
connect_evince_window_cb (LatexilaSynctex *synctex,
- GAsyncResult *result,
- ForwardSearchData *data)
+ GAsyncResult *result,
+ ForwardSearchData *data)
{
- EvinceWindow *evince_window;
- gchar *buffer_path;
+ EvinceWindow *evince_window;
+ gchar *buffer_path;
- connect_evince_window_finish (synctex, result);
+ connect_evince_window_finish (synctex, result);
- evince_window = g_hash_table_lookup (synctex->priv->evince_windows, data->pdf_uri);
+ evince_window = g_hash_table_lookup (synctex->priv->evince_windows, data->pdf_uri);
- if (evince_window == NULL)
- {
- show_warning (_("Can not communicate with evince."));
- forward_search_data_free (data);
- return;
- }
+ if (evince_window == NULL)
+ {
+ show_warning (_ ("Can not communicate with evince."));
+ forward_search_data_free (data);
+ return;
+ }
- buffer_path = g_file_get_path (data->buffer_location);
+ buffer_path = g_file_get_path (data->buffer_location);
- evince_window_call_sync_view (evince_window,
- buffer_path,
- get_buffer_position (data->buffer),
- data->timestamp,
- NULL,
- (GAsyncReadyCallback) sync_view_cb,
- data);
+ evince_window_call_sync_view (evince_window,
+ buffer_path,
+ get_buffer_position (data->buffer),
+ data->timestamp,
+ NULL,
+ (GAsyncReadyCallback) sync_view_cb,
+ data);
- g_free (buffer_path);
+ g_free (buffer_path);
}
static void
synctex_file_query_exists_cb (GFile *synctex_file,
- GAsyncResult *result,
- ForwardSearchData *data)
+ GAsyncResult *result,
+ ForwardSearchData *data)
{
- gboolean synctex_file_exists;
+ gboolean synctex_file_exists;
- synctex_file_exists = latexila_utils_file_query_exists_finish (synctex_file, result);
+ synctex_file_exists = latexila_utils_file_query_exists_finish (synctex_file, result);
- if (!synctex_file_exists)
- {
- gchar *basename = g_file_get_basename (synctex_file);
- gchar *message = g_strdup_printf (_("The file \"%s\" doesn't exist."), basename);
+ if (!synctex_file_exists)
+ {
+ gchar *basename = g_file_get_basename (synctex_file);
+ gchar *message = g_strdup_printf (_ ("The file \"%s\" doesn't exist."), basename);
- show_warning (message);
+ show_warning (message);
- g_free (basename);
- g_free (message);
- g_object_unref (synctex_file);
- forward_search_data_free (data);
- return;
- }
+ g_free (basename);
+ g_free (message);
+ g_object_unref (synctex_file);
+ forward_search_data_free (data);
+ return;
+ }
- connect_evince_window_async (instance,
- data->pdf_uri,
- (GAsyncReadyCallback) connect_evince_window_cb,
- data);
+ connect_evince_window_async (instance,
+ data->pdf_uri,
+ (GAsyncReadyCallback) connect_evince_window_cb,
+ data);
- g_object_unref (synctex_file);
+ g_object_unref (synctex_file);
}
static void
pdf_file_query_exists_cb (GFile *pdf_file,
- GAsyncResult *result,
- ForwardSearchData *data)
+ GAsyncResult *result,
+ ForwardSearchData *data)
{
- gboolean pdf_file_exists;
- gchar *short_uri;
- gchar *synctex_uri;
- GFile *synctex_file;
-
- pdf_file_exists = latexila_utils_file_query_exists_finish (pdf_file, result);
- g_object_unref (pdf_file);
-
- if (!pdf_file_exists)
- {
- show_warning (_("The PDF file doesn't exist."));
- forward_search_data_free (data);
- return;
- }
-
- short_uri = latexila_utils_get_shortname (data->pdf_uri);
- synctex_uri = g_strdup_printf ("%s.synctex.gz", short_uri);
- synctex_file = g_file_new_for_uri (synctex_uri);
- g_free (short_uri);
- g_free (synctex_uri);
-
- latexila_utils_file_query_exists_async (synctex_file,
- NULL,
- (GAsyncReadyCallback) synctex_file_query_exists_cb,
- data);
+ gboolean pdf_file_exists;
+ gchar *short_uri;
+ gchar *synctex_uri;
+ GFile *synctex_file;
+
+ pdf_file_exists = latexila_utils_file_query_exists_finish (pdf_file, result);
+ g_object_unref (pdf_file);
+
+ if (!pdf_file_exists)
+ {
+ show_warning (_ ("The PDF file doesn't exist."));
+ forward_search_data_free (data);
+ return;
+ }
+
+ short_uri = latexila_utils_get_shortname (data->pdf_uri);
+ synctex_uri = g_strdup_printf ("%s.synctex.gz", short_uri);
+ synctex_file = g_file_new_for_uri (synctex_uri);
+ g_free (short_uri);
+ g_free (synctex_uri);
+
+ latexila_utils_file_query_exists_async (synctex_file,
+ NULL,
+ (GAsyncReadyCallback) synctex_file_query_exists_cb,
+ data);
}
/**
@@ -626,37 +628,37 @@ pdf_file_query_exists_cb (GFile *pdf_file,
*/
void
latexila_synctex_forward_search (LatexilaSynctex *synctex,
- GtkTextBuffer *buffer,
- GFile *buffer_location,
- GFile *main_tex_file,
- guint timestamp)
+ GtkTextBuffer *buffer,
+ GFile *buffer_location,
+ GFile *main_tex_file,
+ guint timestamp)
{
- ForwardSearchData *data;
- GFile *pdf_file;
-
- g_return_if_fail (LATEXILA_IS_SYNCTEX (synctex));
- g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
- g_return_if_fail (buffer_location == NULL || G_IS_FILE (buffer_location));
- g_return_if_fail (main_tex_file == NULL || G_IS_FILE (main_tex_file));
-
- if (buffer_location == NULL)
- {
- show_warning (_("The document is not saved."));
- return;
- }
-
- g_return_if_fail (G_IS_FILE (main_tex_file));
-
- data = forward_search_data_new ();
- data->buffer = g_object_ref (buffer);
- data->buffer_location = g_object_ref (buffer_location);
- data->pdf_uri = get_pdf_uri (main_tex_file);
- data->timestamp = timestamp;
-
- pdf_file = g_file_new_for_uri (data->pdf_uri);
-
- latexila_utils_file_query_exists_async (pdf_file,
- NULL,
- (GAsyncReadyCallback) pdf_file_query_exists_cb,
- data);
+ ForwardSearchData *data;
+ GFile *pdf_file;
+
+ g_return_if_fail (LATEXILA_IS_SYNCTEX (synctex));
+ g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
+ g_return_if_fail (buffer_location == NULL || G_IS_FILE (buffer_location));
+ g_return_if_fail (main_tex_file == NULL || G_IS_FILE (main_tex_file));
+
+ if (buffer_location == NULL)
+ {
+ show_warning (_ ("The document is not saved."));
+ return;
+ }
+
+ g_return_if_fail (G_IS_FILE (main_tex_file));
+
+ data = forward_search_data_new ();
+ data->buffer = g_object_ref (buffer);
+ data->buffer_location = g_object_ref (buffer_location);
+ data->pdf_uri = get_pdf_uri (main_tex_file);
+ data->timestamp = timestamp;
+
+ pdf_file = g_file_new_for_uri (data->pdf_uri);
+
+ latexila_utils_file_query_exists_async (pdf_file,
+ NULL,
+ (GAsyncReadyCallback) pdf_file_query_exists_cb,
+ data);
}
diff --git a/src/liblatexila/latexila-templates-common.c b/src/liblatexila/latexila-templates-common.c
index 3b359f9..0b75646 100644
--- a/src/liblatexila/latexila-templates-common.c
+++ b/src/liblatexila/latexila-templates-common.c
@@ -24,11 +24,11 @@
void
latexila_templates_init_store (GtkListStore *store)
{
- GType types[] = {G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_FILE};
+ GType types[] = {G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_FILE};
- gtk_list_store_set_column_types (store,
- LATEXILA_TEMPLATES_N_COLUMNS,
- types);
+ gtk_list_store_set_column_types (store,
+ LATEXILA_TEMPLATES_N_COLUMNS,
+ types);
}
/* For compatibility reasons. @config_icon_name is the string stored in the rc
@@ -40,47 +40,59 @@ latexila_templates_init_store (GtkListStore *store)
static const gchar *
get_pixbuf_icon_name (const gchar *config_icon_name)
{
- g_return_val_if_fail (config_icon_name != NULL, NULL);
-
- if (g_str_equal (config_icon_name, "empty"))
- return "text-x-preview";
-
- if (g_str_equal (config_icon_name, "article"))
- return "text-x-generic";
-
- if (g_str_equal (config_icon_name, "report"))
- return "x-office-document";
-
- if (g_str_equal (config_icon_name, "book"))
- return "accessories-dictionary";
-
- if (g_str_equal (config_icon_name, "letter"))
- return "emblem-mail";
-
- if (g_str_equal (config_icon_name, "beamer"))
- return "x-office-presentation";
-
- g_return_val_if_reached (NULL);
+ g_return_val_if_fail (config_icon_name != NULL, NULL);
+
+ if (g_str_equal (config_icon_name, "empty"))
+ {
+ return "text-x-preview";
+ }
+
+ if (g_str_equal (config_icon_name, "article"))
+ {
+ return "text-x-generic";
+ }
+
+ if (g_str_equal (config_icon_name, "report"))
+ {
+ return "x-office-document";
+ }
+
+ if (g_str_equal (config_icon_name, "book"))
+ {
+ return "accessories-dictionary";
+ }
+
+ if (g_str_equal (config_icon_name, "letter"))
+ {
+ return "emblem-mail";
+ }
+
+ if (g_str_equal (config_icon_name, "beamer"))
+ {
+ return "x-office-presentation";
+ }
+
+ g_return_val_if_reached (NULL);
}
void
latexila_templates_add_template (GtkListStore *store,
- const gchar *name,
- const gchar *config_icon_name,
- GFile *file)
+ const gchar *name,
+ const gchar *config_icon_name,
+ GFile *file)
{
- GtkTreeIter iter;
- const gchar *pixbuf_icon_name;
-
- pixbuf_icon_name = get_pixbuf_icon_name (config_icon_name);
-
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- LATEXILA_TEMPLATES_COLUMN_PIXBUF_ICON_NAME, pixbuf_icon_name,
- LATEXILA_TEMPLATES_COLUMN_CONFIG_ICON_NAME, config_icon_name,
- LATEXILA_TEMPLATES_COLUMN_NAME, name,
- LATEXILA_TEMPLATES_COLUMN_FILE, file,
- -1);
+ GtkTreeIter iter;
+ const gchar *pixbuf_icon_name;
+
+ pixbuf_icon_name = get_pixbuf_icon_name (config_icon_name);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ LATEXILA_TEMPLATES_COLUMN_PIXBUF_ICON_NAME, pixbuf_icon_name,
+ LATEXILA_TEMPLATES_COLUMN_CONFIG_ICON_NAME, config_icon_name,
+ LATEXILA_TEMPLATES_COLUMN_NAME, name,
+ LATEXILA_TEMPLATES_COLUMN_FILE, file,
+ -1);
}
/**
@@ -92,41 +104,41 @@ latexila_templates_add_template (GtkListStore *store,
GtkTreeView *
latexila_templates_get_view (GtkListStore *store)
{
- GtkTreeView *view;
- GtkTreeSelection *selection;
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
+ GtkTreeView *view;
+ GtkTreeSelection *selection;
+ GtkCellRenderer *renderer;
+ GtkTreeViewColumn *column;
- view = GTK_TREE_VIEW (gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)));
- gtk_tree_view_set_headers_visible (view, FALSE);
- gtk_widget_set_hexpand (GTK_WIDGET (view), TRUE);
- gtk_widget_set_vexpand (GTK_WIDGET (view), TRUE);
+ view = GTK_TREE_VIEW (gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)));
+ gtk_tree_view_set_headers_visible (view, FALSE);
+ gtk_widget_set_hexpand (GTK_WIDGET (view), TRUE);
+ gtk_widget_set_vexpand (GTK_WIDGET (view), TRUE);
- selection = gtk_tree_view_get_selection (view);
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
+ selection = gtk_tree_view_get_selection (view);
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
- /* Icon */
- renderer = gtk_cell_renderer_pixbuf_new ();
- g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL);
+ /* Icon */
+ renderer = gtk_cell_renderer_pixbuf_new ();
+ g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL);
- column = gtk_tree_view_column_new_with_attributes (NULL,
- renderer,
- "icon-name",
- LATEXILA_TEMPLATES_COLUMN_PIXBUF_ICON_NAME,
- NULL);
+ column = gtk_tree_view_column_new_with_attributes (NULL,
+ renderer,
+ "icon-name",
+ LATEXILA_TEMPLATES_COLUMN_PIXBUF_ICON_NAME,
+ NULL);
- gtk_tree_view_append_column (view, column);
+ gtk_tree_view_append_column (view, column);
- /* Name */
- renderer = gtk_cell_renderer_text_new ();
+ /* Name */
+ renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes (NULL,
- renderer,
- "text",
- LATEXILA_TEMPLATES_COLUMN_NAME,
- NULL);
+ column = gtk_tree_view_column_new_with_attributes (NULL,
+ renderer,
+ "text",
+ LATEXILA_TEMPLATES_COLUMN_NAME,
+ NULL);
- gtk_tree_view_append_column (view, column);
+ gtk_tree_view_append_column (view, column);
- return view;
+ return view;
}
diff --git a/src/liblatexila/latexila-templates-default.c b/src/liblatexila/latexila-templates-default.c
index 6a8b12c..ac471b2 100644
--- a/src/liblatexila/latexila-templates-default.c
+++ b/src/liblatexila/latexila-templates-default.c
@@ -50,7 +50,7 @@
struct _LatexilaTemplatesDefault
{
- GtkListStore parent;
+ GtkListStore parent;
};
G_DEFINE_TYPE (LatexilaTemplatesDefault, latexila_templates_default, GTK_TYPE_LIST_STORE)
@@ -62,40 +62,40 @@ latexila_templates_default_class_init (LatexilaTemplatesDefaultClass *klass)
static void
add_default_template (LatexilaTemplatesDefault *templates,
- const gchar *name,
- const gchar *config_icon_name,
- const gchar *filename)
+ const gchar *name,
+ const gchar *config_icon_name,
+ const gchar *filename)
{
- gchar *path;
- GFile *file;
+ gchar *path;
+ GFile *file;
- path = g_build_filename (DATA_DIR, "templates", filename, NULL);
- file = g_file_new_for_path (path);
+ path = g_build_filename (DATA_DIR, "templates", filename, NULL);
+ file = g_file_new_for_path (path);
- latexila_templates_add_template (GTK_LIST_STORE (templates),
- name,
- config_icon_name,
- file);
+ latexila_templates_add_template (GTK_LIST_STORE (templates),
+ name,
+ config_icon_name,
+ file);
- g_free (path);
- g_object_unref (file);
+ g_free (path);
+ g_object_unref (file);
}
static void
latexila_templates_default_init (LatexilaTemplatesDefault *templates)
{
- latexila_templates_init_store (GTK_LIST_STORE (templates));
-
- latexila_templates_add_template (GTK_LIST_STORE (templates),
- _("Empty"),
- "empty",
- NULL);
-
- add_default_template (templates, _("Article"), "article", "article.xml");
- add_default_template (templates, _("Report"), "report", "report.xml");
- add_default_template (templates, _("Book"), "book", "book.xml");
- add_default_template (templates, _("Letter"), "letter", "letter.xml");
- add_default_template (templates, _("Presentation"), "beamer", "beamer.xml");
+ latexila_templates_init_store (GTK_LIST_STORE (templates));
+
+ latexila_templates_add_template (GTK_LIST_STORE (templates),
+ _ ("Empty"),
+ "empty",
+ NULL);
+
+ add_default_template (templates, _ ("Article"), "article", "article.xml");
+ add_default_template (templates, _ ("Report"), "report", "report.xml");
+ add_default_template (templates, _ ("Book"), "book", "book.xml");
+ add_default_template (templates, _ ("Letter"), "letter", "letter.xml");
+ add_default_template (templates, _ ("Presentation"), "beamer", "beamer.xml");
}
/**
@@ -108,79 +108,89 @@ latexila_templates_default_init (LatexilaTemplatesDefault *templates)
LatexilaTemplatesDefault *
latexila_templates_default_get_instance (void)
{
- static LatexilaTemplatesDefault *instance = NULL;
+ static LatexilaTemplatesDefault *instance = NULL;
- if (instance == NULL)
- instance = g_object_new (LATEXILA_TYPE_TEMPLATES_DEFAULT, NULL);
+ if (instance == NULL)
+ {
+ instance = g_object_new (LATEXILA_TYPE_TEMPLATES_DEFAULT, NULL);
+ }
- return instance;
+ return instance;
}
static void
parser_add_chunk (GString *string,
- const gchar *chunk,
- gint chunk_len)
+ const gchar *chunk,
+ gint chunk_len)
{
- if (chunk == NULL)
- return;
-
- /* Remove the first '\n'. Without this, the XML files would be less well
- * presented.
- */
- if (chunk[0] == '\n')
- {
- chunk = chunk + 1;
-
- if (chunk_len != -1)
- chunk_len--;
- }
-
- if (chunk_len != -1)
- g_string_append_len (string, chunk, chunk_len);
- else
- g_string_append (string, chunk);
+ if (chunk == NULL)
+ {
+ return;
+ }
+
+ /* Remove the first '\n'. Without this, the XML files would be less well
+ * presented.
+ */
+ if (chunk[0] == '\n')
+ {
+ chunk = chunk + 1;
+
+ if (chunk_len != -1)
+ {
+ chunk_len--;
+ }
+ }
+
+ if (chunk_len != -1)
+ {
+ g_string_append_len (string, chunk, chunk_len);
+ }
+ else
+ {
+ g_string_append (string, chunk);
+ }
}
static void
parser_text (GMarkupParseContext *context,
- const gchar *text,
- gsize text_len,
- gpointer user_data,
- GError **error)
+ const gchar *text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error)
{
- GString *template_contents = user_data;
- const gchar *element;
- gchar *text_nul_terminated = NULL;
-
- element = g_markup_parse_context_get_element (context);
-
- if (g_strcmp0 (element, "chunk") == 0)
- {
- parser_add_chunk (template_contents, text, text_len);
- }
-
- else if (g_strcmp0 (element, "translatableChunk") == 0)
- {
- const gchar *chunk;
-
- text_nul_terminated = g_strndup (text, text_len);
- chunk = _(text_nul_terminated);
-
- parser_add_chunk (template_contents, chunk, -1);
- }
-
- else if (g_strcmp0 (element, "babel") == 0)
- {
- const gchar *translated_text;
-
- text_nul_terminated = g_strndup (text, text_len);
- translated_text = _(text_nul_terminated);
-
- if (translated_text != text_nul_terminated)
- parser_add_chunk (template_contents, translated_text, -1);
- }
-
- g_free (text_nul_terminated);
+ GString *template_contents = user_data;
+ const gchar *element;
+ gchar *text_nul_terminated = NULL;
+
+ element = g_markup_parse_context_get_element (context);
+
+ if (g_strcmp0 (element, "chunk") == 0)
+ {
+ parser_add_chunk (template_contents, text, text_len);
+ }
+ else if (g_strcmp0 (element, "translatableChunk") == 0)
+ {
+ const gchar *chunk;
+
+ text_nul_terminated = g_strndup (text, text_len);
+ chunk = _ (text_nul_terminated);
+
+ parser_add_chunk (template_contents, chunk, -1);
+ }
+ else if (g_strcmp0 (element, "babel") == 0)
+ {
+ const gchar *translated_text;
+
+ text_nul_terminated = g_strndup (text, text_len);
+ translated_text = _ (text_nul_terminated);
+
+ if (translated_text != text_nul_terminated)
+ {
+ parser_add_chunk (template_contents, translated_text, -1);
+ }
+ }
+
+ g_free (text_nul_terminated);
}
/**
@@ -196,53 +206,59 @@ parser_text (GMarkupParseContext *context,
*/
gchar *
latexila_templates_default_get_contents (LatexilaTemplatesDefault *templates,
- GtkTreePath *path)
+ GtkTreePath *path)
{
- GtkTreeIter iter;
- GFile *xml_file;
- gchar *xml_contents = NULL;
- gsize xml_length;
- GString *template_contents = NULL;
- GMarkupParser parser = { NULL, NULL, parser_text, NULL, NULL };
- GMarkupParseContext *context = NULL;
- GError *error = NULL;
+ GtkTreeIter iter;
+ GFile *xml_file;
+ gchar *xml_contents = NULL;
+ gsize xml_length;
+ GString *template_contents = NULL;
+ GMarkupParser parser = { NULL, NULL, parser_text, NULL, NULL };
+ GMarkupParseContext *context = NULL;
+ GError *error = NULL;
- g_return_val_if_fail (LATEXILA_IS_TEMPLATES_DEFAULT (templates), NULL);
+ g_return_val_if_fail (LATEXILA_IS_TEMPLATES_DEFAULT (templates), NULL);
- gtk_tree_model_get_iter (GTK_TREE_MODEL (templates),
- &iter,
- path);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (templates),
+ &iter,
+ path);
- gtk_tree_model_get (GTK_TREE_MODEL (templates),
- &iter,
- LATEXILA_TEMPLATES_COLUMN_FILE, &xml_file,
- -1);
+ gtk_tree_model_get (GTK_TREE_MODEL (templates),
+ &iter,
+ LATEXILA_TEMPLATES_COLUMN_FILE, &xml_file,
+ -1);
- if (xml_file == NULL)
- return g_strdup ("");
+ if (xml_file == NULL)
+ {
+ return g_strdup ("");
+ }
- g_file_load_contents (xml_file, NULL, &xml_contents, &xml_length, NULL, &error);
+ g_file_load_contents (xml_file, NULL, &xml_contents, &xml_length, NULL, &error);
- template_contents = g_string_new (NULL);
+ template_contents = g_string_new (NULL);
- if (error != NULL)
- goto out;
+ if (error != NULL)
+ {
+ goto out;
+ }
- context = g_markup_parse_context_new (&parser, 0, template_contents, NULL);
- g_markup_parse_context_parse (context, xml_contents, xml_length, &error);
+ context = g_markup_parse_context_new (&parser, 0, template_contents, NULL);
+ g_markup_parse_context_parse (context, xml_contents, xml_length, &error);
out:
- g_object_unref (xml_file);
- g_free (xml_contents);
+ g_object_unref (xml_file);
+ g_free (xml_contents);
- if (context != NULL)
- g_markup_parse_context_unref (context);
+ if (context != NULL)
+ {
+ g_markup_parse_context_unref (context);
+ }
- if (error != NULL)
- {
- g_warning ("Error when loading default template contents: %s", error->message);
- g_error_free (error);
- }
+ if (error != NULL)
+ {
+ g_warning ("Error when loading default template contents: %s", error->message);
+ g_error_free (error);
+ }
- return g_string_free (template_contents, FALSE);
+ return g_string_free (template_contents, FALSE);
}
diff --git a/src/liblatexila/latexila-templates-dialogs.c b/src/liblatexila/latexila-templates-dialogs.c
index 063d379..eddb632 100644
--- a/src/liblatexila/latexila-templates-dialogs.c
+++ b/src/liblatexila/latexila-templates-dialogs.c
@@ -26,71 +26,73 @@
static void
init_open_dialog (GtkDialog *dialog,
- GtkTreeView *default_view,
- GtkTreeView *personal_view)
+ GtkTreeView *default_view,
+ GtkTreeView *personal_view)
{
- GtkContainer *hgrid;
- GtkWidget *scrolled_window;
- GtkWidget *component;
- GtkWidget *content_area;
+ GtkContainer *hgrid;
+ GtkWidget *scrolled_window;
+ GtkWidget *component;
+ GtkWidget *content_area;
- hgrid = GTK_CONTAINER (gtk_grid_new ());
- gtk_orientable_set_orientation (GTK_ORIENTABLE (hgrid), GTK_ORIENTATION_HORIZONTAL);
- gtk_grid_set_column_spacing (GTK_GRID (hgrid), 10);
+ hgrid = GTK_CONTAINER (gtk_grid_new ());
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (hgrid), GTK_ORIENTATION_HORIZONTAL);
+ gtk_grid_set_column_spacing (GTK_GRID (hgrid), 10);
- /* Default templates */
+ /* Default templates */
- scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN);
- gtk_widget_set_size_request (scrolled_window, 250, 200);
+ scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN);
+ gtk_widget_set_size_request (scrolled_window, 250, 200);
- gtk_container_add (GTK_CONTAINER (scrolled_window),
- GTK_WIDGET (default_view));
+ gtk_container_add (GTK_CONTAINER (scrolled_window),
+ GTK_WIDGET (default_view));
- component = latexila_utils_get_dialog_component (_("Default Templates"), scrolled_window);
- gtk_container_add (hgrid, component);
+ component = latexila_utils_get_dialog_component (_ ("Default Templates"), scrolled_window);
+ gtk_container_add (hgrid, component);
- /* Personal templates */
+ /* Personal templates */
- scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN);
- gtk_widget_set_size_request (scrolled_window, 250, 200);
+ scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN);
+ gtk_widget_set_size_request (scrolled_window, 250, 200);
- gtk_container_add (GTK_CONTAINER (scrolled_window),
- GTK_WIDGET (personal_view));
+ gtk_container_add (GTK_CONTAINER (scrolled_window),
+ GTK_WIDGET (personal_view));
- component = latexila_utils_get_dialog_component (_("Personal Templates"), scrolled_window);
- gtk_container_add (hgrid, component);
+ component = latexila_utils_get_dialog_component (_ ("Personal Templates"), scrolled_window);
+ gtk_container_add (hgrid, component);
- content_area = gtk_dialog_get_content_area (dialog);
- gtk_box_pack_start (GTK_BOX (content_area), GTK_WIDGET (hgrid), TRUE, TRUE, 0);
- gtk_widget_show_all (content_area);
+ content_area = gtk_dialog_get_content_area (dialog);
+ gtk_box_pack_start (GTK_BOX (content_area), GTK_WIDGET (hgrid), TRUE, TRUE, 0);
+ gtk_widget_show_all (content_area);
}
static void
selection_changed_cb (GtkTreeSelection *selection,
- GtkTreeSelection *other_selection)
+ GtkTreeSelection *other_selection)
{
- /* Only one item of the two lists can be selected at once. */
-
- /* We unselect all the items of the other list only if the current list have
- * an item selected, because when we unselect all the items the "changed"
- * signal is emitted for the other list, so for the other list this function
- * is also called but no item is selected so nothing is done and the item
- * selected by the user is kept selected.
- */
-
- if (gtk_tree_selection_count_selected_rows (selection) > 0)
- gtk_tree_selection_unselect_all (other_selection);
+ /* Only one item of the two lists can be selected at once. */
+
+ /* We unselect all the items of the other list only if the current list have
+ * an item selected, because when we unselect all the items the "changed"
+ * signal is emitted for the other list, so for the other list this function
+ * is also called but no item is selected so nothing is done and the item
+ * selected by the user is kept selected.
+ */
+
+ if (gtk_tree_selection_count_selected_rows (selection) > 0)
+ {
+ gtk_tree_selection_unselect_all (other_selection);
+ }
}
static void
row_activated_cb (GtkTreeView *tree_view,
- GtkTreePath *path,
- GtkTreeViewColumn *column,
- GtkDialog *dialog)
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ GtkDialog *dialog)
{
- gtk_dialog_response (dialog, GTK_RESPONSE_OK);
+ gtk_dialog_response (dialog, GTK_RESPONSE_OK);
}
/**
@@ -105,103 +107,101 @@ row_activated_cb (GtkTreeView *tree_view,
gchar *
latexila_templates_dialogs_open (GtkWindow *parent_window)
{
- GtkDialog *dialog;
- LatexilaTemplatesDefault *default_store;
- LatexilaTemplatesPersonal *personal_store;
- GtkTreeView *default_view;
- GtkTreeView *personal_view;
- GtkTreeSelection *default_selection;
- GtkTreeSelection *personal_selection;
- gint response;
- gchar *contents = NULL;
-
- g_return_val_if_fail (GTK_IS_WINDOW (parent_window), NULL);
-
- dialog = g_object_new (GTK_TYPE_DIALOG,
- "use-header-bar", TRUE,
- "title", _("New File..."),
- "destroy-with-parent", TRUE,
- "transient-for", parent_window,
- NULL);
-
- gtk_dialog_add_buttons (dialog,
- _("_Cancel"), GTK_RESPONSE_CANCEL,
- _("_New"), GTK_RESPONSE_OK,
- NULL);
-
- gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK);
-
- default_store = latexila_templates_default_get_instance ();
- personal_store = latexila_templates_personal_get_instance ();
-
- default_view = latexila_templates_get_view (GTK_LIST_STORE (default_store));
- personal_view = latexila_templates_get_view (GTK_LIST_STORE (personal_store));
-
- init_open_dialog (dialog, default_view, personal_view);
-
- /* Selection: at most one selected template in both GtkTreeViews. */
- default_selection = gtk_tree_view_get_selection (default_view);
- personal_selection = gtk_tree_view_get_selection (personal_view);
-
- g_signal_connect_object (default_selection,
- "changed",
- G_CALLBACK (selection_changed_cb),
- personal_selection,
- 0);
-
- g_signal_connect_object (personal_selection,
- "changed",
- G_CALLBACK (selection_changed_cb),
- default_selection,
- 0);
-
- /* Double-click */
- g_signal_connect (default_view,
- "row-activated",
- G_CALLBACK (row_activated_cb),
- dialog);
-
- g_signal_connect (personal_view,
- "row-activated",
- G_CALLBACK (row_activated_cb),
- dialog);
-
- response = gtk_dialog_run (dialog);
-
- if (response == GTK_RESPONSE_OK)
- {
- GList *selected_rows = NULL;
- GtkTreePath *path;
-
- if (gtk_tree_selection_count_selected_rows (default_selection) > 0)
- {
- selected_rows = gtk_tree_selection_get_selected_rows (default_selection, NULL);
- g_assert (g_list_length (selected_rows) == 1);
-
- path = selected_rows->data;
- contents = latexila_templates_default_get_contents (default_store, path);
- }
-
- else if (gtk_tree_selection_count_selected_rows (personal_selection) > 0)
- {
- selected_rows = gtk_tree_selection_get_selected_rows (personal_selection, NULL);
- g_assert (g_list_length (selected_rows) == 1);
-
- path = selected_rows->data;
- contents = latexila_templates_personal_get_contents (personal_store, path);
- }
-
- /* No templates selected. */
- else
- {
- contents = g_strdup ("");
- }
-
- g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
- }
-
- gtk_widget_destroy (GTK_WIDGET (dialog));
- return contents;
+ GtkDialog *dialog;
+ LatexilaTemplatesDefault *default_store;
+ LatexilaTemplatesPersonal *personal_store;
+ GtkTreeView *default_view;
+ GtkTreeView *personal_view;
+ GtkTreeSelection *default_selection;
+ GtkTreeSelection *personal_selection;
+ gint response;
+ gchar *contents = NULL;
+
+ g_return_val_if_fail (GTK_IS_WINDOW (parent_window), NULL);
+
+ dialog = g_object_new (GTK_TYPE_DIALOG,
+ "use-header-bar", TRUE,
+ "title", _ ("New File..."),
+ "destroy-with-parent", TRUE,
+ "transient-for", parent_window,
+ NULL);
+
+ gtk_dialog_add_buttons (dialog,
+ _ ("_Cancel"), GTK_RESPONSE_CANCEL,
+ _ ("_New"), GTK_RESPONSE_OK,
+ NULL);
+
+ gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK);
+
+ default_store = latexila_templates_default_get_instance ();
+ personal_store = latexila_templates_personal_get_instance ();
+
+ default_view = latexila_templates_get_view (GTK_LIST_STORE (default_store));
+ personal_view = latexila_templates_get_view (GTK_LIST_STORE (personal_store));
+
+ init_open_dialog (dialog, default_view, personal_view);
+
+ /* Selection: at most one selected template in both GtkTreeViews. */
+ default_selection = gtk_tree_view_get_selection (default_view);
+ personal_selection = gtk_tree_view_get_selection (personal_view);
+
+ g_signal_connect_object (default_selection,
+ "changed",
+ G_CALLBACK (selection_changed_cb),
+ personal_selection,
+ 0);
+
+ g_signal_connect_object (personal_selection,
+ "changed",
+ G_CALLBACK (selection_changed_cb),
+ default_selection,
+ 0);
+
+ /* Double-click */
+ g_signal_connect (default_view,
+ "row-activated",
+ G_CALLBACK (row_activated_cb),
+ dialog);
+
+ g_signal_connect (personal_view,
+ "row-activated",
+ G_CALLBACK (row_activated_cb),
+ dialog);
+
+ response = gtk_dialog_run (dialog);
+
+ if (response == GTK_RESPONSE_OK)
+ {
+ GList *selected_rows = NULL;
+ GtkTreePath *path;
+
+ if (gtk_tree_selection_count_selected_rows (default_selection) > 0)
+ {
+ selected_rows = gtk_tree_selection_get_selected_rows (default_selection, NULL);
+ g_assert (g_list_length (selected_rows) == 1);
+
+ path = selected_rows->data;
+ contents = latexila_templates_default_get_contents (default_store, path);
+ }
+ else if (gtk_tree_selection_count_selected_rows (personal_selection) > 0)
+ {
+ selected_rows = gtk_tree_selection_get_selected_rows (personal_selection, NULL);
+ g_assert (g_list_length (selected_rows) == 1);
+
+ path = selected_rows->data;
+ contents = latexila_templates_personal_get_contents (personal_store, path);
+ }
+ /* No templates selected. */
+ else
+ {
+ contents = g_strdup ("");
+ }
+
+ g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ return contents;
}
/**
@@ -214,135 +214,139 @@ latexila_templates_dialogs_open (GtkWindow *parent_window)
*/
void
latexila_templates_dialogs_create_template (GtkWindow *parent_window,
- const gchar *template_contents)
+ const gchar *template_contents)
{
- GtkDialog *dialog;
- GtkBox *content_area;
- GtkEntry *entry;
- GtkWidget *component;
- LatexilaTemplatesDefault *default_store;
- GtkTreeView *default_view;
- GtkWidget *scrolled_window;
-
- g_return_if_fail (GTK_IS_WINDOW (parent_window));
- g_return_if_fail (template_contents != NULL);
-
- dialog = g_object_new (GTK_TYPE_DIALOG,
- "use-header-bar", TRUE,
- "title", _("New Template..."),
- "destroy-with-parent", TRUE,
- "transient-for", parent_window,
- NULL);
-
- gtk_dialog_add_buttons (dialog,
- _("_Cancel"), GTK_RESPONSE_CANCEL,
- _("Crea_te"), GTK_RESPONSE_OK,
- NULL);
-
- gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK);
-
- content_area = GTK_BOX (gtk_dialog_get_content_area (dialog));
-
- /* Name */
- entry = GTK_ENTRY (gtk_entry_new ());
- gtk_widget_set_hexpand (GTK_WIDGET (entry), TRUE);
- component = latexila_utils_get_dialog_component (_("Name of the new template"),
- GTK_WIDGET (entry));
- gtk_box_pack_start (content_area, component, FALSE, TRUE, 0);
-
- /* Icon.
- * Take the default store because it contains all the icons.
- */
- default_store = latexila_templates_default_get_instance ();
- default_view = latexila_templates_get_view (GTK_LIST_STORE (default_store));
-
- scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_widget_set_size_request (scrolled_window, 400, 200);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
- GTK_SHADOW_IN);
-
- gtk_container_add (GTK_CONTAINER (scrolled_window),
- GTK_WIDGET (default_view));
-
- component = latexila_utils_get_dialog_component (_("Choose an icon"), scrolled_window);
- gtk_box_pack_start (content_area, component, TRUE, TRUE, 0);
-
- gtk_widget_show_all (GTK_WIDGET (content_area));
-
- while (gtk_dialog_run (dialog) == GTK_RESPONSE_OK)
- {
- GtkTreeSelection *selection;
- GList *selected_rows;
- GtkTreePath *path;
- GtkTreeIter iter;
- gchar *config_icon_name = NULL;
- const gchar *name = NULL;
- LatexilaTemplatesPersonal *personal_store;
- GError *error = NULL;
-
- /* If no name specified. */
- if (gtk_entry_get_text_length (entry) == 0)
- continue;
-
- selection = gtk_tree_view_get_selection (default_view);
-
- /* If no icons selected. */
- if (gtk_tree_selection_count_selected_rows (selection) == 0)
- continue;
-
- /* Get config icon name. */
- selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
- g_assert (g_list_length (selected_rows) == 1);
-
- path = selected_rows->data;
-
- if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (default_store), &iter, path))
- {
- g_warning ("Create template dialog: invalid path");
- break;
- }
-
- gtk_tree_model_get (GTK_TREE_MODEL (default_store), &iter,
- LATEXILA_TEMPLATES_COLUMN_CONFIG_ICON_NAME, &config_icon_name,
- -1);
-
- name = gtk_entry_get_text (entry);
-
- personal_store = latexila_templates_personal_get_instance ();
-
- latexila_templates_personal_create (personal_store,
- name,
- config_icon_name,
- template_contents,
- &error);
-
- g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
- g_free (config_icon_name);
-
- if (error != NULL)
- {
- GtkWidget *error_dialog;
-
- error_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
- GTK_DIALOG_MODAL |
- GTK_DIALOG_DESTROY_WITH_PARENT |
- GTK_DIALOG_USE_HEADER_BAR,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- "%s", _("Impossible to create the personal template."));
-
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog),
- "%s", error->message);
-
- gtk_dialog_run (GTK_DIALOG (error_dialog));
- gtk_widget_destroy (error_dialog);
-
- g_error_free (error);
- continue;
- }
-
- break;
- }
-
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ GtkDialog *dialog;
+ GtkBox *content_area;
+ GtkEntry *entry;
+ GtkWidget *component;
+ LatexilaTemplatesDefault *default_store;
+ GtkTreeView *default_view;
+ GtkWidget *scrolled_window;
+
+ g_return_if_fail (GTK_IS_WINDOW (parent_window));
+ g_return_if_fail (template_contents != NULL);
+
+ dialog = g_object_new (GTK_TYPE_DIALOG,
+ "use-header-bar", TRUE,
+ "title", _ ("New Template..."),
+ "destroy-with-parent", TRUE,
+ "transient-for", parent_window,
+ NULL);
+
+ gtk_dialog_add_buttons (dialog,
+ _ ("_Cancel"), GTK_RESPONSE_CANCEL,
+ _ ("Crea_te"), GTK_RESPONSE_OK,
+ NULL);
+
+ gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK);
+
+ content_area = GTK_BOX (gtk_dialog_get_content_area (dialog));
+
+ /* Name */
+ entry = GTK_ENTRY (gtk_entry_new ());
+ gtk_widget_set_hexpand (GTK_WIDGET (entry), TRUE);
+ component = latexila_utils_get_dialog_component (_ ("Name of the new template"),
+ GTK_WIDGET (entry));
+ gtk_box_pack_start (content_area, component, FALSE, TRUE, 0);
+
+ /* Icon.
+ * Take the default store because it contains all the icons.
+ */
+ default_store = latexila_templates_default_get_instance ();
+ default_view = latexila_templates_get_view (GTK_LIST_STORE (default_store));
+
+ scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_set_size_request (scrolled_window, 400, 200);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
+ GTK_SHADOW_IN);
+
+ gtk_container_add (GTK_CONTAINER (scrolled_window),
+ GTK_WIDGET (default_view));
+
+ component = latexila_utils_get_dialog_component (_ ("Choose an icon"), scrolled_window);
+ gtk_box_pack_start (content_area, component, TRUE, TRUE, 0);
+
+ gtk_widget_show_all (GTK_WIDGET (content_area));
+
+ while (gtk_dialog_run (dialog) == GTK_RESPONSE_OK)
+ {
+ GtkTreeSelection *selection;
+ GList *selected_rows;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ gchar *config_icon_name = NULL;
+ const gchar *name = NULL;
+ LatexilaTemplatesPersonal *personal_store;
+ GError *error = NULL;
+
+ /* If no name specified. */
+ if (gtk_entry_get_text_length (entry) == 0)
+ {
+ continue;
+ }
+
+ selection = gtk_tree_view_get_selection (default_view);
+
+ /* If no icons selected. */
+ if (gtk_tree_selection_count_selected_rows (selection) == 0)
+ {
+ continue;
+ }
+
+ /* Get config icon name. */
+ selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
+ g_assert (g_list_length (selected_rows) == 1);
+
+ path = selected_rows->data;
+
+ if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (default_store), &iter, path))
+ {
+ g_warning ("Create template dialog: invalid path");
+ break;
+ }
+
+ gtk_tree_model_get (GTK_TREE_MODEL (default_store), &iter,
+ LATEXILA_TEMPLATES_COLUMN_CONFIG_ICON_NAME, &config_icon_name,
+ -1);
+
+ name = gtk_entry_get_text (entry);
+
+ personal_store = latexila_templates_personal_get_instance ();
+
+ latexila_templates_personal_create (personal_store,
+ name,
+ config_icon_name,
+ template_contents,
+ &error);
+
+ g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
+ g_free (config_icon_name);
+
+ if (error != NULL)
+ {
+ GtkWidget *error_dialog;
+
+ error_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
+ GTK_DIALOG_MODAL |
+ GTK_DIALOG_DESTROY_WITH_PARENT |
+ GTK_DIALOG_USE_HEADER_BAR,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ "%s", _ ("Impossible to create the personal
template."));
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog),
+ "%s", error->message);
+
+ gtk_dialog_run (GTK_DIALOG (error_dialog));
+ gtk_widget_destroy (error_dialog);
+
+ g_error_free (error);
+ continue;
+ }
+
+ break;
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
diff --git a/src/liblatexila/latexila-templates-manage-dialog.c
b/src/liblatexila/latexila-templates-manage-dialog.c
index 3235d02..e66a5a6 100644
--- a/src/liblatexila/latexila-templates-manage-dialog.c
+++ b/src/liblatexila/latexila-templates-manage-dialog.c
@@ -35,19 +35,19 @@
struct _LatexilaTemplatesManageDialog
{
- GtkDialog parent;
+ GtkDialog parent;
- GtkTreeView *templates_view;
+ GtkTreeView *templates_view;
- GtkToolButton *delete_button;
- GtkToolButton *move_up_button;
- GtkToolButton *move_down_button;
+ GtkToolButton *delete_button;
+ GtkToolButton *move_up_button;
+ GtkToolButton *move_down_button;
};
typedef enum
{
- MOVE_UP,
- MOVE_DOWN
+ MOVE_UP,
+ MOVE_DOWN
} MoveType;
G_DEFINE_TYPE (LatexilaTemplatesManageDialog, latexila_templates_manage_dialog, GTK_TYPE_DIALOG)
@@ -55,252 +55,256 @@ G_DEFINE_TYPE (LatexilaTemplatesManageDialog, latexila_templates_manage_dialog,
static void
update_move_buttons_sensitivity (LatexilaTemplatesManageDialog *manage_dialog)
{
- GtkTreeSelection *selection;
- gint n_selected_rows;
- GList *selected_rows;
- GtkTreeModel *model;
- GtkTreePath *path;
- gint *indices;
- gint depth;
- gint items_count;
- gboolean first_item_selected;
- gboolean last_item_selected;
-
- selection = gtk_tree_view_get_selection (manage_dialog->templates_view);
- n_selected_rows = gtk_tree_selection_count_selected_rows (selection);
-
- if (n_selected_rows != 1)
- {
- gtk_widget_set_sensitive (GTK_WIDGET (manage_dialog->move_up_button), FALSE);
- gtk_widget_set_sensitive (GTK_WIDGET (manage_dialog->move_down_button), FALSE);
- return;
- }
-
- selected_rows = gtk_tree_selection_get_selected_rows (selection, &model);
- g_assert (g_list_length (selected_rows) == 1);
-
- path = selected_rows->data;
- indices = gtk_tree_path_get_indices_with_depth (path, &depth);
- g_assert (depth == 1);
-
- items_count = gtk_tree_model_iter_n_children (model, NULL);
-
- first_item_selected = indices[0] == 0;
- last_item_selected = indices[0] == (items_count - 1);
-
- gtk_widget_set_sensitive (GTK_WIDGET (manage_dialog->move_up_button), !first_item_selected);
- gtk_widget_set_sensitive (GTK_WIDGET (manage_dialog->move_down_button), !last_item_selected);
-
- g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
+ GtkTreeSelection *selection;
+ gint n_selected_rows;
+ GList *selected_rows;
+ GtkTreeModel *model;
+ GtkTreePath *path;
+ gint *indices;
+ gint depth;
+ gint items_count;
+ gboolean first_item_selected;
+ gboolean last_item_selected;
+
+ selection = gtk_tree_view_get_selection (manage_dialog->templates_view);
+ n_selected_rows = gtk_tree_selection_count_selected_rows (selection);
+
+ if (n_selected_rows != 1)
+ {
+ gtk_widget_set_sensitive (GTK_WIDGET (manage_dialog->move_up_button), FALSE);
+ gtk_widget_set_sensitive (GTK_WIDGET (manage_dialog->move_down_button), FALSE);
+ return;
+ }
+
+ selected_rows = gtk_tree_selection_get_selected_rows (selection, &model);
+ g_assert (g_list_length (selected_rows) == 1);
+
+ path = selected_rows->data;
+ indices = gtk_tree_path_get_indices_with_depth (path, &depth);
+ g_assert (depth == 1);
+
+ items_count = gtk_tree_model_iter_n_children (model, NULL);
+
+ first_item_selected = indices[0] == 0;
+ last_item_selected = indices[0] == (items_count - 1);
+
+ gtk_widget_set_sensitive (GTK_WIDGET (manage_dialog->move_up_button), !first_item_selected);
+ gtk_widget_set_sensitive (GTK_WIDGET (manage_dialog->move_down_button), !last_item_selected);
+
+ g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
}
static void
update_buttons_sensitivity (LatexilaTemplatesManageDialog *manage_dialog)
{
- GtkTreeSelection *selection;
- gint n_selected_rows;
+ GtkTreeSelection *selection;
+ gint n_selected_rows;
- selection = gtk_tree_view_get_selection (manage_dialog->templates_view);
- n_selected_rows = gtk_tree_selection_count_selected_rows (selection);
+ selection = gtk_tree_view_get_selection (manage_dialog->templates_view);
+ n_selected_rows = gtk_tree_selection_count_selected_rows (selection);
- gtk_widget_set_sensitive (GTK_WIDGET (manage_dialog->delete_button),
- n_selected_rows > 0);
+ gtk_widget_set_sensitive (GTK_WIDGET (manage_dialog->delete_button),
+ n_selected_rows > 0);
- update_move_buttons_sensitivity (manage_dialog);
+ update_move_buttons_sensitivity (manage_dialog);
}
static void
delete_button_clicked_cb (GtkToolButton *delete_button,
- LatexilaTemplatesManageDialog *manage_dialog)
+ LatexilaTemplatesManageDialog *manage_dialog)
{
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- LatexilaTemplatesPersonal *templates_store;
- GtkTreeIter iter;
- gchar *name;
- GtkDialog *confirm_dialog;
- gint response;
-
- selection = gtk_tree_view_get_selection (manage_dialog->templates_view);
-
- if (!gtk_tree_selection_get_selected (selection, &model, &iter))
- g_return_if_reached ();
-
- templates_store = latexila_templates_personal_get_instance ();
- g_return_if_fail (GTK_TREE_MODEL (templates_store) == model);
-
- gtk_tree_model_get (model, &iter,
- LATEXILA_TEMPLATES_COLUMN_NAME, &name,
- -1);
-
- confirm_dialog = GTK_DIALOG (gtk_message_dialog_new (GTK_WINDOW (manage_dialog),
- GTK_DIALOG_MODAL |
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_NONE,
- _("Do you really want to delete the template “%s”?"),
- name));
-
- gtk_dialog_add_buttons (confirm_dialog,
- _("_Cancel"), GTK_RESPONSE_CANCEL,
- _("_Delete"), GTK_RESPONSE_YES,
- NULL);
-
- response = gtk_dialog_run (confirm_dialog);
- gtk_widget_destroy (GTK_WIDGET (confirm_dialog));
-
- if (response == GTK_RESPONSE_YES)
- {
- GError *error = NULL;
-
- latexila_templates_personal_delete (templates_store, &iter, &error);
-
- if (error != NULL)
- {
- GtkWidget *error_dialog;
-
- error_dialog = gtk_message_dialog_new (GTK_WINDOW (manage_dialog),
- GTK_DIALOG_MODAL |
- GTK_DIALOG_DESTROY_WITH_PARENT |
- GTK_DIALOG_USE_HEADER_BAR,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("Error when deleting the template “%s”."),
- name);
-
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog),
- "%s", error->message);
-
- gtk_dialog_run (GTK_DIALOG (error_dialog));
- gtk_widget_destroy (error_dialog);
-
- g_error_free (error);
- }
- }
-
- g_free (name);
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ LatexilaTemplatesPersonal *templates_store;
+ GtkTreeIter iter;
+ gchar *name;
+ GtkDialog *confirm_dialog;
+ gint response;
+
+ selection = gtk_tree_view_get_selection (manage_dialog->templates_view);
+
+ if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+ {
+ g_return_if_reached ();
+ }
+
+ templates_store = latexila_templates_personal_get_instance ();
+ g_return_if_fail (GTK_TREE_MODEL (templates_store) == model);
+
+ gtk_tree_model_get (model, &iter,
+ LATEXILA_TEMPLATES_COLUMN_NAME, &name,
+ -1);
+
+ confirm_dialog = GTK_DIALOG (gtk_message_dialog_new (GTK_WINDOW (manage_dialog),
+ GTK_DIALOG_MODAL |
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ _ ("Do you really want to delete the template
“%s”?"),
+ name));
+
+ gtk_dialog_add_buttons (confirm_dialog,
+ _ ("_Cancel"), GTK_RESPONSE_CANCEL,
+ _ ("_Delete"), GTK_RESPONSE_YES,
+ NULL);
+
+ response = gtk_dialog_run (confirm_dialog);
+ gtk_widget_destroy (GTK_WIDGET (confirm_dialog));
+
+ if (response == GTK_RESPONSE_YES)
+ {
+ GError *error = NULL;
+
+ latexila_templates_personal_delete (templates_store, &iter, &error);
+
+ if (error != NULL)
+ {
+ GtkWidget *error_dialog;
+
+ error_dialog = gtk_message_dialog_new (GTK_WINDOW (manage_dialog),
+ GTK_DIALOG_MODAL |
+ GTK_DIALOG_DESTROY_WITH_PARENT |
+ GTK_DIALOG_USE_HEADER_BAR,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _ ("Error when deleting the template “%s”."),
+ name);
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog),
+ "%s", error->message);
+
+ gtk_dialog_run (GTK_DIALOG (error_dialog));
+ gtk_widget_destroy (error_dialog);
+
+ g_error_free (error);
+ }
+ }
+
+ g_free (name);
}
static void
move_template (LatexilaTemplatesManageDialog *manage_dialog,
- MoveType move_type)
+ MoveType move_type)
{
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- LatexilaTemplatesPersonal *templates_store;
- GtkTreeIter iter;
- GError *error = NULL;
-
- selection = gtk_tree_view_get_selection (manage_dialog->templates_view);
-
- if (!gtk_tree_selection_get_selected (selection, &model, &iter))
- g_return_if_reached ();
-
- templates_store = latexila_templates_personal_get_instance ();
- g_return_if_fail (GTK_TREE_MODEL (templates_store) == model);
-
- switch (move_type)
- {
- case MOVE_UP:
- latexila_templates_personal_move_up (templates_store, &iter, &error);
- break;
-
- case MOVE_DOWN:
- latexila_templates_personal_move_down (templates_store, &iter, &error);
- break;
-
- default:
- g_assert_not_reached ();
- }
-
- if (error != NULL)
- {
- GtkWidget *error_dialog;
-
- error_dialog = gtk_message_dialog_new (GTK_WINDOW (manage_dialog),
- GTK_DIALOG_MODAL |
- GTK_DIALOG_DESTROY_WITH_PARENT |
- GTK_DIALOG_USE_HEADER_BAR,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- "%s", _("Error when moving the template."));
-
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog),
- "%s", error->message);
-
- gtk_dialog_run (GTK_DIALOG (error_dialog));
- gtk_widget_destroy (error_dialog);
-
- g_error_free (error);
- }
-
- update_buttons_sensitivity (manage_dialog);
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ LatexilaTemplatesPersonal *templates_store;
+ GtkTreeIter iter;
+ GError *error = NULL;
+
+ selection = gtk_tree_view_get_selection (manage_dialog->templates_view);
+
+ if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+ {
+ g_return_if_reached ();
+ }
+
+ templates_store = latexila_templates_personal_get_instance ();
+ g_return_if_fail (GTK_TREE_MODEL (templates_store) == model);
+
+ switch (move_type)
+ {
+ case MOVE_UP:
+ latexila_templates_personal_move_up (templates_store, &iter, &error);
+ break;
+
+ case MOVE_DOWN:
+ latexila_templates_personal_move_down (templates_store, &iter, &error);
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ if (error != NULL)
+ {
+ GtkWidget *error_dialog;
+
+ error_dialog = gtk_message_dialog_new (GTK_WINDOW (manage_dialog),
+ GTK_DIALOG_MODAL |
+ GTK_DIALOG_DESTROY_WITH_PARENT |
+ GTK_DIALOG_USE_HEADER_BAR,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ "%s", _ ("Error when moving the template."));
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog),
+ "%s", error->message);
+
+ gtk_dialog_run (GTK_DIALOG (error_dialog));
+ gtk_widget_destroy (error_dialog);
+
+ g_error_free (error);
+ }
+
+ update_buttons_sensitivity (manage_dialog);
}
static void
move_up_button_clicked_cb (GtkToolButton *move_up_button,
- LatexilaTemplatesManageDialog *manage_dialog)
+ LatexilaTemplatesManageDialog *manage_dialog)
{
- move_template (manage_dialog, MOVE_UP);
+ move_template (manage_dialog, MOVE_UP);
}
static void
move_down_button_clicked_cb (GtkToolButton *move_down_button,
- LatexilaTemplatesManageDialog *manage_dialog)
+ LatexilaTemplatesManageDialog *manage_dialog)
{
- move_template (manage_dialog, MOVE_DOWN);
+ move_template (manage_dialog, MOVE_DOWN);
}
static GtkToolbar *
init_toolbar (LatexilaTemplatesManageDialog *manage_dialog)
{
- GtkToolbar *toolbar;
- GtkStyleContext *context;
+ GtkToolbar *toolbar;
+ GtkStyleContext *context;
- toolbar = GTK_TOOLBAR (gtk_toolbar_new ());
- gtk_toolbar_set_icon_size (toolbar, GTK_ICON_SIZE_SMALL_TOOLBAR);
- gtk_toolbar_set_style (toolbar, GTK_TOOLBAR_ICONS);
+ toolbar = GTK_TOOLBAR (gtk_toolbar_new ());
+ gtk_toolbar_set_icon_size (toolbar, GTK_ICON_SIZE_SMALL_TOOLBAR);
+ gtk_toolbar_set_style (toolbar, GTK_TOOLBAR_ICONS);
- context = gtk_widget_get_style_context (GTK_WIDGET (toolbar));
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_INLINE_TOOLBAR);
+ context = gtk_widget_get_style_context (GTK_WIDGET (toolbar));
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_INLINE_TOOLBAR);
- /* Delete */
- manage_dialog->delete_button = GTK_TOOL_BUTTON (gtk_tool_button_new (NULL, NULL));
- gtk_tool_button_set_icon_name (manage_dialog->delete_button, "list-remove-symbolic");
- gtk_widget_set_tooltip_text (GTK_WIDGET (manage_dialog->delete_button), _("Delete"));
+ /* Delete */
+ manage_dialog->delete_button = GTK_TOOL_BUTTON (gtk_tool_button_new (NULL, NULL));
+ gtk_tool_button_set_icon_name (manage_dialog->delete_button, "list-remove-symbolic");
+ gtk_widget_set_tooltip_text (GTK_WIDGET (manage_dialog->delete_button), _ ("Delete"));
- gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (manage_dialog->delete_button), -1);
+ gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (manage_dialog->delete_button), -1);
- g_signal_connect (manage_dialog->delete_button,
- "clicked",
- G_CALLBACK (delete_button_clicked_cb),
- manage_dialog);
+ g_signal_connect (manage_dialog->delete_button,
+ "clicked",
+ G_CALLBACK (delete_button_clicked_cb),
+ manage_dialog);
- /* Move up */
- manage_dialog->move_up_button = GTK_TOOL_BUTTON (gtk_tool_button_new (NULL, NULL));
- gtk_tool_button_set_icon_name (manage_dialog->move_up_button, "go-up-symbolic");
- gtk_widget_set_tooltip_text (GTK_WIDGET (manage_dialog->move_up_button), _("Move up"));
+ /* Move up */
+ manage_dialog->move_up_button = GTK_TOOL_BUTTON (gtk_tool_button_new (NULL, NULL));
+ gtk_tool_button_set_icon_name (manage_dialog->move_up_button, "go-up-symbolic");
+ gtk_widget_set_tooltip_text (GTK_WIDGET (manage_dialog->move_up_button), _ ("Move up"));
- gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (manage_dialog->move_up_button), -1);
+ gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (manage_dialog->move_up_button), -1);
- g_signal_connect (manage_dialog->move_up_button,
- "clicked",
- G_CALLBACK (move_up_button_clicked_cb),
- manage_dialog);
+ g_signal_connect (manage_dialog->move_up_button,
+ "clicked",
+ G_CALLBACK (move_up_button_clicked_cb),
+ manage_dialog);
- /* Move down */
- manage_dialog->move_down_button = GTK_TOOL_BUTTON (gtk_tool_button_new (NULL, NULL));
- gtk_tool_button_set_icon_name (manage_dialog->move_down_button, "go-down-symbolic");
- gtk_widget_set_tooltip_text (GTK_WIDGET (manage_dialog->move_down_button), _("Move down"));
+ /* Move down */
+ manage_dialog->move_down_button = GTK_TOOL_BUTTON (gtk_tool_button_new (NULL, NULL));
+ gtk_tool_button_set_icon_name (manage_dialog->move_down_button, "go-down-symbolic");
+ gtk_widget_set_tooltip_text (GTK_WIDGET (manage_dialog->move_down_button), _ ("Move down"));
- gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (manage_dialog->move_down_button), -1);
+ gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (manage_dialog->move_down_button), -1);
- g_signal_connect (manage_dialog->move_down_button,
- "clicked",
- G_CALLBACK (move_down_button_clicked_cb),
- manage_dialog);
+ g_signal_connect (manage_dialog->move_down_button,
+ "clicked",
+ G_CALLBACK (move_down_button_clicked_cb),
+ manage_dialog);
- return toolbar;
+ return toolbar;
}
static void
@@ -311,40 +315,40 @@ latexila_templates_manage_dialog_class_init (LatexilaTemplatesManageDialogClass
static void
latexila_templates_manage_dialog_init (LatexilaTemplatesManageDialog *manage_dialog)
{
- LatexilaTemplatesPersonal *templates_store;
- GtkWidget *scrolled_window;
- GtkToolbar *toolbar;
- GtkWidget *dialog_content;
- GtkBox *content_area;
- GtkTreeSelection *selection;
+ LatexilaTemplatesPersonal *templates_store;
+ GtkWidget *scrolled_window;
+ GtkToolbar *toolbar;
+ GtkWidget *dialog_content;
+ GtkBox *content_area;
+ GtkTreeSelection *selection;
- templates_store = latexila_templates_personal_get_instance ();
- manage_dialog->templates_view = latexila_templates_get_view (GTK_LIST_STORE (templates_store));
+ templates_store = latexila_templates_personal_get_instance ();
+ manage_dialog->templates_view = latexila_templates_get_view (GTK_LIST_STORE (templates_store));
- scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_widget_set_size_request (scrolled_window, 350, 300);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
- GTK_SHADOW_IN);
+ scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_set_size_request (scrolled_window, 350, 300);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
+ GTK_SHADOW_IN);
- gtk_container_add (GTK_CONTAINER (scrolled_window),
- GTK_WIDGET (manage_dialog->templates_view));
+ gtk_container_add (GTK_CONTAINER (scrolled_window),
+ GTK_WIDGET (manage_dialog->templates_view));
- toolbar = init_toolbar (manage_dialog);
+ toolbar = init_toolbar (manage_dialog);
- dialog_content = latexila_utils_join_widgets (scrolled_window, GTK_WIDGET (toolbar));
+ dialog_content = latexila_utils_join_widgets (scrolled_window, GTK_WIDGET (toolbar));
- content_area = GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (manage_dialog)));
- gtk_box_pack_start (content_area, dialog_content, TRUE, TRUE, 0);
- gtk_widget_show_all (GTK_WIDGET (content_area));
+ content_area = GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (manage_dialog)));
+ gtk_box_pack_start (content_area, dialog_content, TRUE, TRUE, 0);
+ gtk_widget_show_all (GTK_WIDGET (content_area));
- selection = gtk_tree_view_get_selection (manage_dialog->templates_view);
+ selection = gtk_tree_view_get_selection (manage_dialog->templates_view);
- g_signal_connect_swapped (selection,
- "changed",
- G_CALLBACK (update_buttons_sensitivity),
- manage_dialog);
+ g_signal_connect_swapped (selection,
+ "changed",
+ G_CALLBACK (update_buttons_sensitivity),
+ manage_dialog);
- update_buttons_sensitivity (manage_dialog);
+ update_buttons_sensitivity (manage_dialog);
}
/**
@@ -356,14 +360,14 @@ latexila_templates_manage_dialog_init (LatexilaTemplatesManageDialog *manage_dia
GtkDialog *
latexila_templates_manage_dialog_new (GtkWindow *parent_window)
{
- g_return_val_if_fail (GTK_IS_WINDOW (parent_window), NULL);
-
- return g_object_new (LATEXILA_TYPE_TEMPLATES_MANAGE_DIALOG,
- "title", _("Manage Personal Templates"),
- "transient-for", parent_window,
- "modal", TRUE,
- "destroy-with-parent", TRUE,
- "use-header-bar", TRUE,
- "border-width", 6,
- NULL);
+ g_return_val_if_fail (GTK_IS_WINDOW (parent_window), NULL);
+
+ return g_object_new (LATEXILA_TYPE_TEMPLATES_MANAGE_DIALOG,
+ "title", _ ("Manage Personal Templates"),
+ "transient-for", parent_window,
+ "modal", TRUE,
+ "destroy-with-parent", TRUE,
+ "use-header-bar", TRUE,
+ "border-width", 6,
+ NULL);
}
diff --git a/src/liblatexila/latexila-templates-personal.c b/src/liblatexila/latexila-templates-personal.c
index 18537fc..3d144b4 100644
--- a/src/liblatexila/latexila-templates-personal.c
+++ b/src/liblatexila/latexila-templates-personal.c
@@ -40,7 +40,7 @@
struct _LatexilaTemplatesPersonal
{
- GtkListStore parent;
+ GtkListStore parent;
};
G_DEFINE_TYPE (LatexilaTemplatesPersonal, latexila_templates_personal, GTK_TYPE_LIST_STORE)
@@ -53,149 +53,165 @@ latexila_templates_personal_class_init (LatexilaTemplatesPersonalClass *klass)
static GFile *
get_rc_file (void)
{
- gchar *path;
- GFile *rc_file;
+ gchar *path;
+ GFile *rc_file;
- path = g_build_filename (g_get_user_data_dir (), "latexila", "templatesrc", NULL);
- rc_file = g_file_new_for_path (path);
+ path = g_build_filename (g_get_user_data_dir (), "latexila", "templatesrc", NULL);
+ rc_file = g_file_new_for_path (path);
- g_free (path);
- return rc_file;
+ g_free (path);
+ return rc_file;
}
static GFile *
get_personal_template_file_by_filename (const gchar *filename)
{
- gchar *path;
- GFile *template_file;
+ gchar *path;
+ GFile *template_file;
- path = g_build_filename (g_get_user_data_dir (), "latexila", filename, NULL);
- template_file = g_file_new_for_path (path);
+ path = g_build_filename (g_get_user_data_dir (), "latexila", filename, NULL);
+ template_file = g_file_new_for_path (path);
- g_free (path);
- return template_file;
+ g_free (path);
+ return template_file;
}
static GFile *
get_personal_template_file_by_index (gint template_num)
{
- gchar *filename;
- GFile *template_file;
+ gchar *filename;
+ GFile *template_file;
- filename = g_strdup_printf ("%d.tex", template_num);
- template_file = get_personal_template_file_by_filename (filename);
+ filename = g_strdup_printf ("%d.tex", template_num);
+ template_file = get_personal_template_file_by_filename (filename);
- g_free (filename);
- return template_file;
+ g_free (filename);
+ return template_file;
}
static void
load_rc_file (LatexilaTemplatesPersonal *templates)
{
- GFile *rc_file;
- gchar *contents = NULL;
- gsize length;
- GKeyFile *key_file = NULL;
- gchar **names = NULL;
- gchar **icons = NULL;
- gchar **files = NULL;
- gsize n_names;
- gsize n_icons;
- gsize n_files;
- gboolean has_files;
- guint i;
- GError *error = NULL;
-
- rc_file = get_rc_file ();
-
- g_file_load_contents (rc_file, NULL, &contents, &length, NULL, &error);
-
- if (error != NULL)
- {
- /* If the rc file doesn't exist, it means that there is no personal
- * templates.
- */
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
- {
- g_error_free (error);
- error = NULL;
- }
-
- goto out;
- }
-
- key_file = g_key_file_new ();
- g_key_file_load_from_data (key_file, contents, length, G_KEY_FILE_NONE, &error);
-
- if (error != NULL)
- goto out;
-
- names = g_key_file_get_string_list (key_file, PACKAGE_NAME, "names", &n_names, &error);
-
- if (error != NULL)
- goto out;
-
- icons = g_key_file_get_string_list (key_file, PACKAGE_NAME, "icons", &n_icons, &error);
-
- if (error != NULL)
- goto out;
-
- g_return_if_fail (n_names == n_icons);
-
- has_files = g_key_file_has_key (key_file, PACKAGE_NAME, "files", &error);
-
- if (error != NULL)
- goto out;
-
- if (has_files)
- {
- files = g_key_file_get_string_list (key_file, PACKAGE_NAME, "files", &n_files, &error);
-
- if (error != NULL)
- goto out;
-
- g_return_if_fail (n_names == n_files);
- }
-
- for (i = 0; i < n_names; i++)
- {
- GFile *template_file;
-
- if (has_files)
- template_file = get_personal_template_file_by_filename (files[i]);
- else
- template_file = get_personal_template_file_by_index (i);
-
- latexila_templates_add_template (GTK_LIST_STORE (templates),
- names[i],
- icons[i],
- template_file);
-
- g_object_unref (template_file);
- }
+ GFile *rc_file;
+ gchar *contents = NULL;
+ gsize length;
+ GKeyFile *key_file = NULL;
+ gchar **names = NULL;
+ gchar **icons = NULL;
+ gchar **files = NULL;
+ gsize n_names;
+ gsize n_icons;
+ gsize n_files;
+ gboolean has_files;
+ guint i;
+ GError *error = NULL;
+
+ rc_file = get_rc_file ();
+
+ g_file_load_contents (rc_file, NULL, &contents, &length, NULL, &error);
+
+ if (error != NULL)
+ {
+ /* If the rc file doesn't exist, it means that there is no personal
+ * templates.
+ */
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+ {
+ g_error_free (error);
+ error = NULL;
+ }
+
+ goto out;
+ }
+
+ key_file = g_key_file_new ();
+ g_key_file_load_from_data (key_file, contents, length, G_KEY_FILE_NONE, &error);
+
+ if (error != NULL)
+ {
+ goto out;
+ }
+
+ names = g_key_file_get_string_list (key_file, PACKAGE_NAME, "names", &n_names, &error);
+
+ if (error != NULL)
+ {
+ goto out;
+ }
+
+ icons = g_key_file_get_string_list (key_file, PACKAGE_NAME, "icons", &n_icons, &error);
+
+ if (error != NULL)
+ {
+ goto out;
+ }
+
+ g_return_if_fail (n_names == n_icons);
+
+ has_files = g_key_file_has_key (key_file, PACKAGE_NAME, "files", &error);
+
+ if (error != NULL)
+ {
+ goto out;
+ }
+
+ if (has_files)
+ {
+ files = g_key_file_get_string_list (key_file, PACKAGE_NAME, "files", &n_files, &error);
+
+ if (error != NULL)
+ {
+ goto out;
+ }
+
+ g_return_if_fail (n_names == n_files);
+ }
+
+ for (i = 0; i < n_names; i++)
+ {
+ GFile *template_file;
+
+ if (has_files)
+ {
+ template_file = get_personal_template_file_by_filename (files[i]);
+ }
+ else
+ {
+ template_file = get_personal_template_file_by_index (i);
+ }
+
+ latexila_templates_add_template (GTK_LIST_STORE (templates),
+ names[i],
+ icons[i],
+ template_file);
+
+ g_object_unref (template_file);
+ }
out:
- if (error != NULL)
- {
- g_warning ("The loading of personal templates failed: %s", error->message);
- g_error_free (error);
- }
-
- g_object_unref (rc_file);
- g_free (contents);
- g_strfreev (names);
- g_strfreev (icons);
-
- if (key_file != NULL)
- g_key_file_unref (key_file);
+ if (error != NULL)
+ {
+ g_warning ("The loading of personal templates failed: %s", error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (rc_file);
+ g_free (contents);
+ g_strfreev (names);
+ g_strfreev (icons);
+
+ if (key_file != NULL)
+ {
+ g_key_file_unref (key_file);
+ }
}
static void
latexila_templates_personal_init (LatexilaTemplatesPersonal *templates)
{
- latexila_templates_init_store (GTK_LIST_STORE (templates));
- load_rc_file (templates);
+ latexila_templates_init_store (GTK_LIST_STORE (templates));
+ load_rc_file (templates);
}
/**
@@ -208,12 +224,14 @@ latexila_templates_personal_init (LatexilaTemplatesPersonal *templates)
LatexilaTemplatesPersonal *
latexila_templates_personal_get_instance (void)
{
- static LatexilaTemplatesPersonal *instance = NULL;
+ static LatexilaTemplatesPersonal *instance = NULL;
- if (instance == NULL)
- instance = g_object_new (LATEXILA_TYPE_TEMPLATES_PERSONAL, NULL);
+ if (instance == NULL)
+ {
+ instance = g_object_new (LATEXILA_TYPE_TEMPLATES_PERSONAL, NULL);
+ }
- return instance;
+ return instance;
}
/**
@@ -229,200 +247,212 @@ latexila_templates_personal_get_instance (void)
*/
gchar *
latexila_templates_personal_get_contents (LatexilaTemplatesPersonal *templates,
- GtkTreePath *path)
+ GtkTreePath *path)
{
- GtkTreeIter iter;
- GFile *file;
- gchar *contents = NULL;
- GError *error = NULL;
+ GtkTreeIter iter;
+ GFile *file;
+ gchar *contents = NULL;
+ GError *error = NULL;
- g_return_val_if_fail (LATEXILA_IS_TEMPLATES_PERSONAL (templates), NULL);
- g_return_val_if_fail (path != NULL, NULL);
+ g_return_val_if_fail (LATEXILA_IS_TEMPLATES_PERSONAL (templates), NULL);
+ g_return_val_if_fail (path != NULL, NULL);
- gtk_tree_model_get_iter (GTK_TREE_MODEL (templates),
- &iter,
- path);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (templates),
+ &iter,
+ path);
- gtk_tree_model_get (GTK_TREE_MODEL (templates),
- &iter,
- LATEXILA_TEMPLATES_COLUMN_FILE, &file,
- -1);
+ gtk_tree_model_get (GTK_TREE_MODEL (templates),
+ &iter,
+ LATEXILA_TEMPLATES_COLUMN_FILE, &file,
+ -1);
- g_return_val_if_fail (G_IS_FILE (file), NULL);
+ g_return_val_if_fail (G_IS_FILE (file), NULL);
- g_file_load_contents (file, NULL, &contents, NULL, NULL, &error);
+ g_file_load_contents (file, NULL, &contents, NULL, NULL, &error);
- if (error != NULL)
- {
- g_warning ("Error when loading personal template contents: %s", error->message);
- g_error_free (error);
- }
+ if (error != NULL)
+ {
+ g_warning ("Error when loading personal template contents: %s", error->message);
+ g_error_free (error);
+ }
- g_object_unref (file);
- return contents;
+ g_object_unref (file);
+ return contents;
}
static gboolean
save_rc_file (LatexilaTemplatesPersonal *templates,
- GError **error)
+ GError **error)
{
- GFile *rc_file;
- gchar *rc_path = NULL;
- gint personal_templates_count;
- gchar **names = NULL;
- gchar **icons = NULL;
- gchar **files = NULL;
- GtkTreeIter iter;
- gint template_num;
- GKeyFile *key_file = NULL;
- gboolean ret = TRUE;
-
- rc_file = get_rc_file ();
- personal_templates_count = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (templates), NULL);
-
- if (personal_templates_count == 0)
- {
- GError *my_error = NULL;
-
- g_file_delete (rc_file, NULL, &my_error);
-
- if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
- {
- g_error_free (my_error);
- my_error = NULL;
- }
- else if (my_error != NULL)
- {
- ret = FALSE;
- g_propagate_error (error, my_error);
- }
-
- goto out;
- }
-
- names = g_new0 (gchar *, personal_templates_count + 1);
- icons = g_new0 (gchar *, personal_templates_count + 1);
- files = g_new0 (gchar *, personal_templates_count + 1);
-
- if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (templates), &iter))
- g_assert_not_reached ();
-
- template_num = 0;
- do
- {
- gchar *name;
- gchar *icon;
- GFile *file;
-
- gtk_tree_model_get (GTK_TREE_MODEL (templates), &iter,
- LATEXILA_TEMPLATES_COLUMN_NAME, &name,
- LATEXILA_TEMPLATES_COLUMN_CONFIG_ICON_NAME, &icon,
- LATEXILA_TEMPLATES_COLUMN_FILE, &file,
- -1);
-
- g_assert_cmpint (template_num, <, personal_templates_count);
- names[template_num] = name;
- icons[template_num] = icon;
- files[template_num] = g_file_get_basename (file);
-
- g_object_unref (file);
- template_num++;
- }
- while (gtk_tree_model_iter_next (GTK_TREE_MODEL (templates), &iter));
-
- g_assert_cmpint (template_num, ==, personal_templates_count);
-
- key_file = g_key_file_new ();
-
- g_key_file_set_string_list (key_file,
- PACKAGE_NAME,
- "names",
- (const gchar * const *) names,
- personal_templates_count);
-
- g_key_file_set_string_list (key_file,
- PACKAGE_NAME,
- "icons",
- (const gchar * const *) icons,
- personal_templates_count);
-
- g_key_file_set_string_list (key_file,
- PACKAGE_NAME,
- "files",
- (const gchar * const *) files,
- personal_templates_count);
-
- if (!latexila_utils_create_parent_directories (rc_file, error))
- {
- ret = FALSE;
- goto out;
- }
-
- rc_path = g_file_get_path (rc_file);
- if (!g_key_file_save_to_file (key_file, rc_path, error))
- ret = FALSE;
+ GFile *rc_file;
+ gchar *rc_path = NULL;
+ gint personal_templates_count;
+ gchar **names = NULL;
+ gchar **icons = NULL;
+ gchar **files = NULL;
+ GtkTreeIter iter;
+ gint template_num;
+ GKeyFile *key_file = NULL;
+ gboolean ret = TRUE;
+
+ rc_file = get_rc_file ();
+ personal_templates_count = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (templates), NULL);
+
+ if (personal_templates_count == 0)
+ {
+ GError *my_error = NULL;
+
+ g_file_delete (rc_file, NULL, &my_error);
+
+ if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+ {
+ g_error_free (my_error);
+ my_error = NULL;
+ }
+ else if (my_error != NULL)
+ {
+ ret = FALSE;
+ g_propagate_error (error, my_error);
+ }
+
+ goto out;
+ }
+
+ names = g_new0 (gchar *, personal_templates_count + 1);
+ icons = g_new0 (gchar *, personal_templates_count + 1);
+ files = g_new0 (gchar *, personal_templates_count + 1);
+
+ if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (templates), &iter))
+ {
+ g_assert_not_reached ();
+ }
+
+ template_num = 0;
+ do
+ {
+ gchar *name;
+ gchar *icon;
+ GFile *file;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (templates), &iter,
+ LATEXILA_TEMPLATES_COLUMN_NAME, &name,
+ LATEXILA_TEMPLATES_COLUMN_CONFIG_ICON_NAME, &icon,
+ LATEXILA_TEMPLATES_COLUMN_FILE, &file,
+ -1);
+
+ g_assert_cmpint (template_num, <, personal_templates_count);
+ names[template_num] = name;
+ icons[template_num] = icon;
+ files[template_num] = g_file_get_basename (file);
+
+ g_object_unref (file);
+ template_num++;
+ }
+ while (gtk_tree_model_iter_next (GTK_TREE_MODEL (templates), &iter));
+
+ g_assert_cmpint (template_num, ==, personal_templates_count);
+
+ key_file = g_key_file_new ();
+
+ g_key_file_set_string_list (key_file,
+ PACKAGE_NAME,
+ "names",
+ (const gchar * const *) names,
+ personal_templates_count);
+
+ g_key_file_set_string_list (key_file,
+ PACKAGE_NAME,
+ "icons",
+ (const gchar * const *) icons,
+ personal_templates_count);
+
+ g_key_file_set_string_list (key_file,
+ PACKAGE_NAME,
+ "files",
+ (const gchar * const *) files,
+ personal_templates_count);
+
+ if (!latexila_utils_create_parent_directories (rc_file, error))
+ {
+ ret = FALSE;
+ goto out;
+ }
+
+ rc_path = g_file_get_path (rc_file);
+ if (!g_key_file_save_to_file (key_file, rc_path, error))
+ {
+ ret = FALSE;
+ }
out:
- g_object_unref (rc_file);
- g_free (rc_path);
- g_strfreev (names);
- g_strfreev (icons);
- g_strfreev (files);
-
- if (key_file != NULL)
- g_key_file_unref (key_file);
-
- return ret;
+ g_object_unref (rc_file);
+ g_free (rc_path);
+ g_strfreev (names);
+ g_strfreev (icons);
+ g_strfreev (files);
+
+ if (key_file != NULL)
+ {
+ g_key_file_unref (key_file);
+ }
+
+ return ret;
}
static gboolean
is_template_index_used (LatexilaTemplatesPersonal *templates,
- gint template_num)
+ gint template_num)
{
- GtkTreeIter iter;
-
- if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (templates), &iter))
- return FALSE;
-
- do
- {
- GFile *file;
- gchar *basename;
- gchar *endptr;
- glong cur_template_num;
- gboolean numeric_basename;
-
- gtk_tree_model_get (GTK_TREE_MODEL (templates), &iter,
- LATEXILA_TEMPLATES_COLUMN_FILE, &file,
- -1);
-
- basename = g_file_get_basename (file);
- cur_template_num = strtol (basename, &endptr, 10);
- numeric_basename = endptr != basename;
-
- g_object_unref (file);
- g_free (basename);
-
- if (numeric_basename && template_num == cur_template_num)
- return TRUE;
- }
- while (gtk_tree_model_iter_next (GTK_TREE_MODEL (templates), &iter));
-
- return FALSE;
+ GtkTreeIter iter;
+
+ if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (templates), &iter))
+ {
+ return FALSE;
+ }
+
+ do
+ {
+ GFile *file;
+ gchar *basename;
+ gchar *endptr;
+ glong cur_template_num;
+ gboolean numeric_basename;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (templates), &iter,
+ LATEXILA_TEMPLATES_COLUMN_FILE, &file,
+ -1);
+
+ basename = g_file_get_basename (file);
+ cur_template_num = strtol (basename, &endptr, 10);
+ numeric_basename = endptr != basename;
+
+ g_object_unref (file);
+ g_free (basename);
+
+ if (numeric_basename && template_num == cur_template_num)
+ {
+ return TRUE;
+ }
+ }
+ while (gtk_tree_model_iter_next (GTK_TREE_MODEL (templates), &iter));
+
+ return FALSE;
}
static gint
get_first_free_template_index (LatexilaTemplatesPersonal *templates)
{
- gint template_num;
+ gint template_num;
- for (template_num = 0; template_num < G_MAXINT; template_num++)
- {
- if (!is_template_index_used (templates, template_num))
- return template_num;
- }
+ for (template_num = 0; template_num < G_MAXINT; template_num++)
+ {
+ if (!is_template_index_used (templates, template_num))
+ {
+ return template_num;
+ }
+ }
- g_return_val_if_reached (-1);
+ g_return_val_if_reached (-1);
}
/**
@@ -440,64 +470,66 @@ get_first_free_template_index (LatexilaTemplatesPersonal *templates)
*/
gboolean
latexila_templates_personal_create (LatexilaTemplatesPersonal *templates,
- const gchar *name,
- const gchar *config_icon_name,
- const gchar *contents,
- GError **error)
+ const gchar *name,
+ const gchar *config_icon_name,
+ const gchar *contents,
+ GError **error)
{
- gint template_num;
- GFile *template_file = NULL;
- GFileOutputStream *stream = NULL;
- gboolean ret = TRUE;
-
- g_return_val_if_fail (LATEXILA_IS_TEMPLATES_PERSONAL (templates), FALSE);
- g_return_val_if_fail (name != NULL && name[0] != '\0', FALSE);
- g_return_val_if_fail (config_icon_name != NULL && config_icon_name[0] != '\0', FALSE);
- g_return_val_if_fail (contents != NULL, FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
- template_num = get_first_free_template_index (templates);
- g_return_val_if_fail (template_num >= 0, FALSE);
-
- template_file = get_personal_template_file_by_index (template_num);
-
- if (!latexila_utils_create_parent_directories (template_file, error))
- {
- ret = FALSE;
- goto out;
- }
-
- stream = g_file_create (template_file, G_FILE_CREATE_NONE, NULL, error);
-
- if (stream == NULL)
- {
- ret = FALSE;
- goto out;
- }
-
- if (!g_output_stream_write_all (G_OUTPUT_STREAM (stream),
- contents,
- strlen (contents),
- NULL,
- NULL,
- error))
- {
- ret = FALSE;
- goto out;
- }
-
- latexila_templates_add_template (GTK_LIST_STORE (templates),
- name,
- config_icon_name,
- template_file);
-
- if (!save_rc_file (templates, error))
- ret = FALSE;
+ gint template_num;
+ GFile *template_file = NULL;
+ GFileOutputStream *stream = NULL;
+ gboolean ret = TRUE;
+
+ g_return_val_if_fail (LATEXILA_IS_TEMPLATES_PERSONAL (templates), FALSE);
+ g_return_val_if_fail (name != NULL && name[0] != '\0', FALSE);
+ g_return_val_if_fail (config_icon_name != NULL && config_icon_name[0] != '\0', FALSE);
+ g_return_val_if_fail (contents != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ template_num = get_first_free_template_index (templates);
+ g_return_val_if_fail (template_num >= 0, FALSE);
+
+ template_file = get_personal_template_file_by_index (template_num);
+
+ if (!latexila_utils_create_parent_directories (template_file, error))
+ {
+ ret = FALSE;
+ goto out;
+ }
+
+ stream = g_file_create (template_file, G_FILE_CREATE_NONE, NULL, error);
+
+ if (stream == NULL)
+ {
+ ret = FALSE;
+ goto out;
+ }
+
+ if (!g_output_stream_write_all (G_OUTPUT_STREAM (stream),
+ contents,
+ strlen (contents),
+ NULL,
+ NULL,
+ error))
+ {
+ ret = FALSE;
+ goto out;
+ }
+
+ latexila_templates_add_template (GTK_LIST_STORE (templates),
+ name,
+ config_icon_name,
+ template_file);
+
+ if (!save_rc_file (templates, error))
+ {
+ ret = FALSE;
+ }
out:
- g_clear_object (&template_file);
- g_clear_object (&stream);
- return ret;
+ g_clear_object (&template_file);
+ g_clear_object (&stream);
+ return ret;
}
/**
@@ -512,36 +544,40 @@ out:
*/
gboolean
latexila_templates_personal_delete (LatexilaTemplatesPersonal *templates,
- GtkTreeIter *iter,
- GError **error)
+ GtkTreeIter *iter,
+ GError **error)
{
- GFile *file = NULL;
- gboolean success = FALSE;
+ GFile *file = NULL;
+ gboolean success = FALSE;
- g_return_val_if_fail (LATEXILA_IS_TEMPLATES_PERSONAL (templates), FALSE);
- g_return_val_if_fail (iter != NULL, FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail (LATEXILA_IS_TEMPLATES_PERSONAL (templates), FALSE);
+ g_return_val_if_fail (iter != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- gtk_tree_model_get (GTK_TREE_MODEL (templates),
- iter,
- LATEXILA_TEMPLATES_COLUMN_FILE, &file,
- -1);
+ gtk_tree_model_get (GTK_TREE_MODEL (templates),
+ iter,
+ LATEXILA_TEMPLATES_COLUMN_FILE, &file,
+ -1);
- g_return_val_if_fail (G_IS_FILE (file), FALSE);
+ g_return_val_if_fail (G_IS_FILE (file), FALSE);
- gtk_list_store_remove (GTK_LIST_STORE (templates), iter);
+ gtk_list_store_remove (GTK_LIST_STORE (templates), iter);
- if (!save_rc_file (templates, error))
- goto out;
+ if (!save_rc_file (templates, error))
+ {
+ goto out;
+ }
- if (!g_file_delete (file, NULL, error))
- goto out;
+ if (!g_file_delete (file, NULL, error))
+ {
+ goto out;
+ }
- success = TRUE;
+ success = TRUE;
out:
- g_clear_object (&file);
- return success;
+ g_clear_object (&file);
+ return success;
}
/**
@@ -556,24 +592,26 @@ out:
*/
gboolean
latexila_templates_personal_move_up (LatexilaTemplatesPersonal *templates,
- GtkTreeIter *iter,
- GError **error)
+ GtkTreeIter *iter,
+ GError **error)
{
- GtkTreeIter prev_iter;
+ GtkTreeIter prev_iter;
- g_return_val_if_fail (LATEXILA_IS_TEMPLATES_PERSONAL (templates), FALSE);
- g_return_val_if_fail (iter != NULL, FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail (LATEXILA_IS_TEMPLATES_PERSONAL (templates), FALSE);
+ g_return_val_if_fail (iter != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- prev_iter = *iter;
- if (!gtk_tree_model_iter_previous (GTK_TREE_MODEL (templates), &prev_iter))
- g_return_val_if_reached (FALSE);
+ prev_iter = *iter;
+ if (!gtk_tree_model_iter_previous (GTK_TREE_MODEL (templates), &prev_iter))
+ {
+ g_return_val_if_reached (FALSE);
+ }
- gtk_list_store_move_before (GTK_LIST_STORE (templates),
- iter,
- &prev_iter);
+ gtk_list_store_move_before (GTK_LIST_STORE (templates),
+ iter,
+ &prev_iter);
- return save_rc_file (templates, error);
+ return save_rc_file (templates, error);
}
/**
@@ -591,19 +629,21 @@ latexila_templates_personal_move_down (LatexilaTemplatesPersonal *templates,
GtkTreeIter *iter,
GError **error)
{
- GtkTreeIter next_iter;
+ GtkTreeIter next_iter;
- g_return_val_if_fail (LATEXILA_IS_TEMPLATES_PERSONAL (templates), FALSE);
- g_return_val_if_fail (iter != NULL, FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail (LATEXILA_IS_TEMPLATES_PERSONAL (templates), FALSE);
+ g_return_val_if_fail (iter != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- next_iter = *iter;
- if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (templates), &next_iter))
- g_return_val_if_reached (FALSE);
+ next_iter = *iter;
+ if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (templates), &next_iter))
+ {
+ g_return_val_if_reached (FALSE);
+ }
- gtk_list_store_move_after (GTK_LIST_STORE (templates),
- iter,
- &next_iter);
+ gtk_list_store_move_after (GTK_LIST_STORE (templates),
+ iter,
+ &next_iter);
- return save_rc_file (templates, error);
+ return save_rc_file (templates, error);
}
diff --git a/src/liblatexila/latexila-utils.c b/src/liblatexila/latexila-utils.c
index a232ac4..107d2f3 100644
--- a/src/liblatexila/latexila-utils.c
+++ b/src/liblatexila/latexila-utils.c
@@ -37,28 +37,34 @@
static gint
get_extension_position (const gchar *filename)
{
- const gchar *pos;
- gint length;
-
- if (filename == NULL)
- return 0;
-
- length = strlen (filename);
- pos = filename + length;
- g_assert (pos[0] == '\0');
-
- while (TRUE)
- {
- pos = g_utf8_find_prev_char (filename, pos);
-
- if (pos == NULL || pos[0] == '/')
- break;
-
- if (pos[0] == '.')
- return pos - filename;
- }
-
- return length;
+ const gchar *pos;
+ gint length;
+
+ if (filename == NULL)
+ {
+ return 0;
+ }
+
+ length = strlen (filename);
+ pos = filename + length;
+ g_assert (pos[0] == '\0');
+
+ while (TRUE)
+ {
+ pos = g_utf8_find_prev_char (filename, pos);
+
+ if (pos == NULL || pos[0] == '/')
+ {
+ break;
+ }
+
+ if (pos[0] == '.')
+ {
+ return pos - filename;
+ }
+ }
+
+ return length;
}
/**
@@ -70,7 +76,7 @@ get_extension_position (const gchar *filename)
gchar *
latexila_utils_get_shortname (const gchar *filename)
{
- return g_strndup (filename, get_extension_position (filename));
+ return g_strndup (filename, get_extension_position (filename));
}
/**
@@ -83,8 +89,9 @@ latexila_utils_get_shortname (const gchar *filename)
gchar *
latexila_utils_get_extension (const gchar *filename)
{
- gint pos = get_extension_position (filename);
- return g_ascii_strdown (filename + pos, -1);
+ gint pos = get_extension_position (filename);
+
+ return g_ascii_strdown (filename + pos, -1);
}
/**
@@ -101,40 +108,44 @@ latexila_utils_get_extension (const gchar *filename)
gchar *
latexila_utils_replace_home_dir_with_tilde (const gchar *filename)
{
- gchar *tmp;
- gchar *home;
-
- g_return_val_if_fail (filename != NULL, NULL);
-
- /* Note that g_get_home_dir returns a const string */
- tmp = (gchar *) g_get_home_dir ();
-
- if (tmp == NULL)
- return g_strdup (filename);
-
- home = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
- if (home == NULL)
- return g_strdup (filename);
-
- if (strcmp (filename, home) == 0)
- {
- g_free (home);
- return g_strdup ("~");
- }
-
- tmp = home;
- home = g_strdup_printf ("%s/", tmp);
- g_free (tmp);
-
- if (g_str_has_prefix (filename, home))
- {
- gchar *res = g_strdup_printf ("~/%s", filename + strlen (home));
- g_free (home);
- return res;
- }
-
- g_free (home);
- return g_strdup (filename);
+ gchar *tmp;
+ gchar *home;
+
+ g_return_val_if_fail (filename != NULL, NULL);
+
+ /* Note that g_get_home_dir returns a const string */
+ tmp = (gchar *) g_get_home_dir ();
+
+ if (tmp == NULL)
+ {
+ return g_strdup (filename);
+ }
+
+ home = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
+ if (home == NULL)
+ {
+ return g_strdup (filename);
+ }
+
+ if (strcmp (filename, home) == 0)
+ {
+ g_free (home);
+ return g_strdup ("~");
+ }
+
+ tmp = home;
+ home = g_strdup_printf ("%s/", tmp);
+ g_free (tmp);
+
+ if (g_str_has_prefix (filename, home))
+ {
+ gchar *res = g_strdup_printf ("~/%s", filename + strlen (home));
+ g_free (home);
+ return res;
+ }
+
+ g_free (home);
+ return g_strdup (filename);
}
/**
@@ -152,8 +163,8 @@ latexila_utils_replace_home_dir_with_tilde (const gchar *filename)
void
latexila_utils_register_icons (void)
{
- gtk_icon_theme_add_resource_path (gtk_icon_theme_get_default (),
- "/org/gnome/gnome-latex/stock-icons/");
+ gtk_icon_theme_add_resource_path (gtk_icon_theme_get_default (),
+ "/org/gnome/gnome-latex/stock-icons/");
}
/**
@@ -165,27 +176,27 @@ latexila_utils_register_icons (void)
*/
GdkPixbuf *
latexila_utils_get_pixbuf_from_icon_name (const gchar *icon_name,
- GtkIconSize icon_size)
+ GtkIconSize icon_size)
{
- gint size;
- GdkPixbuf *pixbuf;
- GError *error = NULL;
+ gint size;
+ GdkPixbuf *pixbuf;
+ GError *error = NULL;
- gtk_icon_size_lookup (icon_size, &size, NULL);
+ gtk_icon_size_lookup (icon_size, &size, NULL);
- pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
- icon_name,
- size,
- 0,
- &error);
+ pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ icon_name,
+ size,
+ 0,
+ &error);
- if (error != NULL)
- {
- g_warning ("Error when loading icon \"%s\": %s", icon_name, error->message);
- g_error_free (error);
- }
+ if (error != NULL)
+ {
+ g_warning ("Error when loading icon \"%s\": %s", icon_name, error->message);
+ g_error_free (error);
+ }
- return pixbuf;
+ return pixbuf;
}
/**
@@ -200,24 +211,28 @@ latexila_utils_get_pixbuf_from_icon_name (const gchar *icon_name,
*/
gchar *
latexila_utils_str_replace (const gchar *string,
- const gchar *search,
- const gchar *replacement)
+ const gchar *search,
+ const gchar *replacement)
{
- gchar **chunks;
- gchar *ret;
-
- g_return_val_if_fail (string != NULL, NULL);
- g_return_val_if_fail (search != NULL, NULL);
- g_return_val_if_fail (replacement != NULL, NULL);
-
- chunks = g_strsplit (string, search, -1);
- if (chunks != NULL && chunks[0] != NULL)
- ret = g_strjoinv (replacement, chunks);
- else
- ret = g_strdup (string);
-
- g_strfreev (chunks);
- return ret;
+ gchar **chunks;
+ gchar *ret;
+
+ g_return_val_if_fail (string != NULL, NULL);
+ g_return_val_if_fail (search != NULL, NULL);
+ g_return_val_if_fail (replacement != NULL, NULL);
+
+ chunks = g_strsplit (string, search, -1);
+ if (chunks != NULL && chunks[0] != NULL)
+ {
+ ret = g_strjoinv (replacement, chunks);
+ }
+ else
+ {
+ ret = g_strdup (string);
+ }
+
+ g_strfreev (chunks);
+ return ret;
}
/**
@@ -233,17 +248,17 @@ latexila_utils_str_replace (const gchar *string,
*/
void
latexila_utils_file_query_exists_async (GFile *file,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- g_file_query_info_async (file,
- G_FILE_ATTRIBUTE_STANDARD_TYPE,
- G_FILE_QUERY_INFO_NONE,
- G_PRIORITY_DEFAULT,
- cancellable,
- callback,
- user_data);
+ g_file_query_info_async (file,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_DEFAULT,
+ cancellable,
+ callback,
+ user_data);
}
/**
@@ -260,46 +275,46 @@ latexila_utils_file_query_exists_async (GFile *file,
*/
gboolean
latexila_utils_file_query_exists_finish (GFile *file,
- GAsyncResult *result)
+ GAsyncResult *result)
{
- GFileInfo *info = g_file_query_info_finish (file, result, NULL);
+ GFileInfo *info = g_file_query_info_finish (file, result, NULL);
- if (info != NULL)
- {
- g_object_unref (info);
- return TRUE;
- }
+ if (info != NULL)
+ {
+ g_object_unref (info);
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
default_document_viewer_is_evince (const gchar *uri)
{
- GFile *file;
- GAppInfo *app_info;
- const gchar *executable;
- gboolean ret;
- GError *error = NULL;
-
- file = g_file_new_for_uri (uri);
- app_info = g_file_query_default_handler (file, NULL, &error);
- g_object_unref (file);
-
- if (error != NULL)
- {
- g_warning ("Impossible to know if evince is the default document viewer: %s",
- error->message);
-
- g_error_free (error);
- return FALSE;
- }
-
- executable = g_app_info_get_executable (app_info);
- ret = strstr (executable, "evince") != NULL;
-
- g_object_unref (app_info);
- return ret;
+ GFile *file;
+ GAppInfo *app_info;
+ const gchar *executable;
+ gboolean ret;
+ GError *error = NULL;
+
+ file = g_file_new_for_uri (uri);
+ app_info = g_file_query_default_handler (file, NULL, &error);
+ g_object_unref (file);
+
+ if (error != NULL)
+ {
+ g_warning ("Impossible to know if evince is the default document viewer: %s",
+ error->message);
+
+ g_error_free (error);
+ return FALSE;
+ }
+
+ executable = g_app_info_get_executable (app_info);
+ ret = strstr (executable, "evince") != NULL;
+
+ g_object_unref (app_info);
+ return ret;
}
/**
@@ -315,39 +330,41 @@ default_document_viewer_is_evince (const gchar *uri)
*/
void
latexila_utils_show_uri (GtkWidget *widget,
- const gchar *uri,
- guint32 timestamp,
- GError **error)
+ const gchar *uri,
+ guint32 timestamp,
+ GError **error)
{
- GtkWindow *parent = NULL;
-
- g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
- g_return_if_fail (uri != NULL);
- g_return_if_fail (error == NULL || *error == NULL);
-
- if (widget != NULL)
- {
- GtkWidget *toplevel;
-
- toplevel = gtk_widget_get_toplevel (widget);
- if (gtk_widget_is_toplevel (toplevel) &&
- GTK_IS_WINDOW (toplevel))
- parent = GTK_WINDOW (toplevel);
- }
-
- if (gtk_show_uri_on_window (parent, uri, timestamp, error))
- {
- gchar *extension = latexila_utils_get_extension (uri);
-
- if (g_strcmp0 (extension, ".pdf") == 0 &&
- default_document_viewer_is_evince (uri))
- {
- LatexilaSynctex *synctex = latexila_synctex_get_instance ();
- latexila_synctex_connect_evince_window (synctex, uri);
- }
-
- g_free (extension);
- }
+ GtkWindow *parent = NULL;
+
+ g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
+ g_return_if_fail (uri != NULL);
+ g_return_if_fail (error == NULL || *error == NULL);
+
+ if (widget != NULL)
+ {
+ GtkWidget *toplevel;
+
+ toplevel = gtk_widget_get_toplevel (widget);
+ if (gtk_widget_is_toplevel (toplevel) &&
+ GTK_IS_WINDOW (toplevel))
+ {
+ parent = GTK_WINDOW (toplevel);
+ }
+ }
+
+ if (gtk_show_uri_on_window (parent, uri, timestamp, error))
+ {
+ gchar *extension = latexila_utils_get_extension (uri);
+
+ if (g_strcmp0 (extension, ".pdf") == 0 &&
+ default_document_viewer_is_evince (uri))
+ {
+ LatexilaSynctex *synctex = latexila_synctex_get_instance ();
+ latexila_synctex_connect_evince_window (synctex, uri);
+ }
+
+ g_free (extension);
+ }
}
/**
@@ -365,30 +382,30 @@ latexila_utils_show_uri (GtkWidget *widget,
*/
GtkWidget *
latexila_utils_get_dialog_component (const gchar *title,
- GtkWidget *widget)
+ GtkWidget *widget)
{
- GtkContainer *grid;
- GtkWidget *label;
- gchar *markup;
-
- grid = GTK_CONTAINER (gtk_grid_new ());
- gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
- gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
- gtk_container_set_border_width (grid, 6);
-
- /* Title in bold, left-aligned. */
- label = gtk_label_new (NULL);
- markup = g_strdup_printf ("<b>%s</b>", title);
- gtk_label_set_markup (GTK_LABEL (label), markup);
- gtk_widget_set_halign (label, GTK_ALIGN_START);
- gtk_container_add (grid, label);
-
- /* Left margin for the widget. */
- gtk_widget_set_margin_start (widget, 12);
- gtk_container_add (grid, widget);
-
- g_free (markup);
- return GTK_WIDGET (grid);
+ GtkContainer *grid;
+ GtkWidget *label;
+ gchar *markup;
+
+ grid = GTK_CONTAINER (gtk_grid_new ());
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
+ gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
+ gtk_container_set_border_width (grid, 6);
+
+ /* Title in bold, left-aligned. */
+ label = gtk_label_new (NULL);
+ markup = g_strdup_printf ("<b>%s</b>", title);
+ gtk_label_set_markup (GTK_LABEL (label), markup);
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
+ gtk_container_add (grid, label);
+
+ /* Left margin for the widget. */
+ gtk_widget_set_margin_start (widget, 12);
+ gtk_container_add (grid, widget);
+
+ g_free (markup);
+ return GTK_WIDGET (grid);
}
/**
@@ -404,37 +421,39 @@ latexila_utils_get_dialog_component (const gchar *title,
*/
gboolean
latexila_utils_create_parent_directories (GFile *file,
- GError **error)
+ GError **error)
{
- GFile *parent;
- GError *my_error = NULL;
-
- g_return_val_if_fail (G_IS_FILE (file), FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
- parent = g_file_get_parent (file);
-
- if (parent == NULL)
- return TRUE;
-
- g_file_make_directory_with_parents (parent, NULL, &my_error);
- g_object_unref (parent);
-
- if (my_error != NULL)
- {
- if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_EXISTS))
- {
- g_error_free (my_error);
- return TRUE;
- }
- else
- {
- g_propagate_error (error, my_error);
- return FALSE;
- }
- }
-
- return TRUE;
+ GFile *parent;
+ GError *my_error = NULL;
+
+ g_return_val_if_fail (G_IS_FILE (file), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ parent = g_file_get_parent (file);
+
+ if (parent == NULL)
+ {
+ return TRUE;
+ }
+
+ g_file_make_directory_with_parents (parent, NULL, &my_error);
+ g_object_unref (parent);
+
+ if (my_error != NULL)
+ {
+ if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_EXISTS))
+ {
+ g_error_free (my_error);
+ return TRUE;
+ }
+ else
+ {
+ g_propagate_error (error, my_error);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
}
/**
@@ -449,23 +468,23 @@ latexila_utils_create_parent_directories (GFile *file,
*/
GtkWidget *
latexila_utils_join_widgets (GtkWidget *widget_top,
- GtkWidget *widget_bottom)
+ GtkWidget *widget_bottom)
{
- GtkStyleContext *context;
- GtkBox *vbox;
+ GtkStyleContext *context;
+ GtkBox *vbox;
- g_return_val_if_fail (GTK_IS_WIDGET (widget_top), NULL);
- g_return_val_if_fail (GTK_IS_WIDGET (widget_bottom), NULL);
+ g_return_val_if_fail (GTK_IS_WIDGET (widget_top), NULL);
+ g_return_val_if_fail (GTK_IS_WIDGET (widget_bottom), NULL);
- context = gtk_widget_get_style_context (widget_top);
- gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
+ context = gtk_widget_get_style_context (widget_top);
+ gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
- context = gtk_widget_get_style_context (widget_bottom);
- gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
+ context = gtk_widget_get_style_context (widget_bottom);
+ gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
- vbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 0));
- gtk_box_pack_start (vbox, widget_top, TRUE, TRUE, 0);
- gtk_box_pack_start (vbox, widget_bottom, FALSE, FALSE, 0);
+ vbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 0));
+ gtk_box_pack_start (vbox, widget_top, TRUE, TRUE, 0);
+ gtk_box_pack_start (vbox, widget_bottom, FALSE, FALSE, 0);
- return GTK_WIDGET (vbox);
+ return GTK_WIDGET (vbox);
}
diff --git a/src/liblatexila/latexila-view.c b/src/liblatexila/latexila-view.c
index dafb374..7af4a17 100644
--- a/src/liblatexila/latexila-view.c
+++ b/src/liblatexila/latexila-view.c
@@ -37,26 +37,26 @@
void
latexila_view_configure_space_drawer (GtkSourceView *view)
{
- GtkSourceSpaceDrawer *space_drawer;
+ GtkSourceSpaceDrawer *space_drawer;
- g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
+ g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
- space_drawer = gtk_source_view_get_space_drawer (view);
+ space_drawer = gtk_source_view_get_space_drawer (view);
- /* Rationale for always drawing non-breaking spaces:
- *
- * With my Dvorak bépo keyboard layout, it is possible to type a non-breaking
- * space. I remember that one time I inserted one by mistake in GNOME LaTeX,
- * and when compiling the document there was an incomprehensible error, it
- * took me some time to figure out that there was a non-breaking space... So,
- * I think it's better to always draw non-breaking spaces, to distinguish them
- * from normal spaces. -- swilmet
- */
- gtk_source_space_drawer_set_types_for_locations (space_drawer,
- GTK_SOURCE_SPACE_LOCATION_ALL,
- GTK_SOURCE_SPACE_TYPE_NBSP);
+ /* Rationale for always drawing non-breaking spaces:
+ *
+ * With my Dvorak bépo keyboard layout, it is possible to type a non-breaking
+ * space. I remember that one time I inserted one by mistake in GNOME LaTeX,
+ * and when compiling the document there was an incomprehensible error, it
+ * took me some time to figure out that there was a non-breaking space... So,
+ * I think it's better to always draw non-breaking spaces, to distinguish them
+ * from normal spaces. -- swilmet
+ */
+ gtk_source_space_drawer_set_types_for_locations (space_drawer,
+ GTK_SOURCE_SPACE_LOCATION_ALL,
+ GTK_SOURCE_SPACE_TYPE_NBSP);
- gtk_source_space_drawer_set_enable_matrix (space_drawer, TRUE);
+ gtk_source_space_drawer_set_enable_matrix (space_drawer, TRUE);
}
/**
@@ -75,17 +75,19 @@ latexila_view_configure_space_drawer (GtkSourceView *view)
gchar *
latexila_view_get_indentation_style (GtkSourceView *view)
{
- guint tab_width;
- gint indent_width;
+ guint tab_width;
+ gint indent_width;
- g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), NULL);
+ g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), NULL);
- tab_width = gtk_source_view_get_tab_width (view);
- indent_width = gtk_source_view_get_indent_width (view);
- g_return_val_if_fail (indent_width == -1 || indent_width == (gint)tab_width, NULL);
+ tab_width = gtk_source_view_get_tab_width (view);
+ indent_width = gtk_source_view_get_indent_width (view);
+ g_return_val_if_fail (indent_width == -1 || indent_width == (gint)tab_width, NULL);
- if (gtk_source_view_get_insert_spaces_instead_of_tabs (view))
- return g_strnfill (tab_width, ' ');
+ if (gtk_source_view_get_insert_spaces_instead_of_tabs (view))
+ {
+ return g_strnfill (tab_width, ' ');
+ }
- return g_strdup ("\t");
+ return g_strdup ("\t");
}
diff --git a/tests/test-build-tools.c b/tests/test-build-tools.c
index d562e32..77285a6 100644
--- a/tests/test-build-tools.c
+++ b/tests/test-build-tools.c
@@ -22,197 +22,201 @@
static void
check_build_jobs (LatexilaBuildJob *build_job1,
- LatexilaBuildJob *build_job2)
+ LatexilaBuildJob *build_job2)
{
- gchar *command1;
- gchar *command2;
- LatexilaPostProcessorType pp_type1;
- LatexilaPostProcessorType pp_type2;
-
- g_object_get (build_job1,
- "command", &command1,
- "post-processor-type", &pp_type1,
- NULL);
-
- g_object_get (build_job2,
- "command", &command2,
- "post-processor-type", &pp_type2,
- NULL);
-
- g_assert_cmpstr (command1, ==, command2);
- g_assert_cmpint (pp_type1, ==, pp_type2);
-
- g_free (command1);
- g_free (command2);
+ gchar *command1;
+ gchar *command2;
+ LatexilaPostProcessorType pp_type1;
+ LatexilaPostProcessorType pp_type2;
+
+ g_object_get (build_job1,
+ "command", &command1,
+ "post-processor-type", &pp_type1,
+ NULL);
+
+ g_object_get (build_job2,
+ "command", &command2,
+ "post-processor-type", &pp_type2,
+ NULL);
+
+ g_assert_cmpstr (command1, ==, command2);
+ g_assert_cmpint (pp_type1, ==, pp_type2);
+
+ g_free (command1);
+ g_free (command2);
}
static void
check_build_tools (LatexilaBuildTool *build_tool1,
- LatexilaBuildTool *build_tool2)
+ LatexilaBuildTool *build_tool2)
{
- gchar *label1;
- gchar *label2;
- gchar *description1;
- gchar *description2;
- gchar *extensions1;
- gchar *extensions2;
- gchar *icon1;
- gchar *icon2;
- gchar *files_to_open1;
- gchar *files_to_open2;
- gint id1;
- gint id2;
- gboolean enabled1;
- gboolean enabled2;
- GList *jobs1;
- GList *jobs2;
-
- g_object_get (build_tool1,
- "label", &label1,
- "description", &description1,
- "extensions", &extensions1,
- "icon", &icon1,
- "files-to-open", &files_to_open1,
- "id", &id1,
- "enabled", &enabled1,
- NULL);
-
- g_object_get (build_tool2,
- "label", &label2,
- "description", &description2,
- "extensions", &extensions2,
- "icon", &icon2,
- "files-to-open", &files_to_open2,
- "id", &id2,
- "enabled", &enabled2,
- NULL);
-
- g_assert_cmpstr (label1, ==, label2);
- g_assert_cmpstr (description1, ==, description2);
- g_assert_cmpstr (extensions1, ==, extensions2);
- g_assert_cmpstr (icon1, ==, icon2);
- g_assert_cmpstr (files_to_open1, ==, files_to_open2);
- g_assert_cmpint (id1, ==, id2);
- g_assert_cmpint (enabled1, ==, enabled2);
-
- jobs1 = latexila_build_tool_get_jobs (build_tool1);
- jobs2 = latexila_build_tool_get_jobs (build_tool2);
-
- g_assert_cmpint (g_list_length (jobs1), ==, g_list_length (jobs2));
-
- for (; jobs1 != NULL; jobs1 = jobs1->next, jobs2 = jobs2->next)
- check_build_jobs (jobs1->data, jobs2->data);
-
- g_free (label1);
- g_free (label2);
- g_free (description1);
- g_free (description2);
- g_free (extensions1);
- g_free (extensions2);
- g_free (icon1);
- g_free (icon2);
- g_free (files_to_open1);
- g_free (files_to_open2);
+ gchar *label1;
+ gchar *label2;
+ gchar *description1;
+ gchar *description2;
+ gchar *extensions1;
+ gchar *extensions2;
+ gchar *icon1;
+ gchar *icon2;
+ gchar *files_to_open1;
+ gchar *files_to_open2;
+ gint id1;
+ gint id2;
+ gboolean enabled1;
+ gboolean enabled2;
+ GList *jobs1;
+ GList *jobs2;
+
+ g_object_get (build_tool1,
+ "label", &label1,
+ "description", &description1,
+ "extensions", &extensions1,
+ "icon", &icon1,
+ "files-to-open", &files_to_open1,
+ "id", &id1,
+ "enabled", &enabled1,
+ NULL);
+
+ g_object_get (build_tool2,
+ "label", &label2,
+ "description", &description2,
+ "extensions", &extensions2,
+ "icon", &icon2,
+ "files-to-open", &files_to_open2,
+ "id", &id2,
+ "enabled", &enabled2,
+ NULL);
+
+ g_assert_cmpstr (label1, ==, label2);
+ g_assert_cmpstr (description1, ==, description2);
+ g_assert_cmpstr (extensions1, ==, extensions2);
+ g_assert_cmpstr (icon1, ==, icon2);
+ g_assert_cmpstr (files_to_open1, ==, files_to_open2);
+ g_assert_cmpint (id1, ==, id2);
+ g_assert_cmpint (enabled1, ==, enabled2);
+
+ jobs1 = latexila_build_tool_get_jobs (build_tool1);
+ jobs2 = latexila_build_tool_get_jobs (build_tool2);
+
+ g_assert_cmpint (g_list_length (jobs1), ==, g_list_length (jobs2));
+
+ for (; jobs1 != NULL; jobs1 = jobs1->next, jobs2 = jobs2->next)
+ {
+ check_build_jobs (jobs1->data, jobs2->data);
+ }
+
+ g_free (label1);
+ g_free (label2);
+ g_free (description1);
+ g_free (description2);
+ g_free (extensions1);
+ g_free (extensions2);
+ g_free (icon1);
+ g_free (icon2);
+ g_free (files_to_open1);
+ g_free (files_to_open2);
}
static void
loaded_cb (LatexilaBuildTools *build_tools)
{
- GList *list = NULL;
- LatexilaBuildTool *build_tool;
- LatexilaBuildJob *build_job;
- GList *l1;
- GList *l2;
+ GList *list = NULL;
+ LatexilaBuildTool *build_tool;
+ LatexilaBuildJob *build_job;
+ GList *l1;
+ GList *l2;
- /* First build tool */
+ /* First build tool */
- build_tool = latexila_build_tool_new ();
+ build_tool = latexila_build_tool_new ();
- g_object_set (build_tool,
- "id", 1,
- "enabled", TRUE,
- "extensions", ".tex",
- "icon", "compile_pdf",
- "label", "LaTeX → PDF (Latexmk)",
- "files-to-open", "$shortname.pdf",
- NULL);
+ g_object_set (build_tool,
+ "id", 1,
+ "enabled", TRUE,
+ "extensions", ".tex",
+ "icon", "compile_pdf",
+ "label", "LaTeX → PDF (Latexmk)",
+ "files-to-open", "$shortname.pdf",
+ NULL);
- build_job = latexila_build_job_new ();
+ build_job = latexila_build_job_new ();
- g_object_set (build_job,
- "post-processor-type", LATEXILA_POST_PROCESSOR_TYPE_LATEXMK,
- "command", "latexmk -pdf -synctex=1 $filename",
- NULL);
+ g_object_set (build_job,
+ "post-processor-type", LATEXILA_POST_PROCESSOR_TYPE_LATEXMK,
+ "command", "latexmk -pdf -synctex=1 $filename",
+ NULL);
- latexila_build_tool_add_job (build_tool, build_job);
- g_object_unref (build_job);
+ latexila_build_tool_add_job (build_tool, build_job);
+ g_object_unref (build_job);
- build_job = latexila_build_job_new ();
+ build_job = latexila_build_job_new ();
- g_object_set (build_job,
- "post-processor-type", LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT,
- "command", "build job 2",
- NULL);
+ g_object_set (build_job,
+ "post-processor-type", LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT,
+ "command", "build job 2",
+ NULL);
- latexila_build_tool_add_job (build_tool, build_job);
- g_object_unref (build_job);
+ latexila_build_tool_add_job (build_tool, build_job);
+ g_object_unref (build_job);
- list = g_list_append (list, build_tool);
+ list = g_list_append (list, build_tool);
- /* Second build tool */
+ /* Second build tool */
- build_tool = latexila_build_tool_new ();
+ build_tool = latexila_build_tool_new ();
- g_object_set (build_tool,
- "enabled", FALSE,
- "label", "build tool 2",
- NULL);
+ g_object_set (build_tool,
+ "enabled", FALSE,
+ "label", "build tool 2",
+ NULL);
- list = g_list_append (list, build_tool);
+ list = g_list_append (list, build_tool);
- /* Compare */
+ /* Compare */
- g_assert_cmpint (g_list_length (list), ==, g_list_length (build_tools->build_tools));
+ g_assert_cmpint (g_list_length (list), ==, g_list_length (build_tools->build_tools));
- for (l1 = list, l2 = build_tools->build_tools;
- l1 != NULL && l2 != NULL;
- l1 = l1->next, l2 = l2->next)
- check_build_tools (l1->data, l2->data);
+ for (l1 = list, l2 = build_tools->build_tools;
+ l1 != NULL && l2 != NULL;
+ l1 = l1->next, l2 = l2->next)
+ {
+ check_build_tools (l1->data, l2->data);
+ }
- g_list_free_full (list, g_object_unref);
- gtk_main_quit ();
+ g_list_free_full (list, g_object_unref);
+ gtk_main_quit ();
}
static void
test_load (void)
{
- LatexilaBuildTools *build_tools;
- GFile *xml_file;
+ LatexilaBuildTools *build_tools;
+ GFile *xml_file;
- build_tools = g_object_new (LATEXILA_TYPE_BUILD_TOOLS, NULL);
+ build_tools = g_object_new (LATEXILA_TYPE_BUILD_TOOLS, NULL);
- g_signal_connect (build_tools,
- "loaded",
- G_CALLBACK (loaded_cb),
- NULL);
+ g_signal_connect (build_tools,
+ "loaded",
+ G_CALLBACK (loaded_cb),
+ NULL);
- xml_file = g_file_new_for_uri ("resource:///org/gnome/gnome-latex/build_tools_test.xml");
- g_assert (g_file_query_exists (xml_file, NULL));
+ xml_file = g_file_new_for_uri ("resource:///org/gnome/gnome-latex/build_tools_test.xml");
+ g_assert (g_file_query_exists (xml_file, NULL));
- latexila_build_tools_load (build_tools, xml_file);
- g_object_unref (xml_file);
+ latexila_build_tools_load (build_tools, xml_file);
+ g_object_unref (xml_file);
- gtk_main ();
- g_object_unref (build_tools);
+ gtk_main ();
+ g_object_unref (build_tools);
}
gint
main (gint argc,
gchar **argv)
{
- g_test_init (&argc, &argv, NULL);
+ g_test_init (&argc, &argv, NULL);
- g_test_add_func ("/build-tools/load", test_load);
+ g_test_add_func ("/build-tools/load", test_load);
- return g_test_run ();
+ return g_test_run ();
}
diff --git a/tests/test-utils.c b/tests/test-utils.c
index b6a02b0..68809d5 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -22,97 +22,97 @@
static void
test_get_shortname (void)
{
- gchar *shortname;
+ gchar *shortname;
- shortname = latexila_utils_get_shortname ("file.txt");
- g_assert_cmpstr (shortname, ==, "file");
- g_free (shortname);
+ shortname = latexila_utils_get_shortname ("file.txt");
+ g_assert_cmpstr (shortname, ==, "file");
+ g_free (shortname);
- shortname = latexila_utils_get_shortname ("file.tar.gz");
- g_assert_cmpstr (shortname, ==, "file.tar");
- g_free (shortname);
+ shortname = latexila_utils_get_shortname ("file.tar.gz");
+ g_assert_cmpstr (shortname, ==, "file.tar");
+ g_free (shortname);
- shortname = latexila_utils_get_shortname ("file");
- g_assert_cmpstr (shortname, ==, "file");
- g_free (shortname);
+ shortname = latexila_utils_get_shortname ("file");
+ g_assert_cmpstr (shortname, ==, "file");
+ g_free (shortname);
- shortname = latexila_utils_get_shortname ("dir.ext/blah");
- g_assert_cmpstr (shortname, ==, "dir.ext/blah");
- g_free (shortname);
+ shortname = latexila_utils_get_shortname ("dir.ext/blah");
+ g_assert_cmpstr (shortname, ==, "dir.ext/blah");
+ g_free (shortname);
}
static void
test_get_extension (void)
{
- gchar *extension;
+ gchar *extension;
- extension = latexila_utils_get_extension ("file.pdf");
- g_assert_cmpstr (extension, ==, ".pdf");
- g_free (extension);
+ extension = latexila_utils_get_extension ("file.pdf");
+ g_assert_cmpstr (extension, ==, ".pdf");
+ g_free (extension);
- extension = latexila_utils_get_extension ("file.tar.gz");
- g_assert_cmpstr (extension, ==, ".gz");
- g_free (extension);
+ extension = latexila_utils_get_extension ("file.tar.gz");
+ g_assert_cmpstr (extension, ==, ".gz");
+ g_free (extension);
- extension = latexila_utils_get_extension ("file");
- g_assert_cmpstr (extension, ==, "");
- g_free (extension);
+ extension = latexila_utils_get_extension ("file");
+ g_assert_cmpstr (extension, ==, "");
+ g_free (extension);
}
static void
test_replace_home_dir_with_tilde (void)
{
- const gchar *homedir = g_get_home_dir ();
- gchar *before;
- gchar *after;
-
- before = g_build_filename (homedir, "blah", NULL);
- after = latexila_utils_replace_home_dir_with_tilde (before);
- g_assert_cmpstr (after, ==, "~/blah");
- g_free (before);
- g_free (after);
-
- after = latexila_utils_replace_home_dir_with_tilde (homedir);
- g_assert_cmpstr (after, ==, "~");
- g_free (after);
-
- after = latexila_utils_replace_home_dir_with_tilde ("/blah");
- g_assert_cmpstr (after, ==, "/blah");
- g_free (after);
+ const gchar *homedir = g_get_home_dir ();
+ gchar *before;
+ gchar *after;
+
+ before = g_build_filename (homedir, "blah", NULL);
+ after = latexila_utils_replace_home_dir_with_tilde (before);
+ g_assert_cmpstr (after, ==, "~/blah");
+ g_free (before);
+ g_free (after);
+
+ after = latexila_utils_replace_home_dir_with_tilde (homedir);
+ g_assert_cmpstr (after, ==, "~");
+ g_free (after);
+
+ after = latexila_utils_replace_home_dir_with_tilde ("/blah");
+ g_assert_cmpstr (after, ==, "/blah");
+ g_free (after);
}
static void
test_str_replace (void)
{
- gchar *result;
+ gchar *result;
- result = latexila_utils_str_replace ("$filename", "$filename", "blah");
- g_assert_cmpstr (result, ==, "blah");
- g_free (result);
+ result = latexila_utils_str_replace ("$filename", "$filename", "blah");
+ g_assert_cmpstr (result, ==, "blah");
+ g_free (result);
- result = latexila_utils_str_replace ("$shortname.pdf", "$shortname", "blah");
- g_assert_cmpstr (result, ==, "blah.pdf");
- g_free (result);
+ result = latexila_utils_str_replace ("$shortname.pdf", "$shortname", "blah");
+ g_assert_cmpstr (result, ==, "blah.pdf");
+ g_free (result);
- result = latexila_utils_str_replace ("abcdabcd", "ab", "r");
- g_assert_cmpstr (result, ==, "rcdrcd");
- g_free (result);
+ result = latexila_utils_str_replace ("abcdabcd", "ab", "r");
+ g_assert_cmpstr (result, ==, "rcdrcd");
+ g_free (result);
- result = latexila_utils_str_replace ("abcd", "ef", "r");
- g_assert_cmpstr (result, ==, "abcd");
- g_free (result);
+ result = latexila_utils_str_replace ("abcd", "ef", "r");
+ g_assert_cmpstr (result, ==, "abcd");
+ g_free (result);
}
gint
main (gint argc,
gchar **argv)
{
- g_test_init (&argc, &argv, NULL);
+ g_test_init (&argc, &argv, NULL);
- g_test_add_func ("/utils/get-shortname", test_get_shortname);
- g_test_add_func ("/utils/get-extension", test_get_extension);
- g_test_add_func ("/utils/replace-home-dir-with-tilde", test_replace_home_dir_with_tilde);
- g_test_add_func ("/utils/str-replace", test_str_replace);
+ g_test_add_func ("/utils/get-shortname", test_get_shortname);
+ g_test_add_func ("/utils/get-extension", test_get_extension);
+ g_test_add_func ("/utils/replace-home-dir-with-tilde", test_replace_home_dir_with_tilde);
+ g_test_add_func ("/utils/str-replace", test_str_replace);
- return g_test_run ();
+ return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]