App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/Wx/EditorPanel.pm view on Meta::CPAN
$ln--;
my $line = $stc->GetLine($ln);
if ( $line =~ /^\{(\s*)start_of_(\w+(?:-\w*!?)?)/ ) {
if ( $2 eq $closed ) {
$closed = "";
next;
}
$stc->AddText( $self->nl )
if $stc->GetColumn($stc->GetCurrentPos);
$stc->AddText( "{$1end_of_$2}" . $self->nl );
$did++;
last;
}
elsif ( $line =~ /^\{(\s*)so(\w(?:-\w*!?)?)/ ) {
if ( $2 eq $closed ) {
$closed = "";
next;
}
$stc->AddText( $self->nl )
if $stc->GetColumn($stc->GetCurrentPos);
$stc->AddText( "{$1eo$2}" . $self->nl );
$did++;
last;
}
elsif ( $line =~ /^\{(\s*)end_of_(\w+(?:-\w*!?)?)/ ) {
$closed = $2;
}
elsif ( $line =~ /^\{(\s*)so(\w(?:-\w*!?)?)/ ) {
$closed = $2;
}
}
return if $did;
$stc->CallTipShow( $stc->GetCurrentPos, "No open section to close" );
}
method OnCopy($event) {
$self->{t_editor}->Copy;
}
method OnCut($event) {
$self->{t_editor}->Cut;
}
method OnDelete($event) {
my ( $from, $to ) = $self->{t_editor}->GetSelection;
$self->{t_editor}->Remove( $from, $to ) if $from < $to;
}
method OnExternalEditor($event) {
my $editor = $ENV{VISUAL} // $ENV{EDITOR};
$self->alert( 0, "No external editor specified" ), return unless $editor;
my $e = $self->{t_editor};
my $pos = $e->GetCurrentPos;
my $mod = $e->IsModified;
# Save in temp file and call editor.
use File::Temp qw(tempfile);
( undef, my $file ) = tempfile( SUFFIX => $preferences{chordproext},
OPEN => 0 );
$e->SaveFile($file);
my @st = stat($file);
$self->log( 'I', "Running $editor on $file (" .
plural( $e->GetLineCount, " line" ) . ", " .
plural( $st[7], " byte" ) . ")" );
::sys( $editor, $file );
if ( (stat($file))[7] == $st[7] && (stat(_))[9] == $st[9] ) {
$self->log( 'I', "Running $editor did not make changes" );
$self->alert( 0, "No changes from external editor" );
}
else {
$e->LoadFile($file);
$self->log( 'I', "Updated editor from $file (" .
plural( $e->GetLineCount, " line" ) . ", " .
plural( (stat(_))[7], " byte" ) . ")" );
$mod = 1;
# Clear selection and set insertion point.
$e->SetSelection( $pos, $pos );
$e->EmptyUndoBuffer;
}
unlink($file);
$e->SetModified($mod);
$e->SetFocus;
}
# Experimental.
# This approach is a bit clumsy and prone to errors.
method OnExternalEditorSync($event) {
my $editor = $ENV{VISUAL} // $ENV{EDITOR};
$self->alert( 0, "No external editor specified" ), return unless $editor;
my $e = $self->{t_editor};
my $pos = $e->GetCurrentPos;
my $mod = $e->IsModified;
# Save in temp file and call editor.
use File::Temp qw(tempfile);
( undef, my $file ) = tempfile( SUFFIX => $preferences{chordproext},
OPEN => 0 );
$e->SaveFile($file);
my @st = stat($file);
$self->log( 'I', "Running $editor on $file (" .
plural( $e->GetLineCount, " line" ) . ", " .
plural( $st[7], " byte" ) . ")" );
my $cmd = sprintf("%s %s", $editor, qquote($file) );
my $edit = Wx::Process::Open( $cmd );
unless ( $edit ) {
$self->log( 'I', "Cannot start editor");
return;
}
my $pid = $edit->GetPid;
$self->log( 'I', "Editor pid = $pid");
my $did;
while ( Wx::Process::Exists($pid) ) {
next if (stat($file))[7] == $st[7] && (stat(_))[9] == $st[9];
@st = stat(_);
$e->LoadFile($file);
$self->log( 'I', "Updated editor from $file (" .
plural( $e->GetLineCount, " line" ) . ", " .
plural( $st[7], " byte" ) . ")" );
$mod = 1;
# Clear selection and set insertion point.
$e->SetSelection( $pos, $pos );
$e->EmptyUndoBuffer;
$did++;
}
continue {
wxTheApp->Yield;
sleep(1);
}
if ( !$did && (stat($file))[7] == $st[7] && (stat(_))[9] == $st[9] ) {
$self->log( 'I', "Running $editor did not make changes" );
$self->alert( 0, "No changes from external editor" );
}
unlink($file);
$e->SetModified($mod);
$e->SetFocus;
}
method OnPaste($event) {
$self->{t_editor}->Paste;
}
method OnRedo($event) {
$self->{t_editor}->CanRedo && $self->{t_editor}->Redo;
}
method OnSave($event) {
return unless $self->{t_editor}->IsModified
|| !defined $state{currentfile};
$self->save_file( $state{currentfile} )
}
method OnSaveAs {
$self->save_file;
}
method OnSongbook {
return unless $self->check_source_saved;
$self->GetParent->select_mode("sbexport");
}
method OnText($event) {
$self->{t_editor}->SetModified(1);
}
method OnUndo($event) {
$self->{t_editor}->Undo;
}
#### Insertions
method OnInsertTitle($event) {
$self->embrace_directive("title");
}
method OnInsertSubtitle($event) {
$self->embrace_directive("subtitle");
}
method OnInsertKey($event) {
$self->embrace_directive("key");
}
method OnInsertArtist($event) {
$self->embrace_directive("artist");
}
method OnInsertChorus($event) {
$self->embrace_section("chorus");
( run in 2.332 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )