Commit 04a2ace804477886338b119b1969ae7592ca502b
1 parent
7abe674b
Exists in
master
and in
5 other branches
Ativando opção para salvamento do buffer do terminal em um arquivo texto
Showing
5 changed files
with
60 additions
and
3 deletions
Show diff stats
src/gtk/dialog.c
... | ... | @@ -194,8 +194,21 @@ |
194 | 194 | |
195 | 195 | void save_all_action(GtkAction *action, GtkWidget *widget) |
196 | 196 | { |
197 | + gchar *text = v3270_get_text(widget); | |
198 | + | |
197 | 199 | trace("Action %s activated on widget %p",gtk_action_get_name(action),widget); |
198 | 200 | |
201 | + if(!text) | |
202 | + return; | |
203 | + | |
204 | + save_dialog( action, | |
205 | + widget, | |
206 | + N_( "Save screen to file" ), | |
207 | + N_( "Can't save screen to file \n%s" ), | |
208 | + text); | |
209 | + | |
210 | + g_free(text); | |
211 | + | |
199 | 212 | } |
200 | 213 | |
201 | 214 | void save_selected_action(GtkAction *action, GtkWidget *widget) | ... | ... |
src/gtk/v3270/clipboard.c
... | ... | @@ -75,6 +75,27 @@ static void clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection, |
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
78 | +gchar * v3270_get_text(GtkWidget *widget) | |
79 | +{ | |
80 | + v3270 * terminal; | |
81 | + gchar * text; | |
82 | + char * str; | |
83 | + | |
84 | + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | |
85 | + | |
86 | + terminal = GTK_V3270(widget); | |
87 | + | |
88 | + str = lib3270_get_text(terminal->host); | |
89 | + | |
90 | + if(!str) | |
91 | + return NULL; | |
92 | + | |
93 | + text = g_convert(str, -1, "UTF-8", lib3270_get_charset(terminal->host), NULL, NULL, NULL); | |
94 | + | |
95 | + free(str); | |
96 | + return text; | |
97 | +} | |
98 | + | |
78 | 99 | const gchar * v3270_get_selected_text(GtkWidget *widget) |
79 | 100 | { |
80 | 101 | v3270 *terminal; | ... | ... |
src/gtk/v3270/v3270.h
... | ... | @@ -202,6 +202,7 @@ |
202 | 202 | |
203 | 203 | // Clipboard |
204 | 204 | const gchar * v3270_get_selected_text(GtkWidget *widget); |
205 | + gchar * v3270_get_text(GtkWidget *widget); | |
205 | 206 | void v3270_copy_clipboard(GtkWidget *widget); |
206 | 207 | void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding); |
207 | 208 | void v3270_paste_clipboard(GtkWidget *widget); | ... | ... |
src/include/lib3270.h
... | ... | @@ -637,6 +637,15 @@ |
637 | 637 | */ |
638 | 638 | LIB3270_EXPORT char * lib3270_get_selected(H3270 *h); |
639 | 639 | |
640 | + /** | |
641 | + * Get all text inside the terminal. | |
642 | + * | |
643 | + * @param h Session Handle. | |
644 | + * | |
645 | + * @return All text if available, or NULL. Release it with free() | |
646 | + * | |
647 | + */ | |
648 | + LIB3270_EXPORT char * lib3270_get_text(H3270 *h); | |
640 | 649 | |
641 | 650 | LIB3270_EXPORT int lib3270_set_model(H3270 *session, int model); |
642 | 651 | LIB3270_EXPORT int lib3270_get_model(H3270 *session); | ... | ... |
src/lib3270/selection.c
... | ... | @@ -313,13 +313,13 @@ LIB3270_ACTION( reselect ) |
313 | 313 | return 0; |
314 | 314 | } |
315 | 315 | |
316 | -LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) | |
316 | +static char * get_text(H3270 *hSession,unsigned char all) | |
317 | 317 | { |
318 | 318 | int row, col, baddr; |
319 | 319 | char *ret; |
320 | 320 | size_t sz = 0; |
321 | 321 | |
322 | - if(!hSession->selected || hSession->select.begin == hSession->select.end) | |
322 | + if(!lib3270_connected(hSession)) | |
323 | 323 | return NULL; |
324 | 324 | |
325 | 325 | ret = malloc(hSession->rows * (hSession->cols+1)); |
... | ... | @@ -331,7 +331,7 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) |
331 | 331 | |
332 | 332 | for(col = 0; col < hSession->cols;col++) |
333 | 333 | { |
334 | - if(hSession->text[baddr].attr & LIB3270_ATTR_SELECTED) | |
334 | + if(all || hSession->text[baddr].attr & LIB3270_ATTR_SELECTED) | |
335 | 335 | { |
336 | 336 | cr++; |
337 | 337 | ret[sz++] = hSession->text[baddr].chr; |
... | ... | @@ -347,6 +347,19 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) |
347 | 347 | return realloc(ret,sz+1); |
348 | 348 | } |
349 | 349 | |
350 | +LIB3270_EXPORT char * lib3270_get_text(H3270 *hSession) | |
351 | +{ | |
352 | + return get_text(hSession,1); | |
353 | +} | |
354 | + | |
355 | +LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) | |
356 | +{ | |
357 | + if(!hSession->selected || hSession->select.begin == hSession->select.end) | |
358 | + return NULL; | |
359 | + | |
360 | + return get_text(hSession,0); | |
361 | +} | |
362 | + | |
350 | 363 | LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir) |
351 | 364 | { |
352 | 365 | if(!hSession->selected || hSession->select.begin == hSession->select.end) | ... | ... |