package Kephra::Dialog::Template; our $VERSION = 0.01; use strict; use warnings; use Wx qw( wxVERTICAL wxHORIZONTAL wxLEFT wxRIGHT wxTOP wxALL wxBOTTOM wxGROW wxEXPAND wxALIGN_RIGHT wxSYSTEM_MENU wxCAPTION wxSTAY_ON_TOP wxNO_FULL_REPAINT_ON_RESIZE wxCLOSE_BOX wxMINIMIZE_BOX wxFRAME_NO_TASKBAR wxBITMAP_TYPE_XPM wxWHITE wxTR_NO_BUTTONS wxTR_HIDE_ROOT wxTR_SINGLE ); use Wx::Event qw( EVT_BUTTON EVT_LISTBOX EVT_LISTBOX_DCLICK EVT_CLOSE); my $TEMPLATE = ""; sub _ref { if (ref $_[0] eq 'Wx::Dialog'){ $Kephra::app{dialog}{config} = $_[0] } else { $Kephra::app{dialog}{config} } } sub template_dialog { my $frame = Kephra::App::Window::_ref(); my $g_l10n = $Kephra::localisation{dialog}{general}; $TEMPLATE = ""; # making window & main design my $d = Wx::Dialog->new( $frame, -1, ' Templates', [ 0,0 ], [ 470, 560 ], ); my ($panel); my $list = Wx::ListBox->new( $d, -1 ); my $counter = 0; for my $name ( _list() ){ $list->Append( $name ); $list->SetClientData( $counter++, $name ); } EVT_LISTBOX( $list, $list, \&onselected ); EVT_LISTBOX_DCLICK( $list, $list, sub{ &onselected; $d->Close } ); # button line $d->{apply_button} = Wx::Button->new ( $d, -1, $g_l10n->{apply} ); $d->{cancel_button} = Wx::Button->new( $d, -1, $g_l10n->{cancel}); EVT_BUTTON( $d, $d->{apply_button}, sub {shift->Close} ); EVT_BUTTON( $d, $d->{cancel_button},sub {shift->Close} ); my $button_sizer = Wx::BoxSizer->new(wxHORIZONTAL); $button_sizer->Add( $d->{apply_button}, 0, wxRIGHT, 14 ); $button_sizer->Add( $d->{cancel_button}, 0, wxRIGHT, 22 ); # assembling lines my $d_sizer = Wx::BoxSizer->new(wxVERTICAL); $d_sizer->Add( $list, 1, wxEXPAND|wxALL, 14); $d_sizer->Add( $button_sizer, 0, wxBOTTOM|wxALIGN_RIGHT, 12); # release $d->SetSizer($d_sizer); $d->SetAutoLayout(1); $d->ShowModal; Wx::Window::SetFocus( $d->{cancel_button} ); EVT_CLOSE( $d, \&quit_config_dialog ); $TEMPLATE; } sub onselected { my ($list,$event) = @_; my $new = ""; unless( $event->GetInt() == -1 ) { $new = $event->GetString; } $TEMPLATE = $new; } sub _list { my @list; my $cfg = $Kephra::config{file}{templates}; my $file = Kephra::Config::filepath($cfg->{directory}, $cfg->{file}); my $tmp = Kephra::Config::File::load( $file ); if (exists $tmp->{template}){ $tmp = Kephra::Config::Tree::_convert_node_2_AoH(\$tmp->{template}); for my $template ( @{$tmp} ) { push @list, $template->{name}; } } @list; } sub quit_config_dialog { my ( $win, $event ) = @_; $win->Destroy; } 1;