diff --git a/include/eepp/ui.hpp b/include/eepp/ui.hpp index bc7370a21..692b0ac64 100644 --- a/include/eepp/ui.hpp +++ b/include/eepp/ui.hpp @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -73,6 +74,7 @@ #include #include #include +#include #include #include diff --git a/include/eepp/ui/tools/uidocfindreplace.hpp b/include/eepp/ui/tools/uidocfindreplace.hpp new file mode 100644 index 000000000..c419ea37d --- /dev/null +++ b/include/eepp/ui/tools/uidocfindreplace.hpp @@ -0,0 +1,82 @@ +#ifndef EE_UI_TOOLS_UIDOCFINDREPLACE_HPP +#define EE_UI_TOOLS_UIDOCFINDREPLACE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace EE { namespace UI { namespace Tools { + +class EE_API UIDocFindReplace : public UILinearLayout, public WidgetCommandExecuter { + public: + static std::unordered_map getDefaultKeybindings() { + return { { "mod+g", "repeat-find" }, { "escape", "close-find-replace" }, + { "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" } }; + } + + static UIDocFindReplace* + New( UIWidget* parent, const std::shared_ptr& doc, + std::unordered_map keybindings = getDefaultKeybindings() ); + + const std::shared_ptr& getDoc() const; + + void setDoc( const std::shared_ptr& doc ); + + virtual void show(); + + virtual void hide(); + + protected: + struct SearchState { + String text; + TextRange range = TextRange(); + bool caseSensitive{ false }; + bool wholeWord{ false }; + bool escapeSequences{ false }; + TextDocument::FindReplaceType type{ TextDocument::FindReplaceType::Normal }; + void reset() { + range = TextRange(); + text = ""; + } + }; + + bool mReady{ false }; + UITextInput* mFindInput{ nullptr }; + UITextInput* mReplaceInput{ nullptr }; + UISelectButton* mCaseSensitive{ nullptr }; + UISelectButton* mLuaPattern{ nullptr }; + UISelectButton* mWholeWord{ nullptr }; + UISelectButton* mEscapeSequences{ nullptr }; + UIWidget* mToggle{ nullptr }; + UIWidget* mReplaceBox{ nullptr }; + std::shared_ptr mDoc; + + UIDocFindReplace( + UIWidget* parent, const std::shared_ptr& doc, + std::unordered_map keybindings = getDefaultKeybindings() ); + + SearchState mSearchState; + String mLastSearch; + + bool findAndReplace( SearchState& search, const String& replace ); + + bool findPrevText( SearchState& search ); + + bool findNextText( SearchState& search ); + + int replaceAll( SearchState& search, const String& replace ); + + virtual Uint32 onKeyDown( const KeyEvent& event ); +}; + +}}} // namespace EE::UI::Tools + +#endif // EE_UI_TOOLS_UIDOCFINDREPLACE_HPP diff --git a/include/eepp/ui/uicodeeditor.hpp b/include/eepp/ui/uicodeeditor.hpp index 65328176f..ce9f41fb7 100644 --- a/include/eepp/ui/uicodeeditor.hpp +++ b/include/eepp/ui/uicodeeditor.hpp @@ -18,6 +18,10 @@ class Font; namespace EE { namespace UI { +namespace Tools { +class UIDocFindReplace; +} + class UICodeEditor; class UIWindow; class UIScrollBar; @@ -554,6 +558,7 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { String::HashType hash; }; mutable std::map mTextCache; + Tools::UIDocFindReplace* mFindReplace{ nullptr }; UICodeEditor( const std::string& elementTag, const bool& autoRegisterBaseCommands = true, const bool& autoRegisterBaseKeybindings = true ); @@ -728,6 +733,8 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { Text& getLineText( const Int64& lineNumber ) const; void updateLineCache( const Int64& lineIndex ); + + void findReplace(); }; }} // namespace EE::UI diff --git a/include/eepp/ui/widgetcommandexecuter.hpp b/include/eepp/ui/widgetcommandexecuter.hpp new file mode 100644 index 000000000..6f73b24aa --- /dev/null +++ b/include/eepp/ui/widgetcommandexecuter.hpp @@ -0,0 +1,49 @@ +#ifndef EE_UI_WIDGETCOMMANDEXECUTER_HPP +#define EE_UI_WIDGETCOMMANDEXECUTER_HPP + +#include +#include +#include +#include + +using namespace EE::Scene; + +namespace EE { namespace UI { + +class EE_API WidgetCommandExecuter { + public: + typedef std::function CommandCallback; + + WidgetCommandExecuter( const KeyBindings& keybindings ) : mKeyBindings( keybindings ) {} + + void addCommand( const std::string& name, const CommandCallback& cb ) { mCommands[name] = cb; } + + void execute( const std::string& command ) { + auto cmdIt = mCommands.find( command ); + if ( cmdIt != mCommands.end() ) + cmdIt->second(); + } + + KeyBindings& getKeyBindings() { return mKeyBindings; } + + protected: + KeyBindings mKeyBindings; + std::unordered_map> mCommands; + + Uint32 onKeyDown( const KeyEvent& event ) { + std::string cmd = + mKeyBindings.getCommandFromKeyBind( { event.getKeyCode(), event.getMod() } ); + if ( !cmd.empty() ) { + auto cmdIt = mCommands.find( cmd ); + if ( cmdIt != mCommands.end() ) { + cmdIt->second(); + return 1; + } + } + return 0; + } +}; + +}} // namespace EE::UI + +#endif // EE_UI_WIDGETCOMMANDEXECUTER_HPP diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index e53e28813..5ff483d7f 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -109,7 +109,7 @@ {388e5431-b31b-42b3-b9ad-9002d279d75d} 10 0 - 19 + 15 ../../make/linux @@ -186,7 +186,7 @@ true - --with-mojoal --with-mold-linker gmake + --with-mojoal gmake premake4 %{buildDir}../../../ ProjectExplorer.ProcessStep @@ -227,7 +227,7 @@ true - --with-mold-linker --with-mojoal gmake + --with-mold-linker --with-debug-symbols --with-mojoal gmake premake4 %{buildDir}../../../ ProjectExplorer.ProcessStep @@ -1105,7 +1105,7 @@ eepp-UIEditor-debug ProjectExplorer.CustomExecutableRunConfiguration - --css=assets/layouts/test.css --xml=assets/layouts/test.xml -u + --xml=/home/downloads/temp/eepp/search_box.xml -u true false false @@ -1429,9 +1429,109 @@ 21 + + ProjectExplorer.Project.Target.1 + + Desktop + Replacement for "Desktop" + Replacement for "Desktop" + {6d057187-158a-4883-8d5b-d470a6b6b025} + 0 + 0 + 0 + + /home/programming/eepp/projects/linux + + + + all + + true + GenericProjectManager.GenericMakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + GenericProjectManager.GenericMakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Default + GenericProjectManager.GenericBuildConfiguration + + 1 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + false + /usr/bin/kcachegrind + 2 + 2 + true + true + /usr/bin/valgrind + + 11 + 14 + 12 + 13 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 0 + 1 + + + 2 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + true + false + true + + 1 + + ProjectExplorer.Project.TargetCount - 1 + 2 ProjectExplorer.Project.Updater.FileVersion diff --git a/projects/linux/ee.files b/projects/linux/ee.files index dfea626f5..b02a348ed 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -352,6 +352,7 @@ ../../include/eepp/ui/tools/textureatlaseditor.hpp ../../include/eepp/ui/tools/uicodeeditorsplitter.hpp ../../include/eepp/ui/tools/uicolorpicker.hpp +../../include/eepp/ui/tools/uidocfindreplace.hpp ../../include/eepp/ui/uiabstractview.hpp ../../include/eepp/ui/uibackgrounddrawable.hpp ../../include/eepp/ui/uiborderdrawable.hpp @@ -431,6 +432,7 @@ ../../include/eepp/ui/uiwidgettable.hpp ../../include/eepp/ui/uiwidgettablerow.hpp ../../include/eepp/ui/uiwindow.hpp +../../include/eepp/ui/widgetcommandexecuter.hpp ../../include/eepp/version.hpp ../../include/eepp/window/base.hpp ../../include/eepp/window/clipboard.hpp @@ -834,6 +836,7 @@ ../../src/eepp/ui/tools/textureatlastextureregioneditor.hpp ../../src/eepp/ui/tools/uicodeeditorsplitter.cpp ../../src/eepp/ui/tools/uicolorpicker.cpp +../../src/eepp/ui/tools/uidocfindreplace.cpp ../../src/eepp/ui/uiabstractview.cpp ../../src/eepp/ui/uibackgrounddrawable.cpp ../../src/eepp/ui/uiborderdrawable.cpp @@ -908,6 +911,7 @@ ../../src/eepp/ui/uiwidgettable.cpp ../../src/eepp/ui/uiwidgettablerow.cpp ../../src/eepp/ui/uiwindow.cpp +../../src/eepp/ui/widgetcommandexecuter.hpp ../../src/eepp/window/backend/allegro5/cbackendal.hpp ../../src/eepp/window/backend/allegro5/cclipboardal.cpp ../../src/eepp/window/backend/allegro5/cclipboardal.hpp diff --git a/projects/linux/ee.includes b/projects/linux/ee.includes index 583984a46..33d722d85 100644 --- a/projects/linux/ee.includes +++ b/projects/linux/ee.includes @@ -12,3 +12,7 @@ ../../src/modules/eterm/include/ ../../src/modules/eterm/include/eterm/ui ../../src/modules/eterm/src/eterm/ui +../../include/eepp/ui/tools +../../src/eepp/ui/tools +../../src/eepp/ui +../../include/eepp/ui diff --git a/src/eepp/ui/tools/uicodeeditorsplitter.cpp b/src/eepp/ui/tools/uicodeeditorsplitter.cpp index fb8db631e..a0430ad21 100644 --- a/src/eepp/ui/tools/uicodeeditorsplitter.cpp +++ b/src/eepp/ui/tools/uicodeeditorsplitter.cpp @@ -128,7 +128,7 @@ UISplitter* UICodeEditorSplitter::splitterFromWidget( UIWidget* widget ) const { } UICodeEditor* UICodeEditorSplitter::createCodeEditor() { - UICodeEditor* editor = UICodeEditor::NewOpt( false, true ); + UICodeEditor* editor = UICodeEditor::NewOpt( true, true ); TextDocument& doc = editor->getDocument(); /* global commands */ doc.setCommand( "move-to-previous-line", [&] { diff --git a/src/eepp/ui/tools/uidocfindreplace.cpp b/src/eepp/ui/tools/uidocfindreplace.cpp new file mode 100644 index 000000000..74c4624dc --- /dev/null +++ b/src/eepp/ui/tools/uidocfindreplace.cpp @@ -0,0 +1,465 @@ +#include "eepp/window/clipboard.hpp" +#include +#include +#include +#include + +namespace EE { namespace UI { namespace Tools { + +const char DOC_FIND_REPLACE_XML[] = R"xml( + + + +