lib/Kephra/App/Window/Menu.pm

filter: Statementstmt 75.0% 6 / 8 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 81.8% 9 / 11 CC 1 SCAR 0.9
CC
1
Cov
75%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« lib/Kephra/App/SearchBar.pm ↑ Summary lib/Kephra/App/Window.pm »
1 1 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 0 ▶use Wx;
Subroutine BEGIN: called CC=1 SCAR=2.6
4  
5 package Kephra::App::Window::Menu;
6  
7 my $edit;
8  
9 sub mount {
10 my ($win) = @_;
11 my $ed = $win->{'editor'};
12  
13 $win->{'file_menu'} = my $file_menu = Wx::Menu->new();
14 $file_menu->Append( 11100, "&New\tCtrl+N", "create new empty document" );
15 $file_menu->AppendSeparator();
16 $file_menu->Append( 11200, "&Open\tCtrl+O", "create document by loading a given (dialog) file" );
17 $file_menu->Append( 11210, "&Reload\tCtrl+Shift+O", "disregard current state of document and laod associated file" );
18 $file_menu->AppendSeparator();
19 $file_menu->Append( 11400, "&Save\tCtrl+S", "save current sate of document into associated file" );
20 $file_menu->Append( 11500, "Save &As\tCtrl+Shift+S", "save document into different file, which will be the new associated file" );
21 $file_menu->Append( 11600, "Save &Under\tAlt+Shift+S", "save document into different file, but keep the old associated file" );
22 $file_menu->AppendSeparator();
23 $file_menu->Append( 11900, "&Quit\tCtrl+Q", "close program" );
24 $file_menu->Append( 11910, "No Ask Qui&t\tCtrl+Shift+Q", "close program without file dialog" );
25  
26 my $edit_menu = Wx::Menu->new();
27 $edit_menu->Append( 12110, "&Undo\tCtrl+Z", "undo last text change" );
28 $edit_menu->Append( 12120, "&Redo\tCtrl+Y", "undo last undo" );
29 $edit_menu->Append( 12130, "&fast Undo\tCtrl+Shift+Z", "undo last five changes" );
30 $edit_menu->Append( 12140, "f&ast Redo\tCtrl+Shift+Y", "undo last five undo" );
31 $edit_menu->Append( 12150, "&total Undo\tAlt+Shift+Z", "undo all changes" );
32 $edit_menu->Append( 12160, "t&otal Redo\tAlt+Shift+Y", "redo all changes" );
33 $edit_menu->AppendSeparator();
34 $edit_menu->Append( 12200, "&Cut\tCtrl+X", "delete selected text and move it into clipboard" );
35 $edit_menu->Append( 12210, "Cop&y\tCtrl+C", "move selected text into clipboard" );
36 $edit_menu->Append( 12220, "&Paste\tCtrl+V", "insert clipboard content at cursor position" );
37 $edit_menu->Append( 12230, "S&wap\tCtrl+Shift+V", "replace selected text with clipboard content" );
38 $edit_menu->Append( 12240, "De&lete\tDel", "delete selected text" );
39 $edit_menu->Append( 12310, "Del&ete Row\tAlt+Del", "delete row of caret location" );
40 $edit_menu->AppendSeparator();
41 $edit_menu->Append( 12410, "&Grow Selection\tCtrl+A", "select entire text" );
42 $edit_menu->Append( 12420, "&Shrink Selection\tCtrl+Shift+A", "select entire text" );
43 $edit_menu->AppendSeparator();
44 $edit_menu->Append( 12510, "&Duplicate\tCtrl+D", "copy and paste selected text or current line" );
45  
46 my $format_menu = Wx::Menu->new();
47 $format_menu->Append( 13100, "Move &Left\tAlt+Left", "move current line or selected lines one character to the left" );
48 $format_menu->Append( 13110, "Move &Right\tAlt+Right","move current line or selected lines one character to right" );
49 $format_menu->Append( 13120, "Move &Up\tAlt+Up", "move current line or selected lines one row up" );
50 $format_menu->Append( 13130, "Move &Down\tAlt+Down", "move current line or selected lines one row down" );
51 $format_menu->AppendSeparator();
52 $format_menu->Append( 13200, "&Indent\tTab", "move current line or selected block one tab to right" );
53 $format_menu->Append( 13210, "D&edent\tShift+Tab", "move current line or selected block one tab to left" );
54 $format_menu->AppendSeparator();
55 $format_menu->Append( 13300, "&Block Comment\tCtrl+K", "insert or remove (toggle) script comment with #~" );
56 $format_menu->Append( 13310, "&Comment\tCtrl+Shift+K", "insert or remove (toggle) script comment with #" );
57  
58 my $search_menu = Wx::Menu->new();
59 $search_menu->Append( 14110, "&Find\tCtrl+F", "enter search phrase into search bar" );
60 $search_menu->Append( 14120, "Find &Prev\tShift+F3", "jump to previous match of search term" );
61 $search_menu->Append( 14130, "Find &Next\tF3", "jump to next match of search text" );
62 $search_menu->AppendSeparator();
63 $search_menu->Append( 14210, "&Replace\tCtrl+Shift+F", "enter replace term into replace bar" );
64 $search_menu->Append( 14220, "Replace Pre&v\tAlt+Shift+F3", "replace selection and go to previous match" );
65 $search_menu->Append( 14230, "Replace Ne&xt\tAlt+F3", "replace selection and go to next match" );
66 $search_menu->Append( 14240, "Replace In &Selection\tAlt+Shift+F", "replace all search term matches inside selected text" );
67 $search_menu->Append( 14250, "Replace &All\tAlt+F", "replace all search term matches in the document" );
68 $search_menu->AppendSeparator();
69 $search_menu->Append( 14310, "&Toggle Marker\tCtrl+M", "set or remove marker on current line" );
70 $search_menu->Append( 14320, "Prev Mar&ker\tShift+F2", "jump to previous marked line above current caret position " );
71 $search_menu->Append( 14330, "Next &Marker\tF2", "jump to next marked line below current caret position" );
72 $search_menu->Append( 14340, "&Delete All Marker\tCtrl+Shift+M", "remove all marker" );
73 $search_menu->AppendSeparator();
74 $search_menu->Append( 14400, "&Goto Edit\tCtrl+E", "move cursor position of last change" );
75  
76 my $doc_menu = Wx::Menu->new();
77 $doc_menu->AppendCheckItem( 15100, "&Soft Tabs", "several space characters (see below) will inserted instead of one tab character" );
78 $doc_menu->Check(15100, 1);
79 my $doc_tab_menu = Wx::Menu->new();
80 my @tab_range = 1..10;
81 $doc_tab_menu->AppendRadioItem( 15200+$_, $_ , ) for @tab_range;
82 $doc_tab_menu->Check(15204, 1);
83 $doc_menu->Append( 15200, '&Indention Size', $doc_tab_menu, 'size of tab character' );
84 $doc_menu->AppendSeparator();
85 my $doc_eol_menu = Wx::Menu->new();
86 $doc_eol_menu->AppendRadioItem( 15411, '&Linux (LF)', 'use only LF as line end character and convert all line endings to it' );
87 $doc_eol_menu->AppendRadioItem( 15412, '&Mac (CR)', 'use only CR as line end character and convert all line endings to it' );
88 $doc_eol_menu->AppendRadioItem( 15413, '&Windows (CR+LF)', 'use CR and LF combination as line end character and convert all line endings to it' );
89 $doc_menu->Check(15410, 1);
90 $doc_menu->Append( 15400, '&Line Ending', $doc_eol_menu, '' );
91 my $doc_encoding_menu = Wx::Menu->new();
92 $doc_encoding_menu->AppendRadioItem( 15601, 'ASCII' );
93 $doc_encoding_menu->AppendRadioItem( 15602, 'UTF-8' );
94 $doc_encoding_menu->AppendRadioItem( 15603, 'UTF-16' );
95 $doc_encoding_menu->AppendRadioItem( 15604, 'Latin 1' );
96 $doc_encoding_menu->AppendRadioItem( 15605, 'Latin 2' );
97 $doc_encoding_menu->AppendRadioItem( 15606, 'Latin 3' );
98 $doc_encoding_menu->AppendRadioItem( 15607, 'Latin 4' );
99 $doc_encoding_menu->AppendRadioItem( 15608, 'Cyrillic' );
100 # $doc_menu->Check(15601, 1);
101 # $doc_menu->Append( 15600, '&Encoding', $doc_encoding_menu, '' );
102 #my $doc_mode_menu = Wx::Menu->new();
103 #my @mode_label = (qw/no Bash C\/++ JSON Markdown Perl Python Ruby Rust YAML/);
104 #my @modes = (qw/no bash cpp json markdown perl python ruby rust yaml/);
105 #$doc_mode_menu->AppendRadioItem( 15701+$_, $mode_label[$_] ) for 0 .. $#mode_label;
106 #$doc_menu->Append( 15700, '&Syntax Mode', $doc_mode_menu, '' );
107 #$doc_menu->Check(15706, 1);
108  
109 my @zoom_range = -10 .. 25;
110 my $zoom_menu = Wx::Menu->new();
111 $zoom_menu->Append( 16310, "Zoom &In\tCtrl+-", 'increase zoom level' );
112 $zoom_menu->Append( 16320, "Zoom &Out\tCtrl++", 'decrease zoom level ' );
113 $zoom_menu->AppendSeparator();
114 $zoom_menu->AppendRadioItem( 16340+$_, "Zoom Level ".$_, 'set zoom level to '.$_ ) for @zoom_range;
115  
116 my $view_menu = Wx::Menu->new();
117 $view_menu->AppendCheckItem( 16430, "&Caret Line", "make current row (line) with caret (curso) extra visible by color" );
118 $view_menu->AppendCheckItem( 16120, "&EOL Marker", "show symbols marking the otherwise invisible end of line characters" );
119 $view_menu->AppendCheckItem( 16110, "&Whitespace", "make white space and tabs visible by dots and arrows" );
120 $view_menu->AppendCheckItem( 16130, "&Indent Guide", "vertical lines on top of space at tab size distance" );
121 $view_menu->AppendCheckItem( 16140, "&Right Margin", "vertical line at the 80 (changeable) character mark" );
122 $view_menu->AppendSeparator();
123 $view_menu->AppendCheckItem( 16210, "&Line Number Margin", "make line numbers visible or not" );
124 $view_menu->AppendCheckItem( 16220, "&Marker Margin", "make marker margin (right beside line number) visible or not" );
125 $view_menu->AppendSeparator();
126 $view_menu->AppendCheckItem( 16420, "Line Wra&p", "break up lines so they fit the window" );
127 $view_menu->Append( 16300, '&Zoom', $zoom_menu, '' );
128 $view_menu->AppendCheckItem( 16410, "&Fullscreen\tF11", "switches to or from fullscreen mode" );
129 $view_menu->Check(16110, 1);
130 $view_menu->Check(16130, 1);
131 $view_menu->Check(16140, 1);
132 $view_menu->Check(16210, 1);
133 $view_menu->Check(16220, 1);
134 $zoom_menu->Check(16340, 1);
135 $view_menu->Check(16430, 1);
136  
137 my $help_menu = Wx::Menu->new();
138 #$help_menu->Append( 15100, "&Usage", "Explaining the user interface" );
139 #$help_menu->Append( 15200, "&Keymap\tAlt+K", "listings with all key kombination from all widgets" );
140 $help_menu->Append( 17500, "&About", "Dialog with some general information" );
141  
142 my $menu_bar = Wx::MenuBar->new();
143 $menu_bar->Append( $file_menu, '&File' );
144 $menu_bar->Append( $edit_menu, '&Edit' );
145 $menu_bar->Append( $format_menu, 'F&ormat' );
146 $menu_bar->Append( $search_menu, '&Search' );
147 $menu_bar->Append( $doc_menu, '&Document' );
148 $menu_bar->Append( $view_menu, '&View' );
149 $menu_bar->Append( $help_menu, '&Help' );
150 $win->SetMenuBar($menu_bar);
151 update_recent_files_menu( $win );
152  
153 Wx::Event::EVT_MENU( $win, 11100, sub { $win->new_file });
154 Wx::Event::EVT_MENU( $win, 11200, sub { $win->open_file });
155 Wx::Event::EVT_MENU( $win, 11210, sub { $win->reopen_file });
156 Wx::Event::EVT_MENU( $win, 11400, sub { $win->save_file });
157 Wx::Event::EVT_MENU( $win, 11500, sub { $win->save_as_file });
158 Wx::Event::EVT_MENU( $win, 11600, sub { $win->save_under_file });
159 Wx::Event::EVT_MENU( $win, 11900, sub { $win->Close });
160 Wx::Event::EVT_MENU( $win, 11910, sub { $win->{'dontask'} = 1; $win->Close });
161 Wx::Event::EVT_MENU( $win, 12110, sub { $ed->Undo });
162 Wx::Event::EVT_MENU( $win, 12120, sub { $ed->Redo });
163 Wx::Event::EVT_MENU( $win, 12130, sub { $ed->fast_undo });
164 Wx::Event::EVT_MENU( $win, 12140, sub { $ed->fast_redo });
165 Wx::Event::EVT_MENU( $win, 12150, sub { $ed->total_undo });
166 Wx::Event::EVT_MENU( $win, 12160, sub { $ed->total_redo });
167 Wx::Event::EVT_MENU( $win, 12200, sub { $ed->cut });
168 Wx::Event::EVT_MENU( $win, 12210, sub { $ed->copy });
169 Wx::Event::EVT_MENU( $win, 12220, sub { $ed->Paste });
170 Wx::Event::EVT_MENU( $win, 12230, sub { $ed->replace });
171 Wx::Event::EVT_MENU( $win, 12240, sub { $ed->Clear });
172 Wx::Event::EVT_MENU( $win, 12410, sub { $ed->expand_selecton });
173 Wx::Event::EVT_MENU( $win, 12420, sub { $ed->shrink_selecton });
174 Wx::Event::EVT_MENU( $win, 12510, sub { $ed->duplicate });
175 Wx::Event::EVT_MENU( $win, 13100, sub { $ed->move_left });
176 Wx::Event::EVT_MENU( $win, 13110, sub { $ed->move_right });
177 Wx::Event::EVT_MENU( $win, 13120, sub { $ed->move_up });
178 Wx::Event::EVT_MENU( $win, 13130, sub { $ed->move_down });
179 Wx::Event::EVT_MENU( $win, 13300, sub { $ed->toggle_block_comment });
180 Wx::Event::EVT_MENU( $win, 13310, sub { $ed->toggle_comment });
181 Wx::Event::EVT_MENU( $win, 14110, sub { $win->{'searchbar'}->enter });
182 Wx::Event::EVT_MENU( $win, 14120, sub { $win->{'searchbar'}->find_prev });
183 Wx::Event::EVT_MENU( $win, 14130, sub { $win->{'searchbar'}->find_next });
184 Wx::Event::EVT_MENU( $win, 14210, sub { $win->{'replacebar'}->enter });
185 Wx::Event::EVT_MENU( $win, 14220, sub { $win->{'replacebar'}->replace_prev });
186 Wx::Event::EVT_MENU( $win, 14230, sub { $win->{'replacebar'}->replace_next });
187 Wx::Event::EVT_MENU( $win, 14240, sub { $win->{'replacebar'}->replace_in_selection });
188 Wx::Event::EVT_MENU( $win, 14250, sub { $win->{'replacebar'}->replace_all });
189 Wx::Event::EVT_MENU( $win, 14310, sub { $ed->marker_toggle });
190 Wx::Event::EVT_MENU( $win, 14320, sub { $ed->marker_prev });
191 Wx::Event::EVT_MENU( $win, 14330, sub { $ed->marker_next });
192 Wx::Event::EVT_MENU( $win, 14310, sub { $ed->toggle_marker });
193 Wx::Event::EVT_MENU( $win, 14340, sub { $ed->delete_all_marker });
194 Wx::Event::EVT_MENU( $win, 14320, sub { $ed->goto_prev_marker });
195 Wx::Event::EVT_MENU( $win, 14330, sub { $ed->goto_next_marker });
196 Wx::Event::EVT_MENU( $win, 14400, sub { $ed->goto_last_edit });
197 Wx::Event::EVT_MENU( $win, 15100, sub { $ed->toggle_tab_usage });
198 Wx::Event::EVT_MENU( $win, 15200 + $_, eval 'sub { $ed->set_tab_size('.$_.')}') for @tab_range;
199 Wx::Event::EVT_MENU( $win, 15411, sub { $ed->set_EOL_lf });
200 Wx::Event::EVT_MENU( $win, 15412, sub { $ed->set_EOL_cr });
201 Wx::Event::EVT_MENU( $win, 15413, sub { $ed->set_EOL_crlf });
202 #Wx::Event::EVT_MENU( $win, 15701 + $_, eval 'sub { Kephra::App::Editor::SyntaxMode::set($win->{editor},"'.$modes[$_].'")}') for 0 .. $#modes;
203 Wx::Event::EVT_MENU( $win, 16110, sub { $ed->toggle_view_whitespace });
204 Wx::Event::EVT_MENU( $win, 16120, sub { $ed->toggle_view_eol });
205 Wx::Event::EVT_MENU( $win, 16130, sub { $ed->toggle_view_indent_guide });
206 Wx::Event::EVT_MENU( $win, 16140, sub { $ed->toggle_view_right_margin });
207 Wx::Event::EVT_MENU( $win, 16210, sub { $ed->toggle_view_line_nr_margin });
208 Wx::Event::EVT_MENU( $win, 16220, sub { $ed->toggle_view_marker_margin });
209 Wx::Event::EVT_MENU( $win, 16310, sub { $ed->zoom_in });
210 Wx::Event::EVT_MENU( $win, 16320, sub { $ed->zoom_out });
211  
212 Wx::Event::EVT_MENU( $win, 16340 + $_, eval 'sub { $win->{editor}->set_zoom_level('.$_.')}') for @zoom_range;
213 Wx::Event::EVT_MENU( $win, 16410, sub { $win->toggle_full_screen });
214 Wx::Event::EVT_MENU( $win, 16420, sub { $win->{'editor'}->toggle_view_line_wrap });
215 Wx::Event::EVT_MENU( $win, 16430, sub { $win->{'editor'}->toggle_view_caret_line });
216 # Wx::Event::EVT_MENU( $win, 15100, sub { Kephra::App::Dialog::documentation( $win ) });
217 # Wx::Event::EVT_MENU( $win, 15200, sub { Kephra::App::Dialog::keymap($win) });
218 Wx::Event::EVT_MENU( $win, 17500, sub { Kephra::App::Dialog::about( $win) });
219 }
220  
221 sub update_recent_files_menu {
222 my ($win, $closed_file) = @_;
223 my $recent_files = $win->config->get_value('file', 'closed');
224 return unless ref $recent_files eq 'ARRAY';
225 if (defined $closed_file and $closed_file){
226 unshift @$recent_files, $closed_file;
227 for my $i (reverse 1 .. $#$recent_files){
228 splice( @$recent_files, $i, 1) if $recent_files->[$i] eq $closed_file;
229 }
230 }
231 my $start_menu_ID = 11300;
232 $win->{'file_menu'}->Destroy( $start_menu_ID );
233 my $Recent_ID = $start_menu_ID + 1;
234 $win->{'recent_menu'} = Wx::Menu->new();
235 for my $path (@$recent_files){
236 $win->{'recent_menu'}->Append($Recent_ID, $path);
237 Wx::Event::EVT_MENU( $win, $Recent_ID++, sub { $win->read_file( $path ) });
238 }
239 $win->{'file_menu'}->Insert( 4, $start_menu_ID, '&Closed', $win->{'recent_menu'}, 'reopen recently closed files' );
240 }
241  
242  
243 sub edit_context { $edit }
244  
245  
246 1;
« lib/Kephra/App/SearchBar.pm ↑ Summary lib/Kephra/App/Window.pm »