static GtkTreeIter keyword_tree_default_append(GtkTreeStore *keyword_tree, GtkTreeIter *parent, const gchar *name, gboolean is_keyword) { GtkTreeIter iter; gtk_tree_store_append(keyword_tree, &iter, parent); keyword_set(keyword_tree, &iter, name, is_keyword); return iter; }
GtkTreeIter *keyword_add_from_config(GtkTreeStore *keyword_tree, GtkTreeIter *parent, const gchar **attribute_names, const gchar **attribute_values) { gchar *name = NULL; gboolean is_kw = TRUE; while (*attribute_names) { const gchar *option = *attribute_names++; const gchar *value = *attribute_values++; if (READ_CHAR_FULL("name", name)) continue; if (READ_BOOL_FULL("kw", is_kw)) continue; log_printf("unknown attribute %s = %s\n", option, value); } if (name && name[0]) { GtkTreeIter iter; /* re-use existing keyword if any */ if (!keyword_exists(GTK_TREE_MODEL(keyword_tree), parent, NULL, name, FALSE, &iter)) { gtk_tree_store_append(keyword_tree, &iter, parent); } keyword_set(keyword_tree, &iter, name, is_kw); g_free(name); return gtk_tree_iter_copy(&iter); } g_free(name); return NULL; }
static void bar_pane_keywords_edit_ok_cb(GenericDialog *gd, gpointer data) { ConfDialogData *cdd = data; PaneKeywordsData *pkd = cdd->pkd; GtkTreeModel *model; GtkTreeModel *keyword_tree; GtkTreeIter kw_iter; gboolean have_dest = FALSE; GList *keywords; model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); if (cdd->click_tpath) { GtkTreeIter iter; if (gtk_tree_model_get_iter(model, &iter, cdd->click_tpath)) { gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &kw_iter, &iter); have_dest = TRUE; } } if (cdd->edit_existing && !have_dest) return; keywords = keyword_list_pull(cdd->edit_widget); if (cdd->edit_existing) { if (keywords && keywords->data && /* there should be one keyword */ !keyword_exists(keyword_tree, NULL, &kw_iter, keywords->data, TRUE, NULL)) { keyword_set(GTK_TREE_STORE(keyword_tree), &kw_iter, keywords->data, cdd->is_keyword); } } else { GList *work = keywords; gboolean append_to = FALSE; while (work) { GtkTreeIter add; if (keyword_exists(keyword_tree, NULL, (have_dest || append_to) ? &kw_iter : NULL, work->data, FALSE, NULL)) { work = work->next; continue; } if (have_dest) { gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &add, &kw_iter); } else if (append_to) { gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &add, NULL, &kw_iter); } else { gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &add, NULL); append_to = TRUE; kw_iter = add; } keyword_set(GTK_TREE_STORE(keyword_tree), &add, work->data, cdd->is_keyword); work = work->next; } } string_list_free(keywords); }
static void bar_pane_keywords_dnd_receive(GtkWidget *tree_view, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time, gpointer data) { PaneKeywordsData *pkd = data; GtkTreePath *tpath = NULL; GtkTreeViewDropPosition pos; GtkTreeModel *model; GtkTreeModel *keyword_tree; gboolean src_valid = FALSE; GList *new_keywords = NULL; GList *work; /* iterators for keyword_tree */ GtkTreeIter src_kw_iter; GtkTreeIter dest_kw_iter; GtkTreeIter new_kw_iter; g_signal_stop_emission_by_name(tree_view, "drag_data_received"); model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)); keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, &tpath, &pos); gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), NULL, pos); switch (info) { case TARGET_APP_KEYWORD_PATH: { GList *path = *(gpointer *)gtk_selection_data_get_data(selection_data); src_valid = keyword_tree_get_iter(keyword_tree, &src_kw_iter, path); string_list_free(path); break; } default: new_keywords = string_to_keywords_list((gchar *)gtk_selection_data_get_data(selection_data)); break; } if (tpath) { GtkTreeIter dest_iter; gtk_tree_model_get_iter(model, &dest_iter, tpath); gtk_tree_path_free(tpath); gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &dest_kw_iter, &dest_iter); if (src_valid && gtk_tree_store_is_ancestor(GTK_TREE_STORE(keyword_tree), &src_kw_iter, &dest_kw_iter)) { /* can't move to it's own child */ return; } if (src_valid && keyword_compare(keyword_tree, &src_kw_iter, &dest_kw_iter) == 0) { /* can't move to itself */ return; } if ((pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE || pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) && !gtk_tree_model_iter_has_child(keyword_tree, &dest_kw_iter)) { /* the node has no children, all keywords can be added */ gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &new_kw_iter, &dest_kw_iter); } else { if (src_valid && !bar_pane_keywords_dnd_can_move(keyword_tree, &src_kw_iter, &dest_kw_iter)) { /* the keyword can't be moved if the same name already exist */ return; } if (new_keywords && !bar_pane_keywords_dnd_skip_existing(keyword_tree, &dest_kw_iter, &new_keywords)) { /* the keywords can't be added if the same name already exist */ return; } switch (pos) { case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: case GTK_TREE_VIEW_DROP_BEFORE: gtk_tree_store_insert_before(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL, &dest_kw_iter); break; case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: case GTK_TREE_VIEW_DROP_AFTER: gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL, &dest_kw_iter); break; } } } else { if (src_valid && !bar_pane_keywords_dnd_can_move(keyword_tree, &src_kw_iter, NULL)) { /* the keyword can't be moved if the same name already exist */ return; } if (new_keywords && !bar_pane_keywords_dnd_skip_existing(keyword_tree, NULL, &new_keywords)) { /* the keywords can't be added if the same name already exist */ return; } gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL); } if (src_valid) { keyword_move_recursive(GTK_TREE_STORE(keyword_tree), &new_kw_iter, &src_kw_iter); } work = new_keywords; while (work) { gchar *keyword = work->data; keyword_set(GTK_TREE_STORE(keyword_tree), &new_kw_iter, keyword, TRUE); work = work->next; if (work) { GtkTreeIter add; gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &add, NULL, &new_kw_iter); new_kw_iter = add; } } string_list_free(new_keywords); bar_keyword_tree_sync(pkd); }