From 057233e1f21337281df2f208c56e916edcd54e6d Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Mon, 29 Jul 2019 14:46:20 -0300 Subject: [PATCH] Finishing the new "save" dialog. --- src/dialogs/save/save.c | 11 +++++++---- src/include/clipboard.h | 10 +++++----- src/selection/copy.c | 2 +- src/selection/html.c | 20 ++++++++++---------- src/selection/table.c | 18 +++++++++--------- src/selection/text.c | 6 +++--- 6 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/dialogs/save/save.c b/src/dialogs/save/save.c index c03e275..68175ab 100644 --- a/src/dialogs/save/save.c +++ b/src/dialogs/save/save.c @@ -335,6 +335,9 @@ static void icon_press(G_GNUC_UNUSED GtkEntry *entry, G_GNUC_UNUSED GtkEntryIcon switch(dialog->mode) { case LIB3270_CONTENT_ALL: + dynamic = g_new0(GList,1); + dynamic->data = (gpointer) lib3270_get_selection(v3270_get_session(dialog->terminal),0,1); + selection = dynamic; break; case LIB3270_CONTENT_COPY: @@ -343,7 +346,7 @@ static void icon_press(G_GNUC_UNUSED GtkEntry *entry, G_GNUC_UNUSED GtkEntryIcon case LIB3270_CONTENT_SELECTED: dynamic = g_new0(GList,1); - dynamic->data = (gpointer) lib3270_get_selection(v3270_get_session(dialog->terminal),0); + dynamic->data = (gpointer) lib3270_get_selection(v3270_get_session(dialog->terminal),0,0); selection = dynamic; break; @@ -366,15 +369,15 @@ static void icon_press(G_GNUC_UNUSED GtkEntry *entry, G_GNUC_UNUSED GtkEntryIcon switch(gtk_combo_box_get_active(GTK_COMBO_BOX(dialog->format))) { case 0: // "Plain text" - text = v3270_get_selection_as_text(GTK_V3270(dialog->terminal), selection, encoding); + text = v3270_get_selection_as_text(GTK_V3270(dialog->terminal), selection, encoding, dialog->mode == LIB3270_CONTENT_ALL); break; case 1: // "Comma-separated values (CSV)" - text = v3270_get_selection_as_table(GTK_V3270(dialog->terminal),selection,";",encoding); + text = v3270_get_selection_as_table(GTK_V3270(dialog->terminal),selection,";",encoding, dialog->mode == LIB3270_CONTENT_ALL); break; case 2: // "HyperText Markup Language (HTML)" - text = v3270_get_selection_as_html_div(GTK_V3270(dialog->terminal),selection,encoding); + text = v3270_get_selection_as_html_div(GTK_V3270(dialog->terminal),selection,encoding, dialog->mode == LIB3270_CONTENT_ALL); break; default: diff --git a/src/include/clipboard.h b/src/include/clipboard.h index 592630f..11e7318 100644 --- a/src/include/clipboard.h +++ b/src/include/clipboard.h @@ -87,13 +87,13 @@ G_GNUC_INTERNAL void v3270_update_system_clipboard(GtkWidget *widget); G_GNUC_INTERNAL const char * v3270_update_selected_text(GtkWidget *widget, gboolean cut); - G_GNUC_INTERNAL GList * v3270_getColumns_from_selection(v3270 * terminal, const GList *selection); + G_GNUC_INTERNAL GList * v3270_getColumns_from_selection(v3270 * terminal, const GList *selection, gboolean all); /// @brief Get contents. - G_GNUC_INTERNAL gchar * v3270_get_selection_as_text(v3270 * terminal, const GList *selection, const gchar *encoding); - G_GNUC_INTERNAL gchar * v3270_get_selection_as_table(v3270 * terminal, const GList *selection, const gchar *delimiter, const gchar *encoding); - G_GNUC_INTERNAL gchar * v3270_get_selection_as_html_div(v3270 * terminal, const GList *selection, const gchar *encoding); - G_GNUC_INTERNAL gchar * v3270_get_selection_as_html_table(v3270 * terminal, const GList *selection, const gchar *encoding); + G_GNUC_INTERNAL gchar * v3270_get_selection_as_text(v3270 * terminal, const GList *selection, const gchar *encoding, gboolean all); + G_GNUC_INTERNAL gchar * v3270_get_selection_as_table(v3270 * terminal, const GList *selection, const gchar *delimiter, const gchar *encoding, gboolean all); + G_GNUC_INTERNAL gchar * v3270_get_selection_as_html_div(v3270 * terminal, const GList *selection, const gchar *encoding, gboolean all); + G_GNUC_INTERNAL gchar * v3270_get_selection_as_html_table(v3270 * terminal, const GList *selection, const gchar *encoding, gboolean all); G_GNUC_INTERNAL const GList * v3270_get_selection_blocks(GtkWidget *widget); diff --git a/src/selection/copy.c b/src/selection/copy.c index d94a1a7..762599f 100644 --- a/src/selection/copy.c +++ b/src/selection/copy.c @@ -32,7 +32,7 @@ static void do_copy(v3270 *terminal, gboolean cut) { - lib3270_selection * selection = lib3270_get_selection(terminal->host,cut); + lib3270_selection * selection = lib3270_get_selection(terminal->host,cut,0); if(selection) { diff --git a/src/selection/html.c b/src/selection/html.c index 9363464..8e72e6d 100644 --- a/src/selection/html.c +++ b/src/selection/html.c @@ -49,7 +49,7 @@ static void get_element_colors(v3270 * terminal, unsigned short attr, gchar **fg } /// @brief Get formatted contents as HTML DIV. -static gchar * get_as_div(v3270 * terminal, const GList *selection) +static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all) { const GList * element = selection; GString * string = g_string_new(""); @@ -110,7 +110,7 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection) } - if(block->contents[src].attribute.visual & LIB3270_ATTR_SELECTED && !isspace(block->contents[src].chr)) + if( (block->contents[src].attribute.visual & LIB3270_ATTR_SELECTED || all) && !isspace(block->contents[src].chr)) { g_string_append_c(string,block->contents[src].chr); } @@ -144,7 +144,7 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection) } /// @brief Get formatted contents as HTML TABLE. -static gchar * get_as_table(v3270 * terminal, const GList *selection) +static gchar * get_as_table(v3270 * terminal, const GList *selection, gboolean all) { const GList * element = selection; GString * string = g_string_new(""); @@ -155,7 +155,7 @@ static gchar * get_as_table(v3270 * terminal, const GList *selection) GList * column; // Get contents - GList * columns = v3270_getColumns_from_selection(terminal, selection); + GList * columns = v3270_getColumns_from_selection(terminal, selection, all); while(element) { @@ -214,15 +214,15 @@ static gchar * get_as_table(v3270 * terminal, const GList *selection) } -gchar * v3270_get_selection_as_html_div(v3270 * terminal, const GList *selection, const gchar *encoding) +gchar * v3270_get_selection_as_html_div(v3270 * terminal, const GList *selection, const gchar *encoding, gboolean all) { - g_autofree char * text = get_as_div(terminal, selection); + g_autofree char * text = get_as_div(terminal, selection, all); return g_convert(text, -1, (encoding ? encoding : "UTF-8"), lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); } -gchar * v3270_get_selection_as_html_table(v3270 * terminal, const GList *selection, const gchar *encoding) +gchar * v3270_get_selection_as_html_table(v3270 * terminal, const GList *selection, const gchar *encoding, gboolean all) { - g_autofree char * text = get_as_table(terminal, selection); + g_autofree char * text = get_as_table(terminal, selection, all); return g_convert(text, -1, (encoding ? encoding : "UTF-8"), lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); } @@ -230,8 +230,8 @@ gchar * v3270_get_copy_as_html(v3270 * terminal, const gchar *encoding) { if(terminal->selection.format == V3270_SELECT_TABLE) - return v3270_get_selection_as_html_table(terminal, terminal->selection.blocks, encoding); + return v3270_get_selection_as_html_table(terminal, terminal->selection.blocks, encoding, FALSE); - return v3270_get_selection_as_html_div(terminal, terminal->selection.blocks, encoding); + return v3270_get_selection_as_html_div(terminal, terminal->selection.blocks, encoding, FALSE); } diff --git a/src/selection/table.c b/src/selection/table.c index e133ddc..372d007 100644 --- a/src/selection/table.c +++ b/src/selection/table.c @@ -34,7 +34,7 @@ /*--[ Implement ]------------------------------------------------------------------------------------*/ /// @brief Check if column has data. -static gboolean hasDataOnColumn(v3270 * terminal, unsigned int col, const GList *selection) +static gboolean hasDataOnColumn(v3270 * terminal, unsigned int col, const GList *selection, gboolean all) { while(selection) { @@ -47,7 +47,7 @@ static gboolean hasDataOnColumn(v3270 * terminal, unsigned int col, const GList for(row = 0; row < block->bounds.height; row++) { - if( (block->contents[pos].attribute.visual & LIB3270_ATTR_SELECTED) && !isspace(block->contents[pos].chr)) + if( ((block->contents[pos].attribute.visual & LIB3270_ATTR_SELECTED) || all) && !isspace(block->contents[pos].chr)) { return TRUE; } @@ -63,7 +63,7 @@ static gboolean hasDataOnColumn(v3270 * terminal, unsigned int col, const GList } /// @brief Get column list. -GList * v3270_getColumns_from_selection(v3270 * terminal, const GList *selection) +GList * v3270_getColumns_from_selection(v3270 * terminal, const GList *selection, gboolean all) { unsigned int col = 0; GList *rc = NULL; @@ -73,7 +73,7 @@ GList * v3270_getColumns_from_selection(v3270 * terminal, const GList *selection // debug("col(%u): %s", col, hasDataOnColumn(terminal,col) ? "yes" : "no"); // Get first column. - while(!hasDataOnColumn(terminal,col,selection)) { + while(!hasDataOnColumn(terminal,col,selection,all)) { if(col >= lib3270_get_width(terminal->host)) return rc; col++; @@ -85,7 +85,7 @@ GList * v3270_getColumns_from_selection(v3270 * terminal, const GList *selection rc = g_list_append(rc,columndescription); // Get width. - while(hasDataOnColumn(terminal,col++,selection)) { + while(hasDataOnColumn(terminal,col++,selection,all)) { columndescription->width++; if(col >= lib3270_get_width(terminal->host)) return rc; @@ -96,11 +96,11 @@ GList * v3270_getColumns_from_selection(v3270 * terminal, const GList *selection } -gchar * v3270_get_selection_as_table(v3270 * terminal, const GList *selection, const gchar *delimiter, const gchar *encoding) +gchar * v3270_get_selection_as_table(v3270 * terminal, const GList *selection, const gchar *delimiter, const gchar *encoding, gboolean all) { GString * string = g_string_new(""); - GList * columns = v3270_getColumns_from_selection(terminal, selection); + GList * columns = v3270_getColumns_from_selection(terminal, selection, all); debug("columns=%p",columns); @@ -136,7 +136,7 @@ gchar * v3270_get_selection_as_table(v3270 * terminal, const GList *selection, c memset(line,' ',width); for(col=0; colbounds.width; col++) { - if(block->contents[src].attribute.visual & LIB3270_ATTR_SELECTED) + if((block->contents[src].attribute.visual & LIB3270_ATTR_SELECTED) || all) { line[block->bounds.col+col] = block->contents[src].chr; } @@ -170,6 +170,6 @@ gchar * v3270_get_selection_as_table(v3270 * terminal, const GList *selection, c /// @brief Get formatted contents as single text. gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter, const gchar *encoding) { - return v3270_get_selection_as_table(terminal, terminal->selection.blocks, delimiter, encoding); + return v3270_get_selection_as_table(terminal, terminal->selection.blocks, delimiter, encoding, FALSE); } diff --git a/src/selection/text.c b/src/selection/text.c index b9a1102..e85626d 100644 --- a/src/selection/text.c +++ b/src/selection/text.c @@ -33,7 +33,7 @@ /*--[ Implement ]------------------------------------------------------------------------------------*/ /// @brief Get formatted contents as single text. -gchar * v3270_get_selection_as_text(v3270 * terminal, const GList *selection, const gchar *encoding) +gchar * v3270_get_selection_as_text(v3270 * terminal, const GList *selection, const gchar *encoding, gboolean all) { GString * string = g_string_new(""); @@ -46,7 +46,7 @@ gchar * v3270_get_selection_as_text(v3270 * terminal, const GList *selection, co { for(col=0; colbounds.width; col++) { - if(block->contents[src].attribute.visual & LIB3270_ATTR_SELECTED) + if( (block->contents[src].attribute.visual & LIB3270_ATTR_SELECTED) || all ) g_string_append_c(string,block->contents[src].chr); src++; @@ -68,7 +68,7 @@ gchar * v3270_get_copy_as_text(v3270 * terminal, const gchar *encoding) { if(terminal->selection.format == V3270_SELECT_TABLE) return v3270_get_copy_as_table(terminal,"\t",encoding); - return v3270_get_selection_as_text(terminal, terminal->selection.blocks, encoding); + return v3270_get_selection_as_text(terminal, terminal->selection.blocks, encoding, FALSE); } LIB3270_EXPORT void v3270_input_text(GtkWidget *widget, const gchar *text, const gchar *encoding) -- libgit2 0.21.2