Commits

Herbert Breunung committed 5bb19d7

fixing menu compiler to handle submenus

Comments (0)

Files changed (5)

lib/Kephra/App/Bar/Document.pm

 use Kephra::App::Editor;
 use Kephra::App::Panel;
 use Kephra::App::Util;
+use Kephra::CommandList;
 use Kephra::DocumentStash;
 
 package Kephra::App::Bar::Document;
 our @ISA = 'Wx::AuiNotebook';
 
+Kephra::CommandList::register_cmd_namespace('app-docbar');
+Kephra::CommandList::register_object_switch_var('Kepra::API::active_docbar()');
+Kephra::CommandList::register_cmd({
+	'doc-select-left'=> { sub => '$_->select_page_left()', label => 'Previous Tab',
+						help => ''},
+	'doc-select-right' => { sub => '$_->select_page_right()', label => 'Next Tab',
+						help => ''},
+});
+
+
 my ($is_panel, $is_widget) = Kephra::App::Util::get(qw/is_panel is_widget/);
 
 sub new {

lib/Kephra/App/Menu.pm

 			next unless $cmd_data;
 			push @menu_data, {
 				'type' => 'item',
-				'label'=> ucfirst $cmd_data->{'name'},
-				'callref' => $cmd_data->{'callref'},
+				'label'=> ucfirst $cmd_data->{'label'},
+				'coderef' => $cmd_data->{'coderef'},
 			};
 		}
 	}
 
 	for my $item_data (@$menu_data) {
 		if (ref $item_data eq ref []) {
+			my ($submenu, $name) = compile( $item_data );
 			my $item = Wx::MenuItem->new(
-				$menu, $item_ID++, $item_data->[0]{'menu_ID'}, '',
-				&Wx::wxITEM_NORMAL, compile( $item_data ),
+				$menu, $item_ID++, $name, ' ', &Wx::wxITEM_NORMAL, $submenu
 			);
 			#if (defined $item_data->{icon}) {
 				#my $bmp = ;
 		elsif (ref $item_data eq ref {} and exists $item_data->{'type'}) {
 			my $item = Wx::MenuItem->new(
 				$menu, $item_ID,
-				$item_data->{'label'}, '', &Wx::wxITEM_NORMAL
+				$item_data->{'label'}, ' ', &Wx::wxITEM_NORMAL
 			);
 
-			Wx::Event::EVT_MENU( $win, $item_ID, $item_data->{'callref'} );
+			Wx::Event::EVT_MENU( $win, $item_ID, $item_data->{'coderef'} );
 
 			$menu->Append( $item );
 			$item_ID++;

lib/Kephra/CommandList.pm

 sub register_cmd {
 	my $cmd = shift;
 	$cmd = [$cmd] unless ref $cmd eq ref [];
-	my $caller = (caller)[0];
+	my $calling_module = (caller)[0];
 	for my $cmd (@$cmd) {
-		Kephra::Log::warning( 'register_cmd: '.
-			"$cmd already registered to do ". cmd_property($cmd, 'function') .
-		                             " by " . cmd_property($cmd, 'source')  ), next
-			if cmd_exists( $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}{'function'} = 
-		#$list{$cmd}{'source'} = $caller;
+		#$list{$cmd}{'sub'} = 
+		#$list{$cmd}{'source'} = $calling_module;
 	}
 }
 
 sub init {
-print "----";
 	%list = %{ Kephra::Config::Default::commandlist() };
 	for (values %list){
-		$_->{'callref'} = eval 'sub {'. $_->{'function'}.'}';
+		$_->{'coderef'} = eval 'sub {'. $_->{'sub'}.'}';
 	}
 }
+sub prepare_cmd {}
 
-sub call {}
+sub call {
+	my $cmd = shift;
+	$cmd = [$cmd] unless ref $cmd eq ref [];
+	for (@$cmd) { $list{$_}{'callref'}() }
+}
 
 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] } }
 __END__
 
 cmd_ID => {
-	callref   => # compiled function with maybe one option
-	function  => 'Kephra::File::new',
+	coderef   => # compiled function with maybe one option
+	sub       => 'Kephra::File::new',
 	options   => [],
 	source    => # module file where function is located
 	state     => '',
 	event     => '',
-	name      => 'New',
+	label     => 'New',
 	help      => '',
 	keys      => 'Ctrl + N',
 	icon      => '',

lib/Kephra/Config/Default/CommandList.pm

 sub get {
 	return {
 		'file-new' => {
-			function  => 'Kephra::File::new',
-			name  => 'New',
+			sub   => 'Kephra::File::new',
+			label => 'New',
 			help  => '',
 			keys  => 'Ctrl + N',
 			icon  => '',
 		},
 		'file-open' => {
-			function  => 'Kephra::File::open',
-			name => 'Open',
+			sub   => 'Kephra::File::open',
+			label => 'Open',
 			help  => 'open one ore multiple files',
 			keys  => 'Ctrl + O',
 			icon  => '',
 		},
 		'file-save' => {
-			function  => 'Kephra::File::save_active',
-			name => 'Save',
+			sub   => 'Kephra::File::save_active',
+			label => 'Save',
 			help  => '',
 			keys  => 'Ctrl + Q',
 			icon  => '',
 		},
 		'file-close' => {
-			function  => 'Kephra::File::close_active',
-			name => 'Close',
+			sub   => 'Kephra::File::close_active',
+			label => 'Close',
 			help  => '',
 			keys  => 'Ctrl + Q',
 			icon  => '',
 		},
 		'app-close-save' => {
-			function  => 'Kephra::App::close_save',
-			name => 'Exit',
+			sub   => 'Kephra::App::close_save',
+			label => 'Exit',
 			help  => '',
 			keys  => 'Alt + Q',
 			icon  => '',
 		},
 		'edit-select-all' => {
-			function  => '',
-			name => 'Select All',
+			sub   => '',
+			label => 'Select All',
 			help  => '',
 			keys  => 'Ctrl + A',
 		},
 		'edit-select-block' => {
-			function  => '',
-			name => '',
+			sub   => '',
+			label => '',
 			help  => '',
 			keys  => '',
 		},
 		'edit-select-block-up' => {
-			function  => '',
-			name => '',
+			sub   => '',
+			label => '',
 			help  => '',
 			keys  => '',
 		},
 		'edit-select-block-down' => {
-			function  => '',
-			name => '',
+			sub   => '',
+			label => '',
 			help  => '',
 			keys  => '',
 		},
 		'document-select-leftmost' => {
-			function  => 'Kephra::App::Panel::Editor::select_tab_leftmost',
-			name => '',
+			sub   => 'Kephra::App::Panel::Editor::select_tab_leftmost',
+			label => '',
 			help  => '',
 			keys  => '',
 		},
 		'document-select-rightmost' => {
-			function  => 'Kephra::App::Panel::Editor::select_tab_rightmost',
-			name => '',
+			sub   => 'Kephra::App::Panel::Editor::select_tab_rightmost',
+			label => ' ',
 			help  => '',
 			keys  => '',
 		},
 		'document-select-left' => {
-			function  => 'Kephra::App::Panel::Editor::select_tab_left',
-			name => '',
+			sub   => 'Kephra::App::Panel::Editor::select_tab_left',
+			label => ' ',
 			help  => '',
 			keys  => '',
 		},
 		'document-select-right' => {
-			function  => 'Kephra::App::Panel::Editor::select_tab_right',
-			name => '',
+			sub   => 'Kephra::App::Panel::Editor::select_tab_right',
+			label => ' ',
 			help  => '',
 			keys  => '',
 		},
 		'document-move-leftmost' => {
-			function  => 'Kephra::App::Panel::Editor::move_tab_leftmost',
-			name => '',
+			sub   => 'Kephra::App::Panel::Editor::move_tab_leftmost',
+			label => ' ',
 			help  => '',
 			keys  => '',
 		},
 		'document-move-rightmost' => {
-			function  => 'Kephra::App::Panel::Editor::move_tab_rightmost',
-			name => '',
+			sub   => 'Kephra::App::Panel::Editor::move_tab_rightmost',
+			label => ' ',
 			help  => '',
 			keys  => '',
 		},
 		'document-move-left' => {
-			function  => 'Kephra::App::Panel::Editor::move_tab_left',
-			name => '',
+			sub   => 'Kephra::App::Panel::Editor::move_tab_left',
+			label => ' ',
 			help  => '',
 			keys  => '',
 		},
 		'document-move-right' => {
-			function  => 'Kephra::App::Panel::Editor::move_tab_right',
-			name => '',
+			sub   => 'Kephra::App::Panel::Editor::move_tab_right',
+			label => ' ',
 			help  => '',
 			keys  => '',
 		},
 		'config-global-dialog' => {
-			function  => 'Kephra::App::Dialog::config',
-			name => 'Global Dialog',
+			sub   => 'Kephra::App::Dialog::config',
+			label => 'Global Dialog',
 			help  => '',
 			keys  => 'Alt + C',
 			icon  => '',
 		},
 		'config-keymap-dialog' => {
-			function  => 'Kephra::App::Dialog::keymap',
-			name => 'Keymapping',
+			sub   => 'Kephra::App::Dialog::keymap',
+			label => 'Keymapping',
 			help  => '',
 			keys  => 'Alt + K',
 			icon  => '',
 		},
 		'help-documentation' => {
-			function  => 'Kephra::App::Dialog::documentation',
-			name => 'Documentation',
+			sub   => 'Kephra::App::Dialog::documentation',
+			label => 'Documentation',
 			help  => '',
 			keys  => 'F1',
 			icon  => '',
 		},
 		'help-homepage' => {
-			function  => 'Kephra::Help::homepage',
-			name => 'Homepage',
+			sub   => 'Kephra::Help::homepage',
+			label => 'Homepage',
 			help  => '',
 			keys  => 'Ctrl + Alt + H',
 			icon  => '',
 		},
 		'help-bugreport' => {
-			function  => 'Kephra::Help::bugreport',
-			name => 'Send a Wish',
+			sub   => 'Kephra::Help::bugreport',
+			label => 'Send a Wish',
 			help  => '',
 			keys  => 'Ctrl + Alt + B',
 			icon  => '',
 		},
 		'help-about' => {
-			function  => 'Kephra::App::Dialog::about',
-			name => 'About ...',
+			sub   => 'Kephra::App::Dialog::about',
+			label => 'About ...',
 			help  => '',
 			keys  => 'Ctrl + Alt + A',
 			icon  => '',

lib/Kephra/Config/Default/MainMenu.pm

 			'-global-dialog',
 			'-keymap-dialog',
 		],
+		[	{menu_ID => 'document'},
+			[
+				{menu_ID => 'change'},
+				'-select-left',
+				'-select-right',
+				'-select-leftmost',
+				'-select-rightmost',
+				'',
+				'-move-left',
+				'-move-right',
+				'-move-leftmost',
+				'-move-rightmost',
+			],
+		],
 		[	{menu_ID => 'help'},
 			'-documentation',
 			'-homepage',