App-Music-ChordPro

 view release on metacpan or  search on metacpan

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

	my $panel = $self->{"pn_$p"};
	#$handler = "OnI".ucfirst($p);
	my $h = $self->can($handler);
	warn("Missing pn handler $handler") unless $h;
	$handler = sub { &$h( $self, undef ) };
	Wx::Event::EVT_LEFT_UP( $panel, $handler );
	foreach my $n ( $panel->GetChildren ) {
	    Wx::Event::EVT_LEFT_UP( $n, $handler );
	}
    }

    Wx::Event::EVT_MAXIMIZE( $self, $self->can("OnMaximized") );
}

method select_mode( $mode ) {
    my @panels = panels;

    if ( $mode eq "initial" ) {
	$self->{$_}->Show(0) for @panels;
	$self->{p_initial}->Show(1);
	$self->refresh;
	$self->SetTitle("ChordPro");
    }
    else {
	$self->{p_initial}->Show(0);
	$self->{$_}->Show( $_ eq "p_$mode" ) for @panels;
	$self->{"p_$mode"}->refresh;
    }
    $self->{sz_main}->Layout;
    $state{mode} = $mode;
    return $state{panel} = $self->{"p_$mode"};
}

# Explicit (re)initialisation of this class.
method init( $options ) {

    $state{mode} = "initial";

    # General runtime options.
    $state{verbose}   = $options->{verbose};
    $state{trace}     = $options->{trace};
    $state{debug}     = $options->{debug};

    # For development/debugging.
    $state{logstderr} = $options->{logstderr};

    $self->SetStatusBar(undef);
    $self->get_preferences;
    $self->setup_menubar;
    $self->setup_statusbar;
    Wx::Event::EVT_SYS_COLOUR_CHANGED( $self,
				       $self->can("OnSysColourChanged") );
    $self->init_theme;

    if ( @ARGV ) {
	# use DDP;
	use charnames ':full';
	require _charnames;
	push( @{$state{msgs}},
	      "ARGV: " . np(@ARGV,
			      show_unicode => 1,
			      escape_chars => 'nonascii',
			      unicode_charnames => 1 ) ) if 0;
	my $arg = shift(@ARGV);	# ignore rest
	$arg = decode_utf8($arg);
	push( @{$state{msgs}},
	      'DECODED: ' . np($arg,
			    show_unicode => 1,
			    escape_chars => 'nonascii',
			    unicode_charnames => 1 ) ) if 0;

	if ( fs_test( 'd', $arg ) ) {
	    return 1 if $self->select_mode("sbexport")->open_dir($arg);
	}
	elsif ( !fs_test( 'r', $arg ) ) {
	    return 1 if $self->select_mode("editor")->newfile($arg);
	    Wx::MessageDialog->new( $self, "Error opening $arg",
				    "File Open Error",
				    wxOK | wxICON_ERROR )->ShowModal;
	}
	else {
	    return $self->select_mode("editor")->openfile($arg);
	}
    }
    if ( $options->{new} ) {
	$self->select_mode("editor")->newfile;
    }
    else {
	$self->select_mode("initial");
    }

    return 1;
}

method refresh() {
    $self->init_recents;
    $self->update_menubar(M_MAIN);
}

method init_recents() {

    my $r = $state{recents};

    if ( defined $r->[0] ) {
	my $ctl = $self->{lb_recent};
	$ctl->Clear;
	$ctl->Enable(1);
	my $i = 0;
	for my $file ( @$r ) {
	    next unless fs_test( s => $file );
	    last unless defined $file;
	    $ctl->Append( fn_basename($file) );
	    $ctl->SetClientData( $i, $file );
	    $i++;
	}
    }
}

method init_theme() {
    # Command line always overrides. Once.
    if ( !defined $state{editortheme} && defined $options->{dark} ) {
	$state{editortheme} = $options->{dark} ? "dark" : "light";
    }
    elsif ( $preferences{editortheme} eq "auto" ) {
	if ( Wx::SystemSettings->can("GetAppearance") ) {
	    my $a = Wx::SystemSettings::GetAppearance();
	    if ( $a->IsDark ) {
		$state{editortheme} = "dark";
	    }
	    else {



( run in 0.917 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )