From 92cb3ce12a14919fc9490409ae2d75888aa412d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Tue, 5 Jan 2021 00:17:30 -0300 Subject: [PATCH] ecode: Added notification center. --- TODO.md | 2 -- projects/linux/ee.files | 2 ++ src/tools/codeeditor/codeeditor.cpp | 21 ++++++++++++++++++ src/tools/codeeditor/codeeditor.hpp | 4 ++++ src/tools/codeeditor/docsearchcontroller.cpp | 4 +++- .../codeeditor/globalsearchcontroller.cpp | 14 +++++++++--- .../codeeditor/globalsearchcontroller.hpp | 4 ++-- src/tools/codeeditor/notificationcenter.cpp | 22 +++++++++++++++++++ src/tools/codeeditor/notificationcenter.hpp | 16 ++++++++++++++ 9 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 src/tools/codeeditor/notificationcenter.cpp create mode 100644 src/tools/codeeditor/notificationcenter.hpp diff --git a/TODO.md b/TODO.md index 56b00d3ae..85acba44d 100644 --- a/TODO.md +++ b/TODO.md @@ -25,8 +25,6 @@ Detect errors and log them. * Add support for function listing. -* Display number of results in search and number of replacements. - ## UI Editor * Integrate the `UICodeEditor` into the editor in order to be able to edit the layouts and CSS in app. diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 6dc4231b1..b2cbf3da8 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -1109,6 +1109,8 @@ ../../src/tools/codeeditor/ignorematcher.hpp ../../src/tools/codeeditor/lintermodule.cpp ../../src/tools/codeeditor/lintermodule.hpp +../../src/tools/codeeditor/notificationcenter.cpp +../../src/tools/codeeditor/notificationcenter.hpp ../../src/tools/codeeditor/projectdirectorytree.cpp ../../src/tools/codeeditor/projectdirectorytree.hpp ../../src/tools/codeeditor/projectsearch.cpp diff --git a/src/tools/codeeditor/codeeditor.cpp b/src/tools/codeeditor/codeeditor.cpp index f937bcbe1..0809c6c64 100644 --- a/src/tools/codeeditor/codeeditor.cpp +++ b/src/tools/codeeditor/codeeditor.cpp @@ -1248,6 +1248,10 @@ bool App::isDirTreeReady() const { return mDirTreeReady; } +NotificationCenter* App::getNotificationCenter() const { + return mNotificationCenter.get(); +} + void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { const CodeEditorConfig& config = mConfig.editor; editor->setFontSize( config.fontSize.asDp( 0, Sizef(), mUISceneNode->getDPI() ) ); @@ -1929,6 +1933,17 @@ void App::init( const std::string& file, const Float& pidelDensity ) { #global_search_layout > .replace_box { padding: 4dp; } + .notification { + background-color: var(--button-back); + border-color: var(--button-border); + border-width: 1dp; + border-radius: 8dp; + color: var(--font); + padding: 4dp; + min-height: 48dp; + margin-bottom: 8dp; + opacity: 0.8; + } @@ -1947,6 +1962,9 @@ void App::init( const std::string& file, const Float& pidelDensity ) { + + @@ -2085,6 +2103,9 @@ void App::init( const std::string& file, const Float& pidelDensity ) { mFileWatcher->watch(); #endif + mNotificationCenter = std::make_unique( + mUISceneNode->find( "notification_center" ) ); + mDocSearchController = std::make_unique( mEditorSplitter, this ); mDocSearchController->initSearchBar( mUISceneNode->find( "search_bar" ) ); diff --git a/src/tools/codeeditor/codeeditor.hpp b/src/tools/codeeditor/codeeditor.hpp index 4369b4741..b66e24893 100644 --- a/src/tools/codeeditor/codeeditor.hpp +++ b/src/tools/codeeditor/codeeditor.hpp @@ -6,6 +6,7 @@ #include "filelocator.hpp" #include "filesystemlistener.hpp" #include "globalsearchcontroller.hpp" +#include "notificationcenter.hpp" #include "projectdirectorytree.hpp" #include "projectsearch.hpp" #include "uitreeviewglobalsearch.hpp" @@ -65,6 +66,8 @@ class App : public UICodeEditorSplitter::Client { bool isDirTreeReady() const; + NotificationCenter* getNotificationCenter() const; + protected: EE::Window::Window* mWindow{ nullptr }; UISceneNode* mUISceneNode{ nullptr }; @@ -115,6 +118,7 @@ class App : public UICodeEditorSplitter::Client { std::unique_ptr mGlobalSearchController; std::unique_ptr mDocSearchController; std::unique_ptr mFileLocator; + std::unique_ptr mNotificationCenter; void saveAllProcess(); diff --git a/src/tools/codeeditor/docsearchcontroller.cpp b/src/tools/codeeditor/docsearchcontroller.cpp index 037ce0158..f3bf94ef4 100644 --- a/src/tools/codeeditor/docsearchcontroller.cpp +++ b/src/tools/codeeditor/docsearchcontroller.cpp @@ -70,7 +70,9 @@ void DocSearchController::initSearchBar( UISearchBar* searchBar ) { } ); mSearchBarLayout->addCommand( "repeat-find", [this] { findNextText( mSearchState ); } ); mSearchBarLayout->addCommand( "replace-all", [this, replaceInput] { - replaceAll( mSearchState, replaceInput->getText() ); + size_t count = replaceAll( mSearchState, replaceInput->getText() ); + mApp->getNotificationCenter()->addNotification( + String::format( "Replaced %zu occurrences.", count ) ); replaceInput->setFocus(); } ); mSearchBarLayout->addCommand( "find-and-replace", [this, replaceInput] { diff --git a/src/tools/codeeditor/globalsearchcontroller.cpp b/src/tools/codeeditor/globalsearchcontroller.cpp index d11709e99..c1047222a 100644 --- a/src/tools/codeeditor/globalsearchcontroller.cpp +++ b/src/tools/codeeditor/globalsearchcontroller.cpp @@ -22,9 +22,11 @@ static String replaceInText( String text, const String& replaceText, return text; } -void GlobalSearchController::replaceInFiles( const String& replaceText, - std::shared_ptr model ) { +size_t GlobalSearchController::replaceInFiles( const String& replaceText, + std::shared_ptr model ) { const ProjectSearch::Result& res = model.get()->getResult(); + size_t count = 0; + for ( const auto& fileResult : res ) { std::map>> replaceRangeMap; std::map replaceStringMap; @@ -32,6 +34,7 @@ void GlobalSearchController::replaceInFiles( const String& replaceText, if ( result.selected ) { replaceRangeMap[result.position.start().line()].first = result.line; replaceRangeMap[result.position.start().line()].second.push_back( result.position ); + count++; } } @@ -58,7 +61,10 @@ void GlobalSearchController::replaceInFiles( const String& replaceText, doc->save(); } } + + return count; } + void GlobalSearchController::initGlobalSearchBar( UIGlobalSearchBar* globalSearchBar ) { mGlobalSearchBarLayout = globalSearchBar; mGlobalSearchBarLayout->setVisible( false )->setEnabled( false ); @@ -187,9 +193,11 @@ void GlobalSearchController::initGlobalSearchBar( UIGlobalSearchBar* globalSearc if ( listBox->getItemSelectedIndex() < mGlobalSearchHistory.size() ) { const auto& replaceData = mGlobalSearchHistory[mGlobalSearchHistory.size() - 1 - listBox->getItemSelectedIndex()]; - replaceInFiles( replaceInput->getText(), replaceData.second ); + size_t count = replaceInFiles( replaceInput->getText(), replaceData.second ); mGlobalSearchBarLayout->execute( "search-again" ); mGlobalSearchBarLayout->execute( "close-global-searchbar" ); + mApp->getNotificationCenter()->addNotification( + String::format( "Replaced %zu occurrences.", count ) ); } } ); mGlobalSearchTreeSearch = diff --git a/src/tools/codeeditor/globalsearchcontroller.hpp b/src/tools/codeeditor/globalsearchcontroller.hpp index cb12c3aa9..5a8e0f98b 100644 --- a/src/tools/codeeditor/globalsearchcontroller.hpp +++ b/src/tools/codeeditor/globalsearchcontroller.hpp @@ -27,8 +27,8 @@ class GlobalSearchController { void doGlobalSearch( const String& text, bool caseSensitive, bool wholeWord, bool luaPattern, bool searchReplace, bool searchAgain = false ); - void replaceInFiles( const String& replaceText, - std::shared_ptr model ); + size_t replaceInFiles( const String& replaceText, + std::shared_ptr model ); void showGlobalSearch( bool searchAndReplace = false ); diff --git a/src/tools/codeeditor/notificationcenter.cpp b/src/tools/codeeditor/notificationcenter.cpp new file mode 100644 index 000000000..fb3480e29 --- /dev/null +++ b/src/tools/codeeditor/notificationcenter.cpp @@ -0,0 +1,22 @@ +#include "notificationcenter.hpp" + +NotificationCenter::NotificationCenter( UILayout* layout ) : mLayout( layout ) {} + +UITextView* NotificationCenter::addNotification( const String& text ) { + UITextView* tv = UITextView::New(); + tv->addEventListener( Event::MouseClick, [tv]( const Event* event ) { + const MouseEvent* mouseEvent = static_cast( event ); + if ( mouseEvent->getFlags() & EE_BUTTON_LMASK ) + tv->close(); + } ); + tv->setParent( mLayout ); + tv->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::WrapContent ); + tv->setFlags( UI_WORD_WRAP ); + tv->setText( text ); + tv->addClass( "notification" ); + Action* sequence = Actions::Sequence::New( + { Actions::FadeIn::New( Seconds( 0.125 ) ), Actions::Delay::New( Seconds( 2.5 ) ), + Actions::FadeOut::New( Seconds( 0.125 ) ), Actions::Close::New() } ); + tv->runAction( sequence ); + return tv; +} diff --git a/src/tools/codeeditor/notificationcenter.hpp b/src/tools/codeeditor/notificationcenter.hpp new file mode 100644 index 000000000..3b801681a --- /dev/null +++ b/src/tools/codeeditor/notificationcenter.hpp @@ -0,0 +1,16 @@ +#ifndef NOTIFICATIONCENTER_HPP +#define NOTIFICATIONCENTER_HPP + +#include + +class NotificationCenter { + public: + NotificationCenter( UILayout* layout ); + + UITextView* addNotification( const String& text ); + + protected: + UILayout* mLayout{ nullptr }; +}; + +#endif // NOTIFICATIONCENTER_HPP