App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/Wx/Utils.pm view on Meta::CPAN
"Make line endings visible for debugging", 1,
"OnExpertLineEndings" ],
[ wxID_ANY, M_ALL, "View White Space",
"Make white space visible for debugging", 1,
"OnExpertWhiteSpace" ],
) : (),
[],
[ wxID_FULLSCREEN(), M_ALL, "Zoom\tShift-Ctrl-Z",
"OnMaximize" ],
]
],
[ wxID_ANY, M_EDITOR, "&Insert",
[ [ wxID_ANY, M_EDITOR, "{&title}",
"Insert a {title} directive", "OnInsertTitle" ],
[ wxID_ANY, M_EDITOR, "{&subtitle}",
"Insert a {subtitle} directive", "OnInsertSubtitle" ],
[],
[ wxID_ANY, M_EDITOR, "&Verse section",
"Insert start/end of verse directive.", "OnInsertVerse" ],
[ wxID_ANY, M_EDITOR, "&Chorus section",
"Insert start/end of chorus directive.", "OnInsertChorus" ],
[ wxID_ANY, M_EDITOR, "&Tab section",
"Insert start/end of tab directive.", "OnInsertTab" ],
[ wxID_ANY, M_EDITOR, "&Grid section",
"Insert start/end of grid directive.", "OnInsertGrid" ],
[],
[ wxID_ANY, M_EDITOR, "Special symbol",
"Insert a special symbol.", "OnInsertSymbol" ],
]
],
[ wxID_ANY, M_EDITOR|M_SONGBOOK, "Tasks",
[ [ wxID_ANY, M_EDITOR|M_SONGBOOK, "Default Preview\tCtrl-P",
"Preview with default formatting", "OnPreview" ],
[ wxID_ANY, M_EDITOR|M_SONGBOOK, "No Chord Diagrams",
"Preview without chord diagrams", "OnPreviewNoDiagrams" ],
[ wxID_ANY, M_EDITOR|M_SONGBOOK, "Lyrics Only",
"Preview with just the lyrics", "OnPreviewLyricsOnly" ],
[ wxID_ANY, M_EDITOR|M_SONGBOOK, "More...",
"Transpose, transcode, and more", "OnPreviewMore" ],
[],
]
],
[ wxID_HELP,
[ [ wxID_ANY, M_ALL, "ChordPro File Format",
"Help about the ChordPro file format", "OnHelp_ChordPro" ],
[ wxID_ANY, M_ALL, "ChordPro Configuration Files",
"Help about the configuration files", "OnHelp_Config" ],
[],
[ wxID_ANY, M_ALL, "Enable Debugging Info in PDF",
"Add sources and configuration files to the PDF for debugging", 1,
"OnHelp_DebugInfo" ],
[],
[ wxID_ABOUT, M_ALL, "About ChordPro",
"About WxChordPro", "OnAbout" ],
]
]
];
my $target = $Wx::wxTheApp->GetTopWindow;
my $mb = Wx::MenuBar->new;
for ( @$ctl ) {
# [ wxID_FILE, [ ... ] ]
my @data = @$_;
my $id = shift(@data);
my $menu = pop(@data);
my $sels = shift(@data) // M_ALL;
my $text = shift(@data);
$id = Wx::NewId if $id < 0;
my $m = Wx::Menu->new;
for my $item ( @$menu ) {
if ( !@$item ) {
# []
$m->AppendSeparator;
next;
}
# [ wxID_NEW, "", "Create new", ..., "OnNew" ],
my @data = @$item;
my $id = shift(@data);
my $cb = pop(@data);
my $sels = shift(@data) // M_ALL;
my $text = shift(@data);
my $tip = shift(@data);
$id = Wx::NewId if $id < 0;
my $mi = $m->Append( $id,
_T($text // Wx::GetStockLabel($id)),
$tip ? _T($tip) : "", @data );
push( @swingers, [ $mi, $sels ] ) unless $sels == M_ALL;
if ( my $code = $target->can($cb) ) {
Wx::Event::EVT_MENU( $target, $id, $code );
}
else {
# $self->log("W", "No callback for $cb" );
Wx::Event::EVT_MENU
( $target, $id,
sub {
if ( my $code = $ChordPro::Wx::Config::state{panel}->can($cb) ) {
&$code( $ChordPro::Wx::Config::state{panel}, $_[1] );
}
else {
$self->log("E", "No callback for $cb" );
}
} );
}
}
# Add menu to menu bar.
$mb->Append( $m, _T($text // Wx::GetStockLabel($id)) );
}
# Append the tasks.
my $menu = $mb->FindMenu("Tasks");
$menu = $mb->GetMenu($menu);
my $tasks = $ChordPro::Wx::Config::state{presets}{tasks};
$menu->AppendSeparator if %{$tasks};
while ( my ($title,$info) = each %{$tasks} ) {
my $file = $info->{file};
my $id = Wx::NewId();
# Append to the menu.
my $mi = $menu->Append( $id, $title, _T("Custom task: ").$title );
Wx::Event::EVT_MENU
( $self, $id,
sub { $ChordPro::Wx::Config::state{panel}->preview( [ "--config", $file ] ) }
);
push( @swingers, [ $mi, M_ALL & ~M_MAIN ] );
}
# Add menu bar.
$target->SetMenuBar($mb);
return $mb;
}
push( @EXPORT, "setup_menubar", "update_menubar" );
################ ################
sub savewinpos( $win, $name ) {
return unless $name eq "main";
$ChordPro::Wx::Config::state{windows}->{$name} =
join( " ", $win->GetPositionXY, $win->GetSizeWH );
}
sub restorewinpos( $win, $name ) {
return unless $name eq "main";
$win = $Wx::wxTheApp->GetTopWindow;
my $t = $ChordPro::Wx::Config::state{windows}->{$name};
if ( $t ) {
my @a = split( ' ', $t );
if ( is_msw || is_macos ) {
$win->SetSizeXYWHF( $a[0],$a[1],$a[2],$a[3], 0 );
}
else {
# Linux WM usually prevent placement.
$win->SetSize( $a[2],$a[3] );
}
}
}
push( @EXPORT, 'savewinpos', 'restorewinpos' );
################ ################
sub panels() {
my @panels = qw( p_editor p_sbexport );
wantarray ? @panels : \@panels;
}
push( @EXPORT, 'panels' );
################ ################
sub ellipsize( $widget, %opts ) {
my $text = $opts{text} // $widget->GetText;
my $home = ChordPro::Paths->get->home;
$text =~ s/^\Q$home\E\/*/~\//;
my $width = ($widget->GetSizeWH)[0];
$text = Wx::Control::Ellipsize( $text, Wx::WindowDC->new($widget),
$opts{type} // wxELLIPSIZE_END(),
$width-10, wxELLIPSIZE_FLAGS_DEFAULT() )
if Wx::Control->can("Ellipsize");
# Change w/o triggering a EVT_TEXT event.
$widget->ChangeValue($text);
}
push( @EXPORT, "ellipsize" );
( run in 0.856 second using v1.01-cache-2.11-cpan-5837b0d9d2c )