static void glade_gtk_listbox_child_insert_action (GladeWidgetAdaptor *adaptor, GObject *container, GObject *object, const gchar *group_format, gboolean after) { GladeWidget *parent; GladeWidget *gchild; gint position; parent = glade_widget_get_from_gobject (container); glade_command_push_group (group_format, glade_widget_get_name (parent)); position = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (object)); if (after) position++; gchild = glade_command_create (glade_widget_adaptor_get_by_type (GTK_TYPE_LIST_BOX_ROW), parent, NULL, glade_widget_get_project (parent)); glade_widget_pack_property_set (gchild, "position", position); glade_command_pop_group (); }
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 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 (); }
static void glade_popup_widget_add_cb (GtkMenuItem *item, RootAddData *data) { g_return_if_fail (data->adaptor != NULL); if (glade_command_create (data->adaptor, data->parent, data->placeholder, data->project)) glade_project_set_add_item (data->project, NULL); }
void glade_gtk_listbox_action_activate (GladeWidgetAdaptor * adaptor, GObject * object, const gchar * action_path) { if (strcmp (action_path, "add_row") == 0) { GladeWidgetAdaptor *adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_LIST_BOX_ROW); GladeWidget *gparent = glade_widget_get_from_gobject (object); GladeProject *project = glade_widget_get_project (gparent); glade_command_create (adaptor, gparent, NULL, project); glade_project_selection_set (project, object, TRUE); } else GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor, object, action_path); }
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); }
static void glade_popup_root_add_cb (GtkMenuItem *item, RootAddData *data) { glade_command_create (data->adaptor, NULL, NULL, data->project); }