Tue, 11 Jun 2024 21:49:13 +0200
fix path textfield (GTK)
ui/gtk/text.c | file | annotate | diff | comparison | revisions |
--- a/ui/gtk/text.c Sun Jun 09 17:00:06 2024 +0200 +++ b/ui/gtk/text.c Tue Jun 11 21:49:13 2024 +0200 @@ -691,6 +691,7 @@ static gboolean path_textfield_btn_pressed(GtkWidget *widget, GdkEventButton *event, UiPathTextField *pathtf) { gtk_box_pack_start(GTK_BOX(pathtf->hbox), pathtf->entry, TRUE, TRUE, 0); gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->buttonbox); + pathtf->buttonbox = NULL; gtk_widget_show(pathtf->entry); gtk_widget_grab_focus(pathtf->entry); @@ -847,6 +848,9 @@ int ui_pathtextfield_update(UiPathTextField* pathtf, const char *full_path) { size_t full_path_len = strlen(full_path); + if(full_path_len == 0) { + return 1; + } size_t nelm = 0; UiPathElm* path_elm = pathtf->getpathelm(full_path, full_path_len, &nelm, pathtf->getpathelmdata); @@ -862,12 +866,16 @@ pathtf->current_nelm = nelm; GtkWidget *buttonbox = create_path_button_box(); + + // switch from entry to buttonbox or remove current buttonbox + if(pathtf->buttonbox) { + gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->buttonbox); + } else { + gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->entry); + } + gtk_box_pack_start(GTK_BOX(pathtf->hbox), buttonbox, FALSE, FALSE, 0); pathtf->buttonbox = buttonbox; - // switch from entry to buttonbox - gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->entry); - gtk_box_pack_start(GTK_BOX(pathtf->hbox), buttonbox, FALSE, FALSE, 0); - for (int i=0;i<nelm;i++) { UiPathElm *elm = &path_elm[i];