Skip to content

Commit aa82e1e

Browse files
committed
FIXED: error in get_selected_elements
ADDED: disable action override in asciio_to_text why: - added the possibility to override the asciio object at setup time to avoid displaying warnings when setting up actions - App::Asciio::Scripting created a static asciio object for simplified scripts that displayed the warnings we wanted to avoid (as it is part of the setup) - removed the 'use' of App::Asciio::Scripting in the setup fixed: - created App::Asciio:Utils::Scripting which requires App::Asciio::Scripting at run time, imports all the simplified functions and links the static asciio object to the current asciio object
1 parent 94e2843 commit aa82e1e

File tree

10 files changed

+83
-41
lines changed

10 files changed

+83
-41
lines changed

Build.PL

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ lib/App/Asciio/stripes/triangle_up.pm
7070
lib/App/Asciio/stripes/wirl_arrow.pm
7171
7272
lib/App/Asciio/Utils/Presentation.pm
73+
lib/App/Asciio/Utils/Scripting.pm
7374
7475
lib/App/Asciio/GTK/Asciio.pm
7576

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ lib/App/Asciio/stripes/triangle_up.pm
9797
lib/App/Asciio/stripes/wirl_arrow.pm
9898

9999
lib/App/Asciio/Utils/Presentation.pm
100+
lib/App/Asciio/Utils/Scripting.pm
100101

101102
t/001_load.t
102103
t/002_multi_wirl_connection.t

documentation/scripting/asciio_script.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
add 'box3', new_box(TEXT_ONLY =>'C'), 40, 5 ;
55

66
select_all_script_elements 1 ;
7+

lib/App/Asciio/Elements.pm

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,22 @@ sub get_selected_elements
533533
{
534534
my ($self, $state) = @_ ;
535535

536-
return grep { $state == $_->{SELECTED}//0 } @{$self->{ELEMENTS}} ;
536+
$state //= 1 ;
537+
538+
return
539+
(
540+
grep
541+
{
542+
if($state)
543+
{
544+
exists $_->{SELECTED} && $_->{SELECTED} != 0
545+
}
546+
else
547+
{
548+
! exists $_->{SELECTED} || $_->{SELECTED} == 0
549+
}
550+
} @{$self->{ELEMENTS}}
551+
) ;
537552
}
538553

539554
#-----------------------------------------------------------------------------

lib/App/Asciio/Scripting.pm

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
package App::Asciio::Scripting ;
33

44
require Exporter ;
5-
@ISA = qw(Exporter) ;
6-
@EXPORT = qw(
5+
6+
our @ISA = qw(Exporter) ;
7+
our @EXPORT = qw(
78
update_display
89
start_updating_display
910
stop_updating_display
@@ -59,7 +60,6 @@ use App::Asciio::Elements ;
5960
use App::Asciio::Io ;
6061
use App::Asciio::Options ;
6162

62-
use App::Asciio::stripes::angled_arrow ;
6363
use App::Asciio::stripes::angled_arrow ;
6464
use App::Asciio::stripes::section_wirl_arrow ;
6565
use App::Asciio::stripes::stripes ;
@@ -76,7 +76,7 @@ use App::Asciio::Actions::Colors ;
7676

7777
{
7878

79-
my $script_asciio ; # make script non OO
79+
our $script_asciio ; # make script non OO
8080

8181
#------------------------------------------------------------------------------------------------------
8282

@@ -103,35 +103,12 @@ if(defined $script)
103103
}
104104
}
105105

106-
sub run_external_script
107-
{
108-
my ($asciio, $file) = @_ ;
109-
110-
$file //= $asciio->get_file_name() ;
111-
112-
if(defined $file)
113-
{
114-
print STDERR "Asciio: script file: '$file'\n" ;
115-
116-
$script_asciio = $asciio ;
117-
118-
unless (my $return = do $file)
119-
{
120-
warn "Asciio: error running script $file: $@" if $@ ;
121-
# warn "couldn't do $file: $!" unless defined $return ;
122-
# warn "couldn't run $file" unless $return ;
123-
}
124-
125-
$asciio->update_display() ;
126-
}
127-
}
128-
129106
sub new_script_asciio
130107
{
131108
local @ARGV = @ARGV ;
132109
$script_asciio = App::Asciio->new() ;
133110

134-
warn "Asciio: created script asciio object\n" ;
111+
# warn "Asciio: created script asciio object\n" ;
135112

136113
my ($command_line_switch_parse_ok, $command_line_parse_message, $asciio_config)
137114
= $script_asciio->ParseSwitches([@ARGV], 0) ;
@@ -258,8 +235,6 @@ sub select_elements
258235
{
259236
my ($state, @elements_names) = @_ ;
260237

261-
my %named_elements = map { $_ => 1 } @elements_names ;
262-
263238
for my $element (grep { $_->get_user_data('SCRIPT_OBJECT') } $script_asciio->get_elements())
264239
{
265240
$script_asciio->select_elements($state, $element) ;
@@ -298,7 +273,7 @@ if($axis eq 'vertical')
298273
}
299274
else
300275
{
301-
$data = {TYPE => 'hORIZONTAL', POSITION => $position} ;
276+
$data = {TYPE => 'HORIZONTAL', POSITION => $position} ;
302277
}
303278

304279
$script_asciio->add_ruler_lines({NAME => 'from script', %{$data}}) ;

lib/App/Asciio/Setup.pm

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use File::Basename ;
1717

1818
sub setup
1919
{
20-
my($self, $setup_ini_files) = @_ ;
20+
my($self, $setup_ini_files, $object_overrides) = @_ ;
2121

2222
for my $setup_file (@{$setup_ini_files})
2323
{
@@ -43,6 +43,15 @@ for my $setup_file (@{$setup_ini_files})
4343
}
4444

4545
$self->setup_object_options($setup_path, $ini_files->{ASCIIO_OBJECT_SETUP} || []) ;
46+
if (defined $object_overrides)
47+
{
48+
while( my ($k, $v) = each $object_overrides->%* )
49+
{
50+
# print "object override $k -> $v\n" ;
51+
$self->{$k} = $v ;
52+
}
53+
}
54+
4655
$self->setup_stencils($setup_path, $ini_files->{STENCILS} || []) ;
4756
$self->setup_hooks($setup_path, $ini_files->{HOOK_FILES} || []) ;
4857
$self->setup_action_handlers($setup_path, $ini_files->{ACTION_FILES} || []) ;
@@ -123,8 +132,6 @@ sub setup_action_handlers
123132
{
124133
my($self, $setup_path, $action_files) = @_ ;
125134

126-
use strict ; use warnings ;
127-
128135
use Module::Util qw(find_installed) ;
129136
use File::Basename ;
130137

@@ -323,8 +330,9 @@ my $name = $action_handler->{NAME} ;
323330
if(exists $self->{ACTIONS_BY_NAME}{$name})
324331
{
325332
my $reused = '' ;
326-
print STDERR "\e[33mOverriding action: '$name', file: '$action_file', old_file: '" . ($self->{ACTIONS_BY_NAME}{ORIGINS}{$name}{ORIGIN} // 'unknown') ;
327-
333+
print STDERR "\e[33mOverriding action: '$name', file: '$action_file', old_file: '" . ($self->{ACTIONS_BY_NAME}{ORIGINS}{$name}{ORIGIN} // 'unknown')
334+
if $self->{DISPLAY_SETUP_ACTION_INFORMATION} ;
335+
328336
my $old_handler = $self->{ACTIONS_BY_NAME}{$name} ;
329337

330338
if(! defined $action_handler->{SHORTCUTS})
@@ -414,7 +422,7 @@ for my $name (grep { $_ ne 'SHORTCUTS' && $_ ne 'ESCAPE_KEYS' } keys %{$group_de
414422
for my $shortcut ('ARRAY' eq ref $shortcuts_definition ? @$shortcuts_definition : ($shortcuts_definition))
415423
{
416424
print STDERR "Overriding action group '$shortcut' with definition from file '$setup_path/$action_file'!\n"
417-
if exists $handler{$shortcut} ;
425+
if exists $handler{$shortcut} && $self->{DISPLAY_SETUP_ACTION_INFORMATION} ;
418426

419427
# print STDERR "\e[32maction_handler: '$name' shortcut: $shortcut\e[m\n" ;
420428
$handler{$shortcut} = $action_handler ;

lib/App/Asciio/Utils/Scripting.pm

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
use strict;
3+
use warnings;
4+
5+
#------------------------------------------------------------------------------------------------------
6+
7+
package App::Asciio::Utils::Scripting ;
8+
9+
sub run_external_script
10+
{
11+
my ($asciio, $file) = @_ ;
12+
13+
require App::Asciio::Scripting ;
14+
App::Asciio::Scripting->import(@App::Asciio::Scripting::EXPORT) ;
15+
16+
$file //= $asciio->get_file_name() ;
17+
18+
if(defined $file && $file ne '')
19+
{
20+
print STDERR "Asciio: script file: '$file'\n" ;
21+
22+
$App::Asciio::Scripting::script_asciio = $asciio ;
23+
24+
unless (my $return = do $file)
25+
{
26+
warn "Asciio: error running script $file: $@" if $@ ;
27+
# warn "couldn't do $file: $!" unless defined $return ;
28+
# warn "couldn't run $file" unless $return ;
29+
}
30+
31+
$asciio->update_display() ;
32+
}
33+
}
34+
35+
#------------------------------------------------------------------------------------------------------
36+
37+
1 ;
38+
39+

script/asciio_to_text

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use Module::Util qw(find_installed) ;
1010
use File::Basename ;
1111

1212
my $asciio = new App::Asciio() ;
13+
1314
$asciio->{UI} = 'TUI' ;
1415

1516
my ($command_line_switch_parse_ok, $command_line_parse_message, $asciio_config)
@@ -35,7 +36,7 @@ else
3536
] ;
3637
}
3738

38-
$asciio->setup($setup_paths) ;
39+
$asciio->setup($setup_paths, { DISPLAY_SETUP_ACTION_INFORMATION => 0 }) ;
3940

4041
if(defined $asciio_config->{TARGETS}[0])
4142
{

setup/actions/default_bindings.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use App::Asciio::Actions::Unsorted ;
2323
use App::Asciio::Actions::ZBuffer ;
2424

25-
use App::Asciio::Scripting ;
25+
use App::Asciio::Utils::Scripting ;
2626

2727
#----------------------------------------------------------------------------------------------
2828

@@ -237,7 +237,7 @@
237237
'Display action files' => ['000-f', \&App::Asciio::Actions::Unsorted::display_action_files ],
238238
'Display manpage' => ['000-m', \&App::Asciio::Actions::Unsorted::manpage_in_browser ],
239239

240-
'Run external script' => ['00S-exclam', \&App::Asciio::Scripting::run_external_script ],
240+
'Run external script' => ['00S-exclam', \&App::Asciio::Utils::Scripting::run_external_script ],
241241

242242
'Open' => ['000-e', \&App::Asciio::Actions::File::open ],
243243
'Save' => ['000-w', \&App::Asciio::Actions::File::save, undef ],

setup/asciio_object/basic.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
WORK_DIRECTORY => '.asciio_work_dir',
127127
CREATE_BACKUP => 1,
128128
DISPLAY_SETUP_INFORMATION => 0,
129+
DISPLAY_SETUP_ACTION_INFORMATION => 1,
129130
MIDDLE_BUTTON_SELECTION_FILTER =>
130131
sub
131132
{

0 commit comments

Comments
 (0)