Skip to content

Commit

Permalink
Ctrl-F should open the find dialog with the focused **window** (and n…
Browse files Browse the repository at this point in the history
…ot only clEditor) selected text

Signed-off-by: Eran Ifrah <[email protected]>
  • Loading branch information
eranif committed Dec 20, 2024
1 parent ec8f940 commit 651f51a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 30 deletions.
8 changes: 4 additions & 4 deletions LiteEditor/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1847,14 +1847,14 @@ void clMainFrame::DispatchCommandEvent(wxCommandEvent& event)
}

clEditor* editor = GetMainBook()->GetActiveEditor();
if (editor) {
editor->OnMenuCommand(event);
} else if (event.GetId() == XRCID("id_find")) {
if (event.GetId() == XRCID("id_find")) {
wxStyledTextCtrl* stc = dynamic_cast<wxStyledTextCtrl*>(wxWindow::FindFocus());
if (stc) {
GetMainBook()->GetFindBar()->SetEditor(stc);
GetMainBook()->ShowQuickBar(true);
GetMainBook()->ShowQuickBar(::clGetVisibleSelection(stc), true);
}
} else if (editor) {
editor->OnMenuCommand(event);
} else if (event.GetId() == XRCID("goto_linenumber")) {
auto stc = CurrentSTC(this);
CHECK_PTR_RET(stc);
Expand Down
92 changes: 66 additions & 26 deletions Plugin/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ void MSWSetWindowDarkTheme(wxWindow* win)
// Internal handler to handle queuing requests... end
// --------------------------------------------------------

static wxString DoExpandAllVariables(const wxString& expression, clCxxWorkspace* workspace, const wxString& projectName,
const wxString& confToBuild, const wxString& fileName);
static wxString DoExpandAllVariables(const wxString& expression,
clCxxWorkspace* workspace,
const wxString& projectName,
const wxString& confToBuild,
const wxString& fileName);

#if defined(__WXGTK__)
#include <dirent.h>
Expand Down Expand Up @@ -328,8 +331,11 @@ wxString ExpandVariables(const wxString& expression, ProjectPtr proj, IEditor* e
}

// This functions accepts expression and expand all variables in it
wxString ExpandAllVariables(const wxString& expression, clCxxWorkspace* workspace, const wxString& projectName,
const wxString& selConf, const wxString& fileName)
wxString ExpandAllVariables(const wxString& expression,
clCxxWorkspace* workspace,
const wxString& projectName,
const wxString& selConf,
const wxString& fileName)
{
// add support for backticks commands
wxString tmpExp;
Expand Down Expand Up @@ -378,8 +384,11 @@ wxString ExpandAllVariables(const wxString& expression, clCxxWorkspace* workspac
return DoExpandAllVariables(tmpExp, workspace, projectName, selConf, fileName);
}

wxString DoExpandAllVariables(const wxString& expression, clCxxWorkspace* workspace, const wxString& projectName,
const wxString& confToBuild, const wxString& fileName)
wxString DoExpandAllVariables(const wxString& expression,
clCxxWorkspace* workspace,
const wxString& projectName,
const wxString& confToBuild,
const wxString& fileName)
{
wxString errMsg;
wxString output(expression);
Expand Down Expand Up @@ -728,8 +737,8 @@ wxString clGetUserName()
return (squashedname.IsEmpty() ? wxString("someone") : squashedname);
}

static void DoReadProjectTemplatesFromFolder(const wxString& folder, std::list<ProjectPtr>& list,
bool loadDefaults = true)
static void
DoReadProjectTemplatesFromFolder(const wxString& folder, std::list<ProjectPtr>& list, bool loadDefaults = true)
{
// read all files under this directory
if (wxFileName::DirExists(folder)) {
Expand Down Expand Up @@ -792,7 +801,9 @@ void MSWSetNativeTheme(wxWindow* win, const wxString& theme)
#endif
}

void StringManager::AddStrings(size_t size, const wxString* strings, const wxString& current,
void StringManager::AddStrings(size_t size,
const wxString* strings,
const wxString& current,
wxControlWithItems* control)
{
m_size = size;
Expand Down Expand Up @@ -1338,10 +1349,14 @@ void LaunchTerminalForDebugger(const wxString& title, wxString& tty, wxString& r
#endif // !__WXMSW__
}

wxStandardID PromptForYesNoCancelDialogWithCheckbox(const wxString& message, const wxString& dlgId,
const wxString& yesLabel, const wxString& noLabel,
const wxString& cancelLabel, const wxString& checkboxLabel,
long style, bool checkboxInitialValue)
wxStandardID PromptForYesNoCancelDialogWithCheckbox(const wxString& message,
const wxString& dlgId,
const wxString& yesLabel,
const wxString& noLabel,
const wxString& cancelLabel,
const wxString& checkboxLabel,
long style,
bool checkboxInitialValue)
{
int res = clConfig::Get().GetAnnoyingDlgAnswer(dlgId, wxNOT_FOUND);
if (res == wxNOT_FOUND) {
Expand All @@ -1364,12 +1379,16 @@ wxStandardID PromptForYesNoCancelDialogWithCheckbox(const wxString& message, con
return static_cast<wxStandardID>(res);
}

wxStandardID PromptForYesNoDialogWithCheckbox(const wxString& message, const wxString& dlgId, const wxString& yesLabel,
const wxString& noLabel, const wxString& checkboxLabel, long style,
wxStandardID PromptForYesNoDialogWithCheckbox(const wxString& message,
const wxString& dlgId,
const wxString& yesLabel,
const wxString& noLabel,
const wxString& checkboxLabel,
long style,
bool checkboxInitialValue)
{
return PromptForYesNoCancelDialogWithCheckbox(message, dlgId, yesLabel, noLabel, "", checkboxLabel, style,
checkboxInitialValue);
return PromptForYesNoCancelDialogWithCheckbox(
message, dlgId, yesLabel, noLabel, "", checkboxLabel, style, checkboxInitialValue);
}

wxString& WrapWithQuotes(wxString& str)
Expand Down Expand Up @@ -1455,11 +1474,11 @@ void clRecalculateSTCHScrollBar(wxStyledTextCtrl* ctrl)
ctrl->SetScrollWidth(maxPixel);
}
}
wxString clGetTextFromUser(const wxString& title, const wxString& message, const wxString& initialValue,
int charsToSelect, wxWindow* parent)
wxString clGetTextFromUser(
const wxString& title, const wxString& message, const wxString& initialValue, int charsToSelect, wxWindow* parent)
{
clGetTextFromUserDialog dialog(parent == NULL ? EventNotifier::Get()->TopFrame() : parent, title, message,
initialValue, charsToSelect);
clGetTextFromUserDialog dialog(
parent == NULL ? EventNotifier::Get()->TopFrame() : parent, title, message, initialValue, charsToSelect);
if (dialog.ShowModal() == wxID_OK) {
return dialog.GetValue();
}
Expand Down Expand Up @@ -1541,7 +1560,9 @@ void clSetEditorFontEncoding(const wxString& encoding)
EditorConfigST::Get()->SetOptions(options);
}

bool clFindExecutable(const wxString& name, wxFileName& exepath, const wxArrayString& hint,
bool clFindExecutable(const wxString& name,
wxFileName& exepath,
const wxArrayString& hint,
const wxArrayString& suffix_list)
{
return FileUtils::FindExe(name, exepath, hint, suffix_list);
Expand Down Expand Up @@ -1678,8 +1699,8 @@ static void DoSetDialogSize(wxDialog* win, double factor)
}
}

std::pair<wxString, wxString> clRemoteFolderSelector(const wxString& title, const wxString& accountName,
wxWindow* parent)
std::pair<wxString, wxString>
clRemoteFolderSelector(const wxString& title, const wxString& accountName, wxWindow* parent)
{
#if USE_SFTP
SFTPBrowserDlg dlg(parent, title, wxEmptyString, clSFTP::SFTP_BROWSE_FOLDERS, accountName);
Expand All @@ -1692,8 +1713,8 @@ std::pair<wxString, wxString> clRemoteFolderSelector(const wxString& title, cons
#endif
}

std::pair<wxString, wxString> clRemoteFileSelector(const wxString& title, const wxString& accountName,
const wxString& filter, wxWindow* parent)
std::pair<wxString, wxString>
clRemoteFileSelector(const wxString& title, const wxString& accountName, const wxString& filter, wxWindow* parent)
{
#if USE_SFTP
SFTPBrowserDlg dlg(parent, title, filter, clSFTP::SFTP_BROWSE_FOLDERS | clSFTP::SFTP_BROWSE_FILES, accountName);
Expand Down Expand Up @@ -1842,3 +1863,22 @@ wxColour GetRandomColour()
return c;
}
}

wxString clGetVisibleSelection(wxStyledTextCtrl* ctrl)
{
CHECK_PTR_RET_EMPTY_STRING(ctrl);

int start_pos = ctrl->GetSelectionStart();
int end_pos = ctrl->GetSelectionEnd();
CHECK_COND_RET_EMPTY_STRING(end_pos > start_pos);

// Make sure we only pick visible chars (embedded ANSI colour can break the selected word)
wxString res;
res.reserve(end_pos - start_pos + 1);
for (; start_pos < end_pos; start_pos++) {
if (ctrl->StyleGetVisible(ctrl->GetStyleAt(start_pos))) {
res << (wxChar)ctrl->GetCharAt(start_pos);
}
}
return res;
}
4 changes: 4 additions & 0 deletions Plugin/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,4 +617,8 @@ wxString clJoin(const Container& c, const wxString& glue = "\n")
return output;
}

/// Return the selected text in a wxSTC. This function ensures that only
/// visible text is returned (for example, if the selected text contains
/// ANSI code style hidden - it will be dropped)
WXDLLIMPEXP_SDK wxString clGetVisibleSelection(wxStyledTextCtrl* ctrl);
#endif // GLOBALS_H

0 comments on commit 651f51a

Please sign in to comment.