Commit d678623ce2b5f3e72864f5907310d7496f99fbea

Authored by Perry Werneck
1 parent 08322062

Testando em windows 32 & 64.

src/pw3270/include/v3270ft.h
... ... @@ -75,7 +75,7 @@
75 75 void v3270ft_append_file(GtkWidget *widget, const gchar *filename, gboolean text);
76 76 guint v3270ft_append_selection(GtkWidget *widget, GtkSelectionData *data);
77 77  
78   - gchar * v3270ft_select_file(v3270ft *dialog, const gchar *title, const gchar *button, GtkFileChooserAction action, const gchar *filename);
  78 + gchar * v3270ft_select_file(v3270ft *dialog, const gchar *title, const gchar *button, GtkFileChooserAction action, const gchar *filename, const gchar *filter, ... ) G_GNUC_NULL_TERMINATED;
79 79  
80 80 gint v3270ft_transfer(GtkWidget *dialog, H3270 *session);
81 81  
... ...
src/pw3270/v3270ft/select.c
... ... @@ -28,7 +28,8 @@
28 28 *
29 29 */
30 30  
31   - #include "private.h"
  31 +#include "private.h"
  32 +#include <stdarg.h>
32 33  
33 34 #ifdef WIN32
34 35 #include <gdk/gdkwin32.h>
... ... @@ -53,13 +54,13 @@ static gpointer select_file(struct file *fl) {
53 54 case GTK_FILE_CHOOSER_ACTION_SAVE: // Receber arquivo
54 55 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms646839(v=vs.85).aspx
55 56 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms646829(v=vs.85).aspx#open_file
56   - fl->ofn.Flags = OFN_OVERWRITEPROMPT;
  57 + fl->ofn.Flags = OFN_OVERWRITEPROMPT | OFN_CREATEPROMPT | OFN_HIDEREADONLY;
57 58 fl->ok = GetSaveFileName(&fl->ofn);
58 59 break;
59 60  
60 61 case GTK_FILE_CHOOSER_ACTION_OPEN: // Enviar arquivo
61 62 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms646928(v=vs.85).aspx
62   - fl->ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  63 + fl->ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
63 64 fl->ok = GetOpenFileName(&fl->ofn);
64 65 break;
65 66 }
... ... @@ -71,7 +72,7 @@ static gpointer select_file(struct file *fl) {
71 72  
72 73 #endif // _WIN32
73 74  
74   -gchar * v3270ft_select_file(v3270ft *dialog, const gchar *title, const gchar *button, GtkFileChooserAction action, const gchar *filename) {
  75 +gchar * v3270ft_select_file(v3270ft *dialog, const gchar *title, const gchar *button, GtkFileChooserAction action, const gchar *filename, const gchar *filter, ...) {
75 76  
76 77 gchar *rc = NULL;
77 78  
... ... @@ -113,10 +114,35 @@ gchar * v3270ft_select_file(v3270ft *dialog, const gchar *title, const gchar *bu
113 114 fl.ofn.lpstrFile[0] = '\0';
114 115  
115 116 fl.ofn.nMaxFile = sizeof(fl.szName);
116   - fl.ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
  117 +
  118 + // Monta lista de arquivos.
  119 + va_list args;
  120 + size_t ix = 0;
  121 +
  122 + fl.ofn.lpstrFilter = (char *) g_malloc0(4096);
  123 +
  124 + va_start (args, filter);
  125 + while(filter) {
  126 +
  127 + filter = gettext(filter);
  128 + size_t sz = strlen(filter)+1;
  129 +
  130 + if(ix+sz > 4095)
  131 + break;
  132 +
  133 + debug("%s",filter);
  134 +
  135 + memcpy(((char *) fl.ofn.lpstrFilter)+ix,filter,sz);
  136 + ix += sz;
  137 + filter = va_arg(args, const char *);
  138 + }
  139 + va_end (args);
  140 +
  141 + debug("%s",fl.ofn.lpstrFilter);
  142 +
117 143 fl.ofn.nFilterIndex = 1;
118   - fl.ofn.nMaxFileTitle = 0;
119 144 fl.ofn.lpstrInitialDir = NULL;
  145 + fl.ofn.nMaxFileTitle = 0;
120 146  
121 147 // Guarda o valor atual
122 148 if(filename)
... ... @@ -137,6 +163,7 @@ gchar * v3270ft_select_file(v3270ft *dialog, const gchar *title, const gchar *bu
137 163 rc = g_strdup(fl.szName);
138 164 }
139 165  
  166 + g_free( ((char *) fl.ofn.lpstrFilter) );
140 167 gtk_widget_set_sensitive(GTK_WIDGET(dialog),TRUE);
141 168  
142 169  
... ...
src/pw3270/v3270ft/v3270ft.c
... ... @@ -188,7 +188,13 @@ static void remove_file(GtkButton *button, v3270ft *dialog) {
188 188  
189 189 static void load_file(GtkButton *button, v3270ft *dialog) {
190 190  
191   - gchar * filename = v3270ft_select_file(dialog, _("Load queue from file"), _("Load"), GTK_FILE_CHOOSER_ACTION_OPEN, NULL);
  191 + gchar * filename = v3270ft_select_file(
  192 + dialog,
  193 + _("Load queue from file"),
  194 + _("Load"), GTK_FILE_CHOOSER_ACTION_OPEN,
  195 + "",
  196 + N_("XML file"), "*.xml",
  197 + NULL );
192 198  
193 199 if(filename) {
194 200 v3270ft_load(GTK_WIDGET(dialog),filename);
... ... @@ -201,7 +207,14 @@ static void load_file(GtkButton *button, v3270ft *dialog) {
201 207  
202 208 static void save_file(GtkButton *button, v3270ft *dialog) {
203 209  
204   - gchar * filename = v3270ft_select_file(dialog, _("Save queue to file"), _("Save"), GTK_FILE_CHOOSER_ACTION_SAVE, NULL);
  210 + gchar * filename = v3270ft_select_file(
  211 + dialog,
  212 + _("Save queue to file"),
  213 + _("Save"),
  214 + GTK_FILE_CHOOSER_ACTION_SAVE,
  215 + "",
  216 + N_("XML file"), "*.xml",
  217 + NULL );
205 218  
206 219 if(filename) {
207 220 v3270ft_save(GTK_WIDGET(dialog),filename);
... ... @@ -282,7 +295,15 @@ static void select_local_file(GtkButton *button, v3270ft *dialog) {
282 295 static void icon_press(GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event, v3270ft *dialog) {
283 296 #endif // WIN32
284 297  
285   - gchar *filename = v3270ft_select_file(dialog, _("Select local file"), _("Select"), GTK_FILE_CHOOSER_ACTION_OPEN, gtk_entry_get_text(dialog->local));
  298 + gchar *filename = v3270ft_select_file(
  299 + dialog,
  300 + _("Select local file"),
  301 + _("Select"),
  302 + GTK_FILE_CHOOSER_ACTION_OPEN,
  303 + gtk_entry_get_text(dialog->local),
  304 + N_("All files"), "*.*",
  305 + N_("Text files"), "*.txt",
  306 + NULL );
286 307  
287 308 if(filename) {
288 309  
... ...