diff --git a/Todo.txt b/Todo.txt index 761e6e2e..b67ad66c 100644 --- a/Todo.txt +++ b/Todo.txt @@ -1,4 +1,7 @@ +run script from asciio + insert boxes, ... + constraints alignement arrows not overlapping diff --git a/documentation/mdbook_asciio/src/for_developers/scripting.md b/documentation/mdbook_asciio/src/for_developers/scripting.md index 00f9a4b4..3bda49a2 100644 --- a/documentation/mdbook_asciio/src/for_developers/scripting.md +++ b/documentation/mdbook_asciio/src/for_developers/scripting.md @@ -159,4 +159,20 @@ save_to "from_script.asciio" ; ascii_out ; ``` +## Executing your script + +### From the command line + +The script is a normal perl script. + +``` +perl my_asciio_script.pl +``` + +### From within Asciio + +***Binding:*** «:!» + +Pick the file you want to execute. + diff --git a/documentation/scripting/asciio_script.pl b/documentation/scripting/asciio_script.pl new file mode 100644 index 00000000..f6308ad4 --- /dev/null +++ b/documentation/scripting/asciio_script.pl @@ -0,0 +1,6 @@ + +add 'box1', new_box(TEXT_ONLY =>'A'), 0, 2 ; +add 'box2', new_box(TEXT_ONLY =>'B'), 20, 10 ; +add 'box3', new_box(TEXT_ONLY =>'C'), 40, 5 ; + +select_all_elements 1 ; diff --git a/documentation/scripting/connected_boxes.pl b/documentation/scripting/connected_boxes.pl index 0d0dd427..cdfbf78e 100644 --- a/documentation/scripting/connected_boxes.pl +++ b/documentation/scripting/connected_boxes.pl @@ -23,3 +23,4 @@ ascii_out ; +select_all_elements ; diff --git a/lib/App/Asciio/Scripting.pm b/lib/App/Asciio/Scripting.pm index 5702ef9a..332ef78b 100644 --- a/lib/App/Asciio/Scripting.pm +++ b/lib/App/Asciio/Scripting.pm @@ -19,6 +19,7 @@ require Exporter ; move_named_connector optimize_connections get_canonizer + run_external_script ) ; use strict ; use warnings ; @@ -50,6 +51,22 @@ use App::Asciio::stripes::wirl_arrow ; my $script_asciio ; # make script non OO my %name_to_element ; +sub run_external_script +{ +my ($asciio) = @_ ; + +my $script = $asciio->get_file_name() ; + +if(defined $script) + { + $script_asciio = $asciio ; + + do $script ; + + $asciio->update_display() ; + } +} + sub new_script_asciio { $script_asciio = new App::Asciio() ; @@ -97,6 +114,15 @@ my ($element1_name, $element2_name, @args) = @_ ; add_connection($script_asciio, @name_to_element{$element1_name, $element2_name}, @args) ; } +sub select_elements +{ +my ($state, @elements) = @_ ; +$script_asciio->select_elements($state, @name_to_element{@elements}) ; +} + +sub select_all_elements { $script_asciio->select_all_elements() ; } +sub deselect_all_elements { $script_asciio->select_all_elements() ; } + sub save_to { $script_asciio->save_with_type(undef, 'asciio', $_[0]) ; } sub to_ascii { $script_asciio->transform_elements_to_ascii_buffer() ; } sub ascii_out { print $script_asciio->transform_elements_to_ascii_buffer() ; } diff --git a/setup/actions/default_bindings.pl b/setup/actions/default_bindings.pl index 0fe67824..3b869b05 100644 --- a/setup/actions/default_bindings.pl +++ b/setup/actions/default_bindings.pl @@ -15,11 +15,11 @@ use App::Asciio::Actions::Multiwirl ; use App::Asciio::Actions::Presentation ; use App::Asciio::Actions::Ruler ; +use App::Asciio::Scripting ; use App::Asciio::Actions::Shapes ; use App::Asciio::Actions::Unsorted ; use App::Asciio::Actions::ZBuffer ; - #---------------------------------------------------------------------------------------------- register_action_handlers @@ -220,14 +220,15 @@ 'Display commands' => ['000-c', \&App::Asciio::Actions::Unsorted::display_commands ], 'Display action files' => ['000-f', \&App::Asciio::Actions::Unsorted::display_action_files ], 'Display manpage' => ['000-m', \&App::Asciio::Actions::Unsorted::manpage_in_browser ], - - 'Open' => ['000-e', \&App::Asciio::Actions::File::open ], - 'Save' => ['000-w', \&App::Asciio::Actions::File::save, undef ], - 'SaveAs' => ['00S-W', \&App::Asciio::Actions::File::save, 'as' ], - 'Insert' => ['000-r', \&App::Asciio::Actions::File::insert ], - 'Quit' => ['000-q', \&App::Asciio::Actions::File::quit ], - 'Quit no save' => ['00S-Q', \&App::Asciio::Actions::File::quit_no_save], + 'Run external script' => ['00S-exclam', \&App::Asciio::Scripting::run_external_script ], + + 'Open' => ['000-e', \&App::Asciio::Actions::File::open ], + 'Save' => ['000-w', \&App::Asciio::Actions::File::save, undef ], + 'SaveAs' => ['00S-W', \&App::Asciio::Actions::File::save, 'as' ], + 'Insert' => ['000-r', \&App::Asciio::Actions::File::insert ], + 'Quit' => ['000-q', \&App::Asciio::Actions::File::quit ], + 'Quit no save' => ['00S-Q', \&App::Asciio::Actions::File::quit_no_save ], }, 'Insert leader' =>