Herbert Breunung avatar Herbert Breunung committed 1c8948e

simplify API::command : no more need to call init, its inḿplicit in switchvar definition call

Comments (0)

Files changed (7)

lib/Kephra/API.pm

  '$doc'    => { switch => 'document',    class => 'Kephra::Document' },
  '$ed'     => { switch => 'editor',      class => 'Kephra::App::Editor' },
 });
-Kephra::API::Command::init();
 
 sub app                 { $Kephra::App::_ref }
 sub main_window         { $Kephra::App::Frame::_ref }

lib/Kephra/API/Command.pm

 use warnings;
 use Kephra::Log;
 
-package Kephra::API::Command;                             # callable by the user
-
+package Kephra::API::Command;                             # callable by the user (UI)
 my %list;     # by ID
 #my %keyproxy;# by keycode
 my %switchvar; #switchvar vor cmd definitions
-my $done_init = 0;
 
 
 sub      _raw_list { \%list }
 	my $api = 'Kephra::API';
 	my $caller = calling_module();
 	return Kephra::Log::error("only callable by $api", 1) if $caller ne $api;
-	return Kephra::Log::error("has to be called before init", 1)
-		if $done_init and not keys %switchvar;
 	#return Kephra::Log::error("call me just once", 1) if keys %switchvar;
 	return Kephra::Log::error("need a hashref", 1) unless ref $var_def eq 'HASH';
 	for my $var (keys %$var_def){
 		#delete $var_def->{$var} unless package_exists ( $var_def->{$var}{'class'} ); # class could be loaded later
 	}
 	%switchvar = %$var_def;
+	compile( keys %list );
 }
 
 sub register {
 		#for (qw/sub options state event label help keys icon/){} filter input later
 		$list{$ID}           = $cmd->{$ID};
 		$list{$ID}{'source'} = $caller;
-		compile($ID) if $done_init;
+		compile($ID) if %switchvar; #dont make sense without defined switch var
 	}
 }
 
-sub init {
-	compile( keys %list );
-	$done_init = 1;
-}
 
 sub compile {
 	for my $cmd_ID (@_) {

lib/Kephra/App/Bar/Document.pm

 use Wx;
 use Wx::AUI;
 use Kephra::API;
+use Kephra::API::Command;
 
 package Kephra::App::Bar::Document;
 our @ISA = 'Wx::AuiNotebook';
 
 use Scalar::Util qw(blessed looks_like_number);
 
+
 Kephra::API::Command::register({
  'docbar-select-left'     =>{sub=>'$docbar->select_page_left',     label=>'Previous Tab',  keys=>'ctrl+pageup'},
  'docbar-select-right'    =>{sub=>'$docbar->select_page_right',    label=>'Next Tab',      keys=>'ctrl+pagedown'},

lib/Kephra/App/Frame.pm

 use v5.12;
 use warnings;
 use Wx;
-use Kephra::API;
 
 
 package Kephra::App::Frame;
 our $_ref;
 my $title_end = "$Kephra::NAME $Kephra::VERSION";
 
-#Kephra::CommandList::register_cmd({
+use Kephra::API;
+
+#Kephra::API::Command::register({
  #'window-fullscreen-toggle'=>{sub => '$win->toggle_fullscreen', label=>'Fullscreen', keys=>'F11'},
  #'iounit-focus'            =>{sub =>'$win->{"part"}{"iounit"}->focus_on_input', label => ' ', keys => 'esc'},
 #});
 	my( $class, $title ) = @_;
 	my( $self ) = $_ref = $class->SUPER::new ( undef, -1, $title, [-1,-1],[1000, 800] );
 	$self->SetIcon( Wx::GetWxPerlIcon() );
-	Kephra::App::Focus::set($self);
+	Kephra::API::focus($self);
 
 	#Wx::Event::EVT_CLOSE( $self, sub{ Kephra::App::close_save() });
 

lib/Kephra/App/Part/Editor.pm

 use Cwd;
 use File::Find;
 use File::Spec;
+use Kephra::App::Panel;
 use Kephra::App::Bar::Document;
 use Kephra::App::Splitter;
 

lib/Kephra/Log.pm

 our $test_mode = 0;
 
 sub init {}
+sub on {}
+sub off {$test_mode = 1}
 
 sub note {
 	return if $test_mode;
 use v5.12;
 use warnings;
+use FindBin;
+BEGIN { unshift @INC, $FindBin::Bin, '.' }
+
 
 package Kephra;
 BEGIN {
 
 package Kephra::App;
 use Wx;
+use Kephra::API;
 use Kephra::App::Bar::Document;
 use Kephra::App::Dialog;
 use Kephra::App::Editor;
 use Kephra::App::Splitter;
 use Kephra::App::Part::Editor;
 use Kephra::File;
-use Kephra::API;
+use Kephra::Log;
+
 use base qw(Wx::App);
 our $_ref;
 
 sub OnInit {
 	my $app  = $_ref = shift;
-	$Kephra::Log::test_mode = 1; 
+	Kephra::Log::off(); 
 	my $win = Kephra::App::Frame->new( 'DDD - double docbar demo' );
+	#my $win = Wx::Frame->new(undef, -1, '');
 	my $ep = Kephra::App::Part::Editor->new($win);
 	Kephra::File::new();
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.