1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
#! perl -- -*- coding: utf-8 -*-
use utf8;
# Author : Johan Vromans
# Created On : Sun Jul 31 23:35:10 2005
# Last Modified By: Johan Vromans
# Last Modified On: Wed Feb 1 14:47:19 2017
# Update Count : 446
# Status : Unknown, Use with caution!
################ Common stuff ################
package main;
our $cfg;
our $app;
use EB::Wx::FakeApp;
package EB::Wx::Shell::Main;
use strict;
use warnings;
use EekBoek;
use EB;
use Getopt::Long 2.13;
################ The Process ################
my $app_dir;
use base qw(Wx::App);
use Wx qw[
wxBITMAP_TYPE_ANY
wxCONFIG_USE_LOCAL_FILE
wxDefaultPosition
wxDefaultSize
wxICON_ERROR
wxOK
];
sub OnInit {
my( $self ) = shift;
return 1;
}
################ Run ################
sub run {
my ( $pkg, $opts ) = @_;
$opts = {} unless defined $opts;
binmode(STDOUT, ":encoding(utf8)");
binmode(STDERR, ":encoding(utf8)");
# Preliminary initialize config.
EB->app_init( { app => $EekBoek::PACKAGE } );
# Command line options.
$opts =
{
#config, # config file
#nostdconf, # skip standard configs
#define, # config overrides
verbose => 0, # verbose processing
# Development options (not shown with -help).
debug => 0, # debugging
trace => 0, # trace (show process)
test => 0, # test mode.
# Let supplied options override.
%$opts,
};
# Process command line options.
app_options($opts);
# Post-processing.
$opts->{trace} |= ($opts->{debug} || $opts->{test});
# Initialize config.
EB->app_init( { app => $EekBoek::PACKAGE, %$opts } );
if ( $opts->{printconfig} ) {
$cfg->printconf( \@ARGV );
exit;
}
$app_dir = $cfg->user_dir;
mkdir($app_dir) unless -d $app_dir;
Wx::InitAllImageHandlers();
if ( $opts->{showhelp} ) {
# Standalone help browser.
require EB::Wx::Help;
my $h = EB::Wx::Help->new(1);
$h->show_html_help;
exit;
}
#### WHAT THE ***** IS GOING ON HERE????
#*Fcntl::O_NOINHERIT = sub() { 0 };
#*Fcntl::O_EXLOCK = sub() { 0 };
#*Fcntl::O_TEMPORARY = sub() { 0 };
if ( ( defined($opts->{wizard}) ? $opts->{wizard} : 1 )
&& !$opts->{config}
) {
require EB::Wx::IniWiz;
EB::Wx::IniWiz->run($opts); # sets $opts->{runeb}
return unless $opts->{runeb};
EB->app_init( { app => $EekBoek::PACKAGE, %$opts } );
}
my $app = EB::Wx::Shell::Main->new();
$app->SetAppName($EekBoek::PACKAGE);
$app->SetVendorName("Squirrel Consultancy");
if ( $^O =~ /^mswin/i ) {
Wx::ConfigBase::Get->SetPath("/ebwxshell");
}
else {
Wx::ConfigBase::Set
(Wx::FileConfig->new
( $app->GetAppName() ,
$app->GetVendorName() ,
$cfg->user_dir("ebwxshell"),
'',
wxCONFIG_USE_LOCAL_FILE,
));
}
my $histfile = $cfg->user_dir("history");
require EB::Wx::Shell::MainFrame;
my $frame = EB::Wx::Shell::MainFrame->new
(undef, undef, $EekBoek::PACKAGE,
wxDefaultPosition, wxDefaultSize,
undef,
$EekBoek::PACKAGE);
my $config = $opts->{config};
unless ( $config ) {
$config = $cfg->std_config;
$config = $cfg->std_config_alt unless -f $config;
}
$frame->{_ebcfg} = $config if -e $config;
$frame->FillHistory($histfile);
$frame->GetPreferences;
Wx::ConfigBase::Get->Write('general/appversion', $EekBoek::VERSION);
my $icon = Wx::Icon->new();
$icon->CopyFromBitmap(Wx::Bitmap->new("eb.jpg", wxBITMAP_TYPE_ANY));
$frame->SetIcon($icon);
$app->SetTopWindow($frame);
$frame->Show(1);
$frame->RunCommand(undef);
$app->MainLoop();
}
# Since Wx::Bitmap cannot be convinced to use a search path, we
# need a stronger method...
my $wxbitmapnew = \&Wx::Bitmap::new;
no warnings 'redefine';
*Wx::Bitmap::new = sub {
# Only handle Wx::Bitmap->new(file, type) case.
goto &$wxbitmapnew if @_ != 3 || -f $_[1];
my ($self, @rest) = @_;
$rest[0] = EB::findlib("Wx/icons/".File::Basename::basename($rest[0]));
$wxbitmapnew->($self, @rest);
};
use warnings 'redefine';
################ Subroutines ################
sub app_options {
my ( $opts ) = @_;
# Filter psn arguments (Mac OSX).
@ARGV = grep { ! /psn_\d_\d+/ } @ARGV;
# Process options, if any.
# Make sure defaults are set before returning!
return unless @ARGV > 0;
# Store valid & trap invalid option warnings
my @optionerrors;
local $SIG{__WARN__} = sub {
my $warning = shift;
push(@optionerrors, $warning);
};
Getopt::Long::Configure(qw(no_ignore_case));
if ( !GetOptions( $opts,
'define|D=s%',
'nostdconf|X',
'config|f=s',
'admdir=s',
'open=s',
'wizard!',
'printconfig|P',
'showhelp',
'ident',
'verbose',
'trace!',
'help|?',
'debug',
) or $opts->{help} )
{
app_usage();
}
app_usage() if @ARGV && !$opts->{printconfig};
app_ident() if $opts->{ident};
return unless @optionerrors;
my $d = Wx::MessageDialog->new ( undef,
join("\n", @optionerrors),
"Opstartregelfouten",
wxICON_ERROR|wxOK,
wxDefaultPosition );
$d->ShowModal;
$d->Destroy;
CORE::exit(2);
}
sub app_ident {
return;
warn(__x("Dit is {pkg} [{name} {version}]",
pkg => $EekBoek::PACKAGE,
name => "WxShell",
version => $EekBoek::VERSION) . "\n");
}
sub app_usage {
my ($exit) = @_;
app_ident();
warn _T(<<EndOfUsage);
Opstartopties:
--showhelp start de documentatiebrowser
--config=XXX -f specificeer configuratiebestand
--nostdconf -X gebruik uitsluitend dit configuratiebestand
--define=XXX -D definieer configuratiesetting
--printconfig -P print config waarden
--admdir=XXX directory voor de config files
--[no]wizard gebruik de aanmaken/selectiewizard
--help deze hulpboodschap
--ident toon identificatie
--verbose geef meer uitgebreide information
EndOfUsage
CORE::exit $exit if defined $exit && $exit != 0;
}
1;
|