Ticket #693: padre

File padre, 4.9 KB (added by nferraz, 5 years ago)

padre laucher script

Line 
1#!/usr/bin/perl
2
3eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
4  if 0;    # not running under some shell
5
6use 5.008005;
7use strict;
8use warnings;
9
10BEGIN {
11    # use local::lib if available
12    my ($HOME) = $ENV{HOME} =~ /^([\w\/]+)$/;
13    if ( $HOME and -d "$HOME/perl5/lib/perl5" ) {
14        eval("use lib '$HOME/perl5/lib/perl5'");
15    }
16}
17
18use File::Which  ();
19use Getopt::Long ();
20use Carp         ();
21use Pod::Usage   ();
22
23$| = 1;
24
25if ( $ENV{PADRE_DIE} ) {
26    $SIG{__DIE__} = sub { print STDERR Carp::longmess "\nDIE: @_\n" . ( "-" x 80 ) . "\n" };
27}
28
29# Must run using wxPerl on OS X.
30if ( $^O eq 'darwin' and $^X !~ m{/wxPerl\.app/} ) {
31    _spawn_wx_perl();
32    exit(0);
33}
34
35# Handle special command line cases early, because options like --home
36# MUST be processed before the Padre.pm library is loaded.
37
38my $USAGE   = '';
39my $VERSION = '';
40my $HOME    = undef;
41my $SESSION = undef;
42my $DESKTOP = undef;
43
44my $getopt = Getopt::Long::GetOptions(
45    'help'      => \$USAGE,
46    'home=s'    => \$HOME,
47    'session=s' => \$SESSION,
48    'desktop'   => \$DESKTOP,
49    'version'   => \$VERSION,
50);
51
52if ( $USAGE or !$getopt ) {
53    Pod::Usage::pod2usage(1);
54}
55
56if ( defined $HOME ) {
57    $ENV{PADRE_HOME} = $HOME;
58}
59
60require threads;
61require threads::shared;
62
63$ENV{PADRE_PAR_PATH} = $ENV{PAR_TEMP} || '';
64
65my %opts = (
66    files   => \@ARGV,
67    session => $SESSION,
68);
69
70require Padre;
71
72if ($VERSION) {
73    _print_version();
74    exit(0);
75}
76elsif ($DESKTOP) {
77    _desktop_integration();
78    exit(1);
79}
80
81my $app = Padre->new(%opts);
82
83if ( !$app ) {
84
85    # Single instance worked correctly
86    exit(0);
87}
88
89# Start the application
90$app->run;
91
92sub _print_version {
93    my $msg = "Perl Application Development and Refactoring Environment $Padre::VERSION\n";
94    if ( $^O eq 'MSWin32' and $^X =~ /wperl\.exe/ ) {
95
96        # Under wperl, there is no console so we will use
97        # a message box
98        require Padre::Wx;
99        Wx::MessageBox( $msg, Wx::gettext("Version"), Wx::wxOK(), );
100    }
101    else {
102        print $msg;
103    }
104}
105
106sub _desktop_integration {
107    if ( $^O eq 'MSWin32' ) {
108
109        # Integrate with registry via regedit...
110        # VBScript and registry on vista = Does not work!
111        my ( $reg, $regfile ) = File::Temp::tempfile( SUFFIX => '.reg' );
112        print $reg <<'REG';
113Windows Registry Editor Version 5.00
114
115[HKEY_CLASSES_ROOT\*\shell\Edit with Padre]
116
117[HKEY_CLASSES_ROOT\*\shell\Edit with Padre\Command]
118@="c:\\strawberry\\perl\\bin\\padre.exe \"%1\""
119REG
120        close $reg;
121
122        # Create Padre's Desktop Shortcut
123        require File::Temp;
124        my ( $vbs, $vbsfile ) = File::Temp::tempfile( SUFFIX => '.vbs' );
125        print $vbs <<'CODE';
126' Create a Padre shortcut on the current user's desktop
127Set shell = CreateObject("WScript.Shell")
128desktop = shell.SpecialFolders("Desktop")
129Set shortcut = shell.CreateShortcut(desktop & "\Padre.lnk")
130shortcut.Description = "Padre - The Perl IDE"
131shortcut.TargetPath = "C:\strawberry\perl\bin\padre.exe"
132shortcut.WorkingDirectory = "c:\strawberry\perl\bin"
133shortcut.Save
134MsgBox "Padre has created a shortcut on your desktop", vbOKOnly Or vbInformation, "Information"
135CODE
136
137        print $vbs <<"CODE";
138' Now adding "Edit with Padre" to shell context menu
139shell.Run("regedit.exe /S ""$regfile"""), 1, true
140MsgBox """Edit with Padre"" has been added to your right click menu", vbOKOnly Or vbInformation, "Confirmation"
141CODE
142        close $vbs;
143        system(qq{wscript "$vbsfile"});
144
145    }
146    elsif ( ( $^O =~ /linux|bsd/i ) ) {
147
148        # Create Padre.desktop launcher on KDE/gnome
149        my $filename = "$ENV{HOME}/Desktop/Padre.desktop";
150        open my $fh, ">", $filename
151          or die "Cannot create $filename: $!\n";
152        require Padre::Util;
153        my $logo = Padre::Util::sharedir('icons/padre/64x64/logo.png');
154        print $fh <<"DESKTOP";
155[Desktop Entry]
156Name=Padre
157Comment=Padre - The Perl IDE
158Exec=/usr/local/bin/padre
159Icon=$logo
160Terminal=false
161Type=Application
162Categories=Development;Utility;
163MimeType=text/plain;application/x-perl;application/x-perl6;
164DESKTOP
165        close $fh;
166    }
167    else {
168        warn "--desktop not implemented for " . $^O . "\n";
169    }
170}
171
172sub _spawn_wx_perl {
173    my $perl = scalar File::Which::which('wxPerl');
174    chomp($perl);
175
176    if ( -e $perl ) {
177        warn "spawning 'wxPerl' interpreter for OS X\n";
178        system( $perl, '-S', $0, @ARGV );
179    }
180    else {
181        warn "padre cannot find wxPerl executable (which it requires on OS X)\n";
182    }
183
184    exit 0;
185}
186
187__END__
188
189=head1 NAME
190
191padre - the perl IDE
192
193=head1 SYNOPSIS
194
195    padre [options] [filenames]
196
197=head2 OPTIONS
198
199=over
200
201=item --home=dir
202
203Forces Padre's "home" directory to a specific location
204
205=item --help
206
207Shows this help message
208
209=item --session=name
210
211Open given session during Padre startup
212
213=item --version
214
215Prints Padre version and quits
216
217=back
218
219=head1 COPYRIGHT
220
221Copyright 2008-2009 The Padre development team as listed in Padre.pm.
222
223=head1 LICENSE
224
225This program is free software; you can redistribute it and/or
226modify it under the same terms as Perl 5 itself.