diff --git a/include/eepp/ui/tools/uicodeeditorsplitter.hpp b/include/eepp/ui/tools/uicodeeditorsplitter.hpp index c8076ab4e..391004615 100644 --- a/include/eepp/ui/tools/uicodeeditorsplitter.hpp +++ b/include/eepp/ui/tools/uicodeeditorsplitter.hpp @@ -136,6 +136,9 @@ class EE_API UICodeEditorSplitter { void applyColorScheme( const SyntaxColorScheme& colorScheme ); + void forEachWidgetClass( const std::string& className, + std::function run ) const; + void forEachWidgetType( const UINodeType& nodeType, std::function run ) const; diff --git a/include/eepp/ui/uitab.hpp b/include/eepp/ui/uitab.hpp index 2148d857a..ea11201fb 100644 --- a/include/eepp/ui/uitab.hpp +++ b/include/eepp/ui/uitab.hpp @@ -40,6 +40,8 @@ class EE_API UITab : public UISelectButton { virtual UIWidget* getExtraInnerWidget() const; + void removeTab( bool destroyOwnedNode = true, bool immediateClose = false ); + protected: friend class UITabWidget; diff --git a/src/eepp/ui/tools/uicodeeditorsplitter.cpp b/src/eepp/ui/tools/uicodeeditorsplitter.cpp index 63f07cb01..9f3e4ace9 100644 --- a/src/eepp/ui/tools/uicodeeditorsplitter.cpp +++ b/src/eepp/ui/tools/uicodeeditorsplitter.cpp @@ -681,6 +681,22 @@ void UICodeEditorSplitter::applyColorScheme( const SyntaxColorScheme& colorSchem mClient->onColorSchemeChanged( mCurrentColorScheme ); } +void UICodeEditorSplitter::forEachWidgetClass( const std::string& className, + std::function run ) const { + Node* node; + UIWidget* widget; + for ( auto tabWidget : mTabWidgets ) { + for ( size_t i = 0; i < tabWidget->getTabCount(); i++ ) { + node = tabWidget->getTab( i )->getOwnedWidget(); + if ( node && node->isWidget() ) { + widget = node->asType(); + if ( widget->hasClass( className ) ) + run( widget ); + } + } + } +} + void UICodeEditorSplitter::forEachWidgetType( const UINodeType& nodeType, std::function run ) const { Node* node; diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index 8e518d445..4a77d6744 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -163,6 +163,10 @@ UIWidget* UITab::getExtraInnerWidget() const { return mCloseButton; } +void UITab::removeTab( bool destroyOwnedNode, bool immediateClose ) { + getTabWidget()->removeTab( this, destroyOwnedNode, immediateClose ); +} + void UITab::setTheme( UITheme* Theme ) { UIWidget::setTheme( Theme ); diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 903a4d7b6..1cf91efa0 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -5,6 +5,7 @@ #include "plugins/linter/linterplugin.hpp" #include "plugins/lsp/lspclientplugin.hpp" #include "settingsmenu.hpp" +#include "uibuildsettings.hpp" #include "uiwelcomescreen.hpp" #include "version.hpp" #include @@ -1653,7 +1654,8 @@ void App::onRealDocumentLoaded( UICodeEditor* editor, const std::string& path ) ( !mDirTree || !mDirTree->isDirInTree( doc.getFileInfo().getFilepath() ) ) ) { std::string dir( FileSystem::fileRemoveFileName( doc.getFileInfo().getFilepath() ) ); Lock l( mWatchesLock ); - mFilesFolderWatches[dir] = mFileWatcher->addWatch( dir, mFileSystemListener ); + if ( mFileWatcher ) + mFilesFolderWatches[dir] = mFileWatcher->addWatch( dir, mFileSystemListener ); } } @@ -1820,6 +1822,10 @@ void App::closeEditors() { tabWidget->removeTab( (UITab*)terminal->getData(), true, true ); } + mSplitter->forEachWidgetClass( "build_settings", []( UIWidget* widget ) { + widget->asType()->getTab()->removeTab( true, true ); + } ); + mCurrentProject = ""; mDirTree = nullptr; if ( mFileSystemListener ) @@ -2265,23 +2271,22 @@ void App::updateEditorState() { } void App::removeFolderWatches() { - if ( mFileWatcher ) { - std::unordered_set folderWatches; - std::unordered_map filesFolderWatches; - { - Lock l( mWatchesLock ); - folderWatches = mFolderWatches; - filesFolderWatches = mFilesFolderWatches; - mFolderWatches.clear(); - mFilesFolderWatches.clear(); - } + std::unordered_set folderWatches; + std::unordered_map filesFolderWatches; - for ( const auto& dir : folderWatches ) - mFileWatcher->removeWatch( dir ); + Lock l( mWatchesLock ); + if ( !mFileWatcher ) + return; + folderWatches = mFolderWatches; + filesFolderWatches = mFilesFolderWatches; + mFolderWatches.clear(); + mFilesFolderWatches.clear(); - for ( const auto& fileFolder : filesFolderWatches ) - mFileWatcher->removeWatch( fileFolder.second ); - } + for ( const auto& dir : folderWatches ) + mFileWatcher->removeWatch( dir ); + + for ( const auto& fileFolder : filesFolderWatches ) + mFileWatcher->removeWatch( fileFolder.second ); } void App::loadDirTree( const std::string& path ) { @@ -2300,15 +2305,14 @@ void App::loadDirTree( const std::string& path ) { if ( mSplitter->curEditorExistsAndFocused() ) syncProjectTreeWithEditor( mSplitter->getCurEditor() ); } ); - if ( mFileWatcher ) { - removeFolderWatches(); - { - Lock l( mWatchesLock ); + removeFolderWatches(); + { + Lock l( mWatchesLock ); + if ( mFileWatcher ) mFolderWatches.insert( mFileWatcher->addWatch( dirTree.getPath(), mFileSystemListener, true ) ); - } - mFileSystemListener->setDirTree( mDirTree ); } + mFileSystemListener->setDirTree( mDirTree ); }, SyntaxDefinitionManager::instance()->getExtensionsPatternsSupported() ); } diff --git a/src/tools/ecode/uibuildsettings.cpp b/src/tools/ecode/uibuildsettings.cpp index f665224b9..08d8b6506 100644 --- a/src/tools/ecode/uibuildsettings.cpp +++ b/src/tools/ecode/uibuildsettings.cpp @@ -202,8 +202,16 @@ UIBuildSettings* UIBuildSettings::New( ProjectBuild& build, ProjectBuildConfigur return eeNew( UIBuildSettings, ( build, config ) ); } +UIBuildSettings::~UIBuildSettings() { + for ( const auto& cbs : mCbs ) { + for ( const auto& cb : cbs.second ) + cbs.first->removeEventListener( cb ); + } +} + UIBuildSettings::UIBuildSettings( ProjectBuild& build, ProjectBuildConfiguration& config ) : mBuild( build ), mConfig( config ), mOldName( mBuild.getName() ) { + addClass( "build_settings" ); mUISceneNode->loadLayoutFromString( SETTINGS_PANEL_XML, this, String::hash( "build_settings" ) ); auto buildNameInput = find( "build_name" ); @@ -265,7 +273,7 @@ UIBuildSettings::UIBuildSettings( ProjectBuild& build, ProjectBuildConfiguration auto buildTypeDropDown = find( "build_type_list" ); auto panelBuildTypeDDL = getUISceneNode() ->getRoot() - ->querySelector( " #build_tab #build_type_list" ) + ->querySelector( "#build_tab #build_type_list" ) ->asType(); std::vector buildTypes; @@ -279,13 +287,18 @@ UIBuildSettings::UIBuildSettings( ProjectBuild& build, ProjectBuildConfiguration if ( panelBuildTypeDDL ) panelBuildTypeDDL->getListBox()->setSelected( mConfig.buildType ); } ); - if ( panelBuildTypeDDL ) - panelBuildTypeDDL->on( + if ( panelBuildTypeDDL ) { + mCbs[panelBuildTypeDDL].push_back( panelBuildTypeDDL->on( Event::OnItemSelected, [this, buildTypeDropDown, panelBuildTypeDDL]( const Event* ) { mConfig.buildType = panelBuildTypeDDL->getListBox()->getItemSelectedText().toUtf8(); if ( buildTypeDropDown ) buildTypeDropDown->getListBox()->setSelected( mConfig.buildType ); - } ); + } ) ); + mCbs[panelBuildTypeDDL].push_back( + panelBuildTypeDDL->on( Event::OnClose, [this, panelBuildTypeDDL]( auto ) { + mCbs.erase( panelBuildTypeDDL ); + } ) ); + } auto advTitle = querySelector( ".settings_panel > .advanced_options > .title" ); advTitle->onClick( [this]( const MouseEvent* event ) { @@ -377,6 +390,10 @@ void UIBuildSettings::setTab( UITab* tab ) { } } +UITab* UIBuildSettings::getTab() const { + return mTab; +} + void UIBuildSettings::refreshTab() { if ( !mTab ) return; diff --git a/src/tools/ecode/uibuildsettings.hpp b/src/tools/ecode/uibuildsettings.hpp index df96a8fce..f526a8da9 100644 --- a/src/tools/ecode/uibuildsettings.hpp +++ b/src/tools/ecode/uibuildsettings.hpp @@ -13,8 +13,12 @@ class UIBuildSettings : public UIRelativeLayout { public: static UIBuildSettings* New( ProjectBuild& build, ProjectBuildConfiguration& config ); + virtual ~UIBuildSettings(); + void setTab( UITab* tab ); + UITab* getTab() const; + protected: friend class UIBuildStep; @@ -23,6 +27,7 @@ class UIBuildSettings : public UIRelativeLayout { UIDataBindHolder mDataBindHolder; UITab* mTab{ nullptr }; String mOldName; + std::unordered_map> mCbs; explicit UIBuildSettings( ProjectBuild& build, ProjectBuildConfiguration& config );