Commits

Herbert Breunung  committed 340531b

dnd of text and files works now under linux

  • Participants
  • Parent commits ba6f208

Comments (0)

Files changed (7)

File lib/Kephra/API.pm

 my %widget_caller = (
 	main_win     => sub { $Kephra::App::Window::_ref },
 	main_window  => sub { $Kephra::App::Window::_ref },
-	#doc_bar      => \&Kephra::App::Panel::Editor::_active_docbar,
-	#document_bar => \&Kephra::App::Panel::Editor::_active_docbar },
+	doc_bar      => sub { Kephra::App::Panel::Editor::_active_docbar() },
+	document_bar => sub { Kephra::App::Panel::Editor::_active_docbar() },
 );
 
 # gui parts of main window
 
 sub configs  { }
 
-sub active_document { Kephra::DocumentStash::active()}
+sub active_doc      { Kephra::DocumentStash::active_doc() }
 sub active_editor   { Kephra::DocumentStash::active_editor() }
 sub all_documents   { }
 sub do_with_all_documents { }

File lib/Kephra/App/Editor.pm

     $self->SetScrollWidth(200);
 }
 
+sub insert_text {
+    my ($self, $text, $pos) = @_;
+    $pos = $self->GetCurrentPos unless defined $pos;
+    $self->InsertText($pos, $text);
+}
+
 sub set_colors {
     my $self = shift;
     my $color = Kephra::App::Helper::get('make_color');
      $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(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';
+use Kephra::File;
 
 sub new {
-    my ($class, $widget) = @_;
+    my ($class, $ed) = @_;
+    warn __PACKAGE__ ."needs a Kephra::App::Editor, not $ed!" unless $ed->isa('Kephra::App::Editor');
     my $self = $class->SUPER::new();
-    $self->{'WIDGET'} = $widget;
+    $self->{'ed'} = $ed;
     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;
+    $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;

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

 use warnings;
 
 package Kephra::App::Panel::Editor;
+use Kephra::API;
+use Kephra::App::Bar::Document;
 use Kephra::Document;
 use Kephra::DocumentStash;
-use Kephra::App::Bar::Document;
 #my $_ref; # whole panel widget, parent of all this
 my %doc_bar;
 my $active;
 
 sub create_document {
     my $file_path = shift;
-    my $doc = Kephra::DocumentStash::active_doc();
+    my $doc = Kephra::API::active_doc();
     my $main_doc_bar = _active_docbar();
 
     if ( $file_path and Kephra::DocumentStash::file_loaded($file_path) ){

File lib/Kephra/Document.pm

 package Kephra::Document;
 use Moo;
+use Kephra::File;
 use File::Spec;
 
 has editor => (
 has marked_lines => ( is  => 'rw', );
 
 sub load {
-    my ($self, $fiel_path) = @_;
-    return unless $fiel_path;
-    $self->file_path($fiel_path);
+    my ($self, $file_path) = @_;
+    return unless $file_path;
+    $file_path = Kephra::File::_normalize_name($file_path);
+    $self->file_path($file_path);
     my @path_parts = File::Spec->splitpath( $_[0]->file_path );
     $self->file_dir( $path_parts[1] );
     $self->file_name( $path_parts[2] );

File lib/Kephra/DocumentStash.pm

     warn "Kephra::DocumentStash::file_loaded needs a file path as input!"
         unless $file_path and -e $file_path;
     for my $ed (keys %document) {
-        return 1 if $document{$ed}->file_path eq $file_path;
+        return 1 if $document{$ed}->file_path and $document{$ed}->file_path eq $file_path;
     }
 }
 1;

File lib/Kephra/Edit.pm

+use strict;
+use warnings;
+
+package Kephra::Edit;
+
+
+1;

File lib/Kephra/File.pm

 use strict;
 use warnings;
+use File::Spec;
 use Kephra::App::Panel::Editor;
 
 package Kephra::File;
 
+sub _normalize_name {
+	my $file = shift;
+	return unless $file;
+
+	# normalize filename
+	$file = File::Spec->canonpath($file);
+	local $/ = "\r\n";
+	chomp($file);
+	return $file;
+}
+
 sub new  { Kephra::App::Panel::Editor::create_document() }
 sub open {
-	my $file = shift;
-	return unless -e $file;
+	my $file = _normalize_name( shift );
+	return unless $file and -e $file;
+
 	my $doc = Kephra::App::Panel::Editor::create_document($file);
 	return unless ref $doc eq 'Kephra::Document';
 	open my $FH, '<', $file;
 }
 sub save {}
 
-sub close_active {
-}
+sub close_active {}
 sub close_other  {}
 sub close_all    {}