Ticket #815: diff.txt

File diff.txt, 2.8 KB (added by patspam, 4 years ago)

Diff

Line 
1Index: lib/Padre/Wx/Output.pm
2===================================================================
3--- lib/Padre/Wx/Output.pm  (revision 10053)
4+++ lib/Padre/Wx/Output.pm  (working copy)
5@@ -13,7 +13,8 @@
6 use Padre::Wx    ();
7 
8 our $VERSION = '0.53';
9-our @ISA     = 'Wx::TextCtrl';
10+use Wx::RichText;
11+our @ISA     = 'Wx::RichTextCtrl';
12 
13 sub new {
14    my $class = shift;
15@@ -39,6 +40,37 @@
16 
17    # see #351: output should be blank by default at start-up.
18    #$self->AppendText( Wx::gettext('No output') );
19+   
20+   use Padre::Logger;
21+   Wx::Event::EVT_TEXT_URL(
22+       $self,
23+       $self,
24+       sub {
25+           my $self = shift;
26+           my $event = shift;
27+           my $uri_string = $event->GetString or return;
28+           require URI;
29+           require Path::Class;
30+           require Path::Class::URI;
31+           my $uri = URI->new($uri_string) or return;
32+           TRACE(" Detected onclick for URI: $uri") if DEBUG;
33+           
34+           my $file = Path::Class::File->from_uri($uri) or return;
35+           my $path = $file->absolute;
36+           my $line = $uri->fragment || 1;
37+           TRACE(" path: $path") if DEBUG;
38+           TRACE(" line: $line") if DEBUG;
39+           
40+           return unless -e $path;
41+           
42+           $self->main->setup_editor($path);
43+           if ($self->main->current->document->filename eq $path) {
44+               $self->main->current->editor->goto_line_centerize($line - 1);
45+           } else {
46+               TRACE(" Current doc does not match our expectations") if DEBUG;
47+           }
48+       },
49+   );
50 
51    return $self;
52 }
53@@ -194,7 +226,7 @@
54            my $ctrl = $2;
55 
56            # first print the text preceding the control sequence
57-           $self->SUPER::AppendText($1);
58+           $self->_handle_links($1);
59 
60            # split the sequence on ; -- this may be specific to the graphics 'm' sequences, but
61            # we don't handle any others at the moment (see regexp above)
62@@ -257,9 +289,43 @@
63 
64        # the remaining text
65        if ( defined( pos($newtext) ) ) {
66+           $self->_handle_links( substr( $newtext, pos($newtext) ) );
67+       }
68+       unless ($ansi_found) {
69+           $self->_handle_links($newtext);
70+       }
71+   }
72+   
73+   sub _handle_links {
74+       my $self    = shift;
75+       my $newtext = shift;
76+
77+       my $link_found = 0;
78+       while ( $newtext =~ m{ \G (.*?) \s at \s (.*) \s line \s (\d+).$ }xcg ) {
79+           $link_found = 1;
80+           my ($file, $line) = ($2, $3);
81+
82+           # first print the text preceding the link
83+           $self->SUPER::AppendText($1);
84+           $self->SUPER::AppendText(' at ');
85+           
86+           # Turn the filename into a file: uri
87+           $self->BeginURL( "file:$file#$line" );
88+           $self->BeginUnderline;
89+           $self->BeginTextColour($bg_colors->[4]);
90+           $self->AppendText("$file");
91+           $self->EndTextColour;
92+           $self->EndUnderline;
93+           $self->EndURL;
94+           
95+           $self->AppendText(" line $line.");
96+       }
97+
98+       # the remaining text
99+       if ( defined( pos($newtext) ) ) {
100            $self->SUPER::AppendText( substr( $newtext, pos($newtext) ) );
101        }
102-       unless ($ansi_found) {
103+       unless ($link_found) {
104            $self->SUPER::AppendText($newtext);
105        }
106    }