Source

Kephra / lib / Kephra / App / Dialog.pm

Full commit
use v5.10;
use strict;
use warnings;
use Wx;
use Kephra::API;

package Kephra::App::Dialog;

Kephra::CommandList::register_cmd({
 'config-global-dialog'=>{sub=>'config',       label=>'Dialog',       keys=> 'ctrl+alt+c'},
 'config-keymap-dialog'=>{sub=>'keymap',       label=>'Keymapping',   keys=> 'ctrl+alt+k'},
 'help-documentation'  =>{sub=>'documentation',label=>'Documentation',keys=> 'F1'},
 'help-about'          =>{sub=>'about',        label=>'About...',     keys=> 'ctrl+alt+a'},
 'help-homepage'       =>{                     label=>'Homepage',     keys=> '',
                          sub=>'Kephra::App::Util::lounch_browser',   parameter => 'http://kephra.sourceforge.net/site/en/home_news.shtml',},
 'help-bugreport'      =>{                     label=>'Send a Wish',  keys=> '',
                          sub=>'Kephra::App::Util::lounch_browser',   parameter => 'http://sourceforge.net/tracker/?func=add&group_id=169747&atid=851593',},
 'help-forum'          =>{                     label=>'Perl Forum',   keys=> '',
                          sub=>'Kephra::App::Util::lounch_browser',   parameter => 'http://www.perl-community.de/bat/poard/latest/24h',},
});


sub _parent {                            # get main window if no parent is given
	my $parent = shift;
	return Kephra::API::main_window() unless defined $parent;
	Kephra::Log::warning("need a window as parent not $parent")
		unless $parent and ref $parent and $parent->isa('Wx::Window');
	return $parent;
}

# standard dialogs
sub msg_box    { Wx::MessageBox( @_[0,1], &Wx::wxOK | &Wx::wxSTAY_ON_TOP, _parent($_[2]) )}
sub info_box   { Wx::MessageBox( @_[0,1], &Wx::wxOK | &Wx::wxICON_INFORMATION, _parent($_[2]) )}
sub warning_box{ Wx::MessageBox( @_[0,1], &Wx::wxOK | &Wx::wxICON_WARNING, _parent($_[2]) )}
sub get_confirm_2 {Wx::MessageBox(@_[0,1],&Wx::wxYES_NO | &Wx::wxICON_QUESTION, _parent($_[2]))}
sub get_confirm_3 {Wx::MessageBox(@_[0,1],&Wx::wxYES_NO | &Wx::wxCANCEL | &Wx::wxICON_QUESTION, _parent($_[2]) )}
sub get_file_open {
	my $title  = shift // 'Open File ...';
	my $dir    = shift // '.';
	my $filter = shift // '(*)|*';
	my $parent = _parent($_[0]);
	Wx::FileSelector( $title, $dir, '', '', $filter, &Wx::wxFD_OPEN, $parent);
}

sub get_file_save { 
	my $title  = shift // 'Save File As ...';
	my $dir    = shift // '.';
	my $filter = shift // '(*)|*';
	my $parent = _parent($_[0]);
	Wx::FileSelector( $title, $dir, '', '', $filter, &Wx::wxFD_SAVE, $parent);
}
#| &Wx::wxSTAY_ON_TOP
#sub get_dir  {  Wx::DirSelector      ( @_[0,1] ,0, [-1,-1], _win()) }
#sub get_font {  Wx::GetFontFromUser  ( _win(), $_[0]) }
#sub get_text {  Wx::GetTextFromUser  ( $_[0], $_[1], "", _win()) }
#sub get_number {Wx::GetNumberFromUser( $_[0], '', $_[1],$_[2], 0, 100000, _win())}
#
# own dialogs
#sub find {
	#require Kephra::App::Dialog::Search; &Kephra::App::Dialog::Search::find;
#}
#sub replace {
	#require Kephra::App::Dialog::Search; &Kephra::App::Dialog::Search::replace;
#}
#sub choose_color {
	#require Kephra::App::Dialog::Color; Kephra::App::Dialog::Color::choose_color();
#}
sub about {
	require Kephra::App::Dialog::About;
	Kephra::App::Dialog::About::create( )->ShowModal;
}
sub config {
	require Kephra::App::Dialog::Config;
	Kephra::App::Dialog::Config::create( )->ShowModal;
}
sub documentation {
	require Kephra::App::Dialog::Documentation;
	Kephra::App::Dialog::Documentation::create( )->ShowModal;
}
sub keymap {
	require Kephra::App::Dialog::Keymap;
	Kephra::App::Dialog::Keymap::create( )->ShowModal;
}

#sub notify_file_changed {
	#require Kephra::App::Dialog::Notify; &Kephra::App::Dialog::Notify::file_changed;
#}
#sub notify_file_deleted {
	#require Kephra::App::Dialog::Notify; &Kephra::App::Dialog::Notify::file_deleted;
#}
#sub save_on_exit {
	#require Kephra::App::Dialog::Exit; &Kephra::App::Dialog::Exit::save_on_exit;
#}


1;