Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
tagging_completion.c
Go to the documentation of this file.
1/*
2 This file is part of Ansel,
3 Copyright (C) 2026 Paolo SANTUCCI.
4
5 Ansel is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 Ansel is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Ansel. If not, see <http://www.gnu.org/licenses/>.
17*/
18
20
21#include "metadata/tags.h"
22#include "system/macros.h"
23#include "system/mem_alloc.h"
24
26{
27 gtk_list_store_clear(store);
28 GList *tags = NULL;
30 for(GList *tag_iter = tags; tag_iter; tag_iter = g_list_next(tag_iter))
31 {
32 const dt_tag_t *tag = (const dt_tag_t *)tag_iter->data;
33 if(IS_NULL_PTR(tag->tag)) continue;
34 GtkTreeIter store_iter;
35 gtk_list_store_append(store, &store_iter);
36 gtk_list_store_set(store, &store_iter, 0, tag->tag, -1);
37 }
38 dt_tag_free_result(&tags);
39}
40
41gboolean dt_tagging_completion_match_selected(GtkEntryCompletion *completion, GtkTreeModel *model,
42 GtkTreeIter *iter, gpointer user_data)
43{
44 const int column = gtk_entry_completion_get_text_column(completion);
45 if(gtk_tree_model_get_column_type(model, column) != G_TYPE_STRING) return TRUE;
46
47 GtkEditable *entry = GTK_EDITABLE(gtk_entry_completion_get_entry(completion));
48 if(!GTK_IS_EDITABLE(entry)) return FALSE;
49
50 char *tag = NULL;
51 gtk_tree_model_get(model, iter, column, &tag, -1);
52 gint cursor_position = gtk_editable_get_position(entry);
53 gchar *current_text = gtk_editable_get_chars(entry, 0, -1);
54 const gchar *last_tag = g_strrstr(current_text, ",");
55 const gint cut_off = last_tag
56 ? (int)(g_utf8_strlen(current_text, -1) - g_utf8_strlen(last_tag, -1)) + 1
57 : 0;
58 dt_free(current_text);
59
60 const gboolean inline_completion = gtk_entry_completion_get_inline_completion(completion);
61 gtk_entry_completion_set_inline_completion(completion, FALSE);
62 gtk_editable_delete_text(entry, cut_off, cursor_position);
63 cursor_position = cut_off;
64 gtk_editable_insert_text(entry, tag, -1, &cursor_position);
65 gtk_editable_set_position(entry, cursor_position);
66 gtk_entry_completion_set_inline_completion(completion, inline_completion);
67 dt_free(tag);
68 return TRUE;
69}
70
71void dt_tagging_entry_clear(GtkEntry *entry)
72{
73 GtkEntryCompletion *completion = gtk_entry_get_completion(entry);
74 if(!IS_NULL_PTR(completion))
75 {
76 g_object_ref(completion);
77 gtk_entry_set_completion(entry, NULL);
78 }
79 gtk_entry_set_text(entry, "");
80 if(!IS_NULL_PTR(completion))
81 {
82 gtk_entry_set_completion(entry, completion);
83 g_object_unref(completion);
84 }
85}
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
GtkTreeStore * store
its model, owned by the view
const char * model
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition macros.h:96
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
Definition mem_alloc.h:171
void dt_tagging_entry_clear(GtkEntry *entry)
gboolean dt_tagging_completion_match_selected(GtkEntryCompletion *completion, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
void dt_tagging_completion_refresh(GtkListStore *store)
void dt_tag_free_result(GList **result)
Definition tags.c:1003
uint32_t dt_tag_get_with_usage(GList **result)
Definition tags.c:890