Padre-Plugin-Shopify
view release on metacpan or search on metacpan
lib/Padre/Plugin/Shopify.pm view on Meta::CPAN
my $dialog = Wx::DirDialog->new($main, "Select an Empty Directory");
$self->create_shop($dialog->GetPath) if $dialog->ShowModal == Wx::wxID_OK;
}
use List::Util qw(first);
use Cwd 'abs_path';
sub open_shop {
my ($self, $directory) = @_;
eval {
die new Padre::Plugin::Shopify::Exception("Unable to find directory.") unless -d $directory;
my ($setting_file, $manifest_file) = ("$directory/.shopsettings", "$directory/.shopmanifest");
die new Padre::Plugin::Shopify::Exception("Unable to find directory files.") unless -e $setting_file && -e $manifest_file;
my $file_settings = decode_json(read_file($setting_file));
return if first { abs_path($_->directory) eq $directory } $self->projects;
$self->add_project(Padre::Plugin::Shopify::Project->new($self, $directory, $file_settings));
};
if ($@) {
$self->main->info(ref($@) ? $@->error : $@);
}
}
sub create_shop {
my ($self, $directory) = @_;
eval {
die new Padre::Plugin::Shopify::Exception("Unable to find directory.") unless -d $directory;
my ($setting_file, $manifest_file) = ("$directory/.shopsettings", "$directory/.shopmanifest");
die new Padre::Plugin::Shopify::Exception("Found already extant settings files. Not creating.") if -e $setting_file || -e $manifest_file;
my $dialog = Wx::Dialog->new($self->main, -1, "Create Shop", [-1, -1], [-1, -1]);
my $grid = Wx::FlexGridSizer->new( 4, 2, 1, 1);
my ($url_edit, $api_key_edit, $password_edit) = map { Wx::TextCtrl->new( $dialog, -1, '', [-1, -1], [400, -1] ) } 0..2;
my ($url_text, $password_text) = map { Wx::StaticText->new( $dialog, -1, $_ )} ("Shop URL", "Password");
my $api_key_text = Wx::ComboBox->new($dialog, -1, "API Key", [-1, -1], [-1, -1], ["API Key", "Email"]);
my ($okay_button, $cancel_button) = map { Wx::Button->new( $dialog, -1, $_ ) } ("OK", "Cancel");
$grid->Add($_, 0, Wx::wxGROW|Wx::wxALL, 2 ) for($url_text, $url_edit, $api_key_text, $api_key_edit, $password_text, $password_edit, $cancel_button, $okay_button);
$dialog->SetAutoLayout( 1 );
lib/Padre/Plugin/Shopify.pm view on Meta::CPAN
$grid->Fit($dialog);
$grid->SetSizeHints($dialog);
Wx::Event::EVT_BUTTON( $dialog, $okay_button, sub { $dialog->EndModal(Wx::wxID_OK); });
Wx::Event::EVT_BUTTON( $dialog, $cancel_button, sub { $dialog->EndModal(Wx::wxID_CANCEL); });
if ($dialog->ShowModal == Wx::wxID_OK) {
my $settings = { url => $url_edit->GetValue, password => $password_edit->GetValue };
$settings->{api_key} = $api_key_edit->GetValue if $api_key_text->GetValue eq "API Key";
$settings->{email} = $api_key_edit->GetValue if $api_key_text->GetValue eq "Email";
$self->add_project(Padre::Plugin::Shopify::Project->new($self, $directory, $settings));
my %saveSettings = map { $_ => $settings->{$_} } keys(%$settings);
write_file("$directory/.shopsettings", encode_json(\%saveSettings));
}
};
if ($@) {
$self->main->info(ref($@) ? $@->error : $@);
}
}
use Padre::Locale::T;
sub plugin_enable {
my $self = shift;
( run in 1.828 second using v1.01-cache-2.11-cpan-71847e10f99 )