Herbert Breunung avatar Herbert Breunung committed 8f7aa1f

start to use commandlist

Comments (0)

Files changed (6)

lib/Kephra/App.pm

 use warnings;
 use Wx;
 use Kephra::App::Window;
+use Kephra::CommandList;
 
 package Kephra::App;
 our @ISA = 'Wx::App';
 
 sub OnInit {
 	$_ref = shift;
+	Kephra::CommandList::init();
+
 	my $win = Kephra::App::Window->new(__PACKAGE__);
-
 	Kephra::File::new();
 
 	$win->Center();

lib/Kephra/App/Bar/Menu.pm

 use Kephra::API;
 use Kephra::Menu;
 use Kephra::Config::Default;
+use Kephra::CommandList;
 
 package Kephra::App::Bar::Menu;
 
 sub get {
     my $win = Kephra::API::widget('main_window');
     my $menu_def = Kephra::Config::Default::mainmenu();
-    my $cmd_list = Kephra::Config::Default::commandlist();
+    my $cmd_list = Kephra::CommandList::_raw();
     my $start_ID = my $menu_ID = 1000;
 
     my $bar = Wx::MenuBar->new();
             #print $cmd_list->{$command_ID}{'call'}, "\n";
             my $item = Wx::MenuItem->new(
                 $built_menu, $menuitemID,
-                $cmd_list->{$command_ID}{'label'}, '',
+                $cmd_list->{$command_ID}{'name'}, '',
                 &Wx::wxITEM_NORMAL
             );
 
             Wx::Event::EVT_MENU( 
-                $win, $menuitemID,
-                eval 'sub {'. $cmd_list->{$command_ID}{'call'} .'}'
+                $win, $menuitemID, $cmd_list->{$command_ID}{'callref'}
             );
 
             $built_menu->Append( $item );

lib/Kephra/App/Dialog/Config.pm

 
 sub main {
 	my $parent = shift;
-	my $dialog = Wx::Dialog->new($parent, -1, 'title');
+	my $dialog = Wx::Dialog->new($parent, -1, 'Kephra Configs');
 	$dialog->ShowModal;
 }
 

lib/Kephra/App/Menu.pm

 use strict;
 use warnings;
 
+use Kephra::CommandList;
+use Kephra::Config::Default;
+
 package Kephra::App::Menu;
 
+
+my $menuID = 1000;
+
 # build ready to compile data structure from menu definitions (list of commandID)
 sub assemble {
+	my $menu_def = shift;
 }
 
 # make real menus from datastructure
 sub compile {
+	my $menu_def = Kephra::Config::Default::mainmenu();
+	my $cmd_list = Kephra::CommandList::_raw();
+	my $start_ID = my $menu_ID = 1000;
+
+	my $bar = Wx::MenuBar->new();
+
+	for my $menu_def (@$menu_def) {
+		my @names = keys %{ $menu_def->[0] };
+
+		my $built_menu = Wx::Menu->new();
+		my $menuitemID = $menu_ID;
+		
+		for my $command_ID (@{ $menu_def->[0]{$names[0]} }) {
+			unless ($command_ID and $command_ID) {
+				$built_menu->AppendSeparator;
+				next;
+			}
+			#print $cmd_list->{$command_ID}{'call'}, "\n";
+			my $item = Wx::MenuItem->new(
+				$built_menu, $menuitemID,
+				$cmd_list->{$command_ID}{'name'}, '',
+				&Wx::wxITEM_NORMAL
+			);
+
+			Wx::Event::EVT_MENU ( 
+				$win, $menuitemID, $cmd_list->{$command_ID}{'callref'}
+			);
+
+			$built_menu->Append( $item );
+			$menuitemID++;
+		}
+		$bar->Append($built_menu, ucfirst substr($names[0], 5) );
+		$menu_ID += 100;
+
+	}
 }
 
 1;

lib/Kephra/CommandList.pm

 use strict;
 use warnings;
 
-package Kephra::API::CommandList;
+package Kephra::CommandList;
+
+my %list;
+
+sub _raw { \%list }
+sub init {
+	%list = %{ Kephra::Config::Default::commandlist() };
+	for (values %list){
+		$_->{'callref'} = eval 'sub {'. $_->{'function'}.'}';
+		print $_->{'function'}, " ", $_->{'callref'};
+	}
+}
+
+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};
+
+}
 
 
 1;

lib/Kephra/Config/Default/CommandList.pm

 sub get {
 	return {
 		file_new => {
-			call  => 'Kephra::File::new',
-			label => 'New',
+			function  => 'Kephra::File::new',
+			name  => 'New',
 			help  => '',
 			keys  => 'Ctrl + N',
 			icon  => '',
 		},
 		file_open => {
-			call  => 'Kephra::File::open',
-			label => 'Open',
+			function  => 'Kephra::File::open',
+			name => 'Open',
 			help  => 'open one ore multiple files',
 			keys  => 'Ctrl + O',
 			icon  => '',
 		},
 		file_save => {
-			call  => 'Kephra::File::save_active',
-			label => 'Save',
+			function  => 'Kephra::File::save_active',
+			name => 'Save',
 			help  => '',
 			keys  => 'Ctrl + Q',
 			icon  => '',
 		},
 		file_close => {
-			call  => 'Kephra::File::close_active',
-			label => 'Close',
+			function  => 'Kephra::File::close_active',
+			name => 'Close',
 			help  => '',
 			keys  => 'Ctrl + Q',
 			icon  => '',
 		},
 		app_close_save => {
-			call  => 'Kephra::App::close_save',
-			label => 'Exit',
+			function  => 'Kephra::App::close_save',
+			name => 'Exit',
 			help  => '',
 			keys  => 'Alt + Q',
 			icon  => '',
 		},
 		config_dialog => {
-			call  => 'Kephra::App::Dialog::config',
-			label => 'Dialog',
+			function  => 'Kephra::App::Dialog::config',
+			name => 'Dialog',
 			help  => '',
 			keys  => 'Alt + C',
 			icon  => '',
 		},
 		help_documentation => {
-			call  => 'Kephra::Help::documentation',
-			label => 'Documentation',
+			function  => 'Kephra::Help::documentation',
+			name => 'Documentation',
 			help  => '',
 			keys  => 'Alt + D',
 			icon  => '',
 		},
 		help_homepage => {
-			call  => 'Kephra::Help::homepage',
-			label => 'Homepage',
+			function  => 'Kephra::Help::homepage',
+			name => 'Homepage',
 			help  => '',
 			keys  => 'Ctrl + Alt + H',
 			icon  => '',
 		},
 		help_bugreport => {
-			call  => 'Kephra::Help::bugreport',
-			label => 'Send a Wish',
+			function  => 'Kephra::Help::bugreport',
+			name => 'Send a Wish',
 			help  => '',
 			keys  => 'Ctrl + Alt + B',
 			icon  => '',
 		},
 		help_about => {
-			call  => 'Kephra::Help::about',
-			label => 'About ...',
+			function  => 'Kephra::Help::about',
+			name => 'About ...',
 			help  => '',
 			keys  => '',
 			icon  => '',
 __END__
 
 file_new => {
-	call  => 'Kephr::File::new',
-	state => '',
-	event => '',
-	label => 'New',
-	help  => '',
-	keys  => 'Ctrl + N',
-	icon  => '',
+	callref   => compiled function
+	function  => 'Kephra::File::new',
+	state    => '',
+	event    => '',
+	name     => 'New',
+	help     => '',
+	keys     => 'Ctrl + N',
+	icon     => '',
 }
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.