Пример #1
0
static void
gstyle_color_widget_actions_rename (GSimpleAction *action,
                                    GVariant      *variant,
                                    gpointer       user_data)
{
  GstyleColorWidget *self = (GstyleColorWidget *)user_data;
  GtkWidget *popover;
  GstyleColor *color;
  const gchar *name;

  g_assert (GSTYLE_IS_COLOR_WIDGET (self));
  g_assert (G_IS_SIMPLE_ACTION (action));

  color = gstyle_color_widget_get_color (self);
  name = gstyle_color_get_name (color);

  popover = g_object_new (GSTYLE_TYPE_RENAME_POPOVER,
                          "label", _("Color name"),
                          "name", name,
                          "message", _("Enter a new name for the color"),
                          NULL);

  gtk_popover_set_relative_to (GTK_POPOVER (popover), GTK_WIDGET (self));
  g_signal_connect_swapped (popover, "closed", G_CALLBACK (contextual_popover_closed_cb), self);
  g_signal_connect_swapped (popover, "renamed", G_CALLBACK (rename_popover_entry_renamed_cb), self);
  gtk_popover_popup (GTK_POPOVER (popover));
}
Пример #2
0
static gboolean
remove_color_to_names_sets (GstylePalette *self,
                            GstyleColor   *color)
{
  const gchar *name;
  GPtrArray *set;
  gboolean ret = FALSE;

  g_assert (GSTYLE_IS_PALETTE (self));
  g_assert (GSTYLE_IS_COLOR (color));

  name = gstyle_color_get_name (color);
  if (gstyle_str_empty0 (name))
    return FALSE;

  set = g_hash_table_lookup (self->color_names, name);
  if (set == NULL)
    return FALSE;

  ret = g_ptr_array_remove (set, color);
  if (set->len == 0)
    {
      g_ptr_array_unref (set);
      g_hash_table_remove (self->color_names, name);
    }

  return ret;
}
Пример #3
0
static void
update_label_visibility (GstyleColorWidget *self)
{
  const gchar *color_name;
  g_autofree gchar *fallback_name = NULL;

  g_assert (GSTYLE_IS_COLOR_WIDGET (self));

  if (self->color == NULL)
    {
      if (gtk_widget_is_visible (GTK_WIDGET (self->label)))
        gtk_widget_hide (GTK_WIDGET (self->label));

      return;
    }

  if (self->is_name_visible)
    {
      if (self->filter_func != NULL && GSTYLE_IS_COLOR (self->filtered_color))
        color_name = gstyle_color_get_name (self->filtered_color);
      else
        color_name = gstyle_color_get_name (self->color);

      if (color_name != NULL)
        {
          gtk_label_set_text (self->label, color_name);
          if (!gtk_widget_is_visible (GTK_WIDGET (self->label)))
            gtk_widget_show (GTK_WIDGET (self->label));

          return;
        }
    }

  if (self->is_fallback_name_visible)
    {
      if (self->filter_func != NULL && GSTYLE_IS_COLOR (self->filtered_color))
        fallback_name = gstyle_color_to_string (self->filtered_color, self->fallback_name_kind);
      else
        fallback_name = gstyle_color_to_string (self->color, self->fallback_name_kind);

      gtk_label_set_text (self->label, fallback_name);
      if (!gtk_widget_is_visible (GTK_WIDGET (self->label)))
        gtk_widget_show (GTK_WIDGET (self->label));
    }
  else
    gtk_widget_hide (GTK_WIDGET (self->label));
}
Пример #4
0
/* TODO: add an unnamed category ? */
static gboolean
add_color_to_names_sets (GstylePalette *self,
                         GstyleColor   *color)
{
  const gchar *name;
  GPtrArray *set;

  g_assert (GSTYLE_IS_PALETTE (self));
  g_assert (GSTYLE_IS_COLOR (color));

  name = gstyle_color_get_name (color);
  if (gstyle_str_empty0 (name))
    return FALSE;

  set = g_hash_table_lookup (self->color_names, name);
  if (set == NULL)
    {
      set = g_ptr_array_new ();
      g_hash_table_insert (self->color_names, (gpointer)name, set);
    }

  g_ptr_array_add (set, color);
  return TRUE;
}
Пример #5
0
static void
dnd_color_fill (GstyleColorWidget *self,
                GstyleColor       *src_color,
                GstyleColor       *dst_color)
{
  const gchar *name;
  GdkRGBA src_rgba;
  GdkRGBA dst_rgba;

  g_assert (GSTYLE_COLOR_WIDGET (self));
  g_assert (GSTYLE_COLOR (src_color));
  g_assert (GSTYLE_COLOR (dst_color));

  gstyle_color_fill_rgba (src_color, &src_rgba);
  gstyle_color_fill_rgba (dst_color, &dst_rgba);
  if (!(self->dnd_lock & GSTYLE_COLOR_WIDGET_DND_LOCK_FLAGS_COLOR))
    {
      dst_rgba.red = src_rgba.red;
      dst_rgba.green = src_rgba.green;
      dst_rgba.blue = src_rgba.blue;
    }

  if (!(self->dnd_lock & GSTYLE_COLOR_WIDGET_DND_LOCK_FLAGS_ALPHA))
    dst_rgba.alpha = src_rgba.alpha;

  gstyle_color_set_rgba (self->color, &dst_rgba);

  if (!(self->dnd_lock & GSTYLE_COLOR_WIDGET_DND_LOCK_FLAGS_KIND))
    gstyle_color_set_kind (dst_color, gstyle_color_get_kind (src_color));

  if (!(self->dnd_lock & GSTYLE_COLOR_WIDGET_DND_LOCK_FLAGS_NAME))
  {
    name = gstyle_color_get_name (src_color);
    gstyle_color_set_name (dst_color, name);
  }
}
Пример #6
0
/**
 * gstyle_palette_save_to_xml:
 * @self: a #GstylePalette
 * @file: a #GFile
 * @error: (nullable): a #GError location or %NULL
 *
 * Save a palette to Gnome-Builder .xml palette format.
 *
 * Returns: %TRUE if succesfull, %FALSE otherwise.
 */
gboolean
gstyle_palette_save_to_xml (GstylePalette  *self,
                            GFile          *file,
                            GError        **error)
{
  g_autofree gchar *file_path = NULL;
  const gchar *id;
  const gchar *name;
  xmlDocPtr doc;
  xmlNodePtr root_node;
  xmlNodePtr palette_node;
  xmlNodePtr color_node;
  gint n_colors;
  gint succes;

  gchar *header = "Copyright (C) 2016 GNOME Builder Team at irc.gimp.net/#gnome-builder\n" \
                  "This program is free software: you can redistribute it and/or modify\n" \
                  "it under the terms of the GNU General Public License as published by\n" \
                  "the Free Software Foundation, either version 3 of the License, or\n"    \
                  "(at your option) any later version.\n\n"                                \
                  "This program is distributed in the hope that it will be useful,\n"      \
                  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"       \
                  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"        \
                  "GNU General Public License for more details.\n\n"                       \
                  "You should have received a copy of the GNU General Public License\n"    \
                  "along with this program.  If not, see <http://www.gnu.org/licenses/>\n";

  g_return_val_if_fail (GSTYLE_IS_PALETTE (self), FALSE);
  g_return_val_if_fail (G_IS_FILE (file), FALSE);

  doc = xmlNewDoc(CHAR_TO_XML ("1.0"));
  root_node = xmlNewDocComment (doc, CHAR_TO_XML (header));
  xmlDocSetRootElement(doc, root_node);
  palette_node = xmlNewNode (NULL, CHAR_TO_XML ("palette"));
  xmlAddSibling (root_node, palette_node);

  id = gstyle_palette_get_id (self);
  name = gstyle_palette_get_name (self);
  xmlNewProp (palette_node, CHAR_TO_XML ("id"), CHAR_TO_XML (id));
  if (self->gettext_domain)
    {
      xmlNewProp (palette_node, CHAR_TO_XML ("_name"), CHAR_TO_XML (name));
      xmlNewProp (palette_node, CHAR_TO_XML ("gettext-domain"), CHAR_TO_XML (self->gettext_domain));
    }
  else
    xmlNewProp (palette_node, CHAR_TO_XML ("name"), CHAR_TO_XML (name));

  n_colors = gstyle_palette_get_len (self);
  for (gint i = 0; i < n_colors; ++i)
    {
      const GstyleColor *color;
      const gchar *color_name;
      g_autofree gchar *color_string = NULL;

      color = gstyle_palette_get_color_at_index (self, i);
      color_name = gstyle_color_get_name ((GstyleColor *)color);

      if (gstyle_color_get_kind ((GstyleColor *)color) == GSTYLE_COLOR_KIND_PREDEFINED)
        color_string = gstyle_color_to_string ((GstyleColor *)color, GSTYLE_COLOR_KIND_RGB_HEX6);
      else
        color_string = gstyle_color_to_string ((GstyleColor *)color, GSTYLE_COLOR_KIND_ORIGINAL);

      color_node = xmlNewChild (palette_node, NULL, CHAR_TO_XML ("color"), NULL);
      xmlNewProp (color_node, CHAR_TO_XML ("name"), CHAR_TO_XML (color_name));
      xmlNewProp (color_node, CHAR_TO_XML ("value"), CHAR_TO_XML (color_string));
    }

  file_path = g_file_get_path (file);
  succes = xmlSaveFormatFileEnc (file_path, doc, "UTF-8", 1);
  xmlFreeDoc(doc);

  if (succes == -1)
    {
      g_set_error (error, GSTYLE_PALETTE_ERROR, GSTYLE_PALETTE_ERROR_FILE,
                   _("Unable to save %s\n"), file_path);

      return FALSE;
    }
  else
    {
      gstyle_palette_set_changed (self, FALSE);
      return TRUE;
    }
}