Source

Kephra / lib / Kephra / Edit.pm

use strict;
use warnings;

use Wx;
use Kephra::API;
use Kephra::Config;

#package Kephra::Edit;

package Kephra::App::Editor;

Kephra::API::Command::register({
 'edit-undo'             =>{sub=>'$ed->Undo',             label=>'Undo',          keys=> 'ctrl+z'},
 'edit-redo'             =>{sub=>'$ed->Redo',             label=>'Redo',          keys=> 'ctrl+shift+z'},
 'edit-copy'             =>{sub=>'$ed->Copy',             label=>'Copy',          keys=> 'ctrl+c' },
 'edit-copy-line'        =>{sub=>'$ed->LineCopy',         label=>'Copy Line',     keys=> 'ctrl+shift+c'},
 'edit-cut'              =>{sub=>'$ed->Cut',              label=>'Cut',           keys=> 'ctrl+x'},
 'edit-delete'           =>{sub=>'$ed->Clear',            label=>'Delete',        keys=> 'delete'},
 'edit-delete-back'      =>{sub=>'$ed->DeleteBack',       label=>'Del Back',      keys=> 'back'},
 'edit-delete-word-left' =>{sub=>'$ed->DelWordLeft',      label=>'Del Word Left', keys=> 'ctrl+back'},
 'edit-delete-word-right'=>{sub=>'$ed->DelWordRight',     label=>'Del Word Right',keys=> 'ctrl+delete'},
 'edit-delete-line'      =>{sub=>'$ed->LineDelete',       label=>'Del Line',      keys=> 'ctrl+shift+delete'},
 'edit-insert'           =>{sub=>'$ed->Paste',            label=>'Insert',        keys=> 'ctrl+v'}, # thats what sometimes called paste
 'edit-insert-newline'   =>{sub=>'$ed->NewLine',          label=>'Newline',       keys=> 'enter'},
 'edit-replace'          =>{sub=>'$ed->replace',          label=>'Replace',       keys=> 'ctrl+shift+v'},
 'edit-double'           =>{sub=>'$ed->SelectionDuplicate',label=>'Double',       keys=> 'ctrl+d'},
 'edit-select-form'      =>{sub=>'$ed->select_form',      label=>'Form',          keys=> 'ctrl+y'},
 'edit-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 visual_height {	my ($self) = @_; 	$self->GetFirstVisibleLine; $self->}

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;