43 |
gpointer userdata) { |
gpointer userdata) { |
44 |
tag_context_t *context = (tag_context_t*)userdata; |
tag_context_t *context = (tag_context_t*)userdata; |
45 |
GtkTreeIter iter; |
GtkTreeIter iter; |
46 |
|
|
47 |
if(gtk_tree_model_get_iter(model, &iter, path)) { |
if(gtk_tree_model_get_iter(model, &iter, path)) { |
48 |
g_assert(gtk_tree_path_get_depth(path) == 1); |
g_assert(gtk_tree_path_get_depth(path) == 1); |
49 |
|
|
50 |
tag_t *tag; |
tag_t *tag; |
51 |
gtk_tree_model_get(model, &iter, TAG_COL_DATA, &tag, -1); |
gtk_tree_model_get(model, &iter, TAG_COL_DATA, &tag, -1); |
52 |
|
|
|
if(context->but_remove && context->but_edit) { |
|
|
|
|
53 |
/* you just cannot delete or edit the "created_by" tag */ |
/* you just cannot delete or edit the "created_by" tag */ |
54 |
if(context->but_remove && context->but_edit) { |
if(strcasecmp(tag->key, "created_by") == 0) { |
55 |
if(strcasecmp(tag->key, "created_by") == 0) { |
list_button_enable(context->list, LIST_BUTTON_REMOVE, FALSE); |
56 |
gtk_widget_set_sensitive(context->but_remove, FALSE); |
list_button_enable(context->list, LIST_BUTTON_EDIT, FALSE); |
57 |
gtk_widget_set_sensitive(context->but_edit, FALSE); |
} else { |
58 |
} else { |
list_button_enable(context->list, LIST_BUTTON_REMOVE, TRUE); |
59 |
gtk_widget_set_sensitive(context->but_remove, TRUE); |
list_button_enable(context->list, LIST_BUTTON_EDIT, TRUE); |
|
gtk_widget_set_sensitive(context->but_edit, TRUE); |
|
|
} |
|
|
} |
|
60 |
} |
} |
61 |
} |
} |
62 |
|
|
85 |
} |
} |
86 |
|
|
87 |
static void on_tag_remove(GtkWidget *but, tag_context_t *context) { |
static void on_tag_remove(GtkWidget *but, tag_context_t *context) { |
|
GtkTreeSelection *selection; |
|
88 |
GtkTreeModel *model; |
GtkTreeModel *model; |
89 |
GtkTreeIter iter; |
GtkTreeIter iter; |
90 |
|
|
91 |
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view)); |
GtkTreeSelection *selection = list_get_selection(context->list); |
92 |
if(gtk_tree_selection_get_selected(selection, &model, &iter)) { |
if(gtk_tree_selection_get_selected(selection, &model, &iter)) { |
93 |
tag_t *tag; |
tag_t *tag; |
94 |
gtk_tree_model_get(model, &iter, TAG_COL_DATA, &tag, -1); |
gtk_tree_model_get(model, &iter, TAG_COL_DATA, &tag, -1); |
111 |
} |
} |
112 |
|
|
113 |
/* disable remove and edit buttons */ |
/* disable remove and edit buttons */ |
114 |
gtk_widget_set_sensitive(context->but_remove, FALSE); |
list_button_enable(context->list, LIST_BUTTON_REMOVE, FALSE); |
115 |
gtk_widget_set_sensitive(context->but_edit, FALSE); |
list_button_enable(context->list, LIST_BUTTON_EDIT, FALSE); |
116 |
} |
} |
117 |
|
|
118 |
static gboolean tag_edit(tag_context_t *context) { |
static gboolean tag_edit(tag_context_t *context) { |
121 |
GtkTreeIter iter; |
GtkTreeIter iter; |
122 |
tag_t *tag; |
tag_t *tag; |
123 |
|
|
124 |
GtkTreeSelection *sel = gtk_tree_view_get_selection( |
GtkTreeSelection *sel = list_get_selection(context->list); |
|
GTK_TREE_VIEW(context->view)); |
|
125 |
if(!sel) { |
if(!sel) { |
126 |
printf("got no selection object\n"); |
printf("got no selection object\n"); |
127 |
return FALSE; |
return FALSE; |
251 |
TAG_COL_DATA, *tag, |
TAG_COL_DATA, *tag, |
252 |
-1); |
-1); |
253 |
|
|
254 |
gtk_tree_selection_select_iter(gtk_tree_view_get_selection( |
gtk_tree_selection_select_iter( |
255 |
GTK_TREE_VIEW(context->view)), &iter); |
list_get_selection(context->list), &iter); |
256 |
|
|
257 |
if(!tag_edit(context)) { |
if(!tag_edit(context)) { |
258 |
printf("cancelled\n"); |
printf("cancelled\n"); |
278 |
} |
} |
279 |
|
|
280 |
static GtkWidget *tag_widget(tag_context_t *context) { |
static GtkWidget *tag_widget(tag_context_t *context) { |
281 |
GtkWidget *vbox = gtk_vbox_new(FALSE,3); |
context->list = list_new(); |
282 |
context->view = gtk_tree_view_new(); |
|
283 |
|
list_set_static_buttons(context->list, G_CALLBACK(on_tag_add), |
284 |
|
G_CALLBACK(on_tag_edit), G_CALLBACK(on_tag_remove), context); |
285 |
|
|
286 |
|
list_set_selection_function(context->list, view_selection_func, context); |
287 |
|
|
288 |
gtk_tree_selection_set_select_function( |
list_set_user_buttons(context->list, |
289 |
gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view)), |
LIST_BUTTON_USER0, _("Last..."), on_tag_last, |
290 |
view_selection_func, |
0); |
291 |
context, NULL); |
|
292 |
|
/* setup both columns */ |
293 |
/* --- "Key" column --- */ |
list_set_columns(context->list, |
294 |
GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
_("Key"), TAG_COL_KEY, |
295 |
g_object_set(renderer, |
LIST_FLAG_EXPAND|LIST_FLAG_CAN_HIGHLIGHT, TAG_COL_COLLISION, |
296 |
"ellipsize", PANGO_ELLIPSIZE_END, |
_("Value"), TAG_COL_VALUE, |
297 |
"background", "red", |
LIST_FLAG_EXPAND, |
298 |
NULL ); |
NULL); |
299 |
GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes( |
|
300 |
_("Key"), renderer, |
GtkWidget *presets = josm_presets_select(context->appdata, context); |
301 |
"text", TAG_COL_KEY, |
if(presets) |
302 |
"background-set", TAG_COL_COLLISION, |
list_set_custom_user_button(context->list, LIST_BUTTON_USER1, presets); |
303 |
NULL); |
|
304 |
gtk_tree_view_column_set_expand(column, TRUE); |
/* disable if no appropriate "last" tags have been stored or if the */ |
305 |
gtk_tree_view_insert_column(GTK_TREE_VIEW(context->view), column, -1); |
/* selected item isn't a node or way */ |
306 |
|
if(((context->type == NODE) && |
307 |
/* --- "Value" column --- */ |
(!context->appdata->map->last_node_tags)) || |
308 |
renderer = gtk_cell_renderer_text_new(); |
((context->type == WAY) && |
309 |
g_object_set(renderer, |
(!context->appdata->map->last_way_tags)) || |
310 |
"ellipsize", PANGO_ELLIPSIZE_END, |
((context->type != NODE) && (context->type != WAY))) |
311 |
NULL ); |
list_button_enable(context->list, LIST_BUTTON_USER0, FALSE); |
|
column = gtk_tree_view_column_new_with_attributes( |
|
|
_("Value"), renderer, |
|
|
"text", TAG_COL_VALUE, |
|
|
NULL); |
|
|
gtk_tree_view_column_set_expand(column, TRUE); |
|
|
gtk_tree_view_insert_column(GTK_TREE_VIEW(context->view), column, -1); |
|
312 |
|
|
313 |
/* build and fill the store */ |
/* --------- build and fill the store ------------ */ |
314 |
context->store = gtk_list_store_new(TAG_NUM_COLS, |
context->store = gtk_list_store_new(TAG_NUM_COLS, |
315 |
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_POINTER); |
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_POINTER); |
316 |
|
|
317 |
gtk_tree_view_set_model(GTK_TREE_VIEW(context->view), |
list_set_store(context->list, context->store); |
|
GTK_TREE_MODEL(context->store)); |
|
318 |
|
|
319 |
GtkTreeIter iter; |
GtkTreeIter iter; |
320 |
tag_t *tag = *context->tag; |
tag_t *tag = *context->tag; |
332 |
|
|
333 |
g_object_unref(context->store); |
g_object_unref(context->store); |
334 |
|
|
335 |
/* put it into a scrolled window */ |
return context->list; |
|
GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); |
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), |
|
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); |
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), |
|
|
GTK_SHADOW_ETCHED_IN); |
|
|
// gtk_container_set_border_width(GTK_CONTAINER(scrolled_window), 3); |
|
|
gtk_container_add(GTK_CONTAINER(scrolled_window), context->view); |
|
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), scrolled_window); |
|
|
|
|
|
/* ------- button box ------------ */ |
|
|
|
|
|
GtkWidget *hbox = gtk_hbox_new(TRUE,3); |
|
|
|
|
|
GtkWidget *but_last = gtk_button_new_with_label(_("Last...")); |
|
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), but_last); |
|
|
|
|
|
/* disable if no appropriate "last" tags have been stored or if the */ |
|
|
/* selected item isn't a node or way */ |
|
|
if(((context->type == NODE) && |
|
|
(!context->appdata->map->last_node_tags)) || |
|
|
((context->type == WAY) && |
|
|
(!context->appdata->map->last_way_tags)) || |
|
|
((context->type != NODE) && (context->type != WAY))) |
|
|
gtk_widget_set_sensitive(but_last, FALSE); |
|
|
|
|
|
gtk_signal_connect(GTK_OBJECT(but_last), "clicked", |
|
|
GTK_SIGNAL_FUNC(on_tag_last), context); |
|
|
|
|
|
GtkWidget *presets = josm_presets_select(context->appdata, context); |
|
|
if(presets) gtk_box_pack_start_defaults(GTK_BOX(hbox), presets); |
|
|
|
|
|
context->but_add = gtk_button_new_with_label(_("Add...")); |
|
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_add); |
|
|
gtk_signal_connect(GTK_OBJECT(context->but_add), "clicked", |
|
|
GTK_SIGNAL_FUNC(on_tag_add), context); |
|
|
|
|
|
context->but_edit = gtk_button_new_with_label(_("Edit...")); |
|
|
gtk_widget_set_sensitive(context->but_edit, FALSE); |
|
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_edit); |
|
|
gtk_signal_connect(GTK_OBJECT(context->but_edit), "clicked", |
|
|
GTK_SIGNAL_FUNC(on_tag_edit), context); |
|
|
|
|
|
context->but_remove = gtk_button_new_with_label(_("Remove")); |
|
|
gtk_widget_set_sensitive(context->but_remove, FALSE); |
|
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_remove); |
|
|
gtk_signal_connect(GTK_OBJECT(context->but_remove), "clicked", |
|
|
GTK_SIGNAL_FUNC(on_tag_remove), context); |
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
|
|
return vbox; |
|
336 |
} |
} |
337 |
|
|
338 |
/* edit tags of currently selected node or way or of the relation */ |
/* edit tags of currently selected node or way or of the relation */ |