Commit 2d504fcfe926903b2d632d2dfcae7d8f4b61753a
1 parent
83b7128d
Exists in
master
and in
5 other branches
Experimentando com o diálogo padrão do windows.
Showing
2 changed files
with
61 additions
and
29 deletions
Show diff stats
src/pw3270/Makefile.in
| ... | ... | @@ -66,7 +66,8 @@ LIB_SOURCES= window.c actions.c fonts.c dialog.c hostdialog.c print.c colors.c \ |
| 66 | 66 | $(foreach SRC, $(UI_PARSER_SRC), uiparser/$(SRC)) \ |
| 67 | 67 | $(foreach SRC, $(V3270_SRC), v3270/$(SRC)) \ |
| 68 | 68 | $(foreach SRC, $(COMMON_SRC), common/$(SRC)) \ |
| 69 | - filetransfer.c ft/ftdialog.c ft/ftprogress.c | |
| 69 | + filetransfer.c ft/ftdialog.c ft/ftprogress.c \ | |
| 70 | + ft/browse.c | |
| 70 | 71 | |
| 71 | 72 | DEPENDS=*.h common/*.h uiparser/*.h v3270/*.h $(GLOBAL_DEPS) |
| 72 | 73 | ... | ... |
src/pw3270/ft/browse.c
| ... | ... | @@ -36,58 +36,89 @@ |
| 36 | 36 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
| 37 | 37 | |
| 38 | 38 | #ifdef WIN32 |
| 39 | + | |
| 40 | +struct file | |
| 41 | +{ | |
| 42 | + OPENFILENAME ofn; | |
| 43 | + char szName[260]; // buffer for file name | |
| 44 | + int mode; | |
| 45 | + BOOL ok; | |
| 46 | +}; | |
| 47 | + | |
| 48 | +static gpointer select_file(struct file *fl) | |
| 49 | +{ | |
| 50 | + if(fl->mode == 1) | |
| 51 | + { | |
| 52 | + fl->ok = GetSaveFileName(&fl->ofn); | |
| 53 | + } | |
| 54 | + else | |
| 55 | + { | |
| 56 | + fl->ok = GetOpenFileName(&fl->ofn); | |
| 57 | + } | |
| 58 | + | |
| 59 | + fl->mode = 3; | |
| 60 | + | |
| 61 | + return 0; | |
| 62 | +} | |
| 63 | + | |
| 39 | 64 | void browse_file(GtkButton *button,v3270FTD *parent) |
| 40 | 65 | { |
| 41 | - char szFile[260]; // buffer for file name | |
| 66 | + GThread * thd; | |
| 67 | + struct file fl; | |
| 42 | 68 | GdkWindow * win = gtk_widget_get_window(GTK_WIDGET(parent)); |
| 43 | 69 | |
| 44 | 70 | gtk_widget_set_sensitive(GTK_WIDGET(parent),FALSE); |
| 45 | 71 | |
| 46 | - OPENFILENAME ofn; | |
| 47 | - | |
| 48 | - memset(&ofn,0,sizeof(ofn)); | |
| 49 | - ofn.lStructSize = sizeof(ofn); | |
| 50 | - ofn.hwndOwner = GDK_WINDOW_HWND(win); | |
| 51 | - ofn.lpstrFile = szFile; | |
| 72 | + memset(&fl,0,sizeof(fl)); | |
| 73 | + fl.ofn.lStructSize = sizeof(fl.ofn); | |
| 74 | + fl.ofn.hwndOwner = GDK_WINDOW_HWND(win); | |
| 75 | + fl.ofn.lpstrFile = fl.szName; | |
| 52 | 76 | |
| 53 | 77 | // Set lpstrFile[0] to '\0' so that GetOpenFileName does not |
| 54 | 78 | // use the contents of szFile to initialize itself. |
| 55 | - ofn.lpstrFile[0] = '\0'; | |
| 79 | + fl.ofn.lpstrFile[0] = '\0'; | |
| 80 | + | |
| 81 | + fl.ofn.nMaxFile = sizeof(fl.szName); | |
| 82 | + fl.ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0"; | |
| 83 | + fl.ofn.nFilterIndex = 1; | |
| 84 | + fl.ofn.nMaxFileTitle = 0; | |
| 85 | + fl.ofn.lpstrInitialDir = NULL; | |
| 56 | 86 | |
| 57 | - ofn.nMaxFile = sizeof(szFile); | |
| 58 | - ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0"; | |
| 59 | - ofn.nFilterIndex = 1; | |
| 60 | - ofn.nMaxFileTitle = 0; | |
| 61 | - ofn.lpstrInitialDir = NULL; | |
| 87 | + // Guarda o valor atual | |
| 88 | + strncpy(fl.szName,gtk_entry_get_text(GTK_ENTRY(parent->filename[FILENAME_LOCAL])),fl.ofn.nMaxFile); | |
| 62 | 89 | |
| 63 | - if(parent->options & LIB3270_FT_OPTION_RECEIVE) | |
| 90 | + fl.mode = (parent->options & LIB3270_FT_OPTION_RECEIVE) ? 1 : 0; | |
| 91 | + | |
| 92 | + if(fl.mode == 1) | |
| 64 | 93 | { |
| 65 | 94 | // Receber arquivo |
| 66 | 95 | // https://msdn.microsoft.com/en-us/library/windows/desktop/ms646839(v=vs.85).aspx |
| 67 | 96 | // https://msdn.microsoft.com/en-us/library/windows/desktop/ms646829(v=vs.85).aspx#open_file |
| 68 | 97 | |
| 69 | -// ofn.lpstrFileTitle = _( "Select file to receive" ); | |
| 70 | - ofn.Flags = OFN_OVERWRITEPROMPT; | |
| 71 | - | |
| 72 | - if(GetSaveFileName(&ofn)==TRUE) | |
| 73 | - { | |
| 74 | - gtk_entry_set_text(GTK_ENTRY(parent->filename[FILENAME_LOCAL]),szFile); | |
| 75 | - } | |
| 98 | +// fl.ofn.lpstrFileTitle = _( "Select file to receive" ); | |
| 99 | + fl.ofn.Flags = OFN_OVERWRITEPROMPT; | |
| 76 | 100 | |
| 77 | 101 | } |
| 78 | 102 | else |
| 79 | 103 | { |
| 80 | 104 | // Enviar arquivo |
| 81 | 105 | // https://msdn.microsoft.com/en-us/library/windows/desktop/ms646928(v=vs.85).aspx |
| 82 | - OPENFILENAME ofn; | |
| 106 | +// fl.ofn.lpstrFileTitle = _( "Select file to send" ); | |
| 107 | + fl.ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; | |
| 83 | 108 | |
| 84 | -// ofn.lpstrFileTitle = _( "Select file to send" ); | |
| 85 | - ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; | |
| 109 | + } | |
| 86 | 110 | |
| 87 | - if(GetOpenFileName(&ofn)==TRUE) | |
| 88 | - { | |
| 89 | - gtk_entry_set_text(GTK_ENTRY(parent->filename[FILENAME_LOCAL]),szFile); | |
| 90 | - } | |
| 111 | + thd = g_thread_new("GetFileName",(GThreadFunc) select_file, &fl); | |
| 112 | + | |
| 113 | + while(fl.mode != 3) { | |
| 114 | + g_main_context_iteration(NULL,TRUE); | |
| 115 | + } | |
| 116 | + | |
| 117 | + g_thread_unref(thd); | |
| 118 | + | |
| 119 | + if(fl.ok) | |
| 120 | + { | |
| 121 | + gtk_entry_set_text(GTK_ENTRY(parent->filename[FILENAME_LOCAL]),fl.szName); | |
| 91 | 122 | } |
| 92 | 123 | |
| 93 | 124 | gtk_widget_set_sensitive(GTK_WIDGET(parent),TRUE); | ... | ... |