Commits

Herbert Breunung committed bd47e49

simplify API

Comments (0)

Files changed (6)

lib/Kephra/API.pm

 use Kephra::DocumentStash;
 
 Kephra::CommandList::register_object_switch_var({
-	'$doc'    => 'active_document()',
-	'$docbar' => 'active_docbar()',
-	'$editor' => 'active_editor()',
+	'$app'    => 'app()',
+	'$doc'    => 'document()',
+	'$docbar' => 'docbar()',
+	'$editor' => 'editor()',
 });
 
-my %widget_caller = (
-	win          => sub { $Kephra::App::Window::_ref },
-	main_window  => sub { $Kephra::App::Window::_ref },
-	doc_bar      => sub { Kephra::App::Panel::Editor::_active_docbar() },
-	document_bar => sub { Kephra::App::Panel::Editor::_active_docbar() },
-);
+sub app             { $Kephra::App::_ref }
+sub main_window     { $Kephra::App::Window::_ref }
+sub editor          { Kephra::DocumentStash::active_editor() }
+sub docbar          { Kephra::App::Panel::Editor::active_docbar() }
+sub document        { Kephra::DocumentStash::active_doc() }
+sub all_documents   { Kephra::DocumentStash::all_doc() }
+sub do_with_all_documents { }
 
-sub app    { $Kephra::App::_ref }
-sub widget {                           # gui parts of main window
-	my $name = shift;                  # widget names are same as in the config
-	croak "requested widget withou name from Kephra::API::widget " unless $name;
-	my $coderef = $widget_caller{ $name };
-	croak caller, "wanted a widget noneexisting in the API: ", $name
-		unless ref $coderef eq ref sub {};
-	return &$coderef();
-}
 sub focus             {$Kephra::App::Window::_ref->set_focus(@_)}
 sub focus_back        {$Kephra::App::Window::_ref->set_focus_back()}
 
 
 sub configs  { }
 
-sub active_editor         { Kephra::DocumentStash::active_editor() }
-sub active_docbar         { Kephra::App::Panel::Editor::active_docbar() }
-sub active_document       { Kephra::DocumentStash::active_doc() }
-sub all_documents         { Kephra::DocumentStash::all_doc() }
-sub do_with_all_documents { }
-
 # event table
 sub add_event_callback {}
 sub del_event_callback {}

lib/Kephra/App.pm

 our @ISA = 'Wx::App';
 our $_ref;
 
+Kephra::CommandList::register_cmd({
+	'app-close-save' => { sub => 'Kephra::API::app()->close_save()', label => 'Exit',
+						 help => ''},
+});
+
 sub OnInit {
 	$_ref = shift;
 	Kephra::CommandList::init();

lib/Kephra/App/Bar/Document.pm

 		my ($nb, $event ) = @_;
 		my $new_page = $nb->GetPage( $event->GetSelection );
 		Kephra::DocumentStash::set_active_doc( $new_page );
-		Kephra::API::widget('win')->refresh_title();
+		Kephra::API::main_window()->refresh_title();
 		Wx::Window::SetFocus( $new_page );
 		$event->Skip;
 	});

lib/Kephra/App/Dialog.pm

 # supplies and checks parents of a dialog
 sub _parent {
 	my $parent = shift;
-	return Kephra::API::widget('main_window') unless defined $parent;
+	return Kephra::API::main_window() unless defined $parent;
 	die "Kephra::App::Dialog need a window as parent not $parent"
 		unless $parent and ref $parent and $parent->isa('Wx::Window');
 	return $parent;
 	#Wx::MessageBox(
 		#@_[0,1],
 		#&Wx::wxOK | &Wx::wxICON_WARNING | &Wx::wxSTAY_ON_TOP,
-		#Kephra::API::widget('main_window')
+		#Kephra::API::main_window()
 	#);
 #}
 #

lib/Kephra/App/Menu.pm

 	my $menu = Wx::Menu->new();
 	my $item_ID = $menu_ID;
 	$menu_ID += 100;
-	my $win = Kephra::API::widget('main_window');
+	my $win = Kephra::API::main_window();
 
 	for my $item_data (@$menu_data) {
 		if (ref $item_data eq ref []) {

lib/Kephra/App/Panel/Editor.pm

 
 sub create_document {
 	my $file = shift;
-	my $doc = Kephra::API::active_document();
-	my $win = Kephra::API::widget('main_window');
+	my $doc = Kephra::API::document();
+	my $win = Kephra::API::main_window();
 	my $main_doc_bar = active_docbar();
 
 	if ($doc and $doc->editor->is_empty and $file) { # overwrite empty doc
 		$doc->assign_file('');
 		$main_doc_bar->set_page_title(0, '');
 	}
-	Kephra::API::widget('win')->refresh_title();
+	Kephra::API::main_window()->refresh_title();
 }
 
 sub raise_document {