Commit 84c61cc48c1b71a8512020be194286d69d8ed872
1 parent
dce631b2
Exists in
master
and in
4 other branches
Implementing move rows from one view to another.
Showing
3 changed files
with
88 additions
and
1 deletions
Show diff stats
src/include/pw3270/actions.h
| ... | ... | @@ -262,6 +262,7 @@ |
| 262 | 262 | Pw3270ActionList * pw3270_action_list_new(GtkApplication *application); |
| 263 | 263 | void pw3270_action_list_free(Pw3270ActionList *action_list); |
| 264 | 264 | void pw3270_action_view_set_actions(GtkWidget *view, Pw3270ActionList *list); |
| 265 | + void pw3270_action_view_move_selected(GtkWidget *from, GtkWidget *to); | |
| 265 | 266 | |
| 266 | 267 | Pw3270ActionList * pw3270_action_list_move_action(Pw3270ActionList *action_list, const gchar *action_name, GtkWidget *view); |
| 267 | 268 | ... | ... |
src/objects/actions/view.c
| ... | ... | @@ -276,3 +276,51 @@ |
| 276 | 276 | g_slist_free_full((GSList *) action_list, (GDestroyNotify) list_element_free); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | + void pw3270_action_view_move_selected(GtkWidget *from, GtkWidget *to) { | |
| 280 | + | |
| 281 | + size_t ix; | |
| 282 | + | |
| 283 | + // | |
| 284 | + // Get list of selected references. | |
| 285 | + // | |
| 286 | + GtkTreeModel * fromModel = gtk_tree_view_get_model(GTK_TREE_VIEW(from)); | |
| 287 | + GList * list = gtk_tree_selection_get_selected_rows( | |
| 288 | + gtk_tree_view_get_selection(GTK_TREE_VIEW(from)), | |
| 289 | + &fromModel); | |
| 290 | + | |
| 291 | + guint rowCount = g_list_length(list); | |
| 292 | + | |
| 293 | + g_autofree GtkTreeRowReference ** rows = g_new0(GtkTreeRowReference *,rowCount); | |
| 294 | + GList * item = list; | |
| 295 | + for(ix=0;ix < rowCount && item; ix++) { | |
| 296 | + rows[ix] = gtk_tree_row_reference_new(fromModel,(GtkTreePath *) item->data); | |
| 297 | + item = g_list_next(item); | |
| 298 | + } | |
| 299 | + | |
| 300 | + g_list_free_full(list, (GDestroyNotify) gtk_tree_path_free); | |
| 301 | + | |
| 302 | + // | |
| 303 | + // Move references | |
| 304 | + // | |
| 305 | + for(ix = 0; ix < rowCount && rows[ix]; ix++) { | |
| 306 | + | |
| 307 | + GtkTreePath * path = gtk_tree_row_reference_get_path(rows[ix]); | |
| 308 | + | |
| 309 | + if(path) { | |
| 310 | + GtkTreeIter iter; | |
| 311 | + | |
| 312 | + // Add on target widget. | |
| 313 | + | |
| 314 | + | |
| 315 | + // Remove from source widget. | |
| 316 | + if (gtk_tree_model_get_iter(GTK_TREE_MODEL(fromModel), &iter, path)) { | |
| 317 | + gtk_list_store_remove(GTK_LIST_STORE(fromModel), &iter); | |
| 318 | + } | |
| 319 | + | |
| 320 | + } | |
| 321 | + | |
| 322 | + | |
| 323 | + } | |
| 324 | + | |
| 325 | + | |
| 326 | + } | ... | ... |
src/objects/toolbar/settings.c
| ... | ... | @@ -78,9 +78,24 @@ |
| 78 | 78 | debug("%s",__FUNCTION__); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | + static void selection_changed(GtkTreeSelection *selection, GtkWidget *button) { | |
| 82 | + gtk_widget_set_sensitive(button,gtk_tree_selection_count_selected_rows(selection) > 0); | |
| 83 | + } | |
| 84 | + | |
| 85 | + void toolbar_insert(GtkButton G_GNUC_UNUSED(*button), ToolbarSettingsPage *settings) { | |
| 86 | + debug("%s(%p)",__FUNCTION__,settings); | |
| 87 | + pw3270_action_view_move_selected(settings->views[1],settings->views[0]); | |
| 88 | + } | |
| 89 | + | |
| 90 | + void toolbar_remove(GtkButton G_GNUC_UNUSED(*button), ToolbarSettingsPage *settings) { | |
| 91 | + debug("%s(%p)",__FUNCTION__,settings); | |
| 92 | + pw3270_action_view_move_selected(settings->views[0],settings->views[1]); | |
| 93 | + } | |
| 94 | + | |
| 81 | 95 | Pw3270SettingsPage * pw3270_toolbar_settings_new() { |
| 82 | 96 | |
| 83 | 97 | size_t ix; |
| 98 | + GtkTreeSelection * selection; | |
| 84 | 99 | |
| 85 | 100 | ToolbarSettingsPage * page = g_new0(ToolbarSettingsPage,1); |
| 86 | 101 | |
| ... | ... | @@ -102,6 +117,9 @@ |
| 102 | 117 | |
| 103 | 118 | page->views[ix] = pw3270_action_view_new(); |
| 104 | 119 | |
| 120 | + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(page->views[ix])); | |
| 121 | + gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); | |
| 122 | + | |
| 105 | 123 | gtk_grid_attach( |
| 106 | 124 | GTK_GRID(page->parent.widget), |
| 107 | 125 | gtk_label_new(gettext(labels[ix])), |
| ... | ... | @@ -140,17 +158,37 @@ |
| 140 | 158 | gtk_button_set_relief(GTK_BUTTON(page->buttons[ix]),GTK_RELIEF_NONE); |
| 141 | 159 | gtk_widget_set_sensitive(page->buttons[ix],FALSE); |
| 142 | 160 | |
| 161 | + g_signal_connect( | |
| 162 | + gtk_tree_view_get_selection(GTK_TREE_VIEW(page->views[ix])), | |
| 163 | + "changed", | |
| 164 | + G_CALLBACK(selection_changed), | |
| 165 | + page->buttons[ix] | |
| 166 | + ); | |
| 167 | + | |
| 143 | 168 | } |
| 144 | 169 | |
| 145 | 170 | gtk_box_pack_start(GTK_BOX(box),page->buttons[0],FALSE,FALSE,0); |
| 146 | 171 | gtk_box_pack_end(GTK_BOX(box),page->buttons[1],FALSE,FALSE,0); |
| 147 | 172 | |
| 173 | + g_signal_connect( | |
| 174 | + page->buttons[0], | |
| 175 | + "clicked", | |
| 176 | + G_CALLBACK(toolbar_remove), | |
| 177 | + page | |
| 178 | + ); | |
| 179 | + | |
| 180 | + g_signal_connect( | |
| 181 | + page->buttons[1], | |
| 182 | + "clicked", | |
| 183 | + G_CALLBACK(toolbar_insert), | |
| 184 | + page | |
| 185 | + ); | |
| 186 | + | |
| 148 | 187 | gtk_grid_attach( |
| 149 | 188 | GTK_GRID(page->parent.widget), |
| 150 | 189 | box, |
| 151 | 190 | 2,2,1,1 |
| 152 | 191 | ); |
| 153 | 192 | |
| 154 | - | |
| 155 | 193 | return (Pw3270SettingsPage *) page; |
| 156 | 194 | } | ... | ... |