File Coverage

lib/Kephra/App/EditPanel/Indicator.pm
Criterion Covered Total %
statement 6 97 6.1
branch 0 20 0.0
condition 0 36 0.0
subroutine 2 34 5.8
pod 0 29 0.0
total 8 216 3.7


line stmt bran cond sub pod time code
1             package Kephra::App::EditPanel::Indicator;
2             $VERSION = '0.01';
3              
4 1     1   1287 use strict;
  1         2  
  1         40  
5 1     1   5 use warnings;
  1         2  
  1         1853  
6              
7 0     0     sub _ref { Kephra::App::EditPanel::_ref() }
8 0     0     sub _all_ref { Kephra::Document::Data::get_all_ep() }
9 0     0     sub _config { Kephra::API::settings()->{editpanel}{indicator} }
10              
11             # aply all indicator setting to this edit panel
12             sub apply_all_here {
13 0   0 0 0   my $ep = shift || _ref();
14 0           my $indicator = _config();
15 0           my $color = \&Kephra::Config::color;
16              
17 0           $ep->SetCaretLineBack( &$color( $indicator->{caret_line}{color} ) );
18 0           $ep->SetCaretPeriod( $indicator->{caret}{period} );
19 0           $ep->SetCaretWidth( $indicator->{caret}{width} );
20 0           $ep->SetCaretForeground( &$color( $indicator->{caret}{color} ) );
21 0 0         if ( $indicator->{selection}{fore_color} ne '-1' ) {
22 0           $ep->SetSelForeground
23             ( 1, &$color( $indicator->{selection}{fore_color} ) );
24             }
25 0           $ep->SetSelBackground( 1, &$color( $indicator->{selection}{back_color}));
26 0           $ep->SetWhitespaceForeground
27             ( 1, &$color( $indicator->{whitespace}{color} ) );
28              
29 0           apply_whitespace_settings_here($ep);
30 0           apply_bracelight_settings_here($ep);
31 0           apply_caret_line_settings_here($ep);
32 0           apply_indention_guide_settings_here($ep);
33 0           apply_LLI_settings_here($ep);
34 0           apply_EOL_settings_here($ep);
35             }
36              
37             # whitespace
38             #
39 0     0 0   sub whitespace_visible { _config()->{whitespace}{visible} }
40             sub apply_whitespace_settings_here {
41 0   0 0 0   my $ep = shift || _ref();
42 0           $ep->SetViewWhiteSpace( whitespace_visible() )
43             }
44             sub apply_whitespace_settings {
45 0     0 0   apply_whitespace_settings_here($_) for @{_all_ref()}
  0            
46             }
47             sub switch_whitespace_visibility {
48 0     0 0   my $v = _config()->{whitespace}{visible} ^= 1;
49 0           apply_whitespace_settings();
50 0           return $v;
51             }
52             # bracelight
53             #
54 0     0 0   sub bracelight_visible { _config()->{bracelight}{visible} }
55             sub switch_bracelight {
56 0 0   0 0   bracelight_visible() ? set_bracelight_off() : set_bracelight_on();
57             }
58             sub set_bracelight_on {
59 0     0 0   _config()->{bracelight}{visible} = 1;
60 0           apply_bracelight_settings()
61             }
62             sub set_bracelight_off {
63 0     0 0   _config()->{bracelight}{visible} = 0;
64 0           apply_bracelight_settings()
65             }#{bracelight}{mode} = 'adjacent'|'surround';
66              
67             sub apply_bracelight_settings {
68 0     0 0   apply_bracelight_settings_here($_) for @{_all_ref()}
  0            
69             }
70             sub apply_bracelight_settings_here {
71 0   0 0 0   my $ep = shift || _ref();
72 0 0         if (bracelight_visible()){
73 0           Kephra::EventTable::add_call
74             ('caret.move', 'bracelight', \&paint_bracelight);
75 0           paint_bracelight($ep);
76             } else {
77 0           Kephra::EventTable::del_call('caret.move', 'bracelight');
78 0           $ep->BraceHighlight( -1, -1 );
79             }
80             }
81              
82             sub paint_bracelight {
83 0   0 0 0   my $ep = shift || _ref();
84 0           my $pos = $ep->GetCurrentPos;
85 0           my $tab_size = Kephra::Document::Data::get_attribute('tab_size');
86 0           my $matchpos = $ep->BraceMatch(--$pos);
87 0 0         $matchpos = $ep->BraceMatch(++$pos) if $matchpos == -1;
88              
89 0           $ep->SetHighlightGuide(0);
90 0 0         if ( $matchpos > -1 ) {
91             # highlight braces
92 0           $ep->BraceHighlight($matchpos, $pos);
93             # asign pos to opening brace
94 0 0         $pos = $matchpos if $matchpos < $pos;
95 0           my $indent = $ep->GetLineIndentation( $ep->LineFromPosition($pos) );
96             # highlighting indenting guide
97 0 0 0       $ep->SetHighlightGuide($indent)
      0        
98             if $indent and $tab_size and $indent % $tab_size == 0;
99             } else {
100             # disbale all highlight
101 0           $ep->BraceHighlight( -1, -1 );
102 0 0         $ep->BraceBadLight($pos-1)
103             if $ep->GetTextRange($pos-1,$pos) =~ /{|}|\(|\)|\[|\]/;
104 0 0 0       $ep->BraceBadLight($pos)
105             if $pos < $ep->GetTextLength
106             and $ep->GetTextRange( $pos, $pos + 1 ) =~ tr/{}()\[\]//;
107             }
108             }
109             # indention guide
110             #
111 0     0 0   sub indention_guide_visible { _config()->{indent_guide}{visible} }
112             sub apply_indention_guide_settings {
113 0     0 0   apply_indention_guide_settings_here($_) for @{_all_ref()}
  0            
114             }
115             sub apply_indention_guide_settings_here {
116 0   0 0 0   my $ep = shift || _ref();
117 0           $ep->SetIndentationGuides( indention_guide_visible() )
118             }
119             sub switch_indention_guide_visibility {
120 0     0 0   _config()->{indent_guide}{visible} ^= 1;
121 0           apply_indention_guide_settings();
122             }
123              
124             # caret line
125             #
126 0     0 0   sub caret_line_visible { _config()->{caret_line}{visible} }
127             sub apply_caret_line_settings_here {
128 0   0 0 0   my $ep = shift || _ref();
129 0           $ep->SetCaretLineVisible( caret_line_visible() );
130             }
131             sub apply_caret_line_settings {
132 0     0 0   apply_caret_line_settings_here($_) for @{_all_ref()}
  0            
133             }
134             sub switch_caret_line_visibility {
135 0     0 0   _config()->{caret_line}{visible} ^= 1;
136 0           apply_caret_line_settings();
137             }
138              
139             # LLI = long line indicator = right margin
140             #
141 0     0 0   sub LLI_visible { _config()->{right_margin}{style} == &Wx::wxSTC_EDGE_LINE }
142             sub apply_LLI_settings_here {
143 0   0 0 0   my $ep = shift || _ref();
144 0           my $config = _config()->{right_margin};
145 0           my $color = \&Kephra::Config::color;
146 0           $ep->SetEdgeColour( &$color( $config->{color} ) );
147 0           $ep->SetEdgeColumn( $config->{position} );
148 0           show_LLI( $config->{style}, $ep);
149             }
150             sub show_LLI {
151 0     0 0   my $style = shift;
152 0   0       my $ep = shift || _ref();
153 0           $ep->SetEdgeMode( $style );
154             }
155 0     0 0   sub apply_LLI_settings { apply_LLI_settings_here($_) for @{_all_ref()} }
  0            
156             sub switch_LLI_visibility {
157 0 0   0 0   my $style = _config()->{right_margin}{style} = LLI_visible()
158             ? &Wx::wxSTC_EDGE_NONE
159             : &Wx::wxSTC_EDGE_LINE;
160 0           apply_LLI_settings($style);
161             }
162              
163             # EOL = end of line marker
164             #
165 0     0 0   sub EOL_visible { _config()->{end_of_line_marker} }
166             sub switch_EOL_visibility {
167 0     0 0   _config()->{end_of_line_marker} ^= 1;
168 0           apply_EOL_settings();
169             }
170 0     0 0   sub apply_EOL_settings { apply_EOL_settings_here($_) for @{_all_ref()} }
  0            
171             sub apply_EOL_settings_here {
172 0   0 0 0   my $ep = shift || _ref();
173 0           $ep->SetViewEOL( EOL_visible() );
174              
175             }
176              
177             1;