mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-28 17:16:29 +03:00
ecode: Added notification center.
This commit is contained in:
2
TODO.md
2
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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
</style>
|
||||
<RelativeLayout id="main_layout" layout_width="match_parent" layout_height="match_parent">
|
||||
<Splitter id="project_splitter" layout_width="match_parent" layout_height="match_parent">
|
||||
@@ -1947,6 +1962,9 @@ void App::init( const std::string& file, const Float& pidelDensity ) {
|
||||
<TextView id="image_close" layout_width="wrap_content" layout_height="wrap_content" text="" layout_gravity="top|right" enabled="false" />
|
||||
<Loader id="image_loader" layout_width="64dp" layout_height="64dp" outline-thickness="6dp" layout_gravity="center" visible="false" />
|
||||
</RelativeLayout>
|
||||
<vbox id="notification_center" layout_width="256dp" layout_height="wrap_content"
|
||||
layout_gravity="right|bottom" margin-right="22dp" margin-bottom="56dp">
|
||||
</vbox>
|
||||
</RelativeLayout>
|
||||
<searchbar id="search_bar" layout_width="match_parent" layout_height="wrap_content">
|
||||
<vbox layout_width="wrap_content" layout_height="wrap_content" margin-right="4dp">
|
||||
@@ -2085,6 +2103,9 @@ void App::init( const std::string& file, const Float& pidelDensity ) {
|
||||
mFileWatcher->watch();
|
||||
#endif
|
||||
|
||||
mNotificationCenter = std::make_unique<NotificationCenter>(
|
||||
mUISceneNode->find<UILayout>( "notification_center" ) );
|
||||
|
||||
mDocSearchController = std::make_unique<DocSearchController>( mEditorSplitter, this );
|
||||
mDocSearchController->initSearchBar( mUISceneNode->find<UISearchBar>( "search_bar" ) );
|
||||
|
||||
|
||||
@@ -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<GlobalSearchController> mGlobalSearchController;
|
||||
std::unique_ptr<DocSearchController> mDocSearchController;
|
||||
std::unique_ptr<FileLocator> mFileLocator;
|
||||
std::unique_ptr<NotificationCenter> mNotificationCenter;
|
||||
|
||||
void saveAllProcess();
|
||||
|
||||
|
||||
@@ -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] {
|
||||
|
||||
@@ -22,9 +22,11 @@ static String replaceInText( String text, const String& replaceText,
|
||||
return text;
|
||||
}
|
||||
|
||||
void GlobalSearchController::replaceInFiles( const String& replaceText,
|
||||
std::shared_ptr<ProjectSearch::ResultModel> model ) {
|
||||
size_t GlobalSearchController::replaceInFiles( const String& replaceText,
|
||||
std::shared_ptr<ProjectSearch::ResultModel> model ) {
|
||||
const ProjectSearch::Result& res = model.get()->getResult();
|
||||
size_t count = 0;
|
||||
|
||||
for ( const auto& fileResult : res ) {
|
||||
std::map<Int64, std::pair<String, std::vector<TextRange>>> replaceRangeMap;
|
||||
std::map<Int64, String> 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 =
|
||||
|
||||
@@ -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<ProjectSearch::ResultModel> model );
|
||||
size_t replaceInFiles( const String& replaceText,
|
||||
std::shared_ptr<ProjectSearch::ResultModel> model );
|
||||
|
||||
void showGlobalSearch( bool searchAndReplace = false );
|
||||
|
||||
|
||||
22
src/tools/codeeditor/notificationcenter.cpp
Normal file
22
src/tools/codeeditor/notificationcenter.cpp
Normal file
@@ -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<const MouseEvent*>( 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;
|
||||
}
|
||||
16
src/tools/codeeditor/notificationcenter.hpp
Normal file
16
src/tools/codeeditor/notificationcenter.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef NOTIFICATIONCENTER_HPP
|
||||
#define NOTIFICATIONCENTER_HPP
|
||||
|
||||
#include <eepp/ee.hpp>
|
||||
|
||||
class NotificationCenter {
|
||||
public:
|
||||
NotificationCenter( UILayout* layout );
|
||||
|
||||
UITextView* addNotification( const String& text );
|
||||
|
||||
protected:
|
||||
UILayout* mLayout{ nullptr };
|
||||
};
|
||||
|
||||
#endif // NOTIFICATIONCENTER_HPP
|
||||
Reference in New Issue
Block a user