output-item: Make command name part of every output_item.
[pspp] / src / output / chart-item.c
index f4b19a2f275c897abc36919c68cc3be725a77143..cedfa37a60c6cb78c0a9d2f4a165def011606fc0 100644 (file)
 
 #include "libpspp/cast.h"
 #include "libpspp/compiler.h"
+#include "libpspp/str.h"
 #include "output/driver.h"
 #include "output/output-item-provider.h"
 
 #include "gl/xalloc.h"
 
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
 /* Initializes ITEM as a chart item of the specified CLASS.  The new chart item
    initially has the specified TITLE, which may be NULL if no title is yet
    available.  The caller retains ownership of TITLE.
@@ -40,9 +44,11 @@ void
 chart_item_init (struct chart_item *item, const struct chart_item_class *class,
                  const char *title)
 {
-  output_item_init (&item->output_item, &chart_item_class);
-  item->class = class;
-  item->title = title != NULL ? xstrdup (title) : NULL;
+  *item = (struct chart_item) {
+    .output_item = OUTPUT_ITEM_INITIALIZER (&chart_item_class),
+    .class = class,
+    .title = xstrdup_if_nonnull (title)
+  };
 }
 
 /* Returns ITEM's title, which is a null pointer if no title has been set. */
@@ -62,7 +68,7 @@ chart_item_set_title (struct chart_item *item, const char *title)
 {
   assert (!chart_item_is_shared (item));
   free (item->title);
-  item->title = title != NULL ? xstrdup (title) : NULL;
+  item->title = xstrdup_if_nonnull (title);
 }
 
 /* Submits ITEM to the configured output drivers, and transfers ownership to
@@ -73,6 +79,13 @@ chart_item_submit (struct chart_item *item)
   output_submit (&item->output_item);
 }
 \f
+static const char *
+chart_item_get_label (const struct output_item *output_item)
+{
+  const struct chart_item *item = to_chart_item (output_item);
+  return item->title ? item->title : _("Chart");
+}
+
 static void
 chart_item_destroy (struct output_item *output_item)
 {
@@ -84,6 +97,6 @@ chart_item_destroy (struct output_item *output_item)
 
 const struct output_item_class chart_item_class =
   {
-    "chart",
+    chart_item_get_label,
     chart_item_destroy,
   };