diff --git a/include/eepp/scene/event.hpp b/include/eepp/scene/event.hpp index fc1f7a0c8..68913af37 100644 --- a/include/eepp/scene/event.hpp +++ b/include/eepp/scene/event.hpp @@ -98,6 +98,7 @@ class EE_API Event { OnWindowAdded, OnWindowRemoved, OnItemValueChange, + OnCursorPosChangeInteresting, OnCopy, NoEvent = eeINDEX_NOT_FOUND }; diff --git a/include/eepp/system.hpp b/include/eepp/system.hpp index c7508e05c..6c88a508f 100644 --- a/include/eepp/system.hpp +++ b/include/eepp/system.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/include/eepp/system/scopedop.hpp b/include/eepp/system/scopedop.hpp new file mode 100644 index 000000000..7298df868 --- /dev/null +++ b/include/eepp/system/scopedop.hpp @@ -0,0 +1,41 @@ +#ifndef EE_SYSTEM_SCOPEDOP_HPP +#define EE_SYSTEM_SCOPEDOP_HPP + +#include + +namespace EE { namespace System { + +class ScopedOp { + public: + explicit ScopedOp( std::function startOp, std::function endOp = nullptr ) : + mEndOp( endOp ) { + if ( startOp ) + startOp(); + } + + ~ScopedOp() { + if ( mEndOp ) + mEndOp(); + } + + private: + std::function mEndOp; +}; + +class BoolScopedOp { + public: + explicit BoolScopedOp( bool& boolRef ) : boolRef( boolRef ) {} + + explicit BoolScopedOp( bool& boolRef, bool initialVal ) : boolRef( boolRef ) { + boolRef = initialVal; + } + + ~BoolScopedOp() { boolRef = !boolRef; } + + private: + bool& boolRef; +}; + +}} // namespace EE::System + +#endif // EE_SYSTEM_SCOPEDOP_HPP diff --git a/include/eepp/ui/doc/textdocument.hpp b/include/eepp/ui/doc/textdocument.hpp index 333af2e2c..1578c6e36 100644 --- a/include/eepp/ui/doc/textdocument.hpp +++ b/include/eepp/ui/doc/textdocument.hpp @@ -74,6 +74,7 @@ class EE_API TextDocument { virtual void onDocumentTextChanged( const DocumentContentChange& ) = 0; virtual void onDocumentUndoRedo( const UndoRedo& eventType ) = 0; virtual void onDocumentCursorChange( const TextPosition& ) = 0; + virtual void onDocumentInterestingCursorChange( const TextPosition& ){}; virtual void onDocumentSelectionChange( const TextRange& ) = 0; virtual void onDocumentLineCountChange( const size_t& lastCount, const size_t& newCount ) = 0; @@ -245,7 +246,7 @@ class EE_API TextDocument { void moveTo( int columnOffset ); - void textInput( const String& text ); + void textInput( const String& text, bool mightBeInteresting = true ); void registerClient( Client* client ); @@ -600,6 +601,8 @@ class EE_API TextDocument { bool mDeleteOnClose{ false }; bool mMightBeBinary{ false }; bool mHAsCpp{ false }; + bool mLastCursorChangeWasInteresting{ false }; + bool mDoingTextInput{ false }; std::vector> mAutoCloseBracketsPairs; Uint32 mIndentWidth{ 4 }; IndentType mIndentType{ IndentType::IndentTabs }; @@ -650,6 +653,8 @@ class EE_API TextDocument { void notifiyDocumenLineMove( const Int64& fromLine, const Int64& numLines ); + void notifyInterstingCursorChange( TextPosition selection ); + void insertAtStartOfSelectedLines( const String& text, bool skipEmpty ); void removeFromStartOfSelectedLines( const String& text, bool skipEmpty, diff --git a/include/eepp/ui/tools/uicodeeditorsplitter.hpp b/include/eepp/ui/tools/uicodeeditorsplitter.hpp index 391004615..90af20dad 100644 --- a/include/eepp/ui/tools/uicodeeditorsplitter.hpp +++ b/include/eepp/ui/tools/uicodeeditorsplitter.hpp @@ -45,6 +45,7 @@ class EE_API UICodeEditorSplitter { static std::vector getUnlockedCommands(); static UICodeEditorSplitter* New( UICodeEditorSplitter::Client* client, UISceneNode* sceneNode, + std::shared_ptr = nullptr, const std::vector& colorSchemes = {}, const std::string& initColorScheme = "" ); @@ -73,6 +74,8 @@ class EE_API UICodeEditorSplitter { UITabWidget* tabWidgetFromEditor( UICodeEditor* editor ) const; + UITab* tabFromEditor( UICodeEditor* editor ) const; + UITabWidget* tabWidgetFromWidget( UIWidget* widget ) const; UISplitter* splitterFromEditor( UICodeEditor* editor ) const; @@ -103,21 +106,19 @@ class EE_API UICodeEditorSplitter { bool loadFileFromPath( const std::string& path, UICodeEditor* codeEditor = nullptr ); - void loadAsyncFileFromPath( const std::string& path, std::shared_ptr pool, - UICodeEditor* codeEditor = nullptr, + void loadAsyncFileFromPath( const std::string& path, UICodeEditor* codeEditor = nullptr, std::function onLoaded = std::function() ); std::pair loadFileFromPathInNewTab( const std::string& path ); void loadAsyncFileFromPathInNewTab( - const std::string& path, std::shared_ptr pool, - std::function onLoaded = - std::function() ); + const std::string& path, std::function onLoaded = + std::function() ); void loadAsyncFileFromPathInNewTab( - const std::string& path, std::shared_ptr pool, - std::function onLoaded, UITabWidget* tabWidget ); + const std::string& path, std::function onLoaded, + UITabWidget* tabWidget ); void removeUnusedTab( UITabWidget* tabWidge, bool destroyOwnedNode = true, bool immediateCloset = true ); @@ -215,10 +216,10 @@ class EE_API UICodeEditorSplitter { // T must implement setCommand( const std::string& command, const std::function& func ) template void registerSplitterCommands( T& t ) { - t.setCommand( "switch-to-previous-split", [&] { switchPreviousSplit( mCurWidget ); } ); - t.setCommand( "switch-to-next-split", [&] { switchNextSplit( mCurWidget ); } ); - t.setCommand( "close-tab", [&] { tryTabClose( mCurWidget ); } ); - t.setCommand( "create-new", [&] { + t.setCommand( "switch-to-previous-split", [this] { switchPreviousSplit( mCurWidget ); } ); + t.setCommand( "switch-to-next-split", [this] { switchNextSplit( mCurWidget ); } ); + t.setCommand( "close-tab", [this] { tryTabClose( mCurWidget ); } ); + t.setCommand( "create-new", [this] { auto d = createCodeEditorInTabWidget( tabWidgetFromWidget( mCurWidget ) ); if ( d.first != nullptr && d.second != nullptr ) { d.first->getTabWidget()->setTabSelected( d.first ); @@ -228,7 +229,7 @@ class EE_API UICodeEditorSplitter { if ( d.first == nullptr || d.second == nullptr ) Log::error( "Couldn't createCodeEditorInTabWidget in create-new command" ); } ); - t.setCommand( "next-tab", [&] { + t.setCommand( "next-tab", [this] { UITabWidget* tabWidget = tabWidgetFromWidget( mCurWidget ); if ( tabWidget && tabWidget->getTabCount() > 1 ) { UITab* tab = (UITab*)mCurWidget->getData(); @@ -236,7 +237,7 @@ class EE_API UICodeEditorSplitter { switchToTab( ( tabIndex + 1 ) % tabWidget->getTabCount() ); } } ); - t.setCommand( "previous-tab", [&] { + t.setCommand( "previous-tab", [this] { UITabWidget* tabWidget = tabWidgetFromWidget( mCurWidget ); if ( tabWidget && tabWidget->getTabCount() > 1 ) { UITab* tab = (UITab*)mCurWidget->getData(); @@ -249,31 +250,31 @@ class EE_API UICodeEditorSplitter { for ( int i = 1; i <= 10; i++ ) t.setCommand( String::format( "switch-to-tab-%d", i ), [&, i] { switchToTab( i - 1 ); } ); - t.setCommand( "switch-to-first-tab", [&] { + t.setCommand( "switch-to-first-tab", [this] { UITabWidget* tabWidget = tabWidgetFromWidget( mCurWidget ); if ( tabWidget && tabWidget->getTabCount() ) { switchToTab( 0 ); } } ); - t.setCommand( "switch-to-last-tab", [&] { + t.setCommand( "switch-to-last-tab", [this] { UITabWidget* tabWidget = tabWidgetFromWidget( mCurWidget ); if ( tabWidget && tabWidget->getTabCount() ) { switchToTab( tabWidget->getTabCount() - 1 ); } } ); - t.setCommand( "split-right", [&] { + t.setCommand( "split-right", [this] { split( SplitDirection::Right, mCurWidget, curEditorExistsAndFocused() ); } ); - t.setCommand( "split-bottom", [&] { + t.setCommand( "split-bottom", [this] { split( SplitDirection::Bottom, mCurWidget, curEditorExistsAndFocused() ); } ); - t.setCommand( "split-left", [&] { + t.setCommand( "split-left", [this] { split( SplitDirection::Left, mCurWidget, curEditorExistsAndFocused() ); } ); - t.setCommand( "split-top", [&] { + t.setCommand( "split-top", [this] { split( SplitDirection::Top, mCurWidget, curEditorExistsAndFocused() ); } ); - t.setCommand( "split-swap", [&] { + t.setCommand( "split-swap", [this] { if ( UISplitter* splitter = splitterFromWidget( mCurWidget ) ) splitter->swap(); } ); @@ -287,8 +288,25 @@ class EE_API UICodeEditorSplitter { UIOrientation getMainSplitOrientation() const; + void addCurrentPositionToNavigationHistory(); + + void addEditorPositionToNavigationHistory( UICodeEditor* editor ); + + void updateCurrentPositionInNavigationHistory(); + + void goBackInNavigationHistory(); + + void goForwardInNavigationHistory(); + + void clearNavigationHistory(); + + std::shared_ptr getThreadPool() const; + + void setThreadPool( const std::shared_ptr& threadPool ); + protected: UISceneNode* mUISceneNode{ nullptr }; + std::shared_ptr mThreadPool; UICodeEditor* mCurEditor{ nullptr }; UIWidget* mCurWidget{ nullptr }; std::map mColorSchemes; @@ -301,8 +319,16 @@ class EE_API UICodeEditorSplitter { UICodeEditor* mAboutToAddEditor{ nullptr }; UIMessageBox* mTryCloseMsgBox{ nullptr }; Mutex mTabWidgetMutex; + struct NavigationRecord { + std::string path; + TextPosition pos; + }; + size_t mNavigationHistoryMaxSize{ 100 }; + std::vector mNavigationHistory; + size_t mNavigationHistoryPos{ std::numeric_limits::max() }; UICodeEditorSplitter( UICodeEditorSplitter::Client* client, UISceneNode* sceneNode, + std::shared_ptr threadPool, const std::vector& colorSchemes, const std::string& initColorScheme ); diff --git a/include/eepp/ui/uicodeeditor.hpp b/include/eepp/ui/uicodeeditor.hpp index b85896c8a..1717851b9 100644 --- a/include/eepp/ui/uicodeeditor.hpp +++ b/include/eepp/ui/uicodeeditor.hpp @@ -773,6 +773,8 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { virtual void onDocumentLineCountChange( const size_t& lastCount, const size_t& newCount ); + virtual void onDocumentInterestingCursorChange( const TextPosition& ); + virtual void onDocumentLineChanged( const Int64& lineNumber ); virtual void onDocumentUndoRedo( const TextDocument::UndoRedo& ); diff --git a/include/eepp/ui/uitab.hpp b/include/eepp/ui/uitab.hpp index ea11201fb..08083341d 100644 --- a/include/eepp/ui/uitab.hpp +++ b/include/eepp/ui/uitab.hpp @@ -17,6 +17,8 @@ class EE_API UITab : public UISelectButton { void setOwnedWidget( Node* ownedWidget ); + void setTabSelected(); + virtual ~UITab(); virtual Uint32 getType() const; diff --git a/include/eepp/ui/uitreeview.hpp b/include/eepp/ui/uitreeview.hpp index de95f0dd3..2a3e9e051 100644 --- a/include/eepp/ui/uitreeview.hpp +++ b/include/eepp/ui/uitreeview.hpp @@ -63,7 +63,7 @@ class EE_API UITreeViewCell : public UITableCell { mTextBox->setElementTag( mTag + "::text" ); mIcon->setElementTag( mTag + "::icon" ); mInnerWidgetOrientation = InnerWidgetOrientation::WidgetIconTextBox; - auto cb = [&]( const Event* ) { updateLayout(); }; + auto cb = [this]( const Event* ) { updateLayout(); }; mImage = UIImage::NewWithTag( mTag + "::expander" ); mImage->setScaleType( UIScaleType::FitInside ) ->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ) diff --git a/include/eepp/version.hpp b/include/eepp/version.hpp index 846d644c4..1ebc43347 100644 --- a/include/eepp/version.hpp +++ b/include/eepp/version.hpp @@ -6,7 +6,7 @@ #define EEPP_MAJOR_VERSION 2 #define EEPP_MINOR_VERSION 6 -#define EEPP_PATCH_LEVEL 0 +#define EEPP_PATCH_LEVEL 1 #define EEPP_CODENAME "Anathapindika" /** The compiled version of the library */ diff --git a/projects/linux/ee.files b/projects/linux/ee.files index e981615d6..3550c633c 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -263,6 +263,7 @@ ../../include/eepp/system/resourceloader.hpp ../../include/eepp/system/resourcemanager.hpp ../../include/eepp/system/scopedbuffer.hpp +../../include/eepp/system/scopedop.hpp ../../include/eepp/system/singleton.hpp ../../include/eepp/system/sys.hpp ../../include/eepp/system/thread.hpp @@ -1206,7 +1207,6 @@ ../../src/tools/ecode/projectdirectorytree.hpp ../../src/tools/ecode/projectsearch.cpp ../../src/tools/ecode/projectsearch.hpp -../../src/tools/ecode/scopedop.hpp ../../src/tools/ecode/settingsmenu.cpp ../../src/tools/ecode/settingsmenu.hpp ../../src/tools/ecode/statusbuildoutputcontroller.cpp diff --git a/src/eepp/graphics/renderer/renderergl3.cpp b/src/eepp/graphics/renderer/renderergl3.cpp index 1c4a4e346..29ae5fdae 100644 --- a/src/eepp/graphics/renderer/renderergl3.cpp +++ b/src/eepp/graphics/renderer/renderergl3.cpp @@ -89,7 +89,7 @@ void RendererGL3::init() { mShaders[EEGL3_SHADER_BASE] = ShaderProgram::New( vs.c_str(), vs.size(), fs.c_str(), fs.size() ); mShaders[EEGL3_SHADER_BASE]->setReloadCb( - [&]( ShaderProgram* sp ) { reloadShader( sp ); } ); + [this]( ShaderProgram* sp ) { reloadShader( sp ); } ); Shader::ensure( true ); diff --git a/src/eepp/graphics/textureatlasloader.cpp b/src/eepp/graphics/textureatlasloader.cpp index 1e2b97aae..4fecbbdf3 100644 --- a/src/eepp/graphics/textureatlasloader.cpp +++ b/src/eepp/graphics/textureatlasloader.cpp @@ -162,7 +162,7 @@ void TextureAtlasLoader::loadFromStream( IOStream& IOS ) { if ( !mSkipResourceLoad ) { mIsLoading = true; - mRL.load( [&]( ResourceLoader* ) { + mRL.load( [this]( ResourceLoader* ) { if ( !mLoaded ) { createTextureRegions(); } diff --git a/src/eepp/system/resourceloader.cpp b/src/eepp/system/resourceloader.cpp index 9da67b1dc..628d55b2f 100644 --- a/src/eepp/system/resourceloader.cpp +++ b/src/eepp/system/resourceloader.cpp @@ -109,7 +109,7 @@ void ResourceLoader::taskRunner() { auto pool = ThreadPool::createUnique( eemin( mThreads, (Uint32)mTasks.size() ) ); for ( auto& task : mTasks ) { - pool->run( task, [&]( const auto& ) { mTotalLoaded++; } ); + pool->run( task, [this]( const auto& ) { mTotalLoaded++; } ); } } diff --git a/src/eepp/ui/abstract/uiabstracttableview.cpp b/src/eepp/ui/abstract/uiabstracttableview.cpp index 006ed9011..94b31c1f0 100644 --- a/src/eepp/ui/abstract/uiabstracttableview.cpp +++ b/src/eepp/ui/abstract/uiabstracttableview.cpp @@ -423,7 +423,7 @@ UITableRow* UIAbstractTableView::createRow() { rowWidget->setParent( this ); rowWidget->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ); rowWidget->reloadStyle( true, true, true ); - rowWidget->addEventListener( Event::MouseDown, [&]( const Event* event ) { + rowWidget->addEventListener( Event::MouseDown, [this]( const Event* event ) { if ( !( event->asMouseEvent()->getFlags() & EE_BUTTON_LMASK ) || !isRowSelection() ) return; auto index = event->getNode()->asType()->getCurIndex(); @@ -701,7 +701,7 @@ Uint32 UIAbstractTableView::onTextInput( const TextInputEvent& event ) { if ( mSearchTextAction ) removeAction( mSearchTextAction ); mSearchTextAction = Actions::Runnable::New( - [&] { + [this] { mSearchTextAction = nullptr; mSearchText = ""; }, diff --git a/src/eepp/ui/css/stylesheetspecification.cpp b/src/eepp/ui/css/stylesheetspecification.cpp index 936359adc..68370b006 100644 --- a/src/eepp/ui/css/stylesheetspecification.cpp +++ b/src/eepp/ui/css/stylesheetspecification.cpp @@ -842,8 +842,9 @@ void StyleSheetSpecification::registerDefaultShorthandParsers() { return properties; }; - mShorthandParsers["background"] = [&]( const ShorthandDefinition* shorthand, - std::string value ) -> std::vector { + mShorthandParsers["background"] = + [this]( const ShorthandDefinition* shorthand, + std::string value ) -> std::vector { value = String::trim( value ); if ( value.empty() || "none" == value ) return {}; @@ -888,8 +889,8 @@ void StyleSheetSpecification::registerDefaultShorthandParsers() { return properties; }; - mShorthandParsers["border"] = [&]( const ShorthandDefinition* shorthand, - std::string value ) -> std::vector { + mShorthandParsers["border"] = [this]( const ShorthandDefinition* shorthand, + std::string value ) -> std::vector { value = String::trim( value ); if ( value.empty() || "none" == value ) return {}; @@ -933,8 +934,8 @@ void StyleSheetSpecification::registerDefaultShorthandParsers() { }; mShorthandParsers["color-vector2"] = - [&]( const ShorthandDefinition* shorthand, - std::string value ) -> std::vector { + []( const ShorthandDefinition* shorthand, + std::string value ) -> std::vector { value = String::trim( value ); if ( value.empty() || "none" == value ) return {}; diff --git a/src/eepp/ui/doc/textdocument.cpp b/src/eepp/ui/doc/textdocument.cpp index 9bd86e05e..ee9713fde 100644 --- a/src/eepp/ui/doc/textdocument.cpp +++ b/src/eepp/ui/doc/textdocument.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -551,6 +552,7 @@ bool TextDocument::save( const std::string& path ) { bool TextDocument::save( IOStream& stream, bool keepUndoRedoStatus ) { if ( !stream.isOpen() || mLines.empty() ) return false; + BoolScopedOp op( mDoingTextInput, true ); const std::string whitespaces( " \t\f\v\n\r" ); if ( mIsBOM ) { unsigned char bom[] = { 0xEF, 0xBB, 0xBF }; @@ -700,6 +702,11 @@ void TextDocument::setSelection( const size_t& cursorIdx, TextPosition start, Te mSelection[cursorIdx].set( start, end ); notifyCursorChanged( mSelection[cursorIdx].start() ); notifySelectionChanged( mSelection[cursorIdx] ); + + if ( !mDoingTextInput && mLastCursorChangeWasInteresting ) { + notifyInterstingCursorChange( mSelection[cursorIdx].start() ); + mLastCursorChangeWasInteresting = false; + } } } @@ -1105,7 +1112,7 @@ bool TextDocument::replaceLine( const Int64& lineNum, const String& text ) { if ( lineNum >= 0 && lineNum < (Int64)mLines.size() ) { TextRange oldSelection = getSelection(); setSelection( { startOfLine( { lineNum, 0 } ), endOfLine( { lineNum, 0 } ) } ); - textInput( text ); + textInput( text, false ); setSelection( oldSelection ); return true; } @@ -1259,6 +1266,7 @@ TextRange TextDocument::getDocRange() const { void TextDocument::deleteTo( const size_t& cursorIdx, int offset ) { eeASSERT( cursorIdx < mSelection.size() ); + BoolScopedOp op( mDoingTextInput, true ); TextPosition cursorPos = mSelection[cursorIdx].normalized().start(); if ( mSelection[cursorIdx].hasSelection() ) { remove( cursorIdx, getSelectionIndex( cursorIdx ) ); @@ -1273,6 +1281,7 @@ void TextDocument::deleteTo( const size_t& cursorIdx, int offset ) { } void TextDocument::deleteSelection( const size_t& cursorIdx ) { + BoolScopedOp op( mDoingTextInput, true ); TextPosition cursorPos = getSelectionIndex( cursorIdx ).normalized().start(); remove( cursorIdx, getSelectionIndex( cursorIdx ) ); setSelection( cursorIdx, cursorPos ); @@ -1366,7 +1375,9 @@ std::vector TextDocument::autoCloseBrackets( const String& text ) { return inserted; } -void TextDocument::textInput( const String& text ) { +void TextDocument::textInput( const String& text, bool mightBeInteresting ) { + BoolScopedOp op( mDoingTextInput, true ); + if ( mAutoCloseBrackets && 1 == text.size() ) { auto inserted = autoCloseBrackets( text ); @@ -1379,6 +1390,7 @@ void TextDocument::textInput( const String& text ) { deleteTo( i, 0 ); setSelection( i, insert( i, getSelectionIndex( i ).start(), text ) ); } + return; } } @@ -1401,6 +1413,9 @@ void TextDocument::textInput( const String& text ) { setSelection( i, insert( i, getSelectionIndex( i ).start(), text ) ); } } + + if ( mightBeInteresting ) + mLastCursorChangeWasInteresting = true; } void TextDocument::registerClient( Client* client ) { @@ -1559,6 +1574,7 @@ void TextDocument::deleteToNextWord() { } void TextDocument::deleteCurrentLine() { + BoolScopedOp op( mDoingTextInput, true ); for ( size_t i = 0; i < mSelection.size(); ++i ) { if ( mSelection[i].hasSelection() ) { deleteSelection( i ); @@ -1755,6 +1771,7 @@ void TextDocument::newLineAbove() { } void TextDocument::insertAtStartOfSelectedLines( const String& text, bool skipEmpty ) { + BoolScopedOp op( mDoingTextInput, true ); TextPosition prevStart = getSelection().start(); TextRange range = getSelection( true ); bool swap = prevStart != range.start(); @@ -1770,6 +1787,7 @@ void TextDocument::insertAtStartOfSelectedLines( const String& text, bool skipEm void TextDocument::removeFromStartOfSelectedLines( const String& text, bool skipEmpty, bool removeExtraSpaces ) { + BoolScopedOp op( mDoingTextInput, true ); TextPosition prevStart = getSelection().start(); TextRange range = getSelection( true ); bool swap = prevStart != range.start(); @@ -1826,6 +1844,7 @@ void TextDocument::unindent() { } void TextDocument::moveLinesUp() { + BoolScopedOp op( mDoingTextInput, true ); for ( size_t i = 0; i < mSelection.size(); ++i ) { TextRange range = getSelectionIndex( i ).normalized(); bool swap = getSelectionIndex( i ).normalized() != getSelection(); @@ -1841,6 +1860,7 @@ void TextDocument::moveLinesUp() { } void TextDocument::moveLinesDown() { + BoolScopedOp op( mDoingTextInput, true ); for ( size_t i = 0; i < mSelection.size(); ++i ) { TextRange range = getSelectionIndex( i ).normalized(); bool swap = getSelectionIndex( i ).normalized() != getSelection(); @@ -1884,6 +1904,7 @@ void TextDocument::setIndentWidth( const Uint32& tabWidth ) { } void TextDocument::deleteTo( const size_t& cursorIdx, TextPosition position ) { + BoolScopedOp op( mDoingTextInput, true ); TextPosition cursorPos = getSelectionIndex( cursorIdx ).normalized().start(); if ( getSelectionIndex( cursorIdx ).hasSelection() ) { remove( cursorIdx, getSelectionIndex( cursorIdx ) ); @@ -2574,6 +2595,15 @@ void TextDocument::notifyCursorChanged( TextPosition selection ) { } } +void TextDocument::notifyInterstingCursorChange( TextPosition selection ) { + if ( !selection.isValid() ) + selection = getSelection().start(); + Lock l( mClientsMutex ); + for ( auto& client : mClients ) { + client->onDocumentInterestingCursorChange( selection ); + } +} + void TextDocument::notifySelectionChanged( TextRange selection ) { if ( !selection.isValid() ) selection = getSelection(); diff --git a/src/eepp/ui/models/model.cpp b/src/eepp/ui/models/model.cpp index 1bf5e10f7..834f4f399 100644 --- a/src/eepp/ui/models/model.cpp +++ b/src/eepp/ui/models/model.cpp @@ -9,7 +9,7 @@ void Model::onModelUpdate( unsigned flags ) { mOnUpdate(); for ( auto& client : mClients ) client->onModelUpdated( flags ); - forEachView( [&]( UIAbstractView* view ) { view->onModelUpdate( flags ); } ); + forEachView( [flags]( UIAbstractView* view ) { view->onModelUpdate( flags ); } ); } void Model::forEachView( std::function callback ) { @@ -30,7 +30,7 @@ void Model::unregisterClient( Model::Client* client ) { } void Model::refreshView() { - forEachView( [&]( UIAbstractView* view ) { view->invalidateDraw(); } ); + forEachView( []( UIAbstractView* view ) { view->invalidateDraw(); } ); } void Model::registerView( UIAbstractView* view ) { diff --git a/src/eepp/ui/models/sortingproxymodel.cpp b/src/eepp/ui/models/sortingproxymodel.cpp index 7590e1bea..1b2fc8c05 100644 --- a/src/eepp/ui/models/sortingproxymodel.cpp +++ b/src/eepp/ui/models/sortingproxymodel.cpp @@ -25,8 +25,8 @@ void SortingProxyModel::invalidate( unsigned int flags ) { mMappings.clear(); // FIXME: This is really harsh, but without precise invalidation, not much we can do. - forEachView( [&]( UIAbstractView* view ) { view->getSelection().clear( false ); } ); - forEachView( [&]( UIAbstractView* view ) { view->notifySelectionChange(); } ); + forEachView( []( UIAbstractView* view ) { view->getSelection().clear( false ); } ); + forEachView( []( UIAbstractView* view ) { view->notifySelectionChange(); } ); } onModelUpdate( flags ); } diff --git a/src/eepp/ui/tools/textureatlaseditor.cpp b/src/eepp/ui/tools/textureatlaseditor.cpp index 125224d16..94935b823 100644 --- a/src/eepp/ui/tools/textureatlaseditor.cpp +++ b/src/eepp/ui/tools/textureatlaseditor.cpp @@ -456,7 +456,7 @@ void TextureAtlasEditor::onTextureAtlasLoaded( TextureAtlasLoader* textureAtlasL mTextureAtlasLoader = textureAtlasLoader; if ( mTextureAtlasLoader->isLoaded() ) { - mUIContainer->runOnMainThread( [&] { updateWidgets(); } ); + mUIContainer->runOnMainThread( [this] { updateWidgets(); } ); } } diff --git a/src/eepp/ui/tools/textureatlasnew.cpp b/src/eepp/ui/tools/textureatlasnew.cpp index 5084e03b7..f78d431ec 100644 --- a/src/eepp/ui/tools/textureatlasnew.cpp +++ b/src/eepp/ui/tools/textureatlasnew.cpp @@ -111,7 +111,7 @@ TextureAtlasNew::TextureAtlasNew( TGCreateCb NewTGCb ) : mUIWindow( NULL ), mNew mUIWindow->find( "cancelButton" ) ->addEventListener( Event::MouseClick, cb::Make1( this, &TextureAtlasNew::cancelClick ) ); - container->addEventListener( Event::OnLayoutUpdate, [&]( const Event* event ) { + container->addEventListener( Event::OnLayoutUpdate, [this]( const Event* event ) { mUIWindow->setMinWindowSize( event->getNode()->getSize() ); mUIWindow->center(); mUIWindow->show(); diff --git a/src/eepp/ui/tools/uicodeeditorsplitter.cpp b/src/eepp/ui/tools/uicodeeditorsplitter.cpp index 2e2413203..1eb4c9549 100644 --- a/src/eepp/ui/tools/uicodeeditorsplitter.cpp +++ b/src/eepp/ui/tools/uicodeeditorsplitter.cpp @@ -44,6 +44,8 @@ UICodeEditorSplitter::getLocalDefaultKeybindings() { { { KEY_8, KeyMod::getDefaultModifier() }, "switch-to-tab-8" }, { { KEY_9, KeyMod::getDefaultModifier() }, "switch-to-tab-9" }, { { KEY_0, KeyMod::getDefaultModifier() }, "switch-to-last-tab" }, + { { KEY_LEFT, KEYMOD_LALT }, "editor-go-back" }, + { { KEY_RIGHT, KEYMOD_LALT }, "editor-go-forward" }, }; } @@ -67,16 +69,19 @@ std::vector UICodeEditorSplitter::getUnlockedCommands() { UICodeEditorSplitter* UICodeEditorSplitter::New( UICodeEditorSplitter::Client* client, UISceneNode* sceneNode, + std::shared_ptr threadPool, const std::vector& colorSchemes, const std::string& initColorScheme ) { - return eeNew( UICodeEditorSplitter, ( client, sceneNode, colorSchemes, initColorScheme ) ); + return eeNew( UICodeEditorSplitter, + ( client, sceneNode, threadPool, colorSchemes, initColorScheme ) ); } UICodeEditorSplitter::UICodeEditorSplitter( UICodeEditorSplitter::Client* client, UISceneNode* sceneNode, + std::shared_ptr threadPool, const std::vector& colorSchemes, const std::string& initColorScheme ) : - mUISceneNode( sceneNode ), mClient( client ) { + mUISceneNode( sceneNode ), mThreadPool( threadPool ), mClient( client ) { if ( !colorSchemes.empty() ) { for ( auto& colorScheme : colorSchemes ) mColorSchemes.insert( std::make_pair( colorScheme.getName(), colorScheme ) ); @@ -97,6 +102,12 @@ UITabWidget* UICodeEditorSplitter::tabWidgetFromEditor( UICodeEditor* editor ) c return nullptr; } +UITab* UICodeEditorSplitter::tabFromEditor( UICodeEditor* editor ) const { + if ( editor ) + return (UITab*)editor->getData(); + return nullptr; +} + UITabWidget* UICodeEditorSplitter::tabWidgetFromWidget( UIWidget* widget ) const { if ( widget ) return ( (UITab*)widget->getData() )->getTabWidget(); @@ -121,66 +132,66 @@ UICodeEditor* UICodeEditorSplitter::createCodeEditor() { UICodeEditor* editor = UICodeEditor::NewOpt( true, true ); TextDocument& doc = editor->getDocument(); /* document commands */ - doc.setCommand( "move-to-previous-line", [&] { + doc.setCommand( "move-to-previous-line", [this] { if ( mCurEditor ) mCurEditor->moveToPreviousLine(); } ); - doc.setCommand( "move-to-next-line", [&] { + doc.setCommand( "move-to-next-line", [this] { if ( mCurEditor ) mCurEditor->moveToNextLine(); } ); - doc.setCommand( "select-to-previous-line", [&] { + doc.setCommand( "select-to-previous-line", [this] { if ( mCurEditor ) mCurEditor->selectToPreviousLine(); } ); - doc.setCommand( "select-to-next-line", [&] { + doc.setCommand( "select-to-next-line", [this] { if ( mCurEditor ) mCurEditor->selectToNextLine(); } ); - doc.setCommand( "move-scroll-up", [&] { + doc.setCommand( "move-scroll-up", [this] { if ( mCurEditor ) mCurEditor->moveScrollUp(); } ); - doc.setCommand( "move-scroll-down", [&] { + doc.setCommand( "move-scroll-down", [this] { if ( mCurEditor ) mCurEditor->moveScrollDown(); } ); - doc.setCommand( "indent", [&] { + doc.setCommand( "indent", [this] { if ( mCurEditor ) mCurEditor->indent(); } ); - doc.setCommand( "unindent", [&] { + doc.setCommand( "unindent", [this] { if ( mCurEditor ) mCurEditor->unindent(); } ); - doc.setCommand( "copy", [&] { + doc.setCommand( "copy", [this] { if ( mCurEditor ) mCurEditor->copy(); } ); - doc.setCommand( "cut", [&] { + doc.setCommand( "cut", [this] { if ( mCurEditor ) mCurEditor->cut(); } ); - doc.setCommand( "paste", [&] { + doc.setCommand( "paste", [this] { if ( mCurEditor ) mCurEditor->paste(); } ); - doc.setCommand( "font-size-grow", [&] { zoomIn(); } ); - doc.setCommand( "font-size-shrink", [&] { zoomOut(); } ); - doc.setCommand( "font-size-reset", [&] { zoomReset(); } ); - doc.setCommand( "lock", [&] { + doc.setCommand( "font-size-grow", [this] { zoomIn(); } ); + doc.setCommand( "font-size-shrink", [this] { zoomOut(); } ); + doc.setCommand( "font-size-reset", [this] { zoomReset(); } ); + doc.setCommand( "lock", [this] { if ( mCurEditor ) { mCurEditor->setLocked( true ); mClient->onDocumentStateChanged( mCurEditor, mCurEditor->getDocument() ); } } ); - doc.setCommand( "unlock", [&] { + doc.setCommand( "unlock", [this] { if ( mCurEditor ) { mCurEditor->setLocked( false ); mClient->onDocumentStateChanged( mCurEditor, mCurEditor->getDocument() ); } } ); - doc.setCommand( "lock-toggle", [&] { + doc.setCommand( "lock-toggle", [this] { if ( mCurEditor ) { mCurEditor->setLocked( !mCurEditor->isLocked() ); mClient->onDocumentStateChanged( mCurEditor, mCurEditor->getDocument() ); @@ -191,13 +202,13 @@ UICodeEditor* UICodeEditorSplitter::createCodeEditor() { /* document commands */ /* editor commands */ - doc.setCommand( "switch-to-previous-colorscheme", [&] { + doc.setCommand( "switch-to-previous-colorscheme", [this] { auto it = mColorSchemes.find( mCurrentColorScheme ); setColorScheme( it == mColorSchemes.begin() ? mColorSchemes.rbegin()->first : ( --it )->first ); } ); - doc.setCommand( "switch-to-next-colorscheme", [&] { + doc.setCommand( "switch-to-next-colorscheme", [this] { auto it = mColorSchemes.find( mCurrentColorScheme ); if ( ++it != mColorSchemes.end() ) mCurrentColorScheme = it->first; @@ -205,33 +216,35 @@ UICodeEditor* UICodeEditorSplitter::createCodeEditor() { mCurrentColorScheme = mColorSchemes.begin()->first; applyColorScheme( mColorSchemes[mCurrentColorScheme] ); } ); - doc.setCommand( "open-containing-folder", [&] { + doc.setCommand( "open-containing-folder", [this] { if ( mCurEditor ) mCurEditor->openContainingFolder(); } ); - doc.setCommand( "copy-file-path", [&] { + doc.setCommand( "copy-file-path", [this] { if ( mCurEditor ) mCurEditor->copyFilePath(); } ); + doc.setCommand( "editor-go-back", [this] { goBackInNavigationHistory(); } ); + doc.setCommand( "editor-go-forward", [this] { goForwardInNavigationHistory(); } ); /* editor commands */ /* Splitter commands */ registerSplitterCommands( doc ); /* Splitter commands */ - editor->addEventListener( Event::OnFocus, [&]( const Event* event ) { + editor->addEventListener( Event::OnFocus, [this]( const Event* event ) { setCurrentWidget( event->getNode()->asType() ); } ); - editor->addEventListener( Event::OnTextChanged, [&]( const Event* event ) { + editor->addEventListener( Event::OnTextChanged, [this]( const Event* event ) { mClient->onDocumentModified( event->getNode()->asType(), event->getNode()->asType()->getDocument() ); } ); - editor->addEventListener( Event::OnSelectionChanged, [&]( const Event* event ) { + editor->addEventListener( Event::OnSelectionChanged, [this]( const Event* event ) { mClient->onDocumentSelectionChange( event->getNode()->asType(), event->getNode()->asType()->getDocument() ); } ); - editor->addEventListener( Event::OnCursorPosChange, [&]( const Event* event ) { + editor->addEventListener( Event::OnCursorPosChange, [this]( const Event* event ) { mClient->onDocumentCursorPosChange( event->getNode()->asType(), event->getNode()->asType()->getDocument() ); @@ -338,9 +351,15 @@ bool UICodeEditorSplitter::loadFileFromPath( const std::string& path, UICodeEdit } void UICodeEditorSplitter::loadAsyncFileFromPath( - const std::string& path, std::shared_ptr pool, UICodeEditor* codeEditor, + const std::string& path, UICodeEditor* codeEditor, std::function onLoaded ) { #if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN || defined( __EMSCRIPTEN_PTHREADS__ ) + if ( !mThreadPool ) { + Log::error( "UICodeEditorSplitter::loadAsyncFileFromPath loading file async " + "without thread pool." ); + loadFileFromPath( path ); + return; + } if ( FileSystem::isDirectory( path ) ) return; if ( nullptr == codeEditor ) @@ -359,7 +378,8 @@ void UICodeEditorSplitter::loadAsyncFileFromPath( } ); } else { codeEditor->loadAsyncFromFile( - path, pool, [&, codeEditor, path, onLoaded]( std::shared_ptr, bool ) { + path, mThreadPool, + [&, codeEditor, path, onLoaded]( std::shared_ptr, bool ) { mClient->onDocumentLoaded( codeEditor, path ); if ( onLoaded ) onLoaded( codeEditor, path ); @@ -395,8 +415,14 @@ UICodeEditorSplitter::loadFileFromPathInNewTab( const std::string& path ) { } void UICodeEditorSplitter::loadAsyncFileFromPathInNewTab( - const std::string& path, std::shared_ptr pool, - std::function onLoaded, UITabWidget* tabWidget ) { + const std::string& path, std::function onLoaded, + UITabWidget* tabWidget ) { + if ( !mThreadPool ) { + Log::error( "UICodeEditorSplitter::loadAsyncFileFromPathInNewTab loading file async " + "without thread pool." ); + loadFileFromPathInNewTab( path ); + return; + } auto d = createCodeEditorInTabWidget( tabWidget ); if ( d.first == nullptr || d.second == nullptr ) { if ( !mTabWidgets.empty() && mTabWidgets[0]->getTabCount() > 0 ) { @@ -408,13 +434,18 @@ void UICodeEditorSplitter::loadAsyncFileFromPathInNewTab( } } UITab* addedTab = d.first; - loadAsyncFileFromPath( path, pool, d.second, onLoaded ); + loadAsyncFileFromPath( path, d.second, onLoaded ); tabWidget->setTabSelected( addedTab ); } void UICodeEditorSplitter::loadAsyncFileFromPathInNewTab( - const std::string& path, std::shared_ptr pool, - std::function onLoaded ) { + const std::string& path, std::function onLoaded ) { + if ( !mThreadPool ) { + Log::error( "UICodeEditorSplitter::loadAsyncFileFromPathInNewTab loading file async " + "without thread pool." ); + loadFileFromPathInNewTab( path ); + return; + } auto d = createCodeEditorInTabWidget( tabWidgetFromWidget( mCurWidget ) ); if ( d.first == nullptr || d.second == nullptr ) { if ( !mTabWidgets.empty() && mTabWidgets[0]->getTabCount() > 0 ) { @@ -427,7 +458,7 @@ void UICodeEditorSplitter::loadAsyncFileFromPathInNewTab( } UITabWidget* tabWidget = d.first->getTabWidget(); UITab* addedTab = d.first; - loadAsyncFileFromPath( path, pool, d.second, onLoaded ); + loadAsyncFileFromPath( path, d.second, onLoaded ); tabWidget->setTabSelected( addedTab ); } @@ -463,7 +494,7 @@ UICodeEditorSplitter::createCodeEditorInTabWidget( UITabWidget* tabWidget ) { return std::make_pair( (UITab*)nullptr, (UICodeEditor*)nullptr ); UICodeEditor* editor = createCodeEditor(); mAboutToAddEditor = editor; - editor->addEventListener( Event::OnDocumentChanged, [&]( const Event* event ) { + editor->addEventListener( Event::OnDocumentChanged, [this]( const Event* event ) { mClient->onDocumentStateChanged( event->getNode()->asType(), event->getNode()->asType()->getDocument() ); } ); @@ -504,10 +535,10 @@ UICodeEditorSplitter::createWidgetInTabWidget( UITabWidget* tabWidget, UIWidget* return std::make_pair( (UITab*)nullptr, (UIWidget*)nullptr ); UITab* tab = tabWidget->add( tabName, widget ); widget->setData( (UintPtr)tab ); - widget->addEventListener( Event::OnFocus, [&]( const Event* event ) { + widget->addEventListener( Event::OnFocus, [this]( const Event* event ) { setCurrentWidget( event->getNode()->asType() ); } ); - widget->addEventListener( Event::OnTitleChange, [&]( const Event* event ) { + widget->addEventListener( Event::OnTitleChange, [this]( const Event* event ) { const TextEvent* tevent = static_cast( event ); UIWidget* widget = event->getNode()->asType(); UITabWidget* tabWidget = tabWidgetFromWidget( widget ); @@ -575,7 +606,7 @@ UITabWidget* UICodeEditorSplitter::createEditorWithTabWidget( Node* parent, bool tabWidget->setAllowDragAndDropTabs( true ); tabWidget->setAllowSwitchTabsInEmptySpaces( true ); tabWidget->setFocusTabBehavior( UITabWidget::FocusTabBehavior::FocusOrder ); - tabWidget->addEventListener( Event::OnTabSelected, [&]( const Event* event ) { + tabWidget->addEventListener( Event::OnTabSelected, [this]( const Event* event ) { UITabWidget* tabWidget = event->getNode()->asType(); if ( tabWidget->getTabSelected()->getOwnedWidget()->isType( UI_TYPE_CODEEDITOR ) ) { setCurrentEditor( @@ -584,14 +615,14 @@ UITabWidget* UICodeEditorSplitter::createEditorWithTabWidget( Node* parent, bool setCurrentWidget( tabWidget->getTabSelected()->getOwnedWidget()->asType() ); } } ); - tabWidget->setTabTryCloseCallback( [&]( UITab* tab ) -> bool { + tabWidget->setTabTryCloseCallback( [this]( UITab* tab ) -> bool { if ( tab->getOwnedWidget()->isType( UI_TYPE_CODEEDITOR ) ) { tryTabClose( tab->getOwnedWidget()->asType() ); return false; } return true; } ); - tabWidget->addEventListener( Event::OnTabClosed, [&]( const Event* event ) { + tabWidget->addEventListener( Event::OnTabClosed, [this]( const Event* event ) { onTabClosed( static_cast( event ) ); } ); auto editorData = createCodeEditorInTabWidget( tabWidget ); @@ -889,7 +920,7 @@ bool UICodeEditorSplitter::tryTabClose( UIWidget* widget ) { "Do you really want to close this tab?\nAll changes will be lost." ) ); mTryCloseMsgBox->addEventListener( Event::OnConfirm, [&, editor]( const Event* ) { closeTab( editor ); } ); - mTryCloseMsgBox->addEventListener( Event::OnClose, [&]( const Event* ) { + mTryCloseMsgBox->addEventListener( Event::OnClose, [this]( const Event* ) { mTryCloseMsgBox = nullptr; if ( mCurEditor ) mCurEditor->setFocus(); @@ -1149,6 +1180,140 @@ UIOrientation UICodeEditorSplitter::getMainSplitOrientation() const { return UIOrientation::Vertical; } +void UICodeEditorSplitter::addCurrentPositionToNavigationHistory() { + addEditorPositionToNavigationHistory( mCurEditor ); +} + +void UICodeEditorSplitter::addEditorPositionToNavigationHistory( UICodeEditor* editor ) { + if ( editor == nullptr || !editor->hasDocument() ) + return; + + auto doc = editor->getDocumentRef(); + if ( doc->isLoading() || doc->isUntitledEmpty() ) + return; + + if ( !mNavigationHistory.empty() && + doc->getFilePath() == mNavigationHistory[mNavigationHistory.size() - 1].path && + doc->getSelection().start() == mNavigationHistory[mNavigationHistory.size() - 1].pos ) { + return; + } + + NavigationRecord rec{ doc->getFilePath(), doc->getSelection().start() }; + mNavigationHistory.emplace_back( std::move( rec ) ); + mNavigationHistoryPos = mNavigationHistory.size() - 1; + + while ( mNavigationHistory.size() >= mNavigationHistoryMaxSize ) { + if ( mNavigationHistoryPos > mNavigationHistoryMaxSize / 2 ) { + mNavigationHistory.erase( mNavigationHistory.begin() ); + mNavigationHistoryPos--; + } else { + mNavigationHistory.pop_back(); + } + } +} + +void UICodeEditorSplitter::updateCurrentPositionInNavigationHistory() { + if ( mCurEditor == nullptr || !mCurEditor->hasDocument() ) + return; + + auto doc = mCurEditor->getDocumentRef(); + if ( doc->isLoading() || doc->isUntitledEmpty() ) + return; + + NavigationRecord* rec; + if ( mNavigationHistoryPos < mNavigationHistory.size() ) { + rec = &mNavigationHistory[mNavigationHistoryPos]; + } else { + mNavigationHistory.push_back( {} ); + rec = &mNavigationHistory[mNavigationHistory.size() - 1]; + } + + if ( ( mNavigationHistoryPos > 0 && mNavigationHistory.size() > 1 && + doc->getSelection().start() == mNavigationHistory[mNavigationHistoryPos - 1].pos ) || + ( mNavigationHistoryPos < mNavigationHistory.size() - 1 && + doc->getSelection().start() == mNavigationHistory[mNavigationHistoryPos + 1].pos ) ) { + return; // shouldn't happen + } + + rec->path = doc->getFilePath(); + rec->pos = doc->getSelection().start(); +} + +void UICodeEditorSplitter::goBackInNavigationHistory() { + updateCurrentPositionInNavigationHistory(); + while ( mNavigationHistoryPos > 0 ) { + mNavigationHistoryPos--; + + const auto& rec = mNavigationHistory[mNavigationHistoryPos]; + auto editor = findEditorFromPath( rec.path ); + if ( editor ) { + if ( !editor->hasDocument() || editor->getDocument().isLoading() ) + break; + editor->goToLine( rec.pos ); + auto tab = tabFromEditor( editor ); + if ( tab ) + tab->setTabSelected(); + break; + } else { + if ( !FileSystem::fileExists( rec.path ) ) { + mNavigationHistory.erase( mNavigationHistory.begin() + mNavigationHistoryPos ); + continue; + } else { + auto pos = rec.pos; + loadAsyncFileFromPathInNewTab( + rec.path, [pos]( UICodeEditor* editor, auto ) { editor->goToLine( pos ); } ); + break; + } + } + } +} + +void UICodeEditorSplitter::goForwardInNavigationHistory() { + updateCurrentPositionInNavigationHistory(); + if ( mNavigationHistoryPos >= mNavigationHistory.size() - 1 ) + return; + mNavigationHistoryPos++; + while ( mNavigationHistoryPos < mNavigationHistory.size() ) { + const auto& rec = mNavigationHistory[mNavigationHistoryPos]; + auto editor = findEditorFromPath( rec.path ); + + if ( editor ) { + if ( !editor->hasDocument() || editor->getDocument().isLoading() ) + break; + editor->goToLine( rec.pos ); + auto tab = tabFromEditor( editor ); + if ( tab ) + tab->setTabSelected(); + break; + } else { + if ( !FileSystem::fileExists( rec.path ) ) { + mNavigationHistory.erase( mNavigationHistory.begin() + mNavigationHistoryPos ); + continue; + } else { + auto pos = rec.pos; + loadAsyncFileFromPathInNewTab( + rec.path, [pos]( UICodeEditor* editor, auto ) { editor->goToLine( pos ); } ); + break; + } + } + } + if ( mNavigationHistoryPos >= mNavigationHistory.size() ) + mNavigationHistoryPos = eemax( mNavigationHistory.size(), 0UL ); +} + +void UICodeEditorSplitter::clearNavigationHistory() { + mNavigationHistory.clear(); + mNavigationHistoryPos = std::numeric_limits::max(); +} + +std::shared_ptr UICodeEditorSplitter::getThreadPool() const { + return mThreadPool; +} + +void UICodeEditorSplitter::setThreadPool( const std::shared_ptr& threadPool ) { + mThreadPool = threadPool; +} + bool UICodeEditorSplitter::curWidgetExists() const { bool found = false; forEachWidgetStoppable( [&]( UIWidget* widget ) { diff --git a/src/eepp/ui/tools/uicolorpicker.cpp b/src/eepp/ui/tools/uicolorpicker.cpp index 6a0e8bd87..db726f7a2 100644 --- a/src/eepp/ui/tools/uicolorpicker.cpp +++ b/src/eepp/ui/tools/uicolorpicker.cpp @@ -265,8 +265,8 @@ UIColorPicker::UIColorPicker( UIWindow* attachTo, const UIColorPicker::ColorPick } } mUIWindow->getModalWidget()->addEventListener( Event::MouseClick, - [&]( const Event* ) { closePicker(); } ); - mUIWindow->addEventListener( Event::KeyDown, [&]( const Event* event ) { + [this]( const Event* ) { closePicker(); } ); + mUIWindow->addEventListener( Event::KeyDown, [this]( const Event* event ) { const KeyEvent* keyEvent = static_cast( event ); onKeyDown( *keyEvent ); } ); @@ -285,9 +285,9 @@ UIColorPicker::UIColorPicker( UIWindow* attachTo, const UIColorPicker::ColorPick mRoot->bind( "footer", mFooter ); mTextInput = mFooter->findByTag( "textinput" )->asType(); - mRoot->addEventListener( Event::OnSizeChange, [&]( const Event* ) { updateAll(); } ); + mRoot->addEventListener( Event::OnSizeChange, [this]( const Event* ) { updateAll(); } ); - mRoot->addEventListener( Event::OnLayoutUpdate, [&]( const Event* ) { + mRoot->addEventListener( Event::OnLayoutUpdate, [this]( const Event* ) { if ( mHuePicker->getDrawable() == nullptr ) { mHuePicker->setDrawable( createHueTexture( mHuePicker->getPixelsSize() ), true ); mCurrentColor->setBackgroundDrawable( createGridTexture(), true ); @@ -458,17 +458,17 @@ void UIColorPicker::updateAll() { } void UIColorPicker::registerEvents() { - mColorPicker->addEventListener( Event::MouseDown, [&]( const Event* event ) { + mColorPicker->addEventListener( Event::MouseDown, [this]( const Event* event ) { onColorPickerEvent( reinterpret_cast( event ) ); } ); - mHuePicker->addEventListener( Event::MouseDown, [&]( const Event* event ) { + mHuePicker->addEventListener( Event::MouseDown, [this]( const Event* event ) { onHuePickerEvent( reinterpret_cast( event ) ); } ); UISlider* redSlider = mRedContainer->findByTag( "slider" ); - redSlider->addEventListener( Event::OnValueChange, [&]( const Event* event ) { + redSlider->addEventListener( Event::OnValueChange, [this]( const Event* event ) { if ( mUpdating ) return; setColor( @@ -477,7 +477,7 @@ void UIColorPicker::registerEvents() { UISlider* greenSlider = mGreenContainer->findByTag( "slider" ); - greenSlider->addEventListener( Event::OnValueChange, [&]( const Event* event ) { + greenSlider->addEventListener( Event::OnValueChange, [this]( const Event* event ) { if ( mUpdating ) return; setColor( @@ -486,7 +486,7 @@ void UIColorPicker::registerEvents() { UISlider* blueSlider = mBlueContainer->findByTag( "slider" ); - blueSlider->addEventListener( Event::OnValueChange, [&]( const Event* event ) { + blueSlider->addEventListener( Event::OnValueChange, [this]( const Event* event ) { if ( mUpdating ) return; setColor( @@ -495,7 +495,7 @@ void UIColorPicker::registerEvents() { UISlider* alphaSlider = mAlphaContainer->findByTag( "slider" ); - alphaSlider->addEventListener( Event::OnValueChange, [&]( const Event* event ) { + alphaSlider->addEventListener( Event::OnValueChange, [this]( const Event* event ) { if ( mUpdating ) return; setColor( @@ -504,7 +504,7 @@ void UIColorPicker::registerEvents() { UISpinBox* redSpinBox = mRedContainer->findByTag( "spinbox" ); - redSpinBox->addEventListener( Event::OnValueChange, [&]( const Event* event ) { + redSpinBox->addEventListener( Event::OnValueChange, [this]( const Event* event ) { if ( mUpdating ) return; setColor( @@ -513,7 +513,7 @@ void UIColorPicker::registerEvents() { UISpinBox* greenSpinBox = mGreenContainer->findByTag( "spinbox" ); - greenSpinBox->addEventListener( Event::OnValueChange, [&]( const Event* event ) { + greenSpinBox->addEventListener( Event::OnValueChange, [this]( const Event* event ) { if ( mUpdating ) return; setColor( @@ -522,7 +522,7 @@ void UIColorPicker::registerEvents() { UISpinBox* blueSpinBox = mBlueContainer->findByTag( "spinbox" ); - blueSpinBox->addEventListener( Event::OnValueChange, [&]( const Event* event ) { + blueSpinBox->addEventListener( Event::OnValueChange, [this]( const Event* event ) { if ( mUpdating ) return; setColor( @@ -531,7 +531,7 @@ void UIColorPicker::registerEvents() { UISpinBox* alphaSpinBox = mAlphaContainer->findByTag( "spinbox" ); - alphaSpinBox->addEventListener( Event::OnValueChange, [&]( const Event* event ) { + alphaSpinBox->addEventListener( Event::OnValueChange, [this]( const Event* event ) { if ( mUpdating ) return; setColor( @@ -539,7 +539,7 @@ void UIColorPicker::registerEvents() { } ); mFooter->findByTag( "pushbutton" ) - ->addEventListener( Event::MouseClick, [&]( const Event* ) { + ->addEventListener( Event::MouseClick, [this]( const Event* ) { if ( mPickedCb ) mPickedCb( mRgb ); @@ -547,14 +547,14 @@ void UIColorPicker::registerEvents() { mUIWindow->closeWindow(); } ); - mTextInput->addEventListener( Event::OnPressEnter, [&]( const Event* ) { + mTextInput->addEventListener( Event::OnPressEnter, [this]( const Event* ) { if ( mUpdating ) return; std::string buffer( mTextInput->getText().toUtf8() ); onColorPicked( buffer ); } ); - mTextInput->addEventListener( Event::OnTextChanged, [&]( const Event* ) { + mTextInput->addEventListener( Event::OnTextChanged, [this]( const Event* ) { std::string buffer( mTextInput->getText().toUtf8() ); if ( Color::validHexColorString( "#" + buffer ) && ( buffer.size() == 3 || buffer.size() == 6 || buffer.size() == 8 ) ) @@ -562,7 +562,7 @@ void UIColorPicker::registerEvents() { } ); mRoot->find( "picker_icon" ) - ->addEventListener( Event::MouseClick, [&]( const Event* ) { + ->addEventListener( Event::MouseClick, [this]( const Event* ) { UIWidget* coverWidget = UIWidget::New(); setModalAlpha( 0 ); coverWidget->setParent( mRoot->getSceneNode() ) @@ -570,13 +570,13 @@ void UIColorPicker::registerEvents() { ->setSize( mRoot->getSceneNode()->getSize() ); coverWidget->setAnchors( UI_ANCHOR_LEFT | UI_ANCHOR_TOP | UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); - coverWidget->addEventListener( Event::MouseMove, [&]( const Event* event ) { + coverWidget->addEventListener( Event::MouseMove, [this]( const Event* event ) { Vector2i position = reinterpret_cast( event )->getPosition(); setColor( GLi->readPixel( position.x, event->getNode()->getSceneNode()->getWindow()->getHeight() - position.y ) ); } ); - coverWidget->addEventListener( Event::MouseClick, [&]( const Event* event ) { + coverWidget->addEventListener( Event::MouseClick, [this]( const Event* event ) { Vector2i position = reinterpret_cast( event )->getPosition(); setColor( GLi->readPixel( position.x, diff --git a/src/eepp/ui/tools/uidocfindreplace.cpp b/src/eepp/ui/tools/uidocfindreplace.cpp index 2a4bca1e8..1d5d803fd 100644 --- a/src/eepp/ui/tools/uidocfindreplace.cpp +++ b/src/eepp/ui/tools/uidocfindreplace.cpp @@ -180,8 +180,8 @@ UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptraddEventListener( Event::MouseClick, [&]( const Event* event ) { - if ( static_cast( event )->getFlags() & EE_BUTTON_LMASK ) { + mToggle->addEventListener( Event::MouseClick, [this]( const Event* event ) { + if ( event->asMouseEvent()->getFlags() & EE_BUTTON_LMASK ) { if ( mToggle->hasClass( "enabled" ) ) { mToggle->removeClass( "enabled" ); mReplaceBox->removeClass( "enabled" ); @@ -203,7 +203,7 @@ UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptraddEventListener( Event::OnTextChanged, [&, editor]( const Event* ) { refreshHighlight( editor ); } ); - mFindInput->addEventListener( Event::OnTextPasted, [&]( const Event* ) { + mFindInput->addEventListener( Event::OnTextPasted, [this]( const Event* ) { if ( mFindInput->getUISceneNode()->getWindow()->getClipboard()->getText().find( '\n' ) != String::InvalidPos ) { if ( !mEscapeSequences->isSelected() ) @@ -254,7 +254,7 @@ UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptr( ".input-replace" ); - auto addClickListener = [&]( UIWidget* widget, std::string cmd ) { + auto addClickListener = [this]( UIWidget* widget, std::string cmd ) { if ( !widget ) return; widget->setTooltipText( getKeyBindings().getCommandKeybindString( cmd ) ); @@ -264,7 +264,7 @@ UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptraddEventListener( Event::OnPressEnter, [this, cmd]( const Event* ) { execute( cmd ); } ); }; @@ -280,7 +280,7 @@ UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptrsetTabStop(); mReplaceInput->setTabStop(); - mFindInput->addEventListener( Event::OnTabNavigate, [&]( const Event* ) { + mFindInput->addEventListener( Event::OnTabNavigate, [this]( const Event* ) { if ( !mToggle->hasClass( "enabled" ) ) { mToggle->addClass( "enabled" ); mReplaceBox->addClass( "enabled" ); @@ -289,7 +289,7 @@ UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptraddEventListener( Event::OnTabNavigate, - [&]( const Event* ) { mFindInput->setFocus(); } ); + [this]( const Event* ) { mFindInput->setFocus(); } ); mDataBinds.emplace_back( UIDataBindBool::New( &mSearchState.caseSensitive, mCaseSensitive ) ); mDataBinds.emplace_back( UIDataBindBool::New( &mSearchState.wholeWord, mWholeWord ) ); @@ -318,9 +318,9 @@ UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptraddEventListener( Event::OnSizeChange, [&]( const Event* ) { + getParent()->addEventListener( Event::OnSizeChange, [this]( const Event* ) { Float startX = eemax( 0.f, getParent()->getSize().getWidth() - getSize().getWidth() ); setPosition( startX, getPosition().y ); } ); @@ -328,7 +328,7 @@ UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptrsetVisible( false ); diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index a3fb84493..a5e3cfbb6 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -128,16 +128,16 @@ UICodeEditor::UICodeEditor( const std::string& elementTag, const bool& autoRegis mVScrollBar = UIScrollBar::NewVertical(); mVScrollBar->setParent( this ); mVScrollBar->addEventListener( Event::OnSizeChange, - [&]( const Event* ) { updateScrollBar(); } ); - mVScrollBar->addEventListener( Event::OnValueChange, [&]( const Event* ) { + [this]( const Event* ) { updateScrollBar(); } ); + mVScrollBar->addEventListener( Event::OnValueChange, [this]( const Event* ) { setScrollY( mVScrollBar->getValue() * getMaxScroll().y, false ); } ); mHScrollBar = UIScrollBar::NewHorizontal(); mHScrollBar->setParent( this ); mHScrollBar->addEventListener( Event::OnSizeChange, - [&]( const Event* ) { updateScrollBar(); } ); - mHScrollBar->addEventListener( Event::OnValueChange, [&]( const Event* ) { + [this]( const Event* ) { updateScrollBar(); } ); + mHScrollBar->addEventListener( Event::OnValueChange, [this]( const Event* ) { setScrollX( mHScrollBar->getValue() * getMaxScroll().x, false ); } ); @@ -496,10 +496,11 @@ bool UICodeEditor::loadAsyncFromURL( onLoaded( mDoc, success ); } ); }, - [&]( const Http&, const Http::Request&, const Http::Response&, - const Http::Request::Status& status, size_t /*totalBytes*/, size_t /*currentBytes*/ ) { + [this]( const Http&, const Http::Request&, const Http::Response&, + const Http::Request::Status& status, size_t /*totalBytes*/, + size_t /*currentBytes*/ ) { if ( status == Http::Request::ContentReceived ) { - runOnMainThread( [&] { invalidateDraw(); } ); + runOnMainThread( [this] { invalidateDraw(); } ); } return true; } ); @@ -1051,11 +1052,11 @@ bool UICodeEditor::onCreateContextMenu( const Vector2i& position, const Uint32& menu->show(); mCurrentMenu = menu; } ); - menu->addEventListener( Event::OnMenuHide, [&]( const Event* ) { + menu->addEventListener( Event::OnMenuHide, [this]( const Event* ) { if ( !isClosing() ) setFocus(); } ); - menu->addEventListener( Event::OnClose, [&]( const Event* ) { mCurrentMenu = nullptr; } ); + menu->addEventListener( Event::OnClose, [this]( const Event* ) { mCurrentMenu = nullptr; } ); return true; } @@ -1364,7 +1365,7 @@ void UICodeEditor::checkColorPickerAction() { if ( isHash || isRgb || isRgba ) { UIColorPicker* colorPicker = NULL; if ( isHash ) { - colorPicker = UIColorPicker::NewModal( this, [&]( Color color ) { + colorPicker = UIColorPicker::NewModal( this, [this]( Color color ) { mDoc->replaceSelection( color.toHexString( false ) ); } ); colorPicker->setColor( Color( '#' + text ) ); @@ -1382,7 +1383,7 @@ void UICodeEditor::checkColorPickerAction() { } if ( colorPicker ) colorPicker->getUIWindow()->addEventListener( - Event::OnWindowClose, [&]( const Event* ) { + Event::OnWindowClose, [this]( const Event* ) { if ( !SceneManager::instance()->isShuttingDown() ) setFocus(); } ); @@ -1592,6 +1593,11 @@ void UICodeEditor::onDocumentCursorChange( const Doc::TextPosition& ) { onCursorPosChange(); } +void UICodeEditor::onDocumentInterestingCursorChange( const TextPosition& ) { + sendCommonEvent( Event::OnCursorPosChangeInteresting ); + invalidateDraw(); +} + void UICodeEditor::onDocumentSelectionChange( const Doc::TextRange& ) { resetCursor(); invalidateDraw(); @@ -3113,29 +3119,29 @@ void UICodeEditor::drawLineEndings( const std::pair& lineRange, } void UICodeEditor::registerCommands() { - mDoc->setCommand( "move-to-previous-line", [&] { moveToPreviousLine(); } ); - mDoc->setCommand( "move-to-next-line", [&] { moveToNextLine(); } ); - mDoc->setCommand( "select-to-previous-line", [&] { selectToPreviousLine(); } ); - mDoc->setCommand( "select-to-next-line", [&] { selectToNextLine(); } ); - mDoc->setCommand( "move-scroll-up", [&] { moveScrollUp(); } ); - mDoc->setCommand( "move-scroll-down", [&] { moveScrollDown(); } ); - mDoc->setCommand( "indent", [&] { indent(); } ); - mDoc->setCommand( "unindent", [&] { unindent(); } ); - mDoc->setCommand( "copy", [&] { copy(); } ); - mDoc->setCommand( "cut", [&] { cut(); } ); - mDoc->setCommand( "paste", [&] { paste(); } ); - mDoc->setCommand( "font-size-grow", [&] { fontSizeGrow(); } ); - mDoc->setCommand( "font-size-shrink", [&] { fontSizeShrink(); } ); - mDoc->setCommand( "font-size-reset", [&] { fontSizeReset(); } ); - mDoc->setCommand( "lock", [&] { setLocked( true ); } ); - mDoc->setCommand( "unlock", [&] { setLocked( false ); } ); - mDoc->setCommand( "lock-toggle", [&] { setLocked( !isLocked() ); } ); - mDoc->setCommand( "open-containing-folder", [&] { openContainingFolder(); } ); - mDoc->setCommand( "copy-containing-folder-path", [&] { copyContainingFolderPath(); } ); - mDoc->setCommand( "copy-file-path", [&] { copyFilePath(); } ); - mDoc->setCommand( "copy-file-path-and-position", [&] { copyFilePath( true ); } ); - mDoc->setCommand( "find-replace", [&] { showFindReplace(); } ); - mDoc->setCommand( "open-context-menu", [&] { createContextMenu(); } ); + mDoc->setCommand( "move-to-previous-line", [this] { moveToPreviousLine(); } ); + mDoc->setCommand( "move-to-next-line", [this] { moveToNextLine(); } ); + mDoc->setCommand( "select-to-previous-line", [this] { selectToPreviousLine(); } ); + mDoc->setCommand( "select-to-next-line", [this] { selectToNextLine(); } ); + mDoc->setCommand( "move-scroll-up", [this] { moveScrollUp(); } ); + mDoc->setCommand( "move-scroll-down", [this] { moveScrollDown(); } ); + mDoc->setCommand( "indent", [this] { indent(); } ); + mDoc->setCommand( "unindent", [this] { unindent(); } ); + mDoc->setCommand( "copy", [this] { copy(); } ); + mDoc->setCommand( "cut", [this] { cut(); } ); + mDoc->setCommand( "paste", [this] { paste(); } ); + mDoc->setCommand( "font-size-grow", [this] { fontSizeGrow(); } ); + mDoc->setCommand( "font-size-shrink", [this] { fontSizeShrink(); } ); + mDoc->setCommand( "font-size-reset", [this] { fontSizeReset(); } ); + mDoc->setCommand( "lock", [this] { setLocked( true ); } ); + mDoc->setCommand( "unlock", [this] { setLocked( false ); } ); + mDoc->setCommand( "lock-toggle", [this] { setLocked( !isLocked() ); } ); + mDoc->setCommand( "open-containing-folder", [this] { openContainingFolder(); } ); + mDoc->setCommand( "copy-containing-folder-path", [this] { copyContainingFolderPath(); } ); + mDoc->setCommand( "copy-file-path", [this] { copyFilePath(); } ); + mDoc->setCommand( "copy-file-path-and-position", [this] { copyFilePath( true ); } ); + mDoc->setCommand( "find-replace", [this] { showFindReplace(); } ); + mDoc->setCommand( "open-context-menu", [this] { createContextMenu(); } ); mUnlockedCmd.insert( { "copy", "select-all" } ); } diff --git a/src/eepp/ui/uicombobox.cpp b/src/eepp/ui/uicombobox.cpp index c68bf0148..295ca7767 100644 --- a/src/eepp/ui/uicombobox.cpp +++ b/src/eepp/ui/uicombobox.cpp @@ -17,13 +17,14 @@ UIComboBox::UIComboBox() : UIWidget( "combobox" ), mDropDownList( NULL ), mButto mDropDownList->setTextSelection( true ); mDropDownList->addEventListener( Event::OnPaddingChange, [this]( const Event* ) { onPaddingChange(); } ); - mDropDownList->addEventListener( Event::OnSizeChange, [&]( const Event* ) { onSizeChange(); } ); + mDropDownList->addEventListener( Event::OnSizeChange, + [this]( const Event* ) { onSizeChange(); } ); mButton = UIWidget::NewWithTag( "combobox::button" ); mButton->setParent( this ); mButton->setVisible( true ); mButton->setEnabled( true ); - mButton->addEventListener( Event::OnSizeChange, [&]( const Event* ) { onSizeChange(); } ); + mButton->addEventListener( Event::OnSizeChange, [this]( const Event* ) { onSizeChange(); } ); applyDefaultTheme(); } diff --git a/src/eepp/ui/uiconsole.cpp b/src/eepp/ui/uiconsole.cpp index b93dcf7ec..4bcf8abf8 100644 --- a/src/eepp/ui/uiconsole.cpp +++ b/src/eepp/ui/uiconsole.cpp @@ -472,22 +472,22 @@ void UIConsole::draw() { // CMDS void UIConsole::createDefaultCommands() { - addCommand( "clear", [&]( const auto& ) { cmdClear(); } ); - addCommand( "quit", [&]( const auto& ) { getUISceneNode()->getWindow()->close(); } ); - addCommand( "cmdlist", [&]( const auto& ) { cmdCmdList(); } ); - addCommand( "help", [&]( const auto& ) { cmdCmdList(); } ); - addCommand( "showcursor", [&]( const auto& params ) { cmdShowCursor( params ); } ); - addCommand( "setfpslimit", [&]( const auto& params ) { cmdFrameLimit( params ); } ); - addCommand( "getlog", [&]( const auto& ) { cmdGetLog(); } ); - addCommand( "setgamma", [&]( const auto& params ) { cmdSetGamma( params ); } ); - addCommand( "setvolume", [&]( const auto& params ) { cmdSetVolume( params ); } ); - addCommand( "getgpuextensions", [&]( const auto& ) { cmdGetGpuExtensions(); } ); - addCommand( "dir", [&]( const auto& params ) { cmdDir( params ); } ); - addCommand( "ls", [&]( const auto& params ) { cmdDir( params ); } ); - addCommand( "showfps", [&]( const auto& params ) { cmdShowFps( params ); } ); - addCommand( "gettexturememory", [&]( const auto& ) { cmdGetTextureMemory(); } ); - addCommand( "hide", [&]( const auto& ) { hide(); } ); - addCommand( "grep", [&]( const auto& params ) { cmdGrep( params ); } ); + addCommand( "clear", [this]( const auto& ) { cmdClear(); } ); + addCommand( "quit", [this]( const auto& ) { getUISceneNode()->getWindow()->close(); } ); + addCommand( "cmdlist", [this]( const auto& ) { cmdCmdList(); } ); + addCommand( "help", [this]( const auto& ) { cmdCmdList(); } ); + addCommand( "showcursor", [this]( const auto& params ) { cmdShowCursor( params ); } ); + addCommand( "setfpslimit", [this]( const auto& params ) { cmdFrameLimit( params ); } ); + addCommand( "getlog", [this]( const auto& ) { cmdGetLog(); } ); + addCommand( "setgamma", [this]( const auto& params ) { cmdSetGamma( params ); } ); + addCommand( "setvolume", [this]( const auto& params ) { cmdSetVolume( params ); } ); + addCommand( "getgpuextensions", [this]( const auto& ) { cmdGetGpuExtensions(); } ); + addCommand( "dir", [this]( const auto& params ) { cmdDir( params ); } ); + addCommand( "ls", [this]( const auto& params ) { cmdDir( params ); } ); + addCommand( "showfps", [this]( const auto& params ) { cmdShowFps( params ); } ); + addCommand( "gettexturememory", [this]( const auto& ) { cmdGetTextureMemory(); } ); + addCommand( "hide", [this]( const auto& ) { hide(); } ); + addCommand( "grep", [this]( const auto& params ) { cmdGrep( params ); } ); } void UIConsole::cmdClear() { @@ -837,10 +837,10 @@ Uint32 UIConsole::onPressEnter() { return 0; } void UIConsole::registerCommands() { - mDoc.setCommand( "copy", [&] { copy(); } ); - mDoc.setCommand( "cut", [&] { cut(); } ); - mDoc.setCommand( "paste", [&] { paste(); } ); - mDoc.setCommand( "press-enter", [&] { onPressEnter(); } ); + mDoc.setCommand( "copy", [this] { copy(); } ); + mDoc.setCommand( "cut", [this] { cut(); } ); + mDoc.setCommand( "paste", [this] { paste(); } ); + mDoc.setCommand( "press-enter", [this] { onPressEnter(); } ); } void UIConsole::registerKeybindings() { @@ -1247,7 +1247,7 @@ void UIConsole::show() { auto* spawn = Actions::Spawn::New( { Actions::FadeIn::New( Seconds( .25f ) ), Actions::Move::New( { 0, -getSize().getHeight() }, { 0, 0 }, Seconds( .25f ) ) } ); - runAction( Actions::Sequence::New( { spawn, Actions::Runnable::New( [&] { + runAction( Actions::Sequence::New( { spawn, Actions::Runnable::New( [this] { setVisible( true ); setEnabled( true ); mFading = false; @@ -1270,7 +1270,7 @@ void UIConsole::hide() { auto* spawn = Actions::Spawn::New( { Actions::FadeOut::New( Seconds( .25f ) ), Actions::Move::New( { 0, 0 }, { 0, -getSize().getHeight() }, Seconds( .25f ) ) } ); - runAction( Actions::Sequence::New( { spawn, Actions::Runnable::New( [&] { + runAction( Actions::Sequence::New( { spawn, Actions::Runnable::New( [this] { setVisible( false ); setEnabled( false ); mHiding = false; diff --git a/src/eepp/ui/uidropdownlist.cpp b/src/eepp/ui/uidropdownlist.cpp index 4b07448d0..010fd8d6c 100644 --- a/src/eepp/ui/uidropdownlist.cpp +++ b/src/eepp/ui/uidropdownlist.cpp @@ -47,7 +47,7 @@ UIDropDownList::UIDropDownList( const std::string& tag ) : cb::Make1( this, &UIDropDownList::onItemKeyDown ) ); mListBox->addEventListener( Event::KeyDown, cb::Make1( this, &UIDropDownList::onItemKeyDown ) ); mListBox->addEventListener( Event::OnClear, cb::Make1( this, &UIDropDownList::onWidgetClear ) ); - mListBox->addEventListener( Event::OnClose, [&]( const Event* ) { mListBox = nullptr; } ); + mListBox->addEventListener( Event::OnClose, [this]( const Event* ) { mListBox = nullptr; } ); mListBox->addEventListener( Event::OnSelectionChanged, [this]( auto ) { if ( !mListBox->hasSelection() ) mListBox->setSelected( 0 ); diff --git a/src/eepp/ui/uifiledialog.cpp b/src/eepp/ui/uifiledialog.cpp index eba6accbc..64fc3d3bb 100644 --- a/src/eepp/ui/uifiledialog.cpp +++ b/src/eepp/ui/uifiledialog.cpp @@ -94,9 +94,8 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, const std::string& defaultFilePa ->setLayoutMarginLeft( 4 ) ->setLayoutSizePolicy( SizePolicy::WrapContent, SizePolicy::MatchParent ) ->setParent( hLayout ); - mButtonNewFolder->addEventListener( Event::MouseClick, [&]( const Event* event ) { - const MouseEvent* mouseEvent = static_cast( event ); - if ( mouseEvent->getFlags() & EE_BUTTON_LMASK ) { + mButtonNewFolder->addEventListener( Event::MouseClick, [this]( const Event* event ) { + if ( event->asMouseEvent()->getFlags() & EE_BUTTON_LMASK ) { UIMessageBox* msgBox = UIMessageBox::New( UIMessageBox::INPUT, getTranslatorString( "@string/uifiledialog_enter_new_folder_name", @@ -105,7 +104,7 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, const std::string& defaultFilePa "Create new folder" ) ); msgBox->setCloseShortcut( { KEY_ESCAPE, 0 } ); msgBox->show(); - msgBox->addEventListener( Event::OnConfirm, [&, msgBox]( const Event* ) { + msgBox->addEventListener( Event::OnConfirm, [this, msgBox]( const Event* ) { auto folderName( msgBox->getTextInput()->getText() ); auto newFolderPath( getCurPath() + folderName ); if ( !FileSystem::fileExists( newFolderPath ) && @@ -143,9 +142,8 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, const std::string& defaultFilePa mMultiView->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::WrapContent ) ->setLayoutWeight( 1 ) ->setLayoutMargin( Rectf( 0, 0, 0, 4 ) ); - mMultiView->addEventListener( Event::KeyDown, [&]( const Event* event ) { - const KeyEvent* kevent = reinterpret_cast( event ); - if ( kevent->getKeyCode() == KEY_BACKSPACE ) + mMultiView->addEventListener( Event::KeyDown, [this]( const Event* event ) { + if ( event->asKeyEvent()->getKeyCode() == KEY_BACKSPACE ) goFolderUp(); } ); mMultiView->addEventListener( Event::OnModelEvent, [&]( const Event* event ) { @@ -167,7 +165,7 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, const std::string& defaultFilePa } } } ); - mMultiView->setOnSelectionChange( [&] { + mMultiView->setOnSelectionChange( [this] { if ( mMultiView->getSelection().isEmpty() || mDisplayingDrives ) return; const FileSystemModel::Node* node = getSelectionNode(); diff --git a/src/eepp/ui/uiicon.cpp b/src/eepp/ui/uiicon.cpp index 2105384ac..2e1745674 100644 --- a/src/eepp/ui/uiicon.cpp +++ b/src/eepp/ui/uiicon.cpp @@ -54,7 +54,7 @@ Drawable* UIGlyphIcon::getSize( const int& size ) const { UIGlyphIcon::UIGlyphIcon( const std::string& name, FontTrueType* font, const Uint32& codePoint ) : UIIcon( name ), mFont( font ), mCodePoint( codePoint ) { eeASSERT( mFont ); - mCloseCb = mFont->pushFontEventCallback( [&]( Uint32, Font::Event event, Font* ) { + mCloseCb = mFont->pushFontEventCallback( [this]( Uint32, Font::Event event, Font* ) { if ( event == Font::Event::Unload ) mFont = nullptr; } ); diff --git a/src/eepp/ui/uilistbox.cpp b/src/eepp/ui/uilistbox.cpp index 24c1e3746..c9c4ee0bd 100644 --- a/src/eepp/ui/uilistbox.cpp +++ b/src/eepp/ui/uilistbox.cpp @@ -41,7 +41,7 @@ UIListBox::UIListBox( const std::string& tag ) : mSmoothScroll( true ) { setFlags( UI_AUTO_PADDING ); - auto cb = [&]( const Event* ) { containerResize(); }; + auto cb = [this]( const Event* ) { containerResize(); }; mContainer = eeNew( UIItemContainer, () ); mContainer->setParent( this ); diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 5a8a890d3..25ee36d0e 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -162,7 +162,7 @@ UIWidget* UIMenu::add( UIWidget* widget ) { widget->setPixelsPosition( mPaddingPx.Left, mPaddingPx.Top + mNextPosY ); mNextPosY += widget->getPixelsSize().getHeight(); mItems.push_back( widget ); - auto cb = [&]( const Event* ) { + auto cb = [this]( const Event* ) { if ( !mResizing ) { widgetsSetPos(); widgetsResize(); @@ -189,7 +189,7 @@ UIMenuSeparator* UIMenu::addSeparator() { mNextPosY += separator->getPixelsSize().getHeight(); mItems.push_back( separator ); resizeMe(); - separator->addEventListener( Event::OnSizeChange, [&]( const Event* ) { + separator->addEventListener( Event::OnSizeChange, [this]( const Event* ) { if ( !mResizing ) { widgetsSetPos(); widgetsResize(); diff --git a/src/eepp/ui/uimenubar.cpp b/src/eepp/ui/uimenubar.cpp index 9a7fe5594..594c92a65 100644 --- a/src/eepp/ui/uimenubar.cpp +++ b/src/eepp/ui/uimenubar.cpp @@ -55,7 +55,7 @@ void UIMenuBar::addMenuButton( const String& buttonText, UIPopUpMenu* menu ) { button->setText( buttonText ); button->setVisible( true ); button->setEnabled( true ); - button->addEventListener( Event::OnSizeChange, [&]( const Event* ) { refreshButtons(); } ); + button->addEventListener( Event::OnSizeChange, [this]( const Event* ) { refreshButtons(); } ); button->addEventListener( Event::OnFocus, [&, button]( const Event* ) { if ( getEventDispatcher()->getReleaseTrigger() & EE_BUTTON_LMASK ) { getMenuFromButton( button )->setFocus(); @@ -75,7 +75,7 @@ void UIMenuBar::addMenuButton( const String& buttonText, UIPopUpMenu* menu ) { button->unselect(); } } ); - menu->addEventListener( Event::OnItemClicked, [&]( const Event* ) { + menu->addEventListener( Event::OnItemClicked, [this]( const Event* ) { mWaitingUp = nullptr; mCurrentMenu = nullptr; } ); diff --git a/src/eepp/ui/uimenuitem.cpp b/src/eepp/ui/uimenuitem.cpp index 8487c9458..24327dc66 100644 --- a/src/eepp/ui/uimenuitem.cpp +++ b/src/eepp/ui/uimenuitem.cpp @@ -98,7 +98,7 @@ void UIMenuItem::createShortcutView() { mShortcutView = UITextView::NewWithTag( mTag + "::shortcut" ); mShortcutView->setParent( this )->setVisible( true )->setEnabled( false ); mShortcutView->setFlags( UI_AUTO_SIZE | UI_HALIGN_RIGHT ); - auto cb = [&]( const Event* ) { onSizeChange(); }; + auto cb = [this]( const Event* ) { onSizeChange(); }; mShortcutView->addEventListener( Event::OnPaddingChange, cb ); mShortcutView->addEventListener( Event::OnMarginChange, cb ); mShortcutView->addEventListener( Event::OnSizeChange, cb ); diff --git a/src/eepp/ui/uimenusubmenu.cpp b/src/eepp/ui/uimenusubmenu.cpp index b7364d189..8c4d7bcba 100644 --- a/src/eepp/ui/uimenusubmenu.cpp +++ b/src/eepp/ui/uimenusubmenu.cpp @@ -18,8 +18,8 @@ UIMenuSubMenu::UIMenuSubMenu() : mArrow->setParent( this ); mArrow->setFlags( UI_AUTO_SIZE ); applyDefaultTheme(); - mArrow->addEventListener( Event::OnSizeChange, [&]( const Event* ) { onSizeChange(); } ); - mArrow->addEventListener( Event::OnMarginChange, [&]( const Event* ) { onSizeChange(); } ); + mArrow->addEventListener( Event::OnSizeChange, [this]( const Event* ) { onSizeChange(); } ); + mArrow->addEventListener( Event::OnMarginChange, [this]( const Event* ) { onSizeChange(); } ); mArrow->setVisible( true ); mArrow->setEnabled( false ); } @@ -105,7 +105,7 @@ void UIMenuSubMenu::showSubMenu() { Uint32 UIMenuSubMenu::onMouseOver( const Vector2i& pos, const Uint32& flags ) { if ( nullptr == mCurWait ) { mCurWait = Actions::Runnable::New( - [&] { + [this] { if ( isMouseOver() ) showSubMenu(); mCurWait = nullptr; diff --git a/src/eepp/ui/uimessagebox.cpp b/src/eepp/ui/uimessagebox.cpp index fb8a24243..76d05b9d5 100644 --- a/src/eepp/ui/uimessagebox.cpp +++ b/src/eepp/ui/uimessagebox.cpp @@ -40,7 +40,7 @@ UIMessageBox::UIMessageBox( const Type& type, const String& message, const Uint3 ->setLayoutMargin( Rectf( 0, 4, 0, 4 ) ) ->setParent( vlay ) ->addEventListener( Event::OnPressEnter, - [&]( const Event* ) { sendCommonEvent( Event::OnConfirm ); } ); + [this]( const Event* ) { sendCommonEvent( Event::OnConfirm ); } ); } UILinearLayout* hlay = UILinearLayout::NewHorizontal(); diff --git a/src/eepp/ui/uimultimodelview.cpp b/src/eepp/ui/uimultimodelview.cpp index e247ef181..2e12855c4 100644 --- a/src/eepp/ui/uimultimodelview.cpp +++ b/src/eepp/ui/uimultimodelview.cpp @@ -11,15 +11,15 @@ UIMultiModelView* UIMultiModelView::NewWithTag( const std::string& tag ) { } UIMultiModelView::UIMultiModelView( const std::string& tag ) : UIStackWidget( tag ) { - auto modelEvent = [&]( const Event* event ) { + auto modelEvent = [this]( const Event* event ) { const ModelEvent* mevent = static_cast( event ); sendEvent( mevent ); }; - auto selectionChange = [&]() { + auto selectionChange = [this]() { if ( mOnSelectionChange ) mOnSelectionChange(); }; - auto selection = [&]( const ModelIndex& index ) { + auto selection = [this]( const ModelIndex& index ) { if ( mOnSelection ) mOnSelection( index ); }; diff --git a/src/eepp/ui/uinodedrawable.cpp b/src/eepp/ui/uinodedrawable.cpp index 632fb77f1..bf9280639 100644 --- a/src/eepp/ui/uinodedrawable.cpp +++ b/src/eepp/ui/uinodedrawable.cpp @@ -408,7 +408,7 @@ void UINodeDrawable::LayerDrawable::setDrawable( Drawable* drawable, const bool& if ( NULL != mDrawable && mDrawable->isDrawableResource() ) { mResourceChangeCbId = reinterpret_cast( mDrawable ) ->pushResourceChangeCallback( - [&]( DrawableResource::Event event, DrawableResource* ) { + [this]( DrawableResource::Event event, DrawableResource* ) { invalidate(); if ( event == DrawableResource::Event::Unload ) { mResourceChangeCbId = 0; diff --git a/src/eepp/ui/uipopupmenu.cpp b/src/eepp/ui/uipopupmenu.cpp index 71b5c70a7..1f316a22f 100644 --- a/src/eepp/ui/uipopupmenu.cpp +++ b/src/eepp/ui/uipopupmenu.cpp @@ -17,8 +17,7 @@ UIPopUpMenu::UIPopUpMenu() : UIMenu() { applyDefaultTheme(); } -UIPopUpMenu::~UIPopUpMenu() { -} +UIPopUpMenu::~UIPopUpMenu() {} Uint32 UIPopUpMenu::getType() const { return UI_TYPE_POPUPMENU; @@ -67,7 +66,7 @@ bool UIPopUpMenu::hide() { Actions::FadeOut::New( getUISceneNode()->getUIThemeManager()->getWidgetsFadeOutTime() ), Actions::Spawn::New( Actions::Disable::New(), Actions::Visible::New( false ), - Actions::Runnable::New( [&] { + Actions::Runnable::New( [this] { mHidingAction = nullptr; if ( mCloseOnHide ) close(); diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index 324bedadd..a22f160f8 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -73,7 +73,7 @@ UIPushButton::UIPushButton( const std::string& tag, ->setVisible( true ) ->setEnabled( false ); - auto cb = [&]( const Event* ) { onSizeChange(); }; + auto cb = [this]( const Event* ) { onSizeChange(); }; mIcon->addEventListener( Event::OnPaddingChange, cb ); mIcon->addEventListener( Event::OnMarginChange, cb ); diff --git a/src/eepp/ui/uiradiobutton.cpp b/src/eepp/ui/uiradiobutton.cpp index 913b950c8..d9bfb8e87 100644 --- a/src/eepp/ui/uiradiobutton.cpp +++ b/src/eepp/ui/uiradiobutton.cpp @@ -15,7 +15,7 @@ UIRadioButton::UIRadioButton() : mInactiveButton( NULL ), mActive( false ), mTextSeparation( 4 ) { - auto cb = [&]( const Event* event ) { onAutoSize(); }; + auto cb = [this]( const Event* ) { onAutoSize(); }; mActiveButton = UIWidget::NewWithTag( "radiobutton::active" ); mActiveButton->setVisible( false ); diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index 10f0466d2..de06c6095 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -147,7 +147,7 @@ void UISceneNode::onParentChange() { setPixelsSize( getParent()->getPixelsSize() ); mCurOnSizeChangeListener = - getParent()->addEventListener( Event::OnSizeChange, [&]( const Event* ) { + getParent()->addEventListener( Event::OnSizeChange, [this]( const Event* ) { setDirty(); setPixelsSize( getParent()->getPixelsSize() ); onMediaChanged(); @@ -948,7 +948,7 @@ void UISceneNode::loadFontFaces( const StyleSheetStyleVector& styles ) { font->loadFromFile( filePath ); mFontFaces.push_back( font ); - runOnMainThread( [&] { mRoot->reloadFontFamily(); } ); + runOnMainThread( [this] { mRoot->reloadFontFamily(); } ); } else if ( String::startsWith( path, "http://" ) || String::startsWith( path, "https://" ) ) { std::string familyName = familyProp.getValue(); @@ -961,7 +961,7 @@ void UISceneNode::loadFontFaces( const StyleSheetStyleVector& styles ) { font->loadFromMemory( &response.getBody()[0], response.getBody().size() ); mFontFaces.push_back( font ); - runOnMainThread( [&] { mRoot->reloadFontFamily(); } ); + runOnMainThread( [this] { mRoot->reloadFontFamily(); } ); } }, URI( path ), Seconds( 5 ) ); @@ -974,7 +974,7 @@ void UISceneNode::loadFontFaces( const StyleSheetStyleVector& styles ) { font->loadFromStream( *stream ); mFontFaces.push_back( font ); - runOnMainThread( [&] { mRoot->reloadFontFamily(); } ); + runOnMainThread( [this] { mRoot->reloadFontFamily(); } ); } } } diff --git a/src/eepp/ui/uiselectbutton.cpp b/src/eepp/ui/uiselectbutton.cpp index e142a25bd..7b4c65ca3 100644 --- a/src/eepp/ui/uiselectbutton.cpp +++ b/src/eepp/ui/uiselectbutton.cpp @@ -131,8 +131,8 @@ void UISelectButton::setSelected( bool set ) { void UISelectButton::setSelectOnClick( bool set ) { if ( set ) { if ( mSelectOnClickCbId == 0 ) - mSelectOnClickCbId = - addEventListener( Event::MouseClick, [&]( const Event* ) { toggleSelection(); } ); + mSelectOnClickCbId = addEventListener( Event::MouseClick, + [this]( const Event* ) { toggleSelection(); } ); } else { if ( mSelectOnClickCbId != 0 ) removeEventListener( mSelectOnClickCbId ); diff --git a/src/eepp/ui/uislider.cpp b/src/eepp/ui/uislider.cpp index 673919ce6..2c0c95faf 100644 --- a/src/eepp/ui/uislider.cpp +++ b/src/eepp/ui/uislider.cpp @@ -55,7 +55,7 @@ UISlider::UISlider( const std::string& tag, const UIOrientation& orientation ) : mSlider = UIWidget::NewWithTag( mTag + "::vbutton" ); } - auto cb = [&]( const Event* ) { + auto cb = [this]( const Event* ) { if ( !mUpdating ) adjustChilds(); }; @@ -71,7 +71,7 @@ UISlider::UISlider( const std::string& tag, const UIOrientation& orientation ) : mSlider->setDragEnabled( true ); mSlider->setSize( 4, 4 ); mSlider->setPosition( 0, 0 ); - mSlider->addEventListener( Event::OnPositionChange, [&]( const Event* ) { + mSlider->addEventListener( Event::OnPositionChange, [this]( const Event* ) { if ( !mUpdating && !mOnPosChange ) fixSliderPos(); } ); diff --git a/src/eepp/ui/uispinbox.cpp b/src/eepp/ui/uispinbox.cpp index 160ab67f5..ac35e5a33 100644 --- a/src/eepp/ui/uispinbox.cpp +++ b/src/eepp/ui/uispinbox.cpp @@ -23,7 +23,7 @@ UISpinBox::UISpinBox() : mInput->setEnabled( true ); mInput->setParent( this ); - auto cb = [&]( const Event* ) { adjustChilds(); }; + auto cb = [this]( const Event* ) { adjustChilds(); }; mPushUp = UIWidget::NewWithTag( "spinbox::btnup" ); mPushUp->setVisible( true ); diff --git a/src/eepp/ui/uisplitter.cpp b/src/eepp/ui/uisplitter.cpp index b74ce54d7..bc7cbe08d 100644 --- a/src/eepp/ui/uisplitter.cpp +++ b/src/eepp/ui/uisplitter.cpp @@ -18,22 +18,21 @@ UISplitter::UISplitter() : mFlags |= UI_OWNS_CHILDS_POSITION; mSplitter = UIWidget::NewWithTag( "splitter::separator" ); mSplitter->setDragEnabled( true ); - mSplitter->addEventListener( Event::OnDragStart, [&]( const Event* ) { - mSplitter->pushState( UIState::StateSelected ); - } ); - mSplitter->addEventListener( - Event::OnDragStop, [&]( const Event* ) { mSplitter->popState( UIState::StateSelected ); } ); + mSplitter->on( Event::OnDragStart, + [this]( const Event* ) { mSplitter->pushState( UIState::StateSelected ); } ); + mSplitter->on( Event::OnDragStop, + [this]( const Event* ) { mSplitter->popState( UIState::StateSelected ); } ); mSplitter->setParent( this ); mSplitter->setMinWidth( 4 ); mSplitter->setMinHeight( 4 ); - mSplitter->addEventListener( Event::OnSizeChange, [&]( const Event* ) { setLayoutDirty(); } ); - mSplitter->addEventListener( Event::MouseOver, [&]( const Event* ) { + mSplitter->on( Event::OnSizeChange, [this]( const Event* ) { setLayoutDirty(); } ); + mSplitter->on( Event::MouseOver, [this]( const Event* ) { getUISceneNode()->setCursor( mOrientation == UIOrientation::Horizontal ? Cursor::SizeWE : Cursor::SizeNS ); } ); - mSplitter->addEventListener( - Event::MouseLeave, [&]( const Event* ) { getUISceneNode()->setCursor( Cursor::Arrow ); } ); - mSplitter->addEventListener( Event::OnPositionChange, [&]( const Event* ) { + mSplitter->on( Event::MouseLeave, + [this]( const Event* ) { getUISceneNode()->setCursor( Cursor::Arrow ); } ); + mSplitter->on( Event::OnPositionChange, [this]( const Event* ) { if ( mSplitter->isDragging() && !mDirtyLayout ) updateFromDrag(); } ); diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index 4a77d6744..efe1dabc0 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -14,7 +14,7 @@ UITab::UITab() : UISelectButton( "tab" ), mOwnedWidget( NULL ), mDragTotalDiff( 0.f ), mTabWidget( NULL ) { mTextBox->setElementTag( mTag + "::text" ); mIcon->setElementTag( mTag + "::icon" ); - auto cb = [&]( const Event* ) { onSizeChange(); }; + auto cb = [this]( const Event* ) { onSizeChange(); }; mTextBox->addEventListener( Event::OnSizeChange, cb ); mIcon->addEventListener( Event::OnSizeChange, cb ); mCloseButton = UIWidget::NewWithTag( mTag + "::close" ); @@ -399,4 +399,9 @@ void UITab::setOwnedWidget( Node* ownedWidget ) { } } +void UITab::setTabSelected() { + if ( getTabWidget() ) + getTabWidget()->setTabSelected( this ); +} + }} // namespace EE::UI diff --git a/src/eepp/ui/uitableheadercolumn.cpp b/src/eepp/ui/uitableheadercolumn.cpp index 77021f33e..ee4793c06 100644 --- a/src/eepp/ui/uitableheadercolumn.cpp +++ b/src/eepp/ui/uitableheadercolumn.cpp @@ -9,7 +9,7 @@ UITableHeaderColumn::UITableHeaderColumn( const std::string& parentTag, UIAbstra UIPushButton( parentTag + "::header::column" ), mView( view ), mColIndex( colIndex ) { setDragEnabled( true ); mInnerWidgetOrientation = InnerWidgetOrientation::IconTextBoxWidget; - auto cb = [&]( const Event* ) { updateLayout(); }; + auto cb = [this]( const Event* ) { updateLayout(); }; mImage = UIImage::NewWithTag( mTag + "::arrow" ); mImage->setLayoutSizePolicy( SizePolicy::WrapContent, SizePolicy::WrapContent ) ->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER ) diff --git a/src/eepp/ui/uitabwidget.cpp b/src/eepp/ui/uitabwidget.cpp index 64afd5847..d1eec129b 100644 --- a/src/eepp/ui/uitabwidget.cpp +++ b/src/eepp/ui/uitabwidget.cpp @@ -45,8 +45,8 @@ UITabWidget::UITabWidget() : mTabScroll = UIScrollBar::NewHorizontalWithTag( "scrollbarmini" ); mTabScroll->setParent( this ); mTabScroll->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::WrapContent ); - mTabScroll->addEventListener( Event::OnSizeChange, [&]( const Event* ) { updateScrollBar(); } ); - mTabScroll->addEventListener( Event::OnValueChange, [&]( const Event* ) { updateScroll(); } ); + mTabScroll->on( Event::OnSizeChange, [this]( const Event* ) { updateScrollBar(); } ); + mTabScroll->on( Event::OnValueChange, [this]( const Event* ) { updateScroll(); } ); onSizeChange(); diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index 68a0a8cec..472fcf8a5 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -712,10 +712,10 @@ void UITextInput::paste() { } void UITextInput::registerCommands() { - mDoc.setCommand( "copy", [&] { copy(); } ); - mDoc.setCommand( "cut", [&] { cut(); } ); - mDoc.setCommand( "paste", [&] { paste(); } ); - mDoc.setCommand( "press-enter", [&] { onPressEnter(); } ); + mDoc.setCommand( "copy", [this] { copy(); } ); + mDoc.setCommand( "cut", [this] { cut(); } ); + mDoc.setCommand( "paste", [this] { paste(); } ); + mDoc.setCommand( "press-enter", [this] { onPressEnter(); } ); } void UITextInput::registerKeybindings() { @@ -881,7 +881,7 @@ bool UITextInput::onCreateContextMenu( const Vector2i& position, const Uint32& f } menu->setCloseOnHide( true ); - menu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + menu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; UIMenuItem* item = event->getNode()->asType(); @@ -896,7 +896,7 @@ bool UITextInput::onCreateContextMenu( const Vector2i& position, const Uint32& f UIMenu::findBestMenuPos( pos, menu ); menu->setPixelsPosition( pos ); menu->show(); - menu->addEventListener( Event::OnClose, [&]( const Event* ) { mCurrentMenu = nullptr; } ); + menu->addEventListener( Event::OnClose, [this]( const Event* ) { mCurrentMenu = nullptr; } ); mCurrentMenu = menu; selCurInit( init ); selCurEnd( end ); diff --git a/src/eepp/ui/uitreeview.cpp b/src/eepp/ui/uitreeview.cpp index 771f3ea5f..a6b6ad611 100644 --- a/src/eepp/ui/uitreeview.cpp +++ b/src/eepp/ui/uitreeview.cpp @@ -93,7 +93,7 @@ void UITreeView::createOrUpdateColumns( bool resetColumnData ) { size_t UITreeView::getItemCount() const { size_t count = 0; - traverseTree( [&]( const int&, const ModelIndex&, const size_t&, const Float& ) { + traverseTree( [&count]( const int&, const ModelIndex&, const size_t&, const Float& ) { count++; return IterationDecision::Continue; } ); @@ -181,7 +181,7 @@ UIWidget* UITreeView::setupCell( UITableCell* widget, UIWidget* rowWidget, widget->setCurIndex( index ); if ( index.column() == (Int64)getModel()->treeColumn() ) { bindNavigationClick( widget ); - widget->addEventListener( Event::MouseClick, [&]( const Event* event ) { + widget->addEventListener( Event::MouseClick, [this]( const Event* event ) { if ( mSingleClickNavigation ) return; auto mouseEvent = static_cast( event ); @@ -364,8 +364,8 @@ Sizef UITreeView::getContentSize() const { void UITreeView::drawChilds() { int realIndex = 0; - traverseTree( [&]( const int&, const ModelIndex& index, const size_t& indentLevel, - const Float& yOffset ) { + traverseTree( [this, &realIndex]( const int&, const ModelIndex& index, + const size_t& indentLevel, const Float& yOffset ) { if ( yOffset - mScrollOffset.y > mSize.getHeight() ) return IterationDecision::Stop; if ( yOffset - mScrollOffset.y + getRowHeight() < 0 ) diff --git a/src/eepp/ui/uiviewpager.cpp b/src/eepp/ui/uiviewpager.cpp index 6e960faf3..1073060b9 100644 --- a/src/eepp/ui/uiviewpager.cpp +++ b/src/eepp/ui/uiviewpager.cpp @@ -60,7 +60,7 @@ void UIViewPager::onChildCountChange( Node* child, const bool& removed ) { } if ( !removed && child != mContainer ) { - child->addEventListener( Event::OnPositionChange, [&]( const Event* ) { updateChilds(); } ); + child->on( Event::OnPositionChange, [this]( const Event* ) { updateChilds(); } ); } UIWidget::onChildCountChange( child, removed ); @@ -216,7 +216,7 @@ void UIViewPager::moveToPage( const Int32& pageNum, bool animate ) { mOrientation == UIOrientation::Horizontal ? Actions::MoveCoordinate::CoordinateX : Actions::MoveCoordinate::CoordinateY, Actions::MoveCoordinate::CoordinateType::PixelPosition ); - action->addEventListener( Action::OnDone, [&]( Action*, const Action::ActionType& ) { + action->on( Action::OnDone, [this]( Action*, const Action::ActionType& ) { sendCommonEvent( Event::OnPageChanged ); } ); mContainer->runAction( action ); diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index 7b124fd7f..a5f1997b3 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -331,7 +331,7 @@ Uint32 UIWidget::onMouseOver( const Vector2i& position, const Uint32& flags ) { mTooltip->show(); } else { runAction( Actions::Runnable::New( - [&] { + [this] { if ( isTooltipEnabled() && getEventDispatcher()->getMouseOverNode() == this ) { createTooltip(); diff --git a/src/eepp/ui/uiwidgettable.cpp b/src/eepp/ui/uiwidgettable.cpp index 1eba295ba..a75351f16 100644 --- a/src/eepp/ui/uiwidgettable.cpp +++ b/src/eepp/ui/uiwidgettable.cpp @@ -30,7 +30,7 @@ UIWidgetTable::UIWidgetTable() : mCollWidthAssigned( false ) { setFlags( UI_AUTO_PADDING ); - auto cb = [&]( const Event* ) { containerResize(); }; + auto cb = [this]( const Event* ) { containerResize(); }; mContainer = eeNew( UIItemContainer, () ); mContainer->setVisible( true ); diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index cb97da68c..aa473e024 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -89,7 +89,7 @@ UIWindow::UIWindow( UIWindow::WindowBaseContainerType type, const StyleConfig& w applyDefaultTheme(); - runOnMainThread( [&]() { onWindowReady(); } ); + runOnMainThread( [this]() { onWindowReady(); } ); mUISceneNode->setIsLoading( loading ); } @@ -158,7 +158,7 @@ void UIWindow::updateWinFlags() { mWindowDecoration->writeNodeFlag( NODE_FLAG_OWNED_BY_NODE, 1 ); } - auto cb = [&]( const Event* ) { onSizeChange(); }; + auto cb = [this]( const Event* ) { onSizeChange(); }; mWindowDecoration->setParent( this ); mWindowDecoration->setVisible( true ); diff --git a/src/modules/eterm/src/eterm/ui/uiterminal.cpp b/src/modules/eterm/src/eterm/ui/uiterminal.cpp index 336f4f915..cbf7a81fe 100644 --- a/src/modules/eterm/src/eterm/ui/uiterminal.cpp +++ b/src/modules/eterm/src/eterm/ui/uiterminal.cpp @@ -53,7 +53,7 @@ UITerminal::UITerminal( const std::shared_ptr& terminalDisplay mFlags |= UI_TAB_STOP | UI_SCROLLABLE; if ( !terminalDisplay ) return; - mTerm->pushEventCallback( [&]( const TerminalDisplay::Event& event ) { + mTerm->pushEventCallback( [this]( const TerminalDisplay::Event& event ) { switch ( event.type ) { case TerminalDisplay::EventType::TITLE: { if ( !mIsCustomTitle && mTitle != event.eventData ) { @@ -77,28 +77,28 @@ UITerminal::UITerminal( const std::shared_ptr& terminalDisplay } ); mVScroll->setParent( this ); - mVScroll->addEventListener( Event::OnValueChange, [&]( const Event* ) { updateScroll(); } ); + mVScroll->addEventListener( Event::OnValueChange, [this]( const Event* ) { updateScroll(); } ); setCommand( "terminal-scroll-up-screen", - [&] { mTerm->action( TerminalShortcutAction::SCROLLUP_SCREEN ); } ); + [this] { mTerm->action( TerminalShortcutAction::SCROLLUP_SCREEN ); } ); setCommand( "terminal-scroll-down-screen", - [&] { mTerm->action( TerminalShortcutAction::SCROLLDOWN_SCREEN ); } ); + [this] { mTerm->action( TerminalShortcutAction::SCROLLDOWN_SCREEN ); } ); setCommand( "terminal-scroll-up-row", - [&] { mTerm->action( TerminalShortcutAction::SCROLLUP_ROW ); } ); + [this] { mTerm->action( TerminalShortcutAction::SCROLLUP_ROW ); } ); setCommand( "terminal-scroll-down-row", - [&] { mTerm->action( TerminalShortcutAction::SCROLLDOWN_ROW ); } ); + [this] { mTerm->action( TerminalShortcutAction::SCROLLDOWN_ROW ); } ); setCommand( "terminal-scroll-up-history", - [&] { mTerm->action( TerminalShortcutAction::SCROLLUP_HISTORY ); } ); + [this] { mTerm->action( TerminalShortcutAction::SCROLLUP_HISTORY ); } ); setCommand( "terminal-scroll-down-history", - [&] { mTerm->action( TerminalShortcutAction::SCROLLDOWN_HISTORY ); } ); + [this] { mTerm->action( TerminalShortcutAction::SCROLLDOWN_HISTORY ); } ); setCommand( "terminal-font-size-grow", - [&] { mTerm->action( TerminalShortcutAction::FONTSIZE_GROW ); } ); + [this] { mTerm->action( TerminalShortcutAction::FONTSIZE_GROW ); } ); setCommand( "terminal-font-size-shrink", - [&] { mTerm->action( TerminalShortcutAction::FONTSIZE_SHRINK ); } ); - setCommand( "terminal-paste", [&] { mTerm->action( TerminalShortcutAction::PASTE ); } ); - setCommand( "terminal-copy", [&] { mTerm->action( TerminalShortcutAction::COPY ); } ); + [this] { mTerm->action( TerminalShortcutAction::FONTSIZE_SHRINK ); } ); + setCommand( "terminal-paste", [this] { mTerm->action( TerminalShortcutAction::PASTE ); } ); + setCommand( "terminal-copy", [this] { mTerm->action( TerminalShortcutAction::COPY ); } ); setCommand( "terminal-open-link", - [&] { Engine::instance()->openURI( mTerm->getTerminal()->getSelection() ); } ); + [this] { Engine::instance()->openURI( mTerm->getTerminal()->getSelection() ); } ); subscribeScheduledUpdate(); } @@ -565,7 +565,7 @@ bool UITerminal::onCreateContextMenu( const Vector2i& position, const Uint32& fl } menu->setCloseOnHide( true ); - menu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + menu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; UIMenuItem* item = event->getNode()->asType(); @@ -578,7 +578,7 @@ bool UITerminal::onCreateContextMenu( const Vector2i& position, const Uint32& fl UIMenu::findBestMenuPos( pos, menu ); menu->setPixelsPosition( pos ); menu->show(); - menu->addEventListener( Event::OnClose, [&]( const Event* ) { mCurrentMenu = nullptr; } ); + menu->addEventListener( Event::OnClose, [this]( const Event* ) { mCurrentMenu = nullptr; } ); mCurrentMenu = menu; return true; } diff --git a/src/modules/maps/src/eepp/maps/mapeditor/mapeditor.cpp b/src/modules/maps/src/eepp/maps/mapeditor/mapeditor.cpp index ca7a2a3bf..5fe72f542 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/mapeditor.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/mapeditor.cpp @@ -158,10 +158,11 @@ void MapEditor::createMenuBar() { PU3->getUISceneNode()->findIconDrawable( "zoom-out", PixelDensity::dpToPxI( 16 ) ) ); PU3->add( "Normal Size", PU3->getUISceneNode()->findIconDrawable( "zoom-original", PixelDensity::dpToPxI( 16 ) ) ); - addShortcut( { KEY_KP_PLUS, KeyMod::getDefaultModifier() }, "zoom-in", [&] { zoomIn(); } ); - addShortcut( { KEY_KP_MINUS, KeyMod::getDefaultModifier() }, "zoom-out", [&] { zoomOut(); } ); + addShortcut( { KEY_KP_PLUS, KeyMod::getDefaultModifier() }, "zoom-in", [this] { zoomIn(); } ); + addShortcut( { KEY_KP_MINUS, KeyMod::getDefaultModifier() }, "zoom-out", + [this] { zoomOut(); } ); addShortcut( { KEY_0, KeyMod::getDefaultModifier() }, "zoom-reset", - [&] { mUIMap->Map()->setScale( 1 ); } ); + [this] { mUIMap->Map()->setScale( 1 ); } ); PU3->addSeparator(); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/uimap.cpp b/src/modules/maps/src/eepp/maps/mapeditor/uimap.cpp index 01e3016d6..f6e0f82c1 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/uimap.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/uimap.cpp @@ -50,7 +50,7 @@ UIMap::UIMap( UITheme* Theme, TileMap* Map ) : onUpdateScreenPos(); - addEventListener( Event::OnUpdateScreenPosition, [&]( const Event* ) { onUpdateScreenPos(); } ); + on( Event::OnUpdateScreenPosition, [this]( const Event* ) { onUpdateScreenPos(); } ); getUIStyle()->setDisableAnimations( false ); } diff --git a/src/tests/test_all/test.cpp b/src/tests/test_all/test.cpp index 5eea6827e..171540b43 100644 --- a/src/tests/test_all/test.cpp +++ b/src/tests/test_all/test.cpp @@ -1029,13 +1029,13 @@ void EETest::createETGEditor() { windowStyleConfig.MinWindowSize = tWin->getSizeWithoutDecoration(); tWin->setStyleConfig( windowStyleConfig ); - mETGEditor = Tools::TextureAtlasEditor::New( tWin, [&] { mETGEditor = NULL; } ); + mETGEditor = Tools::TextureAtlasEditor::New( tWin, [this] { mETGEditor = NULL; } ); tWin->center(); tWin->show(); } void EETest::createColorPicker( Node* node ) { - mColorPicker = Tools::UIColorPicker::NewModal( node, [&]( Color color ) { + mColorPicker = Tools::UIColorPicker::NewModal( node, []( Color color ) { UIMessageBox* msgBox = UIMessageBox::New( UIMessageBox::OK, color.toHexString() ); msgBox->center(); msgBox->show(); @@ -1139,7 +1139,7 @@ void EETest::createDecoratedWindow() { ->setParent( lay ); Button->addEventListener( Event::MouseClick, cb::Make1( this, &EETest::onButtonClick ) ); - mUIWindow->setKeyBindingCommand( "button-click", [&] { addFlyingIcon(); } ); + mUIWindow->setKeyBindingCommand( "button-click", [this] { addFlyingIcon(); } ); mUIWindow->addKeyBinding( { KEY_C, KEYMOD_LALT }, "button-click" ); UITabWidget* TabWidget = UITabWidget::New(); diff --git a/src/tools/ecode/appconfig.cpp b/src/tools/ecode/appconfig.cpp index 7f479da83..cce54d6b1 100644 --- a/src/tools/ecode/appconfig.cpp +++ b/src/tools/ecode/appconfig.cpp @@ -405,13 +405,18 @@ static int countTotalEditors( json j ) { void AppConfig::editorLoadedCounter( ecode::App* app ) { editorsToLoad--; if ( editorsToLoad <= 0 ) { - app->getUISceneNode()->runOnMainThread( [app] { app->loadFileDelayed(); } ); + app->getUISceneNode()->runOnMainThread( [app] { + if ( !app->getFileToOpen().empty() ) { + app->loadFileDelayed(); + } else { + app->getSplitter()->addCurrentPositionToNavigationHistory(); + } + } ); } } -void AppConfig::loadDocuments( UICodeEditorSplitter* editorSplitter, - std::shared_ptr pool, json j, UITabWidget* curTabWidget, - ecode::App* app ) { +void AppConfig::loadDocuments( UICodeEditorSplitter* editorSplitter, json j, + UITabWidget* curTabWidget, ecode::App* app ) { if ( j["type"] == "tabwidget" ) { Int64 currentPage = j["current_page"]; size_t totalToLoad = j["files"].size(); @@ -442,7 +447,7 @@ void AppConfig::loadDocuments( UICodeEditorSplitter* editorSplitter, editorLoadedCounter( app ); } else { editorSplitter->loadAsyncFileFromPathInNewTab( - path, pool, + path, [this, curTabWidget, selection, totalToLoad, currentPage, app]( UICodeEditor* editor, const std::string& ) { if ( !editor->getDocument().getSelection().isValid() || @@ -477,9 +482,9 @@ void AppConfig::loadDocuments( UICodeEditorSplitter* editorSplitter, if ( nullptr == splitter ) return; - loadDocuments( editorSplitter, pool, j["first"], curTabWidget, app ); + loadDocuments( editorSplitter, j["first"], curTabWidget, app ); UITabWidget* tabWidget = splitter->getLastWidget()->asType(); - loadDocuments( editorSplitter, pool, j["last"], tabWidget, app ); + loadDocuments( editorSplitter, j["last"], tabWidget, app ); splitter->setSplitPartition( StyleSheetLength( j["split"] ) ); } @@ -535,7 +540,7 @@ void AppConfig::loadProject( std::string projectFolder, UICodeEditorSplitter* ed editorsToLoad = countTotalEditors( j ); UITabWidget* curTabWidget = editorSplitter->tabWidgetFromWidget( editorSplitter->getCurWidget() ); - loadDocuments( editorSplitter, pool, j, curTabWidget, app ); + loadDocuments( editorSplitter, j, curTabWidget, app ); } } diff --git a/src/tools/ecode/appconfig.hpp b/src/tools/ecode/appconfig.hpp index 9653e88e1..0e4d232ee 100644 --- a/src/tools/ecode/appconfig.hpp +++ b/src/tools/ecode/appconfig.hpp @@ -192,8 +192,8 @@ class AppConfig { protected: Int64 editorsToLoad{ 0 }; - void loadDocuments( UICodeEditorSplitter* editorSplitter, std::shared_ptr pool, - json j, UITabWidget* curTabWidget, ecode::App* app ); + void loadDocuments( UICodeEditorSplitter* editorSplitter, json j, UITabWidget* curTabWidget, + ecode::App* app ); void editorLoadedCounter( ecode::App* app ); }; diff --git a/src/tools/ecode/docsearchcontroller.cpp b/src/tools/ecode/docsearchcontroller.cpp index cef4e4fa6..4dc5f694a 100644 --- a/src/tools/ecode/docsearchcontroller.cpp +++ b/src/tools/ecode/docsearchcontroller.cpp @@ -4,10 +4,10 @@ namespace ecode { DocSearchController::DocSearchController( UICodeEditorSplitter* editorSplitter, App* app ) : - mEditorSplitter( editorSplitter ), mApp( app ) {} + mSplitter( editorSplitter ), mApp( app ) {} void DocSearchController::refreshHighlight() { - if ( mSearchState.editor && mEditorSplitter->editorExists( mSearchState.editor ) ) { + if ( mSearchState.editor && mSplitter->editorExists( mSearchState.editor ) ) { mSearchState.text = mFindInput->getText(); mSearchState.editor->setHighlightWord( mSearchState.toTextSearchParams() ); if ( !mSearchState.text.empty() ) { @@ -30,7 +30,7 @@ void DocSearchController::initSearchBar( std::unordered_map keybindings ) { mSearchBarLayout = searchBar; mSearchBarLayout->setVisible( false )->setEnabled( false ); - auto addClickListener = [&]( UIWidget* widget, std::string cmd ) { + auto addClickListener = [this]( UIWidget* widget, std::string cmd ) { widget->setTooltipText( mSearchBarLayout->getKeyBindings().getCommandKeybindString( cmd ) ); widget->addEventListener( Event::MouseClick, [this, cmd]( const Event* event ) { const MouseEvent* mouseEvent = static_cast( event ); @@ -38,7 +38,7 @@ void DocSearchController::initSearchBar( mSearchBarLayout->execute( cmd ); } ); }; - auto addReturnListener = [&]( UIWidget* widget, std::string cmd ) { + auto addReturnListener = [this]( UIWidget* widget, std::string cmd ) { widget->addEventListener( Event::OnPressEnter, [this, cmd]( const Event* ) { mSearchBarLayout->execute( cmd ); } ); @@ -79,42 +79,42 @@ void DocSearchController::initSearchBar( mEscapeSequenceChk->setTooltipText( mEscapeSequenceChk->getTooltipText() + " (" + kbindEscape + ")" ); - mCaseSensitiveChk->addEventListener( Event::OnValueChange, [&]( const Event* ) { + mCaseSensitiveChk->addEventListener( Event::OnValueChange, [this]( const Event* ) { mSearchState.caseSensitive = mCaseSensitiveChk->isChecked(); refreshHighlight(); } ); - mEscapeSequenceChk->addEventListener( Event::OnValueChange, [&]( const Event* ) { + mEscapeSequenceChk->addEventListener( Event::OnValueChange, [this]( const Event* ) { mSearchState.escapeSequences = mEscapeSequenceChk->isChecked(); refreshHighlight(); } ); - mWholeWordChk->addEventListener( Event::OnValueChange, [&]( const Event* ) { + mWholeWordChk->addEventListener( Event::OnValueChange, [this]( const Event* ) { mSearchState.wholeWord = mWholeWordChk->isChecked(); refreshHighlight(); } ); - mLuaPatternChk->addEventListener( Event::OnValueChange, [&]( const Event* ) { + mLuaPatternChk->addEventListener( Event::OnValueChange, [this]( const Event* ) { mSearchState.type = mLuaPatternChk->isChecked() ? TextDocument::FindReplaceType::LuaPattern : TextDocument::FindReplaceType::Normal; refreshHighlight(); } ); mFindInput->addEventListener( Event::OnTextChanged, - [&]( const Event* ) { refreshHighlight(); } ); - mFindInput->addEventListener( Event::OnTextPasted, [&]( const Event* ) { + [this]( const Event* ) { refreshHighlight(); } ); + mFindInput->addEventListener( Event::OnTextPasted, [this]( const Event* ) { if ( mFindInput->getUISceneNode()->getWindow()->getClipboard()->getText().find( '\n' ) != String::InvalidPos ) { if ( !mEscapeSequenceChk->isChecked() ) mEscapeSequenceChk->setChecked( true ); } } ); - mSearchBarLayout->setCommand( "close-searchbar", [&] { + mSearchBarLayout->setCommand( "close-searchbar", [this] { hideSearchBar(); - if ( mEditorSplitter->getCurWidget() ) - mEditorSplitter->getCurWidget()->setFocus(); + if ( mSplitter->getCurWidget() ) + mSplitter->getCurWidget()->setFocus(); if ( mSearchState.editor ) { - if ( mEditorSplitter->editorExists( mSearchState.editor ) ) { + if ( mSplitter->editorExists( mSearchState.editor ) ) { mSearchState.editor->setHighlightWord( { "" } ); mSearchState.editor->setHighlightTextRange( TextRange() ); } @@ -134,16 +134,19 @@ void DocSearchController::initSearchBar( mSearchBarLayout->setCommand( "replace-selection", [this] { replaceSelection( mSearchState, mReplaceInput->getText() ); } ); - mSearchBarLayout->setCommand( - "change-case", [&] { mCaseSensitiveChk->setChecked( !mCaseSensitiveChk->isChecked() ); } ); - mSearchBarLayout->setCommand( - "change-whole-word", [&] { mWholeWordChk->setChecked( !mWholeWordChk->isChecked() ); } ); - mSearchBarLayout->setCommand( "change-escape-sequence", [&] { - mEscapeSequenceChk->setChecked( !mEscapeSequenceChk->isChecked() ); + mSearchBarLayout->setCommand( "change-case", [this] { + mCaseSensitiveChk->setChecked( !mCaseSensitiveChk->isChecked() ); } ); mSearchBarLayout->setCommand( - "toggle-lua-pattern", [&] { mLuaPatternChk->setChecked( !mLuaPatternChk->isChecked() ); } ); - mSearchBarLayout->setCommand( "open-global-search", [&] { mApp->showGlobalSearch( false ); } ); + "change-whole-word", [this] { mWholeWordChk->setChecked( !mWholeWordChk->isChecked() ); } ); + mSearchBarLayout->setCommand( "change-escape-sequence", [this] { + mEscapeSequenceChk->setChecked( !mEscapeSequenceChk->isChecked() ); + } ); + mSearchBarLayout->setCommand( "toggle-lua-pattern", [this] { + mLuaPatternChk->setChecked( !mLuaPatternChk->isChecked() ); + } ); + mSearchBarLayout->setCommand( "open-global-search", + [this] { mApp->showGlobalSearch( false ); } ); addReturnListener( mFindInput, "repeat-find" ); addReturnListener( mReplaceInput, "find-and-replace" ); @@ -155,16 +158,16 @@ void DocSearchController::initSearchBar( addClickListener( replaceAllButton, "replace-all" ); addClickListener( closeButton, "close-searchbar" ); mReplaceInput->addEventListener( Event::OnTabNavigate, - [&]( const Event* ) { mFindInput->setFocus(); } ); + [this]( const Event* ) { mFindInput->setFocus(); } ); } void DocSearchController::showFindView() { mApp->hideLocateBar(); mApp->hideGlobalSearchBar(); - if ( !mEditorSplitter->curEditorExistsAndFocused() ) + if ( !mSplitter->curEditorExistsAndFocused() ) return; - UICodeEditor* editor = mEditorSplitter->getCurEditor(); + UICodeEditor* editor = mSplitter->getCurEditor(); mSearchState.editor = editor; mSearchState.range = TextRange(); mSearchState.caseSensitive = mCaseSensitiveChk->isChecked(); @@ -201,7 +204,7 @@ void DocSearchController::showFindView() { bool DocSearchController::findPrevText( SearchState& search ) { if ( search.text.empty() ) search.text = mLastSearch; - if ( !search.editor || !mEditorSplitter->editorExists( search.editor ) || search.text.empty() ) + if ( !search.editor || !mSplitter->editorExists( search.editor ) || search.text.empty() ) return false; search.editor->getDocument().setActiveClient( search.editor ); @@ -222,6 +225,7 @@ bool DocSearchController::findPrevText( SearchState& search ) { search.range ); if ( found.isValid() ) { doc.setSelection( found ); + mSplitter->addEditorPositionToNavigationHistory( search.editor ); mFindInput->removeClass( "error" ); return true; } else { @@ -229,6 +233,7 @@ bool DocSearchController::findPrevText( SearchState& search ) { range ); if ( found.isValid() ) { doc.setSelection( found ); + mSplitter->addEditorPositionToNavigationHistory( search.editor ); mFindInput->removeClass( "error" ); return true; } @@ -240,7 +245,7 @@ bool DocSearchController::findPrevText( SearchState& search ) { bool DocSearchController::findNextText( SearchState& search ) { if ( search.text.empty() ) search.text = mLastSearch; - if ( !search.editor || !mEditorSplitter->editorExists( search.editor ) || search.text.empty() ) + if ( !search.editor || !mSplitter->editorExists( search.editor ) || search.text.empty() ) return false; search.editor->getDocument().setActiveClient( search.editor ); @@ -261,6 +266,7 @@ bool DocSearchController::findNextText( SearchState& search ) { doc.find( txt, from, search.caseSensitive, search.wholeWord, search.type, range ); if ( found.isValid() ) { doc.setSelection( found.reversed() ); + mSplitter->addEditorPositionToNavigationHistory( search.editor ); mFindInput->removeClass( "error" ); return true; } else { @@ -268,6 +274,7 @@ bool DocSearchController::findNextText( SearchState& search ) { range ); if ( found.isValid() ) { doc.setSelection( found.reversed() ); + mSplitter->addEditorPositionToNavigationHistory( search.editor ); mFindInput->removeClass( "error" ); return true; } @@ -277,7 +284,7 @@ bool DocSearchController::findNextText( SearchState& search ) { } bool DocSearchController::replaceSelection( SearchState& search, const String& replacement ) { - if ( !search.editor || !mEditorSplitter->editorExists( search.editor ) || + if ( !search.editor || !mSplitter->editorExists( search.editor ) || !search.editor->getDocument().hasSelection() ) return false; search.editor->getDocument().setActiveClient( search.editor ); @@ -286,7 +293,7 @@ bool DocSearchController::replaceSelection( SearchState& search, const String& r } void DocSearchController::selectAll( SearchState& search ) { - if ( !search.editor || !mEditorSplitter->editorExists( search.editor ) ) + if ( !search.editor || !mSplitter->editorExists( search.editor ) ) return; if ( search.text.empty() ) search.text = mLastSearch; @@ -302,7 +309,7 @@ void DocSearchController::selectAll( SearchState& search ) { } int DocSearchController::replaceAll( SearchState& search, const String& replace ) { - if ( !search.editor || !mEditorSplitter->editorExists( search.editor ) ) + if ( !search.editor || !mSplitter->editorExists( search.editor ) ) return 0; if ( search.text.empty() ) search.text = mLastSearch; @@ -327,7 +334,7 @@ int DocSearchController::replaceAll( SearchState& search, const String& replace } bool DocSearchController::findAndReplace( SearchState& search, const String& replace ) { - if ( !search.editor || !mEditorSplitter->editorExists( search.editor ) ) + if ( !search.editor || !mSplitter->editorExists( search.editor ) ) return false; if ( search.text.empty() ) search.text = mLastSearch; @@ -358,7 +365,7 @@ void DocSearchController::hideSearchBar() { void DocSearchController::onCodeEditorFocusChange( UICodeEditor* editor ) { if ( mSearchState.editor && mSearchState.editor != editor ) { TextSearchParams word; - if ( mEditorSplitter->editorExists( mSearchState.editor ) ) { + if ( mSplitter->editorExists( mSearchState.editor ) ) { word = mSearchState.editor->getHighlightWord(); mSearchState.editor->setHighlightWord( { "" } ); mSearchState.editor->setHighlightTextRange( TextRange() ); diff --git a/src/tools/ecode/docsearchcontroller.hpp b/src/tools/ecode/docsearchcontroller.hpp index 5ac5e629a..18a1b2059 100644 --- a/src/tools/ecode/docsearchcontroller.hpp +++ b/src/tools/ecode/docsearchcontroller.hpp @@ -74,7 +74,7 @@ class DocSearchController { void refreshHighlight(); protected: - UICodeEditorSplitter* mEditorSplitter{ nullptr }; + UICodeEditorSplitter* mSplitter{ nullptr }; UITextInput* mFindInput{ nullptr }; UITextInput* mReplaceInput{ nullptr }; UISearchBar* mSearchBarLayout{ nullptr }; diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 2f5859876..8292495b3 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -44,7 +44,7 @@ bool App::onCloseRequestCallback( EE::Window::Window* ) { i18n( "confirm_ecode_exit", "Do you really want to close the code editor?\nAll changes will be lost." ) .unescape() ); - msgBox->addEventListener( Event::OnConfirm, [&]( const Event* ) { + msgBox->addEventListener( Event::OnConfirm, [this]( const Event* ) { if ( !mCurrentProject.empty() ) mConfig.saveProject( mCurrentProject, mSplitter, mConfigPath, mProjectDocConfig, mProjectBuildManager ? mProjectBuildManager->getConfig() @@ -93,7 +93,7 @@ void App::saveAllProcess() { if ( mTmpDocs.empty() ) return; - mSplitter->forEachEditorStoppable( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditorStoppable( [this]( UICodeEditor* editor ) { if ( editor->getDocument().isDirty() && std::find( mTmpDocs.begin(), mTmpDocs.end(), &editor->getDocument() ) != mTmpDocs.end() ) { @@ -123,7 +123,7 @@ void App::saveAllProcess() { } void App::saveAll() { - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { if ( editor->isDirty() ) mTmpDocs.insert( &editor->getDocument() ); } ); @@ -190,12 +190,12 @@ void App::openFileDialog() { dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); dialog->setTitle( i18n( "open_file", "Open File" ) ); dialog->setCloseShortcut( KEY_ESCAPE ); - dialog->addEventListener( Event::OpenFile, [&]( const Event* event ) { + dialog->addEventListener( Event::OpenFile, [this]( const Event* event ) { auto file = event->getNode()->asType()->getFullPath(); mLastFileFolder = FileSystem::fileRemoveFileName( file ); loadFileFromPath( file ); } ); - dialog->addEventListener( Event::OnWindowClose, [&]( const Event* ) { + dialog->addEventListener( Event::OnWindowClose, [this]( const Event* ) { if ( mSplitter && mSplitter->getCurWidget() && !SceneManager::instance()->isShuttingDown() ) mSplitter->getCurWidget()->setFocus(); } ); @@ -234,12 +234,12 @@ void App::openFolderDialog() { dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); dialog->setTitle( i18n( "open_folder", "Open Folder" ) ); dialog->setCloseShortcut( KEY_ESCAPE ); - dialog->addEventListener( Event::OpenFile, [&]( const Event* event ) { + dialog->addEventListener( Event::OpenFile, [this]( const Event* event ) { String path( event->getNode()->asType()->getFullPath() ); if ( FileSystem::isDirectory( path ) ) loadFolder( path ); } ); - dialog->addEventListener( Event::OnWindowClose, [&]( const Event* ) { + dialog->addEventListener( Event::OnWindowClose, [this]( const Event* ) { if ( mSplitter && mSplitter->getCurWidget() && !SceneManager::instance()->isShuttingDown() ) mSplitter->getCurWidget()->setFocus(); } ); @@ -262,7 +262,7 @@ void App::openFontDialog( std::string& fontPath, bool loadingMonoFont ) { dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); dialog->setTitle( i18n( "select_font_file", "Select Font File" ) ); dialog->setCloseShortcut( KEY_ESCAPE ); - dialog->addEventListener( Event::OnWindowClose, [&]( const Event* ) { + dialog->addEventListener( Event::OnWindowClose, [this]( const Event* ) { if ( mSplitter && mSplitter->getCurWidget() && !SceneManager::instance()->isShuttingDown() ) mSplitter->getCurWidget()->setFocus(); } ); @@ -286,7 +286,7 @@ void App::openFontDialog( std::string& fontPath, bool loadingMonoFont ) { mFontMono->setBoldAdvanceSameAsRegular( true ); if ( mSplitter ) { mSplitter->forEachEditor( - [&]( UICodeEditor* editor ) { editor->setFont( mFontMono ); } ); + [this]( UICodeEditor* editor ) { editor->setFont( mFontMono ); } ); } }; if ( !fontMono->isMonospace() ) { @@ -398,7 +398,7 @@ void App::runCommand( const std::string& command ) { void App::onPluginEnabled( UICodeEditorPlugin* plugin ) { if ( mSplitter ) mSplitter->forEachEditor( - [&]( UICodeEditor* editor ) { editor->registerPlugin( plugin ); } ); + [plugin]( UICodeEditor* editor ) { editor->registerPlugin( plugin ); } ); } void App::initPluginManager() { @@ -412,12 +412,12 @@ void App::initPluginManager() { cb( tab->getOwnedWidget()->asType(), path ); } } ); - mPluginManager->onPluginEnabled = [&]( UICodeEditorPlugin* plugin ) { + mPluginManager->onPluginEnabled = [this]( UICodeEditorPlugin* plugin ) { if ( nullptr == mUISceneNode || plugin->isReady() ) { onPluginEnabled( plugin ); } else { // If plugin loads asynchronously and is not ready, delay the plugin enabled callback - plugin->addOnReadyCallback( [&]( UICodeEditorPlugin* plugin, const Uint32& cbId ) { + plugin->addOnReadyCallback( [this]( UICodeEditorPlugin* plugin, const Uint32& cbId ) { mUISceneNode->runOnMainThread( [&, plugin]() { onPluginEnabled( plugin ); } ); plugin->removeReadyCallback( cbId ); } ); @@ -657,7 +657,7 @@ void App::updateRecentFiles() { menu->add( file ); menu->addSeparator(); menu->add( i18n( "clear_menu", "Clear Menu" ) )->setId( "clear-menu" ); - menu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + menu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; const std::string& id = event->getNode()->asType()->getId(); @@ -699,7 +699,7 @@ void App::updateRecentFolders() { i18n( "restore_last_session_at_startup", "Restart last session at startup" ) ) ->setActive( mConfig.workspace.restoreLastSession ) ->setId( "restore-last-session-at-startup" ); - menu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + menu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; const std::string& id = event->getNode()->asType()->getId(); @@ -757,6 +757,10 @@ const std::map& App::getRealTerminalKeybindi return mRealTerminalKeybindings; } +const std::string& App::getFileToOpen() const { + return mFileToOpen; +} + void App::switchSidePanel() { mConfig.ui.showSidePanel = !mConfig.ui.showSidePanel; mSettings->getWindowMenu() @@ -988,7 +992,7 @@ void App::setEditorFontSize() { msgBox->showWhenReady(); msgBox->addEventListener( Event::OnConfirm, [&, msgBox]( const Event* ) { mConfig.editor.fontSize = StyleSheetLength( msgBox->getTextInput()->getText() ); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setFontSize( mConfig.editor.fontSize.asDp( 0, Sizef(), mDisplayDPI ) ); } ); } ); @@ -1004,7 +1008,7 @@ void App::setTerminalFontSize() { msgBox->showWhenReady(); msgBox->addEventListener( Event::OnConfirm, [&, msgBox]( const Event* ) { mConfig.term.fontSize = StyleSheetLength( msgBox->getTextInput()->getText() ); - mSplitter->forEachWidget( [&]( UIWidget* widget ) { + mSplitter->forEachWidget( [this]( UIWidget* widget ) { if ( widget && widget->isType( UI_TYPE_TERMINAL ) ) widget->asType()->setFontSize( mConfig.term.fontSize.asPixels( 0, Sizef(), mDisplayDPI ) ); @@ -1026,7 +1030,7 @@ void App::setUIFontSize() { UIThemeManager* manager = mUISceneNode->getUIThemeManager(); manager->setDefaultFontSize( fontSize ); manager->getDefaultTheme()->setDefaultFontSize( fontSize ); - mUISceneNode->forEachNode( [&]( Node* node ) { + mUISceneNode->forEachNode( [this]( Node* node ) { if ( node->isType( UI_TYPE_TEXTVIEW ) ) { UITextView* textView = node->asType(); if ( !textView->getUIStyle()->hasProperty( PropertyId::FontSize ) ) { @@ -1073,7 +1077,7 @@ void App::setUIPanelFontSize() { } void App::setFocusEditorOnClose( UIMessageBox* msgBox ) { - msgBox->addEventListener( Event::OnClose, [&]( const Event* ) { + msgBox->addEventListener( Event::OnClose, [this]( const Event* ) { if ( mSplitter && mSplitter->getCurWidget() ) mSplitter->getCurWidget()->setFocus(); } ); @@ -1158,8 +1162,9 @@ void App::setLineSpacing() { msgBox->showWhenReady(); msgBox->addEventListener( Event::OnConfirm, [&, msgBox]( const Event* ) { mConfig.editor.lineSpacing = StyleSheetLength( msgBox->getTextInput()->getText() ); - mSplitter->forEachEditor( - [&]( UICodeEditor* editor ) { editor->setLineSpacing( mConfig.editor.lineSpacing ); } ); + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { + editor->setLineSpacing( mConfig.editor.lineSpacing ); + } ); } ); setFocusEditorOnClose( msgBox ); } @@ -1176,7 +1181,7 @@ void App::setCursorBlinkingTime() { msgBox->addEventListener( Event::OnConfirm, [&, msgBox]( const Event* ) { mConfig.editor.cursorBlinkingTime = Time::fromString( msgBox->getTextInput()->getText().toUtf8() ); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setCursorBlinkTime( mConfig.editor.cursorBlinkingTime ); } ); msgBox->closeWindow(); @@ -1458,7 +1463,7 @@ void App::reloadKeybindings() { mRealTerminalKeybindings.clear(); mRealDefaultKeybindings.clear(); loadKeybindings(); - mSplitter->forEachEditor( [&]( UICodeEditor* ed ) { + mSplitter->forEachEditor( [this]( UICodeEditor* ed ) { ed->getKeyBindings().reset(); ed->getKeyBindings().addKeybindsStringUnordered( mKeybindings ); } ); @@ -1500,7 +1505,7 @@ void App::updateDocInfo( TextDocument& doc ) { mDocInfo->setVisible( true ); updateDocInfoLocation(); mDocInfo->setText( String::format( - "%s: %lld / %lu %s: %lld %s", i18n( "line_abbr", "line" ).toUtf8().c_str(), + "%s: %lld / %zu %s: %lld %s", i18n( "line_abbr", "line" ).toUtf8().c_str(), doc.getSelection().start().line() + 1, doc.linesCount(), i18n( "col_abbr", "col" ).toUtf8().c_str(), mSplitter->getCurEditor()->getCurrentColumnCount(), @@ -1591,11 +1596,13 @@ void App::loadFileDelayed() { UICodeEditor* editor = tab->getOwnedWidget()->asType(); if ( editor->getDocument().isLoading() ) { Uint32 cb = - editor->on( Event::OnDocumentLoaded, [fileAndPos]( const Event* event ) { + editor->on( Event::OnDocumentLoaded, [this, fileAndPos]( const Event* event ) { if ( event->getNode()->isType( UI_TYPE_CODEEDITOR ) ) { UICodeEditor* editor = event->getNode()->asType(); - editor->runOnMainThread( - [editor, fileAndPos] { editor->goToLine( fileAndPos.second ); } ); + editor->runOnMainThread( [this, editor, fileAndPos] { + editor->goToLine( fileAndPos.second ); + mSplitter->addEditorPositionToNavigationHistory( editor ); + } ); } event->getNode()->removeEventListener( event->getCallbackId() ); } ); @@ -1603,15 +1610,19 @@ void App::loadFileDelayed() { editor->runOnMainThread( [editor, cb]() { editor->removeEventListener( cb ); }, Seconds( 4 ) ); } else { - editor->runOnMainThread( - [editor, fileAndPos] { editor->goToLine( fileAndPos.second ); } ); + editor->runOnMainThread( [this, editor, fileAndPos] { + editor->goToLine( fileAndPos.second ); + mSplitter->addEditorPositionToNavigationHistory( editor ); + } ); } } } else { loadFileFromPath( fileAndPos.first, true, nullptr, - [fileAndPos]( UICodeEditor* editor, const std::string& ) { - editor->runOnMainThread( - [editor, fileAndPos] { editor->goToLine( fileAndPos.second ); } ); + [this, fileAndPos]( UICodeEditor* editor, const std::string& ) { + editor->runOnMainThread( [this, editor, fileAndPos] { + editor->goToLine( fileAndPos.second ); + mSplitter->addEditorPositionToNavigationHistory( editor ); + } ); } ); } @@ -1877,6 +1888,7 @@ void App::closeEditors() { mRecentClosedFiles = {}; mSplitter->removeTabWithOwnedWidgetId( "welcome_ecode" ); + mSplitter->clearNavigationHistory(); mStatusBar->setVisible( mConfig.ui.showStatusBar ); mConfig.saveProject( mCurrentProject, mSplitter, mConfigPath, mProjectDocConfig, @@ -1930,7 +1942,7 @@ void App::closeFolder() { UIMessageBox::OK_CANCEL, i18n( "confirm_close_folder", "Do you really want to close the folder?\nSome files haven't been saved." ) ); - msgBox->addEventListener( Event::OnConfirm, [&]( const Event* ) { closeEditors(); } ); + msgBox->addEventListener( Event::OnConfirm, [this]( const Event* ) { closeEditors(); } ); msgBox->setTitle( i18n( "close_folder_question", "Close Folder?" ) ); msgBox->center(); msgBox->showWhenReady(); @@ -2059,9 +2071,9 @@ void App::loadFileFromPath( } } else { if ( inNewTab ) { - mSplitter->loadAsyncFileFromPathInNewTab( path, mThreadPool, onLoaded ); + mSplitter->loadAsyncFileFromPathInNewTab( path, onLoaded ); } else { - mSplitter->loadAsyncFileFromPath( path, mThreadPool, codeEditor, onLoaded ); + mSplitter->loadAsyncFileFromPath( path, codeEditor, onLoaded ); } } } @@ -2158,42 +2170,42 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { editor->addKeyBinds( getLocalKeybindings() ); editor->addUnlockedCommands( getUnlockedCommands() ); - doc.setCommand( "save-doc", [&] { saveDoc(); } ); - doc.setCommand( "save-as-doc", [&] { + doc.setCommand( "save-doc", [this] { saveDoc(); } ); + doc.setCommand( "save-as-doc", [this] { if ( mSplitter->curEditorExistsAndFocused() ) saveFileDialog( mSplitter->getCurEditor() ); } ); - doc.setCommand( "save-all", [&] { saveAll(); } ); - doc.setCommand( "repeat-find", [&] { + doc.setCommand( "save-all", [this] { saveAll(); } ); + doc.setCommand( "repeat-find", [this] { mDocSearchController->findNextText( mDocSearchController->getSearchState() ); } ); - doc.setCommand( "find-prev", [&] { + doc.setCommand( "find-prev", [this] { mDocSearchController->findPrevText( mDocSearchController->getSearchState() ); } ); - doc.setCommand( "close-folder", [&] { closeFolder(); } ); - doc.setCommand( "lock", [&] { + doc.setCommand( "close-folder", [this] { closeFolder(); } ); + doc.setCommand( "lock", [this] { if ( mSplitter->curEditorExistsAndFocused() ) { mSplitter->getCurEditor()->setLocked( true ); mSettings->updateDocumentMenu(); } } ); - doc.setCommand( "unlock", [&] { + doc.setCommand( "unlock", [this] { if ( mSplitter->curEditorExistsAndFocused() ) { mSplitter->getCurEditor()->setLocked( false ); mSettings->updateDocumentMenu(); } } ); - doc.setCommand( "lock-toggle", [&] { + doc.setCommand( "lock-toggle", [this] { if ( mSplitter->curEditorExistsAndFocused() ) { mSplitter->getCurEditor()->setLocked( !mSplitter->getCurEditor()->isLocked() ); mSettings->updateDocumentMenu(); } } ); - doc.setCommand( "go-to-line", [&] { mUniversalLocator->goToLine(); } ); - doc.setCommand( "load-current-dir", [&] { loadCurrentDirectory(); } ); + doc.setCommand( "go-to-line", [this] { mUniversalLocator->goToLine(); } ); + doc.setCommand( "load-current-dir", [this] { loadCurrentDirectory(); } ); registerUnlockedCommands( doc ); - editor->addEventListener( Event::OnDocumentSave, [&]( const Event* event ) { + editor->addEventListener( Event::OnDocumentSave, [this]( const Event* event ) { UICodeEditor* editor = event->getNode()->asType(); updateEditorTabTitle( editor ); if ( mSplitter->curEditorExistsAndFocused() && mSplitter->getCurEditor() == editor ) @@ -2233,7 +2245,7 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { editor->getKeyBindings().addKeybindsStringUnordered( mKeybindings ); } - editor->addEventListener( Event::OnDocumentClosed, [&]( const Event* event ) { + editor->addEventListener( Event::OnDocumentClosed, [this]( const Event* event ) { if ( !appInstance ) return; const DocEvent* docEvent = static_cast( event ); @@ -2252,7 +2264,7 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { } } ); - editor->addEventListener( Event::OnDocumentMoved, [&]( const Event* event ) { + editor->addEventListener( Event::OnDocumentMoved, [this]( const Event* event ) { if ( !appInstance ) return; UICodeEditor* editor = event->getNode()->asType(); @@ -2299,6 +2311,10 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { editor->addEventListener( Event::OnDocumentSave, docChanged ); editor->addEventListener( Event::OnEditorTabReady, docChanged ); + editor->addEventListener( Event::OnCursorPosChangeInteresting, [this, editor]( auto ) { + mSplitter->addEditorPositionToNavigationHistory( editor ); + } ); + editor->showMinimap( config.minimap ); editor->showLinesRelativePosition( config.linesRelativePosition ); @@ -2375,7 +2391,7 @@ void App::loadDirTree( const std::string& path ) { clock->getElapsedTime().asMilliseconds(), dirTree.getFilesCount() ); eeDelete( clock ); mDirTreeReady = true; - mUISceneNode->runOnMainThread( [&] { + mUISceneNode->runOnMainThread( [this] { mUniversalLocator->updateFilesTable(); if ( mSplitter->curEditorExistsAndFocused() ) syncProjectTreeWithEditor( mSplitter->getCurEditor() ); @@ -2509,7 +2525,7 @@ void App::toggleHiddenFiles() { true, !mFileSystemModel->getDisplayConfig().ignoreHidden, {}, - [&]( const std::string& filePath ) -> bool { + [this]( const std::string& filePath ) -> bool { return isFileVisibleInTreeView( filePath ); } } ); if ( mProjectTreeView ) @@ -2591,7 +2607,7 @@ void App::createAndShowRecentFolderPopUpMenu( Node* recentFolderBut ) { return; for ( const auto& file : mRecentFolders ) menu->add( file ); - menu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + menu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; const String& txt = event->getNode()->asType()->getText(); @@ -2610,7 +2626,7 @@ void App::createAndShowRecentFilesPopUpMenu( Node* recentFilesBut ) { return; for ( const auto& file : mRecentFiles ) menu->add( file ); - menu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + menu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; const String& txt = event->getNode()->asType()->getText(); @@ -2650,12 +2666,12 @@ void App::consoleToggle() { void App::initProjectTreeView( std::string path ) { mProjectViewEmptyCont = mUISceneNode->find( "project_view_empty" ); mProjectViewEmptyCont->find( "open_folder" ) - ->addEventListener( Event::MouseClick, [&]( const Event* event ) { + ->addEventListener( Event::MouseClick, [this]( const Event* event ) { if ( event->asMouseEvent()->getFlags() & EE_BUTTON_LMASK ) runCommand( "open-folder" ); } ); mProjectViewEmptyCont->find( "open_recent_folder" ) - ->addEventListener( Event::MouseClick, [&]( const Event* event ) { + ->addEventListener( Event::MouseClick, [this]( const Event* event ) { if ( event->asMouseEvent()->getFlags() & EE_BUTTON_LMASK ) createAndShowRecentFolderPopUpMenu( mProjectViewEmptyCont->find( "open_recent_folder" ) ); @@ -2673,7 +2689,7 @@ void App::initProjectTreeView( std::string path ) { mProjectTreeView->setHeadersVisible( false ); mProjectTreeView->setExpandersAsIcons( true ); mProjectTreeView->setSingleClickNavigation( mConfig.editor.singleClickTreeNavigation ); - mProjectTreeView->addEventListener( Event::OnModelEvent, [&]( const Event* event ) { + mProjectTreeView->addEventListener( Event::OnModelEvent, [this]( const Event* event ) { const ModelEvent* modelEvent = static_cast( event ); ModelEventType type = modelEvent->getModelEventType(); if ( type == ModelEventType::Open || type == ModelEventType::OpenMenu ) { @@ -2700,12 +2716,12 @@ void App::initProjectTreeView( std::string path ) { } } } ); - mProjectTreeView->addEventListener( Event::MouseClick, [&]( const Event* event ) { + mProjectTreeView->addEventListener( Event::MouseClick, [this]( const Event* event ) { const MouseEvent* mouseEvent = static_cast( event ); if ( mouseEvent->getFlags() & EE_BUTTON_RMASK ) mSettings->createProjectTreeMenu(); } ); - mProjectTreeView->addEventListener( Event::KeyDown, [&]( const Event* event ) { + mProjectTreeView->addEventListener( Event::KeyDown, [this]( const Event* event ) { if ( !mFileSystemModel ) return 0; const KeyEvent* keyEvent = static_cast( event ); @@ -2761,7 +2777,7 @@ void App::initProjectTreeView( std::string path ) { mFileSystemModel = FileSystemModel::New( folderPath, FileSystemModel::Mode::FilesAndDirectories, - { true, true, true, {}, [&]( const std::string& filePath ) -> bool { + { true, true, true, {}, [this]( const std::string& filePath ) -> bool { return isFileVisibleInTreeView( filePath ); } } ); @@ -2774,9 +2790,11 @@ void App::initProjectTreeView( std::string path ) { std::function forcePosition; if ( initialPosition.isValid() ) { - forcePosition = [initialPosition]( UICodeEditor* editor, const auto& ) { - editor->runOnMainThread( - [initialPosition, editor] { editor->goToLine( initialPosition ); } ); + forcePosition = [this, initialPosition]( UICodeEditor* editor, const auto& ) { + editor->runOnMainThread( [this, initialPosition, editor] { + editor->goToLine( initialPosition ); + mSplitter->addEditorPositionToNavigationHistory( editor ); + } ); }; } @@ -2800,7 +2818,7 @@ void App::initProjectTreeView( std::string path ) { } void App::initImageView() { - mImageLayout->on( Event::MouseClick, [&]( const Event* ) { + mImageLayout->on( Event::MouseClick, [this]( const Event* ) { mImageLayout->findByType( UI_TYPE_IMAGE )->setDrawable( nullptr ); mImageLayout->setEnabled( false )->setVisible( false ); } ); @@ -2917,11 +2935,11 @@ void App::loadFolder( const std::string& path ) { loadFileSystemMatcher( rpath ); - mFileSystemModel = - FileSystemModel::New( rpath, FileSystemModel::Mode::FilesAndDirectories, - { true, true, true, {}, [&]( const std::string& filePath ) -> bool { - return isFileVisibleInTreeView( filePath ); - } } ); + mFileSystemModel = FileSystemModel::New( + rpath, FileSystemModel::Mode::FilesAndDirectories, + { true, true, true, {}, [this]( const std::string& filePath ) -> bool { + return isFileVisibleInTreeView( filePath ); + } } ); if ( mProjectTreeView ) mProjectTreeView->setModel( mFileSystemModel ); @@ -3075,9 +3093,9 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe mWindow->maximize(); mWindow->setCloseRequestCallback( - [&]( EE::Window::Window* win ) -> bool { return onCloseRequestCallback( win ); } ); + [this]( EE::Window::Window* win ) -> bool { return onCloseRequestCallback( win ); } ); - mWindow->getInput()->pushCallback( [&]( InputEvent* event ) { + mWindow->getInput()->pushCallback( [this]( InputEvent* event ) { if ( event->Type == InputEvent::FileDropped ) { onFileDropped( event->file.file ); } else if ( event->Type == InputEvent::TextDropped ) { @@ -3620,8 +3638,8 @@ Anchor.error:hover { )html"; - UIIconTheme* iconTheme = UIIconTheme::New( "ecode" ); mMenuIconSize = mConfig.ui.fontSize.asPixels( 0, Sizef(), mDisplayDPI ); + UIIconTheme* iconTheme = UIIconTheme::New( "ecode" ); std::unordered_map icons = { { "document-new", 0xecc3 }, { "document-open", 0xed70 }, { "document-save", 0xf0b3 }, @@ -3850,7 +3868,7 @@ Anchor.error:hover { mUISceneNode->bind( "doc_info", mDocInfo ); mUISceneNode->bind( "panel", mSidePanel ); mUISceneNode->bind( "project_splitter", mProjectSplitter ); - mUISceneNode->addEventListener( Event::KeyDown, [&]( const Event* event ) { + mUISceneNode->addEventListener( Event::KeyDown, [this]( const Event* event ) { trySendUnlockedCmd( *static_cast( event ) ); } ); if ( logLevel == LogLevel::Debug ) @@ -3886,7 +3904,8 @@ Anchor.error:hover { mTerminalManager->loadTerminalColorSchemes(); - mSplitter = UICodeEditorSplitter::New( this, mUISceneNode, colorSchemes, mInitColorScheme ); + mSplitter = UICodeEditorSplitter::New( this, mUISceneNode, mThreadPool, colorSchemes, + mInitColorScheme ); mSplitter->setHideTabBarOnSingleTab( mConfig.editor.hideTabBarOnSingleTab ); mPluginManager->setSplitter( mSplitter ); @@ -3938,7 +3957,7 @@ Anchor.error:hover { mSplitter->createEditorWithTabWidget( mBaseLayout ); mConsole = UIConsole::NewOpt( mFontMono, true, true, 1024 * 10 ); - mConsole->setCommand( "hide", [&]( const auto& ) { consoleToggle(); } ); + mConsole->setCommand( "hide", [this]( const auto& ) { consoleToggle(); } ); mConsole->setQuakeMode( true ); mConsole->setVisible( false ); diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index bf0239f60..113c14156 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -184,60 +184,61 @@ class App : public UICodeEditorSplitter::Client { UIStatusBar* getStatusBar() const { return mStatusBar; } template void registerUnlockedCommands( T& t ) { - t.setCommand( "keybindings", [&] { loadFileFromPath( mKeybindingsPath ); } ); - t.setCommand( "debug-draw-boxes-toggle", [&] { debugDrawBoxesToggle(); } ); - t.setCommand( "debug-draw-highlight-toggle", [&] { debugDrawHighlightToggle(); } ); - t.setCommand( "debug-draw-debug-data", [&] { debugDrawData(); } ); - t.setCommand( "debug-widget-tree-view", [&] { createWidgetInspector(); } ); - t.setCommand( "menu-toggle", [&] { toggleSettingsMenu(); } ); - t.setCommand( "switch-side-panel", [&] { switchSidePanel(); } ); - t.setCommand( "download-file-web", [&] { downloadFileWebDialog(); } ); - t.setCommand( "move-panel-left", [&] { panelPosition( PanelPosition::Left ); } ); - t.setCommand( "move-panel-right", [&] { panelPosition( PanelPosition::Right ); } ); - t.setCommand( "create-new-terminal", [&] { createNewTerminal(); } ); - t.setCommand( "terminal-split-right", [&] { + t.setCommand( "keybindings", [this] { loadFileFromPath( mKeybindingsPath ); } ); + t.setCommand( "debug-draw-boxes-toggle", [this] { debugDrawBoxesToggle(); } ); + t.setCommand( "debug-draw-highlight-toggle", [this] { debugDrawHighlightToggle(); } ); + t.setCommand( "debug-draw-debug-data", [this] { debugDrawData(); } ); + t.setCommand( "debug-widget-tree-view", [this] { createWidgetInspector(); } ); + t.setCommand( "menu-toggle", [this] { toggleSettingsMenu(); } ); + t.setCommand( "switch-side-panel", [this] { switchSidePanel(); } ); + t.setCommand( "download-file-web", [this] { downloadFileWebDialog(); } ); + t.setCommand( "move-panel-left", [this] { panelPosition( PanelPosition::Left ); } ); + t.setCommand( "move-panel-right", [this] { panelPosition( PanelPosition::Right ); } ); + t.setCommand( "create-new-terminal", [this] { createNewTerminal(); } ); + t.setCommand( "terminal-split-right", [this] { auto cwd = getCurrentWorkingDir(); mSplitter->split( UICodeEditorSplitter::SplitDirection::Right, mSplitter->getCurWidget(), false ); mTerminalManager->createNewTerminal( "", nullptr, cwd ); } ); - t.setCommand( "terminal-split-bottom", [&] { + t.setCommand( "terminal-split-bottom", [this] { auto cwd = getCurrentWorkingDir(); mSplitter->split( UICodeEditorSplitter::SplitDirection::Bottom, mSplitter->getCurWidget(), false ); mTerminalManager->createNewTerminal( "", nullptr, cwd ); } ); - t.setCommand( "terminal-split-left", [&] { + t.setCommand( "terminal-split-left", [this] { auto cwd = getCurrentWorkingDir(); mSplitter->split( UICodeEditorSplitter::SplitDirection::Left, mSplitter->getCurWidget(), false ); mTerminalManager->createNewTerminal( "", nullptr, cwd ); } ); - t.setCommand( "terminal-split-top", [&] { + t.setCommand( "terminal-split-top", [this] { auto cwd = getCurrentWorkingDir(); mSplitter->split( UICodeEditorSplitter::SplitDirection::Top, mSplitter->getCurWidget(), false ); mTerminalManager->createNewTerminal( "", nullptr, cwd ); } ); - t.setCommand( "reopen-closed-tab", [&] { reopenClosedTab(); } ); - t.setCommand( "plugin-manager-open", [&] { createPluginManagerUI(); } ); - t.setCommand( "close-app", [&] { closeApp(); } ); - t.setCommand( "fullscreen-toggle", [&]() { fullscreenToggle(); } ); - t.setCommand( "open-file", [&] { openFileDialog(); } ); - t.setCommand( "open-folder", [&] { openFolderDialog(); } ); - t.setCommand( "console-toggle", [&] { consoleToggle(); } ); - t.setCommand( "find-replace", [&] { showFindView(); } ); - t.setCommand( "open-global-search", [&] { showGlobalSearch( false ); } ); + t.setCommand( "reopen-closed-tab", [this] { reopenClosedTab(); } ); + t.setCommand( "plugin-manager-open", [this] { createPluginManagerUI(); } ); + t.setCommand( "close-app", [this] { closeApp(); } ); + t.setCommand( "fullscreen-toggle", [this]() { fullscreenToggle(); } ); + t.setCommand( "open-file", [this] { openFileDialog(); } ); + t.setCommand( "open-folder", [this] { openFolderDialog(); } ); + t.setCommand( "console-toggle", [this] { consoleToggle(); } ); + t.setCommand( "find-replace", [this] { showFindView(); } ); + t.setCommand( "open-global-search", [this] { showGlobalSearch( false ); } ); t.setCommand( "toggle-status-global-search-bar", - [&] { mGlobalSearchController->toggleGlobalSearchBar(); } ); + [this] { mGlobalSearchController->toggleGlobalSearchBar(); } ); t.setCommand( "toggle-status-build-output", - [&] { mStatusBuildOutputController->toggle(); } ); - t.setCommand( "toggle-status-terminal", [&] { mStatusTerminalController->toggle(); } ); - t.setCommand( "open-locatebar", [&] { mUniversalLocator->showLocateBar(); } ); - t.setCommand( "toggle-status-locate-bar", [&] { mUniversalLocator->toggleLocateBar(); } ); - t.setCommand( "open-command-palette", [&] { mUniversalLocator->showCommandPalette(); } ); - t.setCommand( "show-open-documents", [&] { mUniversalLocator->showOpenDocuments(); } ); - t.setCommand( "project-build-start", [&] { + [this] { mStatusBuildOutputController->toggle(); } ); + t.setCommand( "toggle-status-terminal", [this] { mStatusTerminalController->toggle(); } ); + t.setCommand( "open-locatebar", [this] { mUniversalLocator->showLocateBar(); } ); + t.setCommand( "toggle-status-locate-bar", + [this] { mUniversalLocator->toggleLocateBar(); } ); + t.setCommand( "open-command-palette", [this] { mUniversalLocator->showCommandPalette(); } ); + t.setCommand( "show-open-documents", [this] { mUniversalLocator->showOpenDocuments(); } ); + t.setCommand( "project-build-start", [this] { if ( mProjectBuildManager && mStatusBuildOutputController ) { if ( mProjectBuildManager->isBuilding() ) { mProjectBuildManager->cancelBuild(); @@ -245,39 +246,43 @@ class App : public UICodeEditorSplitter::Client { mProjectBuildManager->buildCurrentConfig( mStatusBuildOutputController.get() ); } } ); - t.setCommand( "project-build-cancel", [&] { + t.setCommand( "project-build-cancel", [this] { if ( mProjectBuildManager && mProjectBuildManager->isBuilding() ) { mProjectBuildManager->cancelBuild(); } } ); t.setCommand( "open-workspace-symbol-search", - [&] { mUniversalLocator->showWorkspaceSymbol(); } ); + [this] { mUniversalLocator->showWorkspaceSymbol(); } ); t.setCommand( "open-document-symbol-search", - [&] { mUniversalLocator->showDocumentSymbol(); } ); - t.setCommand( "editor-set-line-breaking-column", [&] { setLineBreakingColumn(); } ); - t.setCommand( "editor-set-line-spacing", [&] { setLineSpacing(); } ); - t.setCommand( "editor-set-cursor-blinking-time", [&] { setCursorBlinkingTime(); } ); - t.setCommand( "check-for-updates", [&] { checkForUpdates(); } ); - t.setCommand( "about-ecode", [&] { aboutEcode(); } ); - t.setCommand( "ecode-source", [&] { ecodeSource(); } ); - t.setCommand( "ui-scale-factor", [&] { setUIScaleFactor(); } ); - t.setCommand( "show-side-panel", [&] { switchSidePanel(); } ); - t.setCommand( "toggle-status-bar", [&] { switchStatusBar(); } ); - t.setCommand( "editor-font-size", [&] { setEditorFontSize(); } ); - t.setCommand( "terminal-font-size", [&] { setTerminalFontSize(); } ); - t.setCommand( "ui-font-size", [&] { setUIFontSize(); } ); - t.setCommand( "ui-panel-font-size", [&] { setUIPanelFontSize(); } ); - t.setCommand( "serif-font", [&] { openFontDialog( mConfig.ui.serifFont, false ); } ); - t.setCommand( "monospace-font", [&] { openFontDialog( mConfig.ui.monospaceFont, true ); } ); - t.setCommand( "terminal-font", [&] { openFontDialog( mConfig.ui.terminalFont, false ); } ); - t.setCommand( "fallback-font", [&] { openFontDialog( mConfig.ui.fallbackFont, false ); } ); - t.setCommand( "tree-view-configure-ignore-files", [&] { treeViewConfigureIgnoreFiles(); } ); - t.setCommand( "check-languages-health", [&] { checkLanguagesHealth(); } ); - t.setCommand( "configure-terminal-shell", [&] { + [this] { mUniversalLocator->showDocumentSymbol(); } ); + t.setCommand( "editor-set-line-breaking-column", [this] { setLineBreakingColumn(); } ); + t.setCommand( "editor-set-line-spacing", [this] { setLineSpacing(); } ); + t.setCommand( "editor-set-cursor-blinking-time", [this] { setCursorBlinkingTime(); } ); + t.setCommand( "check-for-updates", [this] { checkForUpdates(); } ); + t.setCommand( "about-ecode", [this] { aboutEcode(); } ); + t.setCommand( "ecode-source", [this] { ecodeSource(); } ); + t.setCommand( "ui-scale-factor", [this] { setUIScaleFactor(); } ); + t.setCommand( "show-side-panel", [this] { switchSidePanel(); } ); + t.setCommand( "toggle-status-bar", [this] { switchStatusBar(); } ); + t.setCommand( "editor-font-size", [this] { setEditorFontSize(); } ); + t.setCommand( "terminal-font-size", [this] { setTerminalFontSize(); } ); + t.setCommand( "ui-font-size", [this] { setUIFontSize(); } ); + t.setCommand( "ui-panel-font-size", [this] { setUIPanelFontSize(); } ); + t.setCommand( "serif-font", [this] { openFontDialog( mConfig.ui.serifFont, false ); } ); + t.setCommand( "monospace-font", + [this] { openFontDialog( mConfig.ui.monospaceFont, true ); } ); + t.setCommand( "terminal-font", + [this] { openFontDialog( mConfig.ui.terminalFont, false ); } ); + t.setCommand( "fallback-font", + [this] { openFontDialog( mConfig.ui.fallbackFont, false ); } ); + t.setCommand( "tree-view-configure-ignore-files", + [this] { treeViewConfigureIgnoreFiles(); } ); + t.setCommand( "check-languages-health", [this] { checkLanguagesHealth(); } ); + t.setCommand( "configure-terminal-shell", [this] { if ( mTerminalManager ) mTerminalManager->configureTerminalShell(); } ); - t.setCommand( "check-for-updates", [&] { checkForUpdates( false ); } ); + t.setCommand( "check-for-updates", [this] { checkForUpdates( false ); } ); mSplitter->registerSplitterCommands( t ); } @@ -404,6 +409,8 @@ class App : public UICodeEditorSplitter::Client { const std::map& getRealTerminalKeybindings() const; + const std::string& getFileToOpen() const; + protected: std::vector mArgs; EE::Window::Window* mWindow{ nullptr }; diff --git a/src/tools/ecode/globalsearchcontroller.cpp b/src/tools/ecode/globalsearchcontroller.cpp index ff47f71eb..134510bd3 100644 --- a/src/tools/ecode/globalsearchcontroller.cpp +++ b/src/tools/ecode/globalsearchcontroller.cpp @@ -9,8 +9,9 @@ GlobalSearchController::GlobalSearchController( UICodeEditorSplitter* editorSpli UISceneNode* sceneNode, App* app ) : mSplitter( editorSplitter ), mUISceneNode( sceneNode ), mApp( app ) { mApp->getPluginManager()->subscribeMessages( - "GlobalSearchController", - [&]( const PluginMessage& msg ) -> PluginRequestHandle { return processMessage( msg ); } ); + "GlobalSearchController", [this]( const PluginMessage& msg ) -> PluginRequestHandle { + return processMessage( msg ); + } ); } static bool replaceInFile( const std::string& path, const std::string& replaceText, @@ -65,7 +66,7 @@ void GlobalSearchController::initGlobalSearchBar( std::unordered_map keybindings ) { mGlobalSearchBarLayout = globalSearchBar; mGlobalSearchBarLayout->setVisible( false )->setEnabled( false ); - auto addClickListener = [&]( UIWidget* widget, std::string cmd ) { + auto addClickListener = [this]( UIWidget* widget, std::string cmd ) { widget->addEventListener( Event::MouseClick, [this, cmd]( const Event* event ) { const MouseEvent* mouseEvent = static_cast( event ); if ( mouseEvent->getFlags() & EE_BUTTON_LMASK ) @@ -114,7 +115,7 @@ void GlobalSearchController::initGlobalSearchBar( mGlobalSearchHistoryList = mGlobalSearchBarLayout->find( "global_search_history" ); - mGlobalSearchBarLayout->setCommand( "global-search-clear-history", [&] { clearHistory(); } ); + mGlobalSearchBarLayout->setCommand( "global-search-clear-history", [this] { clearHistory(); } ); mGlobalSearchBarLayout->setCommand( "search-in-files", [&, caseSensitiveChk, wholeWordChk, luaPatternChk, escapeSequenceChk] { doGlobalSearch( mGlobalSearchInput->getText(), caseSensitiveChk->isChecked(), @@ -133,23 +134,23 @@ void GlobalSearchController::initGlobalSearchBar( mGlobalSearchTreeReplace == mGlobalSearchTree, true ); } } ); - mGlobalSearchBarLayout->setCommand( "search-set-string", [&] { + mGlobalSearchBarLayout->setCommand( "search-set-string", [this] { auto listBox = mGlobalSearchHistoryList->getListBox(); mGlobalSearchInput->setText( mGlobalSearchHistory[mGlobalSearchHistory.size() - 1 - listBox->getItemSelectedIndex()] .first ); ; } ); - mGlobalSearchBarLayout->setCommand( "close-global-searchbar", [&] { + mGlobalSearchBarLayout->setCommand( "close-global-searchbar", [this] { hideGlobalSearchBar(); if ( mSplitter->getCurWidget() ) mSplitter->getCurWidget()->setFocus(); } ); - mGlobalSearchBarLayout->setCommand( "expand-all", [&] { + mGlobalSearchBarLayout->setCommand( "expand-all", [this] { mGlobalSearchTree->expandAll(); mGlobalSearchTree->setFocus(); } ); - mGlobalSearchBarLayout->setCommand( "collapse-all", [&] { + mGlobalSearchBarLayout->setCommand( "collapse-all", [this] { mGlobalSearchTree->collapseAll(); mGlobalSearchTree->setFocus(); } ); @@ -165,8 +166,8 @@ void GlobalSearchController::initGlobalSearchBar( mGlobalSearchBarLayout->setCommand( "change-escape-sequence", [&, escapeSequenceChk] { escapeSequenceChk->setChecked( !escapeSequenceChk->isChecked() ); } ); - mGlobalSearchBarLayout->setCommand( "find-replace", [&] { mApp->showFindView(); } ); - mGlobalSearchInput->addEventListener( Event::OnPressEnter, [&]( const Event* ) { + mGlobalSearchBarLayout->setCommand( "find-replace", [this] { mApp->showFindView(); } ); + mGlobalSearchInput->addEventListener( Event::OnPressEnter, [this]( const Event* ) { if ( mGlobalSearchInput->hasFocus() ) { mGlobalSearchBarLayout->execute( "search-in-files" ); } else { @@ -175,7 +176,7 @@ void GlobalSearchController::initGlobalSearchBar( mGlobalSearchTree->forceKeyDown( keyEvent ); } } ); - auto switchInputToTree = [&]( const Event* event ) { + auto switchInputToTree = [this]( const Event* event ) { const KeyEvent* keyEvent = static_cast( event ); Uint32 keyCode = keyEvent->getKeyCode(); if ( ( keyCode == KEY_UP || keyCode == KEY_DOWN || keyCode == KEY_PAGEUP || @@ -185,7 +186,7 @@ void GlobalSearchController::initGlobalSearchBar( } }; mGlobalSearchInput->addEventListener( Event::KeyDown, switchInputToTree ); - mGlobalSearchInput->addEventListener( Event::OnSizeChange, [&]( const Event* ) { + mGlobalSearchInput->addEventListener( Event::OnSizeChange, [this]( const Event* ) { if ( mGlobalSearchBarLayout->isVisible() ) updateGlobalSearchBar(); } ); @@ -243,7 +244,7 @@ void GlobalSearchController::initGlobalSearchBar( mGlobalSearchBarLayout->execute( "replace-in-files" ); } ); replaceInput->addEventListener( Event::KeyDown, switchInputToTree ); - mGlobalSearchLayout->addEventListener( Event::KeyDown, [&]( const Event* event ) { + mGlobalSearchLayout->addEventListener( Event::KeyDown, [this]( const Event* event ) { const KeyEvent* keyEvent = static_cast( event ); if ( keyEvent->getKeyCode() == KEY_ESCAPE ) { mGlobalSearchBarLayout->execute( "close-global-searchbar" ); @@ -294,7 +295,7 @@ void GlobalSearchController::initGlobalSearchBar( UITreeViewGlobalSearch::New( mSplitter->getCurrentColorScheme(), true ); initGlobalSearchTree( mGlobalSearchTreeSearch ); initGlobalSearchTree( mGlobalSearchTreeReplace ); - mGlobalSearchTreeReplace->addEventListener( Event::KeyDown, [&]( const Event* event ) { + mGlobalSearchTreeReplace->addEventListener( Event::KeyDown, [this]( const Event* event ) { const KeyEvent* keyEvent = static_cast( event ); if ( keyEvent->getSanitizedMod() == KeyMod::getDefaultModifier() && keyEvent->getKeyCode() == KEY_RETURN ) @@ -380,7 +381,7 @@ GlobalSearchBarConfig GlobalSearchController::getGlobalSearchBarConfig() const { } void GlobalSearchController::updateGlobalSearchBar() { - mGlobalSearchBarLayout->runOnMainThread( [&] { + mGlobalSearchBarLayout->runOnMainThread( [this] { Float width = eeceil( mGlobalSearchInput->getPixelsSize().getWidth() ); Float rowHeight = mGlobalSearchTree->getRowHeight() * LOCATEBAR_MAX_VISIBLE_ITEMS; mGlobalSearchLayout->setPixelsSize( width, 0 ); @@ -524,6 +525,7 @@ void GlobalSearchController::onLoadDone( const Variant& lineNum, const Variant& TextPosition pos{ lineNum.asInt64(), colNum.asInt64() }; mSplitter->getCurEditor()->getDocument().setSelection( pos ); mSplitter->getCurEditor()->goToLine( pos ); + mSplitter->addCurrentPositionToNavigationHistory(); hideGlobalSearchBar(); } } @@ -537,7 +539,7 @@ void GlobalSearchController::initGlobalSearchTree( UITreeViewGlobalSearch* searc searchTree->setHeadersVisible( false ); searchTree->setColumnsHidden( { ProjectSearch::ResultModel::Line, ProjectSearch::ResultModel::ColumnStart }, true ); - searchTree->addEventListener( Event::OnModelEvent, [&]( const Event* event ) { + searchTree->addEventListener( Event::OnModelEvent, [this]( const Event* event ) { const ModelEvent* modelEvent = static_cast( event ); if ( modelEvent->getModelEventType() == ModelEventType::Open ) { const Model* model = modelEvent->getModel(); diff --git a/src/tools/ecode/notificationcenter.cpp b/src/tools/ecode/notificationcenter.cpp index 3a2798007..65fea80db 100644 --- a/src/tools/ecode/notificationcenter.cpp +++ b/src/tools/ecode/notificationcenter.cpp @@ -5,7 +5,7 @@ namespace ecode { NotificationCenter::NotificationCenter( UILayout* layout, PluginManager* pluginManager ) : mLayout( layout ), mPluginManager( pluginManager ) { mPluginManager->subscribeMessages( - "notificationcenter", [&]( const PluginMessage& msg ) -> PluginRequestHandle { + "notificationcenter", [this]( const PluginMessage& msg ) -> PluginRequestHandle { if ( !msg.isBroadcast() ) return {}; if ( msg.type == PluginMessageType::ShowMessage ) { diff --git a/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp b/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp index 8196e5950..d4181d8b2 100644 --- a/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp +++ b/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp @@ -77,7 +77,7 @@ AutoCompletePlugin::AutoCompletePlugin( PluginManager* pluginManager ) : mSymbolPattern( "[%a_ñàáâãäåèéêëìíîïòóôõöùúûüýÿÑÀÁÂÃÄÅÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝ][%w_" "ñàáâãäåèéêëìíîïòóôõöùúûüýÿÑÀÁÂÃÄÅÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝ]*" ), mBoxPadding( PixelDensity::dpToPx( Rectf( 4, 4, 12, 4 ) ) ) { - mManager->subscribeMessages( this, [&]( const PluginMessage& msg ) -> PluginRequestHandle { + mManager->subscribeMessages( this, [this]( const PluginMessage& msg ) -> PluginRequestHandle { return processResponse( msg ); } ); } @@ -106,7 +106,7 @@ void AutoCompletePlugin::onRegister( UICodeEditor* editor ) { } ) ); listeners.push_back( - editor->addEventListener( Event::OnDocumentClosed, [&]( const Event* event ) { + editor->addEventListener( Event::OnDocumentClosed, [this]( const Event* event ) { Lock l( mDocMutex ); const DocEvent* docEvent = static_cast( event ); TextDocument* doc = docEvent->getDoc(); @@ -116,7 +116,7 @@ void AutoCompletePlugin::onRegister( UICodeEditor* editor ) { } ) ); listeners.push_back( - editor->addEventListener( Event::OnDocumentChanged, [&, editor]( const Event* ) { + editor->addEventListener( Event::OnDocumentChanged, [this, editor]( const Event* ) { TextDocument* oldDoc = mEditorDocs[editor]; TextDocument* newDoc = editor->getDocumentRef().get(); Lock l( mDocMutex ); @@ -127,19 +127,19 @@ void AutoCompletePlugin::onRegister( UICodeEditor* editor ) { } ) ); listeners.push_back( - editor->addEventListener( Event::OnCursorPosChange, [&, editor]( const Event* ) { + editor->addEventListener( Event::OnCursorPosChange, [this, editor]( const Event* ) { if ( !mReplacing ) resetSuggestions( editor ); } ) ); listeners.push_back( editor->addEventListener( - Event::OnFocusLoss, [&]( const Event* ) { resetSignatureHelp(); } ) ); + Event::OnFocusLoss, [this]( const Event* ) { resetSignatureHelp(); } ) ); listeners.push_back( editor->addEventListener( - Event::OnDocumentUndoRedo, [&]( const Event* ) { resetSignatureHelp(); } ) ); + Event::OnDocumentUndoRedo, [this]( const Event* ) { resetSignatureHelp(); } ) ); - listeners.push_back( - editor->addEventListener( Event::OnDocumentSyntaxDefinitionChange, [&]( const Event* ev ) { + listeners.push_back( editor->addEventListener( + Event::OnDocumentSyntaxDefinitionChange, [this]( const Event* ev ) { const DocSyntaxDefEvent* event = static_cast( ev ); std::string oldLang = event->getOldLang(); std::string newLang = event->getNewLang(); diff --git a/src/tools/ecode/plugins/formatter/formatterplugin.cpp b/src/tools/ecode/plugins/formatter/formatterplugin.cpp index a6a821f46..ea2bf74c3 100644 --- a/src/tools/ecode/plugins/formatter/formatterplugin.cpp +++ b/src/tools/ecode/plugins/formatter/formatterplugin.cpp @@ -1,11 +1,11 @@ #include "formatterplugin.hpp" -#include "../../scopedop.hpp" #include "eepp/system/md5.hpp" #include #include #include #include #include +#include #include #include #include @@ -43,7 +43,7 @@ FormatterPlugin::FormatterPlugin( PluginManager* pluginManager, bool sync ) : load( pluginManager ); #endif } - mManager->subscribeMessages( this, [&]( const PluginMessage& msg ) -> PluginRequestHandle { + mManager->subscribeMessages( this, [this]( const PluginMessage& msg ) -> PluginRequestHandle { return processMessage( msg ); } ); } @@ -54,7 +54,7 @@ FormatterPlugin::~FormatterPlugin() { if ( mWorkersCount != 0 ) { std::unique_lock lock( mWorkMutex ); - mWorkerCondition.wait( lock, [&]() { return mWorkersCount <= 0; } ); + mWorkerCondition.wait( lock, [this]() { return mWorkersCount <= 0; } ); } for ( auto editor : mEditors ) { @@ -84,7 +84,7 @@ void FormatterPlugin::onRegister( UICodeEditor* editor ) { tryRequestCapabilities( editor->getDocumentRef() ); } ) ); - listeners.push_back( editor->addEventListener( Event::OnDocumentSave, [&]( + listeners.push_back( editor->addEventListener( Event::OnDocumentSave, [this]( const Event* event ) { if ( mAutoFormatOnSave && event->getNode()->isType( UI_TYPE_CODEEDITOR ) ) { UICodeEditor* editor = event->getNode()->asType(); @@ -245,9 +245,10 @@ void FormatterPlugin::loadFormatterConfig( const std::string& path, bool updateC } void FormatterPlugin::load( PluginManager* pluginManager ) { - pluginManager->subscribeMessages( this, [&]( const auto& notification ) -> PluginRequestHandle { - return processMessage( notification ); - } ); + pluginManager->subscribeMessages( this, + [this]( const auto& notification ) -> PluginRequestHandle { + return processMessage( notification ); + } ); registerNativeFormatters(); std::vector paths; @@ -321,11 +322,11 @@ FormatterPlugin::getFormatterForLang( const std::string& lang, void FormatterPlugin::formatDoc( UICodeEditor* editor ) { ScopedOp op( - [&]() { + [this]() { mWorkMutex.lock(); mWorkersCount++; }, - [&]() { + [this]() { mWorkersCount--; mWorkMutex.unlock(); mWorkerCondition.notify_all(); @@ -376,7 +377,7 @@ void FormatterPlugin::formatDoc( UICodeEditor* editor ) { doc->resetCursor(); doc->selectAll(); doc->setRunningTransaction( true ); - doc->textInput( data ); + doc->textInput( data, false ); doc->setSelection( pos ); editor->setScroll( scroll ); if ( mAutoFormatOnSave ) { @@ -413,7 +414,7 @@ void FormatterPlugin::runFormatter( UICodeEditor* editor, const Formatter& forma doc->resetCursor(); doc->selectAll(); doc->setRunningTransaction( true ); - doc->textInput( res.result ); + doc->textInput( res.result, false ); doc->setSelection( pos ); editor->setScroll( scroll ); doc->setRunningTransaction( false ); @@ -462,7 +463,7 @@ void FormatterPlugin::runFormatter( UICodeEditor* editor, const Formatter& forma doc->resetCursor(); doc->selectAll(); doc->setRunningTransaction( true ); - doc->textInput( data ); + doc->textInput( data, false ); doc->setSelection( pos ); editor->setScroll( scroll ); doc->setRunningTransaction( false ); diff --git a/src/tools/ecode/plugins/linter/linterplugin.cpp b/src/tools/ecode/plugins/linter/linterplugin.cpp index b2a596584..f5391b341 100644 --- a/src/tools/ecode/plugins/linter/linterplugin.cpp +++ b/src/tools/ecode/plugins/linter/linterplugin.cpp @@ -1,5 +1,4 @@ #include "linterplugin.hpp" -#include "../../scopedop.hpp" #include #include #include @@ -8,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -50,7 +50,7 @@ LinterPlugin::~LinterPlugin() { if ( mWorkersCount != 0 ) { std::unique_lock lock( mWorkMutex ); - mWorkerCondition.wait( lock, [&]() { return mWorkersCount <= 0; } ); + mWorkerCondition.wait( lock, [this]() { return mWorkersCount <= 0; } ); } for ( const auto& editor : mEditors ) { @@ -411,9 +411,10 @@ TextDocument* LinterPlugin::getDocumentFromURI( const URI& uri ) { } void LinterPlugin::load( PluginManager* pluginManager ) { - pluginManager->subscribeMessages( this, [&]( const auto& notification ) -> PluginRequestHandle { - return processMessage( notification ); - } ); + pluginManager->subscribeMessages( this, + [this]( const auto& notification ) -> PluginRequestHandle { + return processMessage( notification ); + } ); std::vector paths; std::string path( pluginManager->getResourcesPath() + "plugins/linters.json" ); if ( FileSystem::fileExists( path ) ) @@ -446,14 +447,14 @@ void LinterPlugin::onRegister( UICodeEditor* editor ) { std::vector listeners; listeners.push_back( - editor->addEventListener( Event::OnDocumentLoaded, [&]( const Event* event ) { + editor->addEventListener( Event::OnDocumentLoaded, [this]( const Event* event ) { Lock l( mDocMutex ); const DocEvent* docEvent = static_cast( event ); setDocDirty( docEvent->getDoc() ); } ) ); listeners.push_back( - editor->addEventListener( Event::OnDocumentClosed, [&]( const Event* event ) { + editor->addEventListener( Event::OnDocumentClosed, [this]( const Event* event ) { Lock l( mDocMutex ); const DocEvent* docEvent = static_cast( event ); TextDocument* doc = docEvent->getDoc(); @@ -592,11 +593,11 @@ void LinterPlugin::lintDoc( std::shared_ptr doc ) { return; ScopedOp op( - [&]() { + [this]() { mWorkMutex.lock(); mWorkersCount++; }, - [&]() { + [this]() { mWorkersCount--; mWorkMutex.unlock(); mWorkerCondition.notify_all(); @@ -966,6 +967,7 @@ void LinterPlugin::goToNextError( UICodeEditor* editor ) { if ( matched != nullptr ) { editor->goToLine( matched->range.start() ); + mManager->getSplitter()->addCurrentPositionToNavigationHistory(); } else { if ( mGoToIgnoreWarnings ) { for ( const auto& m : matches ) { @@ -973,6 +975,7 @@ void LinterPlugin::goToNextError( UICodeEditor* editor ) { for ( const auto& lm : m.second ) { if ( lm.type == LinterType::Error ) { editor->goToLine( lm.range.start() ); + mManager->getSplitter()->addCurrentPositionToNavigationHistory(); break; } } @@ -982,6 +985,7 @@ void LinterPlugin::goToNextError( UICodeEditor* editor ) { } } else if ( matches.begin()->second.front().range.start().line() != pos.line() ) { editor->goToLine( matches.begin()->second.front().range.start() ); + mManager->getSplitter()->addCurrentPositionToNavigationHistory(); } } } @@ -1019,6 +1023,7 @@ void LinterPlugin::goToPrevError( UICodeEditor* editor ) { if ( matched != nullptr ) { editor->goToLine( matched->range.start() ); + mManager->getSplitter()->addCurrentPositionToNavigationHistory(); } else { if ( mGoToIgnoreWarnings ) { for ( auto m = matches.rbegin(); m != matches.rend(); ++m ) { @@ -1026,6 +1031,7 @@ void LinterPlugin::goToPrevError( UICodeEditor* editor ) { for ( const auto& lm : m->second ) { if ( lm.type == LinterType::Error ) { editor->goToLine( lm.range.start() ); + mManager->getSplitter()->addCurrentPositionToNavigationHistory(); break; } } @@ -1035,6 +1041,7 @@ void LinterPlugin::goToPrevError( UICodeEditor* editor ) { } } else if ( matches.rbegin()->second.front().range.start().line() != pos.line() ) { editor->goToLine( matches.rbegin()->second.front().range.start() ); + mManager->getSplitter()->addCurrentPositionToNavigationHistory(); } } } diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp index 98660607b..f4a34d147 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp @@ -204,7 +204,7 @@ PluginRequestHandle LSPClientPlugin::processCodeCompletionRequest( const PluginM auto ret = res.server->documentCompletion( res.loc.uri, res.loc.pos, - [&]( const PluginIDType& id, const LSPCompletionList& completionList ) { + [this]( const PluginIDType& id, const LSPCompletionList& completionList ) { mManager->sendResponse( this, PluginMessageType::CodeCompletion, PluginMessageFormat::CodeCompletion, &completionList, id ); } ); @@ -221,7 +221,7 @@ PluginRequestHandle LSPClientPlugin::processSignatureHelpRequest( const PluginMe return {}; auto ret = res.server->signatureHelp( - res.loc.uri, res.loc.pos, [&]( const PluginIDType& id, const LSPSignatureHelp& data ) { + res.loc.uri, res.loc.pos, [this]( const PluginIDType& id, const LSPSignatureHelp& data ) { mManager->sendResponse( this, PluginMessageType::SignatureHelp, PluginMessageFormat::SignatureHelp, &data, id ); } ); @@ -507,7 +507,7 @@ void LSPClientPlugin::createListView( UICodeEditor* editor, const std::shared_pt void LSPClientPlugin::createLocationsView( UICodeEditor* editor, const std::vector& res ) { auto model = LSPLocationModel::create( mManager->getWorkspaceFolder(), res ); - createListView( editor, model, [&]( const ModelEvent* modelEvent ) { + createListView( editor, model, [this]( const ModelEvent* modelEvent ) { if ( modelEvent->getModelEventType() != ModelEventType::Open ) return; auto r = modelEvent->getModelIndex().row(); @@ -658,9 +658,10 @@ PluginRequestHandle LSPClientPlugin::processMessage( const PluginMessage& msg ) } void LSPClientPlugin::load( PluginManager* pluginManager ) { - pluginManager->subscribeMessages( this, [&]( const auto& notification ) -> PluginRequestHandle { - return processMessage( notification ); - } ); + pluginManager->subscribeMessages( this, + [this]( const auto& notification ) -> PluginRequestHandle { + return processMessage( notification ); + } ); std::vector paths; std::string path( pluginManager->getResourcesPath() + "plugins/lspclient.json" ); if ( FileSystem::fileExists( path ) ) @@ -798,6 +799,7 @@ void LSPClientPlugin::loadLSPConfig( std::vector& lsps, const std if ( mKeyBindings.empty() ) { mKeyBindings["lsp-go-to-definition"] = "f2"; + mKeyBindings["lsp-go-to-implementation"] = "shift+f2"; mKeyBindings["lsp-symbol-info"] = "f1"; mKeyBindings["lsp-symbol-code-action"] = "alt+return"; mKeyBindings["lsp-rename-symbol-under-cursor"] = "mod+shift+r"; @@ -1032,7 +1034,7 @@ void LSPClientPlugin::renameSymbol( UICodeEditor* editor ) { mClientManager.renameSymbol( editor->getDocumentRef()->getURI(), pos, newName ); msgBox->closeWindow(); } ); - msgBox->addEventListener( Event::OnClose, [&]( const Event* ) { + msgBox->addEventListener( Event::OnClose, [this]( const Event* ) { if ( mManager->getSplitter() && mManager->getSplitter()->getCurWidget() ) mManager->getSplitter()->getCurWidget()->setFocus(); } ); diff --git a/src/tools/ecode/plugins/lsp/lspclientserver.cpp b/src/tools/ecode/plugins/lsp/lspclientserver.cpp index f06f216f0..e94a50e2c 100644 --- a/src/tools/ecode/plugins/lsp/lspclientserver.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientserver.cpp @@ -1087,7 +1087,7 @@ void LSPClientServer::initialize() { write( newRequest( "initialize", params ), - [&]( const IdType&, const json& resp ) { + [this]( const IdType&, const json& resp ) { #ifndef EE_DEBUG try { #endif @@ -1110,7 +1110,7 @@ void LSPClientServer::initialize() { mManager->getPlugin(), PluginMessageType::LanguageServerCapabilities, PluginMessageFormat::LanguageServerCapabilities, &mCapabilities ); }, - [&]( const IdType&, const json& ) {} ); + []( const IdType&, const json& ) {} ); } LSPClientServer::LSPClientServer( LSPClientServerManager* manager, const String::HashType& id, @@ -1781,7 +1781,7 @@ void LSPClientServer::getAndGoToLocation( const URI& document, const TextPositio void LSPClientServer::getAndGoToLocation( const URI& document, const TextPosition& pos, const std::string& search ) { getAndGoToLocation( document, pos, search, - [&]( const IdType&, const std::vector& locs ) { + [this]( const IdType&, const std::vector& locs ) { if ( !locs.empty() ) mManager->goToLocation( locs.front() ); } ); diff --git a/src/tools/ecode/plugins/lsp/lspclientservermanager.cpp b/src/tools/ecode/plugins/lsp/lspclientservermanager.cpp index 3c009f236..1c9aea9b5 100644 --- a/src/tools/ecode/plugins/lsp/lspclientservermanager.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientservermanager.cpp @@ -149,23 +149,30 @@ void LSPClientServerManager::goToLocation( const LSPLocation& loc ) { UICodeEditorSplitter* splitter = mPlugin->getManager()->getSplitter(); if ( nullptr == splitter ) return; - splitter->getUISceneNode()->runOnMainThread( [this, splitter, loc]() { + splitter->getUISceneNode()->runOnMainThread( [splitter, loc]() { UITab* tab = splitter->isDocumentOpen( loc.uri ); if ( !tab ) { std::string path( loc.uri.getFSPath() ); FileInfo fileInfo( path ); if ( fileInfo.exists() && fileInfo.isRegularFile() ) { + splitter->addCurrentPositionToNavigationHistory(); splitter->loadAsyncFileFromPathInNewTab( - path, mThreadPool, [loc]( UICodeEditor* editor, auto ) { - if ( loc.range.isValid() ) + path, [loc, splitter]( UICodeEditor* editor, auto ) { + if ( loc.range.isValid() ) { editor->goToLine( loc.range.start() ); + splitter->addEditorPositionToNavigationHistory( editor ); + } editor->setFocus(); } ); } } else { - tab->getTabWidget()->setTabSelected( tab ); if ( loc.range.isValid() ) + splitter->addCurrentPositionToNavigationHistory(); + tab->getTabWidget()->setTabSelected( tab ); + if ( loc.range.isValid() ) { splitter->editorFromTab( tab )->goToLine( loc.range.start() ); + splitter->addCurrentPositionToNavigationHistory(); + } splitter->editorFromTab( tab )->setFocus(); } } ); diff --git a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp index 5482bddd4..4a206b400 100644 --- a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp +++ b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp @@ -57,7 +57,7 @@ void LSPDocumentClient::onDocumentLineCountChange( const size_t& /*lastCount*/, void LSPDocumentClient::onDocumentLineChanged( const Int64& /*lineIndex*/ ) {} void LSPDocumentClient::onDocumentSaved( TextDocument* ) { - mServer->getThreadPool()->run( [&]() { mServer->didSave( mDoc ); } ); + mServer->getThreadPool()->run( [this]() { mServer->didSave( mDoc ); } ); } void LSPDocumentClient::onDocumentClosed( TextDocument* ) { diff --git a/src/tools/ecode/projectbuild.cpp b/src/tools/ecode/projectbuild.cpp index 7763efdf4..ea27d3a1c 100644 --- a/src/tools/ecode/projectbuild.cpp +++ b/src/tools/ecode/projectbuild.cpp @@ -1,6 +1,5 @@ #include "projectbuild.hpp" #include "ecode.hpp" -#include "scopedop.hpp" #include "statusbuildoutputcontroller.hpp" #include "uibuildsettings.hpp" #include @@ -9,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -147,7 +147,7 @@ json ProjectBuild::serialize( const ProjectBuild::Map& builds ) { } bool ProjectBuild::isOSSupported( const std::string& os ) const { - return mOS.empty() || std::any_of( mOS.begin(), mOS.end(), [&]( const auto& oos ) { + return mOS.empty() || std::any_of( mOS.begin(), mOS.end(), [&os]( const auto& oos ) { return oos == os || oos == "any"; } ); } @@ -692,7 +692,7 @@ void ProjectBuildManager::runBuild( const std::string& buildName, const std::str const ProjectBuildCommandsRes& res, const ProjectBuildProgressFn& progressFn, const ProjectBuildDoneFn& doneFn ) { - ScopedOp scopedOp( [this]() { mBuilding = true; }, [this]() { mBuilding = false; } ); + BoolScopedOp scopedOp( mBuilding, true ); Clock clock; auto printElapsed = [&clock, &i18n, &progressFn]() { diff --git a/src/tools/ecode/projectdirectorytree.cpp b/src/tools/ecode/projectdirectorytree.cpp index 9eab905db..8d362527e 100644 --- a/src/tools/ecode/projectdirectorytree.cpp +++ b/src/tools/ecode/projectdirectorytree.cpp @@ -78,7 +78,7 @@ void ProjectDirectoryTree::scan( const ProjectDirectoryTree::ScanCompleteEvent& mIsReady = true; mRunning = false; mApp->getPluginManager()->subscribeMessages( - "ProjectDirectoryTree", [&]( const PluginMessage& msg ) -> PluginRequestHandle { + "ProjectDirectoryTree", [this]( const PluginMessage& msg ) -> PluginRequestHandle { return processMessage( msg ); } ); #if EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN && !defined( __EMSCRIPTEN_PTHREADS__ ) diff --git a/src/tools/ecode/scopedop.hpp b/src/tools/ecode/scopedop.hpp deleted file mode 100644 index b1fbf440f..000000000 --- a/src/tools/ecode/scopedop.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef ECODE_SCOPEDOP_HPP -#define ECODE_SCOPEDOP_HPP - -#include - -class ScopedOp { - public: - ScopedOp( std::function startOp, - std::function endOp = std::function() ) : - mEndOp( endOp ) { - if ( startOp ) - startOp(); - } - - ~ScopedOp() { - if ( mEndOp ) - mEndOp(); - } - - private: - std::function mEndOp; -}; - -#endif // SCOPEDOP_HPP diff --git a/src/tools/ecode/settingsmenu.cpp b/src/tools/ecode/settingsmenu.cpp index 35f9d9984..3eeea32f9 100644 --- a/src/tools/ecode/settingsmenu.cpp +++ b/src/tools/ecode/settingsmenu.cpp @@ -130,8 +130,8 @@ void SettingsMenu::createSettingsMenu( App* app ) { ->setId( "close-app" ); mSettingsButton = mUISceneNode->find( "settings" ); mSettingsButton->addEventListener( Event::MouseClick, - [&]( const Event* ) { toggleSettingsMenu(); } ); - mSettingsMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + [this]( const Event* ) { toggleSettingsMenu(); } ); + mSettingsMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; const String& id = event->getNode()->asType()->getId(); @@ -190,7 +190,7 @@ UIMenu* SettingsMenu::createFileTypeMenu() { UIMenu* SettingsMenu::createColorSchemeMenu() { mColorSchemeMenuesCreatedWithHeight = mUISceneNode->getPixelsSize().getHeight(); size_t maxItems = 19; - auto cb = [&]( const Event* event ) { + auto cb = [this]( const Event* event ) { UIMenuItem* item = event->getNode()->asType(); const String& name = item->getText(); mSplitter->setColorScheme( name ); @@ -247,7 +247,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { tabTypeMenu->addRadioButton( i18n( "spaces", "Spaces" ) )->setId( "spaces" ); mDocMenu->addSubMenu( i18n( "indentation_type", "Indentation Type" ), nullptr, tabTypeMenu ) ->setId( "indent_type_cur" ); - tabTypeMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + tabTypeMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { const String& text = event->getNode()->asType()->getId(); if ( mSplitter->curEditorExistsAndFocused() ) { TextDocument::IndentType indentType = text == "tabs" @@ -267,7 +267,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { ->setData( w ); mDocMenu->addSubMenu( i18n( "indent_width", "Indent Width" ), nullptr, indentWidthMenu ) ->setId( "indent_width_cur" ); - indentWidthMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + indentWidthMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( mSplitter->curEditorExistsAndFocused() ) { int width = event->getNode()->getData(); mSplitter->getCurEditor()->getDocument().setIndentWidth( width ); @@ -284,7 +284,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { ->setData( w ); mDocMenu->addSubMenu( i18n( "tab_width", "Tab Width" ), nullptr, tabWidthMenu ) ->setId( "tab_width_cur" ); - tabWidthMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + tabWidthMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( mSplitter->curEditorExistsAndFocused() ) { int width = event->getNode()->getData(); mSplitter->getCurEditor()->setTabWidth( width ); @@ -306,7 +306,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { ->setId( "CR" ); mDocMenu->addSubMenu( i18n( "line_endings", "Line Endings" ), nullptr, lineEndingsMenu ) ->setId( "line_endings_cur" ); - lineEndingsMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + lineEndingsMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { auto le = TextDocument::stringToLineEnding( event->getNode()->asType()->getId() ); if ( mSplitter->curEditorExistsAndFocused() ) { @@ -332,7 +332,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { mApp->getConfig().doc.writeUnicodeBOM ) ->setId( "write_bom_cur" ); - mDocMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + mDocMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !mSplitter->curEditorExistsAndFocused() || event->getNode()->isType( UI_TYPE_MENU_SEPARATOR ) || event->getNode()->isType( UI_TYPE_MENUSUBMENU ) ) @@ -379,7 +379,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { globalMenu ->addSubMenu( i18n( "indentation_type", "Indentation Type" ), nullptr, tabTypeMenuGlobal ) ->setId( "indent_type" ); - tabTypeMenuGlobal->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + tabTypeMenuGlobal->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { const String& text = event->getNode()->asType()->getId(); mApp->getConfig().doc.indentSpaces = text != "tabs"; } ); @@ -392,7 +392,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { ->setData( w ); globalMenu->addSubMenu( i18n( "indent_width", "Indent Width" ), nullptr, indentWidthMenuGlobal ) ->setId( "indent_width" ); - indentWidthMenuGlobal->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + indentWidthMenuGlobal->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { int width = event->getNode()->getData(); mApp->getConfig().doc.indentWidth = width; } ); @@ -405,7 +405,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { ->setData( w ); globalMenu->addSubMenu( i18n( "tab_width", "Tab Width" ), nullptr, tabWidthMenuGlobal ) ->setId( "tab_width_cur" ); - tabWidthMenuGlobal->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + tabWidthMenuGlobal->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { int width = event->getNode()->getData(); mApp->getConfig().doc.tabWidth = width; } ); @@ -425,7 +425,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { ->setId( "CR" ); globalMenu->addSubMenu( i18n( "line_endings", "Line Endings" ), nullptr, lineEndingsGlobalMenu ) ->setId( "line_endings" ); - lineEndingsGlobalMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + lineEndingsGlobalMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { mApp->getConfig().doc.lineEndings = TextDocument::stringToLineEnding( event->getNode()->asType()->getId() ); } ); @@ -469,13 +469,13 @@ UIMenu* SettingsMenu::createDocumentMenu() { mApp->getConfig().editor.autoCloseXMLTags ) ->setOnShouldCloseCb( shouldCloseCb ) ->setId( "XML" ); - bracketsMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + bracketsMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { std::string id = event->getNode()->getId(); if ( event->getNode()->isType( UI_TYPE_MENUCHECKBOX ) ) { UIMenuCheckBox* item = event->getNode()->asType(); if ( item->getId() == "XML" ) { mApp->getConfig().editor.autoCloseXMLTags = item->isActive(); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setAutoCloseXMLTags( mApp->getConfig().editor.autoCloseXMLTags ); } ); return; @@ -522,7 +522,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { globalMenu->add( i18n( "cursor_blinking_time", "Cursor Blinking Time" ) ) ->setId( "cursor_blinking_time" ); - globalMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + globalMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !mSplitter->curEditorExistsAndFocused() || event->getNode()->isType( UI_TYPE_MENU_SEPARATOR ) || event->getNode()->isType( UI_TYPE_MENUSUBMENU ) ) @@ -577,7 +577,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { ->addSubMenu( i18n( "indentation_type", "Indentation Type" ), nullptr, tabTypeMenuProject ) ->setId( "indent_type" ) ->setEnabled( !mApp->getProjectDocConfig().useGlobalSettings ); - tabTypeMenuProject->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + tabTypeMenuProject->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { const String& text = event->getNode()->asType()->getId(); mApp->getProjectDocConfig().doc.indentSpaces = text != "tabs"; } ); @@ -593,7 +593,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { ->addSubMenu( i18n( "indent_width", "Indent Width" ), nullptr, indentWidthMenuProject ) ->setId( "indent_width" ) ->setEnabled( !mApp->getProjectDocConfig().useGlobalSettings ); - indentWidthMenuProject->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + indentWidthMenuProject->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { int width = event->getNode()->getData(); mApp->getProjectDocConfig().doc.indentWidth = width; } ); @@ -607,7 +607,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { mProjectDocMenu->addSubMenu( i18n( "tab_width", "Tab Width" ), nullptr, tabWidthMenuProject ) ->setId( "tab_width" ) ->setEnabled( !mApp->getProjectDocConfig().useGlobalSettings ); - tabWidthMenuProject->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + tabWidthMenuProject->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { int width = event->getNode()->getData(); mApp->getProjectDocConfig().doc.tabWidth = width; } ); @@ -629,7 +629,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { ->addSubMenu( i18n( "line_endings", "Line Endings" ), nullptr, lineEndingsProjectMenu ) ->setId( "line_endings" ) ->setEnabled( !mApp->getProjectDocConfig().useGlobalSettings ); - lineEndingsProjectMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + lineEndingsProjectMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { mApp->getProjectDocConfig().doc.lineEndings = TextDocument::stringToLineEnding( event->getNode()->asType()->getId() ); } ); @@ -657,7 +657,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { mProjectDocMenu->add( i18n( "line_breaking_column", "Line Breaking Column" ) ) ->setId( "line_breaking_column" ); - mProjectDocMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + mProjectDocMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !mSplitter->curEditorExistsAndFocused() || event->getNode()->isType( UI_TYPE_MENU_SEPARATOR ) || event->getNode()->isType( UI_TYPE_MENUSUBMENU ) ) @@ -769,12 +769,12 @@ UIMenu* SettingsMenu::createTerminalMenu() { findIcon( "terminal" ), getKeybind( "configure-terminal-shell" ) ) ->setId( "configure-terminal-shell" ); - newTerminalBehaviorSubMenu->on( Event::OnItemClicked, [&]( const Event* event ) { + newTerminalBehaviorSubMenu->on( Event::OnItemClicked, [this]( const Event* event ) { const std::string& id( event->getNode()->getId() ); mApp->getConfig().term.newTerminalOrientation = NewTerminalOrientation::fromString( id ); } ); - mTerminalMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + mTerminalMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { const std::string& id( event->getNode()->getId() ); if ( mSplitter->getCurWidget() && mSplitter->getCurWidget()->isType( UI_TYPE_TERMINAL ) ) { UITerminal* terminal = mSplitter->getCurWidget()->asType(); @@ -826,7 +826,7 @@ UIMenu* SettingsMenu::createEditMenu() { menu->add( i18n( "key_bindings", "Key Bindings" ), findIcon( "keybindings" ), getKeybind( "keybindings" ) ) ->setId( "keybindings" ); - menu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + menu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; runCommand( event->getNode()->getId() ); @@ -857,7 +857,7 @@ UIMenu* SettingsMenu::createWindowMenu() { ->addRadioButton( i18n( "dark", "Dark" ), mApp->getUIColorScheme() == ColorSchemePreference::Dark ) ->setId( "dark" ); - colorsMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + colorsMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; UIMenuItem* item = event->getNode()->asType(); @@ -966,7 +966,7 @@ UIMenu* SettingsMenu::createWindowMenu() { ->add( i18n( "inspect_widgets", "Inspect Widgets" ), findIcon( "package" ), getKeybind( "debug-widget-tree-view" ) ) ->setId( "debug-widget-tree-view" ); - mWindowMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + mWindowMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; UIMenuItem* item = event->getNode()->asType(); @@ -994,7 +994,7 @@ UIMenu* SettingsMenu::createRendererMenu() { mRendererMenu->add( i18n( "frame_rate_limit", "Frame Rate Limit" ), findIcon( "fps" ) ) ->setId( "frame_rate_limit" ); - mRendererMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + mRendererMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; UIMenuItem* item = event->getNode()->asType(); @@ -1038,7 +1038,7 @@ UIMenu* SettingsMenu::createRendererMenu() { ->addRadioButton( Renderer::graphicsLibraryVersionToString( ver ), GLi->version() == ver ) ->setData( ver ); - glVersion->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + glVersion->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; UIMenuItem* item = event->getNode()->asType(); @@ -1061,7 +1061,7 @@ UIMenu* SettingsMenu::createRendererMenu() { ->setData( val ); mRendererMenu->addSubMenu( i18n( "ui_multisamples_level", "Multisample Anti-Aliasing Level" ), findIcon( "multisamples" ), multisampleLvl ); - multisampleLvl->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + multisampleLvl->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; UIMenuItem* item = event->getNode()->asType(); @@ -1147,29 +1147,29 @@ UIMenu* SettingsMenu::createViewMenu() { "directory tree." ) ) ->setId( "sync-project-tree" ); - mViewMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + mViewMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; UIMenuItem* item = event->getNode()->asType(); if ( item->getId() == "show-line-numbers" ) { mApp->getConfig().editor.showLineNumbers = item->asType()->isActive(); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setShowLineNumber( mApp->getConfig().editor.showLineNumbers ); } ); } else if ( item->getId() == "show-white-spaces" ) { mApp->getConfig().editor.showWhiteSpaces = item->asType()->isActive(); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setShowWhitespaces( mApp->getConfig().editor.showWhiteSpaces ); } ); } else if ( item->getId() == "show-line-endings" ) { mApp->getConfig().editor.showLineEndings = item->asType()->isActive(); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setShowLineEndings( mApp->getConfig().editor.showLineEndings ); } ); } else if ( item->getId() == "show-indentation-guides" ) { mApp->getConfig().editor.showIndentationGuides = item->asType()->isActive(); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setShowIndentationGuides( mApp->getConfig().editor.showIndentationGuides ); } ); } else if ( item->getId() == "show-doc-info" ) { @@ -1180,56 +1180,56 @@ UIMenu* SettingsMenu::createViewMenu() { mApp->updateDocInfo( mSplitter->getCurEditor()->getDocument() ); } else if ( item->getId() == "show-minimap" ) { mApp->getConfig().editor.minimap = item->asType()->isActive(); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->showMinimap( mApp->getConfig().editor.minimap ); } ); } else if ( item->getId() == "show-lines-relative-position" ) { mApp->getConfig().editor.linesRelativePosition = item->asType()->isActive(); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->showLinesRelativePosition( mApp->getConfig().editor.linesRelativePosition ); } ); } else if ( item->getId() == "highlight-matching-brackets" ) { mApp->getConfig().editor.highlightMatchingBracket = item->asType()->isActive(); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setHighlightMatchingBracket( mApp->getConfig().editor.highlightMatchingBracket ); } ); } else if ( item->getId() == "highlight-current-line" ) { mApp->getConfig().editor.highlightCurrentLine = item->asType()->isActive(); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setHighlightCurrentLine( mApp->getConfig().editor.highlightCurrentLine ); } ); } else if ( item->getId() == "highlight-selection-match" ) { mApp->getConfig().editor.highlightSelectionMatch = item->asType()->isActive(); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setHighlightSelectionMatch( mApp->getConfig().editor.highlightSelectionMatch ); } ); } else if ( item->getId() == "enable-vertical-scrollbar" ) { mApp->getConfig().editor.verticalScrollbar = item->asType()->isActive(); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setVerticalScrollBarEnabled( mApp->getConfig().editor.verticalScrollbar ); } ); } else if ( item->getId() == "enable-horizontal-scrollbar" ) { mApp->getConfig().editor.horizontalScrollbar = item->asType()->isActive(); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setHorizontalScrollBarEnabled( mApp->getConfig().editor.horizontalScrollbar ); } ); } else if ( item->getId() == "enable-color-preview" ) { mApp->getConfig().editor.colorPreview = item->asType()->isActive(); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setEnableColorPickerOnSelection( mApp->getConfig().editor.colorPreview ); } ); } else if ( item->getId() == "enable-color-picker" ) { mApp->getConfig().editor.colorPickerSelection = item->asType()->isActive(); - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setEnableColorPickerOnSelection( mApp->getConfig().editor.colorPickerSelection ); } ); @@ -1299,7 +1299,7 @@ UIPopUpMenu* SettingsMenu::createToolsMenu() { ->add( i18n( "load_cur_dir_as_folder", "Load current document directory as folder" ), findIcon( "folder" ), getKeybind( "load-current-dir" ) ) ->setId( "load-current-dir" ); - mToolsMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + mToolsMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; runCommand( event->getNode()->getId() ); @@ -1315,7 +1315,7 @@ UIMenu* SettingsMenu::createHelpMenu() { ->setId( "check-for-updates" ); helpMenu->add( i18n( "about_ecode", "About ecode..." ), findIcon( "ecode" ) ) ->setId( "about-ecode" ); - helpMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + helpMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { runCommand( event->getNode()->getId() ); } ); return helpMenu; @@ -1339,7 +1339,7 @@ UIMenu* SettingsMenu::createThemesMenu() { menu->addRadioButton( name, curTheme == name )->setId( name ); } - menu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + menu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { auto id = event->getNode()->getId(); mApp->getConfig().ui.theme = "default_theme" != id ? id : ""; std::string path( mApp->getConfig().ui.theme.empty() @@ -1379,7 +1379,7 @@ void SettingsMenu::updateProjectSettingsMenu() { !mApp->getProjectDocConfig().useGlobalSettings ); } - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { editor->setLineBreakingColumn( !mApp->getCurrentProject().empty() && !mApp->getProjectDocConfig().useGlobalSettings ? mApp->getProjectDocConfig().doc.lineBreakingColumn @@ -1564,7 +1564,7 @@ void SettingsMenu::createProjectTreeMenu() { ->setId( "open-folder" ); } - mProjectTreeMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + mProjectTreeMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; UIMenuItem* item = event->getNode()->asType(); @@ -1829,7 +1829,7 @@ void SettingsMenu::createProjectMenu() { mApp->getProjectDocConfig().hAsCPP ) ->setId( "h_as_cpp" ); - mProjectMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + mProjectMenu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { if ( event->getNode()->isType( UI_TYPE_MENU_SEPARATOR ) || event->getNode()->isType( UI_TYPE_MENUSUBMENU ) ) return; diff --git a/src/tools/ecode/statusbuildoutputcontroller.cpp b/src/tools/ecode/statusbuildoutputcontroller.cpp index 0cc08a0ce..4166e0cad 100644 --- a/src/tools/ecode/statusbuildoutputcontroller.cpp +++ b/src/tools/ecode/statusbuildoutputcontroller.cpp @@ -207,7 +207,7 @@ void StatusBuildOutputController::runBuild( const std::string& buildName, [this]( auto, std::string buffer, const ProjectBuildCommand* cmd ) { mBuildOutput->runOnMainThread( [this, buffer]() { bool scrollToBottom = mBuildOutput->getVScrollBar()->getValue() == 1.f; - mBuildOutput->getDocument().textInput( buffer ); + mBuildOutput->getDocument().textInput( buffer, false ); if ( scrollToBottom ) mBuildOutput->setScrollY( mBuildOutput->getMaxScroll().y ); } ); @@ -243,7 +243,7 @@ void StatusBuildOutputController::runBuild( const std::string& buildName, mBuildOutput->runOnMainThread( [this, buffer]() { bool scrollToBottom = mBuildOutput->getVScrollBar()->getValue() == 1.f; - mBuildOutput->getDocument().textInput( buffer ); + mBuildOutput->getDocument().textInput( buffer, false ); if ( scrollToBottom ) mBuildOutput->setScrollY( mBuildOutput->getMaxScroll().y ); } ); @@ -315,7 +315,7 @@ void StatusBuildOutputController::runClean( const std::string& buildName, [this]( auto, auto buffer, auto ) { mBuildOutput->runOnMainThread( [this, buffer]() { bool scrollToBottom = mBuildOutput->getVScrollBar()->getValue() == 1.f; - mBuildOutput->getDocument().textInput( buffer ); + mBuildOutput->getDocument().textInput( buffer, false ); if ( scrollToBottom ) mBuildOutput->setScrollY( mBuildOutput->getMaxScroll().y ); } ); @@ -333,7 +333,7 @@ void StatusBuildOutputController::runClean( const std::string& buildName, mBuildOutput->runOnMainThread( [this, buffer]() { bool scrollToBottom = mBuildOutput->getVScrollBar()->getValue() == 1.f; - mBuildOutput->getDocument().textInput( buffer ); + mBuildOutput->getDocument().textInput( buffer, false ); if ( scrollToBottom ) mBuildOutput->setScrollY( mBuildOutput->getMaxScroll().y ); } ); @@ -452,6 +452,7 @@ void StatusBuildOutputController::onLoadDone( const Variant& lineNum, const Vari TextPosition pos{ lineNum.asInt64() > 0 ? lineNum.asInt64() - 1 : 0, colNum.asInt64() }; mSplitter->getCurEditor()->getDocument().setSelection( pos ); mSplitter->getCurEditor()->goToLine( pos ); + mSplitter->addCurrentPositionToNavigationHistory(); } } @@ -491,7 +492,7 @@ void StatusBuildOutputController::createContainer() { editor->setShowLineNumber( false ); editor->getDocument().reset(); editor->getDocument().textInput( - mApp->i18n( "no_build_has_been_run", "No build has been run" ) ); + mApp->i18n( "no_build_has_been_run", "No build has been run" ), false ); editor->setScrollY( editor->getMaxScroll().y ); mButOutput = mContainer->find( "but_build_output_output" ); mButIssues = mContainer->find( "but_build_output_issues" ); diff --git a/src/tools/ecode/statusterminalcontroller.cpp b/src/tools/ecode/statusterminalcontroller.cpp index fc40d0602..41799ba19 100644 --- a/src/tools/ecode/statusterminalcontroller.cpp +++ b/src/tools/ecode/statusterminalcontroller.cpp @@ -96,7 +96,7 @@ UITerminal* StatusTerminalController::createTerminal( const std::string& working ? terminalColorSchemes.at( currentTerminalColorScheme ) : TerminalColorScheme::getDefault() ); mApp->getTerminalManager()->setKeybindings( term ); - term->setCommand( "switch-to-previous-colorscheme", [&] { + term->setCommand( "switch-to-previous-colorscheme", [this] { auto it = mApp->getTerminalManager()->getTerminalColorSchemes().find( mApp->getTerminalManager()->getTerminalCurrentColorScheme() ); auto prev = std::prev( it, 1 ); @@ -107,7 +107,7 @@ UITerminal* StatusTerminalController::createTerminal( const std::string& working mApp->getTerminalManager()->getTerminalColorSchemes().rbegin()->first ); } } ); - term->setCommand( "switch-to-next-colorscheme", [&] { + term->setCommand( "switch-to-next-colorscheme", [this] { auto it = mApp->getTerminalManager()->getTerminalColorSchemes().find( mApp->getTerminalManager()->getTerminalCurrentColorScheme() ); mApp->getTerminalManager()->setTerminalColorScheme( diff --git a/src/tools/ecode/terminalmanager.cpp b/src/tools/ecode/terminalmanager.cpp index fd4b85227..7bec24f4d 100644 --- a/src/tools/ecode/terminalmanager.cpp +++ b/src/tools/ecode/terminalmanager.cpp @@ -168,7 +168,7 @@ void TerminalManager::configureTerminalShell() { UIMenu* TerminalManager::createColorSchemeMenu() { mColorSchemeMenuesCreatedWithHeight = mApp->uiSceneNode()->getPixelsSize().getHeight(); size_t maxItems = 19; - auto cb = [&]( const Event* event ) { + auto cb = [this]( const Event* event ) { UIMenuItem* item = event->getNode()->asType(); const String& name = item->getText(); setTerminalColorScheme( name ); @@ -282,7 +282,7 @@ UITerminal* TerminalManager::createNewTerminal( const std::string& title, UITabW term->setColorScheme( csIt != mTerminalColorSchemes.end() ? mTerminalColorSchemes.at( mTerminalCurrentColorScheme ) : TerminalColorScheme::getDefault() ); - term->addEventListener( Event::OnTitleChange, [&]( const Event* event ) { + term->addEventListener( Event::OnTitleChange, [this]( const Event* event ) { if ( event->getNode() != mApp->getSplitter()->getCurWidget() ) return; mApp->setAppTitle( event->getNode()->asType()->getTitle() ); @@ -302,7 +302,7 @@ UITerminal* TerminalManager::createNewTerminal( const std::string& title, UITabW term->setFocus(); } ); } ); - term->setCommand( "switch-to-previous-colorscheme", [&] { + term->setCommand( "switch-to-previous-colorscheme", [this] { auto it = mTerminalColorSchemes.find( mTerminalCurrentColorScheme ); auto prev = std::prev( it, 1 ); if ( prev != mTerminalColorSchemes.end() ) { @@ -311,7 +311,7 @@ UITerminal* TerminalManager::createNewTerminal( const std::string& title, UITabW setTerminalColorScheme( mTerminalColorSchemes.rbegin()->first ); } } ); - term->setCommand( "switch-to-next-colorscheme", [&] { + term->setCommand( "switch-to-next-colorscheme", [this] { auto it = mTerminalColorSchemes.find( mTerminalCurrentColorScheme ); setTerminalColorScheme( ++it != mTerminalColorSchemes.end() ? it->first diff --git a/src/tools/ecode/uitreeviewglobalsearch.cpp b/src/tools/ecode/uitreeviewglobalsearch.cpp index f1f7cdd36..0a85f2c56 100644 --- a/src/tools/ecode/uitreeviewglobalsearch.cpp +++ b/src/tools/ecode/uitreeviewglobalsearch.cpp @@ -1,5 +1,5 @@ -#include "projectsearch.hpp" #include "uitreeviewglobalsearch.hpp" +#include "projectsearch.hpp" #include #include #include @@ -79,7 +79,7 @@ void UITreeViewCellGlobalSearch::toggleSelected() { } std::function UITreeViewCellGlobalSearch::getCheckBoxFn() { - return [&]( UIPushButton* ) -> UITextView* { + return [this]( UIPushButton* ) -> UITextView* { UICheckBox* chk = UICheckBox::New(); addEventListener( Event::MouseClick, [&, chk]( const Event* event ) { const MouseEvent* mouseEvent = static_cast( event ); diff --git a/src/tools/ecode/universallocator.cpp b/src/tools/ecode/universallocator.cpp index 648aa4575..a3e4d3b03 100644 --- a/src/tools/ecode/universallocator.cpp +++ b/src/tools/ecode/universallocator.cpp @@ -118,8 +118,9 @@ UniversalLocator::UniversalLocator( UICodeEditorSplitter* editorSplitter, UIScen mApp( app ), mCommandPalette( mApp->getThreadPool() ) { mApp->getPluginManager()->subscribeMessages( - "universallocator", - [&]( const PluginMessage& msg ) -> PluginRequestHandle { return processResponse( msg ); } ); + "universallocator", [this]( const PluginMessage& msg ) -> PluginRequestHandle { + return processResponse( msg ); + } ); } void UniversalLocator::hideLocateBar() { @@ -187,7 +188,7 @@ void UniversalLocator::updateCommandPaletteTable() { if ( txt.size() > 1 ) { #if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN || defined( __EMSCRIPTEN_PTHREADS__ ) - mCommandPalette.asyncFuzzyMatch( txt.substr( 1 ), 1000, [&]( auto res ) { + mCommandPalette.asyncFuzzyMatch( txt.substr( 1 ), 1000, [this]( auto res ) { mUISceneNode->runOnMainThread( [&, res] { mLocateTable->setModel( res ); mLocateTable->getSelection().set( mLocateTable->getModel()->index( 0 ) ); @@ -228,7 +229,7 @@ static bool isCommand( const std::string& filename ) { void UniversalLocator::initLocateBar( UILocateBar* locateBar, UITextInput* locateInput ) { mLocateBarLayout = locateBar; mLocateInput = locateInput; - auto addClickListener = [&]( UIWidget* widget, std::string cmd ) { + auto addClickListener = [this]( UIWidget* widget, std::string cmd ) { widget->addEventListener( Event::MouseClick, [this, cmd]( const Event* event ) { const MouseEvent* mouseEvent = static_cast( event ); if ( mouseEvent->getFlags() & EE_BUTTON_LMASK ) { @@ -241,7 +242,7 @@ void UniversalLocator::initLocateBar( UILocateBar* locateBar, UITextInput* locat mLocateTable->setParent( mUISceneNode->getRoot() ); mLocateTable->setHeadersVisible( false ); mLocateTable->setVisible( false ); - mLocateInput->addEventListener( Event::OnTextChanged, [&]( const Event* ) { + mLocateInput->addEventListener( Event::OnTextChanged, [this]( const Event* ) { const String& inputTxt = mLocateInput->getText(); if ( mSplitter->curEditorExistsAndFocused() && String::startsWith( inputTxt, String( "l " ) ) ) { @@ -258,6 +259,7 @@ void UniversalLocator::initLocateBar( UILocateBar* locateBar, UITextInput* locat } if ( mSplitter->curEditorExistsAndFocused() ) { mSplitter->getCurEditor()->goToLine( { line - 1, column } ); + mSplitter->addCurrentPositionToNavigationHistory(); } mLocateTable->setVisible( false ); } @@ -274,15 +276,15 @@ void UniversalLocator::initLocateBar( UILocateBar* locateBar, UITextInput* locat updateFilesTable(); } } ); - mLocateInput->addEventListener( Event::OnPressEnter, [&]( const Event* ) { + mLocateInput->addEventListener( Event::OnPressEnter, [this]( const Event* ) { KeyEvent keyEvent( mLocateTable, Event::KeyDown, KEY_RETURN, SCANCODE_UNKNOWN, 0, 0 ); mLocateTable->forceKeyDown( keyEvent ); } ); - mLocateInput->addEventListener( Event::KeyDown, [&]( const Event* event ) { + mLocateInput->addEventListener( Event::KeyDown, [this]( const Event* event ) { const KeyEvent* keyEvent = static_cast( event ); mLocateTable->forceKeyDown( *keyEvent ); } ); - mLocateBarLayout->setCommand( "close-locatebar", [&] { + mLocateBarLayout->setCommand( "close-locatebar", [this] { hideLocateBar(); if ( mSplitter->getCurWidget() ) mSplitter->getCurWidget()->setFocus(); @@ -290,13 +292,13 @@ void UniversalLocator::initLocateBar( UILocateBar* locateBar, UITextInput* locat mLocateBarLayout->getKeyBindings().addKeybindsString( { { "escape", "close-locatebar" }, } ); - mLocateTable->addEventListener( Event::KeyDown, [&]( const Event* event ) { + mLocateTable->addEventListener( Event::KeyDown, [this]( const Event* event ) { const KeyEvent* keyEvent = static_cast( event ); if ( keyEvent->getKeyCode() == KEY_ESCAPE ) mLocateBarLayout->execute( "close-locatebar" ); } ); addClickListener( mLocateBarLayout->find( "locatebar_close" ), "close-locatebar" ); - mLocateTable->addEventListener( Event::OnModelEvent, [&]( const Event* event ) { + mLocateTable->addEventListener( Event::OnModelEvent, [this]( const Event* event ) { const ModelEvent* modelEvent = static_cast( event ); if ( modelEvent->getModelEventType() == ModelEventType::Open ) { // Keep it simple for now, command palette has 3 columns @@ -364,6 +366,7 @@ void UniversalLocator::initLocateBar( UILocateBar* locateBar, UITextInput* locat tab->getTabWidget()->setTabSelected( tab ); UICodeEditor* editor = tab->getOwnedWidget()->asType(); editor->goToLine( range.start() ); + mSplitter->addEditorPositionToNavigationHistory( editor ); mLocateBarLayout->execute( "close-locatebar" ); } } @@ -373,7 +376,7 @@ void UniversalLocator::initLocateBar( UILocateBar* locateBar, UITextInput* locat } void UniversalLocator::updateLocateBar() { - mLocateBarLayout->runOnMainThread( [&] { + mLocateBarLayout->runOnMainThread( [this] { Float width = eeceil( mLocateInput->getPixelsSize().getWidth() ); mLocateTable->setPixelsSize( width, mLocateTable->getRowHeight() * LOCATEBAR_MAX_VISIBLE_ITEMS ); @@ -411,7 +414,7 @@ void UniversalLocator::showBar() { } mLocateInput->addEventListener( Event::OnSizeChange, - [&]( const Event* ) { updateLocateBar(); } ); + [this]( const Event* ) { updateLocateBar(); } ); } void UniversalLocator::showLocateBar() { @@ -528,15 +531,19 @@ void UniversalLocator::focusOrLoadFile( const std::string& path, const TextRange if ( !tab ) { FileInfo fileInfo( path ); if ( fileInfo.exists() && fileInfo.isRegularFile() ) - mApp->loadFileFromPath( path, true, nullptr, [range]( UICodeEditor* editor, auto ) { - if ( range.isValid() ) - editor->goToLine( range.start() ); - } ); + mApp->loadFileFromPath( + path, true, nullptr, [this, range]( UICodeEditor* editor, auto ) { + if ( range.isValid() ) { + editor->goToLine( range.start() ); + mSplitter->addEditorPositionToNavigationHistory( editor ); + } + } ); } else { tab->getTabWidget()->setTabSelected( tab ); if ( range.isValid() ) { UICodeEditor* editor = tab->getOwnedWidget()->asType(); editor->goToLine( range.start() ); + mSplitter->addEditorPositionToNavigationHistory( editor ); } } } @@ -645,9 +652,9 @@ void UniversalLocator::updateDocumentSymbol( const LSPSymbolInformationList& res mLocateTable->getSelection().set( mLocateTable->getModel()->index( 0 ) ); mLocateTable->scrollToTop(); } else { - asyncFuzzyMatchTextDocumentSymbol( res, mCurDocQuery, 100, [&]( const auto model ) { + asyncFuzzyMatchTextDocumentSymbol( res, mCurDocQuery, 100, [this]( const auto model ) { mTextDocumentSymbolModel = model; - mUISceneNode->runOnMainThread( [&] { + mUISceneNode->runOnMainThread( [this] { mLocateTable->setModel( mTextDocumentSymbolModel ); mLocateTable->getSelection().set( mLocateTable->getModel()->index( 0 ) ); mLocateTable->scrollToTop(); diff --git a/src/tools/ecode/version.hpp b/src/tools/ecode/version.hpp index 0602c7adf..841ee6882 100644 --- a/src/tools/ecode/version.hpp +++ b/src/tools/ecode/version.hpp @@ -8,7 +8,7 @@ using namespace EE; #define ECODE_MAJOR_VERSION 0 #define ECODE_MINOR_VERSION 4 -#define ECODE_PATCH_LEVEL 8 +#define ECODE_PATCH_LEVEL 9 #define ECODE_CODENAME "Vajra" /** The compiled version of the library */ diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index a396f9d5b..719274d2d 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -339,7 +339,7 @@ void App::reloadStyleSheet() { UICodeEditor* editor = mSplitter->findEditorFromPath( mCurrentStyleSheet ); if ( !editor ) return; - saveTmpDocument( editor->getDocument(), [&]( const std::string& tmpPath ) { + saveTmpDocument( editor->getDocument(), [this]( const std::string& tmpPath ) { loadStyleSheet( tmpPath, false ); } ); break; @@ -397,8 +397,9 @@ void App::reloadLayout() { UICodeEditor* editor = mSplitter->findEditorFromPath( mCurrentLayout ); if ( !editor ) return; - saveTmpDocument( editor->getDocument(), - [&]( const std::string& tmpPath ) { loadLayout( tmpPath, false ); } ); + saveTmpDocument( editor->getDocument(), [this]( const std::string& tmpPath ) { + loadLayout( tmpPath, false ); + } ); break; } case InvalidationType::FileSystem: @@ -489,7 +490,7 @@ void App::updateRecentFiles() { menu->removeEventListener( mRecentFilesEventClickId ); mRecentFilesEventClickId = menu->addEventListener( - Event::OnItemClicked, [&]( const Event* event ) { onRecentFilesClick( event ); } ); + Event::OnItemClicked, [this]( const Event* event ) { onRecentFilesClick( event ); } ); } SceneManager::instance()->setCurrentUISceneNode( mUISceneNode ); @@ -518,7 +519,7 @@ void App::updateRecentProjects() { menu->removeEventListener( mRecentProjectEventClickId ); mRecentProjectEventClickId = menu->addEventListener( - Event::OnItemClicked, [&]( const Event* event ) { onRecentProjectClick( event ); } ); + Event::OnItemClicked, [this]( const Event* event ) { onRecentProjectClick( event ); } ); } SceneManager::instance()->setCurrentUISceneNode( mUISceneNode ); @@ -631,7 +632,7 @@ void App::refreshLayoutList() { mUIMenuBar->addMenuButton( "Layouts", uiLayoutsMenu ); uiLayoutsMenu->addEventListener( - Event::OnItemClicked, [&]( const Event* event ) { onLayoutSelected( event ); } ); + Event::OnItemClicked, [this]( const Event* event ) { onLayoutSelected( event ); } ); } else { uiLayoutsMenu = mUIMenuBar->getPopUpMenu( "Layouts" ); } @@ -702,7 +703,7 @@ void App::loadProjectNodes( pugi::xml_node node ) { for ( auto it = mWidgetRegistered.begin(); it != mWidgetRegistered.end(); ++it ) { if ( !UIWidgetCreator::existsCustomWidgetCallback( it->first ) ) UIWidgetCreator::addCustomWidgetCallback( - it->first, [&]( std::string widgetName ) -> UIWidget* { + it->first, [this]( std::string widgetName ) -> UIWidget* { return createWidget( widgetName ); } ); } @@ -1061,26 +1062,26 @@ void App::fileMenuClick( const Event* event ) { createNewLayout(); } else if ( "open-project" == id ) { showFileDialog( - "Open project...", [&]( const Event* event ) { projectOpen( event ); }, "*.xml" ); + "Open project...", [this]( const Event* event ) { projectOpen( event ); }, "*.xml" ); } else if ( "open-layout" == id ) { showFileDialog( - "Open layout...", [&]( const Event* event ) { layoutOpen( event ); }, "*.xml" ); + "Open layout...", [this]( const Event* event ) { layoutOpen( event ); }, "*.xml" ); } else if ( "close" == id ) { closeProject(); } else if ( "quit" == id ) { onCloseRequestCallback( mWindow ); } else if ( "load-images-from-path" == id ) { showFileDialog( - "Open images from folder...", [&]( const Event* event ) { imagePathOpen( event ); }, + "Open images from folder...", [this]( const Event* event ) { imagePathOpen( event ); }, "*", UIFileDialog::DefaultFlags | UIFileDialog::AllowFolderSelect ); } else if ( "load-fonts-from-path" == id ) { showFileDialog( - "Open fonts from folder...", [&]( const Event* event ) { fontPathOpen( event ); }, "*", - UIFileDialog::DefaultFlags | UIFileDialog::AllowFolderSelect ); + "Open fonts from folder...", [this]( const Event* event ) { fontPathOpen( event ); }, + "*", UIFileDialog::DefaultFlags | UIFileDialog::AllowFolderSelect ); } else if ( "load-css-from-path" == id ) { showFileDialog( "Open style sheet from path...", - [&]( const Event* event ) { styleSheetPathOpen( event ); }, "*.css" ); + [this]( const Event* event ) { styleSheetPathOpen( event ); }, "*.css" ); } else if ( "toggle-console" == id ) { mConsole->toggle(); } else if ( "toggle-editor" == id ) { @@ -1135,7 +1136,7 @@ void App::createAppMenu() { mUIMenuBar->addMenuButton( "File", uiPopMenu ); uiPopMenu->addEventListener( Event::OnItemClicked, - [&]( const Event* event ) { fileMenuClick( event ); } ); + [this]( const Event* event ) { fileMenuClick( event ); } ); UIPopUpMenu* uiResourceMenu = UIPopUpMenu::New(); uiResourceMenu->add( "Load images from path...", findIcon( "document-open" ) ) @@ -1148,7 +1149,7 @@ void App::createAppMenu() { ->setId( "load-css-from-path" ); mUIMenuBar->addMenuButton( "Resources", uiResourceMenu ); uiResourceMenu->addEventListener( Event::OnItemClicked, - [&]( const Event* event ) { fileMenuClick( event ); } ); + [this]( const Event* event ) { fileMenuClick( event ); } ); UIPopUpMenu* viewMenu = UIPopUpMenu::New(); viewMenu->add( "Highlight Focus & Hover", nullptr, "F6" )->setId( "highlight-focus" ); @@ -1160,7 +1161,7 @@ void App::createAppMenu() { viewMenu->add( "Toggle Editor", findIcon( "editor" ), "F9" )->setId( "toggle-editor" ); mUIMenuBar->addMenuButton( "View", viewMenu ); viewMenu->addEventListener( Event::OnItemClicked, - [&]( const Event* event ) { fileMenuClick( event ); } ); + [this]( const Event* event ) { fileMenuClick( event ); } ); mConsole = UIConsole::New(); mConsole->setQuakeMode( true ); mConsole->setVisible( false ); @@ -1217,7 +1218,7 @@ void App::init( const Float& pixelDensityConf, const bool& useAppTheme, const st PixelDensity::setPixelDensity( eemax( mWindow->getScale(), pixelDensity ) ); mWindow->setCloseRequestCallback( - [&]( auto* window ) -> bool { return onCloseRequestCallback( window ); } ); + [this]( auto* window ) -> bool { return onCloseRequestCallback( window ); } ); mResPath = Sys::getProcessPath(); #if EE_PLATFORM == EE_PLATFORM_MACOSX @@ -1345,7 +1346,7 @@ void App::init( const Float& pixelDensityConf, const bool& useAppTheme, const st mUIContainer = UIWindow::NewOpt( UIWindow::SIMPLE_LAYOUT, winStyle ); mUIContainer->setId( "appContainer" )->setSize( mUISceneNode->getSize() ); mUIContainer->setParent( mUISceneNode->getRoot() ); - mUISceneNode->addEventListener( Event::OnSizeChange, [&]( const Event* ) { + mUISceneNode->addEventListener( Event::OnSizeChange, [this]( const Event* ) { mUIContainer->setPixelsSize( mUISceneNode->getPixelsSize() ); } ); @@ -1380,7 +1381,8 @@ void App::init( const Float& pixelDensityConf, const bool& useAppTheme, const st mAppUISceneNode->bind( "project_splitter", mProjectSplitter ); mSidePanel = mProjectSplitter->getFirstWidget(); SceneManager::instance()->setCurrentUISceneNode( mAppUISceneNode ); - mSplitter = UICodeEditorSplitter::New( this, mAppUISceneNode, colorSchemes, "eepp" ); + mSplitter = + UICodeEditorSplitter::New( this, mAppUISceneNode, nullptr, colorSchemes, "eepp" ); mSplitter->setHideTabBarOnSingleTab( false ); mSplitter->createEditorWithTabWidget( mBaseLayout ); SceneManager::instance()->setCurrentUISceneNode( mUISceneNode ); @@ -1392,7 +1394,8 @@ void App::init( const Float& pixelDensityConf, const bool& useAppTheme, const st resizeCb(); - mUISceneNode->addEventListener( Event::OnSizeChange, [&]( const Event* ) { resizeCb(); } ); + mUISceneNode->addEventListener( Event::OnSizeChange, + [this]( const Event* ) { resizeCb(); } ); mUseDefaultTheme = useAppTheme; @@ -1482,7 +1485,7 @@ void App::saveAllProcess() { if ( mTmpDocs.empty() ) return; - mSplitter->forEachEditorStoppable( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditorStoppable( [this]( UICodeEditor* editor ) { if ( editor->getDocument().isDirty() && std::find( mTmpDocs.begin(), mTmpDocs.end(), &editor->getDocument() ) != mTmpDocs.end() ) { @@ -1519,7 +1522,7 @@ void App::saveDoc() { } void App::saveAll() { - mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { if ( editor->isDirty() ) mTmpDocs.insert( &editor->getDocument() ); } ); @@ -1529,13 +1532,13 @@ void App::saveAll() { void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { editor->setAutoCloseXMLTags( true ); editor->setColorPreview( true ); - doc.setCommand( "save-doc", [&] { saveDoc(); } ); - doc.setCommand( "save-as-doc", [&] { + doc.setCommand( "save-doc", [this] { saveDoc(); } ); + doc.setCommand( "save-as-doc", [this] { if ( mSplitter->curEditorExistsAndFocused() ) saveFileDialog( mSplitter->getCurEditor() ); } ); - doc.setCommand( "save-all", [&] { saveAll(); } ); - doc.setCommand( "create-new", [&] { createNewLayout(); } ); + doc.setCommand( "save-all", [this] { saveAll(); } ); + doc.setCommand( "create-new", [this] { createNewLayout(); } ); } void App::onCodeEditorFocusChange( UICodeEditor* editor ) {