Win32-Mechanize-NotepadPlusPlus
view release on metacpan or search on metacpan
had wrong values that didn't match getEncoding's return values
(#50)
- add setEncoding command to call NPPM_SETBUFFERENCODING
as the logical pair to getEncoding (#51)
v0.004001 2020-Jun-20
- fix bug in notepad->prompt(), which only used two of the three
arguments, in wrong order (#47); test suite verifies default
values for title and default when they aren't used
- added new examples/pasteSpecial.pl to show how to paste a
clipboard entry other than CF_TEXT into Notepad++
v0.004 2020-Jun-04
- fix bug in propertyNames() which deleted final char (#45)
- implemented helper methods: forEachLine, deleteLine, replaceWholeLine,
replaceLine, flash, getWord, getCurrentWord, getUserLineSelection,
getUserCharSelection (#15)
- make setTarget an alias of setTargetRange, and write an alias of
addText, for PythonScript compatibility (#15)
- implemented new auto-wrapper to get searchInTarget and similar calls
to work right (#42)
examples/pasteSpecial.pl view on Meta::CPAN
#!/usr/bin/env perl
################################################
# PasteSpecial for Notepad++
# List formats currently on the clipboard
# Allows you to choose one of those formats
# Will paste the selected type (UTF8-encoded)
# at the current location in the active file
################################################
# HISTORY
# v0.1: STDIN-based choice
# v1.0: DialogBox choice
# v2.0: Add REFRESH button to update the ListBox
# Defaults to selecting/displaying the first Clipboard variant
# Persist checkbox allows dialog to stay open for multiple pastes
examples/pasteSpecial.pl view on Meta::CPAN
sub formats {
my @f = $CLIP->EnumFormats();
foreach my $format (sort {$a <=> $b} @f) {
$map{$format} //= $CLIP->GetFormatName($format) // '<unknown>';
$rmap{ $map{$format} } = $format;
}
return @f;
}
sub runDialog {
my $clipboard;
my $persist = 1;
my $dlg = Win32::GUI::Window->new(
-title => sprintf('Notepad++ Paste Special %s', $VERSION),
-left => CW_USEDEFAULT,
-top => CW_USEDEFAULT,
-size => [580,300],
-resizable => 0,
-maximizebox => 0,
-hashelp => 0,
-dialogui => 1,
);
my $icon = Win32::GUI::Icon->new(100); # v1.1: change the icon
$dlg->SetIcon($icon) if defined $icon;
my $update_preview = sub {
my $self = shift // return -1;
my $value = $self->GetText($self->GetCurSel());
my $f=$rmap{$value};
$clipboard = $CLIP->GetAs($f);
$clipboard = Encode::decode('UTF16-LE', $clipboard) if $f == CF_UNICODETEXT();
(my $preview = $clipboard) =~ s/([^\x20-\x7F\r\n])/sprintf '\x{%02X}', ord $1/ge;
$preview =~ s/\R/\r\n/g;
$self->GetParent()->PREVIEW->Text( $preview );
return 1;
};
my $lb = $dlg->AddListbox(
-name => 'LB',
-pos => [10,10],
-size => [230, $dlg->ScaleHeight()-10],
-vscroll => 1,
-onSelChange => $update_preview, # v1.2: externalize this callback so it can be run from elsewhere
examples/pasteSpecial.pl view on Meta::CPAN
},
);
$dlg->AddButton(
-name => 'OK',
-text => 'Paste',
-size => [80,25],
-left => $dlg->ScaleWidth()-90*2,
-top => $button_top,
-onClick => sub{ # v1.3: allow to persist after paste: TODO: move the editor->addText here
editor->addText( Encode::encode("UTF8", $clipboard) ) if defined $clipboard;
return $persist ? 1 : -1;
},
);
$dlg->AddButton(
-name => 'CANCEL',
-text => 'Cancel',
-size => [80,25],
-left => $dlg->ScaleWidth()-90*1,
-top => $button_top,
-onClick => sub{ $clipboard=undef; -1; },
);
$dlg->AddGroupbox(
-name => 'GB',
-title => 'Preview',
-pos => [250,10],
-size => [$dlg->ScaleWidth()-260, $button_top-20],
);
$dlg->AddLabel(
examples/pasteSpecial.pl view on Meta::CPAN
-onClick => sub {
$persist = !$persist;
1;
},
);
$dlg->CB->SetCheck($persist);
$refresh_formats->();
$dlg->Show();
Win32::GUI::Dialog();
return $clipboard;
}
lib/Win32/Mechanize/NotepadPlusPlus/Editor.pm view on Meta::CPAN
=over
=item cut
editor->cut();
Cut the selection to the clipboard.
See Scintilla documentation for L<SCI_CUT|https://www.scintilla.org/ScintillaDoc.html#SCI_CUT>
=cut
$autogen{SCI_CUT} = {
subProto => 'cut()',
sciProto => 'SCI_CUT',
};
=item copy
editor->copy();
Copy the selection to the clipboard.
See Scintilla documentation for L<SCI_COPY|https://www.scintilla.org/ScintillaDoc.html#SCI_COPY>
=cut
$autogen{SCI_COPY} = {
subProto => 'copy()',
sciProto => 'SCI_COPY',
};
=item paste
editor->paste();
Paste the contents of the clipboard into the document replacing the selection.
See Scintilla documentation for L<SCI_PASTE|https://www.scintilla.org/ScintillaDoc.html#SCI_PASTE>
=cut
$autogen{SCI_PASTE} = {
subProto => 'paste()',
sciProto => 'SCI_PASTE',
};
lib/Win32/Mechanize/NotepadPlusPlus/Editor.pm view on Meta::CPAN
$autogen{SCI_CANPASTE} = {
subProto => 'canPaste() => bool',
sciProto => 'SCI_CANPASTE => bool',
};
=item copyRange
editor->copyRange($start, $end);
Copy a range of text to the clipboard. Positions are clipped into the document.
See Scintilla documentation for L<SCI_COPYRANGE|https://www.scintilla.org/ScintillaDoc.html#SCI_COPYRANGE>
=cut
$autogen{SCI_COPYRANGE} = {
subProto => 'copyRange(start, end)',
sciProto => 'SCI_COPYRANGE(position start, position end)',
};
=item copyText
editor->copyText($text);
Copy argument text to the clipboard.
See Scintilla documentation for L<SCI_COPYTEXT|https://www.scintilla.org/ScintillaDoc.html#SCI_COPYTEXT>
=cut
$autogen{SCI_COPYTEXT} = {
subProto => 'copyText(text) => int',
sciProto => 'SCI_COPYTEXT(position length, const char *text)',
};
lib/Win32/Mechanize/NotepadPlusPlus/Notepad.pm view on Meta::CPAN
Menus are searched for the text, and when found, the internal ID of the menu command is cached. When runMenuCommand is called, the cache is first checked if it holds the internal ID for the given menuName and menuOption. If it does, it simply uses th...
C<@menuNames> is a one-or-more element list of strings; each string can either be a name from the menu hierarchy (either a menu name or a command name) or a pipe-separated string with multiple names. See the example below.
Returns:
True if the menu command was found, otherwise False
e.g.:
notepad()->runMenuCommand('Tools', 'SHA-256', 'Generate from selection into clipboard');
notepad()->runMenuCommand('Tools', 'SHA-256 | Generate from selection into clipboard');
notepad()->runMenuCommand('Tools | SHA-256', 'Generate from selection into clipboard');
notepad()->runMenuCommand('Tools | SHA-256 | Generate from selection into clipboard');
notepad()->runMenuCommand('Macro', 'Trim Trailing Space and Save', { refreshCache => 1 });
=cut
my %cacheMenuCommands;
sub runMenuCommand {
my $self = shift;
# 2019-Oct-14: see debug\menuNav.pl for my attempt to find a specific menu; I will need to add caching here, as well as add test coverage...
# It appears 'menuOption' was meant to be a submenu item; in which case, I might want to collapse it down, or otherwise determine whether the third argument is passed or not
t/02-bits.t view on Meta::CPAN
notepad()->menuCommand($NPPIDM{IDM_DEBUGINFO});
my $hWnd = WaitWindowLike(0, 'Debug Info', undef, undef, undef, 2); #wait up to 2 seconds for the DebugInfo
note sprintf "\tWaitWindowLike: GetForegroundWindow(): %s\n", GetForegroundWindow()//'<undef>';
note sprintf "\tWaitWindowLike: hWnd = '%s'", $hWnd//'<undef>';
note sprintf "\tWaitWindowLike: wmGETTEXT= '%s'", WMGetText($hWnd)//'<undef>';
note sprintf "\tWaitWindowLike: text= '%s'", GetWindowText($hWnd)//'<undef>';
note sprintf "\tWaitWindowLike: class= '%s'", GetClassName($hWnd)//'<undef>';
isnt $hWnd, notepad->hwnd(), 'Debug Info should have popped up by now';
is my $dlgname = GetWindowText($hWnd), 'Debug Info', 'Debug Info: check dialog name';
# need some way to click the "Copy debug info into clipboard" button...
#PushButton("Copy debug info into clipboard");
#sleep(1);
my $debugInfo;
for my $c (GetChildWindows($hWnd)) {
$debugInfo = WMGetText($c),last if GetClassName($c) eq 'Edit';
}
# done with dialog
PushButton("OK", 0.5);
# extract version and bits from debugInfo
t/npp-menucmd.t view on Meta::CPAN
# 2. add known text
editor()->{_hwobj}->SendMessage_sendRawString( $SCIMSG{SCI_SETTEXT}, 0, "Hello World" );
select undef,undef,undef,0.25;
# 3. select that text
notepad()->menuCommand('IDM_EDIT_SELECTALL');
select undef,undef,undef,0.25;
# 4. run the menu command
my $ret = notepad()->runMenuCommand( "Tools | $algorithm", 'Generate from selection into clipboard');
unless(defined $ret) {
$algorithm = 'MD5';
$expected = 'b10a8db164e0754105b7a99be72e3fe5';
$ret = notepad()->runMenuCommand( "Tools | $algorithm", 'Generate from selection into clipboard');
}
ok $ret, "runMenuCommand(Tools | $algorithm | Generate from selection into clipboard): retval"; note sprintf qq(\t=> "%s"\n), $ret // '<undef>';
# 5. paste the resulting text
notepad()->menuCommand('IDM_EDIT_PASTE');
# 6. get the resulting textlength and text
my $len = editor()->{_hwobj}->SendMessage( $SCIMSG{SCI_GETTEXTLENGTH} ); note sprintf qq(\t=> "%s"\n), $len // '<undef>';
{
my $txt;
eval {
$txt = editor()->{_hwobj}->SendMessage_getRawString( $SCIMSG{SCI_GETTEXT}, $len+1, { trim => 'wparam' } );
t/npp-menucmd.t view on Meta::CPAN
};
$txt =~ s/[\0\s]+$//; # remove trailing spaces and nulls
is $txt, $expected, "runMenuCommand(): resulting $algorithm text"; note sprintf qq(\t%s => "%s"\n), $algorithm, $txt // '<undef>';
}
# 7. need to try again without the Tools| prefix, to cover a missing level (search recursion) -- issue#63
editor()->{_hwobj}->SendMessage_sendRawString( $SCIMSG{SCI_SETTEXT}, 0, "Hello World" ); # 2. set text
select undef,undef,undef,0.25;
notepad()->menuCommand('IDM_EDIT_SELECTALL'); # 3. select all
select undef,undef,undef,0.25;
$ret = notepad()->runMenuCommand( $algorithm, 'Generate from selection into clipboard'); # 4. run truncated menu entry
ok $ret, "runMenuCommand($algorithm | Generate from selection into clipboard): retval [TRUNCATED CALL]"; note sprintf qq(\t=> "%s"\n), $ret // '<undef>';
notepad()->menuCommand('IDM_EDIT_PASTE'); # 5. paste
# 6. textLength and value
$len = editor()->{_hwobj}->SendMessage( $SCIMSG{SCI_GETTEXTLENGTH} ); note sprintf qq(\t=> "%s"\n), $len // '<undef>';
{
my $txt;
eval {
$txt = editor()->{_hwobj}->SendMessage_getRawString( $SCIMSG{SCI_GETTEXT}, $len+1, { trim => 'wparam' } );
} or do {
diag "eval(getRawString) = '$@'";
$txt = '';
( run in 0.716 second using v1.01-cache-2.11-cpan-f03e8824b8d )