Commit 61b495373554dd5b91a740e96083e3bdb1276939

  • avatar
  • Sam Thursfield <sam @dja…go.(none)>
  • Wed Jul 22 01:20:42 CEST 2009
[gsettings] Add SetPropertyBinding command.
  
749749 glade_command_set_property_value (property, value);
750750}
751751
752/**************************************************************/
753/******* GLADE_COMMAND_SET_PROPERTY_BINDING *******/
754/**************************************************************/
755
756typedef struct {
757 GladeCommand parent;
758 GladeProperty *property;
759 gchar *old_key;
760 gchar *new_key;
761 gboolean undo;
762} GladeCommandSetPropertyBinding;
763
764/* standard macros */
765GLADE_MAKE_COMMAND (GladeCommandSetPropertyBinding, glade_command_set_property_binding);
766#define GLADE_COMMAND_SET_PROPERTY_BINDING_TYPE (glade_command_set_property_binding_get_type ())
767#define GLADE_COMMAND_SET_PROPERTY_BINDING(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GLADE_COMMAND_SET_PROPERTY_BINDING_TYPE, GladeCommandSetPropertyBinding))
768#define GLADE_COMMAND_SET_PROPERTY_BINDING_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GLADE_COMMAND_SET_PROPERTY_BINDING_TYPE, GladeCommandSetPropertyBindingClass))
769#define GLADE_IS_COMMAND_SET_PROPERTY_BINDING(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GLADE_COMMAND_SET_PROPERTY_BINDING_TYPE))
770#define GLADE_IS_COMMAND_SET_PROPERTY_BINDING_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GLADE_COMMAND_SET_PROPERTY_BINDING_TYPE))
771
772/* Undo the last "set property command" */
773static gboolean
774glade_command_set_property_binding_undo (GladeCommand *cmd)
775{
776 return glade_command_set_property_binding_execute (cmd);
777}
778
779/*
780 * Set binding and reverse the command
781 */
782static gboolean
783glade_command_set_property_binding_execute (GladeCommand *cmd)
784{
785 GladeCommandSetPropertyBinding *self = GLADE_COMMAND_SET_PROPERTY_BINDING (cmd);
786 gchar *key;
787
788 g_return_val_if_fail (self != NULL, FALSE);
789
790 if (self->undo)
791 key = self->old_key;
792 else
793 key = self->new_key;
794
795#if 0
796 g_print ("Binding %s property of %s to %s\n",
797 self->property->klass->id,
798 self->property->widget->name,
799 key);
800#endif
801
802 glade_property_set_binding (self->property, key);
803
804 self->undo = !self->undo;
805
806 return TRUE;
807}
808
809static void
810glade_command_set_property_binding_finalize (GObject *obj)
811{
812 GladeCommandSetPropertyBinding *self = GLADE_COMMAND_SET_PROPERTY_BINDING (obj);
813
814 if (self->old_key != NULL)
815 g_free (self->old_key);
816
817 if (self->new_key != NULL)
818 g_free (self->new_key);
819
820 glade_command_finalize (obj);
821}
822
823static gboolean
824glade_command_set_property_binding_unifies (GladeCommand *this_cmd, GladeCommand *other_cmd)
825{
826 return FALSE;
827}
828
829static void
830glade_command_set_property_binding_collapse (GladeCommand *this_cmd, GladeCommand *other_cmd)
831{
832 g_return_if_reached ();
833};
834
835static gchar *
836glade_command_set_property_binding_description (GladeCommandSetPropertyBinding *self)
837{
838 /* FIXME: translation comments? */
839 const gchar *setting_default = "setting";
840
841 gchar *description = NULL,
842 *setting = setting_default;
843
844 g_assert (self->property->klass->name);
845 g_assert (self->property->widget->name);
846
847 // FIXME: use key name if short enough
848 if (self->new_key == NULL) {
849 description = g_strdup_printf (_("Disconnecting %s of %s from %s"),
850 self->property->klass->name,
851 self->property->widget->name,
852 setting);
853 } else {
854 description = g_strdup_printf (_("Connecting %s of %s to %s"),
855 self->property->klass->name,
856 self->property->widget->name,
857 setting);
858 /*if (!value_name || strlen (value_name) > MAX_UNDO_MENU_ITEM_VALUE_LEN
859 || strchr (value_name, '_')) {
860 description = g_strdup_printf (_("Setting %s of %s"),
861 sdata->property->klass->name,
862 sdata->property->widget->name);
863 } else {*/
864 }
865
866 return description;
867}
868
869
870void
871glade_command_set_property_binding (GladeProperty *property,
872 const gchar *key_name)
873{
874 GladeCommandSetPropertyBinding *self;
875 GladeCommand *cmd;
876
877 self = g_object_new (GLADE_COMMAND_SET_PROPERTY_BINDING_TYPE, NULL);
878 cmd = GLADE_COMMAND (self);
879
880 self->property = property;
881 self->old_key = g_strdup (glade_property_get_binding (property));
882 self->new_key = g_strdup (key_name);
883 self->undo = FALSE;
884
885 cmd->description = glade_command_set_property_binding_description (self);
886
887 glade_command_check_group (cmd);
888
889 if (glade_command_set_property_binding_execute (cmd))
890 glade_project_push_undo (GLADE_PROJECT (property->widget->project), cmd);
891 else
892 g_object_unref (G_OBJECT (self));
893
894};
895
752896/**************************************************/
753897/******* GLADE_COMMAND_SET_NAME *******/
754898/**************************************************/
  
109109void glade_command_set_properties_list (GladeProject *project,
110110 GList *props); /* list of GCSetPropData */
111111
112/************************** property bindings ***************************/
113
114void glade_command_set_property_binding (GladeProperty *property,
115 const gchar *key_name);
116
117
112118/************************** name ******************************/
113119
114120void glade_command_set_name (GladeWidget *glade_widget, const gchar *name);