Commit 574dbb76ae37c0c99702c92b42302727cb291e39

Authored by Perry Werneck
1 parent 60dd822f

Fixing "cut" & "copy" actions.

src/objects/actions/clipboard.c
... ... @@ -35,17 +35,55 @@
35 35 #include "private.h"
36 36 #include <v3270.h>
37 37  
38   - static void activate_copy(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) {
  38 + static V3270_COPY_MODE get_copy_mode_from_parameter(GVariant *parameter) {
  39 +
  40 + static const struct {
  41 + const gchar * name;
  42 + V3270_COPY_MODE value;
  43 + } targets[] = {
  44 + { "auto", V3270_COPY_DEFAULT },
  45 + { "system", V3270_COPY_DEFAULT },
  46 + { "default", V3270_COPY_DEFAULT },
  47 + { "system default", V3270_COPY_DEFAULT },
  48 + { "formatted", V3270_COPY_FORMATTED },
  49 + { "text", V3270_COPY_TEXT },
  50 + { "table", V3270_COPY_TABLE },
  51 + { "append", V3270_COPY_APPEND }
  52 +
  53 + };
  54 +
  55 + if(parameter) {
  56 +
  57 + const gchar * target = g_variant_get_string(parameter,NULL);
  58 +
  59 + if(target && *target) {
  60 +
  61 + size_t ix;
  62 + for(ix = 0; ix < G_N_ELEMENTS(targets); ix++) {
  63 +
  64 + if(!g_ascii_strcasecmp(target,targets[ix].name))
  65 + return targets[ix].value;
  66 +
  67 + }
  68 +
  69 + }
  70 +
  71 + }
  72 +
  73 + return V3270_COPY_DEFAULT;
  74 + }
  75 +
  76 + static void activate_copy(GAction G_GNUC_UNUSED(*action), GVariant *parameter, GtkWidget *terminal) {
39 77  
40 78 debug("%s",__FUNCTION__);
41   - v3270_copy_selection(terminal,V3270_SELECT_TEXT,FALSE);
  79 + v3270_clipboard_set(terminal,get_copy_mode_from_parameter(parameter),FALSE);
42 80  
43 81 }
44 82  
45 83 static void activate_cut(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) {
46 84  
47 85 debug("%s",__FUNCTION__);
48   - v3270_copy_selection(terminal,V3270_SELECT_TEXT,TRUE);
  86 + v3270_clipboard_set(terminal,get_copy_mode_from_parameter(parameter),TRUE);
49 87  
50 88 }
51 89  
... ... @@ -54,47 +92,23 @@
54 92  
55 93 if(!parameter) {
56 94 debug("%s %p",__FUNCTION__,"NULL");
57   - v3270_paste_from_url(terminal,NULL);
  95 + v3270_clipboard_get_from_url(terminal,NULL);
58 96 } else {
59 97 debug("%s \"%s\"",__FUNCTION__,g_variant_get_string(parameter,NULL));
60   - v3270_paste_from_url(terminal,g_variant_get_string(parameter,NULL));
  98 + v3270_clipboard_get_from_url(terminal,g_variant_get_string(parameter,NULL));
61 99 }
62 100  
63 101 }
64 102  
65 103 GAction * pw3270_copy_action_new(void) {
66 104  
67   - /*
68   - static const LIB3270_ACTION action_descriptor = {
69   - .name = "copy",
70   - .type = LIB3270_ACTION_TYPE_SELECTION,
71   -
72   - .key = "<ctrl>c",
73   - .icon = "edit-copy",
74   - .label = N_( "_Copy" ),
75   - .summary = N_( "Copy selected area to clipboard." ),
76   - .activate = NULL,
77   -
78   - .group = LIB3270_ACTION_GROUP_SELECTION,
79   - .activatable = lib3270_has_selection
80   -
81   - };
82   -
83   - GAction * action = pw3270_action_new_from_lib3270(&action_descriptor);
84   -
85   - PW3270_ACTION(action)->activate = activate_copy;
86   -
87   -
88   - return action;
89   -
90   -
91   - */
92   -
93 105 pw3270SimpleAction * action = pw3270_simple_action_new();
94 106  
95 107 action->parent.activate = activate_copy;
  108 + action->parent.types.parameter = G_VARIANT_TYPE_STRING;
  109 +
96 110 action->group.id = LIB3270_ACTION_GROUP_SELECTION;
97   - action->parent.name = "file.transfer";
  111 + action->parent.name = "copy";
98 112 action->icon_name = "edit-copy";
99 113 action->label = N_( "_Copy" );
100 114 action->tooltip = N_( "Copy selected area to clipboard." );
... ... @@ -105,34 +119,13 @@
105 119  
106 120 GAction * pw3270_cut_action_new(void) {
107 121  
108   - /*
109   - static const LIB3270_ACTION action_descriptor = {
110   - .name = "cut",
111   - .type = LIB3270_ACTION_TYPE_SELECTION,
112   -
113   - .key = "<ctrl>x",
114   - .icon = "edit-cut",
115   - .label = N_( "_Cut" ),
116   - .summary = N_( "Cut selected area." ),
117   - .activate = NULL,
118   -
119   - .group = LIB3270_ACTION_GROUP_SELECTION,
120   - .activatable = lib3270_has_selection
121   -
122   - };
123   -
124   - GAction * action = pw3270_action_new_from_lib3270(&action_descriptor);
125   -
126   - PW3270_ACTION(action)->activate = activate_cut;
127   -
128   - return action;
129   - */
130   -
131 122 pw3270SimpleAction * action = pw3270_simple_action_new();
132 123  
133 124 action->parent.activate = activate_cut;
  125 + action->parent.types.parameter = G_VARIANT_TYPE_STRING;
  126 +
134 127 action->group.id = LIB3270_ACTION_GROUP_SELECTION;
135   - action->parent.name = "file.transfer";
  128 + action->parent.name = "cut";
136 129 action->icon_name = "edit-cut";
137 130 action->label = N_( "C_ut" );
138 131 action->tooltip = N_( "Cut selected area." );
... ... @@ -143,29 +136,6 @@
143 136  
144 137 GAction * pw3270_paste_action_new(void) {
145 138  
146   - /*
147   - static const LIB3270_ACTION action_descriptor = {
148   - .name = "paste",
149   - .type = LIB3270_ACTION_TYPE_SELECTION,
150   -
151   - .key = "<ctrl>v",
152   - .icon = "edit-paste",
153   - .label = N_( "_Paste" ),
154   - .summary = N_( "Paste data from clipboard." ),
155   - .activate = NULL,
156   -
157   - .group = LIB3270_ACTION_GROUP_LOCK_STATE,
158   - .activatable = lib3270_is_unlocked
159   -
160   - };
161   -
162   - pw3270Action * action = PW3270_ACTION(pw3270_action_new_from_lib3270(&action_descriptor));
163   -
164   - action->types.parameter = G_VARIANT_TYPE_STRING;
165   - action->activate = activate_paste;
166   -
167   - return G_ACTION(action);
168   - */
169 139  
170 140 pw3270SimpleAction * action = pw3270_simple_action_new();
171 141  
... ...
src/objects/application/actions/window.c
... ... @@ -56,14 +56,14 @@
56 56  
57 57 }
58 58  
59   - void pw3270_application_new_tab_activated(GSimpleAction * action, GVariant *parameter, gpointer application) {
  59 + void pw3270_application_new_tab_activated(GSimpleAction G_GNUC_UNUSED(* action), GVariant G_GNUC_UNUSED(*parameter), gpointer application) {
60 60  
61 61 debug("%s",__FUNCTION__);
62 62 pw3270_terminal_new(GTK_WIDGET(gtk_application_get_active_window(GTK_APPLICATION(application))));
63 63  
64 64 }
65 65  
66   - void pw3270_application_new_window_activated(GSimpleAction * action, GVariant *parameter, gpointer application) {
  66 + void pw3270_application_new_window_activated(GSimpleAction G_GNUC_UNUSED(* action), GVariant G_GNUC_UNUSED(*parameter), gpointer application) {
67 67  
68 68 debug("%s",__FUNCTION__);
69 69 g_application_activate(application);
... ...
ui/application.xml
... ... @@ -115,21 +115,31 @@
115 115 <item>
116 116 <attribute name="label" translatable="yes">Copy</attribute>
117 117 <attribute name="action">win.copy</attribute>
  118 + <attribute name="target">auto</attribute>
  119 + </item>
  120 +
  121 + <item>
  122 + <attribute name="label" translatable="yes">Copy as text</attribute>
  123 + <attribute name="action">win.copy</attribute>
  124 + <attribute name="target">text</attribute>
118 125 </item>
119 126  
120 127 <item>
121 128 <attribute name="label" translatable="yes">Copy as table</attribute>
122   - <attribute name="action">win.copy_as_table</attribute>
  129 + <attribute name="action">win.copy</attribute>
  130 + <attribute name="target">table</attribute>
123 131 </item>
124 132  
125 133 <item>
126 134 <attribute name="label" translatable="yes">Append to copy</attribute>
127   - <attribute name="action">win.append_to_copy</attribute>
  135 + <attribute name="action">win.copy</attribute>
  136 + <attribute name="target">append</attribute>
128 137 </item>
129 138  
130 139 <item>
131 140 <attribute name="label" translatable="yes">Cut</attribute>
132 141 <attribute name="action">win.cut</attribute>
  142 + <attribute name="target">auto</attribute>
133 143 </item>
134 144  
135 145 <item>
... ...