Source

Kephra / lib / Kephra / Edit.pm

Full commit
use strict;
use warnings;

use Wx;
use Kephra::Config;
use Kephra::CommandList;

#package Kephra::Edit;

package Kephra::App::Editor;
Kephra::CommandList::register_cmd_namespace('edit');
Kephra::CommandList::register_cmd({
	'-undo'          =>{ sub => '$ed->Undo',             label=> 'Undo',        keys=> 'ctrl+z' },
	'-redo'          =>{ sub => '$ed->Redo',             label=> 'Redo',        keys=> 'ctrl+shift+z' },
	'-copy'          =>{ sub => '$ed->Copy',             label=> 'Copy',        keys=> 'ctrl+c' },
	'-copy-line'     =>{ sub => '$ed->LineCopy',         label=> 'Copy Line',   keys=> 'ctrl+shift+c'},
	'-cut'           =>{ sub => '$ed->Cut',              label=> 'Cut',         keys=> 'ctrl+x'},
	'-delete'        =>{ sub => '$ed->Clear',            label=> 'Delete',      keys=> 'delete'},
	'-delete-back'   =>{ sub => '$ed->DeleteBack',       label=> 'Del Back',    keys=> 'back'},
	'-delete-word-left'=>{sub=> '$ed->DelWordLeft',      label=> 'Del Word Left',keys=>'ctrl+back'},
	'-delete-word-right'=>{sub=>'$ed->DelWordRight',     label=> 'Del Word Right',keys=>'ctrl+delete'},
	'-delete-line'   =>{ sub => '$ed->LineDelete',       label=> 'Del Line',    keys=> 'ctrl+shift+delete'},
	'-insert'        =>{ sub => '$ed->Paste',            label=> 'Insert',      keys=> 'ctrl+v'},
	'-insert-newline'=>{ sub => '$ed->NewLine',          label=> 'Newline',     keys=> 'enter'},
	'-replace'       =>{ sub => '$ed->replace',          label=> 'Replace',     keys=> 'ctrl+shift+v'},
	'-double'        =>{ sub => '$ed->SelectionDuplicate',label=>'Double',      keys=> 'ctrl+d'},
	'-select-form'   =>{ sub => '$ed->select_form',      label=> 'Form',        keys=> 'ctrl+y'},
	'-select-content'=>{ sub => '$ed->select_content',   label=> 'Content',     keys=> 'ctrl+shift+y'},
});

sub get_clipboard_text {
	my $text;
	my $cboard = &Wx::wxTheClipboard;
	$cboard->Open;
	if ( $cboard->IsSupported( &Wx::wxDF_TEXT ) ) {
		my $data = Wx::TextDataObject->new;
		my $ok = $cboard->GetData( $data );
		if ( $ok ) { $text = $data->GetText; }
		else { # todo: error handling
		}
	}
	$cboard->Close;
	$text = '' unless defined $text and $text;
}

sub copy_line {
}

sub replace {
	my ($self) = @_;
	return unless $self->CanPaste;
	my ($begin, $end_a) = $self->GetSelection();
	$self->BeginUndoAction;
	$self->SetSelection($begin, $begin);
	$self->Paste();
	my $end_b = $self->GetCurrentPos();
	$self->SetSelection($end_b, $end_b + $end_a - $begin);
	$self->Cut();
	$self->SetSelection($begin, $begin + $end_b - $begin);
	$self->EndUndoAction;
}

sub select_form {
	my ($self) = @_;

}

sub select_content {
	my ($self) = @_;

}

1;