[latexila/wip/build-tools-revamp] LatexilaBuildView (not finished)



commit be644c2ecff1b282c77a111433968e26fed70a0b
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon May 5 22:07:01 2014 +0200

    LatexilaBuildView (not finished)

 src/liblatexila/Makefile.am           |    2 +
 src/liblatexila/latexila-build-view.c |  350 +++++++++++++++++++++++++++++++++
 src/liblatexila/latexila-build-view.h |  122 ++++++++++++
 src/liblatexila/latexila-types.h      |    1 +
 4 files changed, 475 insertions(+), 0 deletions(-)
---
diff --git a/src/liblatexila/Makefile.am b/src/liblatexila/Makefile.am
index 4c17717..ec261c1 100644
--- a/src/liblatexila/Makefile.am
+++ b/src/liblatexila/Makefile.am
@@ -11,6 +11,7 @@ liblatexila_headers =                         \
        latexila-build-tools.h                  \
        latexila-build-tools-default.h          \
        latexila-build-tools-personal.h         \
+       latexila-build-view.h                   \
        latexila-post-processor.h               \
        latexila-post-processor-all-output.h    \
        latexila-types.h
@@ -25,6 +26,7 @@ liblatexila_la_SOURCES =                      \
        latexila-build-tools.c                  \
        latexila-build-tools-default.c          \
        latexila-build-tools-personal.c         \
+       latexila-build-view.c                   \
        latexila-post-processor.c               \
        latexila-post-processor-all-output.c    \
        $(liblatexila_headers)                  \
diff --git a/src/liblatexila/latexila-build-view.c b/src/liblatexila/latexila-build-view.c
new file mode 100644
index 0000000..bcf52cb
--- /dev/null
+++ b/src/liblatexila/latexila-build-view.c
@@ -0,0 +1,350 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * LaTeXila is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "latexila-build-view.h"
+#include "latexila-enum-types.h"
+
+struct _LatexilaBuildViewPrivate
+{
+  GtkTreeStore *store;
+  GtkTreeModelFilter *filtered_model;
+
+  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
+};
+
+/* 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
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildView, latexila_build_view, GTK_TYPE_TREE_VIEW)
+
+/**
+ * latexila_build_msg_new: (skip)
+ *
+ * Free the return value with latexila_build_msg_free() when no longer needed.
+ *
+ * Returns: a newly-allocated #LatexilaBuildMsg.
+ */
+LatexilaBuildMsg *
+latexila_build_msg_new (void)
+{
+  LatexilaBuildMsg *build_msg = g_slice_new0 (LatexilaBuildMsg);
+
+  build_msg->start_line = -1;
+  build_msg->end_line = -1;
+  build_msg->expand = TRUE;
+
+  return build_msg;
+}
+
+/**
+ * latexila_build_msg_free: (skip)
+ * @build_msg: a #LatexilaBuildMsg.
+ *
+ * Frees the @build_msg structure.
+ */
+void
+latexila_build_msg_free (LatexilaBuildMsg *build_msg)
+{
+  if (build_msg != NULL)
+    {
+      g_free (build_msg->text);
+      g_free (build_msg->filename);
+      g_slice_free (LatexilaBuildMsg, build_msg);
+    }
+}
+
+static void
+latexila_build_view_get_property (GObject    *object,
+                                  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;
+    }
+}
+
+static void
+latexila_build_view_set_property (GObject      *object,
+                                  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;
+    }
+}
+
+static void
+latexila_build_view_dispose (GObject *object)
+{
+  LatexilaBuildView *build_view = LATEXILA_BUILD_VIEW (object);
+
+  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);
+}
+
+#if 0
+static void
+latexila_build_view_finalize (GObject *object)
+{
+
+  G_OBJECT_CLASS (latexila_build_view_parent_class)->finalize (object);
+}
+#endif
+
+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;
+  /*object_class->finalize = latexila_build_view_finalize;*/
+
+  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));
+}
+
+static gboolean
+visible_func (GtkTreeModel *model,
+              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;
+
+    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,
+                                                GDK_TYPE_PIXBUF,  /* icon */
+                                                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);
+}
+
+static void
+init_tree_view (LatexilaBuildView *build_view)
+{
+  GtkTreeView *tree_view = GTK_TREE_VIEW (build_view);
+  GtkTreeViewColumn *column;
+  GtkCellRenderer *renderer;
+
+  gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (build_view->priv->store));
+  gtk_tree_view_set_headers_visible (tree_view, FALSE);
+
+  /* Columns, cell renderers */
+
+  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, "pixbuf", COLUMN_ICON);
+
+  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_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_LINE_STR,
+                                               NULL);
+
+  gtk_tree_view_set_tooltip_column (tree_view, COLUMN_PATH);
+
+  /* Selection */
+  /* TODO */
+
+  /* Double-click */
+  /* TODO */
+}
+
+static void
+latexila_build_view_init (LatexilaBuildView *build_view)
+{
+  build_view->priv = latexila_build_view_get_instance_private (build_view);
+
+  init_tree_models (build_view);
+  init_tree_view (build_view);
+}
diff --git a/src/liblatexila/latexila-build-view.h b/src/liblatexila/latexila-build-view.h
new file mode 100644
index 0000000..c8c6ffa
--- /dev/null
+++ b/src/liblatexila/latexila-build-view.h
@@ -0,0 +1,122 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * LaTeXila is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LATEXILA_BUILD_VIEW_H__
+#define __LATEXILA_BUILD_VIEW_H__
+
+#include <gtk/gtk.h>
+#include "latexila-types.h"
+
+G_BEGIN_DECLS
+
+#define LATEXILA_TYPE_BUILD_VIEW             (latexila_build_view_get_type ())
+#define LATEXILA_BUILD_VIEW(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), LATEXILA_TYPE_BUILD_VIEW, 
LatexilaBuildView))
+#define LATEXILA_BUILD_VIEW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), LATEXILA_TYPE_BUILD_VIEW, 
LatexilaBuildViewClass))
+#define LATEXILA_IS_BUILD_VIEW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LATEXILA_TYPE_BUILD_VIEW))
+#define LATEXILA_IS_BUILD_VIEW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), LATEXILA_TYPE_BUILD_VIEW))
+#define LATEXILA_BUILD_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), LATEXILA_TYPE_BUILD_VIEW, 
LatexilaBuildViewClass))
+
+typedef struct _LatexilaBuildMsg         LatexilaBuildMsg;
+typedef struct _LatexilaBuildViewClass   LatexilaBuildViewClass;
+typedef struct _LatexilaBuildViewPrivate LatexilaBuildViewPrivate;
+
+/**
+ * LatexilaBuildState:
+ * @LATEXILA_BUILD_STATE_RUNNING: running.
+ * @LATEXILA_BUILD_STATE_SUCCEEDED: succeeded.
+ * @LATEXILA_BUILD_STATE_FAILED: failed.
+ * @LATEXILA_BUILD_STATE_ABORTED: aborted.
+ */
+typedef enum
+{
+  LATEXILA_BUILD_STATE_RUNNING,
+  LATEXILA_BUILD_STATE_SUCCEEDED,
+  LATEXILA_BUILD_STATE_FAILED,
+  LATEXILA_BUILD_STATE_ABORTED
+} LatexilaBuildState;
+
+/**
+ * LatexilaBuildMsgType:
+ * @LATEXILA_BUILD_MSG_TYPE_MAIN_TITLE: main title.
+ * @LATEXILA_BUILD_MSG_TYPE_JOB_TITLE: build job title.
+ * @LATEXILA_BUILD_MSG_TYPE_JOB_SUB_COMMAND: build job sub-command.
+ * @LATEXILA_BUILD_MSG_TYPE_ERROR: error.
+ * @LATEXILA_BUILD_MSG_TYPE_WARNING: warning.
+ * @LATEXILA_BUILD_MSG_TYPE_BADBOX: badbox.
+ * @LATEXILA_BUILD_MSG_TYPE_INFO: other info.
+ */
+typedef enum
+{
+  LATEXILA_BUILD_MSG_TYPE_MAIN_TITLE,
+  LATEXILA_BUILD_MSG_TYPE_JOB_TITLE,
+  LATEXILA_BUILD_MSG_TYPE_JOB_SUB_COMMAND,
+  LATEXILA_BUILD_MSG_TYPE_ERROR,
+  LATEXILA_BUILD_MSG_TYPE_WARNING,
+  LATEXILA_BUILD_MSG_TYPE_BADBOX,
+  LATEXILA_BUILD_MSG_TYPE_INFO
+} LatexilaBuildMsgType;
+
+/**
+ * LatexilaBuildMsg:
+ * @type: the message type.
+ * @text: the text.
+ * @filename: reference to a certain file.
+ * @start_line: reference to a line in the file. -1 to unset.
+ * @end_line: reference to a line in the file. -1 to unset.
+ * @expand: if the message has children, whether to show them by default.
+ *
+ * A build message, one line in the #GtkTreeView. If a @filename is provided,
+ * the file will be opened when the user clicks on the message. If @start_line
+ * and @end_line are provided, the lines between the two positions will be
+ * selected (or just @start_line will be selected if @end_line is -1).
+ *
+ * The @expand field assumes that a #LatexilaBuildMsg is included in a #GNode or
+ * similar N-ary tree structure.
+ */
+struct _LatexilaBuildMsg
+{
+  LatexilaBuildMsgType type;
+  gchar *text;
+  gchar *filename;
+  gint start_line;
+  gint end_line;
+  guint expand : 1;
+};
+
+struct _LatexilaBuildView
+{
+  GtkTreeView parent;
+
+  LatexilaBuildViewPrivate *priv;
+};
+
+struct _LatexilaBuildViewClass
+{
+  GtkTreeViewClass parent_class;
+};
+
+GType                 latexila_build_view_get_type                  (void) G_GNUC_CONST;
+
+LatexilaBuildMsg *    latexila_build_msg_new                        (void);
+
+void                  latexila_build_msg_free                       (LatexilaBuildMsg *build_msg);
+
+G_END_DECLS
+
+#endif /* __LATEXILA_BUILD_VIEW_H__ */
diff --git a/src/liblatexila/latexila-types.h b/src/liblatexila/latexila-types.h
index dce5031..9ca5d99 100644
--- a/src/liblatexila/latexila-types.h
+++ b/src/liblatexila/latexila-types.h
@@ -29,6 +29,7 @@ typedef struct _LatexilaBuildTool               LatexilaBuildTool;
 typedef struct _LatexilaBuildTools              LatexilaBuildTools;
 typedef struct _LatexilaBuildToolsDefault       LatexilaBuildToolsDefault;
 typedef struct _LatexilaBuildToolsPersonal      LatexilaBuildToolsPersonal;
+typedef struct _LatexilaBuildView               LatexilaBuildView;
 typedef struct _LatexilaPostProcessor           LatexilaPostProcessor;
 typedef struct _LatexilaPostProcessorAllOutput  LatexilaPostProcessorAllOutput;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]