1. Herbert Breunung
  2. Kephra

Commits

Herbert Breunung  committed d99fef6

moved GCL into API namespace

  • Participants
  • Parent commits cb20e8b
  • Branches default

Comments (0)

Files changed (9)

File lib/Kephra/API/Command.pm

View file
 use warnings;
 use Kephra::API;
 
-package Kephra::API::Command;
+package Kephra::API::Command;                             # callable by the user
 
 my %list;     # by ID
-#my %keyproxy; # by keycode
+#my %keyproxy;# by keycode
 my %namespace;# module => cmd prefix 
 my %switch   = ( 'name' => {}, 'package' => {} ); #switchvar vor cmd definitions
 my $done_init = 0;
 
 sub _raw_list { \%list }
 
+sub sub_exists { no strict 'refs'; *{ $_[0] }{CODE} }
 
-# register means: to be called before CommandList::init() - module body execution time
-
+# register means: to be called before Command::init() - module body execution time
 sub register_switch_var {
 	my $var = shift;
+	return Kephra::Log::error("need at least one var => sub relation (hash)", 1)
+		unless ref $var eq 'HASH';
 	my $calling_module = (caller)[0];
-	if (ref $var eq 'HASH'){
-		no strict 'refs';
-		#return Kephra::Log::error #("$- already registered as ".$switch{'name'}{$_}) if exists $switch{'name'}{$_};
-		for my $name (keys %$var){
-			$var->{$name} = $calling_module.'::'.$var->{$name}
-				if index($var->{$name},'::') == -1 and $calling_module;
-			$switch{'name'}{$name} = $var->{$name}
-				if $var->{$name} and defined &{ $var->{$name} };
-		}
+	no strict 'refs';
+	for my $name (keys %$var){
+		#return Kephra::Log::error #("$name already registered as ".$switch{'name'}{$name})
+			#if exists $switch{'name'}{$name};
+		$var->{$name} = $calling_module.'::'.$var->{$name}
+			if index($var->{$name},'::') == -1;
+		next, Kephra::Log::error("need name of existing sub, not name", 1) 
+			if not sub_exists( $var->{$name} ) and $done_init;
+		$switch{'name'}{$name} = $var->{$name}
+			if $var->{$name} and defined &{ $var->{$name} };
 	}
-	else { return Kephra::Log::warning("need a sub name string or of a var => sub hash") }
 }
 
 sub register_context_var {
-	my $var = shift;
+	my $sub = shift;
+	return Kephra::Log::error("need name of existing sub(string)", 1) unless defined $sub;
 	my $calling_module = (caller)[0];
-	if (not ref $var and $var) {
-		$var = $calling_module . '::' . $var if index($var, '::') == -1;
-		$switch{'package'}{$calling_module} = $var if defined $calling_module;
-	}
-	else { return Kephra::Log::warning("need a sub name string or of a var => sub hash") }
+	$sub = $calling_module . '::' . $sub if index($sub, '::') == -1;
+	return Kephra::Log::error("need name of existing sub(string), not $sub", 1)
+		if not sub_exists($sub) and $done_init;
+	$switch{'package'}{$calling_module} = $sub;
 }
 
 sub register_namespace {
-	my $name = shift;
-	my $calling_module = (caller)[0];
-	return Kephra::Log::error("called without value from $calling_module") unless $name;
-	$namespace{ $calling_module } = $name;
+	return Kephra::Log::error("need a command name part as first parameter", 1)
+		unless defined $_[0];
+	$namespace{ (caller)[0] } = $_[0];
 }
 
 sub register {
 	my $calling_module = (caller)[0];
 	my $cmd_namespace = $namespace{ $calling_module }; 
 	for my $ID (keys %$cmd) {
-		my $fullID = (substr($ID,0,1) eq '+' and $cmd_namespace)
+		my $full_ID = (substr($ID,0,1) eq '+' and $cmd_namespace)
 			? $cmd_namespace . substr $ID, 1
 			: $ID ;
 		Kephra::Log::warning("$cmd lacks command namespace to prefix"), next
-				if $fullID ne $ID and not $cmd_namespace;
+				if $full_ID ne $ID and not $cmd_namespace;
 		Kephra::Log::warning( "$cmd already registered to do " .
-			property($fullID, 'sub') . " by " .
-			property($fullID, 'source')  ), next if registered( $fullID );
+			property($full_ID, 'sub') . " by " .
+			property($full_ID, 'source')  ), next if registered( $full_ID );
 		#for (qw/sub options state event label help keys icon/){} filter input later
-		$list{$fullID}           = $cmd->{$ID};
-		$list{$fullID}{'source'} = $calling_module;
-		compile($fullID) if $done_init;
+		$list{$full_ID}           = $cmd->{$ID};
+		$list{$full_ID}{'source'} = $calling_module;
+		compile($full_ID) if $done_init;
 	}
 }
 
 
 sub init {
 	compile( keys %list );
+	for my $var (keys %{ $switch{'name'} }) {
+		my $call = $switch{'name'}{$var};
+		Kephra::Log::warning("$var has noneexisting switch call $call")
+			unless sub_exists( $call );
+	}
+	for my $pkg (keys %{ $switch{'package'} }) {
+		my $call = $switch{'package'}{$pkg};
+		Kephra::Log::warning("$pkg has noneexisting context switch call $call")
+			unless sub_exists( $call );
+	}
 	$done_init = 1;
 }
 
 			}
 		}
 		else { $call = $data->{'source'}.'::'.$call if index($call,'::') == -1 }
+		#my $coderef = $call;
+		#my $switchpos = index($coderef, '()->');
+		#substr $coderef, $switchpos, 4, '::' if $switchpos > -1;
+		#Kephra::Log::warning("$cmd calls nonexisting sub $call", 1)
+		#	unless sub_exists( $coderef );
+
 		# adding tail (suffix) of the call, signature part
 		$call .= exists $data->{'parameter'} # just one parameter yet
 			? '(\''.$data->{'parameter'}.'\')'

File lib/Kephra/API/GCL.pm

View file
+use strict;
+use warnings;
+
+# GUI Composition Language
+package Kephra::API::GCL;
+
+
+1;
+
+__END__
+
+will be split one day as a seperate project

File lib/Kephra/App/Editor.pm

View file
 		my $key = Kephra::API::KeyMap::keycode_from_event($event);
 		Kephra::API::log("pressed key $key inside the editor");
 		if (Kephra::API::KeyMap::keycode_is_registered($key)){
-			my $cmd = Kephra::API::KeyMap::cmd_from_code($key);
+			my $cmd = Kephra::API::KeyMap::cmd_from_keycode($key);
 			Kephra::API::log("run command: $cmd");
 			Kephra::API::Command::run( $cmd );
 		}

File lib/Kephra/App/GCL.pm

-use strict;
-use warnings;
-
-# GUI Composition Language
-package Kephra::App::GCL;
-
-
-1;
-
-__END__
-
-will be split one day as a seperate project

File lib/Kephra/App/Panel.pm

View file
 sub hide {}
 sub all_widgets {  }
 sub widget_by_nr { }
-sub get_position {
-	my ($self) = shift; 
-	my ($child) = shift;
-	$self->sizer->get_position($child);
-}
+sub get_position { $_[0]->sizer->get_position($_[1]) }
 
 1;

File lib/Kephra/App/Part/FileBrowser.pm

View file
 	} );
 	Wx::Event::EVT_KEY_DOWN ($self, sub {
 		my ($fb, $event) = @_;
-		my $key = Kephra::KeyMap::code_from_event($event);
+		my $key = Kephra::API::KeyMap::keycode_from_event($event);
 		Kephra::API::log("pressed key $key inside the filebrowser");
 		if    ($key ==  &Wx::WXK_ESCAPE) {Kephra::API::focus_back() }
 		elsif ($key ==  &Wx::WXK_F2)     {Kephra::API::focus_back() }

File lib/Kephra/App/Part/IOUnit.pm

View file
 
 Kephra::API::Command::register_namespace('iounit');
 
-Kephra::API::KeyMap::register_map({'iounit'=>{'esc' => 1, 'window-fullscreen-toggle' => '' } });
+Kephra::API::KeyMap::register_map({ 'iounit' => {
+	'esc' => 1,
+	'window-fullscreen-toggle' => '' 
+} });
 
 
 sub new {
 
 	Wx::Event::EVT_KEY_DOWN ($input, sub {
 		my ($input, $event) = @_;
-		my $key = Kephra::API::KeyMap::code_from_event($event);
+		my $key = Kephra::API::KeyMap::keycode_from_event($event);
 		Kephra::API::log("pressed key $key inside the IOUnit");
 
 		my $slot = $self->{'output_slots'}{ $self->{'active_slot_name'} };

File lib/Kephra/App/Sizer.pm

View file
 sub prepend         { shift->insert(  0, 0, @_ ) }
 sub append          { shift->insert( -1, 0, @_ ) }
 sub append_expanded { shift->insert( -1, 1, @_ ) }
-sub insert_before   { my($self)=shift; $self->insert( $self->get_position(shift)  , 1, @_ ) }
-sub insert_after    { my($self)=shift; $self->insert( $self->get_position(shift)+1, 1, @_ ) }
-
-#sub insert_before   {
-	#my ($self) = shift;
-	#my ($mark_child) = shift;
-	#my $pos = $self->get_position($mark_child);
-	#return Kephra::Log::error("bookmark child $mark_child not found", 1) unless $pos > -1;
-	#$self->insert($pos, 0, @_);
-#}
-#sub insert_after   {
-	#my ($self) = shift;
-	#my ($mark_child) = shift;
-	#my $pos = $self->get_position($mark_child);
-	#return Kephra::Log::error("bookmark child $mark_child not found", 1) unless $pos > -1;
-	#$self->insert($pos+1, 0, @_);
-#}
+sub insert_before   {
+	my ($self) = shift;
+	my ($mark_child) = shift;
+	my $pos = $self->get_position($mark_child);
+	return Kephra::Log::error("bookmark child $mark_child not found", 1) unless $pos > -1;
+	$self->insert($pos, 0, @_);
+}
+sub insert_after   {
+	my ($self) = shift;
+	my ($mark_child) = shift;
+	my $pos = $self->get_position($mark_child);
+	return Kephra::Log::error("bookmark child $mark_child not found", 1) unless $pos > -1;
+	$self->insert($pos+1, 0, @_);
+}
 sub insert          {
 	my ($self) = shift;
 	my ($position) = shift;

File lib/Kephra/App/Window.pm

View file
 my $title_end = "$Kephra::NAME $Kephra::VERSION";
 
 Kephra::API::Command::register({
- 'window-fullscreen-toggle'=>{sub => '$win->toggle_fullscreen', label=>'Fullscreen', keys=>'F11'},
+ 'window-fullscreen-toggle'=>{sub =>'$win->toggle_fullscreen', label=>'Fullscreen', keys=>'F11'},
  'iounit-focus'            =>{sub =>'$win->{"part"}{"iounit"}->focus_on_input', label => ' ', keys => 'esc'},
 });