Commit 61b495373554dd5b91a740e96083e3bdb1276939
- Diff rendering mode:
- inline
- side by side
gladeui/glade-command.c
(144 / 0)
|   | |||
| 749 | 749 | glade_command_set_property_value (property, value); | |
| 750 | 750 | } | |
| 751 | 751 | ||
| 752 | /**************************************************************/ | ||
| 753 | /******* GLADE_COMMAND_SET_PROPERTY_BINDING *******/ | ||
| 754 | /**************************************************************/ | ||
| 755 | |||
| 756 | typedef struct { | ||
| 757 | GladeCommand parent; | ||
| 758 | GladeProperty *property; | ||
| 759 | gchar *old_key; | ||
| 760 | gchar *new_key; | ||
| 761 | gboolean undo; | ||
| 762 | } GladeCommandSetPropertyBinding; | ||
| 763 | |||
| 764 | /* standard macros */ | ||
| 765 | GLADE_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" */ | ||
| 773 | static gboolean | ||
| 774 | glade_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 | */ | ||
| 782 | static gboolean | ||
| 783 | glade_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 | |||
| 809 | static void | ||
| 810 | glade_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 | |||
| 823 | static gboolean | ||
| 824 | glade_command_set_property_binding_unifies (GladeCommand *this_cmd, GladeCommand *other_cmd) | ||
| 825 | { | ||
| 826 | return FALSE; | ||
| 827 | } | ||
| 828 | |||
| 829 | static void | ||
| 830 | glade_command_set_property_binding_collapse (GladeCommand *this_cmd, GladeCommand *other_cmd) | ||
| 831 | { | ||
| 832 | g_return_if_reached (); | ||
| 833 | }; | ||
| 834 | |||
| 835 | static gchar * | ||
| 836 | glade_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 | |||
| 870 | void | ||
| 871 | glade_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 | |||
| 752 | 896 | /**************************************************/ | |
| 753 | 897 | /******* GLADE_COMMAND_SET_NAME *******/ | |
| 754 | 898 | /**************************************************/ |
gladeui/glade-command.h
(6 / 0)
|   | |||
| 109 | 109 | void glade_command_set_properties_list (GladeProject *project, | |
| 110 | 110 | GList *props); /* list of GCSetPropData */ | |
| 111 | 111 | ||
| 112 | /************************** property bindings ***************************/ | ||
| 113 | |||
| 114 | void glade_command_set_property_binding (GladeProperty *property, | ||
| 115 | const gchar *key_name); | ||
| 116 | |||
| 117 | |||
| 112 | 118 | /************************** name ******************************/ | |
| 113 | 119 | ||
| 114 | 120 | void glade_command_set_name (GladeWidget *glade_widget, const gchar *name); |

