Herbert Breunung avatar Herbert Breunung committed 9b67628

punching out the command list API

Comments (0)

Files changed (7)

lib/Kephra/API.pm

 
 use Carp;
 use Kephra::App::Window;
+use Kephra::CommandList;
 use Kephra::DocumentStash;
-use Kephra::App::Panel::Editor;
+
+Kephra::CommandList::register_object_switch_var({
+	'$doc'    => 'active_document()',
+	'$docbar' => 'active_docbar()',
+	'$editor' => 'active_editor()',
+});
 
 my %widget_caller = (
 	win          => sub { $Kephra::App::Window::_ref },
 		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 focus             {$Kephra::App::Window::_ref->set_focus(@_)}
+sub focus_back        {$Kephra::App::Window::_ref->set_focus_back()}
 
 # IO-unit
 sub input             { $Kephra::App::Panel::IOUnit::_ref->get_line() }
 
 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 active_editor         { Kephra::DocumentStash::active_editor() }
 sub all_documents         { Kephra::DocumentStash::all_doc() }
 sub do_with_all_documents { }
 

lib/Kephra/App/Menu.pm

 sub assemble {
 	my $menu_def = shift;
 	die "__PACKAGE__::assemble got no array ref" unless ref $menu_def eq ref [];
-	my $cmd_list = Kephra::CommandList::_raw();
 	my $menu_ID = '';
 	my @menu_data;
 
 			push  @menu_data, 'separator';
 		} else  {
 			$item_def = $menu_ID.$item_def if substr($item_def, 0, 1) eq '-';
-			next unless exists $cmd_list->{$item_def};
+			my $cmd_data = Kephra::CommandList::cmd_all_properties( $item_def );
+			next unless $cmd_data;
 			push @menu_data, {
 				'type' => 'item',
-				'label'=> ucfirst $cmd_list->{$item_def}{'name'},
-				'callref' => $cmd_list->{$item_def}{'callref'},
+				'label'=> ucfirst $cmd_data->{'name'},
+				'callref' => $cmd_data->{'callref'},
 			};
 		}
 	}

lib/Kephra/CommandList.pm

 package Kephra::CommandList;
 
 my %list;
+my %namespace;
 my %object_alias;
 
-sub _raw { \%list }
+sub register_object_switch_var {
+	return unless $_[0] and ref $_[0] eq ref {};
+	my %alias = %{$_[0]};
+	for my $var ( keys %alias ){
+		die "__PACKAGE__::register_object_switch_var: $var already registered as ".
+			$object_alias{$var}
+				if exists $object_alias{$var};
+		my $switch = $alias{$var};
+		$switch = (caller)[0] . '::' . $switch if index($switch, '::') == -1;
+		$object_alias{$var} = $switch;
+	}
+}
+sub register_cmd_namespace {
+	die "__PACKAGE__::register_cmd_namespace: called without value from ".
+		(caller)[0]
+			unless $_[0];
+	$namespace{ (caller)[0] } = $_[0];
+}
+sub register_cmd {
+	my $cmd = shift;
+	$cmd = [$cmd] unless ref $cmd eq ref [];
+	for my $cmd (@$cmd) {
+		die "$cmd already registered to do ". cmd_property($cmd, 'function') .
+		                             " by " . cmd_property($cmd, 'source')
+			if cmd_exists( $cmd );
+		#$list{$cmd}{'function'} = 
+	}
+}
+
 sub init {
 	%list = %{ Kephra::Config::Default::commandlist() };
 	for (values %list){
 	}
 }
 
-sub add_function_alias_var {
-}
-sub add_cmd {}
+sub cmd_exists          { 1 if defined $_[0]     and exists $list{ $_[0] }          }
+sub cmd_property_exists { 1 if cmd_exists($_[0]) and exists $list{ $_[0] }{ $_[1] } }
+sub cmd_add {}
 
-sub cmd_properties {
-	my $cmd = shift;
-	return $list{ $cmd } if exists $list{ $cmd }
-}
-sub cmd_value {
-	my ($cmd, $value) = @_;
-	return $list{ $cmd }{ $value} 
-		if exists $list{ $cmd } and exists $list{ $cmd }{ $value};
-
-}
+sub cmd_all_properties { $list{$_[0]}                if cmd_exists($_[0]) }
+sub cmd_property       { $list{$_[0]}{$_[1]}         if cmd_property_exists(@_) }
+sub cmd_set_property   { $list{$_[0]}{$_[1]} = $_[2] if cmd_property_exists(@_) }
 
 
 1;

lib/Kephra/Config/Default/CommandList.pm

 	callref   => compiled function with maybe one option
 	function  => 'Kephra::File::new',
 	options   => [],
+	source    => '',
 	state     => '',
 	event     => '',
 	name      => 'New',

lib/Kephra/DocumentStash.pm

 
 my %side_buffer;
 
-# Kephra::CommandList::add_function_alias_var
-
 sub previous_doc  { $previous }
 sub active_doc    { $active }
 sub active_editor { $active->editor }
 sub doc_by_anything {
 	my $any = shift;
 	warn __PACKAGE__."::get_by_anything: need a parameter!" unless $any;
-	return ref($any) eq ''                      ? doc_by_path ($any)
+	return     ref($any) eq ''                  ? doc_by_path ($any)
 			 : $any->isa('Wx::Panel')           ? doc_by_panel($any)
 			 : $any->isa('Kephra::App::Editor') ? doc_by_ed   ($any)
 			 : $any->isa('Kephra::Document')    ? $document{$any->editor} 

lib/Kephra/Edit.pm

 #package Kephra::Edit;
 package Kephra::App::Editor;
 
-#Kephra::CommandList::add_cmd {
+Kephra::CommandList::register_cmd_namespace('edit');
+#Kephra::CommandList::add_cmd (
 # id => [function  => '$doc->move_sel_or_word_left',]
-#};
+#);
 
 #$config_container = Kephra::Config:: {}
 

lib/Kephra/Logger.pm

 sub init {
 }
 
+sub error {
+}
+
 1;
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.