Commits

Herbert Breunung  committed 2745a10

can switch between editor and file browser by keys

  • Participants
  • Parent commits f5409c1

Comments (0)

Files changed (4)

File lib/Kephra.pm

     qw/Benchmark Encode Encode::Guess Cwd/,
     qw/File::Find File::Spec File::UserConfig Config::General YAML/,
     qw/PPI Moo/,
-    qw/Wx Wx::Scintilla Wx::Perl::ProcessStream/, # Wx::STC 
+    qw/Wx Wx::STC Wx::Perl::ProcessStream/, # Wx::Scintilla
 );
 our @used_wx_modules = qw/Wx::AUI Wx::DND Wx::RichText/; # Wx::STC
 

File lib/Kephra/App/Editor.pm

 use warnings;
 use Wx;
 #use Wx::DND;
-#use Wx::STC;
-use Wx::Scintilla;
+use Wx::STC;
+#use Wx::Scintilla;
 use Kephra::App::Util;
 
 package Kephra::App::Editor;
-#our @ISA = 'Wx::StyledTextCtrl';
-our @ISA = 'Wx::ScintillaTextCtrl';
+our @ISA = 'Wx::StyledTextCtrl';
+#our @ISA = 'Wx::ScintillaTextCtrl';
 
 my $mk_color = Kephra::App::Util::get('make_color');
 
 			( $event->ShiftDown
 			+ $event->ControlDown * 2 
 			+ $event->AltDown     * 4);
-		# reacting on Enter
 		if      ($event->GetKeyCode ==  &Wx::WXK_UP and $event->ControlDown) {
 			if ($event->ShiftDown) {$self->CmdKeyExecute(&Wx::wxSTC_CMD_PARAUPEXTEND)} 
 			else                   {$self->CmdKeyExecute(&Wx::wxSTC_CMD_PARAUP)}
 		} elsif ($event->GetKeyCode ==  &Wx::WXK_DOWN and $event->ControlDown){
 			if ($event->ShiftDown) {$self->CmdKeyExecute(&Wx::wxSTC_CMD_PARADOWNEXTEND)} 
 			else                   {$self->CmdKeyExecute(&Wx::wxSTC_CMD_PARADOWN)}
-		} elsif ($event->GetKeyCode ==  &Wx::WXK_F12) {
-			Wx::Window::SetFocus(  );
+		} elsif ($event->GetKeyCode ==  &Wx::WXK_ESCAPE) {
+			Kephra::App::Panel::FileBrowser::focus();
 		} else {$event->Skip}
 
 		#print " $key- \n";
 	#Wx::Event::EVT_STC_AUTOCOMP_SELECTION(id, fn) 
 }
 
-sub set_focus {  Wx::Window::SetFocus( $_[0] ) }
+sub focus {  Wx::Window::SetFocus( $_[0] ) }
 
 sub set_margin {
 	my ($self, $style) = @_;

File lib/Kephra/App/Panel/Editor.pm

 	} elsif ($doc and $doc->editor->is_empty and $file_path) {
 		$doc->assign_file($file_path);
 		$main_doc_bar->SetPageText( $main_doc_bar->GetSelection , $doc->file_name );
-		$doc->editor->set_focus();
+		$doc->editor->focus();
 		Kephra::API::widget('win')->refresh_title();
 	# make new editor
 	} else {

File lib/Kephra/App/Panel/FileBrowser.pm

 use Kephra::File;
 
 sub new {
-    my( $class, $parent) = @_;
-    my $self = $panel = $class->SUPER::new(
-        $parent, -1, [-1,-1], [-1,-1], 
-        &Wx::wxTR_SINGLE | &Wx::wxTR_HIDE_ROOT,
-    );
+	my( $class, $parent) = @_;
+	my $self = $panel = $class->SUPER::new(
+		$parent, -1, [-1,-1], [-1,-1], 
+		&Wx::wxTR_SINGLE | &Wx::wxTR_HIDE_ROOT,
+	);
 
-    my @lib = @{ get_modules_and_paths('lib') };
-    my $root_ID = $self->AddRoot( 'Root', -1, -1, Wx::TreeItemData->new( ));
-    for (0 .. $#lib){
-        my $data = Wx::TreeItemData->new; 
-        $data->SetData( $lib[$_][1] );
-        my $ItemID = $self->AppendItem( $root_ID, $lib[$_][0] );
-        $self->SetItemData( $ItemID, $data );
-    }
+	my @lib = @{ get_modules_and_paths('lib') };
+	my $root_ID = $self->AddRoot( 'Root', -1, -1, Wx::TreeItemData->new( ));
+	for (0 .. $#lib){
+		my $data = Wx::TreeItemData->new; 
+		$data->SetData( $lib[$_][1] );
+		my $ItemID = $self->AppendItem( $root_ID, $lib[$_][0] );
+		$self->SetItemData( $ItemID, $data );
+	}
 
-    Wx::Event::EVT_TREE_ITEM_ACTIVATED( $self, -1, sub {
-        my ($fb, $event) = @_;
-        Kephra::File::open( $fb->GetItemData( $event->GetItem )->GetData );
-        Wx::Window::SetFocus( $fb );
-    } );
+	Wx::Event::EVT_TREE_ITEM_ACTIVATED( $self, -1, sub {
+		my ($fb, $event) = @_;
+		Kephra::File::open( $fb->GetItemData( $event->GetItem )->GetData );
+		Wx::Window::SetFocus( $fb );
+	} );
+	Wx::Event::EVT_KEY_DOWN ($self, sub {
+		my ($fb, $event) = @_;
+		my $key = $event->GetKeyCode + 1000 * 
+			( $event->ShiftDown
+			+ $event->ControlDown * 2 
+			+ $event->AltDown     * 4);
+		if ($event->GetKeyCode ==  &Wx::WXK_ESCAPE) {
+			Kephra::API::active_editor->focus();
+		} else { $event->Skip }
+	});
 
-    return $self;
+	return $self;
 }
 
 sub focus{ Wx::Window::SetFocus( $panel ) }
 
 sub get_modules_and_paths {
-    my $dir = shift;
-    return 0 unless -d $dir;
-    my @libs;
-    my $cwd = Cwd::cwd();
-    find( sub {
-        return if not -f $_ or $_ !~ /\.pm$/;
-        my $file = my $module = $File::Find::name;
-        $module =~ s|lib/||;
-        $module =~ s|\.pm||;
-        $module =~ s|/|::|g;
-        push @libs, [ $module, File::Spec->catfile( $cwd, $file ) ];
-    }, $dir);
-    @libs = sort {$a->[0] cmp $b->[0]} @libs;
-    return \@libs;
+	my $dir = shift;
+	return 0 unless -d $dir;
+	my @libs;
+	my $cwd = Cwd::cwd();
+	find( sub {
+		return if not -f $_ or $_ !~ /\.pm$/;
+		my $file = my $module = $File::Find::name;
+		$module =~ s|lib/||;
+		$module =~ s|\.pm||;
+		$module =~ s|/|::|g;
+		push @libs, [ $module, File::Spec->catfile( $cwd, $file ) ];
+	}, $dir);
+	@libs = sort {$a->[0] cmp $b->[0]} @libs;
+	return \@libs;
 }
 
 
-1;
+1;