Commits

Herbert Breunung committed 8217dfd

menu is now autogenerated from default command list and default menu bar definition

  • Participants
  • Parent commits 12f6a90

Comments (0)

Files changed (7)

File lib/Kephra/App.pm

 	1;
 }
 
-sub close_save {}
-sub close_raw  {}
-
-sub exit {
+sub close_save {
+	close_raw();
+}
+sub close_raw  {
 	Wx::wxTheClipboard->Flush;
 	my $win = Kephra::API::widget('win');
 	$win->destroy();

File lib/Kephra/App/Bar/Menu.pm

 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 $start_ID = my $menu_ID = 1000;
+
     my $bar = Wx::MenuBar->new();
-    
-    my $menu = Kephra::Config::Default::mainmenu;
-    my $win = Kephra::API::widget('main_window');
 
-    my $file_menu = Wx::Menu->new();
-    my $mi = $file_menu->Append( 1000, "New\tCtrl+N");
-    #$mi->SetText("New\tCtrl+N´");
-    $file_menu->Append( 1001, "Open    Ctrl + O");
-    $file_menu->Append( 1002, "Save      Ctrl + S");
-    $file_menu->Append( 1003, "Close    Ctrl + Q");
-    $file_menu->AppendSeparator();
-    $file_menu->Append( 1010, "Exit\tAlt+F4");
-    $bar->Append($file_menu, 'File');
-    my $config_menu = Wx::Menu->new();
-    $config_menu->Append( 7000, 'Dialog');
-    $bar->Append($config_menu, 'Config');
-    my $help_menu = Wx::Menu->new();
-    $help_menu->Append( 8000, 'Documentation');
-    $help_menu->Append( 8001, 'Website');
-    $help_menu->Append( 8002, 'Report a Wish');
-    $help_menu->Append( 8003, 'Info');
-    $bar->Append($help_menu, 'Help');
+    for my $menu_def (@$menu_def) {
+        my @names = keys %{ $menu_def->[0] };
 
-    #print "--- $win", keys %$win;
-    Wx::Event::EVT_MENU( $win, 1000, sub { Kephra::File::new() } );
-    Wx::Event::EVT_MENU( $win, 1010, sub { Kephra::App::exit() } );
+        my $built_menu = Wx::Menu->new();
+        my $menuitemID = $menu_ID;
+        
+        for my $command_ID (@{ $menu_def->[0]{$names[0]} }) {
+            #print $command_ID, "\n";
+            unless ($command_ID and $command_ID) {
+                $built_menu->AppendSeparator;
+                next;
+            }
+            my $item = Wx::MenuItem->new(
+                $built_menu, $menuitemID,
+                $cmd_list->{$command_ID}{'label'}, '',
+                &Wx::wxITEM_NORMAL
+            );
+
+            Wx::Event::EVT_MENU( 
+                $win, $menuitemID,
+                eval 'sub {'. $cmd_list->{$command_ID}{'call'} .'}'
+            );
+
+            $built_menu->Append( $item );
+            $menuitemID++;
+        }
+        $bar->Append($built_menu, ucfirst substr($names[0], 5) );
+        $menu_ID += 100;
+
+    }
 
     return $bar;
 }

File lib/Kephra/App/Dialog.pm

 #}
 sub config {
 	require Kephra::App::Dialog::Config;
-	Kephra::App::Dialog::Config::main();
+	Kephra::App::Dialog::Config::main( _parent() );
 }
 #sub info {
 	# require Kephra::App::Dialog::Info; &Kephra::App::Dialog::Info::combined;

File lib/Kephra/App/Dialog/Config.pm

 use strict;
 use warnings;
 
+use Wx;
+
 package Kephra::Dialog::Config;
 
+sub main {
+	my $parent = shift;
+	my $dialog = Wx::Dialog->new();
+	$dialog->ShowModal;
+}
 
 1;

File lib/Kephra/App/Window.pm

     
     
     #Wx::Event::EVT_SPLITTER_DCLICK( ,sub {});  #&Wx::wxSP_NOBORDER  );
-    Wx::Event::EVT_CLOSE( $self, sub{ Kephra::App::exit(); });
+    Wx::Event::EVT_CLOSE( $self, sub{ Kephra::App::close_save() });
 
     return $self;
 }

File lib/Kephra/Config/Default/CommandList.pm

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

File lib/Kephra/Config/Default/MainMenu.pm

 
 sub get {
 	return [
-		[menu_file => [
+		[{menu_file => [
 			'file_new',
 			'file_open',
 			'file_save',
 			'file_close',
-			,
+			'',
 			'app_close_save',
-		],],
-		[menu_config => [
+		]}],
+		[{menu_config => [
 			'config_dialog',
-		],],
-		[menu_help => [
+		]}],
+		[{menu_help => [
 			'help_documentation',
-			'help_goto_homepage',
-			'help_goto_bugreport',
-			'help_info_dialog',
-		],]
+			'help_homepage',
+			'help_bugreport',
+			'',
+			'help_about',
+		]}],
 	];
 }