App-Music-ChordPro

 view release on metacpan or  search on metacpan

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

	    else {
		$state{editortheme} = "light";
	    }
	}
	else {
	    # Auto and no clue? Use light.
	    $preferences{editortheme} = $state{editortheme} = "light";
	}
    }
    else {
	$state{editortheme} = $preferences{editortheme};
    }
    push( @{$state{msgs}}, "Using $state{editortheme} theme" );
}

method get_preferences() {

    restorewinpos( $self, "main" );
    $self->Show(1);
}

method save_preferences() {
    savewinpos( $self, "main" );
    ChordPro::Wx::Config->Store;
}

method aboutmsg() {
    my $firstyear = 2016;
    my $year = 1900 + (localtime(time))[5];
    if ( $year != $firstyear ) {
	$year = "$firstyear,$year";
    }

    # Sometimes version numbers are localized...
    my $dd = sub { my $v = $_[0]; $v =~ s/,/./g; $v };

    local $ENV{CHORDPRO_LIB} =
      $preferences{enable_customlib} ? $preferences{customlib} : "";
    CP->setup_resdirs;
    my $msg = join
      ( "",
	"ChordPro version ",
	$dd->($ChordPro::VERSION),
	"\n",
	"https://www.chordpro.org\n",
	"Copyright $year Johan Vromans <jvromans\@squirrel.nl>\n",
	"\n",
	"GUI designed with wxGlade by the ChordPro Team\n\n",
	"Run-time information:\n",
	::runtimeinfo() =~ s/CHORDPRO_LIB/Custom lib  /rm
      );

    return $msg;
}

method check_saved() {
    for ( panels ) {
	return unless $self->{$_}->check_source_saved;
	return unless $self->{$_}->check_preview_saved;
    }
    # Panels may save prefs to preferences.
    $self->{$_}->save_preferences for panels;
    1;
}

method setup_statusbar() {
    # Add statusbar.
    return unless $preferences{expert};
    $self->{f_main_statusbar} = $self->CreateStatusBar(1);
    $self->{f_main_statusbar}->SetStatusWidths(-1);
}

################ Event handlers (alphabetic order) ################

# This method is called from the helper panels.
method OnAbout($event) {

    my $info = Wx::AboutDialogInfo->new;
    my $year = 1900 + (localtime(time))[5];
    $info->SetName("ChordPro");
    $info->SetVersion( $VERSION .
		       ( $VERSION =~ /_/ ? " (unsupported development snapshot)" : "" ) );
    $info->SetDescription("ChordPro is free software");
    $info->SetCopyright("â’¸ 2016-$year Johan Vromans\nThe ChordPro Team");
    $info->SetWebSite( "https://www.chordpro.org",
		       "Visit the ChordPro web site");
    my $icon = Wx::Icon->new;
    $info->SetIcon($icon)
      if $icon->LoadFile( CP->findres("chordpro-splash.png",class=>"icons"),wxBITMAP_TYPE_PNG );
    Wx::AboutBox($info);
}

method OnClose($event) {
    return unless $self->check_saved;
    # Save preferences to persistent storage.
    $self->save_preferences;
    # Stop webview process (GTK).
    if ( $self->{panel} && $self->{panel}->{webview} ) {
	$self->{panel}->{webview}->Close;
    }
    $self->Destroy;
}

# SHow the create buttons, or the recents list.
method OnCreateRecent($event) {
    $self->create_or_recent( $self->{rb_createrecent}->GetSelection );
}

method OnExportFolder($event) {

    # We handle this here for the same reasons as OnOpen.
    my $fd = Wx::DirDialog->new
      ( $self,
	_T("Select the folder with the songs"),
	$state{sbe_folder} // $state{songbookexport}{folder} // "",
	wxDD_DIR_MUST_EXIST );
    my $ret = $fd->ShowModal;
    if ( $ret == wxID_OK ) {
	$self->select_mode("sbexport")->open_dir( $fd->GetPath );
    }
    $fd->Destroy;

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

    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 );
    }
    $fd->Destroy;
}

method OnPreferences($event) {
    unless ( $self->{d_prefs} ) {
	require ChordPro::Wx::SettingsDialog;
	$self->{d_prefs} = ChordPro::Wx::SettingsDialog->new
	  ( $self, wxID_ANY, "Settings" );
	restorewinpos( $self->{d_prefs}, "prefs" );
    }
    else {
	$self->{d_prefs}->refresh;
    }

    # The Settings dialog operates on the current $preferences.
    my $ret = $self->{d_prefs}->ShowModal;
    savewinpos( $self->{d_prefs}, "prefs" );
    $state{panel}->set_focus unless $state{mode} eq "initial";
    return unless $ret == wxID_OK;

    # $preferences may have changed.
    $self->save_preferences;

    # Update the requestor.
    $state{panel}->update_preferences unless $state{mode} eq "initial";

    $self->setup_menubar;
}

# On the recents list, click selects and displays the file name.
# Double click selects the entry for processing.

method OnRecentDclick($event) {
    my $file = $self->{l_recent}->GetLabel;
    $self->select_mode("editor");
    $self->{p_editor}->openfile( $file, 0 );
}

method OnRecentSelect($event) {
    my $n = $self->{lb_recent}->GetSelection;
    my $file = $self->{lb_recent}->GetClientData($n);
    $self->{l_recent}->SetLabel($file);
    $self->{l_recent}->SetToolTip($file);
}

method OnStart($event) {
    return unless $self->check_saved;
    $self->select_mode("initial");
}

method OnSysColourChanged($event) {
    $self->init_theme;
    $state{panel}->{t_editor}->refresh unless $state{mode} eq "initial";
}

################ End of Event handlers ################

1;



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