Commits

Herbert Breunung committed 0914b64

new shortcut syntax for menu definition if item id contains name of parent

Comments (0)

Files changed (6)

lib/Kephra/App.pm

 our $_ref;
 
 Kephra::CommandList::register_cmd({
-	'app-close-save' => { sub => 'Kephra::API::app()->close_save()', label => 'Exit',
-						 help => ''},
+	'app-close-save' => 
+		{ sub => 'Kephra::API::app()->close_save()', label => 'Exit', keys  => 'Alt + Q',
+		 help => ''},
 });
 
 sub OnInit {
 sub close_save {
 	close_raw();
 }
+
 sub close_raw  {
-	Wx::wxTheClipboard->Flush;
-	my $win = Kephra::API::widget('win');
+	
+	my $win = Kephra::API::main_window();
 	$win->destroy();
 }
 
 sub OnExit {
 	my $app = shift;
+	Wx::wxTheClipboard->Flush;
 	1;
 }
 

lib/Kephra/App/Bar/Menu.pm

 
 use Kephra::App::Menu;
 use Kephra::Config::Default;
+use Kephra::Log;
 
 package Kephra::App::Bar::Menu;
 
 sub get {
-    my $menu_def = Kephra::Config::Default::mainmenu();
-    die "__PACKAGE__::get got no array ref" unless ref $menu_def eq ref [];
+	my $menu_def = Kephra::Config::Default::mainmenu();
+	return Kephra::Log::error("::get: got no array ref")
+		unless ref $menu_def eq ref [];
 
-    my $bar = Wx::MenuBar->new();
-
-    for my $menu_data (@{ Kephra::App::Menu::assemble($menu_def) }) {
-        next unless ref $menu_data eq ref [];
-        $bar->Append( Kephra::App::Menu::compile( $menu_data ) );
-    }
-    return $bar;
+	my $bar = Wx::MenuBar->new();
+	for my $menu_data (@{ Kephra::App::Menu::assemble($menu_def) }) {
+		next unless ref $menu_data eq ref [];
+		$bar->Append( Kephra::App::Menu::compile( $menu_data ) );
+	}
+	return $bar;
 }
 
 sub set {
-    my $which_menu = shift;
+	my $which_menu = shift;
 }
 
 

lib/Kephra/App/Menu.pm

 
 use Kephra::API;
 use Kephra::CommandList;
+use Kephra::Log;
 
 package Kephra::App::Menu;
 
 
 # build ready to compile data structure from menu definitions (list of commandID)
 sub assemble {
-	my $menu_def = shift;
+	my ($menu_def, $parents) = @_;
 	die "__PACKAGE__::assemble got no array ref" unless ref $menu_def eq ref [];
 	my $menu_ID = '';
 	my @menu_data;
+	$parents = [] unless ref $parents eq ref [] and $parents->[0];
 
 	for my $item_def (@$menu_def) {
-		if    (ref $item_def eq ref []) { push  @menu_data, assemble($item_def) }
+		if    (ref $item_def eq ref []) { 
+			push  @menu_data, assemble($item_def, [@$parents, $menu_ID]) 
+		}
 		elsif (ref $item_def eq ref {}) {
 			$menu_ID = $item_def->{'menu_ID'}
 				if defined $item_def->{'menu_ID'} and not $menu_ID;
 		elsif (not defined $item_def or not $item_def) {
 			push  @menu_data, 'separator';
 		} else  {
-			$item_def = $menu_ID.$item_def if substr($item_def, 0, 1) eq '-';
+			if    (substr($item_def, 0, 1) eq '+')
+				{$item_def = join('-',@$parents, $menu_ID) . substr($item_def, 1);}
+			elsif (substr($item_def, 0, 1) eq '-')
+				{$item_def = join('-',@$parents)           . substr($item_def, 1);}
+
 			my $cmd_data = Kephra::CommandList::cmd_all_properties( $item_def );
 			next unless $cmd_data;
 			push @menu_data, {

lib/Kephra/CommandList.pm

 use strict;
 use warnings;
+use Kephra::Log;
 
 package Kephra::CommandList;
 
 }
 sub register_cmd {
 	my $cmd = shift;
-	$cmd = [$cmd] unless ref $cmd eq ref [];
+	return Kephra::Log::warning( 'register_cmd: "$cmd" has to be a hash ref')
+			unless ref $cmd eq ref {};
 	my $calling_module = (caller)[0];
-	for my $cmd (@$cmd) {
+	for my $ID (keys %$cmd) {
 		Kephra::Log::warning( "register_cmd: $cmd already registered to do " .
-			cmd_property($cmd, 'sub') . " by " .
-			cmd_property($cmd, 'source')  ), next
-				if cmd_exists( $cmd );
-		Kephra::Log::warning( 'register_cmd: "$cmd" has to be a hash ref'), next
-			unless ref $cmd eq ref {};
-		#$list{$cmd}{'sub'} = 
-		#$list{$cmd}{'source'} = $calling_module;
+			cmd_property($ID, 'sub') . " by " .
+			cmd_property($ID, 'source')  ), next
+				if cmd_exists( $ID );
+		#for (qw/sub options state event label help keys icon/){} filter input
+		$list{$ID}           = $cmd->{$ID};
+		$list{$ID}{'source'} = $calling_module;
 	}
 }
 
 sub init {
 	%list = %{ Kephra::Config::Default::commandlist() };
 	for (values %list){
-		$_->{'coderef'} = eval 'sub {'. $_->{'sub'}.'}';
+		$_->{'coderef'} = $_->{'sub'};
+		$_->{'coderef'} = $_{'source'} . $_->{'coderef'}
+			if substr($_->{'sub'},0,2 eq '::');
+		$_->{'coderef'} = eval 'sub {'. $_->{'coderef'}.'}';
 	}
 }
 sub prepare_cmd {}
 sub call {
 	my $cmd = shift;
 	$cmd = [$cmd] unless ref $cmd eq ref [];
-	for (@$cmd) { $list{$_}{'callref'}() }
+	for (@$cmd) { $list{$_}{'callref'}->() if exists $list{$_} }
 }
 
 sub cmd_exists          { 1 if defined $_[0]     and exists $list{ $_[0] }          }

lib/Kephra/Config/Default/CommandList.pm

 		},
 		'document-select-left' => {
 			sub   => 'Kephra::App::Panel::Editor::select_tab_left',
-			label => ' ',
+			label => 'Left',
 			help  => '',
 			keys  => '',
 		},
 		'document-select-right' => {
 			sub   => 'Kephra::App::Panel::Editor::select_tab_right',
-			label => ' ',
+			label => 'Right',
 			help  => '',
 			keys  => '',
 		},

lib/Kephra/Config/Default/MainMenu.pm

 sub get {
 	return [
 		[	{menu_ID => 'file'},
-			'-new',
-			'-open',
-			'-save',
-			'-close',
+			'+-new',
+			'+-open',
+			'+-save',
+			'+-close',
 			'',
 			'app-close-save',
 		],
-		[	{menu_ID => 'config'},
-			'-global-dialog',
-			'-keymap-dialog',
-		],
 		[	{menu_ID => 'document'},
 			[
 				{menu_ID => 'change'},
-				'-select-left',
-				'-select-right',
-				'-select-leftmost',
-				'-select-rightmost',
+				'--select-left',
+				'--select-right',
+				'--select-leftmost',
+				'--select-rightmost',
 				'',
-				'-move-left',
-				'-move-right',
-				'-move-leftmost',
-				'-move-rightmost',
+				'--move-left',
+				'--move-right',
+				'--move-leftmost',
+				'--move-rightmost',
 			],
 		],
+		[	{menu_ID => 'config'},
+			'+-global-dialog',
+			'+-keymap-dialog',
+		],
 		[	{menu_ID => 'help'},
-			'-documentation',
-			'-homepage',
-			'-bugreport',
+			'+-documentation',
+			'+-homepage',
+			'+-bugreport',
 			'',
-			'-about',
+			'+-about',
 		],
 	];
 }
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.