diff --git a/src/dialogs/load.c b/src/dialogs/load.c index c000172..e57df4a 100644 --- a/src/dialogs/load.c +++ b/src/dialogs/load.c @@ -35,6 +35,7 @@ #include #include #include + #include /*--[ Widget definition ]----------------------------------------------------------------------------*/ @@ -73,16 +74,7 @@ } - static void cancel_operation(GtkButton G_GNUC_UNUSED(*button), GtkDialog *dialog) - { - gtk_dialog_response(dialog,GTK_RESPONSE_CANCEL); - } - - static void apply_operation(GtkButton G_GNUC_UNUSED(*button), GtkDialog *dialog) - { - gtk_dialog_response(dialog,GTK_RESPONSE_APPLY); - } - +/* #ifdef WIN32 static void icon_press(GtkEntry G_GNUC_UNUSED(*entry), G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G_GNUC_UNUSED GdkEvent *event, V3270LoadDialog *widget) { @@ -128,9 +120,38 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ } #endif // _WIN32 +*/ - static void V3270LoadDialog_init(V3270LoadDialog *dialog) - { + static void filename_changed(GtkEntry *entry, V3270LoadDialog *dialog) { + + const gchar * text = gtk_entry_get_text(entry); + GtkWidget * button = gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog),GTK_RESPONSE_APPLY); + + if(!(text && *text)) { + gtk_widget_set_sensitive(button,FALSE); + return; + } + + if(g_str_has_suffix(text,G_DIR_SEPARATOR_S)) { + gtk_widget_set_sensitive(button,FALSE); + return; + } + + g_autofree gchar * dirname = g_path_get_dirname(text); + + if(!g_file_test(dirname,G_FILE_TEST_IS_DIR)) { + gtk_widget_set_sensitive(button,FALSE); + return; + } + + + // g_autofree gchar * basename = g_path_get_basename(text); + + + gtk_widget_set_sensitive(button,TRUE); + } + + static void V3270LoadDialog_init(V3270LoadDialog *dialog) { // 0--------1---------------------2-------3--------------------4 // 0 - Filename xxxxxxxxx.xxxxxxxxx.xxxxxxxxx.xxxxxxxxx.xxxxxxxxx. x // 1 - Charset xxxxxxxxx.xxxxxxxxx. Format: xxxxxxxxx.xxxxxxxxx. @@ -141,7 +162,6 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ // Setup visual elements // https://developer.gnome.org/hig/stable/visual-layout.html.en GtkWidget *widget; - GtkWidget *button; GtkBox * box = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))); gtk_window_set_resizable(GTK_WINDOW(dialog),FALSE); @@ -166,10 +186,23 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ gtk_grid_attach(grid,widget,0,0,1,1); gtk_label_set_mnemonic_widget(GTK_LABEL(widget),dialog->filename); + /* gtk_entry_set_icon_from_icon_name(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,"document-open"); gtk_entry_set_icon_activatable(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,TRUE); gtk_entry_set_icon_tooltip_text(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,_("Select file")); g_signal_connect(G_OBJECT(dialog->filename),"icon-press",G_CALLBACK(icon_press),dialog); + */ + + g_signal_connect(dialog->filename,"changed",G_CALLBACK(filename_changed),dialog); + + gtk_entry_bind_to_filechooser( + dialog->filename, + GTK_FILE_CHOOSER_ACTION_OPEN, + _( "Select file" ), + NULL, + "*.txt", + _("Text files") + ); gtk_entry_set_width_chars(GTK_ENTRY(dialog->filename),60); gtk_entry_set_max_length(GTK_ENTRY(dialog->filename),PATH_MAX); @@ -191,41 +224,20 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ // Buttons // https://developer.gnome.org/icon-naming-spec/ -#ifdef _WIN32 - widget = NULL; -#elif GTK_CHECK_VERSION(3,14,0) - widget = gtk_dialog_get_header_bar(GTK_DIALOG(dialog)); -#else - widget = NULL; -#endif // GTK(3,14,0) + gtk_dialog_add_buttons( + GTK_DIALOG (dialog), + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_Load"), GTK_RESPONSE_APPLY, + NULL + ); - if(widget) - { - // Have header bar - button = gtk_button_new_with_mnemonic(_("_Cancel")); - gtk_widget_set_tooltip_markup(button,_("Click to cancel operation")); - gtk_header_bar_pack_start(GTK_HEADER_BAR(widget),button); - g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(cancel_operation),dialog); - - button = gtk_button_new_with_mnemonic(_("_Load")); - gtk_widget_set_tooltip_markup(button,_("Click to load file")); - gtk_header_bar_pack_end(GTK_HEADER_BAR(widget),button); - g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(apply_operation),dialog); + if(!v3270_dialog_get_use_header()) { + GtkWidget * content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + gtk_box_set_spacing(GTK_BOX(content_area),6); } - else - { - gtk_box_set_spacing( - GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), - 18 - ); - gtk_dialog_add_buttons( - GTK_DIALOG (dialog), - _("_Cancel"), GTK_RESPONSE_CANCEL, - _("_Load"), GTK_RESPONSE_APPLY, - NULL - ); - } + gtk_widget_set_sensitive(gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog),GTK_RESPONSE_APPLY),FALSE); + } diff --git a/src/dialogs/save/save.c b/src/dialogs/save/save.c index 8c2ea65..915c077 100644 --- a/src/dialogs/save/save.c +++ b/src/dialogs/save/save.c @@ -345,7 +345,7 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ if(!v3270_dialog_get_use_header()) { GtkWidget * content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); - gtk_box_set_spacing(GTK_BOX(content_area),3); + gtk_box_set_spacing(GTK_BOX(content_area),6); } gtk_widget_set_sensitive(gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog),GTK_RESPONSE_APPLY),FALSE); diff --git a/src/dialogs/tools.c b/src/dialogs/tools.c index e57b34d..ca527f6 100644 --- a/src/dialogs/tools.c +++ b/src/dialogs/tools.c @@ -218,10 +218,6 @@ gboolean v3270_dialog_get_use_header() { -#ifdef DEBUG - return FALSE; -#endif // DEBUG - #ifdef _WIN32 return FALSE; #elif GTK_CHECK_VERSION(3,12,0) -- libgit2 0.21.2