diff --git a/include/eepp/ui/uitabwidget.hpp b/include/eepp/ui/uitabwidget.hpp index 9b645c456..748789c43 100644 --- a/include/eepp/ui/uitabwidget.hpp +++ b/include/eepp/ui/uitabwidget.hpp @@ -62,11 +62,13 @@ class EE_API UITabWidget : public UIWidget { Uint32 getTabCount() const; - void removeTab( const Uint32& index, bool destroyOwnedNode = true ); + void removeTab( const Uint32& index, bool destroyOwnedNode = true, + bool immediateClose = false ); - void removeTab( UITab* tab, bool destroyOwnedNode = true ); + void removeTab( UITab* tab, bool destroyOwnedNode = true, bool immediateClose = false ); - void removeAllTabs( bool destroyOwnedNode = true ); + void removeAllTabs( bool destroyOwnedNode = true, + bool immediateClose = false ); void insertTab( const String& text, UINode* nodeOwned, Drawable* icon, const Uint32& index ); @@ -171,9 +173,10 @@ class EE_API UITabWidget : public UIWidget { UITab* createTab( const String& text, UINode* nodeOwned, Drawable* icon ); - void removeTab( const Uint32& index, bool destroyOwnedNode, bool destroyTab = true ); + void removeTab( const Uint32& index, bool destroyOwnedNode, bool destroyTab, + bool immediateClose ); - void removeTab( UITab* tab, bool destroyOwnedNode, bool destroyTab ); + void removeTab( UITab* tab, bool destroyOwnedNode, bool destroyTab, bool immediateClose ); virtual void onSizeChange(); diff --git a/src/eepp/ui/uitabwidget.cpp b/src/eepp/ui/uitabwidget.cpp index 66943365b..bf9353312 100644 --- a/src/eepp/ui/uitabwidget.cpp +++ b/src/eepp/ui/uitabwidget.cpp @@ -485,25 +485,28 @@ Uint32 UITabWidget::getTabCount() const { return mTabs.size(); } -void UITabWidget::removeTab( const Uint32& index, bool destroyOwnedNode ) { - removeTab( index, destroyOwnedNode, true ); +void UITabWidget::removeTab( const Uint32& index, bool destroyOwnedNode, bool immediateClose ) { + removeTab( index, destroyOwnedNode, true, immediateClose ); } -void UITabWidget::removeTab( const Uint32& index, bool destroyOwnedNode, bool destroyTab ) { +void UITabWidget::removeTab( const Uint32& index, bool destroyOwnedNode, bool destroyTab, + bool immediateClose ) { eeASSERT( index < mTabs.size() ); UITab* tab = mTabs[index]; - if ( destroyTab ) { + if ( destroyTab && !immediateClose ) { tab->close(); tab->setVisible( false ); tab->setEnabled( false ); } - if ( destroyOwnedNode ) { + + if ( destroyOwnedNode && !immediateClose ) { tab->getOwnedWidget()->close(); tab->getOwnedWidget()->setVisible( false ); tab->getOwnedWidget()->setEnabled( false ); } + mTabs.erase( mTabs.begin() + index ); if ( index == mTabSelectedIndex ) { @@ -532,28 +535,52 @@ void UITabWidget::removeTab( const Uint32& index, bool destroyOwnedNode, bool de TabEvent tabEvent( this, tab, index, Event::OnTabClosed ); sendEvent( &tabEvent ); + + if ( destroyOwnedNode && immediateClose ) { + eeDelete( tab->getOwnedWidget() ); + } + + if ( destroyTab && immediateClose ) { + eeSAFE_DELETE( tab ); + } } -void UITabWidget::removeTab( UITab* tab, bool destroyOwnedNode ) { - removeTab( getTabIndex( tab ), destroyOwnedNode, true ); +void UITabWidget::removeTab( UITab* tab, bool destroyOwnedNode, bool immediateClose ) { + removeTab( getTabIndex( tab ), destroyOwnedNode, true, immediateClose ); } -void UITabWidget::removeTab( UITab* tab, bool destroyOwnedNode, bool destroyTab ) { - removeTab( getTabIndex( tab ), destroyOwnedNode, destroyTab ); +void UITabWidget::removeTab( UITab* tab, bool destroyOwnedNode, bool destroyTab, + bool immediateClose ) { + removeTab( getTabIndex( tab ), destroyOwnedNode, destroyTab, immediateClose ); } -void UITabWidget::removeAllTabs( bool destroyOwnedNode ) { +void UITabWidget::removeAllTabs( bool destroyOwnedNode, bool immediateClose ) { std::deque tabs = mTabs; + if ( immediateClose ) { + for ( Uint32 i = 0; i < tabs.size(); i++ ) { + if ( NULL != tabs[i] ) { + TabEvent tabEvent( this, tabs[i], i, Event::OnTabClosed ); + sendEvent( &tabEvent ); + } + } + } + for ( Uint32 i = 0; i < mTabs.size(); i++ ) { if ( NULL != mTabs[i] ) { - mTabs[i]->close(); - mTabs[i]->setVisible( false ); - mTabs[i]->setEnabled( false ); - if ( destroyOwnedNode ) { - mTabs[i]->getOwnedWidget()->close(); - mTabs[i]->getOwnedWidget()->setVisible( false ); - mTabs[i]->getOwnedWidget()->setEnabled( false ); + if ( !immediateClose ) { + mTabs[i]->close(); + mTabs[i]->setVisible( false ); + mTabs[i]->setEnabled( false ); + if ( destroyOwnedNode ) { + mTabs[i]->getOwnedWidget()->close(); + mTabs[i]->getOwnedWidget()->setVisible( false ); + mTabs[i]->getOwnedWidget()->setEnabled( false ); + } + } else { + if ( destroyOwnedNode ) + eeDelete( mTabs[i]->getOwnedWidget() ); + eeDelete( mTabs[i] ); } } } @@ -565,10 +592,12 @@ void UITabWidget::removeAllTabs( bool destroyOwnedNode ) { orderTabs(); - for ( Uint32 i = 0; i < tabs.size(); i++ ) { - if ( NULL != tabs[i] ) { - TabEvent tabEvent( this, tabs[i], i, Event::OnTabClosed ); - sendEvent( &tabEvent ); + if ( !immediateClose ) { + for ( Uint32 i = 0; i < tabs.size(); i++ ) { + if ( NULL != tabs[i] ) { + TabEvent tabEvent( this, tabs[i], i, Event::OnTabClosed ); + sendEvent( &tabEvent ); + } } } } diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 257c89228..536a1a8b7 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -5,6 +5,8 @@ #include #include +Clock globalClock; +bool firstFrame = true; App* appInstance = nullptr; void appLoop() { @@ -356,6 +358,10 @@ void App::mainLoop() { SceneManager::instance()->draw(); mConsole->draw( elapsed ); mWindow->display(); + if ( firstFrame ) { + Log::info( "First frame took: %.2fms", globalClock.getElapsed().asMilliseconds() ); + firstFrame = false; + } } else { mWindow->getInput()->waitEvent( Milliseconds( mWindow->hasFocus() ? 16 : 100 ) ); } @@ -1610,16 +1616,13 @@ void App::closeEditors() { std::vector editors = mEditorSplitter->getAllEditors(); for ( auto editor : editors ) { UITabWidget* tabWidget = mEditorSplitter->tabWidgetFromEditor( editor ); - tabWidget->removeTab( (UITab*)editor->getData() ); + tabWidget->removeTab( (UITab*)editor->getData(), true, true ); } mCurrentProject = ""; mDirTree = nullptr; if ( mFileSystemListener ) mFileSystemListener->setDirTree( mDirTree ); - // Force to update the closed tabs. - SceneManager::instance()->update(); - mProjectDocConfig = ProjectDocumentConfig( mConfig.doc ); updateProjectSettingsMenu(); }