« blib/lib/App/Asciio/GTK/Asciio/stripes/angled_arrow.pm
↑ Summary
blib/lib/App/Asciio/GTK/Asciio/stripes/editable_exec_box.pm »
| 1 | |||
| 2 | package App::Asciio::stripes::editable_arrow2 ; | ||
| 3 | |||
| 4 | use base App::Asciio::stripes::stripes ; | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | |||
| 9 | use Glib ':constants'; | ||
| 10 | use Gtk3 -init; | ||
| 11 | use Glib qw(TRUE FALSE); | ||
| 12 | |||
| 13 | #----------------------------------------------------------------------------- | ||
| 14 | |||
| 15 | sub display_box_edit_dialog | ||
| 16 | { | ||
| 17 | my ($self) = @_ ; | ||
| 18 | |||
| 19 | my $rows = $self->{ARROW_TYPE} ; | ||
| 20 | my $window = new Gtk3::Window() ; | ||
| 21 | |||
| 22 | my $dialog = Gtk3::Dialog->new('Arrow attributes', $window, 'destroy-with-parent') ; | ||
| 23 | $dialog->set_default_size (220, 270); | ||
| 24 | $dialog->add_button ('gtk-ok' => 'ok'); | ||
| 25 | |||
| 26 | my $vbox = Gtk3::VBox->new (FALSE, 5); | ||
| 27 | $vbox->add(Gtk3::Label->new ("")); | ||
| 28 | |||
| 29 | my $treeview = Gtk3::TreeView->new_with_model(create_model ($rows)); | ||
| 30 | $treeview->set_rules_hint (TRUE); | ||
| 31 | $treeview->get_selection->set_mode ('single'); | ||
| 32 | |||
| 33 | add_columns($treeview, $rows); | ||
| 34 | |||
| 35 | $vbox->add($treeview); | ||
| 36 | |||
| 37 | $treeview->show() ; | ||
| 38 | $vbox->show() ; | ||
| 39 | |||
| 40 | $dialog->get_content_area()->add($vbox) ; | ||
| 41 | $dialog->run() ; | ||
| 42 | |||
| 43 | $dialog->destroy ; | ||
| 44 | } | ||
| 45 | |||
| 46 | #----------------------------------------------------------------------------- | ||
| 47 | |||
| 48 | sub create_model | ||
| 49 | { | ||
| 50 | my ($rows) = @_ ; | ||
| 51 | |||
| 52 | my $model = Gtk3::ListStore->new(qw/Glib::String Glib::String Glib::String Glib::String Glib::Boolean/); | ||
| 53 | |||
| 54 | foreach my $row (@{$rows}) | ||
| 55 | { | ||
| 56 | my $iter = $model->append; | ||
| 57 | |||
| 58 | my $column = 0 ; | ||
| 59 | $model->set ($iter, map {$column++, $_} @{$row}) ; | ||
| 60 | } | ||
| 61 | |||
| 62 | return $model; | ||
| 63 | } | ||
| 64 | |||
| 65 | #----------------------------------------------------------------------------- | ||
| 66 | |||
| 67 | sub add_columns | ||
| 68 | { | ||
| 69 | my ($treeview, $rows) = @_ ; | ||
| 70 | my $model = $treeview->get_model; | ||
| 71 | |||
| 72 | # column for row titles | ||
| 73 | my $row_renderer = Gtk3::CellRendererText->new; | ||
| 74 | $row_renderer->set_data (column => 0); | ||
| 75 | |||
| 76 | $treeview->insert_column_with_attributes | ||
| 77 | ( | ||
| 78 | -1, '', $row_renderer, | ||
| 79 | text => 0, | ||
| 80 | ) ; | ||
| 81 | |||
| 82 | my $column = $treeview->get_column(0) ; | ||
| 83 | $column->set_sizing('fixed') ; | ||
| 84 | $column->set_fixed_width(80) ; | ||
| 85 | |||
| 86 | my $current_column = 1 ; | ||
| 87 | for my $column_title('start', 'body', 'end') | ||
| 88 | { | ||
| 89 | my $renderer = Gtk3::CellRendererText->new; | ||
| 90 | $renderer->signal_connect (edited => \&cell_edited, [$model, $rows]); | ||
| 91 | $renderer->set_data (column => $current_column ); | ||
| 92 | |||
| 93 | $treeview->insert_column_with_attributes | ||
| 94 | ( | ||
| 95 | -1, $column_title, $renderer, | ||
| 96 | text => $current_column, | ||
| 97 | editable => 4, | ||
| 98 | ); | ||
| 99 | |||
| 100 | $current_column++ ; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | #----------------------------------------------------------------------------- | ||
| 105 | |||
| 106 | sub cell_edited | ||
| 107 | { | ||
| 108 | my ($cell, $path_string, $new_text, $model_and_rows) = @_; | ||
| 109 | |||
| 110 | my ($model, $rows) = @{$model_and_rows} ; | ||
| 111 | |||
| 112 | my $path = Gtk3::TreePath->new_from_string ($path_string); | ||
| 113 | my $column = $cell->get_data ("column"); | ||
| 114 | my $iter = $model->get_iter($path); | ||
| 115 | my $row = ($path->get_indices)[0]; | ||
| 116 | |||
| 117 | $rows->[$row][$column] = $new_text ; | ||
| 118 | |||
| 119 | $model->set($iter, $column, $new_text); | ||
| 120 | } | ||
| 121 | |||
| 122 | #----------------------------------------------------------------------------- | ||
| 123 | |||
| 124 | 1 ; |