~ubuntu-branches/ubuntu/lucid/padre/lucid

« back to all changes in this revision

Viewing changes to lib/Padre/Wx/Menu/Run.pm

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov
  • Date: 2009-02-18 15:55:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090218155500-verj6agdgojx5ihm
Tags: upstream-0.27.ds1
ImportĀ upstreamĀ versionĀ 0.27.ds1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Padre::Wx::Menu::Run;
 
2
 
 
3
# Fully encapsulated Run menu
 
4
 
 
5
use 5.008;
 
6
use strict;
 
7
use warnings;
 
8
use Padre::Wx       ();
 
9
use Padre::Wx::Menu ();
 
10
use Padre::Current  qw{_CURRENT};
 
11
 
 
12
our $VERSION = '0.27';
 
13
our @ISA     = 'Padre::Wx::Menu';
 
14
 
 
15
 
 
16
 
 
17
 
 
18
 
 
19
#####################################################################
 
20
# Padre::Wx::Menu Methods
 
21
 
 
22
sub new {
 
23
        my $class = shift;
 
24
        my $main  = shift;
 
25
 
 
26
        # Create the empty menu as normal
 
27
        my $self = $class->SUPER::new(@_);
 
28
 
 
29
        # Add additional properties
 
30
        $self->{main} = $main;
 
31
 
 
32
        # Script Execution
 
33
        $self->{run_document} = $self->Append( -1,
 
34
                Wx::gettext("Run Script\tF5")
 
35
        );
 
36
        Wx::Event::EVT_MENU( $main,
 
37
                $self->{run_document},
 
38
                sub {
 
39
                        $_[0]->run_document;
 
40
                },
 
41
        );
 
42
 
 
43
        $self->{run_command} = $self->Append( -1,
 
44
                Wx::gettext("Run Command\tCtrl-F5")
 
45
        );
 
46
        Wx::Event::EVT_MENU( $main,
 
47
                $self->{run_command},
 
48
                sub {
 
49
                        $_[0]->on_run_command;
 
50
                },
 
51
        );
 
52
 
 
53
        $self->AppendSeparator;
 
54
 
 
55
        $self->{stop} = $self->Append( -1,
 
56
                Wx::gettext("&Stop")
 
57
        );
 
58
        Wx::Event::EVT_MENU( $main,
 
59
                $self->{stop},
 
60
                sub {
 
61
                        if ( $_[0]->{command} ) {
 
62
                                $_[0]->{command}->TerminateProcess;
 
63
                        }
 
64
                        delete $_[0]->{command};
 
65
                        return;
 
66
                },
 
67
        );
 
68
 
 
69
        # Initialise enabled
 
70
        $self->enable;
 
71
 
 
72
        return $self;
 
73
}
 
74
 
 
75
sub refresh {
 
76
        my $self     = shift;
 
77
        my $document = _CURRENT(@_)->document;
 
78
 
 
79
        # Disable if not document,
 
80
        # otherwise match run_command state
 
81
        $self->{run_document}->Enable(
 
82
                $document
 
83
                        ? $self->{run_command}->IsEnabled
 
84
                        : 0
 
85
        );
 
86
 
 
87
        return 1;
 
88
}
 
89
 
 
90
 
 
91
 
 
92
 
 
93
 
 
94
#####################################################################
 
95
# Custom Methods
 
96
 
 
97
sub enable {
 
98
        my $self = shift;
 
99
        $self->{run_document}->Enable(1);
 
100
        $self->{run_command}->Enable(1);
 
101
        $self->{stop}->Enable(0);
 
102
        return;
 
103
}
 
104
 
 
105
sub disable {
 
106
        my $self = shift;
 
107
        $self->{run_document}->Enable(0);
 
108
        $self->{run_command}->Enable(0);
 
109
        $self->{stop}->Enable(1);
 
110
        return;
 
111
}
 
112
 
 
113
1;
 
114
# Copyright 2008-2009 The Padre development team as listed in Padre.pm.
 
115
# LICENSE
 
116
# This program is free software; you can redistribute it and/or
 
117
# modify it under the same terms as Perl 5 itself.