static GladeEditorProperty * append_item (GladeEditorTable *table, GladePropertyClass *klass, gboolean from_query_dialog) { GladeEditorProperty *property; GtkWidget *label; if (!(property = glade_widget_adaptor_create_eprop (glade_property_class_get_adaptor (klass), klass, from_query_dialog == FALSE))) { g_critical ("Unable to create editor for property '%s' of class '%s'", glade_property_class_id (klass), glade_widget_adaptor_get_name (glade_property_class_get_adaptor (klass))); return NULL; } gtk_widget_show (GTK_WIDGET (property)); gtk_widget_show_all (glade_editor_property_get_item_label (property)); label = glade_editor_property_get_item_label (property); gtk_widget_set_hexpand (label, FALSE); glade_editor_table_attach (table, label, 0, table->priv->rows); glade_editor_table_attach (table, GTK_WIDGET (property), 1, table->priv->rows); table->priv->rows++; return property; }
static void glade_gtk_widget_write_atk_relation (GladeProperty * property, GladeXmlContext * context, GladeXmlNode * node) { GladeXmlNode *prop_node; GladePropertyClass *pclass; gchar *value, **split; gint i; if ((value = glade_widget_adaptor_string_from_value (glade_property_class_get_adaptor (glade_property_get_class (property)), glade_property_get_class (property), glade_property_inline_value (property))) != NULL) { if ((split = g_strsplit (value, GPC_OBJECT_DELIMITER, 0)) != NULL) { for (i = 0; split[i] != NULL; i++) { pclass = glade_property_get_class (property); prop_node = glade_xml_node_new (context, GLADE_TAG_A11Y_RELATION); glade_xml_node_append_child (node, prop_node); glade_xml_node_set_property_string (prop_node, GLADE_TAG_A11Y_TYPE, glade_property_class_id (pclass)); glade_xml_node_set_property_string (prop_node, GLADE_TAG_A11Y_TARGET, split[i]); } g_strfreev (split); } } }
void glade_popup_property_pop (GladeProperty *property, GdkEventButton *event) { GladeWidgetAdaptor *adaptor, *prop_adaptor; GladePropertyClass *pclass; GParamSpec *pspec; GtkWidget *popup_menu; gint button; gint event_time; pclass = glade_property_get_class (property); pspec = glade_property_class_get_pspec (pclass); prop_adaptor = glade_property_class_get_adaptor (pclass); adaptor = glade_widget_adaptor_from_pspec (prop_adaptor, pspec); g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor)); popup_menu = gtk_menu_new (); glade_popup_append_item (popup_menu, _("Set default value"), TRUE, glade_popup_clear_property_cb, property); if (!glade_property_class_get_virtual (pclass) && glade_widget_adaptor_get_book (adaptor) && glade_util_have_devhelp ()) { glade_popup_append_item (popup_menu, _("Read _documentation"), TRUE, glade_popup_property_docs_cb, property); } if (event) { button = event->button; event_time = event->time; } else { button = 0; event_time = gtk_get_current_event_time (); } gtk_menu_popup (GTK_MENU (popup_menu), NULL, NULL, NULL, NULL, button, event_time); }
static void glade_popup_property_docs_cb (GtkMenuItem *item, GladeProperty *property) { GladeWidgetAdaptor *adaptor, *prop_adaptor; GladePropertyClass *pclass; GParamSpec *pspec; gchar *search; pclass = glade_property_get_class (property); pspec = glade_property_class_get_pspec (pclass); prop_adaptor = glade_property_class_get_adaptor (pclass); adaptor = glade_widget_adaptor_from_pspec (prop_adaptor, pspec); search = g_strdup_printf ("The \"%s\" property", glade_property_class_id (pclass)); glade_app_search_docs (glade_widget_adaptor_get_book (adaptor), g_type_name (pspec->owner_type), search); g_free (search); }
static gboolean glade_property_set_value_impl (GladeProperty * property, const GValue * value) { GladeProject *project = property->priv->widget ? glade_widget_get_project (property->priv->widget) : NULL; gboolean changed = FALSE; GValue old_value = { 0, }; gboolean warn_before, warn_after; #ifdef GLADE_ENABLE_DEBUG if (glade_get_debug_flags () & GLADE_DEBUG_PROPERTIES) { g_print ("PROPERTY: Setting %s property %s on %s ", glade_property_class_get_is_packing (property->priv->klass) ? "packing" : "normal", glade_property_class_id (property->priv->klass), property->priv->widget ? glade_widget_get_name (property->priv->widget) : "unknown"); gchar *str1 = glade_widget_adaptor_string_from_value (glade_property_class_get_adaptor (property->priv->klass), property->priv->klass, property->priv->value); gchar *str2 = glade_widget_adaptor_string_from_value (glade_property_class_get_adaptor (property->priv->klass), property->priv->klass, value); g_print ("from %s to %s\n", str1, str2); g_free (str1); g_free (str2); } #endif /* GLADE_ENABLE_DEBUG */ if (!g_value_type_compatible (G_VALUE_TYPE (property->priv->value), G_VALUE_TYPE (value))) { g_warning ("Trying to assign an incompatible value to property %s\n", glade_property_class_id (property->priv->klass)); return FALSE; } /* Check if the backend doesnt give us permission to * set this value. */ if (glade_property_superuser () == FALSE && property->priv->widget && project && glade_project_is_loading (project) == FALSE && glade_property_verify (property, value) == FALSE) { return FALSE; } /* save "changed" state. */ changed = !glade_property_equals_value (property, value); /* Add/Remove references from widget ref stacks here * (before assigning the value) */ if (property->priv->widget && changed && glade_property_class_is_object (property->priv->klass)) glade_property_update_prop_refs (property, property->priv->value, value); /* Check pre-changed warning state */ warn_before = glade_property_warn_usage (property); /* Make a copy of the old value */ g_value_init (&old_value, G_VALUE_TYPE (property->priv->value)); g_value_copy (property->priv->value, &old_value); /* Assign property first so that; if the object need be * rebuilt, it will reflect the new value */ g_value_reset (property->priv->value); g_value_copy (value, property->priv->value); GLADE_PROPERTY_GET_KLASS (property)->sync (property); glade_property_fix_state (property); if (changed && property->priv->widget) { g_signal_emit (G_OBJECT (property), glade_property_signals[VALUE_CHANGED], 0, &old_value, property->priv->value); glade_project_verify_property (property); /* Check post change warning state */ warn_after = glade_property_warn_usage (property); /* Update owning widget's warning state if need be */ if (property->priv->widget != NULL && warn_before != warn_after) glade_widget_verify (property->priv->widget); } /* Special case parentless widget properties */ if (glade_property_class_parentless_widget (property->priv->klass)) { GladeWidget *gobj; GObject *obj; if ((obj = g_value_get_object (&old_value)) && (gobj = glade_widget_get_from_gobject (obj))) glade_widget_show (gobj); if ((obj = g_value_get_object (value)) && (gobj = glade_widget_get_from_gobject (obj))) glade_widget_hide (gobj); } g_value_unset (&old_value); return TRUE; }
/** * glade_property_write: * @property: a #GladeProperty * @context: A #GladeXmlContext * @node: A #GladeXmlNode * * Write @property to @node */ void glade_property_write (GladeProperty * property, GladeXmlContext * context, GladeXmlNode * node) { GladeXmlNode *prop_node; gchar *name, *value; gboolean save_always; g_return_if_fail (GLADE_IS_PROPERTY (property)); g_return_if_fail (node != NULL); /* This code should work the same for <packing>, <widget> and <template> */ if (!(glade_xml_node_verify_silent (node, GLADE_XML_TAG_PACKING) || glade_xml_node_verify_silent (node, GLADE_XML_TAG_WIDGET) || glade_xml_node_verify_silent (node, GLADE_XML_TAG_TEMPLATE))) return; /* There can be a couple of reasons to forcefully save a property */ save_always = (glade_property_class_save_always (property->priv->klass) || property->priv->save_always); save_always = save_always || (glade_property_class_optional (property->priv->klass) && property->priv->enabled); /* Skip properties that are default by original pspec default * (excepting those that specified otherwise). */ if (!save_always && glade_property_original_default (property)) return; /* Escape our string and save with underscores */ name = g_strdup (glade_property_class_id (property->priv->klass)); glade_util_replace (name, '-', '_'); /* convert the value of this property to a string */ if (!(value = glade_widget_adaptor_string_from_value (glade_property_class_get_adaptor (property->priv->klass), property->priv->klass, property->priv->value))) /* make sure we keep the empty string, also... upcomming * funcs that may not like NULL. */ value = g_strdup (""); /* Now dump the node values... */ prop_node = glade_xml_node_new (context, GLADE_XML_TAG_PROPERTY); glade_xml_node_append_child (node, prop_node); /* Name and value */ glade_xml_node_set_property_string (prop_node, GLADE_XML_TAG_NAME, name); glade_xml_set_content (prop_node, value); /* i18n stuff */ if (glade_property_class_translatable (property->priv->klass)) { if (property->priv->i18n_translatable) glade_xml_node_set_property_string (prop_node, GLADE_TAG_TRANSLATABLE, GLADE_XML_TAG_I18N_TRUE); if (property->priv->i18n_context) glade_xml_node_set_property_string (prop_node, GLADE_TAG_CONTEXT, property->priv->i18n_context); if (property->priv->i18n_comment) glade_xml_node_set_property_string (prop_node, GLADE_TAG_COMMENT, property->priv->i18n_comment); } g_free (name); g_free (value); }
void accel_edited (GtkCellRendererAccel * accel, gchar * path_string, guint accel_key, GdkModifierType accel_mods, guint hardware_keycode, GladeEPropAccel * eprop_accel) { gboolean key_was_set; GtkTreeIter iter, parent_iter, new_iter; gchar *accel_text; GladePropertyClass *pclass; GladeWidgetAdaptor *adaptor; gboolean is_action; pclass = glade_editor_property_get_pclass (GLADE_EDITOR_PROPERTY (eprop_accel)); adaptor = glade_property_class_get_adaptor (pclass); if (!gtk_tree_model_get_iter_from_string (eprop_accel->model, &iter, path_string)) return; is_action = (glade_widget_adaptor_get_object_type (adaptor) == GTK_TYPE_ACTION || g_type_is_a (glade_widget_adaptor_get_object_type (adaptor), GTK_TYPE_ACTION)); gtk_tree_model_get (eprop_accel->model, &iter, ACCEL_COLUMN_KEY_ENTERED, &key_was_set, -1); accel_text = gtk_accelerator_name (accel_key, accel_mods); gtk_tree_store_set (GTK_TREE_STORE (eprop_accel->model), &iter, ACCEL_COLUMN_KEY_ENTERED, TRUE, ACCEL_COLUMN_STYLE, PANGO_STYLE_NORMAL, ACCEL_COLUMN_FOREGROUND, "Black", ACCEL_COLUMN_TEXT, accel_text, ACCEL_COLUMN_KEYCODE, accel_key, ACCEL_COLUMN_MODIFIERS, accel_mods, -1); g_free (accel_text); /* Append a new one if needed */ if (is_action == FALSE && key_was_set == FALSE && gtk_tree_model_iter_parent (eprop_accel->model, &parent_iter, &iter)) { gchar *signal, *real_signal; gtk_tree_model_get (eprop_accel->model, &iter, ACCEL_COLUMN_SIGNAL, &signal, ACCEL_COLUMN_REAL_SIGNAL, &real_signal, -1); /* Append a new empty slot at the end */ gtk_tree_store_insert_after (GTK_TREE_STORE (eprop_accel->model), &new_iter, &parent_iter, &iter); gtk_tree_store_set (GTK_TREE_STORE (eprop_accel->model), &new_iter, ACCEL_COLUMN_SIGNAL, signal, ACCEL_COLUMN_REAL_SIGNAL, real_signal, ACCEL_COLUMN_TEXT, _("<choose a key>"), ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL, ACCEL_COLUMN_STYLE, PANGO_STYLE_ITALIC, ACCEL_COLUMN_FOREGROUND, "Grey", ACCEL_COLUMN_VISIBLE, TRUE, ACCEL_COLUMN_KEYCODE, 0, ACCEL_COLUMN_MODIFIERS, 0, ACCEL_COLUMN_KEY_ENTERED, FALSE, -1); g_free (signal); g_free (real_signal); } }
static void glade_eprop_accel_populate_view (GladeEditorProperty * eprop, GtkTreeView * view) { GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); GladeSignalClass *sclass; GladePropertyClass *pclass = glade_editor_property_get_pclass (eprop); GladeProperty *property = glade_editor_property_get_property (eprop); GladeWidgetAdaptor *adaptor = glade_property_class_get_adaptor (pclass); GtkTreeStore *model = (GtkTreeStore *) gtk_tree_view_get_model (view); GtkTreeIter iter; GladeEpropIterTab *parent_tab; GladeAccelInfo *info; GList *l, *found, *accelerators; gchar *name, *accel_text; const GList *list; accelerators = g_value_get_boxed (glade_property_inline_value (property)); /* First make parent iters... */ for (list = glade_widget_adaptor_get_signals (adaptor); list; list = list->next) { sclass = list->data; /* Special case for GtkAction accelerators */ if (glade_widget_adaptor_get_object_type (adaptor) == GTK_TYPE_ACTION || g_type_is_a (glade_widget_adaptor_get_object_type (adaptor), GTK_TYPE_ACTION)) { if (g_strcmp0 (glade_signal_class_get_type (sclass), "GtkAction") != 0 || g_strcmp0 (glade_signal_class_get_name (sclass), "activate") != 0) continue; } /* Only action signals have accelerators. */ else if ((glade_signal_class_get_flags (sclass) & G_SIGNAL_ACTION) == 0) continue; if (g_list_find_custom (eprop_accel->parent_iters, glade_signal_class_get_type (sclass), (GCompareFunc) eprop_find_iter) == NULL) { gtk_tree_store_append (model, &iter, NULL); gtk_tree_store_set (model, &iter, ACCEL_COLUMN_SIGNAL, glade_signal_class_get_type (sclass), ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_BOLD, ACCEL_COLUMN_VISIBLE, FALSE, -1); parent_tab = g_new0 (GladeEpropIterTab, 1); parent_tab->name = glade_signal_class_get_type (sclass); parent_tab->iter = gtk_tree_iter_copy (&iter); eprop_accel->parent_iters = g_list_prepend (eprop_accel->parent_iters, parent_tab); } } /* Now we populate... */ for (list = glade_widget_adaptor_get_signals (adaptor); list; list = list->next) { sclass = list->data; /* Special case for GtkAction accelerators */ if (glade_widget_adaptor_get_object_type (adaptor) == GTK_TYPE_ACTION || g_type_is_a (glade_widget_adaptor_get_object_type (adaptor), GTK_TYPE_ACTION)) { if (g_strcmp0 (glade_signal_class_get_type (sclass), "GtkAction") != 0 || g_strcmp0 (glade_signal_class_get_name (sclass), "activate") != 0) continue; } /* Only action signals have accelerators. */ else if ((glade_signal_class_get_flags (sclass) & G_SIGNAL_ACTION) == 0) continue; if ((found = g_list_find_custom (eprop_accel->parent_iters, glade_signal_class_get_type (sclass), (GCompareFunc) eprop_find_iter)) != NULL) { parent_tab = found->data; name = g_strdup_printf (" %s", glade_signal_class_get_name (sclass)); /* Populate from accelerator list */ for (l = accelerators; l; l = l->next) { info = l->data; if (g_strcmp0 (info->signal, glade_signal_class_get_name (sclass))) continue; accel_text = gtk_accelerator_name (info->key, info->modifiers); gtk_tree_store_append (model, &iter, parent_tab->iter); gtk_tree_store_set (model, &iter, ACCEL_COLUMN_SIGNAL, name, ACCEL_COLUMN_REAL_SIGNAL, glade_signal_class_get_name (sclass), ACCEL_COLUMN_TEXT, accel_text, ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL, ACCEL_COLUMN_STYLE, PANGO_STYLE_NORMAL, ACCEL_COLUMN_FOREGROUND, "Black", ACCEL_COLUMN_VISIBLE, TRUE, ACCEL_COLUMN_KEYCODE, info->key, ACCEL_COLUMN_MODIFIERS, info->modifiers, ACCEL_COLUMN_KEY_ENTERED, TRUE, -1); g_free (accel_text); } /* Special case for GtkAction accelerators */ if ((glade_widget_adaptor_get_object_type (adaptor) == GTK_TYPE_ACTION || g_type_is_a (glade_widget_adaptor_get_object_type (adaptor), GTK_TYPE_ACTION)) && g_list_length (accelerators) > 0) continue; /* Append a new empty slot at the end */ gtk_tree_store_append (model, &iter, parent_tab->iter); gtk_tree_store_set (model, &iter, ACCEL_COLUMN_SIGNAL, name, ACCEL_COLUMN_REAL_SIGNAL, glade_signal_class_get_name (sclass), ACCEL_COLUMN_TEXT, _("<choose a key>"), ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL, ACCEL_COLUMN_STYLE, PANGO_STYLE_ITALIC, ACCEL_COLUMN_FOREGROUND, "Grey", ACCEL_COLUMN_VISIBLE, TRUE, ACCEL_COLUMN_KEYCODE, 0, ACCEL_COLUMN_MODIFIERS, 0, ACCEL_COLUMN_KEY_ENTERED, FALSE, -1); g_free (name); } } }