2020-05-27 22:28:36 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-04-06 23:09:08 +00:00
|
|
|
* Copyright (C) 2020-2022 KiCad Developers, see change_log.txt for contributors.
|
2020-05-27 22:28:36 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SCINTILLA_TRICKS_H
|
|
|
|
#define SCINTILLA_TRICKS_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <wx/stc/stc.h>
|
2021-06-28 10:44:22 +00:00
|
|
|
#include <functional>
|
2020-05-27 22:28:36 +00:00
|
|
|
|
|
|
|
/**
|
2021-12-03 02:41:02 +00:00
|
|
|
* Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl
|
|
|
|
* instance.
|
2020-05-27 22:28:36 +00:00
|
|
|
*/
|
|
|
|
class SCINTILLA_TRICKS : public wxEvtHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2021-06-28 10:19:12 +00:00
|
|
|
SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString& aBraces, bool aSingleLine,
|
2023-08-02 19:11:59 +00:00
|
|
|
std::function<void( wxKeyEvent& )> onAcceptHandler =
|
|
|
|
[]( wxKeyEvent& aEvent )
|
2023-02-20 10:11:57 +00:00
|
|
|
{ },
|
2023-05-24 22:46:48 +00:00
|
|
|
std::function<void( wxStyledTextEvent& )> onCharAddedHandler =
|
2023-02-20 10:11:57 +00:00
|
|
|
[]( wxStyledTextEvent& )
|
|
|
|
{ } );
|
|
|
|
|
|
|
|
wxStyledTextCtrl* Scintilla() const { return m_te; }
|
2020-05-27 22:28:36 +00:00
|
|
|
|
2023-05-24 22:46:48 +00:00
|
|
|
void DoTextVarAutocomplete( std::function<void( const wxString& crossRef,
|
|
|
|
wxArrayString* tokens )> aTokenProvider );
|
|
|
|
|
2020-05-30 19:00:09 +00:00
|
|
|
void DoAutocomplete( const wxString& aPartial, const wxArrayString& aTokens );
|
2020-05-27 22:28:36 +00:00
|
|
|
|
2021-11-20 01:23:43 +00:00
|
|
|
void CancelAutocomplete();
|
|
|
|
|
2020-05-27 22:28:36 +00:00
|
|
|
protected:
|
2021-09-13 22:30:22 +00:00
|
|
|
void setupStyles();
|
|
|
|
|
2020-09-03 19:33:33 +00:00
|
|
|
int firstNonWhitespace( int aLine, int* aWhitespaceCount = nullptr );
|
|
|
|
|
2020-05-27 22:28:36 +00:00
|
|
|
void onCharHook( wxKeyEvent& aEvent );
|
2023-02-20 10:11:57 +00:00
|
|
|
void onChar( wxStyledTextEvent& aEvent );
|
2020-05-27 22:28:36 +00:00
|
|
|
void onScintillaUpdateUI( wxStyledTextEvent& aEvent );
|
2021-09-13 22:30:22 +00:00
|
|
|
void onThemeChanged( wxSysColourChangedEvent &aEvent );
|
2020-05-27 22:28:36 +00:00
|
|
|
|
|
|
|
protected:
|
2021-06-28 10:19:12 +00:00
|
|
|
wxStyledTextCtrl* m_te;
|
|
|
|
wxString m_braces;
|
|
|
|
int m_lastCaretPos;
|
2022-04-06 23:09:08 +00:00
|
|
|
int m_lastSelStart;
|
|
|
|
int m_lastSelEnd;
|
2021-06-28 10:19:12 +00:00
|
|
|
bool m_suppressAutocomplete;
|
|
|
|
bool m_singleLine; // Treat <return> as OK, and skip special tab
|
|
|
|
// stop handling (including monospaced font).
|
2023-02-20 10:11:57 +00:00
|
|
|
|
2023-08-02 19:11:59 +00:00
|
|
|
// Process <return> in singleLine, and <shift> + <return> irrespective.
|
|
|
|
std::function<void( wxKeyEvent& aEvent )> m_onAcceptHandler;
|
2023-05-24 22:46:48 +00:00
|
|
|
std::function<void( wxStyledTextEvent& aEvent )> m_onCharAddedHandler;
|
2020-05-27 22:28:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SCINTILLA_TRICKS_H
|