Commit 27bc20aa3440a449b48aeb340c23ba6ac30ce995
1 parent
922f7557
Exists in
master
and in
1 other branch
Implementing clipboard settings dialog.
Showing
4 changed files
with
245 additions
and
17 deletions
Show diff stats
src/dialogs/settings/clipboard.c
| @@ -32,16 +32,112 @@ | @@ -32,16 +32,112 @@ | ||
| 32 | * | 32 | * |
| 33 | */ | 33 | */ |
| 34 | 34 | ||
| 35 | - #include <internals.h> | 35 | + #include "private.h" |
| 36 | #include <v3270/settings.h> | 36 | #include <v3270/settings.h> |
| 37 | #include <lib3270/log.h> | 37 | #include <lib3270/log.h> |
| 38 | 38 | ||
| 39 | +/*--[ Constants ]------------------------------------------------------------------------------------*/ | ||
| 40 | + | ||
| 41 | + enum { | ||
| 42 | + COPY_SETTINGS, | ||
| 43 | + PASTE_SETTINGS, | ||
| 44 | + HTML_SETTINGS, | ||
| 45 | + | ||
| 46 | + GRID_COUNT | ||
| 47 | + }; | ||
| 48 | + | ||
| 49 | + static const struct ToggleButtonDefinition toggles[] = { | ||
| 50 | + { | ||
| 51 | + .left = 0, | ||
| 52 | + .top = 0, | ||
| 53 | + .width = 1, | ||
| 54 | + .grid = COPY_SETTINGS, | ||
| 55 | + .id = LIB3270_TOGGLE_RECTANGLE_SELECT, | ||
| 56 | + }, | ||
| 57 | + | ||
| 58 | + { | ||
| 59 | + .left = 2, | ||
| 60 | + .top = 0, | ||
| 61 | + .width = 1, | ||
| 62 | + .grid = COPY_SETTINGS, | ||
| 63 | + .id = LIB3270_TOGGLE_MARGINED_PASTE, | ||
| 64 | + }, | ||
| 65 | + | ||
| 66 | + { | ||
| 67 | + .left = 0, | ||
| 68 | + .top = 0, | ||
| 69 | + .width = 1, | ||
| 70 | + .grid = PASTE_SETTINGS, | ||
| 71 | + .id = LIB3270_TOGGLE_SMART_PASTE, | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + }; | ||
| 75 | + | ||
| 76 | + static const struct ComboBoxDefinition combos[] = { | ||
| 77 | + | ||
| 78 | + { | ||
| 79 | + .grid = HTML_SETTINGS, | ||
| 80 | + .left = 0, | ||
| 81 | + .top = 0, | ||
| 82 | + .width = 1, | ||
| 83 | + .height = 1, | ||
| 84 | + .label = N_("Font"), | ||
| 85 | +// .tooltip = | ||
| 86 | + | ||
| 87 | + .n_columns = 2, | ||
| 88 | + .types = (const GType []) { | ||
| 89 | + G_TYPE_STRING, | ||
| 90 | + G_TYPE_UINT | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + }, | ||
| 94 | + | ||
| 95 | + { | ||
| 96 | + .grid = HTML_SETTINGS, | ||
| 97 | + .left = 0, | ||
| 98 | + .top = 1, | ||
| 99 | + .width = 1, | ||
| 100 | + .height = 1, | ||
| 101 | + .label = N_("Color theme"), | ||
| 102 | +// .tooltip = | ||
| 103 | + | ||
| 104 | + .n_columns = 1, | ||
| 105 | + .types = (const GType []) { | ||
| 106 | + G_TYPE_STRING | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + }, | ||
| 110 | + | ||
| 111 | + { | ||
| 112 | + .grid = COPY_SETTINGS, | ||
| 113 | + .left = 0, | ||
| 114 | + .top = 1, | ||
| 115 | + .width = 1, | ||
| 116 | + .height = 1, | ||
| 117 | + .label = N_("Format"), | ||
| 118 | +// .tooltip = | ||
| 119 | + | ||
| 120 | + .n_columns = 2, | ||
| 121 | + .types = (const GType []) { | ||
| 122 | + G_TYPE_STRING, | ||
| 123 | + G_TYPE_UINT | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + }, | ||
| 127 | + | ||
| 128 | + }; | ||
| 129 | + | ||
| 39 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ | 130 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ |
| 40 | 131 | ||
| 41 | typedef struct _V3270ClipboardSettings { | 132 | typedef struct _V3270ClipboardSettings { |
| 42 | 133 | ||
| 43 | V3270Settings parent; | 134 | V3270Settings parent; |
| 44 | 135 | ||
| 136 | + struct { | ||
| 137 | + GtkToggleButton * toggles[G_N_ELEMENTS(toggles)]; ///< @brief Toggle checks. | ||
| 138 | + GtkComboBox * combos[G_N_ELEMENTS(combos)]; ///< @brief Combo-boxes. | ||
| 139 | + } input; | ||
| 140 | + | ||
| 45 | 141 | ||
| 46 | } V3270ClipboardSettings; | 142 | } V3270ClipboardSettings; |
| 47 | 143 | ||
| @@ -70,6 +166,71 @@ static void V3270ClipboardSettings_class_init(V3270ClipboardSettingsClass *klass | @@ -70,6 +166,71 @@ static void V3270ClipboardSettings_class_init(V3270ClipboardSettingsClass *klass | ||
| 70 | 166 | ||
| 71 | static void V3270ClipboardSettings_init(V3270ClipboardSettings *widget) { | 167 | static void V3270ClipboardSettings_init(V3270ClipboardSettings *widget) { |
| 72 | 168 | ||
| 169 | + size_t ix; | ||
| 170 | + GtkWidget * grids[GRID_COUNT]; | ||
| 171 | + | ||
| 172 | + // Create grids | ||
| 173 | + { | ||
| 174 | + static const gchar * labels[GRID_COUNT] = { | ||
| 175 | + N_("Copy options"), | ||
| 176 | + N_("Common paste options"), | ||
| 177 | + N_("HTML Paste options") | ||
| 178 | + }; | ||
| 179 | + | ||
| 180 | + for(ix = 0; ix < G_N_ELEMENTS(labels); ix++) { | ||
| 181 | + | ||
| 182 | + grids[ix] = gtk_grid_new(); | ||
| 183 | + | ||
| 184 | + gtk_grid_set_row_spacing(GTK_GRID(grids[ix]),6); | ||
| 185 | + gtk_grid_set_column_spacing(GTK_GRID(grids[ix]),12); | ||
| 186 | + | ||
| 187 | + gtk_grid_attach( | ||
| 188 | + GTK_GRID(widget), | ||
| 189 | + v3270_dialog_create_frame(grids[ix],g_dgettext(PACKAGE_NAME,labels[ix])), | ||
| 190 | + 0,ix,1,1 | ||
| 191 | + ); | ||
| 192 | + | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + v3270_settings_create_toggle_buttons(toggles, G_N_ELEMENTS(toggles), grids, widget->input.toggles); | ||
| 198 | + v3270_settings_create_combos(combos, G_N_ELEMENTS(combos), grids, widget->input.combos); | ||
| 199 | + | ||
| 200 | + // Setup combos | ||
| 201 | + { | ||
| 202 | + GtkCellRenderer * text_renderer = gtk_cell_renderer_text_new(); | ||
| 203 | + GtkTreeIter iter; | ||
| 204 | + GtkListStore * model; | ||
| 205 | + | ||
| 206 | + for(ix = 0; ix < G_N_ELEMENTS(combos); ix++) { | ||
| 207 | + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget->input.combos[ix]), text_renderer, TRUE); | ||
| 208 | + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget->input.combos[ix]), text_renderer, "text", 0, NULL); | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + // Copy format combo | ||
| 212 | + static const gchar * copy_formats[] = { | ||
| 213 | + N_("Plain text only"), | ||
| 214 | + N_("Complete with terminal attributes") | ||
| 215 | + }; | ||
| 216 | + | ||
| 217 | + model = GTK_LIST_STORE(gtk_combo_box_get_model(widget->input.combos[2])); | ||
| 218 | + for(ix = 0;ix < G_N_ELEMENTS(copy_formats); ix++) { | ||
| 219 | + | ||
| 220 | + gtk_list_store_append(model, &iter); | ||
| 221 | + gtk_list_store_set( | ||
| 222 | + model, | ||
| 223 | + &iter, | ||
| 224 | + 0, g_dgettext(PACKAGE_NAME, copy_formats[ix]), | ||
| 225 | + 1, (guint) ix, | ||
| 226 | + -1 | ||
| 227 | + ); | ||
| 228 | + | ||
| 229 | + } | ||
| 230 | + | ||
| 231 | + | ||
| 232 | + } | ||
| 233 | + | ||
| 73 | } | 234 | } |
| 74 | 235 | ||
| 75 | GtkWidget * v3270_clipboard_settings_new() { | 236 | GtkWidget * v3270_clipboard_settings_new() { |
| @@ -82,11 +243,20 @@ GtkWidget * v3270_clipboard_settings_new() { | @@ -82,11 +243,20 @@ GtkWidget * v3270_clipboard_settings_new() { | ||
| 82 | return GTK_WIDGET(settings); | 243 | return GTK_WIDGET(settings); |
| 83 | } | 244 | } |
| 84 | 245 | ||
| 85 | -static void apply(GtkWidget *w, GtkWidget *terminal) { | 246 | +static void load(GtkWidget *w, GtkWidget *terminal) { |
| 247 | + | ||
| 248 | + V3270ClipboardSettings *widget = (V3270ClipboardSettings *) w; | ||
| 249 | + | ||
| 250 | + v3270_settings_load_toggle_buttons(toggles, G_N_ELEMENTS(toggles), terminal, widget->input.toggles); | ||
| 86 | 251 | ||
| 87 | } | 252 | } |
| 88 | 253 | ||
| 89 | -static void load(GtkWidget *w, GtkWidget *terminal) { | 254 | +static void apply(GtkWidget *w, GtkWidget *terminal) { |
| 255 | + | ||
| 256 | + V3270ClipboardSettings *widget = (V3270ClipboardSettings *) w; | ||
| 257 | + | ||
| 258 | + v3270_settings_apply_toggle_buttons(toggles,G_N_ELEMENTS(toggles),terminal,widget->input.toggles); | ||
| 90 | 259 | ||
| 91 | } | 260 | } |
| 92 | 261 | ||
| 262 | + |
src/dialogs/settings/host.c
| @@ -766,13 +766,7 @@ static void apply(GtkWidget *w, GtkWidget *terminal) | @@ -766,13 +766,7 @@ static void apply(GtkWidget *w, GtkWidget *terminal) | ||
| 766 | } | 766 | } |
| 767 | 767 | ||
| 768 | // Apply toggles | 768 | // Apply toggles |
| 769 | - size_t toggle; | ||
| 770 | - | ||
| 771 | - for(toggle = 0; toggle < G_N_ELEMENTS(toggleList); toggle++) | ||
| 772 | - { | ||
| 773 | - if(widget->input.toggles[toggle]) | ||
| 774 | - v3270_set_toggle(terminal, toggleList[toggle].id, gtk_toggle_button_get_active(widget->input.toggles[toggle])); | ||
| 775 | - } | 769 | + v3270_settings_apply_toggle_buttons(toggleList,G_N_ELEMENTS(toggleList),terminal,widget->input.toggles); |
| 776 | 770 | ||
| 777 | // Apply oversize | 771 | // Apply oversize |
| 778 | lib3270_set_oversize(hSession,gtk_entry_get_text(widget->input.entry[ENTRY_OVERSIZE])); | 772 | lib3270_set_oversize(hSession,gtk_entry_get_text(widget->input.entry[ENTRY_OVERSIZE])); |
| @@ -900,13 +894,7 @@ static void load(GtkWidget *w, GtkWidget *terminal) | @@ -900,13 +894,7 @@ static void load(GtkWidget *w, GtkWidget *terminal) | ||
| 900 | } | 894 | } |
| 901 | 895 | ||
| 902 | // Load toggles | 896 | // Load toggles |
| 903 | - size_t toggle; | ||
| 904 | - | ||
| 905 | - for(toggle = 0; toggle < G_N_ELEMENTS(toggleList); toggle++) | ||
| 906 | - { | ||
| 907 | - if(widget->input.toggles[toggle]) | ||
| 908 | - gtk_toggle_button_set_active(widget->input.toggles[toggle],v3270_get_toggle(terminal,toggleList[toggle].id)); | ||
| 909 | - } | 897 | + v3270_settings_load_toggle_buttons(toggleList, G_N_ELEMENTS(toggleList), terminal, widget->input.toggles); |
| 910 | 898 | ||
| 911 | // Load oversize | 899 | // Load oversize |
| 912 | const char * oversize = lib3270_get_oversize(hSession); | 900 | const char * oversize = lib3270_get_oversize(hSession); |
src/dialogs/settings/private.h
| @@ -44,6 +44,8 @@ | @@ -44,6 +44,8 @@ | ||
| 44 | }; | 44 | }; |
| 45 | 45 | ||
| 46 | G_GNUC_INTERNAL void v3270_settings_create_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget **grids, GtkToggleButton **toggles); | 46 | G_GNUC_INTERNAL void v3270_settings_create_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget **grids, GtkToggleButton **toggles); |
| 47 | + G_GNUC_INTERNAL void v3270_settings_load_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget *terminal, GtkToggleButton **toggles); | ||
| 48 | + G_GNUC_INTERNAL void v3270_settings_apply_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget *terminal, GtkToggleButton **toggles); | ||
| 47 | 49 | ||
| 48 | /// @brief Entry field factory. | 50 | /// @brief Entry field factory. |
| 49 | struct EntryFieldDefinition { | 51 | struct EntryFieldDefinition { |
| @@ -58,4 +60,18 @@ | @@ -58,4 +60,18 @@ | ||
| 58 | 60 | ||
| 59 | G_GNUC_INTERNAL void v3270_settings_create_entry_fields(const struct EntryFieldDefinition * definitions, size_t length, GtkWidget **grids, GtkEntry **entries); | 61 | G_GNUC_INTERNAL void v3270_settings_create_entry_fields(const struct EntryFieldDefinition * definitions, size_t length, GtkWidget **grids, GtkEntry **entries); |
| 60 | 62 | ||
| 63 | + /// @brief Combo Box factory | ||
| 64 | + struct ComboBoxDefinition { | ||
| 65 | + | ||
| 66 | + ENTRY_FIELD_HEAD | ||
| 67 | + | ||
| 68 | + unsigned short grid; | ||
| 69 | + | ||
| 70 | + gint n_columns; | ||
| 71 | + const GType *types; | ||
| 72 | + | ||
| 73 | + }; | ||
| 74 | + | ||
| 75 | + G_GNUC_INTERNAL void v3270_settings_create_combos(const struct ComboBoxDefinition * definitions, size_t length, GtkWidget **grids, GtkComboBox **combos); | ||
| 76 | + | ||
| 61 | #endif // PRIVATE_H_INCLUDED | 77 | #endif // PRIVATE_H_INCLUDED |
src/dialogs/settings/tools.c
| @@ -58,6 +58,32 @@ | @@ -58,6 +58,32 @@ | ||
| 58 | 58 | ||
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | + void v3270_settings_load_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget *terminal, GtkToggleButton **toggles) { | ||
| 62 | + | ||
| 63 | + size_t toggle; | ||
| 64 | + | ||
| 65 | + for(toggle = 0; toggle < length; toggle++) { | ||
| 66 | + | ||
| 67 | + if(toggles[toggle]) | ||
| 68 | + gtk_toggle_button_set_active(toggles[toggle],v3270_get_toggle(terminal,definitions[toggle].id)); | ||
| 69 | + | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + void v3270_settings_apply_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget *terminal, GtkToggleButton **toggles) { | ||
| 75 | + | ||
| 76 | + size_t toggle; | ||
| 77 | + | ||
| 78 | + for(toggle = 0; toggle < length; toggle++) { | ||
| 79 | + | ||
| 80 | + if(toggles[toggle]) | ||
| 81 | + v3270_set_toggle(terminal, definitions[toggle].id, gtk_toggle_button_get_active(toggles[toggle])); | ||
| 82 | + | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + } | ||
| 86 | + | ||
| 61 | void v3270_settings_create_entry_fields(const struct EntryFieldDefinition * definitions, size_t length, GtkWidget **grids, GtkEntry **entries) { | 87 | void v3270_settings_create_entry_fields(const struct EntryFieldDefinition * definitions, size_t length, GtkWidget **grids, GtkEntry **entries) { |
| 62 | 88 | ||
| 63 | size_t entry; | 89 | size_t entry; |
| @@ -78,3 +104,31 @@ | @@ -78,3 +104,31 @@ | ||
| 78 | 104 | ||
| 79 | } | 105 | } |
| 80 | 106 | ||
| 107 | + void v3270_settings_create_combos(const struct ComboBoxDefinition * definitions, size_t length, GtkWidget **grids, GtkComboBox **combos) { | ||
| 108 | + | ||
| 109 | + size_t combo; | ||
| 110 | + | ||
| 111 | + for(combo = 0; combo < length; combo++) { | ||
| 112 | + | ||
| 113 | + if(definitions[combo].n_columns) { | ||
| 114 | + | ||
| 115 | + GtkTreeModel * model = GTK_TREE_MODEL(gtk_list_store_newv(definitions[combo].n_columns,(GType *) definitions[combo].types)); | ||
| 116 | + combos[combo] = GTK_COMBO_BOX(gtk_combo_box_new_with_model(model)); | ||
| 117 | + | ||
| 118 | + } else { | ||
| 119 | + | ||
| 120 | + combos[combo] = GTK_COMBO_BOX(gtk_combo_box_new()); | ||
| 121 | + | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + v3270_grid_attach( | ||
| 125 | + GTK_GRID(grids[definitions[combo].grid]), | ||
| 126 | + (struct v3270_entry_field *) & definitions[combo], | ||
| 127 | + GTK_WIDGET(combos[combo]) | ||
| 128 | + ); | ||
| 129 | + | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + |