App-Music-ChordPro

 view release on metacpan or  search on metacpan

lib/ChordPro/Wx/Main.pm  view on Meta::CPAN

	    "Sorry for the inconvenience.",
	    "Check your Settings",
	    Wx::wxOK|Wx::wxICON_WARNING|Wx::wxDIALOG_NO_PARENT );
	$md->ShowModal;
    }
    return if $self->{p_initial}->IsShown;
    my $mod = $self->{p_editor}->{t_editor}->IsModified;
    my $f = fn_basename($state{windowtitle} // "ChordPro");
    if ( is_macos ) {
	wxTheApp->GetTopWindow->OSXSetModified($mod);
    }
    else {
	$f .= " (modified)" if $mod;
    }
    $f = "ChordPro — $f" if $state{windowtitle};
    $self->SetTitle($f);

    if ( $state{mode} eq "editor") {
	my $t = $self->{p_editor}->{t_editor}->GetText;

	if ( $t =~ /^\{\s*t(?:itle)?[: ]+([^\}]*)\}/m ) {
	    $self->{p_editor}->{l_status}->SetLabel(demarkup($1));
	}

	if ( $state{editchanged}
	     && $self->{p_editor}->{sw_lr}->IsSplit ) {

	    if ( $state{have_webview}
		 && $preferences{enable_htmlviewer} ) {
		$self->{p_editor}->preview([]);
		$state{editchanged} = 0;
	    }
	    else {
		# Preview is no longer actual -- how to signal?
	    }
	}
    }

}

# From menu.
method OnHelp_ChordPro($event) {
    Wx::LaunchDefaultBrowser("https://www.chordpro.org/chordpro/chordpro-introduction/");
}

# From menu.
method OnHelp_Config($event) {
    Wx::LaunchDefaultBrowser("https://www.chordpro.org/chordpro/chordpro-configuration/");
}

method OnHelp_Example($event) {
    $self->select_mode("editor");
    $self->{p_editor}->openfile( CP->findres( $preferences{expert}
					      ? "mollymalone.cho"
					      : "swinglow.cho",
					      class => "examples" ),
				 1, " example.cho " );
}

method OnExpertLineEndings($event) {
    $state{vieweol} = wxTheApp->GetTopWindow->GetMenuBar->FindItem($event->GetId)->IsChecked;
    if ( $state{mode} eq "editor" ) {
	$self->{p_editor}->{t_editor}->SetViewEOL($state{vieweol});
    }
}

method OnExpertWhiteSpace($event) {
    $state{viewws} = wxTheApp->GetTopWindow->GetMenuBar->FindItem($event->GetId)->IsChecked;
    if ( $state{mode} eq "editor" ) {
	$self->{p_editor}->{t_editor}->SetViewWhiteSpace($state{viewws});
    }
}

# From opening panel.
method OnHelp_Docs($event) {
    Wx::LaunchDefaultBrowser("https://www.chordpro.org/chordpro/home/");
}

# From opening panel.
method OnHelp_Site($event) {
    Wx::LaunchDefaultBrowser("https://www.chordpro.org/");
}

method OnMaximize($event) {
    my $top = wxTheApp->GetTopWindow;
    # Note that ShowFullScreen on macOS isn't really Full Screen.
    # https://github.com/ChordPro/chordpro/issues/373#issuecomment-2501855028
    my $full = $top->IsMaximized;
    $top->Maximize( !$full );
}

method OnNew($event) {
    if ( $state{mode} eq "initial" ) {
	$self->select_mode("editor");
    }
    else {
	return unless $self->check_saved;
    }
    $self->{p_editor}->newfile;
}

method OnOpen($event) {
    return unless $self->check_saved;

    # In case it is a synthetic event.
    if ( $event && ( my $arg = $event->GetClientData ) ) {
	$self->select_mode("editor")->openfile( $arg, 1 );
	return;
    }

    # We handle the dialog here, so we do not have to switch to the editor
    # unless there's real editing to do.

    my $fd = Wx::FileDialog->new
      ( $self,
	_T("Choose ChordPro file"),
	fn_dirname($state{recents}[0]//""),
	"",
	$state{ffilters},
	wxFD_OPEN|wxFD_FILE_MUST_EXIST );
    my $ret = $fd->ShowModal;
    if ( $ret == wxID_OK ) {
	$self->select_mode("editor")->openfile( $fd->GetPath, 1 );



( run in 0.714 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )