Curses-UI
view release on metacpan or search on metacpan
lib/Curses/UI.pm view on Meta::CPAN
# ----------------------------------------------------------------------
# Focusable dialog windows
# ----------------------------------------------------------------------
sub tempdialog()
{
my $self = shift;
my $class = shift;
my %args = @_;
my $id = "__window_$class";
my $dialog = $self->add($id, $class, %args);
$dialog->modalfocus;
my $return = $dialog->get;
$self->delete($id);
$self->root->focus(undef, 1);
return $return;
}
# The argument list will be returned unchanged, unless it
# contains only one item. In that case ($ifone, $_[0]) will
# be returned. This enables constructions like:
#
# $cui->dialog("Some dialog message");
#
# instead of:
#
# $cui->dialog(-message => "Some dialog message");
#
sub process_args()
{
my $self = shift;
my $ifone = shift;
if (@_ == 1) { @_ = ($ifone => $_[0]) }
return @_;
}
sub error()
{
my $self = shift;
my %args = $self->process_args('-message', @_);
$self->tempdialog('Dialog::Error', %args);
}
sub dialog()
{
my $self = shift;
my %args = $self->process_args('-message', @_);
$self->tempdialog('Dialog::Basic', %args);
}
sub question()
{
my $self = shift;
my %args = $self->process_args('-question', @_);
$self->tempdialog('Dialog::Question', %args);
}
sub calendardialog()
{
my $self = shift;
my %args = $self->process_args('-title', @_);
$self->tempdialog('Dialog::Calendar', %args);
}
sub filebrowser()
{
my $self = shift;
my %args = $self->process_args('-title', @_);
# Create title
unless (defined $args{-title}) {
my $l = $self->root->lang;
$args{-title} = $l->get('file_title');
}
# Select a file to load from.
$self->tempdialog('Dialog::Filebrowser', %args);
}
sub dirbrowser()
{
my $self = shift;
my %args = $self->process_args('-title', @_);
# Create title
unless (defined $args{-title}) {
my $l = $self->root->lang;
$args{-title} = $l->get('dir_title');
}
# Select a file to load from.
$self->tempdialog('Dialog::Dirbrowser', %args);
}
sub savefilebrowser()
{
my $self = shift;
my %args = $self->process_args('-title', @_);
my $l = $self->root->lang;
# Create title.
$args{-title} = $l->get('file_savetitle')
unless defined $args{-title};
# Select a file to save to.
my $file = $self->filebrowser(-editfilename => 1, %args);
return unless defined $file;
# Check if the file exists. Ask for overwrite
# permission if it does.
if (-e $file)
{
# Get language specific data.
my $pre = $l->get('file_overwrite_question_pre');
my $post = $l->get('file_overwrite_question_post');
my $title = $l->get('file_overwrite_title');
( run in 2.289 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )