From 441c2715bbb50e0063e827ae37c40f58865993d6 Mon Sep 17 00:00:00 2001 From: angel Date: Mon, 20 Apr 2020 21:10:03 +0200 Subject: [PATCH] LibGUI: Add Select all action to TextEditor Previously, TextEditor processed the Select all command directly on the keydown event handler. For this reason, WindowManager would not process it as an action for the focused control and an action with the same keyboard shortcut from the parent could override the TextEditor's one even when it is focused. For instance, when pressing Ctrl+A on the FileManager's path bar, all files were selected instead, which is not the expected behavior. Now the Select all command is an actual action on TextEditor, so that WindowManager can process it correctly before any other actions. I also added an icon for it! --- Base/res/icons/16x16/select-all.png | Bin 0 -> 1311 bytes Libraries/LibGUI/TextEditor.cpp | 8 ++++---- Libraries/LibGUI/TextEditor.h | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 Base/res/icons/16x16/select-all.png diff --git a/Base/res/icons/16x16/select-all.png b/Base/res/icons/16x16/select-all.png new file mode 100644 index 0000000000000000000000000000000000000000..f3f01b3c1820ec876f3892a2f1e5cbd6999e49cb GIT binary patch literal 1311 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!toKUIZ9lmsP~D-;yvr)B1( zDwI?fq$;FVWTr7NRNPuSEpS`222b1l&0Ud9j7|xb9R=s!Buuln_gK62ZEkh-Qw;$p zp-+llU-#Eb|7|`!OXNiNu?bEFJ8C|iOfy+@bKTms$H$Ay&MYldUS4~^=}ExuwbHMy zoS$&IwCR^-eBRR~skb^W3%qYT{&d&#d-JLarHaZXe|{4@>+>dio%DO#d^TVHvGcv? z$q3eOb5x^ct(()|#N8=Nza!_rWw(&YE|rHb=hV)zzBPOKlecSw-}%fdDxb||l&IAb z+_!AbQH@s=04Tf1)EYU(MEEXkUz>tV~x&Sk#( zz=lcP3xXWZI_7+jsQBS~IQ}8Wd2Q#*Mm>gUcSNgH{`lVH-Fj`i-saBgbpq4h?q*9Y zDf-K)%ka>wSW9{T;tPrQXD~;wHyK@$*?1sl+SwyYHFu-)3d$}BKR%hWp6#_2uY&6b zU5++cju{91EH(sYPnE3fc`#XUXX!mXg#$`usaXk+V;JUS?9M+ED7P!@joPt`OahOZ zf)^a@W{SAS{jL93hwYT3o$7*|i-c4?`SgA$D6;VW?K$=8%Ib`Ot1CQcdqIzdcg|n=amlsL zp9`0VX9=v1^C__RTVl*?_*(MFR^bC}+vd*fe6#oM6D#A%I&oYZ7aY6vaLt|0#s%wh zmVP|<&g-3fp2|Pvyl;}0uU`CXk|`~je8+Y>`;}`p`!w?cv17Uzc1KL_s(s3e(#tO?9oi>0X9!2fim?FX6g>t@&SGgjx046)PWZK+ zyI-DiMbby9ilgW3-2V8y?>#g5XP*1J$tP=`{jkVby+M51syjxm##M6rmm9a=+rDXv zYU#=ht*DRN&8^bbn?B5ub4$vykbHfq|5kNvVf3T$vcCn^d-hG*J~1fv@cW!wXD@CL zzjHG=jz7_TUENKYwAB{Q>$9pN`R__shRUbOt6g62Y~ku)-&ZFfZ#(Dj;+Nsxzm2qh zUHEv}vC1OLZvD$}M%xuH7pK(ZzUck%!vD}sp1qyV=R9cs#Q2|kt@#v>`TccU%qH1; zT{_!#?NMQuIx`(M1(mN=9>vmVPIfb=jq}YVsU!!WL>_)20X3y;eml4f803nqaZM_ zdiI@cH`k-qhi>QvnoMfE5+rp&e(Npgf7R3G&pqJC;c$D~L8et&(Y2wXpV*=k=R8`$ z!u~;ap3%z4xyO!~^)YL_)-!SLkbSW%#l@b>SG0OssW`(dEtlwtO1f{{XWra7|Jpef zhCS=~8ETT4@7S%6JeO6wN?TRut-@K!-tyz~pF)%PNc)I$ztaD0e0suYaZkhl9 literal 0 HcmV?d00001 diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp index 967ab401ec..86295b37e1 100644 --- a/Libraries/LibGUI/TextEditor.cpp +++ b/Libraries/LibGUI/TextEditor.cpp @@ -98,6 +98,8 @@ void TextEditor::create_actions() }, this); } + m_select_all_action = Action::create( + "Select all", { Mod_Ctrl, Key_A },Gfx::Bitmap::load_from_file("/res/icons/16x16/select-all.png"), [this](auto&) { select_all(); }, this); } void TextEditor::set_text(const StringView& text) @@ -812,10 +814,6 @@ void TextEditor::keydown_event(KeyEvent& event) } return; } - if (event.modifiers() == Mod_Ctrl && event.key() == KeyCode::Key_A) { - select_all(); - return; - } if (event.alt() && event.shift() && event.key() == KeyCode::Key_S) { sort_selected_lines(); return; @@ -1277,6 +1275,8 @@ void TextEditor::context_menu_event(ContextMenuEvent& event) m_context_menu->add_action(copy_action()); m_context_menu->add_action(paste_action()); m_context_menu->add_action(delete_action()); + m_context_menu->add_separator(); + m_context_menu->add_action(select_all_action()); if (is_multi_line()) { m_context_menu->add_separator(); m_context_menu->add_action(go_to_line_action()); diff --git a/Libraries/LibGUI/TextEditor.h b/Libraries/LibGUI/TextEditor.h index 15bc844973..760c4d4903 100644 --- a/Libraries/LibGUI/TextEditor.h +++ b/Libraries/LibGUI/TextEditor.h @@ -121,6 +121,7 @@ public: Action& paste_action() { return *m_paste_action; } Action& delete_action() { return *m_delete_action; } Action& go_to_line_action() { return *m_go_to_line_action; } + Action& select_all_action() { return *m_select_all_action; } void add_custom_context_menu_action(Action&); @@ -233,6 +234,7 @@ private: RefPtr m_paste_action; RefPtr m_delete_action; RefPtr m_go_to_line_action; + RefPtr m_select_all_action; Core::ElapsedTimer m_triple_click_timer; NonnullRefPtrVector m_custom_context_menu_actions;