static void label_widget_toggled (GtkWidget *widget, GladeToolItemGroupEditor *group_editor) { GladeProperty *property; GladeWidget *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (group_editor)); if (glade_editable_loading (GLADE_EDITABLE (group_editor)) || !gwidget) return; if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (group_editor->label_widget_radio))) return; glade_editable_block (GLADE_EDITABLE (group_editor)); glade_command_push_group (_("Setting %s to use a custom label widget"), glade_widget_get_name (gwidget)); property = glade_widget_get_property (gwidget, "label"); glade_command_set_property (property, NULL); property = glade_widget_get_property (gwidget, "custom-label"); glade_command_set_property (property, TRUE); glade_command_pop_group (); glade_editable_unblock (GLADE_EDITABLE (group_editor)); /* reload buttons and sensitivity and stuff... */ glade_editable_load (GLADE_EDITABLE (group_editor), gwidget); }
static void icon_file_toggled (GtkWidget *widget, GladeWindowEditor *window_editor) { GladeWindowEditorPrivate *priv = window_editor->priv; GladeWidget *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (window_editor)); GladeProperty *property; if (glade_editable_loading (GLADE_EDITABLE (window_editor)) || !gwidget) return; if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->icon_file_radio))) return; glade_editable_block (GLADE_EDITABLE (window_editor)); glade_command_push_group (_("Setting %s to use an icon file"), glade_widget_get_name (gwidget)); property = glade_widget_get_property (gwidget, "icon-name"); glade_command_set_property (property, NULL); property = glade_widget_get_property (gwidget, "icon"); glade_command_set_property (property, NULL); property = glade_widget_get_property (gwidget, "glade-window-icon-name"); glade_command_set_property (property, FALSE); glade_command_pop_group (); glade_editable_unblock (GLADE_EDITABLE (window_editor)); /* reload buttons and sensitivity and stuff... */ glade_editable_load (GLADE_EDITABLE (window_editor), gwidget); }
/* ----------------------------- GtkColorButton ------------------------------ */ static void glade_gtk_color_button_refresh_color (GtkColorButton * button, GladeWidget * gbutton) { GladeProperty *property; GdkRGBA rgba = { 0, }; gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), &rgba); if ((property = glade_widget_get_property (gbutton, "color")) != NULL) { if (glade_property_get_enabled (property)) { GdkColor color = { 0, }; color.red = (gint16) (rgba.red * 65535); color.green = (gint16) (rgba.green * 65535); color.blue = (gint16) (rgba.blue * 65535); glade_command_set_property (property, &color); } } if ((property = glade_widget_get_property (gbutton, "rgba")) != NULL) { if (glade_property_get_enabled (property)) glade_command_set_property (property, &rgba); } }
static void glade_gtk_widget_add2group_cb (GtkMenuItem * item, GladeWidget * gwidget) { GladeWidget *group = g_object_get_data (G_OBJECT (item), "glade-group-widget"); GladeWidgetAdaptor *adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_SIZE_GROUP); GList *widget_list = NULL, *new_list; GladeProperty *property; if (group) glade_command_push_group (_("Adding %s to Size Group %s"), glade_widget_get_name (gwidget), glade_widget_get_name (group)); else glade_command_push_group (_("Adding %s to a new Size Group"), glade_widget_get_name (gwidget)); if (!group) /* Cant cancel a size group */ group = glade_command_create (adaptor, NULL, NULL, glade_widget_get_project (gwidget)); property = glade_widget_get_property (group, "widgets"); glade_property_get (property, &widget_list); new_list = g_list_copy (widget_list); if (!g_list_find (widget_list, glade_widget_get_object (gwidget))) new_list = g_list_append (new_list, glade_widget_get_object (gwidget)); glade_command_set_property (property, new_list); g_list_free (new_list); glade_command_pop_group (); }
static void markup_toggled (GtkWidget *widget, GladeWidgetEditor *widget_editor) { GladeProperty *property; GladeWidget *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (widget_editor)); gboolean active; if (glade_editable_loading (GLADE_EDITABLE (widget_editor)) || !gwidget) return; active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); glade_editable_block (GLADE_EDITABLE (widget_editor)); if (active) { glade_command_push_group (_("Setting %s to use tooltip markup"), glade_widget_get_name (gwidget)); transfer_text_property (gwidget, "tooltip-text", "tooltip-markup"); property = glade_widget_get_property (gwidget, "glade-tooltip-markup"); glade_command_set_property (property, TRUE); glade_command_pop_group (); } else { glade_command_push_group (_("Setting %s to not use tooltip markup"), glade_widget_get_name (gwidget)); transfer_text_property (gwidget, "tooltip-markup", "tooltip-text"); property = glade_widget_get_property (gwidget, "glade-tooltip-markup"); glade_command_set_property (property, FALSE); glade_command_pop_group (); } glade_editable_unblock (GLADE_EDITABLE (widget_editor)); /* reload widgets and sensitivity and stuff... */ glade_editable_load (GLADE_EDITABLE (widget_editor), gwidget); }
static void glade_gtk_widget_add2group_cb (GtkMenuItem * item, GladeWidget * gwidget) { GladeWidget *group = g_object_get_data (G_OBJECT (item), "glade-group-widget"); GladeWidgetAdaptor *adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_SIZE_GROUP); GList *widget_list = NULL, *new_list; GladeProperty *property; const gchar *current_name; const gchar *size_group_name = NULL; gchar *widget_name; /* Display "(unnamed)" for unnamed size groups */ if (group) { size_group_name = glade_widget_get_name (group); if (g_str_has_prefix (size_group_name, GLADE_UNNAMED_PREFIX)) size_group_name = _("(unnamed)"); } /* Ensure the widget has a name if it's going to be referred to by a size group */ current_name = glade_widget_get_name (gwidget); if (g_str_has_prefix (current_name, GLADE_UNNAMED_PREFIX)) widget_name = glade_project_new_widget_name (glade_widget_get_project (gwidget), NULL, glade_widget_adaptor_get_generic_name (glade_widget_get_adaptor (gwidget))); else widget_name = g_strdup (current_name); if (group) glade_command_push_group (_("Adding %s to Size Group %s"), widget_name, size_group_name); else glade_command_push_group (_("Adding %s to a new Size Group"), widget_name); glade_command_set_name (gwidget, widget_name); if (!group) /* Cant cancel a size group */ group = glade_command_create (adaptor, NULL, NULL, glade_widget_get_project (gwidget)); property = glade_widget_get_property (group, "widgets"); glade_property_get (property, &widget_list); new_list = g_list_copy (widget_list); if (!g_list_find (widget_list, glade_widget_get_object (gwidget))) new_list = g_list_append (new_list, glade_widget_get_object (gwidget)); glade_command_set_property (property, new_list); g_list_free (new_list); g_free (widget_name); glade_command_pop_group (); }
/* Use the font-buttons launch dialog to actually set the font-name * glade property through the glade-command api. */ static void glade_gtk_font_button_refresh_font_name (GtkFontButton * button, GladeWidget * gbutton) { GladeProperty *property; if ((property = glade_widget_get_property (gbutton, "font-name")) != NULL) glade_command_set_property (property, gtk_font_button_get_font_name (button)); }
static void use_center_child_toggled (GtkWidget * widget, GladeActionBarEditor * box_editor) { GladeActionBarEditorPrivate *priv = box_editor->priv; GladeWidget *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (box_editor)); GladeWidget *gcenter = NULL; GtkWidget *box; GtkWidget *center; GladeProperty *property; gboolean use_center_child; if (glade_editable_loading (GLADE_EDITABLE (box_editor)) || !gwidget) return; /* Get new desired property state */ use_center_child = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->use_center_child)); /* Get any existing center child */ box = (GtkWidget *)glade_widget_get_object (gwidget); center = gtk_action_bar_get_center_widget (GTK_ACTION_BAR (box)); if (center && !GLADE_IS_PLACEHOLDER (center)) gcenter = glade_widget_get_from_gobject (center); glade_editable_block (GLADE_EDITABLE (box_editor)); if (use_center_child) glade_command_push_group (_("Setting %s to use a center child"), glade_widget_get_name (gwidget)); else glade_command_push_group (_("Setting %s to not use a center child"), glade_widget_get_name (gwidget)); /* If a project widget exists when were disabling center child, it needs * to be removed first as a part of the issuing GladeCommand group */ if (gcenter) { GList list; list.prev = list.next = NULL; list.data = gcenter; glade_command_delete (&list); } property = glade_widget_get_property (gwidget, "use-center-child"); glade_command_set_property (property, use_center_child); glade_command_pop_group (); glade_editable_unblock (GLADE_EDITABLE (box_editor)); /* reload buttons and sensitivity and stuff... */ glade_editable_load (GLADE_EDITABLE (box_editor), gwidget); }
static void transfer_text_property (GladeWidget *gwidget, const gchar *from, const gchar *to) { gchar *value = NULL; gchar *comment = NULL, *context = NULL; gboolean translatable = FALSE; GladeProperty *prop_from; GladeProperty *prop_to; prop_from = glade_widget_get_property (gwidget, from); prop_to = glade_widget_get_property (gwidget, to); g_assert (prop_from); g_assert (prop_to); glade_property_get (prop_from, &value); comment = (gchar *)glade_property_i18n_get_comment (prop_from); context = (gchar *)glade_property_i18n_get_context (prop_from); translatable = glade_property_i18n_get_translatable (prop_from); /* Get our own copies */ value = g_strdup (value); context = g_strdup (context); comment = g_strdup (comment); /* Set target values */ glade_command_set_property (prop_to, value); glade_command_set_i18n (prop_to, translatable, context, comment); /* Clear source values */ glade_command_set_property (prop_from, NULL); glade_command_set_i18n (prop_from, TRUE, NULL, NULL); g_free (value); g_free (comment); g_free (context); }
void glade_gtk_header_bar_child_action_activate (GladeWidgetAdaptor * adaptor, GObject * container, GObject * object, const gchar * action_path) { if (strcmp (action_path, "remove_slot") == 0) { GladeWidget *parent; GladeProperty *property; parent = glade_widget_get_from_gobject (container); glade_command_push_group (_("Remove placeholder from %s"), glade_widget_get_name (parent)); if (g_object_get_data (object, "special-child-type")) { property = glade_widget_get_property (parent, "use-custom-title"); glade_command_set_property (property, FALSE); } else { gint size; gtk_container_remove (GTK_CONTAINER (container), GTK_WIDGET (object)); property = glade_widget_get_property (parent, "size"); glade_property_get (property, &size); glade_command_set_property (property, size - 1); } glade_command_pop_group (); } else GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_action_activate (adaptor, container, object, action_path); }
static void glade_gtk_entry_changed (GtkEditable * editable, GladeWidget * gentry) { const gchar *text, *text_prop; GladeProperty *prop; gboolean use_buffer; if (glade_widget_superuser ()) return; text = gtk_entry_get_text (GTK_ENTRY (editable)); glade_widget_property_get (gentry, "text", &text_prop); glade_widget_property_get (gentry, "use-entry-buffer", &use_buffer); if (use_buffer == FALSE && g_strcmp0 (text, text_prop)) { if ((prop = glade_widget_get_property (gentry, "text"))) glade_command_set_property (prop, text); } }
void glade_gtk_header_bar_action_activate (GladeWidgetAdaptor *adaptor, GObject * object, const gchar *action_path) { if (!strcmp (action_path, "add_slot")) { GladeWidget *parent; GladeProperty *property; gint size; parent = glade_widget_get_from_gobject (object); glade_command_push_group (_("Insert placeholder to %s"), glade_widget_get_name (parent)); property = glade_widget_get_property (parent, "size"); glade_property_get (property, &size); glade_command_set_property (property, size + 1); glade_command_pop_group (); } else GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor, object, action_path); }
static void glade_gtk_grid_child_insert_remove_action (GladeWidgetAdaptor *adaptor, GObject *container, GObject *object, GroupAction group_action, const gchar *n_row_col, const gchar *attach1, /* should be smaller (top/left) attachment */ const gchar *attach2, /* should be larger (bot/right) attachment */ gboolean remove, gboolean after) { GladeWidget *parent; GList *children, *l; gint child_pos, size, offset; gtk_container_child_get (GTK_CONTAINER (container), GTK_WIDGET (object), attach1, &child_pos, NULL); parent = glade_widget_get_from_gobject (container); switch (group_action) { case GROUP_ACTION_INSERT_ROW: glade_command_push_group (_("Insert Row on %s"), glade_widget_get_name (parent)); break; case GROUP_ACTION_INSERT_COLUMN: glade_command_push_group (_("Insert Column on %s"), glade_widget_get_name (parent)); break; case GROUP_ACTION_REMOVE_COLUMN: glade_command_push_group (_("Remove Column on %s"), glade_widget_get_name (parent)); break; case GROUP_ACTION_REMOVE_ROW: glade_command_push_group (_("Remove Row on %s"), glade_widget_get_name (parent)); break; default: g_assert_not_reached (); } children = glade_widget_adaptor_get_children (adaptor, container); /* Make sure widgets does not get destroyed */ g_list_foreach (children, (GFunc) g_object_ref, NULL); glade_widget_property_get (parent, n_row_col, &size); if (remove) { GList *del = NULL; /* Remove children first */ for (l = children; l; l = g_list_next (l)) { GladeWidget *gchild = glade_widget_get_from_gobject (l->data); gint pos1, pos2; /* Skip placeholders */ if (gchild == NULL) continue; glade_widget_pack_property_get (gchild, attach1, &pos1); glade_widget_pack_property_get (gchild, attach2, &pos2); pos2 += pos1; if ((pos1 + 1 == pos2) && ((after ? pos2 : pos1) == child_pos)) { del = g_list_prepend (del, gchild); } } if (del) { glade_command_delete (del); g_list_free (del); } offset = -1; } else { /* Expand the grid */ glade_command_set_property (glade_widget_get_property (parent, n_row_col), size + 1); offset = 1; } /* Reorder children */ for (l = children; l; l = g_list_next (l)) { GladeWidget *gchild = glade_widget_get_from_gobject (l->data); gint pos; /* Skip placeholders */ if (gchild == NULL) continue; /* if removing, do top/left before bot/right */ if (remove) { /* adjust top-left attachment */ glade_widget_pack_property_get (gchild, attach1, &pos); if (pos > child_pos || (after && pos == child_pos)) { glade_command_set_property (glade_widget_get_pack_property (gchild, attach1), pos + offset); } } /* if inserting, do bot/right before top/left */ else { /* adjust top-left attachment */ glade_widget_pack_property_get (gchild, attach1, &pos); if ((after && pos > child_pos) || (!after && pos >= child_pos)) { glade_command_set_property (glade_widget_get_pack_property (gchild, attach1), pos + offset); } } } if (remove) { /* Shrink the grid */ glade_command_set_property (glade_widget_get_property (parent, n_row_col), size - 1); } g_list_foreach (children, (GFunc) g_object_unref, NULL); g_list_free (children); glade_command_pop_group (); }
static void use_csd_toggled (GtkWidget *widget, GladeWindowEditor *window_editor) { GladeWindowEditorPrivate *priv = window_editor->priv; GladeWidget *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (window_editor)); GladeWidget *gtitlebar = NULL; GtkWidget *window; GtkWidget *titlebar; GladeProperty *property; gboolean use_csd; if (glade_editable_loading (GLADE_EDITABLE (window_editor)) || !gwidget) return; /* Get new desired property state */ use_csd = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->use_csd_check)); /* Get any existing titlebar widget */ window = (GtkWidget *)glade_widget_get_object (gwidget); titlebar = gtk_window_get_titlebar (GTK_WINDOW (window)); if (titlebar && !GLADE_IS_PLACEHOLDER (titlebar)) gtitlebar = glade_widget_get_from_gobject (titlebar); glade_editable_block (GLADE_EDITABLE (window_editor)); if (use_csd) glade_command_push_group (_("Setting %s to use a custom titlebar"), glade_widget_get_name (gwidget)); else glade_command_push_group (_("Setting %s to use a system provided titlebar"), glade_widget_get_name (gwidget)); /* If a project widget exists when were disabling CSD, it needs * to be removed first as a part of the issuing GladeCommand group */ if (gtitlebar) { GList list; list.prev = list.next = NULL; list.data = gtitlebar; glade_command_delete (&list); } property = glade_widget_get_property (gwidget, "use-csd"); glade_command_set_property (property, use_csd); if (use_csd) { property = glade_widget_get_property (gwidget, "title"); glade_command_set_property (property, NULL); property = glade_widget_get_property (gwidget, "decorated"); glade_command_set_property (property, TRUE); property = glade_widget_get_property (gwidget, "hide-titlebar-when-maximized"); glade_command_set_property (property, FALSE); } glade_command_pop_group (); glade_editable_unblock (GLADE_EDITABLE (window_editor)); /* reload buttons and sensitivity and stuff... */ glade_editable_load (GLADE_EDITABLE (window_editor), gwidget); }
void glade_gtk_widget_action_activate (GladeWidgetAdaptor * adaptor, GObject * object, const gchar * action_path) { GladeWidget *gwidget = glade_widget_get_from_gobject (object), *gparent; GList this_widget = { 0, }, that_widget = { 0,}; GladeProject *project; gparent = glade_widget_get_parent (gwidget); project = glade_widget_get_project (gwidget); if (strcmp (action_path, "preview") == 0) { glade_project_preview (project, glade_widget_get_from_gobject ((gpointer) object)); } else if (strcmp (action_path, "edit_separate") == 0) { GtkWidget *dialog = glade_editor_dialog_for_widget (gwidget); gtk_widget_show_all (dialog); } else if (strcmp (action_path, "remove_parent") == 0) { GladeWidget *new_gparent; GladeProperty *property; g_return_if_fail (gparent); property = glade_widget_get_parentless_widget_ref (gparent); new_gparent = glade_widget_get_parent (gparent); glade_command_push_group (_("Removing parent of %s"), glade_widget_get_name (gwidget)); /* Remove "this" widget, If the parent we're removing is a parentless * widget reference, the reference will be implicitly broken by the 'cut' command */ this_widget.data = gwidget; glade_command_delete (&this_widget); /* Delete the parent */ that_widget.data = gparent; glade_command_delete (&that_widget); /* Add "this" widget to the new parent, if there is no new parent this will re-add * the widget to the project at the toplevel without a parent */ glade_command_add (&this_widget, new_gparent, NULL, project, FALSE); /* If the parent had a parentless widget reference, undoably add the child * as the new parentless widget reference here */ if (property) glade_command_set_property (property, glade_widget_get_object (gwidget)); glade_command_pop_group (); } else if (strncmp (action_path, "add_parent/", 11) == 0) { const gchar *action = action_path + 11; GType new_type = 0; if (strcmp (action, "alignment") == 0) new_type = GTK_TYPE_ALIGNMENT; else if (strcmp (action, "viewport") == 0) new_type = GTK_TYPE_VIEWPORT; else if (strcmp (action, "eventbox") == 0) new_type = GTK_TYPE_EVENT_BOX; else if (strcmp (action, "frame") == 0) new_type = GTK_TYPE_FRAME; else if (strcmp (action, "aspect_frame") == 0) new_type = GTK_TYPE_ASPECT_FRAME; else if (strcmp (action, "scrolled_window") == 0) new_type = GTK_TYPE_SCROLLED_WINDOW; else if (strcmp (action, "expander") == 0) new_type = GTK_TYPE_EXPANDER; else if (strcmp (action, "grid") == 0) new_type = GTK_TYPE_GRID; else if (strcmp (action, "box") == 0) new_type = GTK_TYPE_BOX; else if (strcmp (action, "paned") == 0) new_type = GTK_TYPE_PANED; else if (strcmp (action, "stack") == 0) new_type = GTK_TYPE_STACK; if (new_type) { GladeWidgetAdaptor *adaptor = glade_widget_adaptor_get_by_type (new_type); GList *saved_props, *prop_cmds; GladeWidget *gnew_parent; GladeProperty *property; glade_command_push_group (_("Adding parent %s for %s"), glade_widget_adaptor_get_title (adaptor), glade_widget_get_name (gwidget)); /* Record packing properties */ saved_props = glade_widget_dup_properties (gwidget, glade_widget_get_packing_properties (gwidget), FALSE, FALSE, FALSE); property = glade_widget_get_parentless_widget_ref (gwidget); /* Remove "this" widget, If the parent we're removing is a parentless * widget reference, the reference will be implicitly broken by the 'cut' command */ this_widget.data = gwidget; glade_command_delete (&this_widget); /* Create new widget and put it where the placeholder was */ if ((gnew_parent = glade_command_create (adaptor, gparent, NULL, project)) != NULL) { /* Now we created the new parent, if gwidget had a parentless widget reference... * set that reference to the new parent instead */ if (property) glade_command_set_property (property, glade_widget_get_object (gnew_parent)); /* Remove the alignment that we added in the frame's post_create... */ if (new_type == GTK_TYPE_FRAME) { GObject *frame = glade_widget_get_object (gnew_parent); GladeWidget *galign = glade_widget_get_from_gobject (gtk_bin_get_child (GTK_BIN (frame))); GList to_delete = { 0, }; to_delete.data = galign; glade_command_delete (&to_delete); } /* Create heavy-duty glade-command properties stuff */ prop_cmds = create_command_property_list (gnew_parent, saved_props); /* Apply the properties in an undoable way */ if (prop_cmds) glade_command_set_properties_list (glade_widget_get_project (gparent), prop_cmds); /* Add "this" widget to the new parent */ glade_command_add (&this_widget, gnew_parent, NULL, project, FALSE); glade_command_pop_group (); } else { glade_command_pop_group (); /* Undo delete command * FIXME: this will leave the "Adding parent..." comand in the * redo list, which I think its better than leaving it in the * undo list by using glade_command_add() to add the widget back * to the original parent. * Ideally we need a way to remove a redo item from the project or * simply do not let the user cancel a widget creation! */ glade_project_undo (project); } g_list_foreach (saved_props, (GFunc) g_object_unref, NULL); g_list_free (saved_props); } } else if (strcmp (action_path, "sizegroup_add") == 0) { /* Ignore dummy */ } else if (strcmp (action_path, "clear_properties") == 0) { glade_editor_reset_dialog_run (gtk_widget_get_toplevel (GTK_WIDGET (object)), gwidget); } else if (strcmp (action_path, "read_documentation") == 0) { glade_app_search_docs (glade_widget_adaptor_get_book (adaptor), glade_widget_adaptor_get_name (adaptor), NULL); } else GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor, object, action_path); }