static void property_model_property_added_cb (MrpProject *project, GType owner_type, MrpProperty *property, MrpPropertyStore *shop) { GtkTreeIter iter; MrpPropertyType type; GtkListStore *store; if (owner_type != shop->owner_type) { return; } store = shop->store; if (store) { type = mrp_property_get_property_type (property); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, COL_NAME, mrp_property_get_name (property), COL_LABEL, mrp_property_get_label (property), COL_TYPE, mrp_property_type_as_string (type), COL_PROPERTY, property, -1); } }
static gboolean property_model_property_changed_helper (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { MrpProperty *property; const gchar *property_name; gchar *name; g_return_val_if_fail (data != NULL, FALSE); property = MRP_PROPERTY (data); property_name = mrp_property_get_name (property); gtk_tree_model_get (model, iter, COL_NAME, &name, -1); if (!strcmp (name, property_name)) { gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LABEL, mrp_property_get_label (property), -1); return TRUE; } return FALSE; }
static PlannerCmd * property_cmd_label_edited (PlannerWindow *window, MrpProperty *property, MrpProject *project, GType owner, const gchar *new_text) { PlannerCmd *cmd_base; PropertyCmdLabelEdited *cmd; cmd_base = planner_cmd_new (PropertyCmdLabelEdited, _("Edit property label"), property_cmd_label_edited_do, property_cmd_label_edited_undo, property_cmd_label_edited_free); cmd = (PropertyCmdLabelEdited *) cmd_base; cmd->window = window; cmd->new_text = g_strdup (new_text); cmd->old_text = g_strdup (mrp_property_get_label (property)); cmd->project = project; cmd->name = g_strdup (mrp_property_get_name (property)); cmd->owner = owner; planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (window), cmd_base); return cmd_base; }
static void property_dialog_label_edited (GtkCellRendererText *cell, gchar *path_str, gchar *new_text, GtkWidget *dialog) { PlannerPropertyDialogPriv *priv; GtkTreePath *path; GtkTreeIter iter; GtkTreeModel *model; MrpProperty *property; priv = GET_PRIV (dialog); model = priv->model; path = gtk_tree_path_new_from_string (path_str); gtk_tree_model_get_iter (model, &iter, path); gtk_tree_model_get (priv->model, &iter, COL_PROPERTY, &property, -1); if (strcmp (new_text, mrp_property_get_label (property)) != 0 ) { property_cmd_label_edited (priv->main_window, property, priv->project, priv->owner, new_text); } gtk_tree_path_free (path); }
static PlannerCmd * property_cmd_remove (PlannerWindow *window, MrpProject *project, GType owner, const gchar *name) { PlannerCmd *cmd_base; PropertyCmdRemove *cmd; MrpProperty *property; cmd_base = planner_cmd_new (PropertyCmdRemove, _("Remove property"), property_cmd_remove_do, property_cmd_remove_undo, property_cmd_remove_free); cmd = (PropertyCmdRemove *) cmd_base; cmd->project = g_object_ref (project); cmd->owner = owner; cmd->name = g_strdup (name); property = mrp_project_get_property (project, name, owner); cmd->property = mrp_property_ref (property); cmd->type = mrp_property_get_property_type (property); cmd->description = g_strdup (mrp_property_get_description (property)); cmd->label_text = g_strdup ( mrp_property_get_label (property)); cmd->user_defined = mrp_property_get_user_defined (property); cmd->tasks = g_hash_table_new (NULL, NULL); cmd->resources = g_hash_table_new (NULL, NULL); planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (window), cmd_base); return cmd_base; }
GtkTreeModel * planner_property_model_new (MrpProject *project, GType owner_type, MrpPropertyStore *shop) { GtkListStore *store; GList *properties, *l; MrpProperty *property; MrpPropertyType type; GtkTreeIter iter; store = gtk_list_store_new (5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_POINTER); shop->store = store; shop->owner_type = owner_type; properties = mrp_project_get_properties_from_type (project, owner_type); for (l = properties; l; l = l->next) { property = l->data; type = mrp_property_get_property_type (property); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, COL_NAME, mrp_property_get_name (property), COL_LABEL, mrp_property_get_label (property), COL_TYPE, mrp_property_type_as_string (type), COL_PROPERTY, property, -1); } /* We need to know which store to add the property so we pass the shop * reference not the store. The shop is a structure that correlates * which store currently holds which owner. We don't have to bother with * this when changing or removing - just adding. */ g_signal_connect (project, "property_added", G_CALLBACK (property_model_property_added_cb), shop); g_signal_connect (project, "property_removed", G_CALLBACK (property_model_property_removed_cb), store); g_signal_connect (project, "property_changed", G_CALLBACK (property_model_property_changed_cb), store); return GTK_TREE_MODEL (store); }
static void mpp_write_property_specs (MrpParser *parser, xmlNodePtr node) { GList *properties, *l; xmlNodePtr child; MrpProperty *property; MrpPropertyType type; properties = mrp_project_get_properties_from_type (parser->project, MRP_TYPE_PROJECT); node = xmlNewChild (node, NULL, "properties", NULL); for (l = properties; l; l = l->next) { property = l->data; child = xmlNewChild (node, NULL, "property", NULL); xmlSetProp (child, "name", mrp_property_get_name (property)); type = mrp_property_get_property_type (property); xmlSetProp (child, "type", mpp_property_type_to_string (type)); xmlSetProp (child, "owner", "project"); xmlSetProp (child, "label", mrp_property_get_label (property)); xmlSetProp (child, "description", mrp_property_get_description (property)); } g_list_free (properties); properties = mrp_project_get_properties_from_type (parser->project, MRP_TYPE_TASK); for (l = properties; l; l = l->next) { property = l->data; child = xmlNewChild (node, NULL, "property", NULL); xmlSetProp (child, "name", mrp_property_get_name (property)); type = mrp_property_get_property_type (property); xmlSetProp (child, "type", mpp_property_type_to_string (type)); xmlSetProp (child, "owner", "task"); xmlSetProp (child, "label", mrp_property_get_label (property)); xmlSetProp (child, "description", mrp_property_get_description (property)); } g_list_free (properties); properties = mrp_project_get_properties_from_type (parser->project, MRP_TYPE_RESOURCE); for (l = properties; l; l = l->next) { property = l->data; child = xmlNewChild (node, NULL, "property", NULL); xmlSetProp (child, "name", mrp_property_get_name (property)); type = mrp_property_get_property_type (property); xmlSetProp (child, "type", mpp_property_type_to_string (type)); xmlSetProp (child, "owner", "resource"); xmlSetProp (child, "label", mrp_property_get_label (property)); xmlSetProp (child, "description", mrp_property_get_description (property)); } g_list_free (properties); }