From a4aa9c1f9425e96508c94cb800535433ea0f03d3 Mon Sep 17 00:00:00 2001 From: Eran Ifrah Date: Sat, 21 Dec 2024 14:07:47 +0200 Subject: [PATCH] Restore the find/replace dialog size from previous session Signed-off-by: Eran Ifrah --- LiteEditor/quickfindbar.cpp | 22 ++++++++++++++++++---- LiteEditor/quickfindbarbase.cpp | 12 +++--------- LiteEditor/quickfindbarbase.wxcp | 8 ++++---- Plugin/clThemedTextCtrl.hpp | 4 ++++ 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/LiteEditor/quickfindbar.cpp b/LiteEditor/quickfindbar.cpp index 1717737b24..e5143b74ec 100644 --- a/LiteEditor/quickfindbar.cpp +++ b/LiteEditor/quickfindbar.cpp @@ -209,11 +209,15 @@ QuickFindBar::QuickFindBar(wxWindow* parent, wxWindowID id) // Make sure that the 'Replace' field is selected when we hit TAB while in the 'Find' field m_textCtrlReplace->MoveAfterInTabOrder(m_textCtrlFind); - GetSizer()->Fit(this); -#if !defined(__WXMAC__) - SetSize(parent->GetSize().GetWidth() / 2, wxNOT_FOUND); -#endif + int w = wxNOT_FOUND; + int h = wxNOT_FOUND; + if (clConfig::Get().Read("FindBar/Width", w) && clConfig::Get().Read("FindBar/Height", h)) { + SetSize(w, h); + SetSizeHints(w, h); + } else { + GetSizer()->Fit(this); + } Layout(); } @@ -222,6 +226,8 @@ QuickFindBar::~QuickFindBar() // Remember the buttons clicked clConfig::Get().Write("FindBar/SearchFlags", (int)DoGetSearchFlags()); clConfig::Get().Write("FindBar/HighlightOccurences", m_highlightMatches); + clConfig::Get().Write("FindBar/Width", GetSize().GetWidth()); + clConfig::Get().Write("FindBar/Height", GetSize().GetHeight()); wxTheApp->Unbind(wxEVT_MENU, &QuickFindBar::OnFindNextCaret, this, XRCID("find_next_at_caret")); wxTheApp->Unbind(wxEVT_MENU, &QuickFindBar::OnFindPreviousCaret, this, XRCID("find_previous_at_caret")); @@ -788,6 +794,10 @@ void QuickFindBar::DoReplaceAll(bool selectionOnly) TargetRange QuickFindBar::DoFind(size_t find_flags, const TargetRange& target) { + if (!m_sci) { + return {}; + } + // define the target range size_t search_options = DoGetSearchFlags(); int target_start = wxNOT_FOUND, target_end = wxNOT_FOUND; @@ -1008,6 +1018,10 @@ bool QuickFindBar::IsReplacementRegex() const TargetRange QuickFindBar::DoFindWithMessage(size_t find_flags, const TargetRange& target) { + if (!m_sci) { + return {}; + } + m_message->SetLabel(wxEmptyString); auto res = DoFind(find_flags, target); if (!res.IsOk()) { diff --git a/LiteEditor/quickfindbarbase.cpp b/LiteEditor/quickfindbarbase.cpp index 8e2911b2d4..98422ea94a 100644 --- a/LiteEditor/quickfindbarbase.cpp +++ b/LiteEditor/quickfindbarbase.cpp @@ -245,7 +245,7 @@ clFindReplaceDialogBase::clFindReplaceDialogBase( wxID_ANY, wxT(""), wxDefaultPosition, - wxDLG_UNIT(m_mainPanel, wxSize(350, -1)), + wxDLG_UNIT(m_mainPanel, wxSize(400, -1)), wxTE_PROCESS_ENTER); m_textCtrlFind->SetFocus(); #if wxVERSION_NUMBER >= 3000 @@ -253,7 +253,6 @@ clFindReplaceDialogBase::clFindReplaceDialogBase( #endif flexGridSizer107->Add(m_textCtrlFind, 0, wxALL | wxEXPAND | wxALIGN_CENTER_VERTICAL, WXC_FROM_DIP(2)); - m_textCtrlFind->SetMinSize(wxSize(350, -1)); m_buttonFind = new clThemedButton( m_mainPanel, wxID_FIND, _("Find"), wxDefaultPosition, wxDLG_UNIT(m_mainPanel, wxSize(-1, -1)), 0); @@ -271,18 +270,13 @@ clFindReplaceDialogBase::clFindReplaceDialogBase( flexGridSizer107->Add(m_buttonFindAll, 0, wxALL | wxEXPAND, WXC_FROM_DIP(2)); - m_textCtrlReplace = new clThemedTextCtrl(m_mainPanel, - wxID_ANY, - wxT(""), - wxDefaultPosition, - wxDLG_UNIT(m_mainPanel, wxSize(350, -1)), - wxTE_PROCESS_ENTER); + m_textCtrlReplace = new clThemedTextCtrl( + m_mainPanel, wxID_ANY, wxT(""), wxDefaultPosition, wxDLG_UNIT(m_mainPanel, wxSize(-1, -1)), wxTE_PROCESS_ENTER); #if wxVERSION_NUMBER >= 3000 m_textCtrlReplace->SetHint(_("Replace with...")); #endif flexGridSizer107->Add(m_textCtrlReplace, 0, wxALL | wxEXPAND | wxALIGN_CENTER_VERTICAL, WXC_FROM_DIP(2)); - m_textCtrlReplace->SetMinSize(wxSize(350, -1)); m_buttonReplace = new clThemedButton( m_mainPanel, wxID_REPLACE, _("Replace"), wxDefaultPosition, wxDLG_UNIT(m_mainPanel, wxSize(-1, -1)), 0); diff --git a/LiteEditor/quickfindbarbase.wxcp b/LiteEditor/quickfindbarbase.wxcp index 5317c394fb..3484fa94f2 100644 --- a/LiteEditor/quickfindbarbase.wxcp +++ b/LiteEditor/quickfindbarbase.wxcp @@ -1157,11 +1157,11 @@ }, { "type": "string", "m_label": "Size:", - "m_value": "350,-1" + "m_value": "400,-1" }, { "type": "string", "m_label": "Minimum Size:", - "m_value": "350,-1" + "m_value": "-1,-1" }, { "type": "string", "m_label": "Name:", @@ -1584,11 +1584,11 @@ }, { "type": "string", "m_label": "Size:", - "m_value": "350,-1" + "m_value": "-1,-1" }, { "type": "string", "m_label": "Minimum Size:", - "m_value": "350,-1" + "m_value": "-1,-1" }, { "type": "string", "m_label": "Name:", diff --git a/Plugin/clThemedTextCtrl.hpp b/Plugin/clThemedTextCtrl.hpp index ea2d6bf431..927584b788 100644 --- a/Plugin/clThemedTextCtrl.hpp +++ b/Plugin/clThemedTextCtrl.hpp @@ -41,6 +41,10 @@ class WXDLLIMPEXP_SDK clThemedTextCtrl : public clThemedTextCtrlBase void SetWrapMode(int) {} wxString GetText() const { return GetValue(); } void ClearAll() { Clear(); } +#else + // wxSTC does not provide "SetHint", what it does, it sets the text to the hint + // which triggers an event (an unwanted one) + bool SetHint(const wxString&) override { return false; } #endif protected: