Commits

Herbert Breunung committed b82d572

set right tab size and make tabs and whitespace visible

Comments (0)

Files changed (1)

lib/Kephra/App/Editor.pm

 package Kephra::App::Editor;
 our @ISA = 'Wx::StyledTextCtrl';
 #our @ISA = 'Wx::ScintillaTextCtrl';
-    
+	
 my $mk_color = Kephra::App::Util::get('make_color');
 
 sub new {
-    my( $class, $parent, $style) = @_;
-    my $self = $class->SUPER::new($parent, -1);
-    $self->load_font();
-    $self->set_margin();
-    $self->set_colors();
-    $self->set_perlhighlight();
-    $self->mount_events();
+	my( $class, $parent, $style) = @_;
+	my $self = $class->SUPER::new($parent, -1);
+	$self->load_font();
+	$self->set_margin();
+	$self->set_colors();
+	$self->set_perlhighlight();
+	$self->mount_events();
+	$self->set_tab_size(4);
 
-    return $self;
+	return $self;
 }
 
 sub is_empty { not shift->GetTextLength }
 
 sub mount_events {
-    my ($self, @which) = @_;
-    #$self->DragAcceptFiles(1);
-    $self->SetAcceleratorTable(
-        Wx::AcceleratorTable->new(
-            #[&Wx::wxACCEL_CTRL, ord 'n', 1000],
-    ));
-    $self->SetDropTarget( TextDropTarget->new($self) );
-    #$self->SetAcceleratorTable( Wx::AcceleratorTable->new() );
-    #Wx::Event::EVT_MENU( $self, 1000, sub { $_[1]->Skip; } );
-    #Wx::Event::EVT_STC_SAVEPOINTREACHED($self, -1, \&Kephra::File::savepoint_reached);
-    #Wx::Event::EVT_STC_SAVEPOINTLEFT($self, -1, \&Kephra::File::savepoint_left);
-    #Wx::Event::EVT_STC_CHANGE       ($self, -1, sub {&$trigger('document.text.change')} );
-    Wx::Event::EVT_KEY_DOWN ($self, sub {
-        my ($ed, $event) = @_;
-        $event->Skip;
-        #print " --- \n";
-    });
-    #Wx::Event::EVT_STC_STYLENEEDED(id, fn) 
-    #Wx::Event::EVT_STC_CHARADDED($self, sub {});
-    #Wx::Event::EVT_STC_ROMODIFYATTEMPT(id, fn) 
-    #Wx::Event::EVT_STC_KEY(id, fn) 
-    #Wx::Event::EVT_STC_DOUBLECLICK(id, fn) 
-    #Wx::Event::EVT_STC_UPDATEUI(id, fn) 
-    #Wx::Event::EVT_STC_MODIFIED($self, sub {});
-    #Wx::Event::EVT_STC_MACRORECORD(id, fn) 
-    #Wx::Event::EVT_STC_MARGINCLICK(id, fn) 
-    #Wx::Event::EVT_STC_NEEDSHOWN($self, sub {});
-    #Wx::Event::EVT_STC_PAINTED(id, fn) 
-    #Wx::Event::EVT_STC_USERLISTSELECTION(id, fn) 
-    #Wx::Event::EVT_STC_URIDROPPED($self, sub {});
-    #Wx::Event::EVT_STC_DWELLSTART(id, fn) 
-    #Wx::Event::EVT_STC_DWELLEND(id, fn) 
-    #Wx::Event::EVT_STC_START_DRAG(id, fn) 
-    #Wx::Event::EVT_STC_DRAG_OVER(id, fn) 
-    #Wx::Event::EVT_STC_DO_DROP($self, sub {});
-    #Wx::Event::EVT_STC_ZOOM(id, fn) 
-    #Wx::Event::EVT_STC_HOTSPOT_CLICK(id, fn) 
-    #Wx::Event::EVT_STC_HOTSPOT_DCLICK(id, fn) 
-    #Wx::Event::EVT_STC_CALLTIP_CLICK(id, fn) 
-    #Wx::Event::EVT_STC_AUTOCOMP_SELECTION(id, fn) 
+	my ($self, @which) = @_;
+	#$self->DragAcceptFiles(1);
+	$self->SetAcceleratorTable(
+		Wx::AcceleratorTable->new(
+			#[&Wx::wxACCEL_CTRL, ord 'n', 1000],
+	));
+	$self->SetDropTarget( TextDropTarget->new($self) );
+	#$self->SetAcceleratorTable( Wx::AcceleratorTable->new() );
+	#Wx::Event::EVT_MENU( $self, 1000, sub { $_[1]->Skip; } );
+	#Wx::Event::EVT_STC_SAVEPOINTREACHED($self, -1, \&Kephra::File::savepoint_reached);
+	#Wx::Event::EVT_STC_SAVEPOINTLEFT($self, -1, \&Kephra::File::savepoint_left);
+	#Wx::Event::EVT_STC_CHANGE       ($self, -1, sub {&$trigger('document.text.change')} );
+	Wx::Event::EVT_KEY_DOWN ($self, sub {
+		my ($ed, $event) = @_;
+		$event->Skip;
+		#print " --- \n";
+	});
+	#Wx::Event::EVT_STC_STYLENEEDED(id, fn) 
+	#Wx::Event::EVT_STC_CHARADDED($self, sub {});
+	#Wx::Event::EVT_STC_ROMODIFYATTEMPT(id, fn) 
+	#Wx::Event::EVT_STC_KEY(id, fn) 
+	#Wx::Event::EVT_STC_DOUBLECLICK(id, fn) 
+	#Wx::Event::EVT_STC_UPDATEUI(id, fn) 
+	#Wx::Event::EVT_STC_MODIFIED($self, sub {});
+	#Wx::Event::EVT_STC_MACRORECORD(id, fn) 
+	#Wx::Event::EVT_STC_MARGINCLICK(id, fn) 
+	#Wx::Event::EVT_STC_NEEDSHOWN($self, sub {});
+	#Wx::Event::EVT_STC_PAINTED(id, fn) 
+	#Wx::Event::EVT_STC_USERLISTSELECTION(id, fn) 
+	#Wx::Event::EVT_STC_URIDROPPED($self, sub {});
+	#Wx::Event::EVT_STC_DWELLSTART(id, fn) 
+	#Wx::Event::EVT_STC_DWELLEND(id, fn) 
+	#Wx::Event::EVT_STC_START_DRAG(id, fn) 
+	#Wx::Event::EVT_STC_DRAG_OVER(id, fn) 
+	#Wx::Event::EVT_STC_DO_DROP($self, sub {});
+	#Wx::Event::EVT_STC_ZOOM(id, fn) 
+	#Wx::Event::EVT_STC_HOTSPOT_CLICK(id, fn) 
+	#Wx::Event::EVT_STC_HOTSPOT_DCLICK(id, fn) 
+	#Wx::Event::EVT_STC_CALLTIP_CLICK(id, fn) 
+	#Wx::Event::EVT_STC_AUTOCOMP_SELECTION(id, fn) 
 }
 
 sub set_focus {  Wx::Window::SetFocus( $_[0] ) }
 
 sub set_margin {
-    my ($self, $style) = @_;
-    $style = 'default' unless defined $style;
+	my ($self, $style) = @_;
+	$style = 'default' unless defined $style;
 
-    if ( $style eq 'default' ){
-        $self->SetMarginType( 0, &Wx::wxSTC_MARGIN_SYMBOL );
-        $self->SetMarginType( 1, &Wx::wxSTC_MARGIN_NUMBER );
-        $self->SetMarginType( 2, &Wx::wxSTC_MARGIN_SYMBOL );
-        $self->SetMarginMask( 0, 0x01FFFFFF );
-        $self->SetMarginMask( 1, 0 );
-        $self->SetMarginMask( 2, &Wx::wxSTC_MASK_FOLDERS );
-        $self->SetMarginSensitive( 0, 1 );
-        $self->SetMarginSensitive( 1, 1 );
-        $self->SetMarginSensitive( 2, 1 );
-        if ($style eq 'no') { $self->SetMarginWidth($_, 0) for 0..2 }
-        else {
-            $self->StyleSetForeground(&Wx::wxSTC_STYLE_LINENUMBER, $mk_color->(123,123,137));
-            $self->StyleSetBackground(&Wx::wxSTC_STYLE_LINENUMBER, $mk_color->(226,226,222));
-            $self->SetMarginWidth(0,  0);
-            $self->SetMarginWidth(1, 31);
-            $self->SetMarginWidth(2,  0);
-        }
-        $self->SetMargins(2, 2 );
-        $self->SetScrollWidth(200);
-    }
-    elsif ( $style eq 'no' ) {
-    }
-    
+	if ( $style eq 'default' ){
+		$self->SetMarginType( 0, &Wx::wxSTC_MARGIN_SYMBOL );
+		$self->SetMarginType( 1, &Wx::wxSTC_MARGIN_NUMBER );
+		$self->SetMarginType( 2, &Wx::wxSTC_MARGIN_SYMBOL );
+		$self->SetMarginMask( 0, 0x01FFFFFF );
+		$self->SetMarginMask( 1, 0 );
+		$self->SetMarginMask( 2, &Wx::wxSTC_MASK_FOLDERS );
+		$self->SetMarginSensitive( 0, 1 );
+		$self->SetMarginSensitive( 1, 1 );
+		$self->SetMarginSensitive( 2, 1 );
+		if ($style eq 'no') { $self->SetMarginWidth($_, 0) for 0..2 }
+		else {
+			$self->StyleSetForeground(&Wx::wxSTC_STYLE_LINENUMBER, $mk_color->(123,123,137));
+			$self->StyleSetBackground(&Wx::wxSTC_STYLE_LINENUMBER, $mk_color->(226,226,222));
+			$self->SetMarginWidth(0,  0);
+			$self->SetMarginWidth(1, 31);
+			$self->SetMarginWidth(2,  0);
+		}
+		$self->SetMargins(2, 2 );
+		$self->SetScrollWidth(200);
+	}
+	elsif ( $style eq 'no' ) {
+	}
+	
 }
 
 sub insert_text {
-    my ($self, $text, $pos) = @_;
-    $pos = $self->GetCurrentPos unless defined $pos;
-    $self->InsertText($pos, $text);
+	my ($self, $text, $pos) = @_;
+	$pos = $self->GetCurrentPos unless defined $pos;
+	$self->InsertText($pos, $text);
+}
+
+sub set_tab_size {
+	my ($self, $size) = @_;
+	$self->SetTabWidth($size);
+	$self->SetIndent($size);
+	$self->SetHighlightGuide($size);
 }
 
 sub set_colors {
-    my $self = shift;
-    my $color = Kephra::App::Util::get('make_color');
-    $self->SetCaretLineBack( $mk_color->(245,245,161) );
-    $self->SetCaretPeriod( 500 );
-    $self->SetCaretWidth( 2 );
-    $self->SetCaretForeground( $mk_color->(0,0,255) );
-    $self->SetCaretLineVisible(1);
-    $self->SetSelForeground( 1, $mk_color->(255,246,194) );
-    $self->SetSelBackground( 1, $mk_color->(0, 17, 119) );
-    $self->SetWhitespaceForeground( 1, $mk_color->(204, 204, 153) );
+	my $self = shift;
+	my $color = Kephra::App::Util::get('make_color');
+	$self->SetCaretLineBack( $mk_color->(245,245,161) );
+	$self->SetCaretPeriod( 500 );
+	$self->SetCaretWidth( 2 );
+	$self->SetCaretForeground( $mk_color->(0,0,255) );
+	$self->SetCaretLineVisible(1);
+	$self->SetSelForeground( 1, $mk_color->(255,246,194) );
+	$self->SetSelBackground( 1, $mk_color->(0, 17, 119) );
+	$self->SetWhitespaceForeground( 1, $mk_color->(204, 204, 153) );
+	$self->SetViewWhiteSpace(1);
 }
 
 sub load_font {
-    my ($self, $font) = @_;
-    my ( $fontweight, $fontstyle ) = ( &Wx::wxNORMAL, &Wx::wxNORMAL );
-    $font = {
-        #family => 'Courier New', # old default
-        family => 'DejaVu Sans Mono',
-        size => 11,
-        style => 'normal',
-        weight => 'normal',    
-    } unless defined $font;
-    #my $font = _config()->{font};
-    $fontweight = &Wx::wxLIGHT  if $font->{weight} eq 'light';
-    $fontweight = &Wx::wxBOLD   if $font->{weight} eq 'bold';
-    $fontstyle  = &Wx::wxSLANT  if $font->{style}  eq 'slant';
-    $fontstyle  = &Wx::wxITALIC if $font->{style}  eq 'italic';
-    my $wx_font = Wx::Font->new( 
-        $font->{size}, &Wx::wxDEFAULT, $fontstyle, $fontweight, 0, $font->{family}
-    );
-    $self->StyleSetFont( &Wx::wxSTC_STYLE_DEFAULT, $wx_font ) if $wx_font->Ok > 0;
+	my ($self, $font) = @_;
+	my ( $fontweight, $fontstyle ) = ( &Wx::wxNORMAL, &Wx::wxNORMAL );
+	$font = {
+		#family => 'Courier New', # old default
+		family => 'DejaVu Sans Mono',
+		size => 10,
+		style => 'normal',
+		weight => 'normal',    
+	} unless defined $font;
+	#my $font = _config()->{font};
+	$fontweight = &Wx::wxLIGHT  if $font->{weight} eq 'light';
+	$fontweight = &Wx::wxBOLD   if $font->{weight} eq 'bold';
+	$fontstyle  = &Wx::wxSLANT  if $font->{style}  eq 'slant';
+	$fontstyle  = &Wx::wxITALIC if $font->{style}  eq 'italic';
+	my $wx_font = Wx::Font->new( 
+		$font->{size}, &Wx::wxDEFAULT, $fontstyle, $fontweight, 0, $font->{family}
+	);
+	$self->StyleSetFont( &Wx::wxSTC_STYLE_DEFAULT, $wx_font ) if $wx_font->Ok > 0;
 }
 
 sub set_perlhighlight {
-    my ($self) = @_;
-    $self->StyleClearAll;
-    $self->SetLexer( &Wx::wxSTC_LEX_PERL );         # Set Lexers to use
-    $self->SetKeyWords(0, 'NULL 
+	my ($self) = @_;
+	$self->StyleClearAll;
+	$self->SetLexer( &Wx::wxSTC_LEX_PERL );         # Set Lexers to use
+	$self->SetKeyWords(0, 'NULL 
 __FILE__ __LINE__ __PACKAGE__ __DATA__ __END__ __WARN__ __DIE__
 AUTOLOAD BEGIN CHECK CORE DESTROY END EQ GE GT INIT LE LT NE UNITCHECK 
 abs accept alarm and atan2 bind binmode bless break
 # Add new keyword.
 # $_[0]->StyleSetSpec( &Wx::wxSTC_H_TAG, "fore:#000055" ); # Apply tag style for selected lexer (blue)
 
-     $self->StyleSetSpec(1,"fore:#ff0000");                                     # Error
-     $self->StyleSetSpec(2,"fore:#aaaaaa");                                     # Comment
-     $self->StyleSetSpec(3,"fore:#004000,back:#E0FFE0,$(font.text),eolfilled"); # POD: = at beginning of line
-     $self->StyleSetSpec(&Wx::wxSTC_PL_NUMBER,"fore:#007f7f");                                     # Number
-     $self->StyleSetSpec(5,"fore:#000077,bold");                                # Keywords
-     $self->StyleSetSpec(6,"fore:#ee7b00,back:#fff8f8");                        # Doublequoted string
-     $self->StyleSetSpec(7,"fore:#f36600,back:#fffcff");                        # Single quoted string
-     $self->StyleSetSpec(8,"fore:#555555");                                     # Symbols / Punctuation. Currently not used by LexPerl.
-     $self->StyleSetSpec(9,"");                                                 # Preprocessor. Currently not used by LexPerl.
-     $self->StyleSetSpec(10,"fore:#002200");                                    # Operators
-     $self->StyleSetSpec(11,"fore:#3355bb");                                    # Identifiers (functions, etc.)
-     $self->StyleSetSpec(12,"fore:#228822");                                    # Scalars: $var
-     $self->StyleSetSpec(13,"fore:#339933");                                    # Array: @var
-     $self->StyleSetSpec(14,"fore:#44aa44");                                    # Hash: %var
-     $self->StyleSetSpec(15,"fore:#55bb55");                                    # Symbol table: *var
-     $self->StyleSetSpec(17,"fore:#000000,back:#A0FFA0");                       # Regex: /re/ or m{re}
-     $self->StyleSetSpec(18,"fore:#000000,back:#F0E080");                       # Substitution: s/re/ore/
-     $self->StyleSetSpec(19,"fore:#000000,back:#8080A0");                       # Long Quote (qq, qr, qw, qx) -- obsolete: replaced by qq, qx, qr, qw
-     $self->StyleSetSpec(20,"fore:#ff7700,back:#f9f9d7");                       # Back Ticks
-     $self->StyleSetSpec(21,"fore:#600000,back:#FFF0D8,eolfilled");             # Data Section: __DATA__ or __END__ at beginning of line
-     $self->StyleSetSpec(22,"fore:#000000,back:#DDD0DD");                       # Here-doc (delimiter)
-     $self->StyleSetSpec(23,"fore:#7F007F,back:#DDD0DD,eolfilled,notbold");     # Here-doc (single quoted, q)
-     $self->StyleSetSpec(24,"fore:#7F007F,back:#DDD0DD,eolfilled,bold");        # Here-doc (double quoted, qq)
-     $self->StyleSetSpec(25,"fore:#7F007F,back:#DDD0DD,eolfilled,italics");     # Here-doc (back ticks, qx)
-     $self->StyleSetSpec(26,"fore:#7F007F,$(font.monospace),notbold");          # Single quoted string, generic 
-     $self->StyleSetSpec(27,"fore:#ee7b00,back:#fff8f8");                       # qq = Double quoted string
-     $self->StyleSetSpec(28,"fore:#ff7700,back:#f9f9d7");                       # qx = Back ticks
-     $self->StyleSetSpec(29,"fore:#000000,back:#A0FFA0");                       # qr = Regex
-     $self->StyleSetSpec(30,"fore:#f36600,back:#fff8f8");                       # qw = Array
+	 $self->StyleSetSpec(1,"fore:#ff0000");                                     # Error
+	 $self->StyleSetSpec(2,"fore:#aaaaaa");                                     # Comment
+	 $self->StyleSetSpec(3,"fore:#004000,back:#E0FFE0,$(font.text),eolfilled"); # POD: = at beginning of line
+	 $self->StyleSetSpec(&Wx::wxSTC_PL_NUMBER,"fore:#007f7f");                                     # Number
+	 $self->StyleSetSpec(5,"fore:#000077,bold");                                # Keywords
+	 $self->StyleSetSpec(6,"fore:#ee7b00,back:#fff8f8");                        # Doublequoted string
+	 $self->StyleSetSpec(7,"fore:#f36600,back:#fffcff");                        # Single quoted string
+	 $self->StyleSetSpec(8,"fore:#555555");                                     # Symbols / Punctuation. Currently not used by LexPerl.
+	 $self->StyleSetSpec(9,"");                                                 # Preprocessor. Currently not used by LexPerl.
+	 $self->StyleSetSpec(10,"fore:#002200");                                    # Operators
+	 $self->StyleSetSpec(11,"fore:#3355bb");                                    # Identifiers (functions, etc.)
+	 $self->StyleSetSpec(12,"fore:#228822");                                    # Scalars: $var
+	 $self->StyleSetSpec(13,"fore:#339933");                                    # Array: @var
+	 $self->StyleSetSpec(14,"fore:#44aa44");                                    # Hash: %var
+	 $self->StyleSetSpec(15,"fore:#55bb55");                                    # Symbol table: *var
+	 $self->StyleSetSpec(17,"fore:#000000,back:#A0FFA0");                       # Regex: /re/ or m{re}
+	 $self->StyleSetSpec(18,"fore:#000000,back:#F0E080");                       # Substitution: s/re/ore/
+	 $self->StyleSetSpec(19,"fore:#000000,back:#8080A0");                       # Long Quote (qq, qr, qw, qx) -- obsolete: replaced by qq, qx, qr, qw
+	 $self->StyleSetSpec(20,"fore:#ff7700,back:#f9f9d7");                       # Back Ticks
+	 $self->StyleSetSpec(21,"fore:#600000,back:#FFF0D8,eolfilled");             # Data Section: __DATA__ or __END__ at beginning of line
+	 $self->StyleSetSpec(22,"fore:#000000,back:#DDD0DD");                       # Here-doc (delimiter)
+	 $self->StyleSetSpec(23,"fore:#7F007F,back:#DDD0DD,eolfilled,notbold");     # Here-doc (single quoted, q)
+	 $self->StyleSetSpec(24,"fore:#7F007F,back:#DDD0DD,eolfilled,bold");        # Here-doc (double quoted, qq)
+	 $self->StyleSetSpec(25,"fore:#7F007F,back:#DDD0DD,eolfilled,italics");     # Here-doc (back ticks, qx)
+	 $self->StyleSetSpec(26,"fore:#7F007F,$(font.monospace),notbold");          # Single quoted string, generic 
+	 $self->StyleSetSpec(27,"fore:#ee7b00,back:#fff8f8");                       # qq = Double quoted string
+	 $self->StyleSetSpec(28,"fore:#ff7700,back:#f9f9d7");                       # qx = Back ticks
+	 $self->StyleSetSpec(29,"fore:#000000,back:#A0FFA0");                       # qr = Regex
+	 $self->StyleSetSpec(30,"fore:#f36600,back:#fff8f8");                       # qw = Array
 }
 
 package TextDropTarget;
 use Kephra::File;
 
 sub new {
-    my ($class, $ed) = @_;
-    warn __PACKAGE__ ."needs a Kephra::App::Editor, not $ed!" unless $ed->isa('Kephra::App::Editor');
-    my $self = $class->SUPER::new();
-    $self->{'ed'} = $ed;
-    return $self;
+	my ($class, $ed) = @_;
+	warn __PACKAGE__ ."needs a Kephra::App::Editor, not $ed!" unless $ed->isa('Kephra::App::Editor');
+	my $self = $class->SUPER::new();
+	$self->{'ed'} = $ed;
+	return $self;
 }
 
 sub OnDropText {
-    my( $self, $x, $y, $text ) = @_;
-    $text =~ m|^(file:)?(.*)|s;
-    if ($1)  { Kephra::File::open($2) }
-    else     {
-        my $pos = $self->{'ed'}->PositionFromPoint( [$x, $y] );
-        $self->{'ed'}->insert_text($2, $pos);
-    }
-    return 1;
+	my( $self, $x, $y, $text ) = @_;
+	$text =~ m|^(file:)?(.*)|s;
+	if ($1)  { Kephra::File::open($2) }
+	else     {
+		my $pos = $self->{'ed'}->PositionFromPoint( [$x, $y] );
+		$self->{'ed'}->insert_text($2, $pos);
+	}
+	return 1;
 }
 
 1;