Source

Kephra / lib / Kephra / App / Editor / TextDropTarget.pm

use v5.12;
use warnings;
use Wx::DND;
use Kephra::File;

package Kephra::App::Editor::TextDropTarget;
use base 'Wx::TextDropTarget';

sub new {
	my ($class, $ed) = @_;
	Kephra::Log::warning("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;
}

1;