Commits

Herbert Breunung committed ba6f208

preparing dnd file open per dnd

  • Participants
  • Parent commits df77580

Comments (0)

Files changed (2)

lib/Kephra/App/Bar/Document.pm

 use strict;
 use warnings;
 use Wx;
+use Wx::DND;
 use Kephra::App::Editor;
 use Kephra::App::Helper;
 
 }
 
 1;
-
-__END__
-    $widget->SetDropTarget
-        ( DateiZiel->new($widget) );
-
-Es klingt umständlich C<DateiZiel>, nochmal das Widget zu übergeben, aber
-die Klasse braucht eine Referenz des Widgets, das später reagieren soll, was
-nicht immer das Widget sein muss, über dem die Datei losgelassen wird.
-
-    package DateiZiel;
-    use base 'Wx::FileDropTarget';
-
-    sub new {
-        my $class = shift;
-        my $self = $class->SUPER::new();
-        $self->{WIDGET} = shift;
-        return $self;
-    }
-
-    sub OnDropFiles {
-        my( $self, $x, $y, $files ) = @_;
-        for my $file ( @$files ) {
-            $self->{WIDGET}->Append(
-                read_file( $file );
-            );
-        }
-        return 1;
-    }

lib/Kephra/App/Editor.pm

 use strict;
 use warnings;
 use Wx;
-use Wx::DND;
-use Wx::STC;
+#use Wx::DND;
+#use Wx::STC;
 use Wx::Scintilla;
 use Kephra::App::Helper;
 
 my $mk_color = Kephra::App::Helper::get('make_color');
 
 sub new {
-    my( $self, $parent, $style) = @_;
-    my $ed = $self->SUPER::new($parent, -1);
-    $ed->load_font();
-    $ed->set_margin();
-    $ed->set_colors();
-    $ed->set_perlhighlight();
-    $ed->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();
 
-    return $ed;
+    return $self;
 }
 
 sub is_empty { not shift->GetTextLength }
 
 sub mount_events {
-    my ($ed, @which) = @_;
-    #$ed->DragAcceptFiles(1);
-    $ed->SetAcceleratorTable(
+    my ($self, @which) = @_;
+    #$self->DragAcceptFiles(1);
+    $self->SetAcceleratorTable(
         Wx::AcceleratorTable->new(
             #[&Wx::wxACCEL_CTRL, ord 'n', 1000],
     ));
-    #$ed->SetAcceleratorTable( Wx::AcceleratorTable->new() );
-    #Wx::Event::EVT_MENU( $ed, 1000, sub { $_[1]->Skip; } );
-    #Wx::Event::EVT_STC_SAVEPOINTREACHED($ed, -1, \&Kephra::File::savepoint_reached);
-    #Wx::Event::EVT_STC_SAVEPOINTLEFT($ed, -1, \&Kephra::File::savepoint_left);
-    #Wx::Event::EVT_STC_CHANGE       ($ed, -1, sub {&$trigger('document.text.change')} );
+    $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 ($win, sub {
     #Wx::Event::EVT_STC_STYLENEEDED(id, fn) 
     #Wx::Event::EVT_STC_CHARADDED(id, fn) 
 sub set_focus {  Wx::Window::SetFocus( $_[0] ) }
 
 sub set_margin {
-    my ($ed, $style) = @_;
+    my ($self, $style) = @_;
     $style = '' unless defined $style;
 
-    $ed->SetMarginType( 0, &Wx::wxSTC_MARGIN_SYMBOL );
-    $ed->SetMarginType( 1, &Wx::wxSTC_MARGIN_NUMBER );
-    $ed->SetMarginType( 2, &Wx::wxSTC_MARGIN_SYMBOL );
-    $ed->SetMarginMask( 0, 0x01FFFFFF );
-    $ed->SetMarginMask( 1, 0 );
-    $ed->SetMarginMask( 2, &Wx::wxSTC_MASK_FOLDERS );
-    $ed->SetMarginSensitive( 0, 1 );
-    $ed->SetMarginSensitive( 1, 1 );
-    $ed->SetMarginSensitive( 2, 1 );
-    if ($style eq 'no') { $ed->SetMarginWidth($_, 0) for 0..2 }
+    $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 {
-        $ed->StyleSetForeground(&Wx::wxSTC_STYLE_LINENUMBER, $mk_color->(123,123,137));
-        $ed->StyleSetBackground(&Wx::wxSTC_STYLE_LINENUMBER, $mk_color->(226,226,222));
-        $ed->SetMarginWidth(0,  0);
-        $ed->SetMarginWidth(1, 31);
-        $ed->SetMarginWidth(2,  0);
+        $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);
     }
-    $ed->SetMargins(2, 2 );
-    $ed->SetScrollWidth(200);
+    $self->SetMargins(2, 2 );
+    $self->SetScrollWidth(200);
 }
 
 sub set_colors {
-    my $ed = shift;
+    my $self = shift;
     my $color = Kephra::App::Helper::get('make_color');
-    $ed->SetCaretLineBack( $mk_color->(245,245,161) );
-    $ed->SetCaretPeriod( 500 );
-    $ed->SetCaretWidth( 2 );
-    $ed->SetCaretForeground( $mk_color->(0,0,255) );
-    $ed->SetCaretLineVisible(1);
-    $ed->SetSelForeground( 1, $mk_color->(255,246,194) );
-    $ed->SetSelBackground( 1, $mk_color->(0, 17, 119) );
-    $ed->SetWhitespaceForeground( 1, $mk_color->(204, 204, 153) );
+    $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) );
 }
 
 sub load_font {
-    my ($ed, $font) = @_;
+    my ($self, $font) = @_;
     my ( $fontweight, $fontstyle ) = ( &Wx::wxNORMAL, &Wx::wxNORMAL );
     $font = {
         #family => 'Courier New', # old default
     my $wx_font = Wx::Font->new( 
         $font->{size}, &Wx::wxDEFAULT, $fontstyle, $fontweight, 0, $font->{family}
     );
-    $ed->StyleSetFont( &Wx::wxSTC_STYLE_DEFAULT, $wx_font ) if $wx_font->Ok > 0;
+    $self->StyleSetFont( &Wx::wxSTC_STYLE_DEFAULT, $wx_font ) if $wx_font->Ok > 0;
 }
 
 sub set_perlhighlight {
-    my ($ed) = @_;
-    $ed->StyleClearAll;
-    $ed->SetLexer( &Wx::wxSTC_LEX_PERL );         # Set Lexers to use
-    $ed->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)
 
-     $ed->StyleSetSpec(1,"fore:#ff0000");                                     # Error
-     $ed->StyleSetSpec(2,"fore:#aaaaaa");                                     # Comment
-     $ed->StyleSetSpec(3,"fore:#004000,back:#E0FFE0,$(font.text),eolfilled"); # POD: = at beginning of line
-     $ed->StyleSetSpec(4,"fore:#007f7f");                                     # Number
-     $ed->StyleSetSpec(5,"fore:#000077,bold");                                # Keywords
-     $ed->StyleSetSpec(6,"fore:#ee7b00,back:#fff8f8");                        # Doublequoted string
-     $ed->StyleSetSpec(7,"fore:#f36600,back:#fffcff");                        # Single quoted string
-     $ed->StyleSetSpec(8,"fore:#555555");                                     # Symbols / Punctuation. Currently not used by LexPerl.
-     $ed->StyleSetSpec(9,"");                                                 # Preprocessor. Currently not used by LexPerl.
-     $ed->StyleSetSpec(10,"fore:#002200");                                    # Operators
-     $ed->StyleSetSpec(11,"fore:#3355bb");                                    # Identifiers (functions, etc.)
-     $ed->StyleSetSpec(12,"fore:#228822");                                    # Scalars: $var
-     $ed->StyleSetSpec(13,"fore:#339933");                                    # Array: @var
-     $ed->StyleSetSpec(14,"fore:#44aa44");                                    # Hash: %var
-     $ed->StyleSetSpec(15,"fore:#55bb55");                                    # Symbol table: *var
-     $ed->StyleSetSpec(17,"fore:#000000,back:#A0FFA0");                       # Regex: /re/ or m{re}
-     $ed->StyleSetSpec(18,"fore:#000000,back:#F0E080");                       # Substitution: s/re/ore/
-     $ed->StyleSetSpec(19,"fore:#000000,back:#8080A0");                       # Long Quote (qq, qr, qw, qx) -- obsolete: replaced by qq, qx, qr, qw
-     $ed->StyleSetSpec(20,"fore:#ff7700,back:#f9f9d7");                       # Back Ticks
-     $ed->StyleSetSpec(21,"fore:#600000,back:#FFF0D8,eolfilled");             # Data Section: __DATA__ or __END__ at beginning of line
-     $ed->StyleSetSpec(22,"fore:#000000,back:#DDD0DD");                       # Here-doc (delimiter)
-     $ed->StyleSetSpec(23,"fore:#7F007F,back:#DDD0DD,eolfilled,notbold");     # Here-doc (single quoted, q)
-     $ed->StyleSetSpec(24,"fore:#7F007F,back:#DDD0DD,eolfilled,bold");        # Here-doc (double quoted, qq)
-     $ed->StyleSetSpec(25,"fore:#7F007F,back:#DDD0DD,eolfilled,italics");     # Here-doc (back ticks, qx)
-     $ed->StyleSetSpec(26,"fore:#7F007F,$(font.monospace),notbold");          # Single quoted string, generic 
-     $ed->StyleSetSpec(27,"fore:#ee7b00,back:#fff8f8");                       # qq = Double quoted string
-     $ed->StyleSetSpec(28,"fore:#ff7700,back:#f9f9d7");                                # qx = Back ticks
-     $ed->StyleSetSpec(29,"fore:#000000,back:#A0FFA0");                                # qr = Regex
-     $ed->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(4,"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 base 'Wx::TextDropTarget';
+
+sub new {
+    my ($class, $widget) = @_;
+    my $self = $class->SUPER::new();
+    $self->{'WIDGET'} = $widget;
+    return $self;
+}
+
+sub OnDropText {
+    my( $self, $x, $y, $text ) = @_;
+        print  "$x, $y $files DND";
+    for my $file ( @$files ) {
+        #$self->{WIDGET}->Append ();
+        print  "$x, $y $file DND";
+            
+     }
+     return 1;
 }
 
 1;