diff --git a/src/gtk/dialog.c b/src/gtk/dialog.c index 2587e59..c9ba071 100644 --- a/src/gtk/dialog.c +++ b/src/gtk/dialog.c @@ -194,8 +194,21 @@ void save_all_action(GtkAction *action, GtkWidget *widget) { + gchar *text = v3270_get_text(widget); + trace("Action %s activated on widget %p",gtk_action_get_name(action),widget); + if(!text) + return; + + save_dialog( action, + widget, + N_( "Save screen to file" ), + N_( "Can't save screen to file \n%s" ), + text); + + g_free(text); + } void save_selected_action(GtkAction *action, GtkWidget *widget) diff --git a/src/gtk/v3270/clipboard.c b/src/gtk/v3270/clipboard.c index d5f9ad1..9524a22 100644 --- a/src/gtk/v3270/clipboard.c +++ b/src/gtk/v3270/clipboard.c @@ -75,6 +75,27 @@ static void clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection, } } +gchar * v3270_get_text(GtkWidget *widget) +{ + v3270 * terminal; + gchar * text; + char * str; + + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); + + terminal = GTK_V3270(widget); + + str = lib3270_get_text(terminal->host); + + if(!str) + return NULL; + + text = g_convert(str, -1, "UTF-8", lib3270_get_charset(terminal->host), NULL, NULL, NULL); + + free(str); + return text; +} + const gchar * v3270_get_selected_text(GtkWidget *widget) { v3270 *terminal; diff --git a/src/gtk/v3270/v3270.h b/src/gtk/v3270/v3270.h index aaa6f7a..d6c6908 100644 --- a/src/gtk/v3270/v3270.h +++ b/src/gtk/v3270/v3270.h @@ -202,6 +202,7 @@ // Clipboard const gchar * v3270_get_selected_text(GtkWidget *widget); + gchar * v3270_get_text(GtkWidget *widget); void v3270_copy_clipboard(GtkWidget *widget); void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding); void v3270_paste_clipboard(GtkWidget *widget); diff --git a/src/include/lib3270.h b/src/include/lib3270.h index dfe0d4b..e96ca02 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -637,6 +637,15 @@ */ LIB3270_EXPORT char * lib3270_get_selected(H3270 *h); + /** + * Get all text inside the terminal. + * + * @param h Session Handle. + * + * @return All text if available, or NULL. Release it with free() + * + */ + LIB3270_EXPORT char * lib3270_get_text(H3270 *h); LIB3270_EXPORT int lib3270_set_model(H3270 *session, int model); LIB3270_EXPORT int lib3270_get_model(H3270 *session); diff --git a/src/lib3270/selection.c b/src/lib3270/selection.c index 3d1fa22..72f6934 100644 --- a/src/lib3270/selection.c +++ b/src/lib3270/selection.c @@ -313,13 +313,13 @@ LIB3270_ACTION( reselect ) return 0; } -LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) +static char * get_text(H3270 *hSession,unsigned char all) { int row, col, baddr; char *ret; size_t sz = 0; - if(!hSession->selected || hSession->select.begin == hSession->select.end) + if(!lib3270_connected(hSession)) return NULL; ret = malloc(hSession->rows * (hSession->cols+1)); @@ -331,7 +331,7 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) for(col = 0; col < hSession->cols;col++) { - if(hSession->text[baddr].attr & LIB3270_ATTR_SELECTED) + if(all || hSession->text[baddr].attr & LIB3270_ATTR_SELECTED) { cr++; ret[sz++] = hSession->text[baddr].chr; @@ -347,6 +347,19 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) return realloc(ret,sz+1); } +LIB3270_EXPORT char * lib3270_get_text(H3270 *hSession) +{ + return get_text(hSession,1); +} + +LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) +{ + if(!hSession->selected || hSession->select.begin == hSession->select.end) + return NULL; + + return get_text(hSession,0); +} + LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir) { if(!hSession->selected || hSession->select.begin == hSession->select.end) -- libgit2 0.21.2