diff --git a/src/gtk/actions.c b/src/gtk/actions.c index 5d51a27..e84322a 100644 --- a/src/gtk/actions.c +++ b/src/gtk/actions.c @@ -97,8 +97,35 @@ static void reload_action(GtkAction *action, GtkWidget *widget) static void copy_action(GtkAction *action, GtkWidget *widget) { - trace("Action %s activated on widget %p",gtk_action_get_name(action),widget); - v3270_copy(widget); + V3270_SELECT_FORMAT mode = V3270_SELECT_TEXT; + const gchar * str = (const gchar *) g_object_get_data(G_OBJECT(action),"format"); + + if(str) + { + static const struct _format + { + V3270_SELECT_FORMAT mode; + const gchar * name; + } format[] = + { + { V3270_SELECT_TEXT, "text" }, + { V3270_SELECT_TABLE, "table" }, + }; + + int f; + + for(f=0;fhost); + if(text) + { + gchar *str = g_strdup(text); + free(text); + return str; + } + return NULL; +} + const gchar * v3270_get_selected_text(GtkWidget *widget) { v3270 *terminal; @@ -111,7 +123,7 @@ const gchar * v3270_get_selected_text(GtkWidget *widget) terminal->clipboard = NULL; } - text = lib3270_get_selected(terminal->host); + text = v3270_get_selected(terminal); if(!text) { @@ -120,9 +132,85 @@ const gchar * v3270_get_selected_text(GtkWidget *widget) return NULL; } + if(terminal->table) + { + // Convert text to table + gchar **ln = g_strsplit(text,"\n",-1); + int width = lib3270_get_width(terminal->host); + gboolean cols[width]; + int l; + GString * buffer; + + memset(cols,0,sizeof(gboolean)*width); + + // Find column delimiters + for(l=0;ln[l];l++) + { + int c; + gchar * ptr = ln[l]; + GString * buffer; + + for(c=0;cclipboard = g_convert(text, -1, "UTF-8", lib3270_get_charset(terminal->host), NULL, NULL, NULL); - free(text); + g_free(text); + return terminal->clipboard; } @@ -175,11 +263,17 @@ const gchar * v3270_copy_append(GtkWidget *widget) return terminal->clipboard; } -const gchar * v3270_copy(GtkWidget *widget) +const gchar * v3270_copy(GtkWidget *widget, V3270_SELECT_FORMAT mode) { - const gchar * text = v3270_get_selected_text(widget); + const gchar * text; GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD); + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); + + GTK_V3270(widget)->table = (mode == V3270_SELECT_TABLE ? 1 : 0); + + text = v3270_get_selected_text(widget); + if(text) { if(gtk_clipboard_set_with_owner( clipboard, diff --git a/src/gtk/v3270/private.h b/src/gtk/v3270/private.h index 9dc74b3..1dfc855 100644 --- a/src/gtk/v3270/private.h +++ b/src/gtk/v3270/private.h @@ -121,10 +121,11 @@ G_BEGIN_DECLS { GtkWidget parent; - // private + // flags int selecting : 1; /**< Selecting region */ int moving : 1; /**< Moving selected region */ int resizing : 1; /**< Resizing selected region */ + int table : 1; /**< Copy mode is table */ #if GTK_CHECK_VERSION(3,0,0) diff --git a/src/gtk/v3270/v3270.h b/src/gtk/v3270/v3270.h index d1f8843..0291057 100644 --- a/src/gtk/v3270/v3270.h +++ b/src/gtk/v3270/v3270.h @@ -142,11 +142,20 @@ void v3270_disconnect(GtkWidget *widget); // Clipboard + typedef enum _v3270_select_format + { + V3270_SELECT_TEXT, + V3270_SELECT_TABLE, + + V3270_SELECT_MAX + } V3270_SELECT_FORMAT; + + const gchar * v3270_copy(GtkWidget *widget, V3270_SELECT_FORMAT mode); + const gchar * v3270_copy_append(GtkWidget *widget); + const gchar * v3270_get_selected_text(GtkWidget *widget); const gchar * v3270_get_copy(GtkWidget *widget); gchar * v3270_get_text(GtkWidget *widget,int offset, int len); - const gchar * v3270_copy(GtkWidget *widget); - const gchar * v3270_copy_append(GtkWidget *widget); void v3270_paste(GtkWidget *widget); void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding); diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 2c44bde..3f55a3d 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -267,6 +267,17 @@ */ LIB3270_EXPORT void lib3270_get_screen_size(H3270 *h, int *r, int *c); + + /** + * Get current screen width in columns. + * + * @param h Handle of the desired session. + * + * @return screen width. + * + */ + LIB3270_EXPORT int lib3270_get_width(H3270 *h); + LIB3270_EXPORT unsigned int lib3270_get_length(H3270 *h); /** diff --git a/src/lib3270/screen.c b/src/lib3270/screen.c index e300441..d841221 100644 --- a/src/lib3270/screen.c +++ b/src/lib3270/screen.c @@ -244,6 +244,12 @@ LIB3270_EXPORT void lib3270_get_screen_size(H3270 *h, int *r, int *c) *c = h->cols; } +LIB3270_EXPORT int lib3270_get_width(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return h->cols; +} + void update_model_info(H3270 *session, int model, int cols, int rows) { if(model == session->model_num && session->maxROWS == rows && session->maxCOLS == cols) diff --git a/ui/00default.xml b/ui/00default.xml index 2f2a4f3..06f4f82 100644 --- a/ui/00default.xml +++ b/ui/00default.xml @@ -57,10 +57,10 @@ - - + + - + @@ -144,7 +144,7 @@ - + @@ -161,8 +161,8 @@ - - + + -- libgit2 0.21.2