Patch: Keyboard shortcut (accelerator) for "select next"

Discussion about CodeLite development process and patches
User avatar
caibbor
CodeLite Veteran
Posts: 78
Joined: Thu Jan 10, 2013 10:37 pm
Genuine User: Yes
IDE Question: c++
Contact:

Patch: Keyboard shortcut (accelerator) for "select next"

Post by caibbor »

I've added a menu option and a keyboard shortcut (accelerator) for my beloved feature "select next" (which was recently added as "find next" with multiple selection in this github feature request. This is quite similar to CodeBlock's CTRL+E "select next" feature.

Expect to see more patch submissions from me in the future (:

PS, I'm not terribly familiar with git (I'm a svn guy) so I'm not sure how to get the current "revision number" if such a thing exists. my copy of CL from git is up to date as of this post.

Code: Select all

diff --git a/LiteEditor/frame.cpp b/LiteEditor/frame.cpp
index 502d1fd..9f23008 100644
--- a/LiteEditor/frame.cpp
+++ b/LiteEditor/frame.cpp
@@ -340,6 +340,8 @@ BEGIN_EVENT_TABLE(clMainFrame, wxFrame)
 
     EVT_UPDATE_UI(wxID_FIND,                        clMainFrame::OnIncrementalSearchUI )
     EVT_UPDATE_UI(wxID_REPLACE,                     clMainFrame::OnFileExistUpdateUI   )
+    EVT_UPDATE_UI(XRCID("select_previous"),         clMainFrame::OnFileExistUpdateUI   )
+    EVT_UPDATE_UI(XRCID("select_next"),             clMainFrame::OnFileExistUpdateUI   )
     EVT_UPDATE_UI(XRCID("find_next"),               clMainFrame::OnFileExistUpdateUI   )
     EVT_UPDATE_UI(XRCID("find_previous"),           clMainFrame::OnFileExistUpdateUI   )
     EVT_UPDATE_UI(XRCID("find_next_at_caret"),      clMainFrame::OnFileExistUpdateUI   )
diff --git a/LiteEditor/quickfindbar.cpp b/LiteEditor/quickfindbar.cpp
index fd7309a..f32534e 100644
--- a/LiteEditor/quickfindbar.cpp
+++ b/LiteEditor/quickfindbar.cpp
@@ -79,6 +79,8 @@ QuickFindBar::QuickFindBar(wxWindow* parent, wxWindowID id)
     wxTheApp->Connect(wxID_COPY,      wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuickFindBar::OnEditUI), NULL, this);
     wxTheApp->Connect(wxID_PASTE,     wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuickFindBar::OnEditUI), NULL, this);
     wxTheApp->Connect(wxID_SELECTALL, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuickFindBar::OnEditUI), NULL, this);
+    wxTheApp->Connect(XRCID("select_previous"),        wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnSelectPrevious),          NULL, this);
+    wxTheApp->Connect(XRCID("select_next"),            wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnSelectNext),          NULL, this);
     wxTheApp->Connect(XRCID("find_next"),              wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnFindNext),          NULL, this);
     wxTheApp->Connect(XRCID("find_previous"),          wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnFindPrevious),      NULL, this);
     wxTheApp->Connect(XRCID("find_next_at_caret"),     wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnFindNextCaret),     NULL, this);
@@ -536,6 +538,34 @@ void QuickFindBar::OnFindPrevious(wxCommandEvent& e)
     DoSearch(false, false);
 }
 
+void QuickFindBar::OnSelectPrevious(wxCommandEvent& e)
+{
+    CHECK_FOCUS_WIN();
+
+    // Highlighted text takes precedence over the current search string
+    wxString selectedText = DoGetSelectedText();
+    if (selectedText.IsEmpty() == false) {
+        m_findWhat->ChangeValue(selectedText);
+        m_findWhat->SelectAll();
+    }
+
+    DoSearch(false, false, true);
+}
+
+void QuickFindBar::OnSelectNext(wxCommandEvent& e)
+{
+    CHECK_FOCUS_WIN();
+
+    // Highlighted text takes precedence over the current search string
+    wxString selectedText = DoGetSelectedText();
+    if (selectedText.IsEmpty() == false) {
+        m_findWhat->ChangeValue( selectedText );
+        m_findWhat->SelectAll();
+    }
+
+    DoSearch(true, false, true);
+}
+
 void QuickFindBar::OnFindNextCaret(wxCommandEvent& e)
 {
     CHECK_FOCUS_WIN();
@@ -718,6 +748,8 @@ QuickFindBar::~QuickFindBar()
     wxTheApp->Disconnect(wxID_COPY,      wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuickFindBar::OnEditUI), NULL, this);
     wxTheApp->Disconnect(wxID_PASTE,     wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuickFindBar::OnEditUI), NULL, this);
     wxTheApp->Disconnect(wxID_SELECTALL, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuickFindBar::OnEditUI), NULL, this);
+    wxTheApp->Disconnect(XRCID("select_previous"),        wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnSelectPrevious),          NULL, this);
+    wxTheApp->Disconnect(XRCID("select_next"),            wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnSelectNext),          NULL, this);
     wxTheApp->Disconnect(XRCID("find_next"),              wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnFindNext),          NULL, this);
     wxTheApp->Disconnect(XRCID("find_previous"),          wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnFindPrevious),      NULL, this);
     wxTheApp->Disconnect(XRCID("find_next_at_caret"),     wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnFindNextCaret),     NULL, this);
diff --git a/LiteEditor/quickfindbar.h b/LiteEditor/quickfindbar.h
index a8da969..e8bc48e 100644
--- a/LiteEditor/quickfindbar.h
+++ b/LiteEditor/quickfindbar.h
@@ -76,6 +76,8 @@ protected:
     void OnReceivingFocus(wxFocusEvent& event);
     void OnReleaseEditor(wxCommandEvent &e);
 
+    void OnSelectPrevious   (wxCommandEvent &e);
+    void OnSelectNext       (wxCommandEvent &e);
     void OnFindNext         (wxCommandEvent &e);
     void OnFindPrevious     (wxCommandEvent &e);
     void OnFindNextCaret    (wxCommandEvent &e);
diff --git a/Runtime/rc/menu.xrc b/Runtime/rc/menu.xrc
index a672b63..b125ac4 100644
--- a/Runtime/rc/menu.xrc
+++ b/Runtime/rc/menu.xrc
@@ -292,6 +292,12 @@
             <object class="wxMenuItem" name="wxID_REPLACE">
                 <label>&Replace...</label>
             </object>
+            <object class="wxMenuItem" name="select_previous">
+                <label>Select Previous Occu&rrence</label>
+            </object>
+            <object class="wxMenuItem" name="select_next">
+                <label>Select Next &Occurrence</label>
+            </object>
             <object class="wxMenuItem" name="find_next">
                 <label>Find &Next</label>
             </object>
appended to my accelerators.conf:

Code: Select all

select_previous|Search|Select Next|Ctrl+Shift+UP
select_next|Search|Select Next|Ctrl+Shift+DOWN
Last edited by caibbor on Wed Jun 11, 2014 10:38 am, edited 5 times in total.
User avatar
caibbor
CodeLite Veteran
Posts: 78
Joined: Thu Jan 10, 2013 10:37 pm
Genuine User: Yes
IDE Question: c++
Contact:

Re: Patch: Keyboard shortcut (accelerator) for "select next"

Post by caibbor »

I goofed and posted the wrong git output, but it's correct now.

I also renamed the feature to "Select Next Occurrence" and added "Select Previous Occurrence"
User avatar
caibbor
CodeLite Veteran
Posts: 78
Joined: Thu Jan 10, 2013 10:37 pm
Genuine User: Yes
IDE Question: c++
Contact:

Re: Patch: Keyboard shortcut (accelerator) for "select next"

Post by caibbor »

come to think of it, the menu options technically belong under the Edit menu, not Search.
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Patch: Keyboard shortcut (accelerator) for "select next"

Post by eranif »

Patched applied ( with 2 minor changes ):
- I moved the 'Select Next' to be on to of 'Select Previous Match'
- I am now using the Ctrl-F3 and Ctrl-Shift-F3 for shortcuts

Eran
Make sure you have read the HOW TO POST thread
User avatar
caibbor
CodeLite Veteran
Posts: 78
Joined: Thu Jan 10, 2013 10:37 pm
Genuine User: Yes
IDE Question: c++
Contact:

Re: Patch: Keyboard shortcut (accelerator) for "select next"

Post by caibbor »

After checking out a fresh copy of the source and thus being 100% matched with what you have, I noticed that these accelerators no longer work. I investigated a bit further and realized that you didn't apply some parts of the patch. I also noticed that feature no longer worked from the Search menu, either.

I merged in the changed lines from the patch in the top post with current git head and recompiled. Everything works now. Here's the patch to get this working properly (your menu oder stays the same):

Code: Select all

diff --git a/LiteEditor/quickfindbar.cpp b/LiteEditor/quickfindbar.cpp
index 518ecc4..58d416f 100644
--- a/LiteEditor/quickfindbar.cpp
+++ b/LiteEditor/quickfindbar.cpp
@@ -83,6 +83,8 @@ QuickFindBar::QuickFindBar(wxWindow* parent, wxWindowID id)
     wxTheApp->Connect(XRCID("find_previous"),          wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnFindPrevious),      NULL, this);
     wxTheApp->Connect(XRCID("find_next_at_caret"),     wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnFindNextCaret),     NULL, this);
     wxTheApp->Connect(XRCID("find_previous_at_caret"), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnFindPreviousCaret), NULL, this);
+    wxTheApp->Connect(XRCID("select_previous"),        wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnSelectPrevious),          NULL, this);
+    wxTheApp->Connect(XRCID("select_next"),            wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnSelectNext),          NULL, this);
 
     EventNotifier::Get()->Connect(wxEVT_FINDBAR_RELEASE_EDITOR, wxCommandEventHandler(QuickFindBar::OnReleaseEditor), NULL, this);
     Connect(QUICKFIND_COMMAND_EVENT, wxCommandEventHandler(QuickFindBar::OnQuickFindCommandEvent), NULL, this);
@@ -525,6 +527,34 @@ void QuickFindBar::OnFindPrevious(wxCommandEvent& e)
     DoSearch(false, false);
 }
 
+void QuickFindBar::OnSelectPrevious(wxCommandEvent& e)
+{
+    CHECK_FOCUS_WIN();
+
+    // Highlighted text takes precedence over the current search string
+    wxString selectedText = DoGetSelectedText();
+    if (selectedText.IsEmpty() == false) {
+        m_findWhat->ChangeValue(selectedText);
+        m_findWhat->SelectAll();
+    }
+
+    DoSearch(false, false, true);
+}
+
+void QuickFindBar::OnSelectNext(wxCommandEvent& e)
+{
+    CHECK_FOCUS_WIN();
+
+    // Highlighted text takes precedence over the current search string
+    wxString selectedText = DoGetSelectedText();
+    if (selectedText.IsEmpty() == false) {
+        m_findWhat->ChangeValue( selectedText );
+        m_findWhat->SelectAll();
+    }
+
+    DoSearch(true, false, true);
+}
+
 void QuickFindBar::OnFindNextCaret(wxCommandEvent& e)
 {
     CHECK_FOCUS_WIN();
@@ -706,6 +736,8 @@ QuickFindBar::~QuickFindBar()
     wxTheApp->Disconnect(wxID_COPY,      wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuickFindBar::OnEditUI), NULL, this);
     wxTheApp->Disconnect(wxID_PASTE,     wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuickFindBar::OnEditUI), NULL, this);
     wxTheApp->Disconnect(wxID_SELECTALL, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuickFindBar::OnEditUI), NULL, this);
+    wxTheApp->Disconnect(XRCID("select_previous"),        wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnSelectPrevious),          NULL, this);
+    wxTheApp->Disconnect(XRCID("select_next"),            wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnSelectNext),          NULL, this);
     wxTheApp->Disconnect(XRCID("find_next"),              wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnFindNext),          NULL, this);
     wxTheApp->Disconnect(XRCID("find_previous"),          wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnFindPrevious),      NULL, this);
     wxTheApp->Disconnect(XRCID("find_next_at_caret"),     wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuickFindBar::OnFindNextCaret),     NULL, this);
diff --git a/LiteEditor/quickfindbar.h b/LiteEditor/quickfindbar.h
index c09bf6c..23c70e9 100644
--- a/LiteEditor/quickfindbar.h
+++ b/LiteEditor/quickfindbar.h
@@ -82,6 +82,8 @@ protected:
     void OnReceivingFocus(wxFocusEvent& event);
     void OnReleaseEditor(wxCommandEvent &e);
 
+    void OnSelectPrevious   (wxCommandEvent &e);
+    void OnSelectNext       (wxCommandEvent &e);
     void OnFindNext         (wxCommandEvent &e);
     void OnFindPrevious     (wxCommandEvent &e);
     void OnFindNextCaret    (wxCommandEvent &e);
DavidGH
CodeLite Plugin
Posts: 819
Joined: Wed Sep 03, 2008 7:26 pm
Contact:

Re: Patch: Keyboard shortcut (accelerator) for "select next"

Post by DavidGH »

Hi,
// Highlighted text takes precedence over the current search string
How can this be prevented ;) ?

Since the recent changes, I find that QuickFind is less likely to do what I want. It's fine if the selected text is what I want to search for, or to SelectNext. But if I then paste a new string into QuickFind, it doesn't automatically become the new search string; I have to press Enter before it's recognised. This is imho a bug, and it's certainly unexpected.

IIUC, the code you pasted will make it even harder to change. It can't be right always to use selected text...

Regards,

David
User avatar
caibbor
CodeLite Veteran
Posts: 78
Joined: Thu Jan 10, 2013 10:37 pm
Genuine User: Yes
IDE Question: c++
Contact:

Re: Patch: Keyboard shortcut (accelerator) for "select next"

Post by caibbor »

That code was word-for-word copy pasta from code Eran wrote, I simply copied FindNext() function to be SelectNext() and changed one line from

Code: Select all

DoSearch(true, false);
to

Code: Select all

DoSearch(true, false, true);
Without this function, the "select next occurence" option in the Search menu simply does nothing.

You seem to know more how CL works internally, feel free to fix my patch. As long as I can select multiple things with multiple cursors and edit them simultaneously, I'm happy. It allows to hack up and refactor code incredibly fast. Once you try it out and get used to it, you won't want to live without it ;)
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: Patch: Keyboard shortcut (accelerator) for "select next"

Post by petah »

IMHO many scintilla issues aren't as much "bugs" but side-effects due to having several immediate UI fields open at the same time and keyboard capture ping-ponging around. F.ex. pressing Enter in the incremental search goes to the next hit, but in the editor it adds a line. The "correct" behavior often depends on user intent... which STC cannot guess. And the focus handling sucks ;)

cheers,

-- p
main: Debian Jessie x64 + custom wxTrunk
Post Reply