Commit f24b2b22e1828692156a730a9e162765059bea9c

Authored by Perry Werneck
1 parent 6e737ce0
Exists in master and in 1 other branch develop

Adjustments on 'load' dialog.

src/dialogs/load.c
... ... @@ -35,6 +35,7 @@
35 35 #include <clipboard.h>
36 36 #include <limits.h>
37 37 #include <v3270/dialogs.h>
  38 + #include <v3270/tools.h>
38 39  
39 40 /*--[ Widget definition ]----------------------------------------------------------------------------*/
40 41  
... ... @@ -73,16 +74,7 @@
73 74  
74 75 }
75 76  
76   - static void cancel_operation(GtkButton G_GNUC_UNUSED(*button), GtkDialog *dialog)
77   - {
78   - gtk_dialog_response(dialog,GTK_RESPONSE_CANCEL);
79   - }
80   -
81   - static void apply_operation(GtkButton G_GNUC_UNUSED(*button), GtkDialog *dialog)
82   - {
83   - gtk_dialog_response(dialog,GTK_RESPONSE_APPLY);
84   - }
85   -
  77 +/*
86 78 #ifdef WIN32
87 79 static void icon_press(GtkEntry G_GNUC_UNUSED(*entry), G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G_GNUC_UNUSED GdkEvent *event, V3270LoadDialog *widget)
88 80 {
... ... @@ -128,9 +120,38 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_
128 120  
129 121 }
130 122 #endif // _WIN32
  123 +*/
131 124  
132   - static void V3270LoadDialog_init(V3270LoadDialog *dialog)
133   - {
  125 + static void filename_changed(GtkEntry *entry, V3270LoadDialog *dialog) {
  126 +
  127 + const gchar * text = gtk_entry_get_text(entry);
  128 + GtkWidget * button = gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog),GTK_RESPONSE_APPLY);
  129 +
  130 + if(!(text && *text)) {
  131 + gtk_widget_set_sensitive(button,FALSE);
  132 + return;
  133 + }
  134 +
  135 + if(g_str_has_suffix(text,G_DIR_SEPARATOR_S)) {
  136 + gtk_widget_set_sensitive(button,FALSE);
  137 + return;
  138 + }
  139 +
  140 + g_autofree gchar * dirname = g_path_get_dirname(text);
  141 +
  142 + if(!g_file_test(dirname,G_FILE_TEST_IS_DIR)) {
  143 + gtk_widget_set_sensitive(button,FALSE);
  144 + return;
  145 + }
  146 +
  147 +
  148 + // g_autofree gchar * basename = g_path_get_basename(text);
  149 +
  150 +
  151 + gtk_widget_set_sensitive(button,TRUE);
  152 + }
  153 +
  154 + static void V3270LoadDialog_init(V3270LoadDialog *dialog) {
134 155 // 0--------1---------------------2-------3--------------------4
135 156 // 0 - Filename xxxxxxxxx.xxxxxxxxx.xxxxxxxxx.xxxxxxxxx.xxxxxxxxx. x
136 157 // 1 - Charset xxxxxxxxx.xxxxxxxxx. Format: xxxxxxxxx.xxxxxxxxx.
... ... @@ -141,7 +162,6 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_
141 162 // Setup visual elements
142 163 // https://developer.gnome.org/hig/stable/visual-layout.html.en
143 164 GtkWidget *widget;
144   - GtkWidget *button;
145 165  
146 166 GtkBox * box = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
147 167 gtk_window_set_resizable(GTK_WINDOW(dialog),FALSE);
... ... @@ -166,10 +186,23 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_
166 186 gtk_grid_attach(grid,widget,0,0,1,1);
167 187 gtk_label_set_mnemonic_widget(GTK_LABEL(widget),dialog->filename);
168 188  
  189 + /*
169 190 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,"document-open");
170 191 gtk_entry_set_icon_activatable(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,TRUE);
171 192 gtk_entry_set_icon_tooltip_text(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,_("Select file"));
172 193 g_signal_connect(G_OBJECT(dialog->filename),"icon-press",G_CALLBACK(icon_press),dialog);
  194 + */
  195 +
  196 + g_signal_connect(dialog->filename,"changed",G_CALLBACK(filename_changed),dialog);
  197 +
  198 + gtk_entry_bind_to_filechooser(
  199 + dialog->filename,
  200 + GTK_FILE_CHOOSER_ACTION_OPEN,
  201 + _( "Select file" ),
  202 + NULL,
  203 + "*.txt",
  204 + _("Text files")
  205 + );
173 206  
174 207 gtk_entry_set_width_chars(GTK_ENTRY(dialog->filename),60);
175 208 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_
191 224  
192 225 // Buttons
193 226 // https://developer.gnome.org/icon-naming-spec/
194   -#ifdef _WIN32
195   - widget = NULL;
196   -#elif GTK_CHECK_VERSION(3,14,0)
197   - widget = gtk_dialog_get_header_bar(GTK_DIALOG(dialog));
198   -#else
199   - widget = NULL;
200   -#endif // GTK(3,14,0)
  227 + gtk_dialog_add_buttons(
  228 + GTK_DIALOG (dialog),
  229 + _("_Cancel"), GTK_RESPONSE_CANCEL,
  230 + _("_Load"), GTK_RESPONSE_APPLY,
  231 + NULL
  232 + );
201 233  
202   - if(widget)
203   - {
204   - // Have header bar
205   - button = gtk_button_new_with_mnemonic(_("_Cancel"));
206   - gtk_widget_set_tooltip_markup(button,_("Click to cancel operation"));
207   - gtk_header_bar_pack_start(GTK_HEADER_BAR(widget),button);
208   - g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(cancel_operation),dialog);
209   -
210   - button = gtk_button_new_with_mnemonic(_("_Load"));
211   - gtk_widget_set_tooltip_markup(button,_("Click to load file"));
212   - gtk_header_bar_pack_end(GTK_HEADER_BAR(widget),button);
213   - g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(apply_operation),dialog);
  234 + if(!v3270_dialog_get_use_header()) {
  235 + GtkWidget * content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
  236 + gtk_box_set_spacing(GTK_BOX(content_area),6);
214 237 }
215   - else
216   - {
217   - gtk_box_set_spacing(
218   - GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
219   - 18
220   - );
221 238  
222   - gtk_dialog_add_buttons(
223   - GTK_DIALOG (dialog),
224   - _("_Cancel"), GTK_RESPONSE_CANCEL,
225   - _("_Load"), GTK_RESPONSE_APPLY,
226   - NULL
227   - );
228   - }
  239 + gtk_widget_set_sensitive(gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog),GTK_RESPONSE_APPLY),FALSE);
  240 +
229 241  
230 242 }
231 243  
... ...
src/dialogs/save/save.c
... ... @@ -345,7 +345,7 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_
345 345  
346 346 if(!v3270_dialog_get_use_header()) {
347 347 GtkWidget * content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
348   - gtk_box_set_spacing(GTK_BOX(content_area),3);
  348 + gtk_box_set_spacing(GTK_BOX(content_area),6);
349 349 }
350 350  
351 351 gtk_widget_set_sensitive(gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog),GTK_RESPONSE_APPLY),FALSE);
... ...
src/dialogs/tools.c
... ... @@ -218,10 +218,6 @@
218 218  
219 219 gboolean v3270_dialog_get_use_header() {
220 220  
221   -#ifdef DEBUG
222   - return FALSE;
223   -#endif // DEBUG
224   -
225 221 #ifdef _WIN32
226 222 return FALSE;
227 223 #elif GTK_CHECK_VERSION(3,12,0)
... ...