static int combobox_numindex(lua_State*L) { lua_combobox combobox; luaA_to(L,lua_combobox,&combobox,1); int key = lua_tointeger(L,2); int length = dt_bauhaus_combobox_length(combobox->widget); if(lua_gettop(L) > 2) { if(key <= 0 || key > length +1) { return luaL_error(L,"Invalid index for combobox : %d\n",key); } else if(key == length +1) { const char * string = luaL_checkstring(L,3); dt_bauhaus_combobox_add(combobox->widget,string); } else if(lua_isnil(L,3)){ dt_bauhaus_combobox_remove_at(combobox->widget,key-1); } else { const char * string = luaL_checkstring(L,3); dt_bauhaus_combobox_remove_at(combobox->widget,key-1); dt_bauhaus_combobox_insert(combobox->widget,string,key-1); } return 0; } if(key <= 0 || key > length) { return luaL_error(L,"Invalid index for combo box : %d\n",key); } else if (key > length) { lua_pushnil(L); return 1; } const GList *labels = dt_bauhaus_combobox_get_labels(combobox->widget); lua_pushstring(L,g_list_nth_data((GList*)labels,key-1)); return 1; }
static void _combo_box_set_active_text(GtkWidget *cb, gchar *text) { int i = 0; for(const GList *iter = dt_bauhaus_combobox_get_labels(cb); iter; iter = g_list_next(iter)) { if(!g_strcmp0((gchar *)iter->data, text)) { dt_bauhaus_combobox_set(cb, i); return; } i++; } }
/** Invoked when a value of a property is changed. */ static void _camera_property_value_changed(const dt_camera_t *camera, const char *name, const char *value, void *data) { dt_lib_camera_t *lib = (dt_lib_camera_t *)data; // Find the property in lib->data.properties, update value GList *citem; if((citem = g_list_find_custom(lib->gui.properties, name, _compare_property_by_name)) != NULL) { dt_lib_camera_property_t *prop = (dt_lib_camera_property_t *)citem->data; int i = 0; for(const GList *iter = dt_bauhaus_combobox_get_labels(prop->values); iter; iter = g_list_next(iter), i++) { if(!g_strcmp0((gchar*)iter->data, value)) { dt_bauhaus_combobox_set(prop->values, i); return; } } } }