Prima
view release on metacpan or search on metacpan
Prima/Edit.pm view on Meta::CPAN
my $font = $_[ 0]-> get_default_font;
my $rtl = $::application-> textDirection;
return {
%def,
accelItems => [
# navigation
[ CursorDown => 0, 0, kb::Down , sub{$_[0]-> cursor_down}],
[ CursorUp => 0, 0, kb::Up , sub{$_[0]-> cursor_up}],
[ CursorLeft => 0, 0, kb::Left , sub{$_[0]-> cursor_left}],
[ CursorRight => 0, 0, kb::Right , sub{$_[0]-> cursor_right}],
[ PageUp => 0, 0, kb::PgUp , sub{$_[0]-> cursor_pgup}],
[ PageDown => 0, 0, kb::PgDn , sub{$_[0]-> cursor_pgdn}],
[ Home => 0, 0, kb::Home , sub{$_[0]-> cursor_home}],
[ End => 0, 0, kb::End , sub{$_[0]-> cursor_end}],
[ CtrlPageUp => 0, 0, kb::PgUp|km::Ctrl , sub{$_[0]-> cursor_cpgup}],
[ CtrlPageDown => 0, 0, kb::PgDn|km::Ctrl , sub{$_[0]-> cursor_cpgdn}],
[ CtrlHome => 0, 0, kb::Home|km::Ctrl , sub{$_[0]-> cursor_chome}],
[ CtrlEnd => 0, 0, kb::End |km::Ctrl , sub{$_[0]-> cursor_cend}],
[ WordLeft => 0, 0, kb::Left |km::Ctrl , sub{$_[0]-> word_left}],
[ WordRight => 0, 0, kb::Right|km::Ctrl , sub{$_[0]-> word_right}],
[ ShiftCursorDown => 0, 0, km::Shift|kb::Down , q(cursor_shift_key)],
[ ShiftCursorUp => 0, 0, km::Shift|kb::Up , q(cursor_shift_key)],
[ ShiftCursorLeft => 0, 0, km::Shift|kb::Left , q(cursor_shift_key)],
[ ShiftCursorRight => 0, 0, km::Shift|kb::Right , q(cursor_shift_key)],
[ ShiftPageUp => 0, 0, km::Shift|kb::PgUp , q(cursor_shift_key)],
[ ShiftPageDown => 0, 0, km::Shift|kb::PgDn , q(cursor_shift_key)],
[ ShiftHome => 0, 0, km::Shift|kb::Home , q(cursor_shift_key)],
[ ShiftEnd => 0, 0, km::Shift|kb::End , q(cursor_shift_key)],
[ ShiftCtrlPageUp => 0, 0, km::Shift|kb::PgUp|km::Ctrl , q(cursor_shift_key)],
[ ShiftCtrlPageDown => 0, 0, km::Shift|kb::PgDn|km::Ctrl , q(cursor_shift_key)],
[ ShiftCtrlHome => 0, 0, km::Shift|kb::Home|km::Ctrl , q(cursor_shift_key)],
[ ShiftCtrlEnd => 0, 0, km::Shift|kb::End |km::Ctrl , q(cursor_shift_key)],
[ ShiftWordLeft => 0, 0, km::Shift|kb::Left |km::Ctrl , q(cursor_shift_key)],
[ ShiftWordRight => 0, 0, km::Shift|kb::Right|km::Ctrl , q(cursor_shift_key)],
[ Insert => 0, 0, kb::Insert , sub {$_[0]-> insertMode(!$_[0]-> insertMode)}],
# edit keys
[ Delete => 0, 0, kb::Delete, sub {
$_[0]-> has_selection ? $_[0]-> delete_block : $_[0]-> delete_char;
}],
[ Backspace => 0, 0, kb::Backspace, sub {
$_[0]-> has_selection ? $_[0]-> delete_block : $_[0]-> back_char;
}],
[ CtrlBackspace => 0, 0, kb::Backspace|km::Ctrl, sub {
$_[0]-> has_selection ? $_[0]-> delete_block : $_[0]-> delete_word(1);
}],
[ CtrlDelete => 0, 0, kb::Delete|km::Ctrl, sub {
$_[0]-> has_selection ? $_[0]-> delete_block : $_[0]-> delete_word(0);
}],
[ DeleteChunk => 0, 0, '^Y', q(delete_current_chunk)],
[ DeleteToEnd => 0, 0, '^E', q(delete_to_end) ],
[ DupLine => 0, 0, '^K', sub {$_[0]-> insert_line($_[0]-> cursorY, $_[0]-> get_line($_[0]-> cursorY)) }],
[ DeleteBlock => 0, 0, '@D', q(delete_block) ],
[ SplitLine => 0, 0, kb::Enter, sub {$_[0]-> split_line if $_[0]-> {wantReturns}}],
[ SplitLine2 => 0, 0, km::Ctrl|kb::Enter,sub {$_[0]-> split_line if !$_[0]-> {wantReturns}}],
# block keys
[ CancelBlock => 0, 0, '@U', q(cancel_block)],
[ MarkVertical => 0, 0, '@B', q(mark_vertical)],
[ MarkHorizontal => 0, 0, '@L', q(mark_horizontal)],
[ CopyBlock => 0, 0, '@C', q(copy_block)],
[ OvertypeBlock => 0, 0, '@O', q(overtype_block)],
# clipboard keys
[ Cut => 0, 0, km::Shift|kb::Delete, q(cut)],
[ Copy => 0, 0, km::Ctrl |kb::Insert, q(copy)],
[ Paste => 0, 0, km::Shift|kb::Insert, q(paste)],
[ CutMS => 0, 0, '^X', q(cut)],
[ CopyMS => 0, 0, '^C', q(copy)],
[ PasteMS => 0, 0, '^V', q(paste)],
# undo
[ Undo => 0, 0, km::Alt|kb::Backspace, q(undo)],
[ Redo => 0, 0, '^R', q(redo)],
],
autoIndent => 1,
autoHScroll => 1,
autoVScroll => 1,
blockType => bt::CUA,
borderWidth => 2,
cursorSize => [ $::application-> get_default_cursor_width, $font-> { height}],
cursorVisible => 1,
cursorX => 0,
cursorY => 0,
cursorWrap => 0,
dndAware => "Text",
insertMode => 0,
hiliteNumbers => cl::Green,
hiliteQStrings => cl::LightBlue,
hiliteQQStrings => cl::LightBlue,
hiliteIDs => [[qw(
abs accept alarm atan2 bind binmode bless caller chdir chmod chomp chop chown
chr chroot close closedir connect continue cos crypt defined
delete die do dump each endgrent endhostent endnetent endprotoent endpwent
endservent eof eval exec exists exit exp fcntl fileno flock for fork format
formline getc getgrent getgrgid getgrnam gethostbyaddr gethostbyname gethostent
getlogin getnetbyaddr getnetbyname getnetent getpeername getpgrp getppid
getpriority getprotobyname getprotobynumber getprotoent getpwent getpwnam
getpwuid getservbyname getservbyport getservent getsockname getsockopt glob
gmtime goto grep hex if import index int ioctl join keys kill last lc lcfirst
length link listen local localtime log lstat m map mkdir msgctl msgget msgrcv
msgsnd my next no oct open opendir ord our pack package pipe pop pos print
printf prototype push q qq qr quotemeta qw qx rand read readdir readline
readlink readpipe recv redo ref rename require reset return reverse rewinddir
rindex rmdir s scalar seek seekdir select semctl semget semop send setgrent
sethostent setnetent setpgrp setpriority setprotoent setpwent setservent
setsockopt shift shmctl shmget shmread shmwrite shutdown sin sleep socket
socketpair sort splice split sprintf sqrt srand stat study sub substr symlink
syscall sysopen sysread sysseek system syswrite tell telldir tie tied time
times tr truncate uc ucfirst umask undef unless unlink unpack unshift untie use
utime values vec wait waitpid wantarray warn while write y
)], cl::Blue],
hiliteChars => ['~!@#$%^&*()+-=[]{};:\'"\\|?.,<>/', cl::Blue],
hiliteREs => [ '(#.*)$', cl::Gray, '(\/\/.*)$', cl::Gray],
hScroll => 0,
markers => [],
modified => 0,
offset => 0,
pointerType => cr::Text,
persistentBlock => 0,
readOnly => 0,
scrollBarClass => 'Prima::ScrollBar',
hScrollBarProfile => {},
vScrollBarProfile => {},
selection => [0, 0, 0, 0],
Prima/Edit.pm view on Meta::CPAN
my $ll = $self-> get_chunk_cluster_length($cs[1]);
$c .= ' ' x ($cs[0] - $ll) if $cs[0] > $ll;
my $s = $self->get_shaped_chunk($cs[1]);
my ($new_text, $new_offset) = $self->handle_bidi_input(
action => (($block || $self->insertMode) ? q(insert) : q(overtype)),
at => $cs[0],
input => $chr x $repeat,
text => $c,
rtl => $self->textDirection,
glyphs => $s,
n_clusters => $ll,
);
$self-> set_line( $cs[1], $new_text, (($block || $self->insertMode) ?
(q(add), $cs[0], $l + $repeat) :
q(overtype)
));
$self-> cursor(
$self->get_shaped_chunk($cs[1])->index2cluster($new_offset, 1),
$cs[1]
);
$self-> end_undo_group;
$self-> clear_event;
}
}
sub on_fontchanged
{
my $self = $_[0];
$self-> reset_render;
$self-> reset_scrolls;
}
sub on_size
{
my $self = $_[0];
$self-> reset_render;
$self-> reset_scrolls;
}
sub on_enable { $_[0]-> repaint; }
sub on_disable { $_[0]-> repaint; }
sub on_enter
{
my $self = $_[0];
$self-> insertMode( $::application-> insertMode);
}
sub on_change { $_[0]-> {modified} = 1;}
sub on_parsesyntax { $_[0]-> {syntaxer}-> (@_); }
sub on_dragbegin
{
my $self = shift;
$self->{drop_transaction} = [];
}
sub on_dragover
{
my ($self, $clipboard, $action, $mod, $x, $y, $ref) = @_;
$ref->{allow} = 1;
my $dt;
if ( $dt = $self->{drop_transaction} and @$dt) {
$self-> invalidate_rect(@$dt);
}
$self-> cursor( $self-> point2xy( $x, $y));
my @cp = $self->cursorPos;
my @cs = $self->cursorSize;
$self->{drop_transaction} = [@cp, $cp[0] + $self->{defcw}, $cp[1] + $cs[1]];
$self-> invalidate_rect(@{ $self->{drop_transaction} });
}
sub on_dragend
{
my ($self, $clipboard, $action, $mod, $x, $y, $ref) = @_;
my $dt;
if ( $dt = $self->{drop_transaction} and @$dt ) {
$self-> invalidate_rect(@$dt);
}
delete $self->{drop_transaction};
return unless $clipboard;
my $cap = $clipboard->text;
$self->insert_text($cap) if defined $cap;
}
sub set_block_type
{
my ( $self, $bt) = @_;
return if $bt == $self-> {blockType};
$self-> push_group_undo_action('blockType', $self-> {blockType});
$self-> {blockType} = $bt;
return unless $self-> has_selection;
$self-> reset_render;
$self-> repaint;
}
sub reset_shaping_caches
{
my $self = shift;
undef $self->{shapedChunk};
undef $self->{shapedIndex};
undef $self->{shapedClusters};
}
sub set_text_ref
{
my ( $self, $ref) = @_;
return unless defined $ref;
$self-> {capLen} = length( $$ref) || 0;
$#{$self-> {lines}} = $self-> {capLen} / 40;
@{$self-> {lines}} = ();
@{$self-> {lines}} = split( "\n", $$ref // '');
$self-> {maxLine} = scalar @{$self-> {lines}} - 1;
$self-> reset_shaping_caches;
$self-> reset_syntax;
$self-> reset_scrolls;
if ( !$self-> {resetDisabled}) {
$self-> lock;
$self-> selection(0,0,0,0);
$self-> reset;
$self-> cursor($self-> {cursorX}, $self-> {cursorY});
$self-> unlock;
$self-> notify(q(Change));
$self-> reset_scrolls;
}
}
sub text
{
unless ($#_) {
my $hugeScalarRef = $_[0]-> textRef;
return $$hugeScalarRef;
} else {
$_[0]-> textRef( \$_[1]);
}
}
sub textDirection
{
return $_[0]-> {textDirection} unless $#_;
my ( $self, $td ) = @_;
return if $self->{textDirection} == $td;
Prima/Edit.pm view on Meta::CPAN
Default value: 0
=item wantReturns BOOLEAN
Selects the way the new line ( \n ) character is recognized in the user input.
If 1, it is recognized by the Enter key; however, this disallows the toolkit
default button activation. If 0, the new line character can be entered by
pressing Ctrl+Enter key combination.
Default value: 1
=item wordDelimiters STRING
Contains string of character that are used for locating a word break.
Default STRING value consists of punctuation marks, space and tab characters,
and C<\xff> character.
See also: L<word_left>, L<word_right>
=item wordWrap BOOLEAN
Selects whether the long lines are wrapped, or can be positioned outside the horizontal
widget inferior borders. If 1, L<syntaxHilite> is not used. A line of text can be represented
by more than one line of screen text ( chunk ) . To access the text chunk-wise, use L<get_chunk>
method.
=back
=head2 Methods
=over
=item add_marker X, Y
Adds visual coordinated X,Y to L<markers> property.
=item back_char [ REPEAT = 1 ]
Removes REPEAT times a character left to the cursor. If the cursor is on 0 x-position,
removes the new-line character and concatenates the lines.
Default key: Backspace
=item cancel_block
Removes the selection block
Default key: Alt+U
=item change_locked
Returns 1 if the logical locking is on, 0 if it is off.
See also L<lock_change>.
=item copy
Copies the selected text, if any, to the clipboard.
Default key: Ctrl+Insert
=item copy_block
Copies the selected text and inserts it into the cursor position, according to
the L<blockType> value.
Default key: Alt+C
=item cursor_cend
Moves cursor to the bottom line
Default key: Ctrl+End
=item cursor_chome
Moves cursor to the top line
Default key: Ctrl+Home
=item cursor_cpgdn
Default key: Ctrl+PageDown
Moves cursor to the end of text.
=item cursor_cpgup
Moves cursor to the beginning of text.
Default key: Ctrl+PageUp
=item cursor_down [ REPEAT = 1 ]
Moves cursor REPEAT times down
Default key: Down
=item cursor_end
Moves cursor to the end of the line
Default key: End
=item cursor_home
Moves cursor to the beginning of the line
Default key: Home
=item cursor_left [ REPEAT = 1 ]
Moves cursor REPEAT times left
Default key: Left
=item cursor_right [ REPEAT = 1 ]
Moves cursor REPEAT times right
Default key: Right
=item cursor_up [ REPEAT = 1 ]
Moves cursor REPEAT times up
Default key: Up
=item cursor_pgdn [ REPEAT = 1 ]
Moves cursor REPEAT pages down
Default key: PageDown
=item cursor_pgup [ REPEAT = 1 ]
Moves cursor REPEAT pages up
Default key: PageUp
=item cursor_shift_key [ ACCEL_TABLE_ITEM ]
Performs action of the cursor movement, bound to ACCEL_TABLE_ITEM action
( defined in C<accelTable> or C<accelItems> property ), and extends the
selection block along the cursor movement. Not called directly.
=item cut
Cuts the selected text into the clipboard.
Default key: Shift+Delete
=item delete_block
Removes the selected text.
Default key: Alt+D
=item delete_char [ REPEAT = 1 ]
Delete REPEAT characters from the cursor position
Default key: Delete
=item delete_line LINE_ID, [ LINES = 1 ]
Removes LINES of text at LINE_ID.
=item delete_current_chunk
Removes the chunk ( or line, if L<wordWrap> is 0 ) at the cursor.
Default key: Ctrl+Y
=item delete_chunk CHUNK_ID, [ CHUNKS = 1 ]
Removes CHUNKS ( or lines, if L<wordWrap> is 0 ) of text at CHUNK_ID
=item delete_marker INDEX
Removes marker INDEX in L<markers> list.
=item delete_to_end
Removes text to the end of the chunk.
Default key: Ctrl+E
=item delete_text X, Y, TEXT_LENGTH
Removes TEXT_LENGTH characters at X,Y physical coordinates
=item draw_colorchunk CANVAS, LINE_ID, X, Y, COLOR
Paints the syntax-highlighted chunk taken from LINE_ID line index, at
X, Y. COLOR is used if the syntax highlighting information contains C<cl::Fore>
as color reference.
=item end_block
Stops the block selection session.
=item find SEARCH_STRING, [ X = 0, Y = 0, REPLACE_LINE = '', OPTIONS ]
Tries to find ( and, if REPLACE_LINE is defined, to replace with it )
SEARCH_STRING from (X,Y) visual coordinates. OPTIONS is an integer
that consists of the C<fdo::> constants; the same constants are used
in L<Prima::Dialog::FindDialog>, which provides graphic interface to the find and replace
facilities of L<Prima::Edit>.
Prima/Edit.pm view on Meta::CPAN
=item insert_line LINE_ID, @TEXT
Inserts @TEXT strings at LINE_ID
=item insert_text TEXT, [ HIGHLIGHT = 0 ]
Inserts TEXT at the cursor position. If HIGHLIGHT is set to 1,
the selection block is canceled and the newly inserted text is selected.
=item lock_change BOOLEAN
Increments ( 1 ) or decrements ( 0 ) lock count. Used to defer change notification
in multi-change calls. When internal lock count hits zero, C<Change> notification is called.
=item physical_to_logical X, Y
Maps visual X,Y coordinates to the logical and returns the integer pair.
Returns same values when L<wordWrap> is 0.
=item logical_to_visual X, Y
Maps logical X,Y coordinates to the visual and returns the integer pair.
Returns same values when L<wordWrap> is 0.
=item visual_to_physical X, Y
Maps visual X,Y coordinates to the physical text offset relative to the Y line
Returns same X when the line does not contain any right-to-left characters or
complex glyphs.
=item physical_to_visual X, Y
Maps test offset X from line Y to the visual X coordinate.
Returns same X when the line does not contain any right-to-left characters or
complex glyphs.
=item mark_horizontal
Starts block marking session with C<bt::Horizontal> block type.
Default key: Alt+L
=item mark_vertical
Starts block marking session with C<bt::Vertical> block type.
Default key: Alt+B
=item overtype_block
Copies the selected text and overwrites the text next to the cursor position, according to
the L<blockType> value.
Default key: Alt+O
=item paste
Copies text from the clipboard and inserts it in the cursor position.
Default key: Shift+Insert
=item realize_panning
Performs deferred widget panning, activated by setting C<{delayPanning}> to 1.
The deferred operations are those performed by L<offset> and L<topLine>.
=item set_line LINE_ID, TEXT, [ OPERATION, FROM, LENGTH ]
Changes line at LINE_ID to new TEXT. Hint scalars OPERATION, FROM and LENGTH
used to maintain selection and marking data. OPERATION is an arbitrary string,
the ones that are recognized are C<'overtype'>, C<'add'>, and C<'delete'>.
FROM and LENGTH define the range of the change; FROM is a cluster offset and
LENGTH is a length of changed text.
=item split_line
Splits a line in two at the cursor position.
Default key: Enter ( or Ctrl+Enter if L<wantReturns> is 0 )
=item select_all
Selects all text
=item start_block [ BLOCK_TYPE ]
Begins the block selection session. The block type if BLOCK_TYPE, if it is
specified, or L<blockType> property value otherwise.
=item update_block
Adjusts the selection inside the block session, extending of shrinking it to
the current cursor position.
=item word_left [ REPEAT = 1 ]
Moves cursor REPEAT words to the left.
=item word_right [ REPEAT = 1 ]
Moves cursor REPEAT words to the right.
=back
=head1 AUTHOR
Dmitry Karasik, E<lt>dmitry@karasik.eu.orgE<gt>.
=head1 SEE ALSO
L<Prima>, L<Prima::Widget>, L<Prima::Dialog::FindDialog>, F<examples/editor.pl>
=cut
( run in 1.897 second using v1.01-cache-2.11-cpan-2398b32b56e )