Files
eepp/src/tools/ecode/docsearchcontroller.hpp
Martín Lucas Golini 0a70817ed1 Added UIDataBind: simple two way data binding between data and widgets.
UIDocFindReplace: first working version completed.
TextDocument: Fixed findTextLast when using case-insensitive search.
StyleSheet: Added StyleSheet::markerExists.
ecode: DocSearchController minor refactor.
2022-09-04 04:06:38 -03:00

85 lines
2.2 KiB
C++

#ifndef ECODE_DOCSEARCHCONTROLLER_HPP
#define ECODE_DOCSEARCHCONTROLLER_HPP
#include "appconfig.hpp"
#include <eepp/ee.hpp>
namespace ecode {
struct SearchState {
UICodeEditor* editor{ nullptr };
String text;
TextRange range = TextRange();
bool caseSensitive{ false };
bool wholeWord{ false };
bool escapeSequences{ false };
TextDocument::FindReplaceType type{ TextDocument::FindReplaceType::Normal };
void reset() {
editor = nullptr;
range = TextRange();
text = "";
}
};
class App;
class UISearchBar;
class DocSearchController {
public:
static std::unordered_map<std::string, std::string> getDefaultKeybindings() {
return { { "mod+g", "repeat-find" },
{ "escape", "close-searchbar" },
{ "mod+r", "replace-selection" },
{ "mod+shift+n", "find-and-replace" },
{ "mod+shift+r", "replace-all" },
{ "mod+s", "change-case" },
{ "mod+w", "change-whole-word" },
{ "mod+l", "toggle-lua-pattern" },
{ "mod+e", "change-escape-sequence" },
{ "mod+shift+g", "find-prev" } };
}
DocSearchController( UICodeEditorSplitter*, App* app );
void initSearchBar(
UISearchBar* searchBar, const SearchBarConfig& searchBarConfig,
std::unordered_map<std::string, std::string> keybindings = getDefaultKeybindings() );
void showFindView();
bool findPrevText( SearchState& search );
bool findNextText( SearchState& search );
bool replaceSelection( SearchState& search, const String& replacement );
int replaceAll( SearchState& search, const String& replace );
bool findAndReplace( SearchState& search, const String& replace );
void hideSearchBar();
void onCodeEditorFocusChange( UICodeEditor* editor );
SearchState& getSearchState();
SearchBarConfig getSearchBarConfig() const;
protected:
UICodeEditorSplitter* mEditorSplitter{ nullptr };
UITextInput* mFindInput{ nullptr };
UITextInput* mReplaceInput{ nullptr };
UISearchBar* mSearchBarLayout{ nullptr };
UICheckBox* mCaseSensitiveChk{ nullptr };
UICheckBox* mEscapeSequenceChk{ nullptr };
UICheckBox* mWholeWordChk{ nullptr };
UICheckBox* mLuaPatternChk{ nullptr };
App* mApp{ nullptr };
SearchState mSearchState;
String mLastSearch;
};
} // namespace ecode
#endif // ECODE_DOCSEARCHCONTROLLER_HPP