57
58
#use constant MAC => !!( $^O eq 'darwin' );
58
59
#use constant UNIX => !( WIN32 or MAC );
60
# Padre targets the three largest Wx backends
64
# The following defined reusable constants for these platforms,
65
# suitable for use in Wx platform-specific adaptation code.
66
# Currently (and a bit naively) we align these to the platforms.
67
# NOTE: They're now in Padre::Constant, if you miss them, please use them from there
68
#use constant WXWIN32 => WIN32;
69
#use constant WXMAC => MAC;
70
#use constant WXGTK => UNIX;
72
61
# The local newline type
73
62
# NOTE: It's now in Padre::Constant, if you miss them, please use it from there
74
63
#use constant NEWLINE => Padre::Constant::WIN32 ? 'WIN' : Padre::Constant::MAC ? 'MAC' : 'UNIX';
549
# Select and focus on the line within the editor provided
550
sub select_line_in_editor {
553
$editor->EnsureVisible($line);
554
$editor->goto_pos_centerize( $editor->GetLineIndentPosition($line) );
562
=head2 C<run_in_directory>
564
Padre::Util::run_in_directory( $command, $directory );
566
Runs the provided C<command> in the C<directory>. On win32 platforms, executes
567
the command to provide *true* background process executions without window
568
popups on each execution. on non-win32 platforms, it runs a C<system>
571
Returns 1 on success and 0 on failure.
573
sub run_in_directory {
574
my ( $cmd, $directory ) = @_;
576
# Make sure we execute from the correct directory
577
if (Padre::Constant::WIN32) {
578
require Padre::Util::Win32;
579
my $retval = Padre::Util::Win32::ExecuteProcessAndWait(
580
directory => $directory,
582
parameters => "/C $cmd",
584
return $retval ? 1 : 0;
587
my $pushd = File::pushd::pushd($directory);
588
my $retval = system $cmd;
589
return ( $retval == 0 ) ? 1 : 0;
595
=head2 C<run_in_directory_two>
597
Plugin replacment for perl command qx{...} to avoid black lines in non *inux os
600
run_in_directory_two('...');
602
optional parameters are dir and return type
604
run_in_directory_two('...', $dir);
605
run_in_directory_two('...', $dir, type);
609
run_in_directory_two('...', type);
611
return type 1 default, returns a string
613
nb you might need to chomp result but thats for you.
615
return type 0 hash_ref
621
Padre::Util::run_in_directory_two('svn --version --quiet');
628
Padre::Util::run_in_directory_two('svn --version --quiet', 0);
632
input "svn --version --quiet",
642
# function Padre::Util::run_in_directory_two
644
sub run_in_directory_two {
645
my $cmd_line = shift;
646
my $location = shift;
647
my $return_option = shift;
649
if ( defined $location ) {
650
if ( $location =~ /\d/ ) {
651
$return_option = $location;
658
$ret_ioe{input} = $cmd_line;
660
$cmd_line =~ m/((?:\w+)\s)/;
663
if ( defined $return_option ) {
664
$return_option = ( $return_option =~ m/[0|1|2]/ ) ? $return_option : 1;
669
# Create a temporary file for standard output redirection
671
my $std_out = File::Temp->new( UNLINK => 1 );
673
# Create a temporary file for standard error redirection
674
my $std_err = File::Temp->new( UNLINK => 1 );
676
my $temp_dir = File::Temp->newdir();
679
if ( defined $location ) {
680
$directory = ($location) ? $location : $temp_dir;
682
$directory = $temp_dir;
687
'1>' . $std_out->filename,
688
'2>' . $std_err->filename,
691
# We need shell redirection (list context does not give that)
692
# Run command in directory
693
Padre::Util::run_in_directory( "@cmd", $directory );
697
# Slurp command standard input and output
698
$ret_ioe{output} = File::Slurp::read_file $std_out->filename;
699
# chomp $ret_ioe{output};
701
# Slurp command standard error
702
$ret_ioe{error} = File::Slurp::read_file $std_err->filename;
703
# chomp $ret_ioe{error};
704
if ( $ret_ioe{error} && ( $return_option eq 1 ) ) {
708
return $ret_ioe{output} if ( $return_option eq 1 );
709
return $ret_ioe{error} if ( $return_option eq 2 );
718
for ( 0 .. $list->GetColumnCount - 1 ) {
719
$list->SetColumnWidth( $_, Wx::LIST_AUTOSIZE_USEHEADER() );
720
my $header_width = $list->GetColumnWidth($_);
721
$list->SetColumnWidth( $_, Wx::LIST_AUTOSIZE() );
722
my $column_width = $list->GetColumnWidth($_);
723
$list->SetColumnWidth( $_, ( $header_width >= $column_width ) ? $header_width : $column_width );