summaryrefslogtreecommitdiffstats
path: root/perl-install/interactive.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/interactive.pm')
-rw-r--r--perl-install/interactive.pm574
1 files changed, 429 insertions, 145 deletions
diff --git a/perl-install/interactive.pm b/perl-install/interactive.pm
index c31d333d3..49f47d05c 100644
--- a/perl-install/interactive.pm
+++ b/perl-install/interactive.pm
@@ -1,4 +1,4 @@
-package interactive; # $Id$
+package interactive;
use diagnostics;
use strict;
@@ -6,74 +6,76 @@ use strict;
#-######################################################################################
#- misc imports
#-######################################################################################
-use MDK::Common::Func;
use common;
use do_pkgs;
-#- minimal example using interactive:
-#
-#- > use lib qw(/usr/lib/libDrakX);
-#- > use interactive;
-#- > my $in = interactive->vnew;
-#- > $in->ask_okcancel('title', 'question');
-#- > $in->exit;
-
-#- ask_from_ takes global options ($common):
-#- title => window title
-#- messages => message displayed in the upper part of the window
-#- advanced_messages => message displayed when "Advanced" is pressed
-#- ok => force the name of the "Ok"/"Next" button
-#- cancel => force the name of the "Cancel"/"Previous" button
-#- advanced_label => force the name of the "Advanced" button
-#- advanced_label_close => force the name of the "Basic" button
-#- advanced_state => if set to 1, force the "Advanced" part of the dialog to be opened initially
-#- focus_cancel => force focus on the "Cancel" button
-#- focus_first => force focus on the first entry
-#- callbacks => functions called when something happen: complete canceled advanced changed focus_out ok_disabled
-
-#- ask_from_ takes a list of entries with fields:
-#- val => reference to the value
-#- label => description
-#- icon => icon to put before the description
-#- help => tooltip
-#- advanced => wether it is shown in by default or only in advanced mode
-#- disabled => function returning wether it should be disabled (grayed)
-#- gtk => gtk preferences
-#- type =>
-#- button => (with clicked or clicked_may_quit)
-#- (type defaults to button if clicked or clicked_may_quit is there)
-#- (val need not be a reference) (if clicked_may_quit return true, it's as if "Ok" was pressed)
-#- label => (val need not be a reference) (type defaults to label if val is not a reference)
-#- bool (with "text" or "image" (which overrides text) giving an image filename)
-#- range (with min, max)
-#- combo (with list, not_edit, format)
-#- list (with list, icon2f (aka icon), separator (aka tree), format (aka pre_format function),
-#- help can be a hash or a function,
-#- tree_expanded boolean telling wether the tree should be wide open by default
-#- quit_if_double_click boolean
-#- allow_empty_list disables the special cases for 0 and 1 element lists
-#- image2f is a subroutine which takes a value of the list as parameter, and returns an array (text, image_file_name))
-#- entry (the default) (with hidden)
-#
-#- heritate from this class and you'll get all made interactivity for same steps.
-#- for this you need to provide
-#- - ask_from_listW(o, title, messages, arrayref, default) returns one string of arrayref
-#-
-#- where
-#- - o is the object
-#- - title is a string
-#- - messages is an refarray of strings
-#- - default is an optional string (default is in arrayref)
-#- - arrayref is an arrayref of strings
-#- - arrayref2 contains booleans telling the default state,
-#-
-#- ask_from_list and ask_from_list_ are wrappers around ask_from_biglist and ask_from_smalllist
-#-
-#- ask_from_list_ just translate arrayref before calling ask_from_list and untranslate the result
-#-
-#- ask_from_listW should handle differently small lists and big ones.
-#-
+=head1 NAME
+interactive - a GUI layer with multiple backend (text console, Gtk+ GUI, web)
+
+=head1 SYNOPSYS
+
+B<interactive> enables to write GUIes that will work everywhere:
+
+=head1 Functions
+
+=over 4
+
+=item * text console
+
+implemented by L<interactive::stdio> & L<interactive::curses>
+
+=item * web browser
+
+implemented by L<interactive::http>
+
+=item * GUI
+
+implemented by L<interactive::gtk>
+
+=back
+
+Interactive inherits from L<do_pkgs> and thus $in->do_pkgs will return
+an usable C<do_pkgs> object suitable for installing packages.
+
+=head1 Minimal example using interactive
+
+ use lib qw(/usr/lib/libDrakX);
+ use interactive;
+ my $in = interactive->vnew;
+ $in->ask_okcancel('title', 'question');
+ $in->exit;
+
+=head1 Backends
+
+heritate from this class and you'll get all made interactivity for same steps.
+for this you need to provide
+
+C<ask_from_listW(o, title, messages, arrayref, default)> which returns one string of arrayref
+
+where:
+
+=over 4
+
+=item * B<o> is the object
+
+=item * B<title> is a string
+
+=item * B<messages> is an refarray of strings
+
+=item * B<default> is an optional string (default is in arrayref)
+
+=item * B<arrayref> is an arrayref of strings
+
+=item * B<arrayref>2 contains booleans telling the default state,
+
+=back
+
+=head1 Functions
+
+=over
+
+=cut
#-######################################################################################
#- OO Stuff
@@ -105,14 +107,73 @@ sub vnew {
my $o = interactive::gtk->new;
if ($o_icon && $o_icon ne 'default' && !$::isWizard) { $o->{icon} = $o_icon } else { undef $o->{icon} }
return $o;
+ } elsif ($::testing) {
+ die;
+ }
+ }
+
+ require interactive::curses;
+ interactive::curses->new;
+}
+
+sub ok { N_("Ok") }
+sub cancel { N_("Cancel") }
+
+sub markup_parse {
+ my ($s) = @_;
+ my @l;
+ my @attrs;
+
+ while ($s) {
+ if ($s =~ s!^<(\w+)(\s+[^>]*?)?>!!s) {
+ push @attrs, [ $1, $2 ];
+ } elsif ($s =~ s!^</(\w+)>!!) {
+ my $previous = pop @attrs;
+ $previous->[0] eq $1 or return;
+ } elsif ($s =~ s!^(&(amp|lt|gt);)!!) {
+ push @l, [ $1, @attrs ];
+ } elsif ($s =~ s!^([^<>&]+)!!s) {
+ push @l, [ $1, @attrs ];
+ } else {
+ return;
}
}
+ markup_simplify(\@l);
+ \@l;
+}
+
+sub markup_simplify {
+ my ($l) = @_;
+ foreach (@$l) {
+ my ($s, @attrs) = @$_;
+ my %attrs = map {
+ my ($tag, $attrs) = @$_;
+ my $long = { b => { weight => "bold" },
+ i => { style => "italic" },
+ big => { size => 'larger' },
+ }->{$tag};
+ $long ? %$long : map { /^(.*?)=['"]?(.*?)['"]?$/ } split(' ', $attrs);
+ } @attrs;
+
+ $s = +{ '&amp;' => '&', '&lt;' => '<', '&gt;' => '>' }->{$s} || $s;
+
+ @$_ = ($s, if_(%attrs, \%attrs));
+ }
+}
- require 'log.pm'; #- "require log" causes some pb, perl thinking that "log" is the log() function
- undef *log::l;
- *log::l = sub {}; # otherwise, it will bother us :(
- require interactive::newt;
- interactive::newt->new;
+sub markup_remove {
+ my ($s) = @_;
+ if (my $l = markup_parse($s)) {
+ join('', map { $_->[0] } @$l);
+ } else {
+ $s;
+ }
+}
+
+#- drop markup as fallback
+sub adapt_markup {
+ my ($_o, $s) = @_;
+ markup_remove($s);
}
sub enter_console {}
@@ -120,56 +181,90 @@ sub leave_console {}
sub suspend {}
sub resume {}
sub end {}
-sub exit { exit($_[0]) }
+sub exit {
+ if ($::isStandalone) {
+ require standalone;
+ standalone::exit($_[0]);
+ } else {
+ exit($_[0]);
+ }
+}
+
#-######################################################################################
#- Interactive functions
#-######################################################################################
sub ask_warn {
- my ($o, $title, $message) = @_;
- ask_warn_($o, { title => $title, messages => $message });
+ my ($o, $title, $message, $o_icon) = @_;
+ ask_warn_($o, { title => $title, messages => $message, icon => $o_icon });
}
sub ask_yesorno {
my ($o, $title, $message, $b_def) = @_;
ask_yesorno_($o, { title => $title, messages => $message }, $b_def);
}
sub ask_okcancel {
- my ($o, $title, $message, $b_def) = @_;
- ask_okcancel_($o, { title => $title, messages => $message }, $b_def);
+ my ($o, $title, $message, $b_def, $o_icon) = @_;
+ ask_okcancel_($o, { title => $title, messages => $message, icon => $o_icon }, $b_def);
}
sub ask_warn_ {
my ($o, $common) = @_;
- ask_from_listf_raw_no_check($o, $common, undef, [ $o->ok ]);
+ local $o->{modal} = $o->{modal} || $::isInstall; # make these popup at install time
+ ask_from_listf_raw_no_check($o, $common, \&translate, [ $o->ok ]);
}
sub ask_yesorno_ {
my ($o, $common, $b_def) = @_;
$common->{cancel} = '';
- ask_from_listf_raw($o, $common, sub { translate($_[0]) }, [ N_("Yes"), N_("No") ], $b_def ? "Yes" : "No") eq "Yes";
+ ask_from_listf_raw($o, $common, \&translate, [ N_("Yes"), N_("No") ], $b_def ? "Yes" : "No") eq "Yes";
}
sub ask_okcancel_ {
my ($o, $common, $b_def) = @_;
if ($::isWizard) {
- $::no_separator = 1;
$common->{focus_cancel} = !$b_def;
ask_from_no_check($o, $common, []);
} else {
- ask_from_listf_raw($o, $common, sub { translate($_[0]) }, [ $o->ok, $o->cancel ], $b_def ? $o->ok : "Cancel") eq $o->ok;
+ ask_from_listf_raw($o, $common, \&translate, [ $o->ok, $o->cancel ], $b_def ? $o->ok : $o->cancel) eq $o->ok;
}
}
+sub ask_filename {
+ my ($o, $common) = @_;
+ $common->{want_a_dir} = 0;
+ $o->ask_fileW($common);
+}
+
+sub ask_directory {
+ my ($o, $common) = @_;
+ $common->{want_a_dir} = 1;
+ $o->ask_fileW($common);
+}
+
+#- predecated
sub ask_file {
my ($o, $title, $o_dir) = @_;
- $o->ask_fileW($title, $o_dir);
+ $o->ask_fileW({ title => $title, want_a_dir => 0, directory => $o_dir });
}
+
sub ask_fileW {
- my ($o, $title, $_dir) = @_;
- $o->ask_from_entry($title, N("Choose a file"));
+ my ($o, $common) = @_;
+ $o->ask_from_entry($common->{title}, $common->{message} || N("Choose a file"));
}
+=item ask_from_list($o, $title, $message, $l, $o_def)
+
+=item ask_from_list_($o, $title, $message, $l, $o_def)
+
+ask_from_list() and ask_from_list_() are wrappers around ask_from_biglist and ask_from_smalllist
+
+ask_from_list_() just translate arrayref before calling ask_from_list and untranslate the result
+
+ask_from_listW() should handle differently small lists and big ones.
+
+=cut
+
sub ask_from_list {
my ($o, $title, $message, $l, $o_def) = @_;
ask_from_listf($o, $title, $message, undef, $l, $o_def);
@@ -177,7 +272,7 @@ sub ask_from_list {
sub ask_from_list_ {
my ($o, $title, $message, $l, $o_def) = @_;
- ask_from_listf($o, $title, $message, sub { translate($_[0]) }, $l, $o_def);
+ ask_from_listf($o, $title, $message, \&translate, $l, $o_def);
}
sub ask_from_listf_ {
@@ -266,7 +361,7 @@ sub ask_from_entries {
my @l = map { my $i = ''; { label => $_, val => \$i } } @$l;
- $o->ask_from_({ title => $title, messages => $message, callbacks => \%callback,
+ $o->ask_from_({ title => $title, messages => $message, %callback,
focus_first => 1 }, \@l) or return;
map { ${$_->{val}} } @l;
}
@@ -293,60 +388,70 @@ sub ask_from__add_modify_remove {
$continue = 1;
} } }
N_("Add"), if_(@{$e->{list}} > 0, N_("Modify"), N_("Remove")));
- $o->ask_from_({ title => $title, messages => $message, callbacks => \%callback }, \@l) or return;
+ $o->ask_from_({ title => $title, messages => $message, %callback }, \@l) or return;
return 1 if !$continue;
}
}
}
-#- can get a hash of callback: focus_out changed and complete
+#- can get a hash of callback: validate
#- moreove if you pass a hash with a field list -> combo
#- if you pass a hash with a field hidden -> emulate stty -echo
sub ask_from {
my ($o, $title, $message, $l, %callback) = @_;
- ask_from_($o, { title => $title, messages => $message, callbacks => \%callback }, $l);
+ ask_from_($o, { title => $title, messages => $message, %callback }, $l);
}
-sub ask_from_normalize {
- my ($o, $common, $l) = @_;
+sub _normalize_entry {
+ my ($o, $e) = @_;
- ref($l) eq 'ARRAY' or internal_error('ask_from_normalize');
- foreach my $e (@$l) {
- if (my $li = $e->{list}) {
- ref($e->{val}) =~ /SCALAR|REF/ or internal_error($e->{val} ? "field {val} must be a reference (it is $e->{val})" : "field {val} is mandatory"); #-#
- if ($e->{sort} || @$li > 10 && !exists $e->{sort}) {
- my @l2 = map { may_apply($e->{format}, $_) } @$li;
- my @places = sort { $l2[$a] cmp $l2[$b] } 0 .. $#l2;
- $e->{list} = $li = [ map { $li->[$_] } @places ];
- }
- $e->{type} = 'iconlist' if $e->{icon2f};
- $e->{type} = 'treelist' if $e->{separator};
- add2hash_($e, { not_edit => 1 });
- $e->{type} ||= 'combo';
+ if (my $li = $e->{list}) {
+ ref($e->{val}) =~ /SCALAR|REF/ or internal_error($e->{val} ? "field {val} must be a reference (it is $e->{val})" : "field {val} is mandatory"); #-#
+ if ($e->{sort} || @$li > 10 && !exists $e->{sort}) {
+ my @l2 = map { may_apply($e->{format}, $_) } @$li;
+ my @places = sort { $l2[$a] cmp $l2[$b] } 0 .. $#l2;
+ $e->{list} = $li = [ map { $li->[$_] } @places ];
+ }
+ $e->{type} = 'iconlist' if $e->{icon2f};
+ $e->{type} = 'treelist' if $e->{separator} && $e->{type} ne 'combo';
+ add2hash_($e, { not_edit => 1 });
+ $e->{type} ||= 'combo';
- if (!$e->{not_edit}) {
- die q(when using "not_edit" you must use strings, not a data structure) if ref(${$e->{val}}) || any { ref $_ } @$li;
- }
- if ($e->{type} ne 'combo' || $e->{not_edit}) {
- ${$e->{val}} = $li->[0] if !member(may_apply($e->{format}, ${$e->{val}}), map { may_apply($e->{format}, $_) } @$li);
- }
- } elsif ($e->{type} eq 'range') {
- $e->{min} <= $e->{max} or die "bad range min $e->{min} > max $e->{max} (called from " . join(':', caller()) . ")";
- ${$e->{val}} = max($e->{min}, min(${$e->{val}}, $e->{max}));
- } elsif ($e->{type} eq 'button' || $e->{clicked} || $e->{clicked_may_quit}) {
- $e->{type} = 'button';
- $e->{clicked_may_quit} ||= $e->{clicked} ? sub { $e->{clicked}(); 0 } : sub {};
- $e->{val} = \ (my $_v = $e->{val}) if !ref($e->{val});
- } elsif ($e->{type} eq 'label' || !ref($e->{val})) {
- $e->{type} = 'label';
- $e->{val} = \ (my $_v = $e->{val}) if !ref($e->{val});
- } else {
- $e->{type} ||= 'entry';
+ if (!$e->{not_edit}) {
+ die q(when using "not_edit" you must use strings, not a data structure) if ref(${$e->{val}}) || any { ref $_ } @$li;
}
- $e->{disabled} ||= sub { 0 };
+ if ($e->{type} ne 'combo' || $e->{not_edit}) {
+ ${$e->{val}} = $li->[0] if !member(may_apply($e->{format}, ${$e->{val}}), map { may_apply($e->{format}, $_) } @$li);
+ }
+ } elsif ($e->{type} eq 'range') {
+ $e->{min} <= $e->{max} or die "bad range min $e->{min} > max $e->{max} (called from " . join(':', caller()) . ")";
+ ${$e->{val}} = max($e->{min}, min(${$e->{val}}, $e->{max}));
+ } elsif ($e->{type} eq 'button' || $e->{clicked} || $e->{clicked_may_quit}) {
+ $e->{type} = 'button';
+ $e->{clicked_may_quit} ||= $e->{clicked} ? sub { $e->{clicked}(); 0 } : sub {};
+ $e->{val} = \ (my $_v = $e->{val}) if !ref($e->{val});
+ } elsif (!$e->{type} && !$e->{val}) {
+ $e->{type} = 'only_label';
+ $e->{val} = \ (my $_v = $o->adapt_markup(delete $e->{label}));
+ } elsif ($e->{type} eq 'label' || !ref($e->{val})) {
+ $e->{type} = 'label';
+ $e->{val} = \ (my $_v = $e->{val}) if !ref($e->{val});
+ } elsif ($e->{type} eq 'expander') {
+ _normalize_entries($o, $e->{children});
+ } else {
+ $e->{type} ||= 'entry';
}
+ $e->{label} = $o->adapt_markup($e->{label}) if $e->{label};
+}
+
+sub _normalize_entries {
+ my ($o, $l) = @_;
+
+ ref($l) eq 'ARRAY' or internal_error('ask_from_normalize');
+
+ _normalize_entry($o, $_) foreach @$l;
#- do not display empty lists and one element lists
@$l = grep {
@@ -362,18 +467,177 @@ sub ask_from_normalize {
1;
}
} @$l;
+}
+
+sub ask_from_normalize {
+ my ($o, $common, $l) = @_;
+
+ if ($common->{focus_first}) {
+ if (my $e = find { $_->{val} } @$l) {
+ $e->{focus} = sub { 1 };
+ }
+ }
+
+ _normalize_entries($o, $l);
if (!$common->{title} && $::isStandalone) {
($common->{title} = $0) =~ s|.*/||;
}
$common->{interactive_help} ||= $o->{interactive_help};
$common->{interactive_help} ||= $common->{interactive_help_id} && $o->interactive_help_sub_get_id($common->{interactive_help_id});
+ if (!$::isInstall) {
+ delete $common->{$_} foreach qw(interactive_help interactive_help_id);
+ }
$common->{advanced_label} ||= N("Advanced");
- $common->{advanced_label_close} ||= N("Basic");
- $common->{$_} = $common->{$_} ? [ deref($common->{$_}) ] : [] foreach qw(messages advanced_messages);
- add2hash_($common->{callbacks} ||= {}, { changed => sub {}, focus_out => sub {}, complete => sub { 0 }, canceled => sub { 0 }, advanced => sub {} });
+ $common->{advanced_label_close} and log::l("advanced_label_close is not used anymore");
+ $common->{$_} = $common->{$_} ? [ map { $o->adapt_markup($_) } deref($common->{$_}) ] : []
+ foreach qw(messages advanced_messages);
+
+ if ($common->{callbacks}) {
+ $common->{callbacks}{changed} and internal_error(q(global "changed" callback is not handled anymore, use a per-entry changed callback));
+ $common->{callbacks}{focus_out} and internal_error(q(global "focus_out" callback is not handled anymore, use a per-entry focus_out callback));
+ add2hash($common, delete $common->{callbacks});
+ }
+ if (my $complete = delete $common->{complete}) {
+ $common->{validate} = sub { !first($complete->()) };
+ }
+ add2hash_($common, { validate => sub { 1 } });
+}
+
+sub migrate_advanced {
+ my ($common, $l) = @_;
+ my ($l1, $l2) = partition { !$_->{advanced} } @$l;
+ my $advanced_message = join("\n", @{$common->{advanced_messages}});
+ [ @$l1, if_(@$l2, { type => 'expander',
+ if_($advanced_message, message => $advanced_message),
+ text => $common->{advanced_label},
+ expanded => $common->{advanced_state},
+ children => $l2,
+ }) ];
}
+
+=item ask_from_($o, $common, $l)
+
+ask_from_() takes global options ($common):
+
+=over 4
+
+=item * B<title>: window title
+
+=item * B<messages>: message displayed in the upper part of the window
+
+=item * B<ok>: force the name of the "Ok"/"Next" button
+
+=item * B<cancel>: force the name of the "Cancel"/"Previous" button
+
+=item * B<focus_cancel>: force focus on the "Cancel" button
+
+=item * I<focus_first>: (deprecated) force focus on the first entry
+
+=item * B<ok_disabled>: function returning whether {ok} should be disabled (grayed)
+
+=item * B<validate>: function called when {ok} is pressed. If it returns false, the first entry is focused, otherwise it quits
+
+=item * I<advanced>: (deprecated) function called when the "advanced" expander is toggled
+
+=item * I<advanced_messages>: (deprecated) message displayed when "Advanced" is pressed
+
+=item * I<advanced_label>: (deprecated) force the name of the "Advanced" button
+
+=item * I<advanced_label_close>: (deprecated) force the name of the "Basic" button
+
+=item * I<advanced_state>: (deprecated) if set to 1, force the "Advanced" part of the dialog to be opened initially
+
+=item * I<advanced_title>: title of the advanced item popup dialog (else reusing main title)
+
+=item * I<callbacks>: (deprecated) functions called when something happen: complete advanced ok_disabled
+
+=back
+
+ask_from_ takes a list of entries with fields:
+
+=over 4
+
+=item * B<val>: reference to the value
+
+=item * B<label>: description
+
+=item * B<title>: a boolean: whether the label should be displayed as a title (see GNOME's HIG)
+
+=item * B<icon>: icon to put before the description
+
+=item * B<help>: tooltip
+
+=item * I<advanced>: (deprecated) whether it is shown in by default or only in advanced mode
+
+=item * B<focus_out>: function called when the entry is focused out
+
+=item * B<changed>: function called when the entry is modified
+
+=item * B<validate>: function called when "Ok" is pressed. If it returns false, this entry is focused, otherwise it quits
+
+=item * B<disabled>: function returning whether it should be disabled (grayed)
+
+=item * B<focus>: function returning whether it should be focused
+
+=item * B<alignment>: preferred alignment
+
+=item * B<do_not_expand>: do not eat all horizontal space
+
+=item * B<install_button>: if possible, use improved graphical style
+
+=item * B<gtk>: gtk preferences
+
+=item * B<type>:
+
+=over 4
+
+=item * B<button>: (with clicked or clicked_may_quit)
+
+I<type> defaults to button if clicked or clicked_may_quit is there.
+I<val> need not be a reference.
+If I<clicked_may_quit> return true, it's as if "Ok" was pressed.
+
+=item * B<label>:
+I<val> need not be a reference.
+I<type> defaults to label if val is not a reference.
+
+=item * B<bool>: (with "text" or "image" (which overrides text) giving an image filename)
+
+=item * B<range>: (with min, max, SpinButton)
+
+=item * B<combo>: (with list, not_edit, format)
+
+=item * B<list>: (with list, icon2f (aka icon), separator (aka tree), format (aka pre_format function),
+
+It has these optional parameters:
+
+=over 4
+
+=item * B<help>: can be a hash or a function,
+
+=item * B<tree_expanded>: boolean telling whether the tree should be wide open by default
+
+=item * B<quit_if_double_click>: boolean
+
+=item * B<allow_empty_list>: disables the special cases for 0 and 1 element lists
+
+=item * B<image2f>: a subroutine which takes a value of the list as parameter, and returns image_file_name
+
+=back
+
+=item * B<entry>: (the default) (with hidden)
+
+=item * B<expander>: (with text, expanded, message, children(a list of sub entries))
+
+=back
+
+=back
+
+=cut
+
+
sub ask_from_ {
my ($o, $common, $l) = @_;
ask_from_normalize($o, $common, $l);
@@ -385,13 +649,20 @@ sub ask_from_no_check {
my ($o, $common, $l) = @_;
ask_from_normalize($o, $common, $l);
$common->{cancel} = '' if !defined wantarray();
- my ($l1, $l2) = partition { !$_->{advanced} } @$l;
- $o->ask_fromW($common, $l1, $l2);
+ my $l_ = migrate_advanced($common, $l);
+ $o->ask_fromW($common, $l_);
}
sub ask_from_real {
my ($o, $common, $l) = @_;
- my ($l1, $l2) = partition { !$_->{advanced} } @$l;
- my $v = $o->ask_fromW($common, $l1, $l2);
+ my $l_ = migrate_advanced($common, $l);
+ my $v = $o->ask_fromW($common, $l_);
+
+ foreach my $e (@$l) {
+ if ($e->{type} eq 'range') {
+ ${$e->{val}} = max($e->{min}, min(${$e->{val}}, $e->{max}));
+ }
+ }
+
%$common = ();
$v;
}
@@ -437,16 +708,36 @@ sub ask_browse_tree_info_refW { #- default definition, do not use with too many
sub wait_message {
my ($o, $title, $message, $b_temp) = @_;
+ my $inline_title = $::isInstall ? $title : '';
+ $inline_title ||= N("Please wait");
- my $w = $o->wait_messageW($title, [ N("Please wait"), deref($message) ]);
+ my $w = $o->wait_messageW($title, $inline_title, $message);
push @tempory::objects, $w if $b_temp;
my $b = before_leaving { $o->wait_message_endW($w) };
#- enable access through set
- MDK::Common::Func::add_f4before_leaving(sub { $o->wait_message_nextW([ deref($_[1]) ], $w) }, $b, 'set');
+ MDK::Common::Func::add_f4before_leaving(sub { $o->wait_message_nextW($_[1], $w) }, $b, 'set');
$b;
}
+
+sub wait_message_with_progress_bar {
+ my ($in, $o_title) = @_;
+
+ my $w = $in->wait_message($o_title, '');
+ my $last_msg;
+ $w, sub {
+ my ($msg, $current, $total) = @_;
+ if ($msg) {
+ $w->set($last_msg = $msg);
+ }
+ if ($total) {
+ $w or internal_error('You must first give some text to display');
+ $w->set(join("\n", $last_msg, "$current / $total"));
+ }
+ };
+}
+
sub kill() {}
@@ -475,27 +766,20 @@ sub helper_separator_tree_to_tree {
}
-sub interactive_help_has_id {
- my ($_o, $id) = @_;
- exists $help::{$id};
-}
-
-sub interactive_help_get_id {
- my ($_o, @l) = @_;
- @l = map {
- join("\n\n", map { s/\n/ /mg; $_ } split("\n\n", translate($help::{$_}->())));
- } grep { exists $help::{$_} } @l;
- join("\n\n\n", @l);
-}
-
sub interactive_help_sub_get_id {
my ($o, $id) = @_;
- $o->interactive_help_has_id($id) && sub { $o->interactive_help_get_id($id) };
+ eval { $o->is_help_file_exist($id) }
+ && sub { $o->interactive_help_get_id($id) };
}
sub interactive_help_sub_display_id {
my ($o, $id) = @_;
- $o->interactive_help_has_id($id) && sub { $o->ask_warn(N("Help"), $o->interactive_help_get_id($id)) };
+ eval { $o->interactive_help_has_id($id) }
+ && sub { $o->ask_warn(N("Help"), $o->interactive_help_get_id($id)) };
}
+=back
+
+=cut
+
1;